diff --git a/example/grid_graph_example.cpp b/example/grid_graph_example.cpp index 1406f2ef..c525f213 100644 --- a/example/grid_graph_example.cpp +++ b/example/grid_graph_example.cpp @@ -32,21 +32,21 @@ int main(int argc, char* argv[]) { // Do a round-trip test of the vertex index functions for (Traits::vertices_size_type v_index = 0; - v_index < num_vertices(graph); ++v_index) { + v_index < boost::num_vertices(graph); ++v_index) { // The two indicies should always be equal std::cout << "Index of vertex " << v_index << " is " << - get(boost::vertex_index, graph, vertex(v_index, graph)) << std::endl; + boost::get(boost::vertex_index, graph, boost::vertex(v_index, graph)) << std::endl; } // Do a round-trip test of the edge index functions for (Traits::edges_size_type e_index = 0; - e_index < num_edges(graph); ++e_index) { + e_index < boost::num_edges(graph); ++e_index) { // The two indicies should always be equal std::cout << "Index of edge " << e_index << " is " << - get(boost::edge_index, graph, edge_at(e_index, graph)) << std::endl; + boost::get(boost::edge_index, graph, edge_at(e_index, graph)) << std::endl; } @@ -63,7 +63,7 @@ int main(int argc, char* argv[]) { (graph.wrapped(2) ? "W" : "U") << std::endl; // prints "W, U, W" // Start with the first vertex in the graph - Traits::vertex_descriptor first_vertex = vertex(0, graph); + Traits::vertex_descriptor first_vertex = boost::vertex(0, graph); print_vertex(first_vertex); // prints "(0, 0, 0)" // Print the next vertex in dimension 0 diff --git a/include/boost/graph/grid_graph.hpp b/include/boost/graph/grid_graph.hpp index 9a09fca3..8d183281 100644 --- a/include/boost/graph/grid_graph.hpp +++ b/include/boost/graph/grid_graph.hpp @@ -63,17 +63,21 @@ namespace boost { return (m_graph->index_of(key)); } - friend inline Index - get(const grid_graph_index_map& index_map, - const typename grid_graph_index_map::key_type& key) - { - return (index_map[key]); - } protected: const Graph* m_graph; }; + template + inline Index + get(const grid_graph_index_map& index_map, + const typename grid_graph_index_map::key_type& key) + { + return (index_map[key]); + } + template struct property_map { typedef grid_graph_index_map& rev_map, - const typename grid_graph_reverse_edge_map::key_type& key) - { - return (rev_map[key]); - } }; + template + inline Descriptor + get(const grid_graph_reverse_edge_map& rev_map, + const typename grid_graph_reverse_edge_map::key_type& key) + { + return (rev_map[key]); + } + template struct property_map { typedef grid_graph_reverse_edge_map type; @@ -411,8 +417,7 @@ namespace boost { return (vertex); } - protected: - + public: // Returns the number of vertices in the graph inline vertices_size_type num_vertices() const { return (m_num_vertices); @@ -536,6 +541,7 @@ namespace boost { return (std::make_pair(vertex_source, vertex_target)); } + public: // Returns the index for [edge] (See also edge_at) edges_size_type index_of(edge_descriptor edge) const { vertex_descriptor source_vertex = source(edge, *this); @@ -619,6 +625,8 @@ namespace boost { return (edge_index); } + protected: + // Returns the number of out-edges for [vertex] degree_size_type out_degree(vertex_descriptor vertex) const { @@ -739,35 +747,6 @@ namespace boost { public: - //================ - // VertexListGraph - //================ - - friend inline std::pair - vertices(const type& graph) { - typedef typename type::vertex_iterator vertex_iterator; - typedef typename type::vertex_function vertex_function; - typedef typename type::vertex_index_iterator vertex_index_iterator; - - return (std::make_pair - (vertex_iterator(vertex_index_iterator(0), - vertex_function(&graph)), - vertex_iterator(vertex_index_iterator(graph.num_vertices()), - vertex_function(&graph)))); - } - - friend inline typename type::vertices_size_type - num_vertices(const type& graph) { - return (graph.num_vertices()); - } - - friend inline typename type::vertex_descriptor - vertex(typename type::vertices_size_type vertex_index, - const type& graph) { - - return (graph.vertex_at(vertex_index)); - } //=============== // IncidenceGraph @@ -821,34 +800,6 @@ namespace boost { adjacent_vertex_function(vertex, &graph)))); } - //============== - // EdgeListGraph - //============== - - friend inline typename type::edges_size_type - num_edges(const type& graph) { - return (graph.num_edges()); - } - - friend inline typename type::edge_descriptor - edge_at(typename type::edges_size_type edge_index, - const type& graph) { - return (graph.edge_at(edge_index)); - } - - friend inline std::pair - edges(const type& graph) { - typedef typename type::edge_index_iterator edge_index_iterator; - typedef typename type::edge_function edge_function; - typedef typename type::edge_iterator edge_iterator; - - return (std::make_pair - (edge_iterator(edge_index_iterator(0), - edge_function(&graph)), - edge_iterator(edge_index_iterator(graph.num_edges()), - edge_function(&graph)))); - } //=================== // BiDirectionalGraph @@ -953,48 +904,6 @@ namespace boost { // Index Property Map Functions //============================= - friend inline typename type::vertices_size_type - get(vertex_index_t, - const type& graph, - typename type::vertex_descriptor vertex) { - return (graph.index_of(vertex)); - } - - friend inline typename type::edges_size_type - get(edge_index_t, - const type& graph, - typename type::edge_descriptor edge) { - return (graph.index_of(edge)); - } - - friend inline grid_graph_index_map< - type, - typename type::vertex_descriptor, - typename type::vertices_size_type> - get(vertex_index_t, const type& graph) { - return (grid_graph_index_map< - type, - typename type::vertex_descriptor, - typename type::vertices_size_type>(graph)); - } - - friend inline grid_graph_index_map< - type, - typename type::edge_descriptor, - typename type::edges_size_type> - get(edge_index_t, const type& graph) { - return (grid_graph_index_map< - type, - typename type::edge_descriptor, - typename type::edges_size_type>(graph)); - } - - friend inline grid_graph_reverse_edge_map< - typename type::edge_descriptor> - get(edge_reverse_t, const type& graph) { - return (grid_graph_reverse_edge_map< - typename type::edge_descriptor>()); - } template + inline std::pair::vertex_iterator, + typename grid_graph::vertex_iterator> + vertices(const grid_graph& graph) { + typedef typename grid_graph::vertex_iterator vertex_iterator; + typedef typename grid_graph::vertex_function vertex_function; + typedef typename grid_graph::vertex_index_iterator vertex_index_iterator; + + return (std::make_pair + (vertex_iterator(vertex_index_iterator(0), + vertex_function(&graph)), + vertex_iterator(vertex_index_iterator(graph.num_vertices()), + vertex_function(&graph)))); + } + + template + inline typename grid_graph::vertices_size_type + num_vertices(const grid_graph& graph) { + return (graph.num_vertices()); + } + + template + inline typename grid_graph::vertex_descriptor + vertex(typename grid_graph::vertices_size_type vertex_index, + const grid_graph& graph) { + + return (graph.vertex_at(vertex_index)); + } + + template + inline VertexIndex + get(vertex_index_t, + const grid_graph & graph, + typename grid_graph::vertex_descriptor vertex) { + return (graph.index_of(vertex)); + } + + template + inline VertexIndex + get(edge_index_t, + const grid_graph& graph, + typename grid_graph::edge_descriptor edge) { + return (graph.index_of(edge)); + } + + template + inline grid_graph_index_map< + grid_graph, + typename grid_graph::vertex_descriptor, + VertexIndex> + get(vertex_index_t, const grid_graph& graph) { + return (grid_graph_index_map< + grid_graph, + typename grid_graph::vertex_descriptor, + VertexIndex>(graph)); + } + + template + inline grid_graph_index_map< + grid_graph, + typename grid_graph::edge_descriptor, + EdgeIndex> + get(edge_index_t, const grid_graph& graph) { + return (grid_graph_index_map< + grid_graph, + typename grid_graph::edge_descriptor, + EdgeIndex>(graph)); + } + + template + inline grid_graph_reverse_edge_map< + typename grid_graph::edge_descriptor> + get(edge_reverse_t, const grid_graph& graph) { + return (grid_graph_reverse_edge_map< + typename grid_graph::edge_descriptor>()); + } + + //============== + // EdgeListGraph + //============== + + template + inline EdgeIndex + num_edges(const grid_graph& graph) { + return (graph.num_edges()); + } + + template + inline typename grid_graph::edge_descriptor + edge_at(EdgeIndex edge_index, + const grid_graph& graph) { + return (graph.edge_at(edge_index)); + } + + template + inline std::pair::edge_iterator, + typename grid_graph::edge_iterator> + edges(const grid_graph& graph) { + typedef typename grid_graph::edge_index_iterator edge_index_iterator; + typedef typename grid_graph::edge_function edge_function; + typedef typename grid_graph::edge_iterator edge_iterator; + + return (std::make_pair + (edge_iterator(edge_index_iterator(0), + edge_function(&graph)), + edge_iterator(edge_index_iterator(graph.num_edges()), + edge_function(&graph)))); + } } // namespace boost #undef BOOST_GRID_GRAPH_TYPE diff --git a/test/grid_graph_test.cpp b/test/grid_graph_test.cpp index d88e68d2..827b69c7 100644 --- a/test/grid_graph_test.cpp +++ b/test/grid_graph_test.cpp @@ -79,7 +79,7 @@ void do_test(minstd_rand& generator) { for (vertices_size_type vertex_index = 0; vertex_index < num_vertices(graph); ++vertex_index) { - BOOST_REQUIRE(get(boost::vertex_index, graph, vertex(vertex_index, graph)) == vertex_index); + BOOST_REQUIRE(boost::get(boost::vertex_index, graph, vertex(vertex_index, graph)) == vertex_index); } for (edges_size_type edge_index = 0; @@ -87,15 +87,15 @@ void do_test(minstd_rand& generator) { ++edge_index) { edge_descriptor current_edge = edge_at(edge_index, graph); - BOOST_REQUIRE(get(boost::edge_index, graph, current_edge) == edge_index); + BOOST_REQUIRE(boost::get(boost::edge_index, graph, current_edge) == edge_index); } // Verify all vertices are within bounds vertices_size_type vertex_count = 0; - BOOST_FOREACH(vertex_descriptor current_vertex, vertices(graph)) { + BOOST_FOREACH(vertex_descriptor current_vertex, boost::vertices(graph)) { vertices_size_type current_index = - get(boost::vertex_index, graph, current_vertex); + boost::get(boost::vertex_index, graph, current_vertex); for (unsigned int dimension_index = 0; dimension_index < Dims; @@ -112,7 +112,7 @@ void do_test(minstd_rand& generator) { out_edges(current_vertex, graph)) { target_vertices.insert - (get(boost::vertex_index, graph, target(out_edge, graph))); + (boost::get(boost::vertex_index, graph, target(out_edge, graph))); ++out_edge_count; } @@ -126,7 +126,7 @@ void do_test(minstd_rand& generator) { in_edges(current_vertex, graph)) { BOOST_REQUIRE(target_vertices.count - (get(boost::vertex_index, graph, source(in_edge, graph))) > 0); + (boost::get(boost::vertex_index, graph, source(in_edge, graph))) > 0); ++in_edge_count; } @@ -145,7 +145,7 @@ void do_test(minstd_rand& generator) { adjacent_vertices(current_vertex, graph)) { BOOST_REQUIRE(target_vertices.count - (get(boost::vertex_index, graph, adjacent_vertex)) > 0); + (boost::get(boost::vertex_index, graph, adjacent_vertex)) > 0); ++adjacent_count; } @@ -154,10 +154,10 @@ void do_test(minstd_rand& generator) { // Verify that this vertex is not listed as connected to any // vertices outside of its adjacent vertices. - BOOST_FOREACH(vertex_descriptor unconnected_vertex, vertices(graph)) { + BOOST_FOREACH(vertex_descriptor unconnected_vertex, boost::vertices(graph)) { vertices_size_type unconnected_index = - get(boost::vertex_index, graph, unconnected_vertex); + boost::get(boost::vertex_index, graph, unconnected_vertex); if ((unconnected_index == current_index) || (target_vertices.count(unconnected_index) > 0)) { @@ -178,10 +178,10 @@ void do_test(minstd_rand& generator) { BOOST_FOREACH(edge_descriptor current_edge, edges(graph)) { vertices_size_type source_index = - get(boost::vertex_index, graph, source(current_edge, graph)); + boost::get(boost::vertex_index, graph, source(current_edge, graph)); vertices_size_type target_index = - get(boost::vertex_index, graph, target(current_edge, graph)); + boost::get(boost::vertex_index, graph, target(current_edge, graph)); BOOST_REQUIRE(source_index != target_index); BOOST_REQUIRE(/* (source_index >= 0) : always true && */ (source_index < num_vertices(graph)));