LArrayIterator is a PowerPlant class that is useful for iterating through arrays of items.
Methods :
The methods in this class are:
Data Members:
The data members in this class are:
Operation:
LArrayIterator provides the functionality needed to walk through an array from an arbitrary starting point, going forward or backward through the array elements. Each LArrayIterator object is associated with a single array. An array may have an arbitrary number of iterators, but each iterator operates on only one array.
To learn more about using iterators, refer to The PowerPlant Book with the rest of the CodeWarrior documentation.
Index values are signed, 32-bit integers.
Source files:
See also:
Purpose:
The constructor creates an object with the passed-in parameters. It constructs an iterator for an array starting at a particular position.
Access:
Prototype:
LArrayIterator( const LArray &inArray,Parameters:
ArrayIndexT inPosition = from_Start );
The parameters for this constructor are:
Purpose:
The destructor destroys the object.
Access:
Prototype:
~LArrayIterator();
Purpose:
This method sets the values of the mCurrIndex and mNextIndex data members to the constant value index_ArrayDied, indicating that the array was deleted.
Access:
Prototype:
void ArrayDied();Parameters:
Return:
Purpose:
This method calculates the mNextIndex value based on the value of mCurrIndex. If the index is at the end, the value index_AfterEnd is assigned.
Access:
Prototype:
void CalcNextIndex();Parameters:
Return:
Purpose:
This method adjusts the internal indexes to access the previous item in an array.
Access:
Prototype:
void CalcPreviousIndex();Parameters:
Return:
Purpose:
This method retrieves the current item in the array and (optionally) the item's size.
Access:
Prototype:
Boolean Current( void *outItem,
USInt32 &ioItemSize );
Boolean Current( void *outItem );Parameters:
The parameters for these methods are:
Return:
Returns true if the current item exists.
Returns false if the current item does not exist, which happens when:
You should use the ioItemSize version of this method with arrays having variable-sized elements.
Purpose:
This method returns the value of the mCurrIndex data member.
Access:
Prototype:
ArrayIndexT GetCurrentIndex() const;Parameters:
Return:
The value of mCurrIndex.
Purpose:
This method returns the value of the mNextIterator data member.
Access:
Prototype:
LArrayIterator* GetNextIterator();Parameters:
Return:
The value of mNextIterator.
Purpose:
This method keeps track of items that have been inserted into the array at the specified index.
Access:
Prototype:
void ItemsInserted( USInt32 inCount,Parameters:
ArrayIndexT inAtIndex );
The parameters for this method are:
Return:
Purpose:
This method keeps track of items starting at the specified index that have been removed from the array.
Access:
Prototype:
void ItemsRemoved( USInt32 inCount,Parameters:
ArrayIndexT inAtIndex );
The parameters for this method are:
Return:
Purpose:
This method moves to the next item in the array and passes back a copy of that item and (optionally) the item's size.
Access:
Prototype:
Boolean Next( void *outItem, USInt32 &ioItemSize );
Boolean Next( void *outItem );Parameters:
The parameters for these methods are:
Return:
Returns true if the next item exists
Returns false if next item does not exist, which happens when:
Current item is at or past end of the Array Array was deleted
Purpose:
This method moves to the previous item in the array and passes back a copy of that item.
Access:
Prototype:
Boolean Previous( void *outItem, USInt32 &ioItemSize);
Boolean Previous( void *outItem );Parameters:
The parameters for these methods are:
Return:
Returns true if the previous item exists.
Returns false if the previos item does not exist, which happens when:
Current item is at or before the start of the Array Array was deleted
Purpose:
Return a pointer to the current item in the array and (optionally) pass back the item's size.
Access:
Prototype:
void* PtrToCurrent( USInt32 &outItemSize );
void* PtrToCurrent();Parameters:
The parameter for these methods is:
Return:
Returns a pointer to the current item. Returns nil and item size of zero if there is no current item.
Purpose:
Return a pointer to the next item in the array and (optionally) pass back the item's size.
Access:
Prototype:
void* PtrToNext( USInt32 &outItemSize );
void* PtrToNext();Parameters:
The parameter for these methods is:
Return:
Returns a pointer to the next item. Returns nil and item size of zero if there is no next item.
Purpose:
Return a pointer to the previous item in the array and (optionally) pass back the item's size.
Access:
Prototype:
void* PtrToPrevious( USInt32 &outItemSize );
void* PtrToPrevious();Parameters:
The parameter for these methods is:
Return:
Returns a pointer to the previous item. Returns nil and item size of zero if there is no previous item.
Purpose:
Reset the current item to the specified index value. The standard
enumeration constants from_Start and from_End are recognized.
Access:
Prototype:
void ResetTo( ArrayIndexT inPosition );Parameters:
The parameter for this method is:
Return:
Purpose:
This method set the value of the mNextIterator data member to the value passed-in.
Access:
Prototype:
void SetNextIterator( LArrayIterator *inIterator );Parameters:
The parameter for this method is:
|
Return:
Purpose:
This data member is used to maintain a singly-linked list of Iterators for a particular Array. LArray traverses this linked list of Iterators at various times.
An Array needs a list of all its current Iterators in order to update the Iterators when the Array changes (adding/removing items or even deleting the Array). This keeps the Iterators in synch with the Array.
Access:
Prototype:
LArrayIterator *mNextIterator;
Purpose:
This data member stores a reference to the array of elements that are iterated over.
Access:
Prototype:
const LArray &mArray;
Purpose:
This data member stores the index of the array element currently pointed to.
Access:
Prototype:
ArrayIndexT mCurrIndex;
Purpose:
This data member stores the index of the array element next in the array.
Access:
Prototype:
ArrayIndexT mNextIndex;