DGtal  0.9.2
ConstIteratorAdapter.h
1 
17 #pragma once
18 
31 #if defined(ConstIteratorAdapter_RECURSES)
32 #error Recursive header files inclusion detected in ConstIteratorAdapter.h
33 #else // defined(ConstIteratorAdapter_RECURSES)
34 
35 #define ConstIteratorAdapter_RECURSES
36 
37 #if !defined ConstIteratorAdapter_h
38 
39 #define ConstIteratorAdapter_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/IteratorCirculatorTraits.h"
46 #include <boost/iterator/iterator_adaptor.hpp>
47 #include <boost/utility.hpp>
49 
50 namespace DGtal
51 {
52 
54  // template class ConstIteratorAdapter
78  template <typename TIterator, typename TLightFunctor, typename TReturnType = typename TLightFunctor::Value >
80  : public boost::iterator_adaptor< ConstIteratorAdapter<TIterator,TLightFunctor,TReturnType>,
81  TIterator, TReturnType, boost::use_default, TReturnType >
82  {
83  typedef typename
84  boost::iterator_adaptor< ConstIteratorAdapter<TIterator,TLightFunctor,TReturnType>,
85  TIterator, TReturnType, boost::use_default, TReturnType >
87 
89 
90  public:
91 
93 
94 
99 
106  ConstIteratorAdapter(TIterator const& i, TLightFunctor f)
107  : Super(i), myF(f) { }
108 
114  template <
115  class OtherFunctor
116  , class OtherIterator
117  , class OtherReturnType>
120  )
121  : Super(other.base()), myF(other.functor())
122  {}
123 
129  TLightFunctor functor() const
130  { return myF; }
131 
132  private:
133 
140  typename Super::reference dereference() const
141  { return myF(*this->base()); }
142 
144  TLightFunctor myF;
145  };
146 
147 
148 } // namespace DGtal
149 
150 
152 // Includes inline functions.
153 //#include "DGtal/base/ConstIteratorAdapter.ih"
154 
155 // //
157 
158 #endif // !defined ConstIteratorAdapter_h
159 
160 #undef ConstIteratorAdapter_RECURSES
161 #endif // else defined(ConstIteratorAdapter_RECURSES)
This class adapts any iterator so that operator* returns another element than the one pointed to by t...
friend class boost::iterator_core_access
ConstIteratorAdapter(ConstIteratorAdapter< OtherFunctor, OtherIterator, OtherReturnType > const &other)
ConstIteratorAdapter(TIterator const &i, TLightFunctor f)
TLightFunctor functor() const
IteratorCirculatorTraits< TIterator >::Type Type
DGtal is the top-level namespace which contains all DGtal functions and types.
Super::reference dereference() const
boost::iterator_adaptor< ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >, TIterator, TReturnType, boost::use_default, TReturnType > Super