1 // Copyright 2007 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 write_graphviz to output a BGL adjacency_list
8 // graph in GraphViz Dot format.
9 
10 // Author: Doug Gregor
11 
12 
13 #include <boost/graph/graphviz.hpp>
14 
15 
16 enum files_e { dax_h, yow_h, boz_h, zow_h, foo_cpp,
17                foo_o, bar_cpp, bar_o, libfoobar_a,
18                zig_cpp, zig_o, zag_cpp, zag_o,
19                  libzigzag_a, killerapp, N };
20 const char* name[] = { "dax.h", "yow.h", "boz.h", "zow.h", "foo.cpp",
21                        "foo.o", "bar.cpp", "bar.o", "libfoobar.a",
22                        "zig.cpp", "zig.o", "zag.cpp", "zag.o",
23                        "libzigzag.a", "killerapp" };
24 
main(int,char * [])25 int main(int,char*[])
26 {
27 
28   typedef std::pair<int,int> Edge;
29   Edge used_by[] = {
30     Edge(dax_h, foo_cpp), Edge(dax_h, bar_cpp), Edge(dax_h, yow_h),
31     Edge(yow_h, bar_cpp), Edge(yow_h, zag_cpp),
32     Edge(boz_h, bar_cpp), Edge(boz_h, zig_cpp), Edge(boz_h, zag_cpp),
33     Edge(zow_h, foo_cpp),
34     Edge(foo_cpp, foo_o),
35     Edge(foo_o, libfoobar_a),
36     Edge(bar_cpp, bar_o),
37     Edge(bar_o, libfoobar_a),
38     Edge(libfoobar_a, libzigzag_a),
39     Edge(zig_cpp, zig_o),
40     Edge(zig_o, libzigzag_a),
41     Edge(zag_cpp, zag_o),
42     Edge(zag_o, libzigzag_a),
43     Edge(libzigzag_a, killerapp)
44   };
45   const int nedges = sizeof(used_by)/sizeof(Edge);
46   int weights[nedges];
47   std::fill(weights, weights + nedges, 1);
48 
49   using namespace boost;
50 
51   typedef adjacency_list< vecS, vecS, directedS,
52       property< vertex_color_t, default_color_type >,
53       property< edge_weight_t, int >
54     > Graph;
55   Graph g(used_by, used_by + nedges, weights, N);
56 
57   write_graphviz(std::cout, g, make_label_writer(name));
58 }
59