FBArrayTemplate< Type > Class Template Reference
#include <fbarray.h>
template<class Type>
class ORSDK2019::FBArrayTemplate< Type >
Template class to contain an array of items.
- Note
- This utility template array only support plain old data structure (POD).
Definition at line 77 of file fbarray.h.
Constructor.
- Parameters
-
pItemPerBlock | Number of items per array block (default is 10). |
Definition at line 83 of file fbarray.h.
88 mItemPerBlock = pItemPerBlock;
Copy constructor.
Definition at line 92 of file fbarray.h.
99 *
this = pArrayTemplate;
Destructor.
Definition at line 103 of file fbarray.h.
void Clear()
Empty the array of all items.
Add an item to the end of the array.
- Parameters
-
pItem | Item to insert into the array. |
- Returns
- Index where pItem was inserted.
Definition at line 298 of file fbarray.h.
300 return InsertAt( mArrayCount,pItem );
int InsertAt(int pIndex, Type pItem)
Insert pItem at pIndex.
Empty the array of all items.
Definition at line 185 of file fbarray.h.
void FBFree(void *memblock)
General free function, actually calling standard function "free".
Find the index of pItem in the array.
- Parameters
-
pItem | Item to look for in the array. |
- Returns
- Index number of element found. Returns -1 if pItem was not found.
Definition at line 283 of file fbarray.h.
286 for (Count=0; Count<mArrayCount; Count++) {
287 if (mArray[Count]==pItem) {
Get a pointer to the array of items.
- Returns
- Pointer to the array of items.
- Warning
- Gives direct access to the array pointer!
Definition at line 307 of file fbarray.h.
Get item at pIndex.
- Parameters
-
pIndex | Index of desired item. |
- Returns
- Item specified by pIndex.
Definition at line 265 of file fbarray.h.
267 assert( pIndex<mArrayCount );
268 return mArray[pIndex];
Get the number of items in the array.
- Returns
- Number of items in the array.
Definition at line 227 of file fbarray.h.
Get last item of the array.
- Returns
- Last item of the array.
Definition at line 274 of file fbarray.h.
276 return mArray[mArrayCount-1];
int InsertAt |
( |
int |
pIndex, |
|
|
Type |
pItem |
|
) |
| |
|
inline |
Insert pItem at pIndex.
- Parameters
-
pIndex | Index to insert at. |
pItem | Item to insert. |
- Returns
- Actual insertion index where pItem was inserted.
Definition at line 113 of file fbarray.h.
115 if (pIndex>mArrayCount)
117 pIndex = mArrayCount;
120 if (mArrayCount>= mBlockCount*mItemPerBlock)
124 mArray = (Type *)
FBRealloc( mArray,(
size_t)(mBlockCount*mItemPerBlock*
sizeof(Type)));
127 if (pIndex<mArrayCount)
130 memmove (&(mArray[pIndex+1]),&(mArray[pIndex]),
sizeof(Type)*(mArrayCount-pIndex));
133 mArray[pIndex] = pItem;
void * FBRealloc(void *memblock, size_t size)
General allocation function, actually calling standard function "realloc".
Copy array of pointers without copying the associated objects.
- Parameters
-
pArrayTemplate | Array to copy from. |
- Returns
- Pointer to the this class.
Definition at line 316 of file fbarray.h.
318 if (
this != &pArrayTemplate)
322 mItemPerBlock = pArrayTemplate.mItemPerBlock;
324 SetCount(pArrayTemplate.GetCount());
325 memcpy(mArray, pArrayTemplate.mArray,
sizeof(Type) * pArrayTemplate.GetCount());
void SetCount(int pCount)
Set the number of items in the array.
void Clear()
Empty the array of all items.
Type& operator[] |
( |
int |
pIndex | ) |
const |
|
inline |
[] operator overload.
- Parameters
-
pIndex | Index of item to access. |
- Returns
- Item corresponding to pIndex.
Definition at line 199 of file fbarray.h.
201 assert( pIndex<mArrayCount );
202 return mArray[pIndex];
bool Remove |
( |
Type & |
pItem | ) |
|
|
inline |
Remove pItem from the array.
- Parameters
-
- Returns
- Operation was successful (true or false).
Definition at line 160 of file fbarray.h.
void RemoveAt(int pIndex)
Remove item at pIndex.
int Find(Type pItem)
Find the index of pItem in the array.
void RemoveAt |
( |
int |
pIndex | ) |
|
|
inline |
Remove item at pIndex.
- Parameters
-
pIndex | Index to remove item from. |
Definition at line 142 of file fbarray.h.
144 assert( pIndex<mArrayCount );
145 if (pIndex+1<mArrayCount) {
146 memmove (&(mArray[pIndex]),&(mArray[pIndex+1]),
sizeof(Type)*(mArrayCount-pIndex-1));
149 memset (&(mArray[mArrayCount]),0,
sizeof(Type));
bool RemoveIt |
( |
Type |
pItem | ) |
|
|
inline |
Remove pItem from the array.
- Parameters
-
- Returns
- Outcome of removal (true or false).
Definition at line 174 of file fbarray.h.
void RemoveAt(int pIndex)
Remove item at pIndex.
int Find(Type pItem)
Find the index of pItem in the array.
Remove the last item in the array.
Definition at line 154 of file fbarray.h.
void RemoveAt(int pIndex)
Remove item at pIndex.
void SetAt |
( |
int |
pIndex, |
|
|
Type |
pItem |
|
) |
| |
|
inline |
Set item at pIndex to pItem.
- Parameters
-
pIndex | Index of item to set. |
pItem | Item to copy into the array. |
Definition at line 209 of file fbarray.h.
211 assert( pIndex<mArrayCount );
212 mArray[pIndex] = pItem;
void SetCount |
( |
int |
pCount | ) |
|
|
inline |
Set the number of items in the array.
Definition at line 234 of file fbarray.h.
236 if (pCount > mArrayCount)
240 const int lTempNewBlockCount = ( (
int) (mArrayCount+pCount + mItemPerBlock - 1 ) / mItemPerBlock );
241 const int lNewBlockCount = (lTempNewBlockCount > 1 ? lTempNewBlockCount : 1);
243 const int lOldArraySize = mArrayCount*
sizeof(Type);
244 const int lNewArraySize = lNewBlockCount*mItemPerBlock*
sizeof(Type);
246 if( lNewBlockCount > (
int) mBlockCount )
248 mArray = (Type *)
FBRealloc( mArray, (
size_t) lNewArraySize );
249 mBlockCount = lNewBlockCount;
252 memset( ((
char *)mArray) + lOldArraySize, 0, (
size_t) (lNewArraySize-lOldArraySize) );
253 mArrayCount += pCount;
257 mArrayCount = pCount;
void * FBRealloc(void *memblock, size_t size)
General allocation function, actually calling standard function "realloc".
void SetLast |
( |
Type |
pItem | ) |
|
|
inline |
Set the last item of the array.
- Parameters
-
pItem | Item to copy as the last item of the array |
- Warning
- Will write over last item in the array!
Definition at line 219 of file fbarray.h.
221 SetAt(mArrayCount-1,pItem );
void SetAt(int pIndex, Type pItem)
Set item at pIndex to pItem.
The documentation for this class was generated from the following file: