访问 BGL GraphProperty

Accessing BGL GraphProperty

我正在尝试使用 Boost 图形库访问 dot(graphviz) 格式的输入文件的图形标签。以下是图形类型的类型定义:

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));

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

设法使用 的第 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;