DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes
DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType > Class Template Reference

#include <ConstRangeAdapter.h>

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

Public Types

typedef ConstIteratorAdapter
< TIterator, TFunctor,
TReturnType > 
ConstIterator
typedef ReverseIterator
< ConstIterator
ConstReverseIterator
typedef Circulator< ConstIteratorConstCirculator
typedef ReverseIterator
< ConstCirculator
ConstReverseCirculator
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(<em>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

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.

: myBegin(itb), myEnd(ite), myFunctor(&aFunctor), myFlagIsOwned(false) {}
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.

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

{
myFunctor = new TFunctor( *other.myFunctor ); //owned copy
else
myFunctor = other.myFunctor; //copy of the alias
}
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
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.

{
return "ConstRangeAdapter";
}
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.

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

{
return ConstReverseIterator(this->end());
}
template<typename TIterator, typename TFunctor, typename TReturnType>
ConstReverseCirculator DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::rc ( ) const
inline

Circulator service.

Returns:
a reverse circulator

Definition at line 262 of file ConstRangeAdapter.h.

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

{
return ConstReverseCirculator( this->c() );
}
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().

{
return ConstReverseIterator(this->begin());
}
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().

{
out << "[ConstRangeAdapter]" << std::endl;
out << "\t";
std::copy( this->begin(), this->end(), ostream_iterator<TReturnType>(out, ", ") );
out << std::endl;
}
template<typename TIterator, typename TFunctor, typename TReturnType>
Difference DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::size ( ) const
inline
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 275 of file ConstRangeAdapter.h.

{
return (ite-itb);
}
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 287 of file ConstRangeAdapter.h.

{
TIterator it = itb;
unsigned int d = 0;
for ( ; it != ite; ++it, ++d)
{}
return d;
}

Field Documentation

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