访问BGL GraphProperty

时间:2016-10-11 00:17:29

标签: c++ boost boost-graph

我正在尝试使用Boost Graph Library访问 dot(graphviz)格式化输入文件的图形标签。下面是图表类型的typedef:

struct DotVertex {
  std::string label;
};

struct DotEdge {
  std::string label;
};

struct DotGraph {
  std::string label;
};

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
                              DotVertex, DotEdge, DotGraph> graph_t;

这就是我分配动态属性的方式:

  graph_t graphviz;

  boost::dynamic_properties dp(boost::ignore_other_properties);

  dp.property("label",       boost::get(&DotGraph::label,          graphviz));
  dp.property("label",       boost::get(&DotVertex::label,         graphviz));
  dp.property("label",       boost::get(&DotEdge::label,           graphviz));
  std::ifstream ifs("sample.dot");
  bool status = boost::read_graphviz(ifs, graphviz, dp);

编译器抱怨 DotGraph :: label 的分配错误消息:

read_graph.cc:25:30: error: no matching function for call to 'get'   dp.property("label",       boost::get(&DotGraph::label,          graphviz));

有人可以指出在这种情况下阅读图形标签的便捷方法是什么?谢谢!

1 个答案:

答案 0 :(得分:3)

管理以使用read_graphviz() in Boost::Graph, pass to constructor的步骤3中的图表属性映射:

  boost::ref_property_map<graph_t *, std::string> dg_label(get_property(graphviz, &DotGraph::label));
  dp.property("label",       dg_label);

然后可以通过以下方式访问标签:

 std::cout<<get_property(graphviz, &DotGraph::label)<<std::endl;