add_edge_visitors.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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>
  22. struct edge_index_update_visitor
  23. {
  24. typedef typename
  25. property_traits<EdgeIndexMap>::value_type edge_index_value_t;
  26. edge_index_update_visitor(EdgeIndexMap em,
  27. edge_index_value_t next_index_available
  28. ) :
  29. m_em(em),
  30. m_next_index(next_index_available)
  31. {}
  32. template <typename Graph, typename Vertex>
  33. void visit_vertex_pair(Vertex u, Vertex v, Graph& g)
  34. {
  35. typedef typename graph_traits<Graph>::edge_descriptor edge_t;
  36. std::pair<edge_t, bool> return_value = add_edge(u,v,g);
  37. if (return_value.second)
  38. put( m_em, return_value.first, m_next_index++);
  39. }
  40. private:
  41. EdgeIndexMap m_em;
  42. edge_index_value_t m_next_index;
  43. };
  44. } // namespace boost
  45. #endif //__ADD_EDGE_VISITORS_HPP__