2
0
mirror of https://github.com/boostorg/graph.git synced 2026-01-19 04:12:11 +00:00

Join ralf_grosse_kunstleve with HEAD

[SVN r9444]
This commit is contained in:
Ralf W. Grosse-Kunstleve
2001-03-05 20:01:01 +00:00
parent 4c4346312c
commit 41517e7509

View File

@@ -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 <utility>
#include <boost/config.hpp>
#include <boost/iterator.hpp>
#include <boost/operators.hpp>
@@ -33,6 +32,8 @@
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/properties.hpp>
// 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 <class Tag> 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<sgb_vertex_iterator,sgb_vertex_iterator>
vertices(Graph* g)
@@ -198,6 +198,14 @@ namespace boost {
sgb_out_edge_iterator(u, 0) );
}
inline boost::graph_traits<Graph*>::degree_size_type
out_degree(Vertex* u, Graph* g)
{
boost::graph_traits<Graph*>::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<sgb_adj_iterator,sgb_adj_iterator>
@@ -206,22 +214,12 @@ namespace boost {
return std::make_pair( sgb_adj_iterator(u->arcs),
sgb_adj_iterator(0) );
}
// deprecated
inline std::pair<sgb_adj_iterator,sgb_adj_iterator>
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 <class T> struct u_property {
typedef vertex_property_tag kind;
typedef T type;
};
template <class T> struct v_property {
typedef vertex_property_tag kind;
typedef T type;
};
template <class T> struct w_property {
typedef vertex_property_tag kind;
typedef T type;
};
template <class T> struct x_property {
typedef vertex_property_tag kind;
typedef T type;
};
template <class T> struct y_property {
typedef vertex_property_tag kind;
typedef T type;
};
template <class T> struct z_property {
typedef vertex_property_tag kind;
typedef T type;
#define SGB_PROPERTY_TAG(KIND,TAG) \
template <class T> 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 <class T> struct a_property {
typedef edge_property_tag kind;
typedef T type;
};
template <class T> 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 <class T> \
inline T& get_util_field(Vertex* v, X##_property<T>) { \
return get_util(v->X, T()); }
inline T& get_util_field(KIND* k, X##_property<T>) { \
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 <class T> \
inline T& get_util_field(Arc* e, X##_property<T>) { \
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 Tag>
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 <class Tag>
inline sgb_vertex_util_map<Tag>
get_property_map(Tag, Graph* g, vertex_property_tag) {
return sgb_vertex_util_map<Tag>();
}
#endif
// Edge Length Access
class sgb_edge_length_map
: public boost::put_get_at_helper<long, sgb_edge_length_map>
{
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 Tag>
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 <class Tag>
inline sgb_vertex_util_map<Tag>
get_property_map(Tag, const Graph* g, vertex_property_tag) {
return sgb_vertex_util_map<Tag>();
}
template <class Tag>
inline sgb_edge_util_map<Tag>
get_property_map(Tag, Graph* g, edge_property_tag) {
get_property_map(Tag, const Graph* g, edge_property_tag) {
return sgb_edge_util_map<Tag>();
}
template <class Tag, class Kind>
struct sgb_util_map { };
template <class Tag> struct sgb_util_map<Tag, vertex_property_tag> {
typedef typename sgb_vertex_util_map<Tag>::type type;
};
template <class Tag> struct sgb_util_map<Tag, edge_property_tag> {
typedef typename sgb_edge_util_map<Tag>::type type;
};
#if 0
template <class Tag>
inline typename sgb_util_map<Tag, typename Tag::kind>::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<long, sgb_edge_length_map>
{
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<Graph*, edge_length> {
struct property_map<Graph*, edge_length_t> {
typedef sgb_edge_length_map type;
typedef sgb_edge_length_map const_type;
};
template <>
struct property_map<Graph*, vertex_index_t> {
typedef sgb_vertex_id_map type;
typedef sgb_vertex_id_map const_type;
};
template <>
struct property_map<Graph*, vertex_name_t> {
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 <class Kind, class PropertyTag>
struct choose_property_map { };
template <class PropertyTag>
struct choose_property_map<edge_property_tag, PropertyTag> {
typedef sgb_edge_util_map<PropertyTag> type;
};
template <class PropertyTag>
struct choose_property_map<vertex_property_tag, PropertyTag> {
typedef sgb_vertex_util_map<PropertyTag> type;
};
template <class PropertyTag>
struct choose_property_map<edge_property_tag, PropertyTag> {
typedef sgb_edge_util_map<PropertyTag> type;
};
} // namespace detail
template <class PropertyTag>
struct property_map<Graph*, PropertyTag> {
typedef typename property_kind<PropertyTag>::type Kind;
typedef typename detail::choose_property_map<Kind, PropertyTag>::type type;
typedef type const_type;
};
#else
#define SGB_VERTEX_UTIL_ACCESSOR(TAG,TYPE) \
inline sgb_vertex_util_map< TAG<TYPE> > \
get(TAG<TYPE>, Graph*) { \
return sgb_vertex_util_map< TAG<TYPE> >(); \
#define SGB_UTIL_ACCESSOR(KIND,X) \
template <class T> \
inline sgb_##KIND##_util_map< X##_property<T> > \
get(X##_property<T>, Graph*) { \
return sgb_##KIND##_util_map< X##_property<T> >(); \
} \
template <> struct property_map<Graph*, TAG<TYPE> > { \
typedef sgb_vertex_util_map< TAG<TYPE> > type; \
template <class T, class Key> \
inline typename sgb_##KIND##_util_map< X##_property<T> >::value_type \
get(X##_property<T>, const Graph*, const Key& key) { \
return sgb_##KIND##_util_map< X##_property<T> >()[key]; \
} \
template <class T, class Key, class Value> \
inline void \
put(X##_property<T>, Graph*, const Key& key, const Value& value) { \
sgb_##KIND##_util_map< X##_property<T> >()[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<TYPE> > \
#define SGB_UTIL_ACCESSOR_TYPE(KIND,TAG,TYPE) \
inline sgb_##KIND##_util_map< TAG<TYPE> > \
get(TAG<TYPE>, Graph*) { \
return sgb_edge_util_map< TAG<TYPE> >(); \
return sgb_##KIND##_util_map< TAG<TYPE> >(); \
} \
template <class Key> \
inline typename sgb_##KIND##_util_map< TAG<TYPE> >::value_type \
get(TAG<TYPE>, const Graph*, const Key& key) { \
return sgb_##KIND##_util_map< TAG<TYPE> >()[key]; \
} \
template <class Key, class Value> \
inline void \
put(TAG<TYPE>, Graph*, const Key& key, const Value& value) { \
sgb_##KIND##_util_map< TAG<TYPE> >()[key] = value; \
} \
template <> struct property_map<Graph*, TAG<TYPE> > { \
typedef sgb_edge_util_map< TAG<TYPE> > type; \
typedef sgb_##KIND##_util_map< TAG<TYPE> > 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