File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
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>

Inheritance 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

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.

Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...

◆ 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.

◆ 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.

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

◆ ~ConstRangeAdapter()

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

Destructor. Does nothing.

Definition at line 144 of file ConstRangeAdapter.h.

145 {
146 if (myFlagIsOwned) delete myFunctor;
147 }

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

Referenced by compare(), and DGtal::ConstRangeAdapter< typename Storage::const_iterator, functors::Identity, SCell >::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

Referenced by main().

◆ 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

◆ 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 }

Referenced by main().

◆ 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 }

◆ 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 {
161 return size( myBegin, myEnd, Category() );
162 }

Referenced by DGtal::ConstRangeAdapter< typename Storage::const_iterator, functors::Identity, SCell >::size().

◆ 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

Begin underlying iterator

Definition at line 191 of file ConstRangeAdapter.h.

◆ myEnd

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.

◆ myFlagIsOwned

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

bool equal to true if myFunctor is owned

Definition at line 203 of file ConstRangeAdapter.h.

◆ 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: