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 11 #include <boost/property_map/property_map.hpp> 12 13 namespace boost 14 { 15 16 struct default_add_edge_visitor 17 { 18 19 template < typename Graph, typename Vertex > visit_vertex_pairboost::default_add_edge_visitor20 void visit_vertex_pair(Vertex u, Vertex v, Graph& g) 21 { 22 add_edge(u, v, g); 23 } 24 }; 25 26 template < typename EdgeIndexMap > struct edge_index_update_visitor 27 { 28 29 typedef 30 typename property_traits< EdgeIndexMap >::value_type edge_index_value_t; 31 edge_index_update_visitorboost::edge_index_update_visitor32 edge_index_update_visitor( 33 EdgeIndexMap em, edge_index_value_t next_index_available) 34 : m_em(em), m_next_index(next_index_available) 35 { 36 } 37 38 template < typename Graph, typename Vertex > visit_vertex_pairboost::edge_index_update_visitor39 void visit_vertex_pair(Vertex u, Vertex v, Graph& g) 40 { 41 typedef typename graph_traits< Graph >::edge_descriptor edge_t; 42 std::pair< edge_t, bool > return_value = add_edge(u, v, g); 43 if (return_value.second) 44 put(m_em, return_value.first, m_next_index++); 45 } 46 47 private: 48 EdgeIndexMap m_em; 49 edge_index_value_t m_next_index; 50 }; 51 52 } // namespace boost 53 54 #endif //__ADD_EDGE_VISITORS_HPP__ 55