Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:21

0001 //=======================================================================
0002 // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
0003 // Copyright 2010 Thomas Claveirole
0004 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek, Thomas Claveirole
0005 //
0006 // Distributed under the Boost Software License, Version 1.0. (See
0007 // accompanying file LICENSE_1_0.txt or copy at
0008 // http://www.boost.org/LICENSE_1_0.txt)
0009 //=======================================================================
0010 
0011 #ifndef BOOST_GRAPH_ADJACENCY_LIST_HPP
0012 #define BOOST_GRAPH_ADJACENCY_LIST_HPP
0013 
0014 #include <boost/config.hpp>
0015 
0016 #include <vector>
0017 #include <list>
0018 #include <set>
0019 
0020 #include <boost/unordered_set.hpp>
0021 
0022 #include <boost/scoped_ptr.hpp>
0023 
0024 #include <boost/graph/graph_traits.hpp>
0025 #include <boost/graph/graph_mutability_traits.hpp>
0026 #include <boost/graph/graph_selectors.hpp>
0027 #include <boost/property_map/property_map.hpp>
0028 #include <boost/mpl/if.hpp>
0029 #include <boost/mpl/and.hpp>
0030 #include <boost/mpl/not.hpp>
0031 #include <boost/mpl/bool.hpp>
0032 #include <boost/graph/detail/edge.hpp>
0033 #include <boost/type_traits/is_same.hpp>
0034 #include <boost/detail/workaround.hpp>
0035 #include <boost/graph/properties.hpp>
0036 #include <boost/graph/named_graph.hpp>
0037 
0038 namespace boost
0039 {
0040 
0041 //===========================================================================
0042 // Selectors for the VertexList and EdgeList template parameters of
0043 // adjacency_list, and the container_gen traits class which is used
0044 // to map the selectors to the container type used to implement the
0045 // graph.
0046 
0047 struct vecS
0048 {
0049 };
0050 struct listS
0051 {
0052 };
0053 struct setS
0054 {
0055 };
0056 struct mapS
0057 {
0058 };
0059 struct multisetS
0060 {
0061 };
0062 struct multimapS
0063 {
0064 };
0065 struct hash_setS
0066 {
0067 };
0068 struct hash_mapS
0069 {
0070 };
0071 struct hash_multisetS
0072 {
0073 };
0074 struct hash_multimapS
0075 {
0076 };
0077 
0078 template < class Selector, class ValueType > struct container_gen
0079 {
0080 };
0081 
0082 template < class ValueType > struct container_gen< listS, ValueType >
0083 {
0084     typedef std::list< ValueType > type;
0085 };
0086 
0087 template < class ValueType > struct container_gen< vecS, ValueType >
0088 {
0089     typedef std::vector< ValueType > type;
0090 };
0091 
0092 template < class ValueType > struct container_gen< mapS, ValueType >
0093 {
0094     typedef std::set< ValueType > type;
0095 };
0096 
0097 template < class ValueType > struct container_gen< setS, ValueType >
0098 {
0099     typedef std::set< ValueType > type;
0100 };
0101 
0102 template < class ValueType > struct container_gen< multisetS, ValueType >
0103 {
0104     typedef std::multiset< ValueType > type;
0105 };
0106 
0107 template < class ValueType > struct container_gen< multimapS, ValueType >
0108 {
0109     typedef std::multiset< ValueType > type;
0110 };
0111 
0112 template < class ValueType > struct container_gen< hash_setS, ValueType >
0113 {
0114     typedef boost::unordered_set< ValueType > type;
0115 };
0116 
0117 template < class ValueType > struct container_gen< hash_mapS, ValueType >
0118 {
0119     typedef boost::unordered_set< ValueType > type;
0120 };
0121 
0122 template < class ValueType > struct container_gen< hash_multisetS, ValueType >
0123 {
0124     typedef boost::unordered_multiset< ValueType > type;
0125 };
0126 
0127 template < class ValueType > struct container_gen< hash_multimapS, ValueType >
0128 {
0129     typedef boost::unordered_multiset< ValueType > type;
0130 };
0131 
0132 template < class StorageSelector > struct parallel_edge_traits
0133 {
0134 };
0135 
0136 template <> struct parallel_edge_traits< vecS >
0137 {
0138     typedef allow_parallel_edge_tag type;
0139 };
0140 
0141 template <> struct parallel_edge_traits< listS >
0142 {
0143     typedef allow_parallel_edge_tag type;
0144 };
0145 
0146 template <> struct parallel_edge_traits< setS >
0147 {
0148     typedef disallow_parallel_edge_tag type;
0149 };
0150 
0151 template <> struct parallel_edge_traits< multisetS >
0152 {
0153     typedef allow_parallel_edge_tag type;
0154 };
0155 
0156 template <> struct parallel_edge_traits< hash_setS >
0157 {
0158     typedef disallow_parallel_edge_tag type;
0159 };
0160 
0161 // mapS is obsolete, replaced with setS
0162 template <> struct parallel_edge_traits< mapS >
0163 {
0164     typedef disallow_parallel_edge_tag type;
0165 };
0166 
0167 template <> struct parallel_edge_traits< hash_mapS >
0168 {
0169     typedef disallow_parallel_edge_tag type;
0170 };
0171 
0172 template <> struct parallel_edge_traits< hash_multisetS >
0173 {
0174     typedef allow_parallel_edge_tag type;
0175 };
0176 
0177 template <> struct parallel_edge_traits< hash_multimapS >
0178 {
0179     typedef allow_parallel_edge_tag type;
0180 };
0181 
0182 namespace detail
0183 {
0184     template < class Directed > struct is_random_access
0185     {
0186         enum
0187         {
0188             value = false
0189         };
0190         typedef mpl::false_ type;
0191     };
0192     template <> struct is_random_access< vecS >
0193     {
0194         enum
0195         {
0196             value = true
0197         };
0198         typedef mpl::true_ type;
0199     };
0200 
0201 } // namespace detail
0202 
0203 template < typename Selector > struct is_distributed_selector : mpl::false_
0204 {
0205 };
0206 
0207 //===========================================================================
0208 // The adjacency_list_traits class, which provides a way to access
0209 // some of the associated types of an adjacency_list type without
0210 // having to first create the adjacency_list type. This is useful
0211 // when trying to create interior vertex or edge properties who's
0212 // value type is a vertex or edge descriptor.
0213 
0214 template < class OutEdgeListS = vecS, class VertexListS = vecS,
0215     class DirectedS = directedS, class EdgeListS = listS >
0216 struct adjacency_list_traits
0217 {
0218     typedef
0219         typename detail::is_random_access< VertexListS >::type is_rand_access;
0220     typedef typename DirectedS::is_bidir_t is_bidir;
0221     typedef typename DirectedS::is_directed_t is_directed;
0222 
0223     typedef typename mpl::if_< is_bidir, bidirectional_tag,
0224         typename mpl::if_< is_directed, directed_tag,
0225             undirected_tag >::type >::type directed_category;
0226 
0227     typedef typename parallel_edge_traits< OutEdgeListS >::type
0228         edge_parallel_category;
0229 
0230     typedef std::size_t vertices_size_type;
0231     typedef void* vertex_ptr;
0232     typedef typename mpl::if_< is_rand_access, vertices_size_type,
0233         vertex_ptr >::type vertex_descriptor;
0234     typedef detail::edge_desc_impl< directed_category, vertex_descriptor >
0235         edge_descriptor;
0236 
0237 private:
0238     // Logic to figure out the edges_size_type
0239     struct dummy
0240     {
0241     };
0242     typedef typename container_gen< EdgeListS, dummy >::type EdgeContainer;
0243     typedef typename DirectedS::is_bidir_t BidirectionalT;
0244     typedef typename DirectedS::is_directed_t DirectedT;
0245     typedef typename mpl::and_< DirectedT,
0246         typename mpl::not_< BidirectionalT >::type >::type on_edge_storage;
0247 
0248 public:
0249     typedef typename mpl::if_< on_edge_storage, std::size_t,
0250         typename EdgeContainer::size_type >::type edges_size_type;
0251 };
0252 
0253 } // namespace boost
0254 
0255 #include <boost/graph/detail/adjacency_list.hpp>
0256 
0257 namespace boost
0258 {
0259 
0260 //===========================================================================
0261 // The adjacency_list class.
0262 //
0263 
0264 template < class OutEdgeListS = vecS, // a Sequence or an AssociativeContainer
0265     class VertexListS = vecS, // a Sequence or a RandomAccessContainer
0266     class DirectedS = directedS, class VertexProperty = no_property,
0267     class EdgeProperty = no_property, class GraphProperty = no_property,
0268     class EdgeListS = listS >
0269 class adjacency_list
0270 : public detail::adj_list_gen<
0271       adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty,
0272           EdgeProperty, GraphProperty, EdgeListS >,
0273       VertexListS, OutEdgeListS, DirectedS, VertexProperty, EdgeProperty,
0274       GraphProperty, EdgeListS >::type,
0275   // Support for named vertices
0276   public graph::maybe_named_graph<
0277       adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty,
0278           EdgeProperty, GraphProperty, EdgeListS >,
0279       typename adjacency_list_traits< OutEdgeListS, VertexListS, DirectedS,
0280           EdgeListS >::vertex_descriptor,
0281       VertexProperty >
0282 {
0283 public:
0284     typedef GraphProperty graph_property_type;
0285     typedef typename lookup_one_property< GraphProperty, graph_bundle_t >::type
0286         graph_bundled;
0287 
0288     typedef VertexProperty vertex_property_type;
0289     typedef
0290         typename lookup_one_property< VertexProperty, vertex_bundle_t >::type
0291             vertex_bundled;
0292 
0293     typedef EdgeProperty edge_property_type;
0294     typedef typename lookup_one_property< EdgeProperty, edge_bundle_t >::type
0295         edge_bundled;
0296 
0297 private:
0298     typedef adjacency_list self;
0299     typedef typename detail::adj_list_gen< self, VertexListS, OutEdgeListS,
0300         DirectedS, vertex_property_type, edge_property_type, GraphProperty,
0301         EdgeListS >::type Base;
0302 
0303 public:
0304     typedef typename Base::stored_vertex stored_vertex;
0305     typedef typename Base::vertices_size_type vertices_size_type;
0306     typedef typename Base::edges_size_type edges_size_type;
0307     typedef typename Base::degree_size_type degree_size_type;
0308     typedef typename Base::vertex_descriptor vertex_descriptor;
0309     typedef typename Base::edge_descriptor edge_descriptor;
0310     typedef OutEdgeListS out_edge_list_selector;
0311     typedef VertexListS vertex_list_selector;
0312     typedef DirectedS directed_selector;
0313     typedef EdgeListS edge_list_selector;
0314 
0315     adjacency_list(const GraphProperty& p = GraphProperty())
0316     : m_property(new graph_property_type(p))
0317     {
0318     }
0319 
0320     adjacency_list(const adjacency_list& x)
0321     : Base(x), m_property(new graph_property_type(*x.m_property))
0322     {
0323     }
0324 
0325     adjacency_list& operator=(const adjacency_list& x)
0326     {
0327         // TBD: probably should give the strong guarantee
0328         if (&x != this)
0329         {
0330             Base::operator=(x);
0331 
0332             // Copy/swap the ptr since we can't just assign it...
0333             property_ptr p(new graph_property_type(*x.m_property));
0334             m_property.swap(p);
0335         }
0336         return *this;
0337     }
0338 
0339     // Required by Mutable Graph
0340     adjacency_list(vertices_size_type num_vertices,
0341         const GraphProperty& p = GraphProperty())
0342     : Base(num_vertices), m_property(new graph_property_type(p))
0343     {
0344     }
0345 
0346     // Required by Iterator Constructible Graph
0347     template < class EdgeIterator >
0348     adjacency_list(EdgeIterator first, EdgeIterator last, vertices_size_type n,
0349         edges_size_type = 0, const GraphProperty& p = GraphProperty())
0350     : Base(n, first, last), m_property(new graph_property_type(p))
0351     {
0352     }
0353 
0354     template < class EdgeIterator, class EdgePropertyIterator >
0355     adjacency_list(EdgeIterator first, EdgeIterator last,
0356         EdgePropertyIterator ep_iter, vertices_size_type n, edges_size_type = 0,
0357         const GraphProperty& p = GraphProperty())
0358     : Base(n, first, last, ep_iter), m_property(new graph_property_type(p))
0359     {
0360     }
0361 
0362     void swap(adjacency_list& x)
0363     {
0364         // Is there a more efficient way to do this?
0365         adjacency_list tmp(x);
0366         x = *this;
0367         *this = tmp;
0368     }
0369 
0370     void clear()
0371     {
0372         this->clearing_graph();
0373         Base::clear();
0374     }
0375 
0376 #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES
0377     // Directly access a vertex or edge bundle
0378     vertex_bundled& operator[](vertex_descriptor v)
0379     {
0380         return get(vertex_bundle, *this)[v];
0381     }
0382 
0383     const vertex_bundled& operator[](vertex_descriptor v) const
0384     {
0385         return get(vertex_bundle, *this)[v];
0386     }
0387 
0388     edge_bundled& operator[](edge_descriptor e)
0389     {
0390         return get(edge_bundle, *this)[e];
0391     }
0392 
0393     const edge_bundled& operator[](edge_descriptor e) const
0394     {
0395         return get(edge_bundle, *this)[e];
0396     }
0397 
0398     graph_bundled& operator[](graph_bundle_t) { return get_property(*this); }
0399 
0400     graph_bundled const& operator[](graph_bundle_t) const
0401     {
0402         return get_property(*this);
0403     }
0404 #endif
0405 
0406     //  protected:  (would be protected if friends were more portable)
0407     typedef scoped_ptr< graph_property_type > property_ptr;
0408     property_ptr m_property;
0409 };
0410 
0411 #define ADJLIST_PARAMS                                               \
0412     typename OEL, typename VL, typename D, typename VP, typename EP, \
0413         typename GP, typename EL
0414 #define ADJLIST adjacency_list< OEL, VL, D, VP, EP, GP, EL >
0415 
0416 template < ADJLIST_PARAMS, typename Tag, typename Value >
0417 inline void set_property(ADJLIST& g, Tag tag, Value const& value)
0418 {
0419     get_property_value(*g.m_property, tag) = value;
0420 }
0421 
0422 template < ADJLIST_PARAMS, typename Tag >
0423 inline typename graph_property< ADJLIST, Tag >::type& get_property(
0424     ADJLIST& g, Tag tag)
0425 {
0426     return get_property_value(*g.m_property, tag);
0427 }
0428 
0429 template < ADJLIST_PARAMS, typename Tag >
0430 inline typename graph_property< ADJLIST, Tag >::type const& get_property(
0431     ADJLIST const& g, Tag tag)
0432 {
0433     return get_property_value(*g.m_property, tag);
0434 }
0435 
0436 // dwa 09/25/00 - needed to be more explicit so reverse_graph would work.
0437 template < class Directed, class Vertex, class OutEdgeListS, class VertexListS,
0438     class DirectedS, class VertexProperty, class EdgeProperty,
0439     class GraphProperty, class EdgeListS >
0440 inline Vertex source(const detail::edge_base< Directed, Vertex >& e,
0441     const adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty,
0442         EdgeProperty, GraphProperty, EdgeListS >&)
0443 {
0444     return e.m_source;
0445 }
0446 
0447 template < class Directed, class Vertex, class OutEdgeListS, class VertexListS,
0448     class DirectedS, class VertexProperty, class EdgeProperty,
0449     class GraphProperty, class EdgeListS >
0450 inline Vertex target(const detail::edge_base< Directed, Vertex >& e,
0451     const adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty,
0452         EdgeProperty, GraphProperty, EdgeListS >&)
0453 {
0454     return e.m_target;
0455 }
0456 
0457 // Mutability Traits
0458 template < ADJLIST_PARAMS > struct graph_mutability_traits< ADJLIST >
0459 {
0460     typedef mutable_property_graph_tag category;
0461 };
0462 
0463 // Can't remove vertices from adjacency lists with VL==vecS
0464 template < typename OEL, typename D, typename VP, typename EP, typename GP,
0465     typename EL >
0466 struct graph_mutability_traits< adjacency_list< OEL, vecS, D, VP, EP, GP, EL > >
0467 {
0468     typedef add_only_property_graph_tag category;
0469 };
0470 #undef ADJLIST_PARAMS
0471 #undef ADJLIST
0472 
0473 } // namespace boost
0474 
0475 #endif // BOOST_GRAPH_ADJACENCY_LIST_HPP