Access BGL GraphProperty

I am trying to access the graph label for a formatted input file with a dot (graphviz) using the Boost Graph library. The following is an example of typedef for a chart type:

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;

And this is how I assign dynamic properties:

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

The compiler complains about the assignment for the label DotGraph :: with an error message:

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

Can someone point out what is a convenient way to read the chart label in this case? Thank!

+4
source share
1 answer

Managed to map graph properties, as shown in step 3 of read_graphviz () in Boost :: Graph, go to the constructor :

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

And then you can access the label:

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

Source: https://habr.com/ru/post/1657332/


All Articles