DGtal  1.5.beta
DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType > Class Template Reference

This class adapts any iterator so that operator* returns another element than the one pointed to by the iterator. More...

#include <DGtal/base/ConstIteratorAdapter.h>

Inheritance diagram for DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >:
[legend]

Public Types

typedef IteratorCirculatorTraits< TIterator >::Type Type
 

Public Member Functions

 ConstIteratorAdapter ()
 
 ConstIteratorAdapter (TIterator const &i, TLightFunctor f)
 
template<class OtherFunctor , class OtherIterator , class OtherReturnType >
 ConstIteratorAdapter (ConstIteratorAdapter< OtherFunctor, OtherIterator, OtherReturnType > const &other)
 
TLightFunctor functor () const
 

Private Types

typedef boost::iterator_adaptor< ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >, TIterator, TReturnType, boost::use_default, TReturnType > Super
 

Private Member Functions

Super::reference dereference () const
 

Private Attributes

TLightFunctor myF
 

Friends

class boost::iterator_core_access
 

Detailed Description

template<typename TIterator, typename TLightFunctor, typename TReturnType = typename TLightFunctor::Value>
class DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >

This class adapts any iterator so that operator* returns another element than the one pointed to by the iterator.

Description of template class 'ConstIteratorAdapter'

Template Parameters
TIteratorthe type of the iterator to adapt.

To achieve this goal, the adapter is based on a functor f given at construction so that operator* calls f(*it), instead of calling directly operator* of the underlying iterator it.

Note
This ConstIteratorAdapter does not satisfy the __is_forward_iterator concept of the STL. It can be a problem if it used through the std::max_element() function that requires a ForwardIterator. In this case you could use the boost::first_max_element function.
Template Parameters
TLightFunctorthe type of functor that transforms the pointed element into another one (required to be light because the functor is passed by value)
TReturnTypethe type of the element returned by the underlying functor (if TLightFunctor has a nested type called 'Value', TReturnType is set to TLightFunctor::Value by default)

NB: from boost/iterator/transform_iterator.hpp

Definition at line 85 of file ConstIteratorAdapter.h.

Member Typedef Documentation

◆ Super

template<typename TIterator , typename TLightFunctor , typename TReturnType = typename TLightFunctor::Value>
typedef boost::iterator_adaptor< ConstIteratorAdapter<TIterator,TLightFunctor,TReturnType>, TIterator, TReturnType, boost::use_default, TReturnType > DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >::Super
private

Definition at line 92 of file ConstIteratorAdapter.h.

◆ Type

template<typename TIterator , typename TLightFunctor , typename TReturnType = typename TLightFunctor::Value>
typedef IteratorCirculatorTraits<TIterator>::Type DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >::Type

Definition at line 98 of file ConstIteratorAdapter.h.

Constructor & Destructor Documentation

◆ ConstIteratorAdapter() [1/3]

template<typename TIterator , typename TLightFunctor , typename TReturnType = typename TLightFunctor::Value>
DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >::ConstIteratorAdapter ( )
inline

Default constructor

Definition at line 104 of file ConstIteratorAdapter.h.

104 { }

◆ ConstIteratorAdapter() [2/3]

template<typename TIterator , typename TLightFunctor , typename TReturnType = typename TLightFunctor::Value>
DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >::ConstIteratorAdapter ( TIterator const &  i,
TLightFunctor  f 
)
inline

Constructor

Parameters
iany iterator
fany functor

Definition at line 112 of file ConstIteratorAdapter.h.

113  : Super(i), myF(f) { }
boost::iterator_adaptor< ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >, TIterator, TReturnType, boost::use_default, TReturnType > Super

◆ ConstIteratorAdapter() [3/3]

template<typename TIterator , typename TLightFunctor , typename TReturnType = typename TLightFunctor::Value>
template<class OtherFunctor , class OtherIterator , class OtherReturnType >
DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >::ConstIteratorAdapter ( ConstIteratorAdapter< OtherFunctor, OtherIterator, OtherReturnType > const &  other)
inline

Copy constructor

Parameters
otherthe object to copy

Definition at line 124 of file ConstIteratorAdapter.h.

127  : Super(other.base()), myF(other.functor())
128  {}

Member Function Documentation

◆ dereference()

template<typename TIterator , typename TLightFunctor , typename TReturnType = typename TLightFunctor::Value>
Super::reference DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >::dereference ( ) const
inlineprivate

Dereference function

Returns
the object returned by the functor from the element pointed by the underlying iterator

Definition at line 146 of file ConstIteratorAdapter.h.

147  { return myF(*this->base()); }

References DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >::myF.

◆ functor()

template<typename TIterator , typename TLightFunctor , typename TReturnType = typename TLightFunctor::Value>
TLightFunctor DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >::functor ( ) const
inline

Accessor on the functor

Returns
a copy of myF

Definition at line 135 of file ConstIteratorAdapter.h.

136  { return myF; }

References DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >::myF.

Friends And Related Function Documentation

◆ boost::iterator_core_access

template<typename TIterator , typename TLightFunctor , typename TReturnType = typename TLightFunctor::Value>
friend class boost::iterator_core_access
friend

Definition at line 94 of file ConstIteratorAdapter.h.

Field Documentation

◆ myF

template<typename TIterator , typename TLightFunctor , typename TReturnType = typename TLightFunctor::Value>
TLightFunctor DGtal::ConstIteratorAdapter< TIterator, TLightFunctor, TReturnType >::myF
private

The documentation for this class was generated from the following file: