[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

 

LArrayIterator



Description:

LArrayIterator is a PowerPlant class that is useful for iterating through arrays of items.

Methods :

The methods in this class are:

 

LArrayIterator()  
~LArrayIterator()  
ArrayDied()  
CalcNextIndex()  
CalcPreviousIndex()  
Current()  
GetCurrentIndex()  
GetNextIterator()  
ItemsInserted()  
ItemsRemoved()  
Next()  
Previous()  
PtrToCurrent()  
PtrToNext()  
PtrToPrevious()  
ResetTo()  
SetNextIterator()  
 

Data Members:

The data members in this class are:

 

mNextIterator  
mArray  
mCurrIndex  
mNextIndex  

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:

(Array Classes)

LArrayIterator.h

LArrayIterator.cp

See also:

LArray

LArrayIterator()

Purpose:

The constructor creates an object with the passed-in parameters. It constructs an iterator for an array starting at a particular position.

Access:

Public

Prototype:

LArrayIterator( const LArray &inArray,
ArrayIndexT inPosition = from_Start );
Parameters:

The parameters for this constructor are:

 

const LArray&  
inArray  
The reference to the array to iterate on.  
ArrayIndexT  
inPosition  
The position in the array to set the iterator to. The default is from_Start.  

~LArrayIterator()

Purpose:

The destructor destroys the object.

Access:

Virtual, Public

Prototype:

~LArrayIterator();

ArrayDied()

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:

Protected

Prototype:

void ArrayDied();
Parameters:

None

Return:

None

CalcNextIndex()

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:

Protected

Prototype:

void CalcNextIndex();
Parameters:

None

Return:

None

CalcPreviousIndex()

Purpose:

This method adjusts the internal indexes to access the previous item in an array.

Access:

Protected

Prototype:

void CalcPreviousIndex();
Parameters:

None

Return:

None

Current()

Purpose:

This method retrieves the current item in the array and (optionally) the item's size.

Access:

Public

Prototype:

Boolean Current( void *outItem,
USInt32 &ioItemSize );

Boolean Current( void *outItem );
Parameters:

The parameters for these methods are:

 

void*  
outItem  
The pointer to the array item that is passed out upon exiting this method.  
USInt32&  
ioItemSize  
A reference to the size of the item retrieved from the array.  

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.

GetCurrentIndex()

Purpose:

This method returns the value of the mCurrIndex data member.

Access:

Inline, Public

Prototype:

ArrayIndexT GetCurrentIndex() const;
Parameters:

None

Return:

The value of mCurrIndex.

GetNextIterator()

Purpose:

This method returns the value of the mNextIterator data member.

Access:

Inline, Public

Prototype:

LArrayIterator* GetNextIterator();
Parameters:

None

Return:

The value of mNextIterator.

ItemsInserted()

Purpose:

This method keeps track of items that have been inserted into the array at the specified index.

Access:

Protected

Prototype:

void ItemsInserted( USInt32 inCount,
ArrayIndexT inAtIndex );
Parameters:

The parameters for this method are:

 

USInt32  
inCount  
The number of items inserted.  
ArrayIndexT  
inAtIndex  
The index that is currently pointed to.  

Return:

None

ItemsRemoved()

Purpose:

This method keeps track of items starting at the specified index that have been removed from the array.

Access:

Protected

Prototype:

void ItemsRemoved( USInt32 inCount,
ArrayIndexT inAtIndex );
Parameters:

The parameters for this method are:

 

USInt32  
inCount  
The number of items removed.  
ArrayIndexT  
inAtIndex  
The index that is currently pointed to.  

Return:

None

Next()

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:

Public

Prototype:

Boolean Next( void *outItem, USInt32 &ioItemSize 
);

Boolean Next( void *outItem );
Parameters:

The parameters for these methods are:

 

void*  
outItem  
The pointer to the array item that is passed out upon exiting this method.  
USInt32&  
ioItemSize  
A reference to the size of the item retrieved from the array.  

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

Previous()

Purpose:

This method moves to the previous item in the array and passes back a copy of that item.

Access:

Public

Prototype:

Boolean Previous( void *outItem, USInt32 
&ioItemSize);

Boolean Previous( void *outItem );
Parameters:

The parameters for these methods are:

 

void*  
outItem  
The pointer to the array item that is passed out upon exiting this method.  
USInt32&  
ioItemSize  
A reference to the size of the item retrieved from the array.  

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

PtrToCurrent()

Purpose:

Return a pointer to the current item in the array and (optionally) pass back the item's size.

Access:

Public

Prototype:

void* PtrToCurrent( USInt32 &outItemSize );

void* PtrToCurrent();
Parameters:

The parameter for these methods is:

 

USInt32&  
outItemSize  
A reference to the size of the item retrieved from the array.  

Return:

Returns a pointer to the current item. Returns nil and item size of zero if there is no current item.

PtrToNext()

Purpose:

Return a pointer to the next item in the array and (optionally) pass back the item's size.

Access:

Public

Prototype:

void* PtrToNext( USInt32 &outItemSize );

void* PtrToNext();
Parameters:

The parameter for these methods is:

 

USInt32&  
outItemSize  
A reference to the size of the item retrieved from the array.  

Return:

Returns a pointer to the next item. Returns nil and item size of zero if there is no next item.

PtrToPrevious()

Purpose:

Return a pointer to the previous item in the array and (optionally) pass back the item's size.

Access:

Public

Prototype:

void* PtrToPrevious( USInt32 &outItemSize );

void* PtrToPrevious();
Parameters:

The parameter for these methods is:

 

USInt32&  
outItemSize  
A reference to the size of the item retrieved from the array.  

Return:

Returns a pointer to the previous item. Returns nil and item size of zero if there is no previous item.

ResetTo()

Purpose:

Reset the current item to the specified index value. The standard enumeration constants from_Start and from_End are recognized.

Access:

Public

Prototype:

void ResetTo( ArrayIndexT inPosition );
Parameters:

The parameter for this method is:

 

ArrayIndexT  
inPosition  
The position to set to, using the enumerations of from_End, index_AfterEnd, etc.  

Return:

None

SetNextIterator()

Purpose:

This method set the value of the mNextIterator data member to the value passed-in.

Access:

Protected

Prototype:

void SetNextIterator( LArrayIterator *inIterator 
);
Parameters:

The parameter for this method is:

 

LArrayIterator*  
inIterator  
The value to assign to mNextIterator.  

Return:

None

mNextIterator

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:

Protected

Prototype:

LArrayIterator *mNextIterator;

mArray

Purpose:

This data member stores a reference to the array of elements that are iterated over.

Access:

Protected

Prototype:

const LArray &mArray;

mCurrIndex

Purpose:

This data member stores the index of the array element currently pointed to.

Access:

Protected

Prototype:

ArrayIndexT mCurrIndex;

mNextIndex

Purpose:

This data member stores the index of the array element next in the array.

Access:

Protected

Prototype:

ArrayIndexT mNextIndex;

 


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: July 21, 2000