1 | // (C) Copyright Jeremy Siek, 2001.
|
---|
2 | // Distributed under the Boost Software License, Version 1.0. (See
|
---|
3 | // accompanying file LICENSE_1_0.txt or copy at
|
---|
4 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
5 |
|
---|
6 | // See http://www.boost.org/libs/property_map for documentation.
|
---|
7 |
|
---|
8 | #ifndef BOOST_PROPERTY_MAP_ITERATOR_HPP
|
---|
9 | #define BOOST_PROPERTY_MAP_ITERATOR_HPP
|
---|
10 |
|
---|
11 | #include <boost/property_map.hpp>
|
---|
12 | #include <boost/iterator/iterator_adaptor.hpp>
|
---|
13 | #include <boost/mpl/if.hpp>
|
---|
14 | #include <boost/type_traits/is_same.hpp>
|
---|
15 |
|
---|
16 | namespace boost {
|
---|
17 |
|
---|
18 | //======================================================================
|
---|
19 | // property iterator, generalized from ideas by François Faure
|
---|
20 |
|
---|
21 | namespace detail {
|
---|
22 |
|
---|
23 | template <class Iterator, class LvaluePropertyMap>
|
---|
24 | class lvalue_pmap_iter
|
---|
25 | : public iterator_adaptor< lvalue_pmap_iter< Iterator, LvaluePropertyMap >,
|
---|
26 | Iterator,
|
---|
27 | typename property_traits<LvaluePropertyMap>::value_type,
|
---|
28 | use_default,
|
---|
29 | typename property_traits<LvaluePropertyMap>::reference>
|
---|
30 | {
|
---|
31 | friend class boost::iterator_core_access;
|
---|
32 |
|
---|
33 | typedef iterator_adaptor< lvalue_pmap_iter< Iterator, LvaluePropertyMap >,
|
---|
34 | Iterator,
|
---|
35 | typename property_traits<LvaluePropertyMap>::value_type,
|
---|
36 | use_default,
|
---|
37 | typename property_traits<LvaluePropertyMap>::reference> super_t;
|
---|
38 |
|
---|
39 | public:
|
---|
40 | lvalue_pmap_iter() { }
|
---|
41 | lvalue_pmap_iter(Iterator const& it,
|
---|
42 | LvaluePropertyMap m)
|
---|
43 | : super_t(it),
|
---|
44 | m_map(m) {}
|
---|
45 |
|
---|
46 | private:
|
---|
47 | typename super_t::reference
|
---|
48 | dereference() const
|
---|
49 | {
|
---|
50 | return m_map[*(this->base_reference())];
|
---|
51 | }
|
---|
52 |
|
---|
53 | LvaluePropertyMap m_map;
|
---|
54 | };
|
---|
55 |
|
---|
56 | template <class Iterator, class ReadablePropertyMap>
|
---|
57 | class readable_pmap_iter :
|
---|
58 | public iterator_adaptor< readable_pmap_iter< Iterator, ReadablePropertyMap >,
|
---|
59 | Iterator,
|
---|
60 | typename property_traits<ReadablePropertyMap>::value_type,
|
---|
61 | use_default,
|
---|
62 | typename property_traits<ReadablePropertyMap>::value_type>
|
---|
63 |
|
---|
64 |
|
---|
65 | {
|
---|
66 | friend class iterator_core_access;
|
---|
67 |
|
---|
68 | typedef iterator_adaptor< readable_pmap_iter< Iterator, ReadablePropertyMap >,
|
---|
69 | Iterator,
|
---|
70 | typename property_traits<ReadablePropertyMap>::value_type,
|
---|
71 | use_default,
|
---|
72 | typename property_traits<ReadablePropertyMap>::value_type> super_t;
|
---|
73 |
|
---|
74 | public:
|
---|
75 | readable_pmap_iter() { }
|
---|
76 | readable_pmap_iter(Iterator const& it,
|
---|
77 | ReadablePropertyMap m)
|
---|
78 | : super_t(it),
|
---|
79 | m_map(m) {}
|
---|
80 |
|
---|
81 | private:
|
---|
82 | typename super_t::reference
|
---|
83 | dereference() const
|
---|
84 | {
|
---|
85 | return get(m_map, *(this->base_reference()));
|
---|
86 | }
|
---|
87 |
|
---|
88 | ReadablePropertyMap m_map;
|
---|
89 | };
|
---|
90 |
|
---|
91 |
|
---|
92 | } // namespace detail
|
---|
93 |
|
---|
94 | template <class PropertyMap, class Iterator>
|
---|
95 | struct property_map_iterator_generator :
|
---|
96 | mpl::if_< is_same< typename property_traits<PropertyMap>::category, lvalue_property_map_tag>,
|
---|
97 | detail::lvalue_pmap_iter<Iterator, PropertyMap>,
|
---|
98 | detail::readable_pmap_iter<Iterator, PropertyMap> >
|
---|
99 | {};
|
---|
100 |
|
---|
101 | template <class PropertyMap, class Iterator>
|
---|
102 | typename property_map_iterator_generator<PropertyMap, Iterator>::type
|
---|
103 | make_property_map_iterator(PropertyMap pmap, Iterator iter)
|
---|
104 | {
|
---|
105 | typedef typename property_map_iterator_generator<PropertyMap,
|
---|
106 | Iterator>::type Iter;
|
---|
107 | return Iter(iter, pmap);
|
---|
108 | }
|
---|
109 |
|
---|
110 | } // namespace boost
|
---|
111 |
|
---|
112 | #endif // BOOST_PROPERTY_MAP_ITERATOR_HPP
|
---|
113 |
|
---|