DGtal  1.5.beta
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType > Class Template Reference

Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [itb, ite) and provides services to (circularly)iterate over it (in a read-only manner). More...

#include <DGtal/base/ConstRangeAdapter.h>

Public Types

typedef ConstIteratorAdapter< TIterator, TFunctor, TReturnType > ConstIterator
 
typedef ReverseIterator< ConstIteratorConstReverseIterator
 
typedef Circulator< ConstIteratorConstCirculator
 
typedef ReverseIterator< ConstCirculatorConstReverseCirculator
 
typedef IteratorCirculatorTraits< ConstIterator >::Difference Difference
 

Public Member Functions

 ConstRangeAdapter (const TIterator &itb, const TIterator &ite, const TFunctor &aFunctor)
 
 ConstRangeAdapter (const TIterator &itb, const TIterator &ite, const TFunctor *aFunctorPtr)
 
 ConstRangeAdapter (const ConstRangeAdapter &other)
 
 ~ConstRangeAdapter ()
 
bool isValid () const
 
Difference size () const
 
void selfDisplay (std::ostream &out) const
 
std::string className () const
 
ConstIterator begin () const
 
ConstIterator end () const
 
ConstReverseIterator rbegin () const
 
ConstReverseIterator rend () const
 
ConstCirculator c () const
 
ConstReverseCirculator rc () const
 

Private Member Functions

 BOOST_CONCEPT_ASSERT ((boost_concepts::ReadableIteratorConcept< TIterator >))
 
 BOOST_CONCEPT_ASSERT ((boost_concepts::BidirectionalTraversalConcept< TIterator >))
 
ConstRangeAdapteroperator= (const ConstRangeAdapter &other)
 
Difference size (const TIterator &itb, const TIterator &ite, RandomAccessCategory) const
 
Difference size (const TIterator &itb, const TIterator &ite, BidirectionalCategory) const
 

Private Attributes

TIterator myBegin
 
TIterator myEnd
 
const TFunctor * myFunctor
 
bool myFlagIsOwned
 

Detailed Description

template<typename TIterator, typename TFunctor, typename TReturnType>
class DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >

Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [itb, ite) and provides services to (circularly)iterate over it (in a read-only manner).

Template Parameters
TIteratorthe type of the iterator to adapt (at least bidirectional).

Moreover, the provided (circular)iterator is adapted with a functor f given at construction so that operator* calls f(*it), instead of calling directly operator* of the underlying iterator it.

Template Parameters
TFunctorthe type of functor that transforms the pointed element into another one
TReturnTypethe type of the element returned by the underlying functor.

NB: the underlying functor is stored in the range as aliasing pointer in order to avoid copies. As a consequence the pointed object must exist and must not be deleted during the use of the range.

See also
ConstIteratorAdapter BasicFunctors.h BasicPointFunctors.h SCellsFunctors.h

Definition at line 86 of file ConstRangeAdapter.h.

Member Typedef Documentation

◆ ConstCirculator

template<typename TIterator , typename TFunctor , typename TReturnType >
typedef Circulator<ConstIterator> DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::ConstCirculator

Definition at line 98 of file ConstRangeAdapter.h.

◆ ConstIterator

template<typename TIterator , typename TFunctor , typename TReturnType >
typedef ConstIteratorAdapter<TIterator,TFunctor,TReturnType> DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::ConstIterator

Definition at line 95 of file ConstRangeAdapter.h.

◆ ConstReverseCirculator

template<typename TIterator , typename TFunctor , typename TReturnType >
typedef ReverseIterator<ConstCirculator> DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::ConstReverseCirculator

Definition at line 99 of file ConstRangeAdapter.h.

◆ ConstReverseIterator

template<typename TIterator , typename TFunctor , typename TReturnType >
typedef ReverseIterator<ConstIterator> DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::ConstReverseIterator

Definition at line 96 of file ConstRangeAdapter.h.

◆ Difference

template<typename TIterator , typename TFunctor , typename TReturnType >
typedef IteratorCirculatorTraits<ConstIterator>::Difference DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::Difference

Definition at line 101 of file ConstRangeAdapter.h.

