]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/read_graphviz.cpp
1 // Copyright 2006 Trustees of Indiana University
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // A simple example of using read_graphviz to load a GraphViz Dot textual
8 // graph into a BGL adjacency_list graph
10 // Author: Ronald Garcia
13 #include <boost/graph/graphviz.hpp>
14 #include <boost/graph/adjacency_list.hpp>
18 using namespace boost
;
23 typedef property
< vertex_name_t
, std::string
,
24 property
< vertex_color_t
, float > > vertex_p
;
26 typedef property
< edge_weight_t
, double > edge_p
;
28 typedef property
< graph_name_t
, std::string
> graph_p
;
29 // adjacency_list-based type
30 typedef adjacency_list
< vecS
, vecS
, directedS
,
31 vertex_p
, edge_p
, graph_p
> graph_t
;
33 // Construct an empty graph and prepare the dynamic_property_maps.
35 dynamic_properties dp
;
37 property_map
<graph_t
, vertex_name_t
>::type name
=
38 get(vertex_name
, graph
);
39 dp
.property("node_id",name
);
41 property_map
<graph_t
, vertex_color_t
>::type mass
=
42 get(vertex_color
, graph
);
43 dp
.property("mass",mass
);
45 property_map
<graph_t
, edge_weight_t
>::type weight
=
46 get(edge_weight
, graph
);
47 dp
.property("weight",weight
);
49 // Use ref_property_map to turn a graph property into a property map
50 boost::ref_property_map
<graph_t
*,std::string
>
51 gname(get_property(graph
,graph_name
));
52 dp
.property("name",gname
);
54 // Sample graph as an std::istream;
56 gvgraph("digraph { graph [name=\"graphname\"] a c e [mass = 6.66] }");
58 bool status
= read_graphviz(gvgraph
,graph
,dp
,"node_id");
60 return status
? EXIT_SUCCESS
: EXIT_FAILURE
;