]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/reachable-loop-head.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / graph / example / reachable-loop-head.cpp
1 //=======================================================================
2 // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
8
9 /*
10 IMPORTANT!!!
11 ~~~~~~~~~~~~
12 This example uses interfaces that have been deprecated and removed from Boost.Grpah.
13 Someone needs to update it, as it does NOT compile.
14 */
15
16
17 #include <boost/config.hpp>
18 #include <iostream>
19 #include <fstream>
20 #include <boost/graph/adjacency_list.hpp>
21 #include <boost/graph/depth_first_search.hpp>
22 #include <boost/graph/graphviz.hpp>
23 #include <boost/graph/copy.hpp>
24
25 int
26 main(int argc, char *argv[])
27 {
28 if (argc < 3) {
29 std::cerr << "usage: reachable-loop-head.exe <in-file> <out-file>"
30 << std::endl;
31 return -1;
32 }
33 using namespace boost;
34 GraphvizDigraph g;
35 read_graphviz(argv[1], g);
36 graph_traits < GraphvizDigraph >::vertex_descriptor loop_head = 1;
37 typedef color_traits < default_color_type > Color;
38
39 std::vector < default_color_type >
40 reachable_from_head(num_vertices(g), Color::white());
41 default_color_type c;
42 depth_first_visit(g, loop_head, default_dfs_visitor(),
43 make_iterator_property_map(reachable_from_head.begin(),
44 get(vertex_index, g), c));
45
46 property_map<GraphvizDigraph, vertex_attribute_t>::type
47 vattr_map = get(vertex_attribute, g);
48
49 graph_traits < GraphvizDigraph >::vertex_iterator i, i_end;
50 for (boost::tie(i, i_end) = vertices(g); i != i_end; ++i)
51 if (reachable_from_head[*i] != Color::white()) {
52 vattr_map[*i]["color"] = "gray";
53 vattr_map[*i]["style"] = "filled";
54 }
55
56 std::ofstream loops_out(argv[2]);
57 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
58 // VC++ has trouble with the get_property() functions
59 loops_out << "digraph G {\n"
60 << "size=\"3,3\"\n"
61 << "ratio=\"fill\"\n"
62 << "shape=\"box\"\n";
63 graph_traits<GraphvizDigraph>::vertex_iterator vi, vi_end;
64 for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) {
65 loops_out << *vi << "[";
66 for (std::map<std::string,std::string>::iterator ai = vattr_map[*vi].begin();
67 ai != vattr_map[*vi].end(); ++ai) {
68 loops_out << ai->first << "=" << ai->second;
69 if (next(ai) != vattr_map[*vi].end())
70 loops_out << ", ";
71 }
72 loops_out<< "]";
73 }
74 property_map<GraphvizDigraph, edge_attribute_t>::type
75 eattr_map = get(edge_attribute, g);
76 graph_traits<GraphvizDigraph>::edge_iterator ei, ei_end;
77 for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) {
78 loops_out << source(*ei, g) << " -> " << target(*ei, g) << "[";
79 std::map<std::string,std::string>& attr_map = eattr_map[*ei];
80 for (std::map<std::string,std::string>::iterator eai = attr_map.begin();
81 eai != attr_map.end(); ++eai) {
82 loops_out << eai->first << "=" << eai->second;
83 if (next(eai) != attr_map.end())
84 loops_out << ", ";
85 }
86 loops_out<< "]";
87 }
88 loops_out << "}\n";
89 #else
90 get_property(g, graph_graph_attribute)["size"] = "3,3";
91 get_property(g, graph_graph_attribute)["ratio"] = "fill";
92 get_property(g, graph_vertex_attribute)["shape"] = "box";
93
94 write_graphviz(loops_out, g,
95 make_vertex_attributes_writer(g),
96 make_edge_attributes_writer(g),
97 make_graph_attributes_writer(g));
98 #endif
99
100
101 return EXIT_SUCCESS;
102 }