This reference page is linked to from the following overview topics: Data types & properties, Utility Classes.
Template class to contain an array of items.
#include <fbarray.h>
Public Member Functions |
|
FBArrayTemplate (int pItemPerBlock=10) | |
Constructor. |
|
~FBArrayTemplate () | |
Destructor. |
|
int | InsertAt (int pIndex, Type pItem) |
Insert pItem at pIndex.
|
|
void | RemoveAt (int pIndex) |
Remove item at pIndex. |
|
void | RemoveLast () |
Remove the last item in the array. |
|
bool | Remove (Type &pItem) |
Remove pItem from the array.
|
|
bool | RemoveIt (Type pItem) |
Remove pItem from the array.
|
|
void | Clear () |
Empty the array of all items. |
|
Type & | operator[] (int pIndex) const |
[] operator overload. |
|
void | SetAt (int pIndex, Type pItem) |
Set item at pIndex to
pItem. |
|
void | SetLast (Type pItem) |
Set the last item of the array. |
|
int | GetCount () const |
Get the number of items in the array.
|
|
void | SetCount (int pCount) |
Set the number of items in the array.
|
|
Type | GetAt (int pIndex) |
Get item at pIndex. |
|
Type | GetLast () |
Get last item of the array. |
|
int | Find (Type pItem) |
Find the index of pItem in the
array. |
|
int | Add (Type pItem) |
Add an item to the end of the array.
|
|
Type * | GetArray () |
Get a pointer to the array of items.
|
|
FBArrayTemplate< Type > & | operator= (const FBArrayTemplate< Type > &pArrayTemplate) |
Copy array of pointers without copying the
associated objects. |
FBArrayTemplate | ( | int | pItemPerBlock = 10 |
) | [inline] |
~FBArrayTemplate | ( | ) | [inline] |
int InsertAt | ( | int | pIndex, |
Type | pItem | ||
) | [inline] |
Insert pItem at pIndex.
pIndex | Index to insert at. |
pItem | Item to insert. |
Definition at line 100 of file fbarray.h.
{ if (pIndex>mArrayCount) { pIndex = mArrayCount; } if (mArrayCount>= mBlockCount*mItemPerBlock) { // must allocate or reallocate block of items mBlockCount++; mArray = (Type *)FBRealloc( mArray,(size_t)(mBlockCount*mItemPerBlock*sizeof(Type))); } if (pIndex<mArrayCount) { // This is an insert memmove (&(mArray[pIndex+1]),&(mArray[pIndex]),sizeof(Type)*(mArrayCount-pIndex)); } mArray[pIndex] = pItem; mArrayCount++; return pIndex; }
void RemoveAt | ( | int | pIndex | ) | [inline] |
Remove item at pIndex.
pIndex | Index to remove item from. |
Definition at line 129 of file fbarray.h.
{ assert( pIndex<mArrayCount ); if (pIndex+1<mArrayCount) { memmove (&(mArray[pIndex]),&(mArray[pIndex+1]),sizeof(Type)*(mArrayCount-pIndex-1)); } mArrayCount --; memset (&(mArray[mArrayCount]),0,sizeof(Type)); // Cleanup last element to make sure we don't access it later }
void RemoveLast | ( | ) | [inline] |
bool Remove | ( | Type & | pItem | ) | [inline] |
Remove pItem from the array.
pItem | Item to remove. |
bool RemoveIt | ( | Type | pItem | ) | [inline] |
Remove pItem from the array.
pItem | Item to remove. |
void Clear | ( | ) | [inline] |
Type& operator[] | ( | int | pIndex | ) | const [inline] |
void SetAt | ( | int | pIndex, |
Type | pItem | ||
) | [inline] |
void SetLast | ( | Type | pItem | ) | [inline] |
int GetCount | ( | ) | const [inline] |
void SetCount | ( | int | pCount | ) | [inline] |
Set the number of items in the array.
Definition at line 221 of file fbarray.h.
{ if (pCount > mArrayCount) { if( pCount ) { const int lTempNewBlockCount = ( (int) (mArrayCount+pCount + mItemPerBlock - 1 ) / mItemPerBlock ); const int lNewBlockCount = (lTempNewBlockCount > 1 ? lTempNewBlockCount : 1); const int lOldArraySize = mArrayCount*sizeof(Type); const int lNewArraySize = lNewBlockCount*mItemPerBlock*sizeof(Type); if( lNewBlockCount > (int) mBlockCount ) { mArray = (Type *)FBRealloc( mArray, (size_t) lNewArraySize ); mBlockCount = lNewBlockCount; } memset( ((char *)mArray) + lOldArraySize, 0, (size_t) (lNewArraySize-lOldArraySize) ); mArrayCount += pCount; } } else { mArrayCount = pCount; } }
Type GetAt | ( | int | pIndex | ) | [inline] |
Type GetLast | ( | ) | [inline] |
int Find | ( | Type | pItem | ) | [inline] |
Find the index of pItem in the array.
pItem | Item to look for in the array. |
Definition at line 270 of file fbarray.h.
{ int Count; for (Count=0; Count<mArrayCount; Count++) { if (mArray[Count]==pItem) { return Count; } } return -1; }
int Add | ( | Type | pItem | ) | [inline] |
Type* GetArray | ( | ) | [inline] |
FBArrayTemplate<Type>& operator= | ( | const FBArrayTemplate< Type > & | pArrayTemplate | ) | [inline] |
Copy array of pointers without copying the associated objects.
pArrayTemplate | Array to copy from. |