c++ - Getting boost property_tree parent node -
i using boost property_tree in program. i've set tree using custom path type. i'm looking getting specific node's parent node id.
here example:
metastoragetree tree; typedef boost::property_tree::basic_ptree<framework::commonclientserver::interfacepathchain_t, metastoragetreenode*> metastoragetreenode_t; class metastoragetree : public metastoragetreenode_t; metastoragetreenode* node = new metastoragetreenode(1); metastoragetreenode* node1 = new metastoragetreenode(2); tree.put(interfacepathchain_t{0}, node); tree.put(interfacepathchain_t{0, 0}, node1); tree.put(interfacepathchain_t{0, 1}, node1); tree.put(interfacepathchain_t{0, 0, 0}, node); tree.put(interfacepathchain_t{0, 1, 0}, node1); tree.put(interfacepathchain_t{0, 1, 1}, node); //interfacepathchain_t vector<int>
and result goes expected:
{0}: 1 {0}: 2 {0}: 1 {1}: 2 {0}: 2 {1}: 1
what need way of getting full id of node without permanently storing it. thinking of way of getting parent node id , pushing front of path , on top level. didn't seem able find way in property_tree. possible? if no, there other ways of calculating full path case?
for example node path {0, 1, 0}:
- id == 0 => path = {0}
- parent != null => parent.id == 1 => path = {1, 0}
- parent != null => parent.id == 0 => path = {0, 1, 0}
- parent == null => end
you can't.
boost ptree nodes self-contained , not know containing datastructure (it's the "tree" equivalent of singly-linked list).
as best approximation child inside parent, e.g. in c++: boost ptree relative key.
this presumes have "a root" available search in.
Comments
Post a Comment