首页 > 解决方案 > 使用 read_graphviz() 读取节点的默认属性

问题描述

我被 BGL 卡住了,试图读取节点的默认属性。我设法读取节点、边甚至图形属性。但不是下图中的默认属性(colorfontnameshape):

digraph G {
node [color = black, fontname = courier, shape = plaintext];
0[id=0, label=start];
1[id=1, label="0x00007ff7ca001358"];
2[id=2, label="0x00007ff7ca001969"];
0->1;
1->2;
}

这是我的代码,首先是:

class Node {
    public:
        std::string label, id;
};
class Branch {
    public:
        bool path;
};

typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS,Node,Branch> DAG;

std::istream & operator>>(std::istream & i, DAG & g)
{
    boost::dynamic_properties dp;        
    dp.property("id",get(&Node::id,g));
    dp.property("label",get(&Node::label,g));
    dp.property("path", get(&Branch::path, g));
    /* ??? dp.property("color", get(&????, g)); <= what to put here ? ref_property_map ? */
    read_graphviz(i,g,dp,"index");
    return i;
}

标签: c++boostgraphvizboost-graph

解决方案


推荐阅读