DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator Class Reference

#include <IndexedListWithBlocks.h>

Collaboration diagram for DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator:
Collaboration graph
[legend]

Public Types

typedef Iterator Self
typedef TValue Value
typedef ValuePointer
typedef ValueReference
typedef std::ptrdiff_t DifferenceType
typedef Value value_type
typedef std::size_t size_type
typedef DifferenceType difference_type
typedef Pointer pointer
typedef Reference reference
typedef std::forward_iterator_tag iterator_category

Public Member Functions

 ~Iterator ()
 Iterator ()
 Iterator (const Iterator &other)
Selfoperator= (const Self &other)
Reference operator* () const
Pointer operator-> () const
Selfoperator++ ()
Self operator++ (int)
Selfoperator+= (DifferenceType n)
Reference operator[] (DifferenceType n) const
bool operator== (const Self &other) const
bool operator!= (const Self &other) const

Protected Member Functions

 Iterator (FirstBlock &block, unsigned int idx)

Protected Attributes

unsigned int myIdx
unsigned int myNbValues
ValuemyValues
AnyBlockmyNext

Friends

class IndexedListWithBlocks

Detailed Description

template<typename TValue, unsigned int N, unsigned int M>
class DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator

Pseudo-random iterator to visit IndexedListWithBlocks (it is only a random forward iterator). Model of boost::ForwardIterator. Provides also + and += arithmetic.

Definition at line 335 of file IndexedListWithBlocks.h.


Member Typedef Documentation

template<typename TValue, unsigned int N, unsigned int M>
typedef DifferenceType DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::difference_type

Definition at line 346 of file IndexedListWithBlocks.h.

template<typename TValue, unsigned int N, unsigned int M>
typedef std::ptrdiff_t DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::DifferenceType

Definition at line 341 of file IndexedListWithBlocks.h.

template<typename TValue, unsigned int N, unsigned int M>
typedef std::forward_iterator_tag DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::iterator_category

Definition at line 350 of file IndexedListWithBlocks.h.

template<typename TValue, unsigned int N, unsigned int M>
typedef Value* DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Pointer

Definition at line 339 of file IndexedListWithBlocks.h.

template<typename TValue, unsigned int N, unsigned int M>
typedef Pointer DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::pointer

Definition at line 347 of file IndexedListWithBlocks.h.

template<typename TValue, unsigned int N, unsigned int M>
typedef Value& DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Reference

Definition at line 340 of file IndexedListWithBlocks.h.

template<typename TValue, unsigned int N, unsigned int M>
typedef Reference DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::reference

Definition at line 348 of file IndexedListWithBlocks.h.

template<typename TValue, unsigned int N, unsigned int M>
typedef Iterator DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Self

Definition at line 337 of file IndexedListWithBlocks.h.

template<typename TValue, unsigned int N, unsigned int M>
typedef std::size_t DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::size_type

Definition at line 345 of file IndexedListWithBlocks.h.

template<typename TValue, unsigned int N, unsigned int M>
typedef TValue DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Value

Definition at line 338 of file IndexedListWithBlocks.h.

template<typename TValue, unsigned int N, unsigned int M>
typedef Value DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::value_type

Definition at line 344 of file IndexedListWithBlocks.h.


Constructor & Destructor Documentation

template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Iterator ( FirstBlock block,
unsigned int  idx 
)
protected

Constructor from first block and index. Used by class IndexedListWithBlocks.

Definition at line 64 of file IndexedListWithBlocks.ih.

References DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::data, DGtal::IndexedListWithBlocks< TValue, N, M >::ValueOrBlockPointer::nextBlock, DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::size, and DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::values.

{
ASSERT( idx <= block.size );
if ( block.size <= N+1 )
{
if ( idx <= N )
{
myIdx = idx;
myNbValues = N + 1;
myValues = block.values;
myNext = 0;
}
else
{ // end iterator.
myIdx = 0;
myValues = 0;
myNext = 0;
}
}
else
{
ASSERT( block.data.nextBlock != 0 );
myNext = block.data.nextBlock;
if ( idx < N )
{
myIdx = idx;
myValues = block.values;
}
else
{
idx -= N;
while ( idx >= M )
{
idx -= M;
myNext = ( myNext != 0 ) ? myNext->next : 0;
}
if ( myNext == 0 )
{
myIdx = 0;
myValues = 0;
}
else
{
myIdx = idx;
}
}
}
}
template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::~Iterator ( )

