From 41517e7509174a9dded79559727348e18f4a45fd Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 5 Mar 2001 20:01:01 +0000 Subject: [PATCH] Join ralf_grosse_kunstleve with HEAD [SVN r9444] --- include/boost/graph/stanford_graph.hpp | 379 ++++++++++++------------- 1 file changed, 178 insertions(+), 201 deletions(-) diff --git a/include/boost/graph/stanford_graph.hpp b/include/boost/graph/stanford_graph.hpp index c0522a90..e897c667 100644 --- a/include/boost/graph/stanford_graph.hpp +++ b/include/boost/graph/stanford_graph.hpp @@ -1,5 +1,5 @@ //======================================================================= -// Copyright 1997, 1998, 1999, 2000 University of Notre Dame. +// Copyright 1997-2001 University of Notre Dame. // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek // // This file is part of the Boost Graph Library @@ -25,7 +25,6 @@ #ifndef BOOST_GRAPH_SGB_GRAPH_HPP #define BOOST_GRAPH_SGB_GRAPH_HPP -#include #include #include #include @@ -33,6 +32,8 @@ #include #include +// Thanks to Andreas Scherer for numerous suggestions and fixes! + // This file adapts a Stanford GraphBase (SGB) Graph pointer into a // VertexListGraph. Note that a graph adaptor class is not needed, // SGB's Graph* is used as is. The VertexListGraph concept is fulfilled by @@ -107,22 +108,24 @@ namespace boost { // we want to add the source(e,g) function which requires // that we carry along a pointer to the source vertex. class sgb_edge { + typedef sgb_edge self; public: - inline sgb_edge() : _arc(0), _src(0) { } - inline sgb_edge(Arc* a, Vertex* s) : _arc(a), _src(s) { } - friend inline Vertex* source(sgb_edge e, Graph*) { return e._src; } - friend inline Vertex* target(sgb_edge e, Graph*) { return e._arc->tip; } - // protected: + sgb_edge() : _arc(0), _src(0) { } + sgb_edge(Arc* a, Vertex* s) : _arc(a), _src(s) { } + friend Vertex* source(self& e, Graph*) { return e._src; } + friend Vertex* target(self& e, Graph*) { return e._arc->tip; } + friend bool operator==(const self& a, const self& b) { + return a._arc == b._arc; } + friend bool operator!=(const self& a, const self& b) { + return a._arc != b._arc; } +#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) + friend class sgb_edge_length_map; + template friend class sgb_edge_util_map; + protected: +#endif Arc* _arc; Vertex* _src; }; - inline bool operator==(const sgb_edge& a, const sgb_edge& b) { - return a._arc == b._arc; - } - inline bool operator!=(const sgb_edge& a, const sgb_edge& b) { - return a._arc != b._arc; - } - } // namespace boost class sgb_out_edge_iterator @@ -132,11 +135,11 @@ namespace boost { { typedef sgb_out_edge_iterator self; public: - inline sgb_out_edge_iterator() : _src(0), _arc(0) {} - inline sgb_out_edge_iterator(Vertex* s, Arc* d) : _src(s), _arc(d) {} - inline boost::sgb_edge operator*() { return boost::sgb_edge(_arc, _src); } - inline self& operator++() { _arc = _arc->next; return *this; } - friend inline bool operator==(const self& x, const self& y) { + sgb_out_edge_iterator() : _src(0), _arc(0) {} + sgb_out_edge_iterator(Vertex* s, Arc* d) : _src(s), _arc(d) {} + boost::sgb_edge operator*() { return boost::sgb_edge(_arc, _src); } + self& operator++() { _arc = _arc->next; return *this; } + friend bool operator==(const self& x, const self& y) { return x._arc == y._arc; } protected: Vertex* _src; @@ -147,13 +150,13 @@ namespace boost { : public boost::forward_iterator_helper< sgb_adj_iterator, Vertex*, std::ptrdiff_t, Vertex**,Vertex*> { - public: typedef sgb_adj_iterator self; - inline sgb_adj_iterator() : _arc(0) {} - inline sgb_adj_iterator(Arc* d) : _arc(d) {} - inline Vertex* operator*() { return _arc->tip; } - inline self& operator++() { _arc = _arc->next; return *this; } - friend inline bool operator==(const self& x, const self& y) { + public: + sgb_adj_iterator() : _arc(0) {} + sgb_adj_iterator(Arc* d) : _arc(d) {} + Vertex* operator*() { return _arc->tip; } + self& operator++() { _arc = _arc->next; return *this; } + friend bool operator==(const self& x, const self& y) { return x._arc == y._arc; } protected: Arc* _arc; @@ -167,22 +170,19 @@ namespace boost { : public boost::forward_iterator_helper< sgb_vertex_iterator, Vertex*, std::ptrdiff_t, Vertex**, Vertex*> { - public: typedef sgb_vertex_iterator self; - inline sgb_vertex_iterator() : _v(0) { } - inline sgb_vertex_iterator(Vertex* v) : _v(v) { } - inline Vertex* operator*() { return _v; } - inline self& operator++() { ++_v; return *this; } - friend inline bool operator==(const self& x, const self& y) { + public: + sgb_vertex_iterator() : _v(0) { } + sgb_vertex_iterator(Vertex* v) : _v(v) { } + Vertex* operator*() { return _v; } + self& operator++() { ++_v; return *this; } + friend bool operator==(const self& x, const self& y) { return x._v == y._v; } protected: Vertex* _v; }; - -#ifndef __GNUC__ namespace boost { -#endif inline std::pair vertices(Graph* g) @@ -198,6 +198,14 @@ namespace boost { sgb_out_edge_iterator(u, 0) ); } + inline boost::graph_traits::degree_size_type + out_degree(Vertex* u, Graph* g) + { + boost::graph_traits::out_edge_iterator i, i_end; + boost::tie(i, i_end) = out_edges(u, g); + return std::distance(i, i_end); + } + // in_edges? inline std::pair @@ -206,22 +214,12 @@ namespace boost { return std::make_pair( sgb_adj_iterator(u->arcs), sgb_adj_iterator(0) ); } - // deprecated - inline std::pair - adj(Vertex* u, Graph* g) - { - return adjacent_vertices(u, g); - } inline long num_vertices(Graph* g) { return g->n; } inline long num_edges(Graph* g) { return g->m; } inline Vertex* vertex(long v, Graph* g) { return g->vertices + v; } -#ifdef __GNUC__ -namespace boost { -#endif - // Various Property Maps // Vertex ID @@ -232,9 +230,10 @@ namespace boost { typedef boost::readable_property_map_tag category; typedef long value_type; typedef Vertex* key_type; - inline sgb_vertex_id_map() : _g(0) { } - inline sgb_vertex_id_map(Graph* g) : _g(g) { } - inline long operator[](Vertex* v) const { return v - _g->vertices; } + sgb_vertex_id_map() : _g(0) { } + sgb_vertex_id_map(Graph* g) : _g(g) { } + long operator[](Vertex* v) const { return v - _g->vertices; } + protected: Graph* _g; }; inline sgb_vertex_id_map get(vertex_index_t, Graph* g) { @@ -249,51 +248,34 @@ namespace boost { typedef boost::readable_property_map_tag category; typedef char* value_type; typedef Vertex* key_type; - inline char* operator[](Vertex* v) const { return v->name; } + char* operator[](Vertex* v) const { return v->name; } }; inline sgb_vertex_name_t_map get(vertex_name_t, Graph*) { return sgb_vertex_name_t_map(); } // Vertex Property Tags - template struct u_property { - typedef vertex_property_tag kind; - typedef T type; - }; - template struct v_property { - typedef vertex_property_tag kind; - typedef T type; - }; - template struct w_property { - typedef vertex_property_tag kind; - typedef T type; - }; - template struct x_property { - typedef vertex_property_tag kind; - typedef T type; - }; - template struct y_property { - typedef vertex_property_tag kind; - typedef T type; - }; - template struct z_property { - typedef vertex_property_tag kind; - typedef T type; +#define SGB_PROPERTY_TAG(KIND,TAG) \ + template struct TAG##_property { \ + typedef KIND##_property_tag kind; \ + typedef T type; \ }; + SGB_PROPERTY_TAG(vertex, u) + SGB_PROPERTY_TAG(vertex, v) + SGB_PROPERTY_TAG(vertex, w) + SGB_PROPERTY_TAG(vertex, x) + SGB_PROPERTY_TAG(vertex, y) + SGB_PROPERTY_TAG(vertex, z) + // Edge Property Tags - template struct a_property { - typedef edge_property_tag kind; - typedef T type; - }; - template struct b_property { - typedef edge_property_tag kind; - typedef T type; - }; - struct edge_length { + SGB_PROPERTY_TAG(edge, a) + SGB_PROPERTY_TAG(edge, b) + + struct edge_length_t { typedef edge_property_tag kind; }; - // Vertex Utility Map + // Various Utility Maps // helpers inline Vertex*& get_util(util& u, Vertex*) { return u.V; } @@ -302,26 +284,22 @@ namespace boost { inline char*& get_util(util& u, char*) { return u.S; } inline long& get_util(util& u, long) { return u.I; } -#define GET_VERTEX_UTIL_FIELD(X) \ +#define SGB_GET_UTIL_FIELD(KIND,X) \ template \ - inline T& get_util_field(Vertex* v, X##_property) { \ - return get_util(v->X, T()); } + inline T& get_util_field(KIND* k, X##_property) { \ + return get_util(k->X, T()); } - GET_VERTEX_UTIL_FIELD(u) - GET_VERTEX_UTIL_FIELD(v) - GET_VERTEX_UTIL_FIELD(w) - GET_VERTEX_UTIL_FIELD(x) - GET_VERTEX_UTIL_FIELD(y) - GET_VERTEX_UTIL_FIELD(z) + SGB_GET_UTIL_FIELD(Vertex, u) + SGB_GET_UTIL_FIELD(Vertex, v) + SGB_GET_UTIL_FIELD(Vertex, w) + SGB_GET_UTIL_FIELD(Vertex, x) + SGB_GET_UTIL_FIELD(Vertex, y) + SGB_GET_UTIL_FIELD(Vertex, z) -#define GET_EDGE_UTIL_FIELD(X) \ - template \ - inline T& get_util_field(Arc* e, X##_property) { \ - return get_util(e->X, T()); } - - GET_EDGE_UTIL_FIELD(a) - GET_EDGE_UTIL_FIELD(b) + SGB_GET_UTIL_FIELD(Arc, a) + SGB_GET_UTIL_FIELD(Arc, b) + // Vertex Utility Map template class sgb_vertex_util_map : public boost::put_get_at_helper< typename Tag::type, @@ -331,41 +309,15 @@ namespace boost { typedef boost::lvalue_property_map_tag category; typedef typename Tag::type value_type; typedef Vertex* key_type; - inline const value_type& operator[](Vertex* v) const { + const value_type& operator[](Vertex* v) const { return get_util_field(v, Tag()); } - inline value_type& operator[](Vertex* v) { + value_type& operator[](Vertex* v) { return get_util_field(v, Tag()); } }; -#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - inline sgb_vertex_util_map - get_property_map(Tag, Graph* g, vertex_property_tag) { - return sgb_vertex_util_map(); - } -#endif - // Edge Length Access - class sgb_edge_length_map - : public boost::put_get_at_helper - { - public: - typedef boost::lvalue_property_map_tag category; - typedef long value_type; - typedef sgb_edge key_type; - inline long& operator[](const sgb_edge& e) { - return e._arc->len; - } - inline const long& operator[](const sgb_edge& e) const { - return e._arc->len; - } - }; - inline sgb_edge_length_map - get(edge_length, Graph*) { - return sgb_edge_length_map(); - } - + // Edge Utility Map template class sgb_edge_util_map : public boost::put_get_at_helper< typename Tag::type, @@ -375,139 +327,164 @@ namespace boost { typedef boost::lvalue_property_map_tag category; typedef typename Tag::type value_type; typedef Vertex* key_type; - inline const value_type& operator[](sgb_edge e) const { + value_type& operator[](const sgb_edge& e) { return get_util_field(e._arc, Tag()); } - inline value_type& operator[](sgb_edge e) { + const value_type& operator[](const sgb_edge& e) const { return get_util_field(e._arc, Tag()); } }; + #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + template + inline sgb_vertex_util_map + get_property_map(Tag, const Graph* g, vertex_property_tag) { + return sgb_vertex_util_map(); + } template inline sgb_edge_util_map - get_property_map(Tag, Graph* g, edge_property_tag) { + get_property_map(Tag, const Graph* g, edge_property_tag) { return sgb_edge_util_map(); } + template struct sgb_util_map { }; + template struct sgb_util_map { typedef typename sgb_vertex_util_map::type type; }; template struct sgb_util_map { typedef typename sgb_edge_util_map::type type; }; -#if 0 - template - inline typename sgb_util_map::type - get(Tag t, Graph* g) { - typedef typename Tag::kind Kind; - return get_property_map(t, g, Kind()); + +#endif // ! BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + // Edge Length Access + class sgb_edge_length_map + : public boost::put_get_at_helper + { + public: + typedef boost::lvalue_property_map_tag category; + typedef long value_type; + typedef sgb_edge key_type; + long& operator[](const sgb_edge& e) { + return e._arc->len; + } + const long& operator[](const sgb_edge& e) const { + return e._arc->len; + } + }; + inline sgb_edge_length_map + get(edge_length_t, const Graph*) { + return sgb_edge_length_map(); + } + inline sgb_edge_length_map::value_type + get(edge_length_t, const Graph*, const sgb_edge_length_map::key_type& key) { + return sgb_edge_length_map()[key]; + } + inline void + put(edge_length_t, Graph*, const sgb_edge_length_map::key_type& key, + const sgb_edge_length_map::value_type& value) + { + sgb_edge_length_map()[key] = value; } -#endif -#endif // Property Map Traits Classes - template <> - struct property_map { + struct property_map { typedef sgb_edge_length_map type; + typedef sgb_edge_length_map const_type; }; template <> struct property_map { typedef sgb_vertex_id_map type; + typedef sgb_vertex_id_map const_type; }; template <> struct property_map { typedef sgb_vertex_name_t_map type; + typedef sgb_vertex_name_t_map const_type; }; -#ifdef BOOST_GRAPH_PARTIAL_SPECIALIZATION + +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) + namespace detail { template struct choose_property_map { }; template - struct choose_property_map { - typedef sgb_edge_util_map type; - }; - template struct choose_property_map { typedef sgb_vertex_util_map type; }; + template + struct choose_property_map { + typedef sgb_edge_util_map type; + }; } // namespace detail template struct property_map { typedef typename property_kind::type Kind; typedef typename detail::choose_property_map::type type; + typedef type const_type; }; -#else -#define SGB_VERTEX_UTIL_ACCESSOR(TAG,TYPE) \ - inline sgb_vertex_util_map< TAG > \ - get(TAG, Graph*) { \ - return sgb_vertex_util_map< TAG >(); \ +#define SGB_UTIL_ACCESSOR(KIND,X) \ + template \ + inline sgb_##KIND##_util_map< X##_property > \ + get(X##_property, Graph*) { \ + return sgb_##KIND##_util_map< X##_property >(); \ } \ - template <> struct property_map > { \ - typedef sgb_vertex_util_map< TAG > type; \ + template \ + inline typename sgb_##KIND##_util_map< X##_property >::value_type \ + get(X##_property, const Graph*, const Key& key) { \ + return sgb_##KIND##_util_map< X##_property >()[key]; \ + } \ + template \ + inline void \ + put(X##_property, Graph*, const Key& key, const Value& value) { \ + sgb_##KIND##_util_map< X##_property >()[key] = value; \ } -SGB_VERTEX_UTIL_ACCESSOR(u_property, Vertex*); -SGB_VERTEX_UTIL_ACCESSOR(u_property, Arc*); -SGB_VERTEX_UTIL_ACCESSOR(u_property, Graph*); -SGB_VERTEX_UTIL_ACCESSOR(u_property, long); -SGB_VERTEX_UTIL_ACCESSOR(u_property, char*); +#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -SGB_VERTEX_UTIL_ACCESSOR(v_property, Vertex*); -SGB_VERTEX_UTIL_ACCESSOR(v_property, Arc*); -SGB_VERTEX_UTIL_ACCESSOR(v_property, Graph*); -SGB_VERTEX_UTIL_ACCESSOR(v_property, long); -SGB_VERTEX_UTIL_ACCESSOR(v_property, char*); - -SGB_VERTEX_UTIL_ACCESSOR(w_property, Vertex*); -SGB_VERTEX_UTIL_ACCESSOR(w_property, Arc*); -SGB_VERTEX_UTIL_ACCESSOR(w_property, Graph*); -SGB_VERTEX_UTIL_ACCESSOR(w_property, long); -SGB_VERTEX_UTIL_ACCESSOR(w_property, char*); - -SGB_VERTEX_UTIL_ACCESSOR(x_property, Vertex*); -SGB_VERTEX_UTIL_ACCESSOR(x_property, Arc*); -SGB_VERTEX_UTIL_ACCESSOR(x_property, Graph*); -SGB_VERTEX_UTIL_ACCESSOR(x_property, long); -SGB_VERTEX_UTIL_ACCESSOR(x_property, char*); - -SGB_VERTEX_UTIL_ACCESSOR(y_property, Vertex*); -SGB_VERTEX_UTIL_ACCESSOR(y_property, Arc*); -SGB_VERTEX_UTIL_ACCESSOR(y_property, Graph*); -SGB_VERTEX_UTIL_ACCESSOR(y_property, long); -SGB_VERTEX_UTIL_ACCESSOR(y_property, char*); - -SGB_VERTEX_UTIL_ACCESSOR(z_property, Vertex*); -SGB_VERTEX_UTIL_ACCESSOR(z_property, Arc*); -SGB_VERTEX_UTIL_ACCESSOR(z_property, Graph*); -SGB_VERTEX_UTIL_ACCESSOR(z_property, long); -SGB_VERTEX_UTIL_ACCESSOR(z_property, char*); - -#define SGB_EDGE_UTIL_ACCESSOR(TAG,TYPE) \ - inline sgb_edge_util_map< TAG > \ +#define SGB_UTIL_ACCESSOR_TYPE(KIND,TAG,TYPE) \ + inline sgb_##KIND##_util_map< TAG > \ get(TAG, Graph*) { \ - return sgb_edge_util_map< TAG >(); \ + return sgb_##KIND##_util_map< TAG >(); \ + } \ + template \ + inline typename sgb_##KIND##_util_map< TAG >::value_type \ + get(TAG, const Graph*, const Key& key) { \ + return sgb_##KIND##_util_map< TAG >()[key]; \ + } \ + template \ + inline void \ + put(TAG, Graph*, const Key& key, const Value& value) { \ + sgb_##KIND##_util_map< TAG >()[key] = value; \ } \ template <> struct property_map > { \ - typedef sgb_edge_util_map< TAG > type; \ + typedef sgb_##KIND##_util_map< TAG > type; \ } -SGB_EDGE_UTIL_ACCESSOR(a_property, Vertex*); -SGB_EDGE_UTIL_ACCESSOR(a_property, Arc*); -SGB_EDGE_UTIL_ACCESSOR(a_property, Graph*); -SGB_EDGE_UTIL_ACCESSOR(a_property, long); -SGB_EDGE_UTIL_ACCESSOR(a_property, char*); - -SGB_EDGE_UTIL_ACCESSOR(b_property, Vertex*); -SGB_EDGE_UTIL_ACCESSOR(b_property, Arc*); -SGB_EDGE_UTIL_ACCESSOR(b_property, Graph*); -SGB_EDGE_UTIL_ACCESSOR(b_property, long); -SGB_EDGE_UTIL_ACCESSOR(b_property, char*); +#define SGB_UTIL_ACCESSOR(KIND,TAG) \ + SGB_UTIL_ACCESSOR_TYPE(KIND, TAG##_property, Vertex*); \ + SGB_UTIL_ACCESSOR_TYPE(KIND, TAG##_property, Arc*); \ + SGB_UTIL_ACCESSOR_TYPE(KIND, TAG##_property, Graph*); \ + SGB_UTIL_ACCESSOR_TYPE(KIND, TAG##_property, long); \ + SGB_UTIL_ACCESSOR_TYPE(KIND, TAG##_property, char*); #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + SGB_UTIL_ACCESSOR(vertex, u) + SGB_UTIL_ACCESSOR(vertex, v) + SGB_UTIL_ACCESSOR(vertex, w) + SGB_UTIL_ACCESSOR(vertex, x) + SGB_UTIL_ACCESSOR(vertex, y) + SGB_UTIL_ACCESSOR(vertex, z) + + SGB_UTIL_ACCESSOR(edge, a) + SGB_UTIL_ACCESSOR(edge, b) + } // namespace boost #endif // BOOST_GRAPH_SGB_GRAPH_HPP