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

#include <Circulator.h>

Collaboration diagram for DGtal::Circulator< TIterator >:
Collaboration graph
[legend]

Public Types

typedef TIterator Iterator
typedef Circulator< TIterator > Self
typedef CirculatorType Type
typedef
boost::iterator_category
< TIterator >::type 
iterator_category
typedef iterator_traits
< TIterator >::value_type 
value_type
typedef iterator_traits
< TIterator >::difference_type 
difference_type
typedef iterator_traits
< TIterator >::pointer 
pointer
typedef iterator_traits
< TIterator >::reference 
reference

Public Member Functions

 Circulator ()
 Circulator (const Iterator &i, const Iterator &itb, const Iterator &ite)
 ~Circulator ()
 Circulator (const Circulator &other)
template<typename other_Iterator >
 Circulator (const Circulator< other_Iterator > &other)
Circulatoroperator= (const Circulator &other)
template<typename other_Iterator >
Circulatoroperator= (const Circulator< other_Iterator > &other)
bool isValid () const
Iterator base () const
Iterator begin () const
Iterator end () const
reference operator* () const
pointer operator-> () const
Selfoperator++ ()
Self operator++ (int)
Selfoperator-- ()
Self operator-- (int)
bool operator== (const Self &other) const
bool operator!= (const Self &other) const
template<typename OtherIterator >
bool operator== (const OtherIterator &other) const
template<typename OtherIterator >
bool operator!= (const OtherIterator &other) const
Selfoperator+= (difference_type d)
Self operator+ (difference_type d) const
Self operator- (difference_type d) const
Selfoperator-= (difference_type d)
difference_type operator- (const Self &c) const
reference operator[] (difference_type d) const

Protected Attributes

Iterator myCurrentIt
Iterator myBeginIt
Iterator myEndIt
bool myFlagIsValid

Detailed Description

template<typename TIterator>
class DGtal::Circulator< TIterator >

Aim: Provides an adapter for STL iterators that can iterate through the underlying data structure as in a loop. The increment (resp. decrement if at least bidirectionnal) operator encapsulates the validity test and the assignement to the first (resp. last) iterator of a given range. For instance, the pre-increment operator does:

Description of template class 'Circulator'

return *this;

whereas the pre-decrement operator does (if at least bidirectionnal):

Template Parameters:
TIteratorany forward, bidirectionnal or random access iterator

Definition at line 77 of file Circulator.h.


Member Typedef Documentation

template<typename TIterator>
typedef iterator_traits<TIterator>::difference_type DGtal::Circulator< TIterator >::difference_type

Definition at line 92 of file Circulator.h.

template<typename TIterator>
typedef TIterator DGtal::Circulator< TIterator >::Iterator

Definition at line 83 of file Circulator.h.

template<typename TIterator>
typedef boost::iterator_category<TIterator>::type DGtal::Circulator< TIterator >::iterator_category

Definition at line 89 of file Circulator.h.

template<typename TIterator>
typedef iterator_traits<TIterator>::pointer DGtal::Circulator< TIterator >::pointer

Definition at line 93 of file Circulator.h.

template<typename TIterator>
typedef iterator_traits<TIterator>::reference DGtal::Circulator< TIterator >::reference

Definition at line 94 of file Circulator.h.

template<typename TIterator>
typedef Circulator<TIterator> DGtal::Circulator< TIterator >::Self

Definition at line 84 of file Circulator.h.

template<typename TIterator>
typedef CirculatorType DGtal::Circulator< TIterator >::Type

Definition at line 86 of file Circulator.h.

template<typename TIterator>
typedef iterator_traits<TIterator>::value_type DGtal::Circulator< TIterator >::value_type

Definition at line 91 of file Circulator.h.


Constructor & Destructor Documentation

template<typename TIterator>
DGtal::Circulator< TIterator >::Circulator ( )
inline

Default constructor. Default-initializes iterator members NB: not valid

Definition at line 106 of file Circulator.h.

template<typename TIterator>
DGtal::Circulator< TIterator >::Circulator ( const Iterator i,
const Iterator itb,
const Iterator ite 
)
inlineexplicit

Constructor. This object can iterate through the underlying data structure as in a loop, because it knows the begin and end iterator of the range.

Parameters:
iany iterator
itbbegin iterator
iteend iterator

Definition at line 118 of file Circulator.h.

References DGtal::Circulator< TIterator >::myBeginIt, DGtal::Circulator< TIterator >::myEndIt, and DGtal::Circulator< TIterator >::myFlagIsValid.

: myCurrentIt(i), myBeginIt(itb), myEndIt(ite), myFlagIsValid(true)
{ if (myBeginIt == myEndIt) myFlagIsValid = false; }
template<typename TIterator>
DGtal::Circulator< TIterator >::~Circulator ( )
inline

