]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/read_graphviz.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / graph / example / read_graphviz.cpp
1 // Copyright 2006 Trustees of Indiana University
2
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)
6
7 // A simple example of using read_graphviz to load a GraphViz Dot textual
8 // graph into a BGL adjacency_list graph
9
10 // Author: Ronald Garcia
11
12
13 #include <boost/graph/graphviz.hpp>
14 #include <boost/graph/adjacency_list.hpp>
15 #include <string>
16 #include <sstream>
17
18 using namespace boost;
19 using namespace std;
20
21 int main() {
22 // Vertex properties
23 typedef property < vertex_name_t, std::string,
24 property < vertex_color_t, float > > vertex_p;
25 // Edge properties
26 typedef property < edge_weight_t, double > edge_p;
27 // Graph properties
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;
32
33 // Construct an empty graph and prepare the dynamic_property_maps.
34 graph_t graph(0);
35 dynamic_properties dp;
36
37 property_map<graph_t, vertex_name_t>::type name =
38 get(vertex_name, graph);
39 dp.property("node_id",name);
40
41 property_map<graph_t, vertex_color_t>::type mass =
42 get(vertex_color, graph);
43 dp.property("mass",mass);
44
45 property_map<graph_t, edge_weight_t>::type weight =
46 get(edge_weight, graph);
47 dp.property("weight",weight);
48
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);
53
54 // Sample graph as an std::istream;
55 std::istringstream
56 gvgraph("digraph { graph [name=\"graphname\"] a c e [mass = 6.66] }");
57
58 bool status = read_graphviz(gvgraph,graph,dp,"node_id");
59
60 return status ? EXIT_SUCCESS : EXIT_FAILURE;
61 }