Iterator Class Reference

API: cArray::Iterator Class Reference
API
cArray::Iterator Class Reference

Public Member Functions

 Iterator (const cArray &a, bool atHead=true)
void init (const cArray &a, bool atHead=true)
cObjectoperator* () const
bool end () const
Iteratoroperator++ ()
Iterator operator++ (int)
Iteratoroperator-- ()
Iterator operator-- (int)

Description

Iterates through elements in a cArray, skipping holes (slots containing nullptr).

Usage:

for (cArray::Iterator it(array); !it.end(); ++it) {
cObject *item = *it;
...
}
Iterates through elements in a cArray, skipping holes (slots containing nullptr).
Definition carray.h:54
bool end() const
Definition carray.h:85

Constructor & Destructor Documentation

◆ Iterator()

Iterator ( const cArray & a,
bool atHead = true )
inline

Constructor. Iterator will walk on the array passed as argument. The starting object will be the first (if atHead==true) or the last (atHead==false) object in the array, not counting empty slots.

References cArray::cArray(), and init().

Referenced by operator++(), operator++(), operator--(), and operator--().

Member Function Documentation

◆ init()

void init ( const cArray & a,
bool atHead = true )

Reinitializes the iterator object.

References cArray::cArray().

Referenced by Iterator().

◆ operator*()

cObject * operator* ( ) const
inline

Returns a pointer to the current object, or nullptr if the iterator is not at a valid position.

◆ end()

bool end ( ) const
inline

Returns true if the iterator has reached either end of the array.

Referenced by operator++(), operator++(), operator--(), and operator--().

◆ operator++() [1/2]

Iterator & operator++ ( )
inline

Prefix increment operator (++it). Moves the iterator to the next non-empty slot in the array. It has no effect if the iterator has reached either end of the array.

References end(), and Iterator().

◆ operator++() [2/2]

Iterator operator++ ( int )
inline

Postfix increment operator (it++). Moves the iterator to the next non-empty slot in the array, and returns the iterator's previous state. It has no effect if the iterator has reached either end of the array.

References end(), and Iterator().

◆ operator--() [1/2]

Iterator & operator-- ( )
inline

Prefix decrement operator (–it). Moves the iterator to the previous non-empty slot in the array. It has no effect if the iterator has reached either end of the array.

References end(), and Iterator().

◆ operator--() [2/2]

Iterator operator-- ( int )
inline

Postfix decrement operator (it–). Moves the iterator to the previous non-empty slot in the array, and returns the iterator's previous state. It has no effect if the iterator has reached either end of the array.

References end(), and Iterator().