DGtal  1.1.0
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
84  template <typename TIterator, typename TLightFunctor, typename TReturnType = typename TLightFunctor::Value >
86  : public boost::iterator_adaptor< ConstIteratorAdapter<TIterator,TLightFunctor,TReturnType>,
87  TIterator, TReturnType, boost::use_default, TReturnType >
88  {
89  typedef typename
90  boost::iterator_adaptor< ConstIteratorAdapter<TIterator,TLightFunctor,TReturnType>,
91  TIterator, TReturnType, boost::use_default, TReturnType >
93 
95 
96  public:
97 
99 
100 
105 
112  ConstIteratorAdapter(TIterator const& i, TLightFunctor f)
113  : Super(i), myF(f) { }
114 
120  template <
121  class OtherFunctor
122  , class OtherIterator
123  , class OtherReturnType>
126  )
127  : Super(other.base()), myF(other.functor())
128  {}
129 
135  TLightFunctor functor() const
136  { return myF; }
137 
138  private:
139 
146  typename Super::reference dereference() const
147  { return myF(*this->base()); }
148 
150  TLightFunctor myF;
151  };
152 
153 
154 } // namespace DGtal
155 
156 
158 // Includes inline functions.
159 //#include "DGtal/base/ConstIteratorAdapter.ih"
160 
161 // //
163 
164 #endif // !defined ConstIteratorAdapter_h
165 
166 #undef ConstIteratorAdapter_RECURSES
167 #endif // else defined(ConstIteratorAdapter_RECURSES)
DGtal::ConstIteratorAdapter::iterator_core_access
friend class boost::iterator_core_access
Definition: ConstIteratorAdapter.h:94
DGtal::ConstIteratorAdapter::ConstIteratorAdapter
ConstIteratorAdapter(ConstIteratorAdapter< OtherFunctor, OtherIterator, OtherReturnType > const &other)
Definition: ConstIteratorAdapter.h:124
DGtal::ConstIteratorAdapter::dereference
Super::reference dereference() const
Definition: ConstIteratorAdapter.h:146
DGtal::ConstIteratorAdapter::myF
TLightFunctor myF
Definition: ConstIteratorAdapter.h:150
DGtal::ConstIteratorAdapter::ConstIteratorAdapter
ConstIteratorAdapter(TIterator const &i, TLightFunctor f)
Definition: ConstIteratorAdapter.h:112
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::ConstIteratorAdapter::functor
TLightFunctor functor() const
Definition: ConstIteratorAdapter.h:135
DGtal::ConstIteratorAdapter::Type
IteratorCirculatorTraits< TIterator >::Type Type
Definition: ConstIteratorAdapter.h:98
DGtal::ConstIteratorAdapter::ConstIteratorAdapter
ConstIteratorAdapter()
Definition: ConstIteratorAdapter.h:104
DGtal::IteratorType
Definition: IteratorCirculatorTraits.h:51
DGtal::ConstIteratorAdapter::Super
boost::iterator_adaptor< ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >, TIterator, TReturnType, boost::use_default, TReturnType > Super
Definition: ConstIteratorAdapter.h:92
DGtal::ConstIteratorAdapter
This class adapts any iterator so that operator* returns another element than the one pointed to by t...
Definition: ConstIteratorAdapter.h:88