Constructor & Destructor Documentation

◆ ConstRangeAdapter() [1/3]

template<typename TIterator , typename TFunctor , typename TReturnType >
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::ConstRangeAdapter ( const TIterator &  itb,
const TIterator &  ite,
const TFunctor &  aFunctor 
)
inline

Standard constructor from two iterators and one functor (stored as an aliasing pointer).

Parameters
itbbegin iterator.
iteend iterator.
aFunctorfunctor used to adapt on-the-fly the elements of the range

Definition at line 112 of file ConstRangeAdapter.h.

◆ ConstRangeAdapter() [2/3]

template<typename TIterator , typename TFunctor , typename TReturnType >
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::ConstRangeAdapter ( const TIterator &  itb,
const TIterator &  ite,
const TFunctor *  aFunctorPtr 
)
inline

Standard constructor from two iterators and one pointer on a functor (stored as an owning pointer).

Parameters
itbbegin iterator.
iteend iterator.
aFunctorPtrpointer on a functor used to adapt on-the-fly the elements of the range

Definition at line 124 of file ConstRangeAdapter.h.

126  : myBegin(itb), myEnd(ite), myFunctor(aFunctorPtr), myFlagIsOwned(true) {}

◆ ConstRangeAdapter() [3/3]

template<typename TIterator , typename TFunctor , typename TReturnType >
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::ConstRangeAdapter ( const ConstRangeAdapter< TIterator, TFunctor, TReturnType > &  other)
inline

Copy constructor.

Parameters
otherthe iterator to clone.

Definition at line 132 of file ConstRangeAdapter.h.

133  : myBegin(other.myBegin), myEnd(other.myEnd), myFlagIsOwned(other.myFlagIsOwned)
134  {
135  if (myFlagIsOwned)
136  myFunctor = new TFunctor( *other.myFunctor ); //owned copy
137  else
138  myFunctor = other.myFunctor; //copy of the alias
139  }

References DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::myFlagIsOwned, and DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::myFunctor.

◆ ~ConstRangeAdapter()

template<typename TIterator , typename TFunctor , typename TReturnType >
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::~ConstRangeAdapter ( )
inline

Member Function Documentation

◆ begin()

template<typename TIterator , typename TFunctor , typename TReturnType >
ConstIterator DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::begin ( ) const
inline

◆ BOOST_CONCEPT_ASSERT() [1/2]

template<typename TIterator , typename TFunctor , typename TReturnType >
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::BOOST_CONCEPT_ASSERT ( (boost_concepts::BidirectionalTraversalConcept< TIterator >)  )
private

◆ BOOST_CONCEPT_ASSERT() [2/2]

template<typename TIterator , typename TFunctor , typename TReturnType >
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::BOOST_CONCEPT_ASSERT ( (boost_concepts::ReadableIteratorConcept< TIterator >)  )
private

◆ c()

template<typename TIterator , typename TFunctor , typename TReturnType >
ConstCirculator DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::c ( ) const
inline

Circulator service. Prodives a circulator such that *c() == *begin()

Returns
a circulator
See also
rc method

Definition at line 257 of file ConstRangeAdapter.h.

257  {
258  return ConstCirculator( this->begin(), this->begin(), this->end() );
259  }
Circulator< ConstIterator > ConstCirculator
ConstIterator begin() const
ConstIterator end() const

References DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::begin(), and DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::end().

Referenced by compare(), and DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::rc().

◆ className()

template<typename TIterator , typename TFunctor , typename TReturnType >
std::string DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::className ( ) const
inline
Returns
the style name used for drawing this object.

Definition at line 180 of file ConstRangeAdapter.h.

181  {
182  return "ConstRangeAdapter";
183  }

◆ end()

◆ isValid()

template<typename TIterator , typename TFunctor , typename TReturnType >
bool DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::isValid ( ) const
inline

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

Definition at line 153 of file ConstRangeAdapter.h.

153 { return true; }

◆ operator=()

template<typename TIterator , typename TFunctor , typename TReturnType >
ConstRangeAdapter& DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::operator= ( const ConstRangeAdapter< TIterator, TFunctor, TReturnType > &  other)
private

