2002-05-21 23:39:58 +00:00
|
|
|
|
// (C) Copyright Jeremy Siek, 2001. Permission to copy, use, modify,
|
|
|
|
|
// sell and distribute this software is granted provided this
|
|
|
|
|
// copyright notice appears in all copies. This software is provided
|
|
|
|
|
// "as is" without express or implied warranty, and with no claim as
|
|
|
|
|
// to its suitability for any purpose.
|
|
|
|
|
|
2003-03-03 15:53:48 +00:00
|
|
|
|
// See http://www.boost.org/libs/property_map for documentation.
|
|
|
|
|
|
2002-05-21 23:39:58 +00:00
|
|
|
|
#ifndef BOOST_PROPERTY_MAP_ITERATOR_HPP
|
|
|
|
|
#define BOOST_PROPERTY_MAP_ITERATOR_HPP
|
|
|
|
|
|
|
|
|
|
#include <boost/property_map.hpp>
|
2004-02-05 09:14:22 +00:00
|
|
|
|
#include <boost/iterator/iterator_adaptor.hpp>
|
|
|
|
|
#include <boost/mpl/if.hpp>
|
|
|
|
|
#include <boost/type_traits/is_same.hpp>
|
2002-05-21 23:39:58 +00:00
|
|
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
|
|
|
|
|
|
//======================================================================
|
|
|
|
|
// property iterator, generalized from ideas by Fran<61>ois Faure
|
|
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
|
2004-02-05 09:14:22 +00:00
|
|
|
|
template <class Iterator, class LvaluePropertyMap>
|
|
|
|
|
class lvalue_pmap_iter
|
|
|
|
|
: public iterator_adaptor< lvalue_pmap_iter< Iterator, LvaluePropertyMap >,
|
|
|
|
|
Iterator,
|
|
|
|
|
typename property_traits<LvaluePropertyMap>::value_type,
|
|
|
|
|
use_default,
|
|
|
|
|
typename property_traits<LvaluePropertyMap>::reference>
|
2002-05-21 23:39:58 +00:00
|
|
|
|
{
|
2004-02-05 09:14:22 +00:00
|
|
|
|
friend class boost::iterator_core_access;
|
2002-05-21 23:39:58 +00:00
|
|
|
|
|
2004-02-05 09:14:22 +00:00
|
|
|
|
typedef iterator_adaptor< lvalue_pmap_iter< Iterator, LvaluePropertyMap >,
|
|
|
|
|
Iterator,
|
|
|
|
|
typename property_traits<LvaluePropertyMap>::value_type,
|
|
|
|
|
use_default,
|
|
|
|
|
typename property_traits<LvaluePropertyMap>::reference> super_t;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
lvalue_pmap_iter() { }
|
|
|
|
|
lvalue_pmap_iter(Iterator const& it,
|
|
|
|
|
LvaluePropertyMap m)
|
|
|
|
|
: super_t(it),
|
|
|
|
|
m_map(m) {}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
typename lvalue_pmap_iter::reference
|
|
|
|
|
dereference() const
|
2002-05-21 23:39:58 +00:00
|
|
|
|
{
|
2004-02-05 09:14:22 +00:00
|
|
|
|
return m_map[*(this->base_reference())];
|
2002-05-21 23:39:58 +00:00
|
|
|
|
}
|
2004-02-05 09:14:22 +00:00
|
|
|
|
|
2002-05-21 23:39:58 +00:00
|
|
|
|
LvaluePropertyMap m_map;
|
|
|
|
|
};
|
|
|
|
|
|
2004-02-05 09:14:22 +00:00
|
|
|
|
template <class Iterator, class ReadablePropertyMap>
|
|
|
|
|
class readable_pmap_iter :
|
|
|
|
|
public iterator_adaptor< readable_pmap_iter< Iterator, ReadablePropertyMap >,
|
|
|
|
|
Iterator,
|
|
|
|
|
typename property_traits<ReadablePropertyMap>::value_type,
|
|
|
|
|
use_default,
|
|
|
|
|
typename property_traits<ReadablePropertyMap>::value_type>
|
|
|
|
|
|
|
|
|
|
|
2002-05-21 23:39:58 +00:00
|
|
|
|
{
|
2004-02-05 09:14:22 +00:00
|
|
|
|
friend class iterator_core_access;
|
2002-05-21 23:39:58 +00:00
|
|
|
|
|
2004-02-05 09:14:22 +00:00
|
|
|
|
typedef iterator_adaptor< readable_pmap_iter< Iterator, ReadablePropertyMap >,
|
|
|
|
|
Iterator,
|
|
|
|
|
typename property_traits<ReadablePropertyMap>::value_type,
|
|
|
|
|
use_default,
|
|
|
|
|
typename property_traits<ReadablePropertyMap>::value_type> super_t;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
readable_pmap_iter() { }
|
|
|
|
|
readable_pmap_iter(Iterator const& it,
|
|
|
|
|
ReadablePropertyMap m)
|
|
|
|
|
: super_t(it),
|
|
|
|
|
m_map(m) {}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
typename readable_pmap_iter::reference
|
|
|
|
|
dereference() const
|
2002-05-21 23:39:58 +00:00
|
|
|
|
{
|
2004-02-05 09:14:22 +00:00
|
|
|
|
return get(m_map, *(this->base_reference()));
|
2002-05-21 23:39:58 +00:00
|
|
|
|
}
|
2004-02-05 09:14:22 +00:00
|
|
|
|
|
2002-05-21 23:39:58 +00:00
|
|
|
|
ReadablePropertyMap m_map;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
|
|
template <class PropertyMap, class Iterator>
|
2004-02-05 09:14:22 +00:00
|
|
|
|
struct property_map_iterator_generator :
|
|
|
|
|
mpl::if_< is_same< typename property_traits<PropertyMap>::category, lvalue_property_map_tag>,
|
|
|
|
|
detail::lvalue_pmap_iter<Iterator, PropertyMap>,
|
|
|
|
|
detail::readable_pmap_iter<Iterator, PropertyMap> >
|
|
|
|
|
{};
|
2002-05-21 23:39:58 +00:00
|
|
|
|
|
|
|
|
|
template <class PropertyMap, class Iterator>
|
|
|
|
|
typename property_map_iterator_generator<PropertyMap, Iterator>::type
|
|
|
|
|
make_property_map_iterator(PropertyMap pmap, Iterator iter)
|
|
|
|
|
{
|
|
|
|
|
typedef typename property_map_iterator_generator<PropertyMap,
|
|
|
|
|
Iterator>::type Iter;
|
|
|
|
|
return Iter(iter, pmap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace boost
|
|
|
|
|
|
|
|
|
|
#endif // BOOST_PROPERTY_MAP_ITERATOR_HPP
|
|
|
|
|
|