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)
6 // See http://www.boost.org/libs/property_map for documentation.
8 #ifndef BOOST_PROPERTY_MAP_ITERATOR_HPP
9 #define BOOST_PROPERTY_MAP_ITERATOR_HPP
11 #include <boost/property_map/property_map.hpp>
12 #include <boost/iterator/iterator_adaptor.hpp>
13 #include <boost/mpl/if.hpp>
14 #include <boost/type_traits/is_same.hpp>
18 //======================================================================
19 // property iterator, generalized from ideas by Francois Faure
23 template <class Iterator
, class LvaluePropertyMap
>
24 class lvalue_pmap_iter
25 : public iterator_adaptor
< lvalue_pmap_iter
< Iterator
, LvaluePropertyMap
>,
27 typename property_traits
<LvaluePropertyMap
>::value_type
,
29 typename property_traits
<LvaluePropertyMap
>::reference
>
31 friend class boost::iterator_core_access
;
33 typedef iterator_adaptor
< lvalue_pmap_iter
< Iterator
, LvaluePropertyMap
>,
35 typename property_traits
<LvaluePropertyMap
>::value_type
,
37 typename property_traits
<LvaluePropertyMap
>::reference
> super_t
;
40 lvalue_pmap_iter() { }
41 lvalue_pmap_iter(Iterator
const& it
,
47 typename
super_t::reference
50 return m_map
[*(this->base_reference())];
53 LvaluePropertyMap m_map
;
56 template <class Iterator
, class ReadablePropertyMap
>
57 class readable_pmap_iter
:
58 public iterator_adaptor
< readable_pmap_iter
< Iterator
, ReadablePropertyMap
>,
60 typename property_traits
<ReadablePropertyMap
>::value_type
,
62 typename property_traits
<ReadablePropertyMap
>::value_type
>
66 friend class boost::iterator_core_access
;
68 typedef iterator_adaptor
< readable_pmap_iter
< Iterator
, ReadablePropertyMap
>,
70 typename property_traits
<ReadablePropertyMap
>::value_type
,
72 typename property_traits
<ReadablePropertyMap
>::value_type
> super_t
;
75 readable_pmap_iter() { }
76 readable_pmap_iter(Iterator
const& it
,
77 ReadablePropertyMap m
)
82 typename
super_t::reference
85 return get(m_map
, *(this->base_reference()));
88 ReadablePropertyMap m_map
;
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
> >
101 template <class PropertyMap
, class Iterator
>
102 typename property_map_iterator_generator
<PropertyMap
, Iterator
>::type
103 make_property_map_iterator(PropertyMap pmap
, Iterator iter
)
105 typedef typename property_map_iterator_generator
<PropertyMap
,
106 Iterator
>::type Iter
;
107 return Iter(iter
, pmap
);
112 #endif // BOOST_PROPERTY_MAP_ITERATOR_HPP