Assignment.

Parameters
otherthe iterator to copy.
Returns
a reference on 'this'.

◆ rbegin()

template<typename TIterator , typename TFunctor , typename TReturnType >
ConstReverseIterator DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::rbegin ( ) const
inline

Iterator service.

Returns
rbegin iterator

Definition at line 238 of file ConstRangeAdapter.h.

238  {
239  return ConstReverseIterator(this->end());
240  }
ReverseIterator< ConstIterator > ConstReverseIterator

References DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::end().

◆ rc()

template<typename TIterator , typename TFunctor , typename TReturnType >
ConstReverseCirculator DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::rc ( ) const
inline

Circulator service. Provides a reverse circulator such that *rc() == *c() == *begin()

Returns
a reverse circulator
See also
c method
begin method

Definition at line 269 of file ConstRangeAdapter.h.

269  {
270  //implemented so that *rc() == *c()
271  ConstCirculator tmp = this->c();
272  ++tmp;
273  return ConstReverseCirculator( tmp );
274  }
ReverseIterator< ConstCirculator > ConstReverseCirculator
ConstCirculator c() const

References DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::c().

◆ rend()

template<typename TIterator , typename TFunctor , typename TReturnType >
ConstReverseIterator DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::rend ( ) const
inline

Iterator service.

Returns
rend iterator

Definition at line 246 of file ConstRangeAdapter.h.

246  {
247  return ConstReverseIterator(this->begin());
248  }

References DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::begin().

◆ selfDisplay()

template<typename TIterator , typename TFunctor , typename TReturnType >
void DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

Definition at line 169 of file ConstRangeAdapter.h.

170  {
171  out << "[ConstRangeAdapter]" << std::endl;
172  out << "\t";
173  std::copy( this->begin(), this->end(), std::ostream_iterator<TReturnType>(out, ", ") );
174  out << std::endl;
175  }

References DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::begin(), and DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::end().

◆ size() [1/3]

template<typename TIterator , typename TFunctor , typename TReturnType >
Difference DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::size ( ) const
inline
Returns
the size of the range.

Definition at line 158 of file ConstRangeAdapter.h.

159  {
160  typedef typename IteratorCirculatorTraits<TIterator>::Category Category;
161  return size( myBegin, myEnd, Category() );
162  }
ToDGtalCategory< typename boost::iterator_category< IC >::type >::Category Category

References DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::myBegin, and DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::myEnd.

◆ size() [2/3]

template<typename TIterator , typename TFunctor , typename TReturnType >
Difference DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::size ( const TIterator &  itb,
const TIterator &  ite,
BidirectionalCategory   
) const
inlineprivate

Get the size of [itb, ite)

Parameters
itbbegin iterator
iteend iterator
Returns
the size of the range. NB: in O(ite-itb)

Definition at line 297 of file ConstRangeAdapter.h.

298  {
299  TIterator it = itb;
300  unsigned int d = 0;
301  for ( ; it != ite; ++it, ++d)
302  {}
303  return d;
304  }

◆ size() [3/3]

template<typename TIterator , typename TFunctor , typename TReturnType >
Difference DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::size ( const TIterator &  itb,
const TIterator &  ite,
RandomAccessCategory   
) const
inlineprivate

Get the size of [itb, ite)

Parameters
itbbegin iterator
iteend iterator
Returns
the size of the range. NB: in O(1)

Definition at line 285 of file ConstRangeAdapter.h.

286  {
287  return (ite-itb);
288  }

Field Documentation

◆ myBegin

template<typename TIterator , typename TFunctor , typename TReturnType >
TIterator DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::myBegin
private

◆ myEnd

template<typename TIterator , typename TFunctor , typename TReturnType >
TIterator DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::myEnd
private

◆ myFlagIsOwned

template<typename TIterator , typename TFunctor , typename TReturnType >
bool DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::myFlagIsOwned
private

◆ myFunctor

template<typename TIterator , typename TFunctor , typename TReturnType >
const TFunctor* DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::myFunctor
private

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