]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/dfs-parenthesis.cpp
1 //=======================================================================
2 // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
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 #include <boost/graph/graphviz.hpp>
9 #include <boost/graph/depth_first_search.hpp>
11 char name
[] = "abcdefghij";
13 struct parenthesis_visitor
: public boost::default_dfs_visitor
15 template <class Vertex
, class Graph
> void
16 start_vertex(Vertex v
, const Graph
&)
20 template <class Vertex
, class Graph
> void
21 discover_vertex(Vertex v
, const Graph
&)
23 std::cout
<< "(" << name
[v
] << ' ';
25 template <class Vertex
, class Graph
> void
26 finish_vertex(Vertex v
, const Graph
&)
28 std::cout
<< ' ' << name
[v
] << ")";
35 using namespace boost
;
37 read_graphviz("figs/dfs-example.dot", g
);
38 graph_traits
< GraphvizGraph
>::edge_iterator e
, e_end
;
39 for (boost::tie(e
, e_end
) = edges(g
); e
!= e_end
; ++e
)
40 std::cout
<< '(' << name
[source(*e
, g
)] << ' '
41 << name
[target(*e
, g
)] << ')' << std::endl
;
44 depth_first_search(g
, visitor(paren_vis
));
45 std::cout
<< std::endl
;