Class for array of basic elements such as pointers and basic types.
This class will not call constructor and destructor for elements, thus it is not suitable for object references. Memory allocations are always done in a single contiguous memory region.
Definition at line 23 of file fbxarray.h.
#include <fbxarray.h>
Public Member Functions | |
| FbxArray () | |
| Constructor. | |
| FbxArray (const FbxArray &pArray) | |
| Copy constructor. | |
| ~FbxArray () | |
| Destructor. | |
| int | InsertAt (const int pIndex, const T pElement) |
| Insert an element at the given position, growing the array if capacity is not sufficient. | |
| int | Add (const T pElement) |
| Append an element at the end of the array, growing the array if capacity is not sufficient. | |
| int | AddUnique (const T pElement) |
| Append an element at the end of array, if not already present, growing the array if capacity is not sufficient. | |
| int | Size () const |
| Retrieve the number of element contained in the array. | |
| int | Capacity () const |
| Retrieve the current allocated memory capacity of the array. | |
| T & | operator[] (int pIndex) const |
| Retrieve the element at given index position in the array. | |
| T | GetAt (const int pIndex) const |
| Returns the value of the element at given position in the array. | |
| T | GetFirst () const |
| Get the first element. | |
| T | GetLast () const |
| Get the last element. | |
| int | Find (const T pElement, const int pStartIndex=0) const |
| Find first matching element, from first to last. | |
| int | FindReverse (const T pElement, const int pStartIndex=FBXSDK_INT_MAX) const |
| Find first matching element, from last to first. | |
| bool | Reserve (const int pCapacity) |
| Request for allocation of additional memory without inserting new elements. | |
| void | SetAt (const int pIndex, const T pElement) |
| Set the element at given position in the array. | |
| void | SetFirst (const T pElement) |
| Set the value of the first element. | |
| void | SetLast (const T pElement) |
| Set the value of the last element. | |
| T | RemoveAt (const int pIndex) |
| Remove an element at the given position in the array. | |
| T | RemoveFirst () |
| Remove the first element in the array. | |
| T | RemoveLast () |
| Remove the last element in the array. | |
| bool | RemoveIt (const T pElement) |
| Remove first matching element in the array. | |
| bool | Resize (const int pSize) |
| Inserts or erases elements at the end such that Size() becomes pSize, increasing capacity if needed. | |
| bool | Grow (const int pSize) |
| Inserts elements at the end such that Size() will be increased to pSize, increasing capacity if needed. | |
| void | Clear () |
| Reset the number of element to zero and free the memory allocated. | |
| T * | GetArray () const |
| Get pointer to internal array of elements. | |
| operator T * () | |
| Cast operator. | |
| void | AddArray (const FbxArray< T > &pOther) |
| Append another array at the end of this array. | |
| void | AddArrayNoDuplicate (const FbxArray< T > &pOther) |
| Append the elements of another array at the end of this array if they are not present. | |
| void | RemoveArray (const FbxArray< T > &pOther) |
| Remove the elements of another array from this array is they are present. | |
| FbxArray< T > & | operator= (const FbxArray< T > &pOther) |
| Operator to copy elements of an array. | |
| int | GetCount () const |
| FBX_DEPRECATED void | Empty () |
| FBX_DEPRECATED int | FindAfter (int pAfterIndex, T pItem) const |
| FBX_DEPRECATED int | FindBefore (int pBeforeIndex, T pItem) const |
| FBX_DEPRECATED void | AddMultiple (int pItemCount) |
| FbxArray | ( | ) | [inline] |
Copy constructor.
Definition at line 30 of file fbxarray.h.
: mSize(0), mCapacity(0), mArray(NULL){ *this = pArray; }
| ~FbxArray | ( | ) | [inline] |
Destructor.
Definition at line 34 of file fbxarray.h.
{ Clear(); }
| int InsertAt | ( | const int | pIndex, |
| const T | pElement | ||
| ) | [inline] |
Insert an element at the given position, growing the array if capacity is not sufficient.
| pIndex | Position where to insert the element. Must be a positive value. |
| pElement | Element to insert in the array. |
Definition at line 41 of file fbxarray.h.
{
FBX_ASSERT_RETURN_VALUE(pIndex >= 0, -1);
int lIndex = FbxMin(pIndex, mSize);
if( mSize >= mCapacity )
{
int lNewCapacity = FbxMax(mCapacity * 2, 1); //Double capacity
T* lArray = Allocate(lNewCapacity);
FBX_ASSERT_RETURN_VALUE(lArray, -1);
mArray = lArray;
mCapacity = lNewCapacity;
}
if( lIndex < mSize ) //Move elements to leave a space open to insert the new element
{
memmove(&mArray[lIndex + 1], &mArray[lIndex], (mSize - lIndex) * sizeof(T));
}
memcpy(&mArray[lIndex], &pElement, sizeof(T));
mSize++;
return lIndex;
}
| int Add | ( | const T | pElement | ) | [inline] |
Append an element at the end of the array, growing the array if capacity is not sufficient.
| pElement | Element to append to the array. |
Definition at line 68 of file fbxarray.h.
{
return InsertAt(mSize, pElement);
}
| int AddUnique | ( | const T | pElement | ) | [inline] |
Append an element at the end of array, if not already present, growing the array if capacity is not sufficient.
| pElement | Element to append to the array. |
Definition at line 76 of file fbxarray.h.
| int Size | ( | ) | const [inline] |
Retrieve the number of element contained in the array.
To increase the capacity without increasing the size, please use Reserve().
Definition at line 85 of file fbxarray.h.
{ return mSize; }
| int Capacity | ( | ) | const [inline] |
Retrieve the current allocated memory capacity of the array.
Definition at line 90 of file fbxarray.h.
{ return mCapacity; }
| T& operator[] | ( | int | pIndex | ) | const [inline] |
Retrieve the element at given index position in the array.
| pIndex | Position of element in the array. |
Definition at line 96 of file fbxarray.h.
{
#ifdef _DEBUG
FBX_ASSERT_MSG(pIndex >= 0, "Index is out of range!");
if( pIndex >= mSize )
{
if( pIndex < mCapacity )
{
FBX_ASSERT_NOW("Index is out of range, but not outside of capacity! Call SetAt() to use reserved memory.");
}
else FBX_ASSERT_NOW("Index is out of range!");
}
#endif
return (T&)mArray[pIndex];
}
| T GetAt | ( | const int | pIndex | ) | const [inline] |
Returns the value of the element at given position in the array.
| pIndex | Position of element in the array. |
Definition at line 116 of file fbxarray.h.
{
return operator[](pIndex);
}
| T GetFirst | ( | ) | const [inline] |
Get the first element.
Definition at line 124 of file fbxarray.h.
{
return GetAt(0);
}
| T GetLast | ( | ) | const [inline] |
Get the last element.
Definition at line 132 of file fbxarray.h.
{
return GetAt(mSize-1);
}
| int Find | ( | const T | pElement, |
| const int | pStartIndex = 0 |
||
| ) | const [inline] |
Find first matching element, from first to last.
| pElement | The element to be compared to each of the elements. |
| pStartIndex | The position to start searching from. |
Definition at line 141 of file fbxarray.h.
{
FBX_ASSERT_RETURN_VALUE(pStartIndex >= 0, -1);
for( int i = pStartIndex; i < mSize; ++i )
{
if( GetAt(i) == pElement ) return i;
}
return -1;
}
| int FindReverse | ( | const T | pElement, |
| const int | pStartIndex = FBXSDK_INT_MAX |
||
| ) | const [inline] |
Find first matching element, from last to first.
| pElement | The element to be compared to each of the elements. |
| pStartIndex | The position to start searching from. |
Definition at line 155 of file fbxarray.h.
| bool Reserve | ( | const int | pCapacity | ) | [inline] |
Request for allocation of additional memory without inserting new elements.
After the memory has been reserved, please use SetAt() to initialize elements.
| pCapacity | The number of additional element memory allocation requested. |
true if the memory allocation succeeded or if the capacity is unchanged, false otherwise. Definition at line 168 of file fbxarray.h.
{
FBX_ASSERT_RETURN_VALUE(pCapacity > 0, false);
if( pCapacity > mCapacity )
{
T* lArray = Allocate(pCapacity);
FBX_ASSERT_RETURN_VALUE(lArray, false);
mArray = lArray;
mCapacity = pCapacity;
//Initialize new memory to zero
memset(&mArray[mSize], 0, (mCapacity - mSize) * sizeof(T));
}
return true;
}
| void SetAt | ( | const int | pIndex, |
| const T | pElement | ||
| ) | [inline] |
Set the element at given position in the array.
| pIndex | Position of element in the array. |
| pElement | The new element. |
Definition at line 189 of file fbxarray.h.
{
if( pIndex >= mSize )
{
FBX_ASSERT_RETURN(pIndex < mCapacity);
mSize = pIndex + 1;
}
memcpy(&mArray[pIndex], &pElement, sizeof(T));
}
| void SetFirst | ( | const T | pElement | ) | [inline] |
Set the value of the first element.
| pElement | The new value of the last element. |
Definition at line 202 of file fbxarray.h.
{
SetAt(0, pElement);
}
| void SetLast | ( | const T | pElement | ) | [inline] |
Set the value of the last element.
| pElement | The new value of the last element. |
Definition at line 210 of file fbxarray.h.
{
SetAt(mSize-1, pElement);
}
| T RemoveAt | ( | const int | pIndex | ) | [inline] |
Remove an element at the given position in the array.
| pIndex | Position of the element to remove. |
Definition at line 219 of file fbxarray.h.
{
T lElement = GetAt(pIndex);
if( pIndex + 1 < mSize )
{
memmove(&mArray[pIndex], &mArray[pIndex + 1], (mSize - pIndex - 1) * sizeof(T));
}
mSize--;
return lElement;
}
| T RemoveFirst | ( | ) | [inline] |
Remove the first element in the array.
Definition at line 233 of file fbxarray.h.
{
return RemoveAt(0);
}
| T RemoveLast | ( | ) | [inline] |
Remove the last element in the array.
Definition at line 241 of file fbxarray.h.
{
return RemoveAt(mSize-1);
}
| bool RemoveIt | ( | const T | pElement | ) | [inline] |
Remove first matching element in the array.
| pElement | Element to be removed. |
true if a matching element is found and removed, false otherwise. Definition at line 249 of file fbxarray.h.
| bool Resize | ( | const int | pSize | ) | [inline] |
Inserts or erases elements at the end such that Size() becomes pSize, increasing capacity if needed.
Please use SetAt() to initialize any new elements.
| pSize | The new count of elements to set the array to. Must be greater or equal to zero. |
true if the memory (re)allocation succeeded, false otherwise. Definition at line 264 of file fbxarray.h.
{
if( pSize == 0 )
{
Clear();
return true;
}
FBX_ASSERT_RETURN_VALUE(pSize > 0, false);
if( pSize != mCapacity )
{
T* lArray = Allocate(pSize);
FBX_ASSERT_RETURN_VALUE(lArray, false);
mArray = lArray;
}
if( pSize > mCapacity ) //Initialize new memory to zero
{
memset(&mArray[mSize], 0, (pSize - mSize) * sizeof(T));
}
mSize = pSize;
mCapacity = pSize;
return true;
}
| bool Grow | ( | const int | pSize | ) | [inline] |
Inserts elements at the end such that Size() will be increased to pSize, increasing capacity if needed.
Please use SetAt() to initialize new elements.
| pSize | The number of elements to insert into the array. Must be greater or equal to zero. |
true if the memory (re)allocation succeeded, false otherwise. Definition at line 294 of file fbxarray.h.
{
return Resize(mSize + pSize);
}
| void Clear | ( | ) | [inline] |
Reset the number of element to zero and free the memory allocated.
Definition at line 301 of file fbxarray.h.
| T* GetArray | ( | ) | const [inline] |
Get pointer to internal array of elements.
Definition at line 313 of file fbxarray.h.
{ return mArray ? (T*)mArray : NULL; }
| operator T * | ( | ) | [inline] |
| void AddArray | ( | const FbxArray< T > & | pOther | ) | [inline] |
Append another array at the end of this array.
| pOther | The other array to append to this array. |
Definition at line 320 of file fbxarray.h.
{
if( Grow(pOther.mSize) )
{
memcpy(&mArray[mSize - pOther.mSize], pOther.mArray, pOther.mSize * sizeof(T));
}
}
| void AddArrayNoDuplicate | ( | const FbxArray< T > & | pOther | ) | [inline] |
Append the elements of another array at the end of this array if they are not present.
| pArray | Another array. |
Definition at line 330 of file fbxarray.h.
{
for( int i = 0, c = pOther.mSize; i < c; ++i )
{
AddUnique(pOther[i]);
}
}
| void RemoveArray | ( | const FbxArray< T > & | pOther | ) | [inline] |
Remove the elements of another array from this array is they are present.
| pArray | Another array. |
Definition at line 340 of file fbxarray.h.
{
for( int i = 0, c = pOther.mSize; i < c; ++i )
{
RemoveIt(pOther[i]);
}
}
Operator to copy elements of an array.
Definition at line 350 of file fbxarray.h.
{
if( this != &pOther )
{
if( Resize(pOther.mSize) )
{
memcpy(mArray, pOther.mArray, pOther.mSize * sizeof(T));
}
}
return *this;
}
| int GetCount | ( | ) | const [inline] |
| FBX_DEPRECATED void Empty | ( | ) | [inline] |
| FBX_DEPRECATED int FindAfter | ( | int | pAfterIndex, |
| T | pItem | ||
| ) | const [inline] |
Definition at line 368 of file fbxarray.h.
{ return Find(pItem, pAfterIndex+1); }
| FBX_DEPRECATED int FindBefore | ( | int | pBeforeIndex, |
| T | pItem | ||
| ) | const [inline] |
Definition at line 369 of file fbxarray.h.
{ return FindReverse(pItem, pBeforeIndex-1); }
| FBX_DEPRECATED void AddMultiple | ( | int | pItemCount | ) | [inline] |