dfs-parenthesis.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. IMPORTANT!!!
  10. ~~~~~~~~~~~~
  11. This example uses interfaces that have been deprecated and removed from Boost.Grpah.
  12. Someone needs to update it, as it does NOT compile.
  13. */
  14. #include <boost/graph/graphviz.hpp>
  15. #include <boost/graph/depth_first_search.hpp>
  16. char name[] = "abcdefghij";
  17. struct parenthesis_visitor : public boost::default_dfs_visitor
  18. {
  19. template <class Vertex, class Graph> void
  20. start_vertex(Vertex v, const Graph &)
  21. {
  22. std::cout << ' ';
  23. }
  24. template <class Vertex, class Graph> void
  25. discover_vertex(Vertex v, const Graph &)
  26. {
  27. std::cout << "(" << name[v] << ' ';
  28. }
  29. template <class Vertex, class Graph> void
  30. finish_vertex(Vertex v, const Graph &)
  31. {
  32. std::cout << ' ' << name[v] << ")";
  33. }
  34. };
  35. int
  36. main()
  37. {
  38. using namespace boost;
  39. GraphvizGraph g;
  40. read_graphviz("figs/dfs-example.dot", g);
  41. graph_traits < GraphvizGraph >::edge_iterator e, e_end;
  42. for (boost::tie(e, e_end) = edges(g); e != e_end; ++e)
  43. std::cout << '(' << name[source(*e, g)] << ' '
  44. << name[target(*e, g)] << ')' << std::endl;
  45. parenthesis_visitor
  46. paren_vis;
  47. depth_first_search(g, visitor(paren_vis));
  48. std::cout << std::endl;
  49. return 0;
  50. }