[英]Getting boost property_tree parent node
我在程序中使用了boost property_tree。 我已经为使用自定义路径类型设置了树。 我正在寻找的是获取特定节点的父节点ID。
这是一个例子:
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 is basically a vector<int>
结果按预期进行:
{0}: 1
{0}: 2
{0}: 1
{1}: 2
{0}: 2
{1}: 1
我需要的是一种获取节点的完整ID而不永久存储它的方法。 我在想的是一种简单地获取其父节点ID并将其推到路径的最前面,以此类推的方法。 但是我似乎无法在property_tree中找到一种方法来执行此操作。 这可能吗? 如果否,是否还有其他方法可以计算这种情况下的完整路径?
例如,路径为{0,1,0}的节点:
你不能
Boost Ptree节点是独立的,不知道任何包含的数据结构(这是单链列表的“树”等效项)。
最好的近似方法是,您可以在父级内部查找子级,例如在C ++中:boost ptree relative key 。
假设您始终可以搜索“ root”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.