New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of grid_graph without "using namespace boost" #91

Open
wants to merge 3 commits into
base: develop
from
Jump to file or symbol
Failed to load files and symbols.
+92 −65
Diff settings

Always

Just for now

Next

grid_graph: Put get() in boost namespace.

Implementing the get() functions as friend functions in the class
declaration just puts them in the global namespace, or at least
doesn't make them callable from the boost:: namespace.
  • Loading branch information...
murraycu committed Oct 11, 2016
commit 779f88a10b7f3883085f27f1ec5950f3c8e684b1
@@ -36,7 +36,7 @@ int main(int argc, char* argv[]) {
// 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, vertex(v_index, graph)) << std::endl;
}
@@ -46,7 +46,7 @@ int main(int argc, char* argv[]) {
// 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,17 +63,21 @@ namespace boost {
return (m_graph->index_of(key));
}
friend inline Index
get(const grid_graph_index_map<Graph, Descriptor, Index>& index_map,
const typename grid_graph_index_map<Graph, Descriptor, Index>::key_type& key)
{
return (index_map[key]);
}
protected:
const Graph* m_graph;
};
template <typename Graph,
typename Descriptor,
typename Index>
inline Index
get(const grid_graph_index_map<Graph, Descriptor, Index>& index_map,
const typename grid_graph_index_map<Graph, Descriptor, Index>::key_type& key)
{
return (index_map[key]);
}
template<BOOST_GRID_GRAPH_TEMPLATE_PARAMS>
struct property_map<BOOST_GRID_GRAPH_TYPE, vertex_index_t> {
typedef grid_graph_index_map<BOOST_GRID_GRAPH_TYPE,
@@ -109,14 +113,16 @@ namespace boost {
return (value_type(key.second, key.first));
}
friend inline Descriptor
get(const grid_graph_reverse_edge_map<Descriptor>& rev_map,
const typename grid_graph_reverse_edge_map<Descriptor>::key_type& key)
{
return (rev_map[key]);
}
};
template <typename Descriptor>
inline Descriptor
get(const grid_graph_reverse_edge_map<Descriptor>& rev_map,
const typename grid_graph_reverse_edge_map<Descriptor>::key_type& key)
{
return (rev_map[key]);
}
template<BOOST_GRID_GRAPH_TEMPLATE_PARAMS>
struct property_map<BOOST_GRID_GRAPH_TYPE, edge_reverse_t> {
typedef grid_graph_reverse_edge_map<BOOST_GRID_GRAPH_TRAITS_T::edge_descriptor> type;
@@ -429,6 +435,7 @@ namespace boost {
return (m_edge_count[dimension_index]);
}
public:
// Returns the index of [vertex] (See also vertex_at)
vertices_size_type index_of(vertex_descriptor vertex) const {
@@ -446,6 +453,8 @@ namespace boost {
return (vertex_index);
}
protected:
// Returns the vertex whose index is [vertex_index] (See also
// index_of(vertex_descriptor))
vertex_descriptor vertex_at
@@ -536,6 +545,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 +629,8 @@ namespace boost {
return (edge_index);
}
protected:
// Returns the number of out-edges for [vertex]
degree_size_type out_degree(vertex_descriptor vertex) const {
@@ -953,48 +965,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<typename Graph,
typename Descriptor,
@@ -1006,6 +976,63 @@ namespace boost {
}; // grid_graph
template <std::size_t Dimensions,
typename VertexIndex = std::size_t,
typename EdgeIndex = VertexIndex>
inline VertexIndex
get(vertex_index_t,
const grid_graph<Dimensions, VertexIndex, EdgeIndex> & graph,
typename grid_graph<Dimensions, VertexIndex, EdgeIndex>::vertex_descriptor vertex) {
return (graph.index_of(vertex));
}
template <std::size_t Dimensions,
typename VertexIndex = std::size_t,
typename EdgeIndex = VertexIndex>
inline VertexIndex
get(edge_index_t,
const grid_graph<Dimensions, VertexIndex, EdgeIndex>& graph,
typename grid_graph<Dimensions, VertexIndex, EdgeIndex>::edge_descriptor edge) {
return (graph.index_of(edge));
}
template <std::size_t Dimensions,
typename VertexIndex = std::size_t,
typename EdgeIndex = VertexIndex>
inline grid_graph_index_map<
grid_graph<Dimensions, VertexIndex, EdgeIndex>,
typename grid_graph<Dimensions, VertexIndex, EdgeIndex>::vertex_descriptor,
VertexIndex>
get(vertex_index_t, const grid_graph<Dimensions, VertexIndex, EdgeIndex>& graph) {
return (grid_graph_index_map<
grid_graph<Dimensions, VertexIndex, EdgeIndex>,
typename grid_graph<Dimensions, VertexIndex, EdgeIndex>::vertex_descriptor,
VertexIndex>(graph));
}
template <std::size_t Dimensions,
typename VertexIndex = std::size_t,
typename EdgeIndex = VertexIndex>
inline grid_graph_index_map<
grid_graph<Dimensions, VertexIndex, EdgeIndex>,
typename grid_graph<Dimensions, VertexIndex, EdgeIndex>::edge_descriptor,
EdgeIndex>
get(edge_index_t, const grid_graph<Dimensions, VertexIndex, EdgeIndex>& graph) {
return (grid_graph_index_map<
grid_graph<Dimensions, VertexIndex, EdgeIndex>,
typename grid_graph<Dimensions, VertexIndex, EdgeIndex>::edge_descriptor,
EdgeIndex>(graph));
}
template <std::size_t Dimensions,
typename VertexIndex = std::size_t,
typename EdgeIndex = VertexIndex>
inline grid_graph_reverse_edge_map<
typename grid_graph<Dimensions, VertexIndex, EdgeIndex>::edge_descriptor>
get(edge_reverse_t, const grid_graph<Dimensions, VertexIndex, EdgeIndex>& graph) {
return (grid_graph_reverse_edge_map<
typename grid_graph<Dimensions, VertexIndex, EdgeIndex>::edge_descriptor>());
}
} // namespace boost
#undef BOOST_GRID_GRAPH_TYPE
Copy path View file
@@ -79,23 +79,23 @@ 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;
edge_index < num_edges(graph);
++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)) {
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;
}
@@ -157,7 +157,7 @@ void do_test(minstd_rand& generator) {
BOOST_FOREACH(vertex_descriptor unconnected_vertex, 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)));
ProTip! Use n and p to navigate between commits in a pull request.