add_edge_visitors.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //=======================================================================
  2. // Copyright 2007 Aaron Windsor
  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. #ifndef __ADD_EDGE_VISITORS_HPP__
  9. #define __ADD_EDGE_VISITORS_HPP__
  10. #include <boost/property_map/property_map.hpp>
  11. namespace boost
  12. {
  13. struct default_add_edge_visitor
  14. {
  15. template < typename Graph, typename Vertex >
  16. void visit_vertex_pair(Vertex u, Vertex v, Graph& g)
  17. {
  18. add_edge(u, v, g);
  19. }
  20. };
  21. template < typename EdgeIndexMap > struct edge_index_update_visitor
  22. {
  23. typedef
  24. typename property_traits< EdgeIndexMap >::value_type edge_index_value_t;
  25. edge_index_update_visitor(
  26. EdgeIndexMap em, edge_index_value_t next_index_available)
  27. : m_em(em), m_next_index(next_index_available)
  28. {
  29. }
  30. template < typename Graph, typename Vertex >
  31. void visit_vertex_pair(Vertex u, Vertex v, Graph& g)
  32. {
  33. typedef typename graph_traits< Graph >::edge_descriptor edge_t;
  34. std::pair< edge_t, bool > return_value = add_edge(u, v, g);
  35. if (return_value.second)
  36. put(m_em, return_value.first, m_next_index++);
  37. }
  38. private:
  39. EdgeIndexMap m_em;
  40. edge_index_value_t m_next_index;
  41. };
  42. } // namespace boost
  43. #endif //__ADD_EDGE_VISITORS_HPP__