Chris@16
|
1 // (C) Copyright 2007-2009 Andrew Sutton
|
Chris@16
|
2 //
|
Chris@16
|
3 // Use, modification and distribution are subject to the
|
Chris@16
|
4 // Boost Software License, Version 1.0 (See accompanying file
|
Chris@16
|
5 // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 #ifndef BOOST_GRAPH_DETAIL_INDEX_HPP
|
Chris@16
|
8 #define BOOST_GRAPH_DETAIL_INDEX_HPP
|
Chris@16
|
9
|
Chris@16
|
10 #include <boost/graph/graph_traits.hpp>
|
Chris@16
|
11
|
Chris@16
|
12 // The structures in this module are responsible for selecting and defining
|
Chris@16
|
13 // types for accessing a builting index map. Note that the selection of these
|
Chris@16
|
14 // types requires the Graph parameter to model either VertexIndexGraph or
|
Chris@16
|
15 // EdgeIndexGraph.
|
Chris@16
|
16
|
Chris@16
|
17 namespace boost
|
Chris@16
|
18 {
|
Chris@16
|
19 namespace detail
|
Chris@16
|
20 {
|
Chris@16
|
21 template <typename Graph>
|
Chris@16
|
22 struct vertex_indexer
|
Chris@16
|
23 {
|
Chris@16
|
24 typedef vertex_index_t index_type;
|
Chris@16
|
25 typedef typename property_map<Graph, vertex_index_t>::type map_type;
|
Chris@16
|
26 typedef typename property_map<Graph, vertex_index_t>::const_type const_map_type;
|
Chris@16
|
27 typedef typename property_traits<map_type>::value_type value_type;
|
Chris@16
|
28 typedef typename graph_traits<Graph>::vertex_descriptor key_type;
|
Chris@16
|
29
|
Chris@16
|
30 static const_map_type index_map(const Graph& g)
|
Chris@16
|
31 { return get(vertex_index, g); }
|
Chris@16
|
32
|
Chris@16
|
33 static map_type index_map(Graph& g)
|
Chris@16
|
34 { return get(vertex_index, g); }
|
Chris@16
|
35
|
Chris@16
|
36 static value_type index(key_type k, const Graph& g)
|
Chris@16
|
37 { return get(vertex_index, g, k); }
|
Chris@16
|
38 };
|
Chris@16
|
39
|
Chris@16
|
40 template <typename Graph>
|
Chris@16
|
41 struct edge_indexer
|
Chris@16
|
42 {
|
Chris@16
|
43 typedef edge_index_t index_type;
|
Chris@16
|
44 typedef typename property_map<Graph, edge_index_t>::type map_type;
|
Chris@16
|
45 typedef typename property_map<Graph, edge_index_t>::const_type const_map_type;
|
Chris@16
|
46 typedef typename property_traits<map_type>::value_type value_type;
|
Chris@16
|
47 typedef typename graph_traits<Graph>::edge_descriptor key_type;
|
Chris@16
|
48
|
Chris@16
|
49 static const_map_type index_map(const Graph& g)
|
Chris@16
|
50 { return get(edge_index, g); }
|
Chris@16
|
51
|
Chris@16
|
52 static map_type index_map(Graph& g)
|
Chris@16
|
53 { return get(edge_index, g); }
|
Chris@16
|
54
|
Chris@16
|
55 static value_type index(key_type k, const Graph& g)
|
Chris@16
|
56 { return get(edge_index, g, k); }
|
Chris@16
|
57 };
|
Chris@16
|
58
|
Chris@16
|
59 // NOTE: The Graph parameter MUST be a model of VertexIndexGraph or
|
Chris@16
|
60 // VertexEdgeGraph - whichever type Key is selecting.
|
Chris@16
|
61 template <typename Graph, typename Key>
|
Chris@16
|
62 struct choose_indexer
|
Chris@16
|
63 {
|
Chris@16
|
64 typedef typename mpl::if_<
|
Chris@16
|
65 is_same<Key, typename graph_traits<Graph>::vertex_descriptor>,
|
Chris@16
|
66 vertex_indexer<Graph>,
|
Chris@16
|
67 edge_indexer<Graph>
|
Chris@16
|
68 >::type indexer_type;
|
Chris@16
|
69 typedef typename indexer_type::index_type index_type;
|
Chris@16
|
70 };
|
Chris@16
|
71 }
|
Chris@16
|
72 }
|
Chris@16
|
73
|
Chris@16
|
74 #endif
|