Default destructor.

Definition at line 46 of file IndexedListWithBlocks.ih.

{}
template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Iterator ( )

Default constructor.

Definition at line 51 of file IndexedListWithBlocks.ih.

: myIdx( 0 ), myValues( 0 )
{}
template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Iterator ( const Iterator other)

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 57 of file IndexedListWithBlocks.ih.

: myIdx( other.myIdx ), myNbValues( other.myNbValues ),
myValues( other.myValues ), myNext( other.myNext )
{}

Member Function Documentation

template<typename TValue , unsigned int N, unsigned int M>
bool DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::operator!= ( const Self other) const
inline

Inequality operator.

Parameters:
otherany other iterator.
Returns:
'true' iff the iterators points on different elements.

Definition at line 187 of file IndexedListWithBlocks.ih.

References DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myIdx, and DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myValues.

{
return ( myValues != other.myValues ) || ( myIdx != other.myIdx );
}
template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Reference DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::operator* ( ) const
inline

Dereference operator.

Returns:
the current value of the iterator, if valid.

Definition at line 138 of file IndexedListWithBlocks.ih.

{
ASSERT( myValues != 0 );
return myValues[ myIdx ];
}
template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Self & DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::operator++ ( )
inline

Pre-increment operator.

Returns:
a reference to itself.

Definition at line 158 of file IndexedListWithBlocks.ih.

{
return this->operator+=( 1 );
}
template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Self DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::operator++ ( int  )
inline

Post-increment operator.

Returns:
a reference to itself.

Definition at line 167 of file IndexedListWithBlocks.ih.

{
Self tmp( *this );
this->operator++();
return tmp;
}
template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Self & DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::operator+= ( DifferenceType  n)
inline

Addition operator. Moves the iterator at position + n.

Parameters:
nany positive integer
Returns:
a reference to itself.

Definition at line 196 of file IndexedListWithBlocks.ih.

{
myIdx += n;
while ( myIdx >= myNbValues )
{
if ( myNext == 0 )
{
myValues = 0;
myIdx = 0;
break;
}
}
return *this;
}
template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Pointer DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::operator-> ( ) const
inline

Pointer dereference operator.

Returns:
a non-mutable pointer on the current value.

Definition at line 148 of file IndexedListWithBlocks.ih.

{
ASSERT( myValues != 0 );
return myValues + myIdx;
}
template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Self & DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::operator= ( const Self other)
inline

Assignment.

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

Definition at line 122 of file IndexedListWithBlocks.ih.

References DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myIdx, DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myNbValues, DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myNext, and DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myValues.

{
if ( this != &other )
{
myIdx = other.myIdx;
myNbValues = other.myNbValues;
myValues = other.myValues;
myNext = other.myNext;
}
return *this;
}
template<typename TValue , unsigned int N, unsigned int M>
bool DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::operator== ( const Self other) const
inline

Equality operator.

Parameters:
otherany other iterator.
Returns:
'true' iff the iterators points on the same element.

Definition at line 178 of file IndexedListWithBlocks.ih.

References DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myIdx, and DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myValues.

{
return ( myValues == other.myValues ) && ( myIdx == other.myIdx );
}
template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::Reference DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::operator[] ( DifferenceType  n) const
inline

Positive offset dereference operator. Moves the iterator at position + n.

Parameters:
nany positive integer
Returns:
a reference to itself.

Definition at line 219 of file IndexedListWithBlocks.ih.

{
Self tmp( *this );
tmp += n;
return *tmp;
}

Friends And Related Function Documentation

template<typename TValue, unsigned int N, unsigned int M>
friend class IndexedListWithBlocks
friend

Definition at line 359 of file IndexedListWithBlocks.h.


Field Documentation

template<typename TValue, unsigned int N, unsigned int M>
unsigned int DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myIdx
protected
template<typename TValue, unsigned int N, unsigned int M>
unsigned int DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myNbValues
protected
template<typename TValue, unsigned int N, unsigned int M>
AnyBlock* DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myNext
protected
template<typename TValue, unsigned int N, unsigned int M>
Value* DGtal::IndexedListWithBlocks< TValue, N, M >::Iterator::myValues
protected

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