]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // (C) Copyright 2007-2009 Andrew Sutton |
2 | // | |
3 | // Use, modification and distribution are subject to the | |
4 | // Boost Software License, Version 1.0 (See accompanying file | |
5 | // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #ifndef BOOST_GRAPH_CONTAINER_PROPERTY_MAP_HPP | |
8 | #define BOOST_GRAPH_CONTAINER_PROPERTY_MAP_HPP | |
9 | ||
10 | #include <boost/graph/detail/index.hpp> | |
11 | #include <boost/property_map/property_map.hpp> | |
12 | ||
13 | namespace boost | |
14 | { | |
15 | // This is an adapter built over the iterator property map with | |
16 | // more useful uniform construction semantics. Specifically, this | |
17 | // requires the container rather than the iterator and the graph | |
18 | // rather than the optional index map. | |
19 | template <typename Graph, typename Key, typename Container> | |
20 | struct container_property_map | |
21 | : public boost::put_get_helper< | |
22 | typename iterator_property_map< | |
23 | typename Container::iterator, | |
24 | typename property_map< | |
25 | Graph, | |
26 | typename detail::choose_indexer<Graph, Key>::index_type | |
27 | >::type | |
28 | >::reference, | |
29 | container_property_map<Graph, Key, Container> | |
30 | > | |
31 | { | |
32 | typedef typename detail::choose_indexer<Graph, Key>::indexer_type indexer_type; | |
33 | typedef typename indexer_type::index_type index_type; | |
34 | typedef iterator_property_map< | |
35 | typename Container::iterator, | |
36 | typename property_map<Graph, index_type>::type | |
37 | > map_type; | |
38 | typedef typename map_type::key_type key_type; | |
39 | typedef typename map_type::value_type value_type; | |
40 | typedef typename map_type::reference reference; | |
41 | typedef typename map_type::category category; | |
42 | ||
43 | // The default constructor will *probably* crash if its actually | |
44 | // used for referencing vertices since the underlying iterator | |
45 | // map points past the end of an unknown container. | |
46 | inline container_property_map() | |
47 | : m_map() | |
48 | { } | |
49 | ||
50 | // This is the preferred constructor. It is invoked over the container | |
51 | // and the graph explicitly. This requires that the underlying iterator | |
52 | // map use the indices of the vertices in g rather than the default | |
53 | // identity map. | |
54 | // | |
55 | // Note the const-cast this ensures the reference type of the | |
56 | // vertex index map is non-const, which happens to be an | |
57 | // artifact of passing const graph references. | |
58 | inline container_property_map(Container& c, const Graph& g) | |
59 | : m_map(c.begin(), indexer_type::index_map(const_cast<Graph&>(g))) | |
60 | { } | |
61 | ||
62 | // Typical copy constructor. | |
63 | inline container_property_map(const container_property_map& x) | |
64 | : m_map(x.m_map) | |
65 | { } | |
66 | ||
67 | // The [] operator delegates to the underlying map/ | |
68 | inline reference operator [](const key_type& k) const | |
69 | { return m_map[k]; } | |
70 | ||
71 | map_type m_map; | |
72 | }; | |
73 | } | |
74 | ||
75 | #endif |