This reference page is linked to from the following overview topics: FBX SDK 2014.
#include <fbxarray.h>
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.
ExportScene03/main.cxx, SwitchBinding/main.cxx, ViewScene/main.cxx, ViewScene/SceneCache.h, ViewScene/SceneContext.cxx, and ViewScene/SceneContext.h.
Definition at line 23 of file fbxarray.h.
Public Member Functions |
|
| FbxArray () | |
| Constructor. |
|
| FbxArray (const FbxArray &pArray) | |
| Copy constructor. |
|
| FbxArray (int pCapacity) | |
| Reserve 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.
|
|
| FbxArray | ( | ) | [inline] |
Copy constructor.
Definition at line 30 of file fbxarray.h.
: mSize(0), mCapacity(0), mArray(NULL){ *this = pArray; }
| FbxArray | ( | int | pCapacity | ) | [inline] |
Reserve constructor.
Definition at line 33 of file fbxarray.h.
| ~FbxArray | ( | ) | [inline] |
Destructor.
Definition at line 37 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 44 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 71 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 79 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 88 of file fbxarray.h.
{ return mSize; }
| int Capacity | ( | ) | const [inline] |
Retrieve the current allocated memory capacity of the array.
Definition at line 93 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 99 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 119 of file fbxarray.h.
{
return operator[](pIndex);
}
| T GetFirst | ( | ) | const [inline] |
Get the first element.
Definition at line 127 of file fbxarray.h.
{
return GetAt(0);
}
| T GetLast | ( | ) | const [inline] |
Get the last element.
Definition at line 135 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 144 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 158 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 171 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 192 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 205 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 213 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 222 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 236 of file fbxarray.h.
{
return RemoveAt(0);
}
| T RemoveLast | ( | ) | [inline] |
Remove the last element in the array.
Definition at line 244 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 252 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 267 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 297 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 304 of file fbxarray.h.
| T* GetArray | ( | ) | const [inline] |
Get pointer to internal array of elements.
Definition at line 316 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 323 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 333 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 343 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 353 of file fbxarray.h.
{
if( this != &pOther )
{
if( Resize(pOther.mSize) )
{
memcpy(mArray, pOther.mArray, pOther.mSize * sizeof(T));
}
}
return *this;
}