Destructor.

Definition at line 127 of file Circulator.h.

{}
template<typename TIterator>
DGtal::Circulator< TIterator >::Circulator ( const Circulator< TIterator > &  other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 133 of file Circulator.h.

: myCurrentIt(other.myCurrentIt),
myBeginIt(other.myBeginIt), myEndIt(other.myEndIt),
myFlagIsValid(other.myFlagIsValid)
{}
template<typename TIterator>
template<typename other_Iterator >
DGtal::Circulator< TIterator >::Circulator ( const Circulator< other_Iterator > &  other)
inline

Copy of circulators that adapts other iterator types (not const / const).

Parameters:
otherthe object to clone.

Definition at line 144 of file Circulator.h.

: myCurrentIt(other.base()),
myBeginIt(other.begin()), myEndIt(other.end()),
myFlagIsValid(other.isValid())
{}

Member Function Documentation

template<typename TIterator>
Iterator DGtal::Circulator< TIterator >::base ( ) const
inline
Returns:
member [myCurrentIt], the underlying iterator.

Definition at line 205 of file Circulator.h.

References DGtal::Circulator< TIterator >::myCurrentIt.

Referenced by DGtal::Circulator< TIterator >::operator=(), and DGtal::Circulator< TIterator >::operator==().

{ return myCurrentIt; }
template<typename TIterator>
Iterator DGtal::Circulator< TIterator >::begin ( ) const
inline
Returns:
member [myBeginIt], begin iterator of the underlying range.

Definition at line 211 of file Circulator.h.

References DGtal::Circulator< TIterator >::myBeginIt.

Referenced by DGtal::Circulator< TIterator >::operator=(), and DGtal::Circulator< TIterator >::operator==().

{ return myBeginIt; }
template<typename TIterator>
Iterator DGtal::Circulator< TIterator >::end ( ) const
inline
Returns:
member [myEndIt], end iterator of the underlying range.

Definition at line 217 of file Circulator.h.

References DGtal::Circulator< TIterator >::myEndIt.

Referenced by DGtal::Circulator< TIterator >::operator=(), and DGtal::Circulator< TIterator >::operator==().

{ return myEndIt; }
template<typename TIterator>
bool DGtal::Circulator< TIterator >::isValid ( ) const
inline
template<typename TIterator>
bool DGtal::Circulator< TIterator >::operator!= ( const Self other) const
inline

Definition at line 297 of file Circulator.h.

{ return !(*this == other); }
template<typename TIterator>
template<typename OtherIterator >
bool DGtal::Circulator< TIterator >::operator!= ( const OtherIterator &  other) const
inline

Definition at line 307 of file Circulator.h.

{ return !(*this == other); }
template<typename TIterator>
reference DGtal::Circulator< TIterator >::operator* ( ) const
inline
Returns:
*myCurrentIt.

Definition at line 223 of file Circulator.h.

References DGtal::Circulator< TIterator >::isValid(), and DGtal::Circulator< TIterator >::myCurrentIt.

{
//ASSERT( myCurrentIt != myEndIt ); //myCurrentIt == myEndIt when using reverse iterators on circulators
ASSERT( isValid() );
return *myCurrentIt;
}
template<typename TIterator>
Self DGtal::Circulator< TIterator >::operator+ ( difference_type  d) const
inline

Definition at line 326 of file Circulator.h.

{
Self tmp = *this;
return tmp += d;
}
template<typename TIterator>
Self& DGtal::Circulator< TIterator >::operator++ ( )
inline
template<typename TIterator>
Self DGtal::Circulator< TIterator >::operator++ ( int  )
inline

Post-increment

Definition at line 256 of file Circulator.h.

References DGtal::Circulator< TIterator >::operator++().

{
Self tmp = *this;
return tmp;
}
template<typename TIterator>
Self& DGtal::Circulator< TIterator >::operator+= ( difference_type  d)
inline

Definition at line 313 of file Circulator.h.

References DGtal::Circulator< TIterator >::isValid(), DGtal::Circulator< TIterator >::myBeginIt, DGtal::Circulator< TIterator >::myCurrentIt, and DGtal::Circulator< TIterator >::myEndIt.

Referenced by DGtal::Circulator< TIterator >::operator-=().

{
ASSERT( isValid() );
typename Iterator::difference_type j = myCurrentIt - myBeginIt;
typename Iterator::difference_type n = myEndIt - myBeginIt;
ASSERT( n > 0 );
ASSERT( (j >= 0) && (j < n) );
typename Iterator::difference_type e = n - j;
if (d < e) j += d;
else j = d - e;
ASSERT( (j >= 0) && (j < n) );
myCurrentIt = myBeginIt + j;
return *this;
}
template<typename TIterator>
Self DGtal::Circulator< TIterator >::operator- ( difference_type  d) const
inline

Definition at line 330 of file Circulator.h.

{
Self tmp = *this;
return tmp += -d;
}
template<typename TIterator>
difference_type DGtal::Circulator< TIterator >::operator- ( const Self c) const
inline

Definition at line 336 of file Circulator.h.

References DGtal::Circulator< TIterator >::isValid(), and DGtal::Circulator< TIterator >::myCurrentIt.

{
ASSERT( isValid() );
ASSERT( c.isValid() );
return myCurrentIt - c.myCurrentIt;
}
template<typename TIterator>
Self& DGtal::Circulator< TIterator >::operator-- ( )
inline
template<typename TIterator>
Self DGtal::Circulator< TIterator >::operator-- ( int  )
inline

Post-decrement

Definition at line 278 of file Circulator.h.

References DGtal::Circulator< TIterator >::operator--().

{
Self tmp = *this;
return tmp;
}
template<typename TIterator>
Self& DGtal::Circulator< TIterator >::operator-= ( difference_type  d)
inline

Definition at line 334 of file Circulator.h.

References DGtal::Circulator< TIterator >::operator+=().

{ return operator+=( -d); }
template<typename TIterator>
pointer DGtal::Circulator< TIterator >::operator-> ( ) const
inline
Returns:
pointer to myCurrentIt

Definition at line 232 of file Circulator.h.

References DGtal::Circulator< TIterator >::isValid(), and DGtal::Circulator< TIterator >::myCurrentIt.

{
//ASSERT( myCurrentIt != myEndIt ); //myCurrentIt == myEndIt when using reverse iterators on circulators
ASSERT( isValid() );
return myCurrentIt.operator->();
}
template<typename TIterator>
Circulator& DGtal::Circulator< TIterator >::operator= ( const Circulator< TIterator > &  other)
inline

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'.

Definition at line 155 of file Circulator.h.

References DGtal::Circulator< TIterator >::myBeginIt, DGtal::Circulator< TIterator >::myCurrentIt, DGtal::Circulator< TIterator >::myEndIt, and DGtal::Circulator< TIterator >::myFlagIsValid.

{
if ( this != &other )
{
myCurrentIt = other.myCurrentIt;
myBeginIt = other.myBeginIt;
myEndIt = other.myEndIt;
if (myBeginIt != myEndIt)
myFlagIsValid = true;
else
myFlagIsValid = false;
}
return *this;
}
template<typename TIterator>
template<typename other_Iterator >
Circulator& DGtal::Circulator< TIterator >::operator= ( const Circulator< other_Iterator > &  other)
inline

Assignment that adapts other iterator types (not const / const).

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'.

Definition at line 176 of file Circulator.h.

References DGtal::Circulator< TIterator >::base(), DGtal::Circulator< TIterator >::begin(), DGtal::Circulator< TIterator >::end(), DGtal::Circulator< TIterator >::myBeginIt, DGtal::Circulator< TIterator >::myCurrentIt, DGtal::Circulator< TIterator >::myEndIt, and DGtal::Circulator< TIterator >::myFlagIsValid.

{
if ( this != &other )
{
myCurrentIt = other.base();
myBeginIt = other.begin();
myEndIt = other.end();
if (myBeginIt != myEndIt)
myFlagIsValid = true;
else
myFlagIsValid = false;
}
return *this;
}
template<typename TIterator>
bool DGtal::Circulator< TIterator >::operator== ( const Self other) const
inline
template<typename TIterator>
template<typename OtherIterator >
bool DGtal::Circulator< TIterator >::operator== ( const OtherIterator &  other) const
inline

Definition at line 300 of file Circulator.h.

References DGtal::Circulator< TIterator >::isValid(), DGtal::Circulator< TIterator >::myBeginIt, DGtal::Circulator< TIterator >::myCurrentIt, and DGtal::Circulator< TIterator >::myEndIt.

{
return ( ( (myBeginIt == other.begin())
&&(myEndIt == other.end())
&&(myCurrentIt == other.base()) )
||( (!isValid())&&(!other.isValid()) ) );
}
template<typename TIterator>
reference DGtal::Circulator< TIterator >::operator[] ( difference_type  d) const
inline

Definition at line 341 of file Circulator.h.

{
Self tmp = *this;
tmp += d;
return *tmp;
}

Field Documentation

template<typename TIterator>
Iterator DGtal::Circulator< TIterator >::myBeginIt
protected
template<typename TIterator>
Iterator DGtal::Circulator< TIterator >::myCurrentIt
protected
template<typename TIterator>
Iterator DGtal::Circulator< TIterator >::myEndIt
protected
template<typename TIterator>
bool DGtal::Circulator< TIterator >::myFlagIsValid
protected

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