AutoIterator< C > Class Template Reference

#include <autoiterator.h>

Public Types

typedef Int ForEachIteratorMarker
 

Public Member Functions

 AutoIterator (C &container)
 
 AutoIterator (const Iterator &s, const Iterator &e)
 
 AutoIterator (C &container, Int s, Int e=InvalidArrayIndex)
 
 AutoIterator (const AutoIterator &src)
 
AutoIteratoroperator= (const AutoIterator &src)
 
Bool HasValue () const
 
Iterator::ValueType * GetPtr () const
 
Iterator::ValueType & operator* () const
 
Iterator::ValueType * operator-> () const
 
Bool operator== (const AutoIterator &b) const
 
Bool operator!= (const AutoIterator &b) const
 
Bool operator>= (const AutoIterator &b) const
 
Bool operator<= (const AutoIterator &b) const
 
Bool operator< (const AutoIterator &b) const
 
Bool operator> (const AutoIterator &b) const
 
AutoIteratoroperator++ ()
 
const AutoIterator operator++ (int)
 
AutoIteratoroperator+= (Int i)
 
AutoIteratoroperator-- ()
 
const AutoIterator operator-- (int)
 
AutoIteratoroperator-= (Int i)
 
AutoIterator operator+ (Int i) const
 
AutoIterator operator- (Int i) const
 
Int operator- (const AutoIterator &b) const
 
Int operator- (const Iterator &b) const
 
 operator Iterator () const
 

Private Types

typedef Select< ::std::is_const< C >::value, typename C::ConstIterator, typename C::Iterator >::Type Iterator
 

Private Attributes

Iterator _it
 
const Iterator _end
 

Detailed Description

template<typename C>
class cineware::AutoIterator< C >

Iterator helper template.

Template Parameters
CClass with an valid Iterator. This templates simplifies cases like iterating over a whole array or list. Typical usage is:
for (AutoIterator<ARRAYTYPE> it(array); it; it++)
{
// ... do something with *it or it->
}

When iterating from the last to the first element you have to take into account that End() is one after the last element. Therefore you have to write:

for (AutoIterator<ARRAYTYPE> it(array.End(), array.Begin()); it; )
{
--it;
// ... do something with *it or it->
}

Other than that the AutoIterator behaves like the iterator it encapsulates and you can do all sorts of iterator arithmetic that the base iterator supports, e.g.

it++; // go to the next element
it--; // go to the previous element
it += 5; // advance by 5 elements
it -= 3; // go back 3 elements
cnt = itB - itA; // number of elements from itA to itB
*it = value; // assign value to the elements referenced by the iterator
value = *it; // get value of the element referenced by the iterator

Member Typedef Documentation

◆ Iterator

typedef Select< ::std::is_const<C>::value, typename C::ConstIterator, typename C::Iterator >::Type Iterator
private

◆ ForEachIteratorMarker

This marker indicates that an AutoIterator supports the protocol of the FOREACH macro.

Constructor & Destructor Documentation

◆ AutoIterator() [1/4]

AutoIterator ( C &  container)
explicit

Use this constructor if you want to iterate over all elements. Please note that the end iterator of the AutoArray is a constant. When you modify an array (via Insert(), Append() or Erase()) the value of its End() iterator will most likely change and trying to iterate over such an array with an AutoIterator while modifying it would crash.

◆ AutoIterator() [2/4]

AutoIterator ( const Iterator s,
const Iterator e 
)
explicit

use this constructor if you want to iterate from s until e (excluding e)

◆ AutoIterator() [3/4]

AutoIterator ( C &  container,
Int  s,
Int  e = InvalidArrayIndex 
)
explicit

◆ AutoIterator() [4/4]

AutoIterator ( const AutoIterator< C > &  src)

Member Function Documentation

◆ operator=()

AutoIterator& operator= ( const AutoIterator< C > &  src)

◆ HasValue()

Bool HasValue ( ) const

Operator that returns false when the end of the array has been reached. operator bool() would be ambiguous because it can be used for integer arithmetic. For C++0x we use explicit bool to avoid that implicit conversion, for older compilers void* is returned because you can't do arithmetic with it.

Returns
False when the end of the array has been reached.

◆ GetPtr()

Iterator::ValueType* GetPtr ( ) const

◆ operator*()

Iterator::ValueType& operator* ( ) const

◆ operator->()

Iterator::ValueType* operator-> ( ) const

◆ operator==()

Bool operator== ( const AutoIterator< C > &  b) const

◆ operator!=()

Bool operator!= ( const AutoIterator< C > &  b) const

◆ operator>=()

Bool operator>= ( const AutoIterator< C > &  b) const

◆ operator<=()

Bool operator<= ( const AutoIterator< C > &  b) const

◆ operator<()

Bool operator< ( const AutoIterator< C > &  b) const

◆ operator>()

Bool operator> ( const AutoIterator< C > &  b) const

◆ operator++() [1/2]

AutoIterator& operator++ ( )

◆ operator++() [2/2]

const AutoIterator operator++ ( int  )

◆ operator+=()

AutoIterator& operator+= ( Int  i)

◆ operator--() [1/2]

AutoIterator& operator-- ( )

◆ operator--() [2/2]

const AutoIterator operator-- ( int  )

◆ operator-=()

AutoIterator& operator-= ( Int  i)

◆ operator+()

AutoIterator operator+ ( Int  i) const

◆ operator-() [1/3]

AutoIterator operator- ( Int  i) const

◆ operator-() [2/3]

Int operator- ( const AutoIterator< C > &  b) const

◆ operator-() [3/3]

Int operator- ( const Iterator b) const

◆ operator Iterator()

operator Iterator ( ) const

Member Data Documentation

◆ _it

Iterator _it
private

◆ _end

const Iterator _end
private