From e662337924d5e0ef876d271b21087590fa5df60a Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Mon, 21 May 2001 18:35:25 +0000 Subject: [PATCH] more fixes for const correctness [SVN r10172] --- include/boost/graph/stanford_graph.hpp | 69 ++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/include/boost/graph/stanford_graph.hpp b/include/boost/graph/stanford_graph.hpp index e078c660..ab633992 100644 --- a/include/boost/graph/stanford_graph.hpp +++ b/include/boost/graph/stanford_graph.hpp @@ -87,10 +87,12 @@ class sgb_vertex_iterator; namespace boost { typedef Graph* sgb_graph_ptr; + typedef const Graph* sgb_const_graph_ptr; struct sgb_traversal_tag : public virtual vertex_list_graph_tag, - public virtual incidence_graph_tag { }; + public virtual incidence_graph_tag, + public virtual adjacency_graph_tag { }; template <> struct graph_traits { typedef Vertex* vertex_descriptor; @@ -107,7 +109,7 @@ namespace boost { typedef sgb_traversal_tag traversal_category; typedef allow_parallel_edge_tag edge_parallel_category; }; - template <> struct graph_traits { + template <> struct graph_traits { typedef Vertex* vertex_descriptor; typedef boost::sgb_edge edge_descriptor; typedef sgb_out_edge_iterator out_edge_iterator; @@ -148,6 +150,7 @@ namespace boost { template friend class sgb_edge_length_map; template friend class sgb_edge_util_map; friend long get(edge_length_t, const sgb_graph_ptr&, const sgb_edge& key); + friend long get(edge_length_t, const sgb_const_graph_ptr&, const sgb_edge& key); friend void put(edge_length_t, sgb_graph_ptr&, const sgb_edge& key, long value); protected: #endif @@ -213,21 +216,21 @@ namespace boost { namespace boost { inline std::pair - vertices(sgb_graph_ptr g) + vertices(sgb_const_graph_ptr g) { return std::make_pair(sgb_vertex_iterator(g->vertices), sgb_vertex_iterator(g->vertices + g->n)); } inline std::pair - out_edges(Vertex* u, sgb_graph_ptr) + out_edges(Vertex* u, sgb_const_graph_ptr) { return std::make_pair( sgb_out_edge_iterator(u, u->arcs), sgb_out_edge_iterator(u, 0) ); } inline boost::graph_traits::degree_size_type - out_degree(Vertex* u, sgb_graph_ptr g) + out_degree(Vertex* u, sgb_const_graph_ptr g) { boost::graph_traits::out_edge_iterator i, i_end; boost::tie(i, i_end) = out_edges(u, g); @@ -237,16 +240,17 @@ namespace boost { // in_edges? inline std::pair - adjacent_vertices(Vertex* u, sgb_graph_ptr) + adjacent_vertices(Vertex* u, sgb_const_graph_ptr) { return std::make_pair( sgb_adj_iterator(u->arcs), sgb_adj_iterator(0) ); } - inline long num_vertices(sgb_graph_ptr g) { return g->n; } - inline long num_edges(sgb_graph_ptr g) { return g->m; } + inline long num_vertices(sgb_const_graph_ptr g) { return g->n; } + inline long num_edges(sgb_const_graph_ptr g) { return g->m; } - inline Vertex* vertex(long v, sgb_graph_ptr g) { return g->vertices + v; } + inline Vertex* vertex(long v, sgb_const_graph_ptr g) + { return g->vertices + v; } // Various Property Maps @@ -400,6 +404,10 @@ namespace boost { get(edge_length_t, const sgb_graph_ptr&) { return sgb_edge_length_map(); } + inline sgb_edge_length_map + get(edge_length_t, const sgb_const_graph_ptr&) { + return sgb_edge_length_map(); + } inline sgb_edge_length_map get(edge_length_t, sgb_graph_ptr&) { return sgb_edge_length_map(); @@ -408,6 +416,10 @@ namespace boost { get(edge_length_t, const sgb_graph_ptr&, const sgb_edge& key) { return key._arc->len; } + inline long + get(edge_length_t, const sgb_const_graph_ptr&, const sgb_edge& key) { + return key._arc->len; + } inline void put(edge_length_t, sgb_graph_ptr&, const sgb_edge& key, long value) { @@ -431,6 +443,19 @@ namespace boost { typedef sgb_vertex_name_t_map const_type; }; + template <> + struct property_map { + typedef sgb_edge_length_map const_type; + }; + template <> + struct property_map { + typedef sgb_vertex_id_map const_type; + }; + template <> + struct property_map { + typedef sgb_vertex_name_t_map const_type; + }; + #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) namespace detail { @@ -456,6 +481,12 @@ namespace boost { typedef typename Choice::type type; typedef typename Choice::const_type const_type; }; + template + struct property_map { + typedef typename property_kind::type Kind; + typedef detail::sgb_choose_property_map Choice; + typedef typename Choice::const_type const_type; + }; #define SGB_UTIL_ACCESSOR(KIND,X) \ template \ @@ -468,12 +499,23 @@ namespace boost { get(X##_property, const sgb_graph_ptr&) { \ return sgb_##KIND##_util_map< X##_property, const T&>(); \ } \ + template \ + inline sgb_##KIND##_util_map< X##_property, const T&> \ + get(X##_property, const sgb_const_graph_ptr&) { \ + return sgb_##KIND##_util_map< X##_property, const T&>(); \ + } \ template \ inline typename \ sgb_##KIND##_util_map< X##_property, const T&>::value_type \ get(X##_property, const sgb_graph_ptr&, const Key& key) { \ return sgb_##KIND##_util_map< X##_property, const T&>()[key]; \ } \ + template \ + inline typename \ + sgb_##KIND##_util_map< X##_property, const T&>::value_type \ + get(X##_property, const sgb_const_graph_ptr&, const Key& key) { \ + return sgb_##KIND##_util_map< X##_property, const T&>()[key]; \ + } \ template \ inline void \ put(X##_property, sgb_graph_ptr&, const Key& key, const Value& value) { \ @@ -491,11 +533,20 @@ namespace boost { get(TAG, const sgb_graph_ptr&) { \ return sgb_##KIND##_util_map< TAG, const TYPE& >(); \ } \ + inline sgb_##KIND##_util_map< TAG, const TYPE& > \ + get(TAG, const sgb_const_graph_ptr&) { \ + return sgb_##KIND##_util_map< TAG, const TYPE& >(); \ + } \ template \ inline typename sgb_##KIND##_util_map< TAG, const TYPE& >::value_type \ get(TAG, const sgb_graph_ptr&, const Key& key) { \ return sgb_##KIND##_util_map< TAG, const TYPE& >()[key]; \ } \ + template \ + inline typename sgb_##KIND##_util_map< TAG, const TYPE& >::value_type \ + get(TAG, const sgb_const_graph_ptr&, const Key& key) { \ + return sgb_##KIND##_util_map< TAG, const TYPE& >()[key]; \ + } \ template \ inline void \ put(TAG, sgb_graph_ptr&, const Key& key, const Value& value) { \