DGtal  0.9.3beta
Public Types | Public Member Functions | Private Member Functions | Private Attributes
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType > Class Template Reference

#include <DGtal/base/ConstRangeAdapter.h>

Collaboration diagram for DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >:
[legend]

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
Examples:
geometry/curves/estimation/exampleCurvature.cpp, and geometry/tools/exampleAlphaShape.cpp.

Definition at line 86 of file ConstRangeAdapter.h.

Member Typedef Documentation

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

Definition at line 98 of file ConstRangeAdapter.h.

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.

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

Definition at line 99 of file ConstRangeAdapter.h.

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

Definition at line 96 of file ConstRangeAdapter.h.

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

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.

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) {}
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.

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

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  }
template<typename TIterator, typename TFunctor, typename TReturnType>
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::~ConstRangeAdapter ( )
inline

Member Function Documentation

template<typename TIterator, typename TFunctor, typename TReturnType>
ConstIterator DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::begin ( ) const
inline
template<typename TIterator, typename TFunctor, typename TReturnType>
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::BOOST_CONCEPT_ASSERT ( (boost_concepts::ReadableIteratorConcept< TIterator >)  )
private
template<typename TIterator, typename TFunctor, typename TReturnType>
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::BOOST_CONCEPT_ASSERT ( (boost_concepts::BidirectionalTraversalConcept< TIterator >)  )
private
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.

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

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

257  {
258  return ConstCirculator( this->begin(), this->begin(), this->end() );
259  }
ConstIterator begin() const
ConstIterator end() const
Circulator< ConstIterator > ConstCirculator
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  }
template<typename TIterator, typename TFunctor, typename TReturnType>
ConstIterator DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::end ( ) const
inline
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; }
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'.
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.

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

238  {
239  return ConstReverseIterator(this->end());
240  }
ReverseIterator< ConstIterator > ConstReverseIterator
ConstIterator end() const
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.

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

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
Circulator< ConstIterator > ConstCirculator
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.

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

246  {
247  return ConstReverseIterator(this->begin());
248  }
ReverseIterator< ConstIterator > ConstReverseIterator
ConstIterator begin() const
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.

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

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  }
ConstIterator begin() const
ConstIterator end() const
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.

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

159  {
160  typedef typename IteratorCirculatorTraits<TIterator>::Category Category;
161  return size( myBegin, myEnd, Category() );
162  }
Difference size() const
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  }
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  }

Field Documentation

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

Begin underlying iterator

Definition at line 191 of file ConstRangeAdapter.h.

Referenced by DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::size().

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

End underlying iterator

Definition at line 195 of file ConstRangeAdapter.h.

Referenced by DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::size().

template<typename TIterator, typename TFunctor, typename TReturnType>
bool DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::myFlagIsOwned
private
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: