1 //=======================================================================
2 // Copyright 2002 Indiana University.
3 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //=======================================================================
10 #ifndef BOOST_GRAPH_ARCHETYPES_HPP
11 #define BOOST_GRAPH_ARCHETYPES_HPP
13 #include <boost/property_map/property_map.hpp>
14 #include <boost/concept_archetype.hpp>
15 #include <boost/graph/graph_traits.hpp>
16 #include <boost/graph/properties.hpp>
19 { // should use a different namespace for this
23 struct null_graph_archetype : public null_archetype<>
25 struct traversal_category
31 //===========================================================================
32 template < typename Vertex, typename Directed, typename ParallelCategory,
33 typename Base = detail::null_graph_archetype >
34 struct incidence_graph_archetype : public Base
36 typedef typename Base::traversal_category base_trav_cat;
37 struct traversal_category : public incidence_graph_tag, public base_trav_cat
41 typedef immutable_graph_tag mutability_category;
43 typedef Vertex vertex_descriptor;
44 typedef unsigned int degree_size_type;
45 typedef unsigned int vertices_size_type;
46 typedef unsigned int edges_size_type;
47 struct edge_descriptor
50 edge_descriptor(const detail::dummy_constructor&) {}
51 bool operator==(const edge_descriptor&) const { return false; }
52 bool operator!=(const edge_descriptor&) const { return false; }
54 typedef input_iterator_archetype< edge_descriptor > out_edge_iterator;
56 typedef Directed directed_category;
57 typedef ParallelCategory edge_parallel_category;
59 typedef void adjacency_iterator;
60 typedef void in_edge_iterator;
61 typedef void vertex_iterator;
62 typedef void edge_iterator;
64 static vertex_descriptor null_vertex() { return vertex_descriptor(); }
66 template < typename V, typename D, typename P, typename B >
68 const typename incidence_graph_archetype< V, D, P, B >::edge_descriptor&,
69 const incidence_graph_archetype< V, D, P, B >&)
71 return V(static_object< detail::dummy_constructor >::get());
73 template < typename V, typename D, typename P, typename B >
75 const typename incidence_graph_archetype< V, D, P, B >::edge_descriptor&,
76 const incidence_graph_archetype< V, D, P, B >&)
78 return V(static_object< detail::dummy_constructor >::get());
81 template < typename V, typename D, typename P, typename B >
82 std::pair< typename incidence_graph_archetype< V, D, P, B >::out_edge_iterator,
83 typename incidence_graph_archetype< V, D, P, B >::out_edge_iterator >
84 out_edges(const V&, const incidence_graph_archetype< V, D, P, B >&)
86 typedef typename incidence_graph_archetype< V, D, P, B >::out_edge_iterator
88 return std::make_pair(Iter(), Iter());
91 template < typename V, typename D, typename P, typename B >
92 typename incidence_graph_archetype< V, D, P, B >::degree_size_type out_degree(
93 const V&, const incidence_graph_archetype< V, D, P, B >&)
98 //===========================================================================
99 template < typename Vertex, typename Directed, typename ParallelCategory,
100 typename Base = detail::null_graph_archetype >
101 struct adjacency_graph_archetype : public Base
103 typedef typename Base::traversal_category base_trav_cat;
104 struct traversal_category : public adjacency_graph_tag, public base_trav_cat
107 typedef Vertex vertex_descriptor;
108 typedef unsigned int degree_size_type;
109 typedef unsigned int vertices_size_type;
110 typedef unsigned int edges_size_type;
111 typedef void edge_descriptor;
112 typedef input_iterator_archetype< Vertex > adjacency_iterator;
114 typedef Directed directed_category;
115 typedef ParallelCategory edge_parallel_category;
117 typedef void in_edge_iterator;
118 typedef void out_edge_iterator;
119 typedef void vertex_iterator;
120 typedef void edge_iterator;
122 static vertex_descriptor null_vertex() { return vertex_descriptor(); }
125 template < typename V, typename D, typename P, typename B >
126 std::pair< typename adjacency_graph_archetype< V, D, P, B >::adjacency_iterator,
127 typename adjacency_graph_archetype< V, D, P, B >::adjacency_iterator >
128 adjacent_vertices(const V&, const adjacency_graph_archetype< V, D, P, B >&)
130 typedef typename adjacency_graph_archetype< V, D, P, B >::adjacency_iterator
132 return std::make_pair(Iter(), Iter());
135 template < typename V, typename D, typename P, typename B >
136 typename adjacency_graph_archetype< V, D, P, B >::degree_size_type out_degree(
137 const V&, const adjacency_graph_archetype< V, D, P, B >&)
142 //===========================================================================
143 template < typename Vertex, typename Directed, typename ParallelCategory,
144 typename Base = detail::null_graph_archetype >
145 struct vertex_list_graph_archetype : public Base
147 typedef incidence_graph_archetype< Vertex, Directed, ParallelCategory >
149 typedef adjacency_graph_archetype< Vertex, Directed, ParallelCategory >
152 typedef typename Base::traversal_category base_trav_cat;
153 struct traversal_category : public vertex_list_graph_tag,
158 typedef immutable_graph_tag mutability_category;
160 typedef Vertex vertex_descriptor;
161 typedef unsigned int degree_size_type;
162 typedef typename Incidence::edge_descriptor edge_descriptor;
163 typedef typename Incidence::out_edge_iterator out_edge_iterator;
164 typedef typename Adjacency::adjacency_iterator adjacency_iterator;
166 typedef input_iterator_archetype< Vertex > vertex_iterator;
167 typedef unsigned int vertices_size_type;
168 typedef unsigned int edges_size_type;
170 typedef Directed directed_category;
171 typedef ParallelCategory edge_parallel_category;
173 typedef void in_edge_iterator;
174 typedef void edge_iterator;
176 static vertex_descriptor null_vertex() { return vertex_descriptor(); }
179 template < typename V, typename D, typename P, typename B >
180 std::pair< typename vertex_list_graph_archetype< V, D, P, B >::vertex_iterator,
181 typename vertex_list_graph_archetype< V, D, P, B >::vertex_iterator >
182 vertices(const vertex_list_graph_archetype< V, D, P, B >&)
184 typedef typename vertex_list_graph_archetype< V, D, P, B >::vertex_iterator
186 return std::make_pair(Iter(), Iter());
189 template < typename V, typename D, typename P, typename B >
190 typename vertex_list_graph_archetype< V, D, P, B >::vertices_size_type
191 num_vertices(const vertex_list_graph_archetype< V, D, P, B >&)
196 // ambiguously inherited from incidence graph and adjacency graph
197 template < typename V, typename D, typename P, typename B >
198 typename vertex_list_graph_archetype< V, D, P, B >::degree_size_type out_degree(
199 const V&, const vertex_list_graph_archetype< V, D, P, B >&)
204 //===========================================================================
206 struct property_graph_archetype_tag
210 template < typename GraphArchetype, typename Property, typename ValueArch >
211 struct property_graph_archetype : public GraphArchetype
213 typedef property_graph_archetype_tag graph_tag;
214 typedef ValueArch vertex_property_type;
215 typedef ValueArch edge_property_type;
218 struct choose_edge_property_map_archetype
220 template < typename Graph, typename Property, typename Tag > struct bind_
222 typedef mutable_lvalue_property_map_archetype<
223 typename Graph::edge_descriptor, Property >
225 typedef lvalue_property_map_archetype< typename Graph::edge_descriptor,
230 template <> struct edge_property_selector< property_graph_archetype_tag >
232 typedef choose_edge_property_map_archetype type;
235 struct choose_vertex_property_map_archetype
237 template < typename Graph, typename Property, typename Tag > struct bind_
239 typedef mutable_lvalue_property_map_archetype<
240 typename Graph::vertex_descriptor, Property >
242 typedef lvalue_property_map_archetype<
243 typename Graph::vertex_descriptor, Property >
248 template <> struct vertex_property_selector< property_graph_archetype_tag >
250 typedef choose_vertex_property_map_archetype type;
253 template < typename G, typename P, typename V >
254 typename property_map< property_graph_archetype< G, P, V >, P >::type get(
255 P, property_graph_archetype< G, P, V >&)
257 typename property_map< property_graph_archetype< G, P, V >, P >::type pmap;
261 template < typename G, typename P, typename V >
262 typename property_map< property_graph_archetype< G, P, V >, P >::const_type get(
263 P, const property_graph_archetype< G, P, V >&)
265 typename property_map< property_graph_archetype< G, P, V >, P >::const_type
270 template < typename G, typename P, typename K, typename V >
271 typename property_traits< typename property_map<
272 property_graph_archetype< G, P, V >, P >::const_type >::value_type
273 get(P p, const property_graph_archetype< G, P, V >& g, K k)
275 return get(get(p, g), k);
278 template < typename G, typename P, typename V, typename Key >
280 P p, property_graph_archetype< G, P, V >& g, const Key& key, const V& value)
282 typedef typename boost::property_map< property_graph_archetype< G, P, V >,
284 Map pmap = get(p, g);
285 put(pmap, key, value);
288 struct color_value_archetype
290 color_value_archetype() {}
291 color_value_archetype(detail::dummy_constructor) {}
292 bool operator==(const color_value_archetype&) const { return true; }
293 bool operator!=(const color_value_archetype&) const { return true; }
295 template <> struct color_traits< color_value_archetype >
297 static color_value_archetype white()
299 return color_value_archetype(
300 static_object< detail::dummy_constructor >::get());
302 static color_value_archetype gray()
304 return color_value_archetype(
305 static_object< detail::dummy_constructor >::get());
307 static color_value_archetype black()
309 return color_value_archetype(
310 static_object< detail::dummy_constructor >::get());
314 template < typename T > class buffer_archetype
317 void push(const T&) {}
319 T& top() { return static_object< T >::get(); }
320 const T& top() const { return static_object< T >::get(); }
321 bool empty() const { return true; }
326 #endif // BOOST_GRAPH_ARCHETYPES_HPP