Introduction
Downloads
Documentation
Tutorials
Pixie Lite
Forum

Home

ArrayIterator< TYPE > Class Template Reference
[Containers]

Iterator for Array. More...

List of all members.


Public Member Functions

 ArrayIterator (const Array< TYPE > &array)
void MoveFirst ()
void MoveNext ()
void MovePrevious ()
void MoveLast ()
bool IsValid () const
TYPE & GetCurrent () const
int GetCurrentIndex () const
bool Find (const TYPE &data)

Detailed Description

template<class TYPE>
class ArrayIterator< TYPE >

Iterator for Array.

Author:
Mattias Gustavsson
The iterator provides a convenient way to loop trough all the items of an Array in the same way as you would a linked list. When created, the iterator points to the first item in the array, and you can then move it around using MoveFirst, MoveNext, MoveLast and MovePrevious, and even search for a specific item using Find (note that such a search would be looping through all items, and that can be quite slow if the array contains many items. For this type of operation, consider using a HashTable instead, which provides very fast lookup of items).

Definition at line 25 of file ArrayIterator.h.


Constructor & Destructor Documentation

template<class TYPE >
ArrayIterator< TYPE >::ArrayIterator ( const Array< TYPE > &  array  ) 

Constructor

Definition at line 9 of file ArrayIterator.inl.


Member Function Documentation

template<class TYPE >
void ArrayIterator< TYPE >::MoveFirst (  ) 

Set the iterator to point at the first item in the array.

Definition at line 20 of file ArrayIterator.inl.

template<class TYPE >
void ArrayIterator< TYPE >::MoveNext (  ) 

Advances the iterator to the next item in the array.

Definition at line 29 of file ArrayIterator.inl.

template<class TYPE >
void ArrayIterator< TYPE >::MovePrevious (  ) 

Moves the iterator back to the previous item in the array.

Definition at line 41 of file ArrayIterator.inl.

template<class TYPE >
void ArrayIterator< TYPE >::MoveLast (  ) 

Set the iterator to point at the last item in the array.

Definition at line 53 of file ArrayIterator.inl.

template<class TYPE >
bool ArrayIterator< TYPE >::IsValid (  )  const

Checks if the iterator is currently pointing at a valid location in the array. If it returns true, it is safe to call GetCurrent and GetCurrentIndex.

Returns:
True if the iterator is currently pointing at a valid item

Definition at line 62 of file ArrayIterator.inl.

template<class TYPE >
TYPE & ArrayIterator< TYPE >::GetCurrent (  )  const

Gets the item the iterator is currently pointing at. If the iterator is not currently pointing at a valid location, a default value will be returned, and in debug builds an assertion will be triggered.

Returns:
The item the iterator is currently pointing at

Definition at line 76 of file ArrayIterator.inl.

template<class TYPE >
int ArrayIterator< TYPE >::GetCurrentIndex (  )  const

Gets the index that the iterator is currently pointing at. If the iterator is not currently pointing at a valid location, this method will return either the value -1 (if the iterator has moved beyond the start of the array) or a value equal to the number of items in the array (if it has been moved beyond the end).

Returns:
Index that the iterator is currently pointing at

Definition at line 92 of file ArrayIterator.inl.

template<class TYPE >
bool ArrayIterator< TYPE >::Find ( const TYPE &  data  ) 

Finds an item in the array, by looping through the array and checking each item. If the item is found, this method will return true, and the item itself and its index can be retrieved by calling GetCurrent and GetCurrentIndex, respectively.

Returns:
True if the item was found, or false if it was not found
Parameters:
data Item to look for

Definition at line 101 of file ArrayIterator.inl.



Pixie University and the Pixie Game Engine is created and managed by Mattias Gustavsson.
Reproduction/republishing of any material on this site without permission is strictly prohibited.