FBX C++ API Reference
FbxArray< T, Alignment > Class Template Reference

Class for array of basic elements such as pointers and basic types. More...

#include <fbxarray.h>

Classes

struct  tData
 

Public Types

typedef int(* CompareFunc) (const void *, const void *)
 Element compare function pointer definition. More...
 

Public Member Functions

 FbxArray ()
 Constructor. More...
 
 FbxArray (const int pCapacity)
 Reserve constructor. More...
 
 FbxArray (const FbxArray &pArray)
 Copy constructor. More...
 
 ~FbxArray ()
 Destructor. More...
 
int InsertAt (const int pIndex, const T &pElement, bool pCompact=false)
 Insert an element at the given position, growing the array if capacity is not sufficient. More...
 
int Add (const T &pElement)
 Append an element at the end of the array, doubling the array if capacity is not sufficient. More...
 
int AddUnique (const T &pElement)
 Append an element at the end of array, if not already present, doubling the array if capacity is not sufficient. More...
 
int AddCompact (const T &pElement)
 Append an element at the end of the array, growing the array by one element if capacity is not sufficient. More...
 
int Size () const
 Retrieve the number of element contained in the array. More...
 
int Capacity () const
 Retrieve the current allocated memory capacity of the array. More...
 
T & operator[] (const int pIndex) const
 Retrieve a reference of the element at given index position in the array. More...
 
GetAt (const int pIndex) const
 Retrieve a copy of the element at given index position in the array. More...
 
GetFirst () const
 Retrieve a copy of the first element. More...
 
GetLast () const
 Retrieve a copy of the last element. More...
 
int Find (const T &pElement, const int pStartIndex=0) const
 Find first matching element, from first to last. More...
 
int FindReverse (const T &pElement, const int pStartIndex=0x7fffffff) const
 Find first matching element, from last to first. More...
 
bool Reserve (const int pCapacity)
 Request for allocation of additional memory without inserting new elements. More...
 
void SetAt (const int pIndex, const T &pElement)
 Set the element at given position in the array. More...
 
void SetFirst (const T &pElement)
 Set the value of the first element. More...
 
void SetLast (const T &pElement)
 Set the value of the last element. More...
 
RemoveAt (const int pIndex)
 Remove an element at the given position in the array. More...
 
RemoveFirst ()
 Remove the first element in the array. More...
 
RemoveLast ()
 Remove the last element in the array. More...
 
bool RemoveIt (const T &pElement)
 Remove first matching element in the array. More...
 
void RemoveRange (const int pIndex, const int pCount)
 Remove a range of elements at the given position in the array. More...
 
bool ResizeUninitialized (const int pSize, bool pPreserveCapacityIfPossible=false)
 Inserts or erases elements at the end such that Size() becomes pSize, increasing capacity if needed. More...
 
bool Resize (const int pSize, bool pPreserveCapacityIfPossible=false)
 Inserts or erases elements at the end such that Size() becomes pSize, increasing capacity if needed. More...
 
bool Grow (const int pSize)
 Increase size of array by the specified size. More...
 
bool Shrink (const int pSize)
 Reduce size of array by the specified size. More...
 
bool Compact ()
 Compact the array so that its capacity is the same as its size. More...
 
void Clear ()
 Reset the number of element to zero and free the memory allocated. More...
 
void Sort (CompareFunc pCompareFunc)
 Sort the array using the specified compare function pointer. More...
 
T * GetArray () const
 Get pointer to internal array of elements. More...
 
 operator T * () const
 Cast operator. More...
 
void AddArray (const FbxArray< T > &pOther)
 Append another array at the end of this array. More...
 
void AddArrayNoDuplicate (const FbxArray< T > &pOther)
 Append the elements of another array at the end of this array if they are not present. More...
 
void RemoveArray (const FbxArray< T > &pOther)
 Remove the elements of another array from this array is they are present. More...
 
FbxArray< T > & operator= (const FbxArray< T > &pOther)
 Operator to copy elements of an array. More...
 
bool operator== (const FbxArray< T > &pOther) const
 Operator to compare elements of an array. More...
 

Protected Attributes

struct FbxArray::tDatamData
 

Detailed Description

template<class T, const int Alignment = 16>
class FbxArray< T, Alignment >

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.

Examples:
ExportScene03/main.cxx, SwitchBinding/main.cxx, ViewScene/main.cxx, ViewScene/SceneCache.h, ViewScene/SceneContext.cxx, and ViewScene/SceneContext.h.

Definition at line 37 of file fbxarray.h.

Member Typedef Documentation

typedef int(* CompareFunc) (const void *, const void *)

Element compare function pointer definition.

Definition at line 52 of file fbxarray.h.

Constructor & Destructor Documentation

FbxArray ( )
inline

Constructor.

Definition at line 55 of file fbxarray.h.

55 : mData(NULL){}
#define NULL
Definition: fbxarch.h:213
struct FbxArray::tData * mData
FbxArray ( const int  pCapacity)
inline

Reserve constructor.

Definition at line 58 of file fbxarray.h.

58 : mData(NULL){ if( pCapacity > 0 ) Reserve(pCapacity); }
#define NULL
Definition: fbxarch.h:213
struct FbxArray::tData * mData
bool Reserve(const int pCapacity)
Request for allocation of additional memory without inserting new elements.
Definition: fbxarray.h:243
FbxArray ( const FbxArray< T, Alignment > &  pArray)
inline

Copy constructor.

Definition at line 61 of file fbxarray.h.

61 : mData(NULL){ *this = pArray; }
#define NULL
Definition: fbxarch.h:213
struct FbxArray::tData * mData
~FbxArray ( )
inline

Destructor.

Remarks
The destructor for each element will not be called.

Definition at line 65 of file fbxarray.h.

65 { Clear(); }
void Clear()
Reset the number of element to zero and free the memory allocated.
Definition: fbxarray.h:490

Member Function Documentation

int InsertAt ( const int  pIndex,
const T &  pElement,
bool  pCompact = false 
)
inline

Insert an element at the given position, growing the array if capacity is not sufficient.

Parameters
pIndexPosition where to insert the element. Must be a positive value.
pElementElement to insert in the array.
pCompactIf true and capacity is exceeded, grow capacity by one, otherwise double capacity (default).
Returns
-1 if insert failed, otherwise the position of the inserted element in the array.
Remarks
If the given index is greater than Size(), the element is appended at the end. Use compact mode only if you need to save memory.

Definition at line 73 of file fbxarray.h.

74  {
75  FBX_ASSERT_RETURN_VALUE(pIndex >= 0, -1);
76  int lIndex = FbxMin(pIndex, GetSize());
77  if( GetSize() >= GetCapacity() )
78  {
79  T lElement = pElement; //Copy element because we might move memory
80  int lNewCapacity = FbxMax(pCompact ? GetCapacity() + 1 : GetCapacity() * 2, 1); //We always double capacity when not compacting
81  Allocate(lNewCapacity);
82  FBX_ASSERT_RETURN_VALUE(mData, -1);
83  mData->mCapacity = lNewCapacity;
84  return InsertAt(pIndex, lElement); //Insert copied element because reference might be moved
85  }
86 
87  if( lIndex < GetSize() ) //Move elements to leave a space open to insert the new element
88  {
89  //If pElement is inside memmove range, copy element and insert copy instead
90  if( (&pElement >= &GetArray()[lIndex]) && (&pElement < &GetArray()[GetSize()]) )
91  {
92  T lElement = pElement;
93  return InsertAt(pIndex, lElement);
94  }
95  memmove(&GetArray()[lIndex + 1], &GetArray()[lIndex], (GetSize() - lIndex) * sizeof(T));
96  }
97 
98  memcpy(&GetArray()[lIndex], &pElement, sizeof(T));
99  mData->mSize++;
100 
101  return lIndex;
102  }
FbxChar FbxMax(const FbxChar)
Definition: fbxtypes.h:173
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
struct FbxArray::tData * mData
FbxChar FbxMin(const FbxChar)
Definition: fbxtypes.h:162
int InsertAt(const int pIndex, const T &pElement, bool pCompact=false)
Insert an element at the given position, growing the array if capacity is not sufficient.
Definition: fbxarray.h:73
int Add ( const T &  pElement)
inline

Append an element at the end of the array, doubling the array if capacity is not sufficient.

Parameters
pElementElement to append to the array.
Returns
-1 if add failed, otherwise the position of the added element in the array.
Remarks
This function is the optimized version of InsertAt(GetSize(), pElement) which, by skipping some validation tests, can provide up to 33% speed gains.

Definition at line 108 of file fbxarray.h.

109  {
110  int lIndex = GetSize();
111 
112  if (lIndex >= GetCapacity())
113  {
114  T lElement = pElement; //Copy element because we might move memory
115  int lNewCapacity = FbxMax(GetCapacity() * 2, 1); //We always double capacity
116  Allocate(lNewCapacity);
117  FBX_ASSERT_RETURN_VALUE(mData, -1);
118  mData->mCapacity = lNewCapacity;
119  return Add(lElement); //Insert copied element because reference might be moved
120  }
121 
122  memcpy(&GetArray()[lIndex], &pElement, sizeof(T));
123  mData->mSize++;
124 
125  return lIndex;
126  }
int Add(const T &pElement)
Append an element at the end of the array, doubling the array if capacity is not sufficient.
Definition: fbxarray.h:108
FbxChar FbxMax(const FbxChar)
Definition: fbxtypes.h:173
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
struct FbxArray::tData * mData
int AddUnique ( const T &  pElement)
inline

Append an element at the end of array, if not already present, doubling the array if capacity is not sufficient.

Parameters
pElementElement to append to the array.
Returns
-1 if add failed, otherwise the position of the added element in the array.

Definition at line 131 of file fbxarray.h.

132  {
133  int lIndex = Find(pElement);
134  return ( lIndex == -1 ) ? Add(pElement) : lIndex;
135  }
int Add(const T &pElement)
Append an element at the end of the array, doubling the array if capacity is not sufficient.
Definition: fbxarray.h:108
int Find(const T &pElement, const int pStartIndex=0) const
Find first matching element, from first to last.
Definition: fbxarray.h:208
int AddCompact ( const T &  pElement)
inline

Append an element at the end of the array, growing the array by one element if capacity is not sufficient.

Parameters
pElementElement to append to the array.
Returns
-1 if add failed, otherwise the position of the added element in the array.

Definition at line 140 of file fbxarray.h.

141  {
142  return InsertAt(GetSize(), pElement, true);
143  }
int InsertAt(const int pIndex, const T &pElement, bool pCompact=false)
Insert an element at the given position, growing the array if capacity is not sufficient.
Definition: fbxarray.h:73
int Size ( ) const
inline

Retrieve the number of element contained in the array.

To increase the capacity without increasing the size, please use Reserve().

Returns
The number of element in the array.
Remarks
The size of the array cannot exceed its capacity.

Definition at line 148 of file fbxarray.h.

148 { return GetSize(); }
int Capacity ( ) const
inline

Retrieve the current allocated memory capacity of the array.

Returns
The capacity of the array in number of element.
Remarks
The capacity will always be greater or equal to its size.

Definition at line 153 of file fbxarray.h.

153 { return GetCapacity(); }
T& operator[] ( const int  pIndex) const
inline

Retrieve a reference of the element at given index position in the array.

Parameters
pIndexPosition of element in the array.
Returns
A reference to the element at the specified position in the array.
Remarks
No error will be thrown if the index is out of bounds.

Definition at line 159 of file fbxarray.h.

160  {
161  if (pIndex < 0)
162  {
163  FBX_THROW("Index is out of range!");
164  }
165 
166  if (pIndex >= GetSize())
167  {
168  if (pIndex < GetCapacity())
169  {
170  FBX_THROW("Index is out of range, but not outside of capacity! Call SetAt() to use reserved memory.");
171  }
172 
173  FBX_THROW("Index is out of range!");
174  }
175 
176  return GetArray()[pIndex];
177  }
#define FBX_THROW(x)
Definition: fbxarray.h:29
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
T GetAt ( const int  pIndex) const
inline

Retrieve a copy of the element at given index position in the array.

Parameters
pIndexPosition of element in the array.
Returns
The value of the element at the specified position in the array.
Remarks
No error will be thrown if the index is out of bounds.

Definition at line 183 of file fbxarray.h.

184  {
185  return operator[](pIndex);
186  }
T & operator[](const int pIndex) const
Retrieve a reference of the element at given index position in the array.
Definition: fbxarray.h:159
T GetFirst ( ) const
inline

Retrieve a copy of the first element.

Returns
Copy of the first element.
Remarks
The array should have at least one element and no error will be thrown if the array is empty.

Definition at line 191 of file fbxarray.h.

192  {
193  return GetAt(0);
194  }
T GetAt(const int pIndex) const
Retrieve a copy of the element at given index position in the array.
Definition: fbxarray.h:183
T GetLast ( ) const
inline

Retrieve a copy of the last element.

Returns
Copy of the last element.
Remarks
The array should have at least one element and no error will be thrown if the array is empty.

Definition at line 199 of file fbxarray.h.

200  {
201  return GetAt(GetSize() - 1);
202  }
T GetAt(const int pIndex) const
Retrieve a copy of the element at given index position in the array.
Definition: fbxarray.h:183
int Find ( const T &  pElement,
const int  pStartIndex = 0 
) const
inline

Find first matching element, from first to last.

Parameters
pElementThe element to be compared to each of the elements.
pStartIndexThe position to start searching from.
Returns
Position of first matching element or -1 if there is no matching element.

Definition at line 208 of file fbxarray.h.

209  {
210  const int size = GetSize();
211 
212  FBX_ASSERT_RETURN_VALUE(pStartIndex >= 0, -1);
213  FBX_ASSERT_RETURN_VALUE(size >= 0, -1);
214 
215  for (int i = pStartIndex; i < size; ++i)
216  {
217  if (GetArray()[i] == pElement) return i;
218  }
219  return -1;
220  }
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
int FindReverse ( const T &  pElement,
const int  pStartIndex = 0x7fffffff 
) const
inline

Find first matching element, from last to first.

Parameters
pElementThe element to be compared to each of the elements.
pStartIndexThe position to start searching from.
Returns
Position of first matching element or -1 if there is no matching element.

Definition at line 226 of file fbxarray.h.

227  {
228  const int size = GetSize();
229 
230  FBX_ASSERT_RETURN_VALUE(size > 0, -1);
231 
232  for (int i = FbxMin(pStartIndex, size - 1); i >= 0; --i)
233  {
234  if (GetArray()[i] == pElement) return i;
235  }
236  return -1;
237  }
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
FbxChar FbxMin(const FbxChar)
Definition: fbxtypes.h:162
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.

Parameters
pCapacityThe number of additional element memory allocation requested.
Returns
true if the memory allocation succeeded or if the capacity is unchanged, false otherwise.
Remarks
If the requested capacity is less than or equal to the current capacity, this call has no effect. In either case, Size() is unchanged.

Definition at line 243 of file fbxarray.h.

244  {
245  FBX_ASSERT_RETURN_VALUE(pCapacity >= 0, false);
246  if( pCapacity > GetCapacity() )
247  {
248  Allocate(pCapacity);
249  FBX_ASSERT_RETURN_VALUE(mData, false);
250  mData->mCapacity = pCapacity;
251 
252  //Initialize new memory to zero
253  memset(&GetArray()[GetSize()], 0, (GetCapacity() - GetSize()) * sizeof(T));
254  }
255  return true;
256  }
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
struct FbxArray::tData * mData
void SetAt ( const int  pIndex,
const T &  pElement 
)
inline

Set the element at given position in the array.

Parameters
pIndexPosition of element in the array.
pElementThe new element.
Remarks
If the index is outside range, and outside capacity, this call has no effect. However, if index is within capacity range, element count is increased such that Size() will become pIndex + 1.

Definition at line 263 of file fbxarray.h.

264  {
265  FBX_ASSERT_RETURN(pIndex >= 0 && pIndex < GetCapacity());
266  if( pIndex >= GetSize() ) mData->mSize = pIndex + 1;
267 
268  T* const array = GetArray();
269  if (array) memcpy(&array[pIndex], &pElement, sizeof(T));
270  }
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
struct FbxArray::tData * mData
void SetFirst ( const T &  pElement)
inline

Set the value of the first element.

Parameters
pElementThe new value of the last element.
Remarks
The array should have at least one element and no error will be thrown if the array is empty.

Definition at line 275 of file fbxarray.h.

276  {
277  SetAt(0, pElement);
278  }
void SetAt(const int pIndex, const T &pElement)
Set the element at given position in the array.
Definition: fbxarray.h:263
void SetLast ( const T &  pElement)
inline

Set the value of the last element.

Parameters
pElementThe new value of the last element.
Remarks
The array should have at least one element and no error will be thrown if the array is empty.

Definition at line 283 of file fbxarray.h.

284  {
285  SetAt(GetSize() - 1, pElement);
286  }
void SetAt(const int pIndex, const T &pElement)
Set the element at given position in the array.
Definition: fbxarray.h:263
T RemoveAt ( const int  pIndex)
inline

Remove an element at the given position in the array.

Parameters
pIndexPosition of the element to remove.
Returns
Removed element.
Remarks
No error will be thrown if the index is out of bounds.

Definition at line 292 of file fbxarray.h.

293  {
294  const int size = GetSize();
295  const int index = pIndex + 1;
296  if (index < 0 || index > size)
297  {
298  FBX_THROW("Index is out of range!");
299  }
300 
301  T lElement = GetAt(pIndex);
302  if (index < size)
303  {
304  memmove(&GetArray()[pIndex], &GetArray()[index], (size - pIndex - 1) * sizeof(T));
305  }
306  mData->mSize--;
307  return lElement;
308  }
T GetAt(const int pIndex) const
Retrieve a copy of the element at given index position in the array.
Definition: fbxarray.h:183
#define FBX_THROW(x)
Definition: fbxarray.h:29
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
struct FbxArray::tData * mData
T RemoveFirst ( )
inline

Remove the first element in the array.

Returns
Removed element.
Remarks
The array should have at least one element and no error will be thrown if the array is empty.

Definition at line 313 of file fbxarray.h.

314  {
315  return RemoveAt(0);
316  }
T RemoveAt(const int pIndex)
Remove an element at the given position in the array.
Definition: fbxarray.h:292
T RemoveLast ( )
inline

Remove the last element in the array.

Returns
Removed element.
Remarks
The array should have at least one element and no error will be thrown if the array is empty.

Definition at line 321 of file fbxarray.h.

322  {
323  return RemoveAt(GetSize() - 1);
324  }
T RemoveAt(const int pIndex)
Remove an element at the given position in the array.
Definition: fbxarray.h:292
bool RemoveIt ( const T &  pElement)
inline

Remove first matching element in the array.

Parameters
pElementElement to be removed.
Returns
true if a matching element is found and removed, false otherwise.

Definition at line 329 of file fbxarray.h.

330  {
331  int Index = Find(pElement);
332  if( Index >= 0 )
333  {
334  RemoveAt(Index);
335  return true;
336  }
337  return false;
338  }
T RemoveAt(const int pIndex)
Remove an element at the given position in the array.
Definition: fbxarray.h:292
int Find(const T &pElement, const int pStartIndex=0) const
Find first matching element, from first to last.
Definition: fbxarray.h:208
void RemoveRange ( const int  pIndex,
const int  pCount 
)
inline

Remove a range of elements at the given position in the array.

Parameters
pIndexBegin position of the elements to remove.
pCountThe count of elements to remove.
Returns
true if successful, otherwise false.
Remarks
This function re-use the memory already allocated

Definition at line 345 of file fbxarray.h.

346  {
347  const int size = GetSize();
348  if (size == 0)
349  // the array is already empty (or not allocated yet)
350  // no point in continuing
351  return;
352 
353  FBX_ASSERT(GetArray() != NULL);
354  FBX_ASSERT_RETURN(pCount > 0);
355  FBX_ASSERT_RETURN(pIndex >= 0);
356 
357  size_t lastItem = pIndex + pCount;
358  FBX_ASSERT_RETURN(lastItem >= 0);
359  FBX_ASSERT_RETURN(lastItem <= (size_t)size);
360  FBX_ASSERT_RETURN(lastItem < FBXSDK_INT_MAX);
361 
362  if (lastItem < (size_t)size)
363  {
364  memmove(&GetArray()[pIndex], &GetArray()[pIndex + pCount], (size - pIndex - pCount) * (unsigned)sizeof(T));
365  }
366 
367  if (mData)
368  {
369  mData->mSize -= pCount;
370  }
371  }
#define NULL
Definition: fbxarch.h:213
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
struct FbxArray::tData * mData
#define FBXSDK_INT_MAX
Definition: fbxtypes.h:119
bool ResizeUninitialized ( const int  pSize,
bool  pPreserveCapacityIfPossible = false 
)
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.

Parameters
pSizeThe new count of elements to set the array to. Must be greater or equal to zero.
pPreserveCapacityIfPossibleIf the new count will fit into the existing allocation, do not adjust the capacity.
Returns
true if the memory (re)allocation succeeded, false otherwise.
Remarks
If the requested element count is less than or equal to the current count, elements are freed from memory. Otherwise, the array grows and elements are unchanged. The new array memory is not cleared to 0.

Definition at line 378 of file fbxarray.h.

379  {
380  if( pSize == GetSize() && GetSize() == GetCapacity() ) return true;
381 
382  if( pSize == 0 )
383  {
384  Clear();
385  return true;
386  }
387 
388  FBX_ASSERT_RETURN_VALUE(pSize > 0, false);
389 
390  bool lReallocate;
391  if (pPreserveCapacityIfPossible)
392  lReallocate = pSize > GetCapacity();
393  else
394  lReallocate = pSize != GetCapacity();
395 
396  if (lReallocate)
397  {
398  Allocate(pSize);
399  FBX_ASSERT_RETURN_VALUE(mData, false);
400  mData->mCapacity = pSize;
401  }
402 
403  mData->mSize = pSize;
404  return true;
405  }
void Clear()
Reset the number of element to zero and free the memory allocated.
Definition: fbxarray.h:490
struct FbxArray::tData * mData
bool Resize ( const int  pSize,
bool  pPreserveCapacityIfPossible = false 
)
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.

Parameters
pSizeThe new count of elements to set the array to. Must be greater or equal to zero.
pPreserveCapacityIfPossibleIf the new count will fit into the existing allocation, do not adjust the capacity.
Returns
true if the memory (re)allocation succeeded, false otherwise.
Remarks
If the requested element count is less than or equal to the current count, elements are freed from memory. Otherwise, the array grows and elements are unchanged.

Definition at line 412 of file fbxarray.h.

413  {
414  if (pSize == GetSize() && GetSize() == GetCapacity()) return true;
415 
416  if (pSize == 0)
417  {
418  Clear();
419  return true;
420  }
421 
422  FBX_ASSERT_RETURN_VALUE(pSize > 0, false);
423 
424  bool lReallocate;
425  if (pPreserveCapacityIfPossible)
426  lReallocate = pSize > GetCapacity();
427  else
428  lReallocate = pSize != GetCapacity();
429 
430  if (lReallocate)
431  {
432  Allocate(pSize);
433  FBX_ASSERT_RETURN_VALUE(mData, false);
434 
435  if (pSize > GetCapacity()) //Initialize new memory to zero
436  {
437  memset(&GetArray()[GetSize()], 0, (pSize - GetSize()) * sizeof(T));
438  }
439 
440  mData->mCapacity = pSize;
441  }
442 
443  mData->mSize = pSize;
444  return true;
445  }
void Clear()
Reset the number of element to zero and free the memory allocated.
Definition: fbxarray.h:490
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
struct FbxArray::tData * mData
bool Grow ( const int  pSize)
inline

Increase size of array by the specified size.

Parameters
pSizeThe size to add to the array size.
Returns
true if operation succeeded, false otherwise.

Definition at line 450 of file fbxarray.h.

451  {
452  const int size = GetSize();
453 
454  // Check int32 paramater does not overflow
455  FbxLongLong newSize = static_cast<FbxLongLong>(size) + static_cast<FbxLongLong>(pSize);
456  if (newSize > INT_MAX)
457  {
458  return false;
459  }
460 
461  return Resize(size + pSize);
462  }
#define INT_MAX
bool Resize(const int pSize, bool pPreserveCapacityIfPossible=false)
Inserts or erases elements at the end such that Size() becomes pSize, increasing capacity if needed...
Definition: fbxarray.h:412
FbxInt64 FbxLongLong
Definition: fbxtypes.h:92
bool Shrink ( const int  pSize)
inline

Reduce size of array by the specified size.

Parameters
pSizeThe size to remove from the array size.
Returns
true if operation succeeded, false otherwise.

Definition at line 467 of file fbxarray.h.

468  {
469  const int size = GetSize();
470 
471  // Check int32 paramater does not overflow
472  FbxLongLong newSize = static_cast<FbxLongLong>(size) - static_cast<FbxLongLong>(pSize);
473  if (pSize < 0 || newSize < 0 || newSize > size)
474  {
475  return false;
476  }
477 
478  return Resize(size - pSize);
479  }
bool Resize(const int pSize, bool pPreserveCapacityIfPossible=false)
Inserts or erases elements at the end such that Size() becomes pSize, increasing capacity if needed...
Definition: fbxarray.h:412
FbxInt64 FbxLongLong
Definition: fbxtypes.h:92
bool Compact ( )
inline

Compact the array so that its capacity is the same as its size.

Returns
true if operation succeeded, false otherwise.

Definition at line 483 of file fbxarray.h.

484  {
485  return Resize(GetSize());
486  }
bool Resize(const int pSize, bool pPreserveCapacityIfPossible=false)
Inserts or erases elements at the end such that Size() becomes pSize, increasing capacity if needed...
Definition: fbxarray.h:412
void Clear ( )
inline

Reset the number of element to zero and free the memory allocated.

Remarks
This only free the memory allocated by the array, and doesn't call the destructor of each element.

Definition at line 490 of file fbxarray.h.

491  {
492  if( mData != NULL )
493  {
494  FbxFree(mData);
495  mData = NULL;
496  }
497  }
#define NULL
Definition: fbxarch.h:213
struct FbxArray::tData * mData
void Sort ( CompareFunc  pCompareFunc)
inline

Sort the array using the specified compare function pointer.

Parameters
pCompareFuncThe compare function to use to sort elements.

Definition at line 501 of file fbxarray.h.

502  {
503  qsort(GetArray(), GetSize(), sizeof(T), pCompareFunc);
504  }
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
T* GetArray ( ) const
inline

Get pointer to internal array of elements.

Definition at line 507 of file fbxarray.h.

507 { return mData ? &mData->mArray[0] : NULL; }
#define NULL
Definition: fbxarch.h:213
T mArray[15]
15 represent only the number of items to see debug
Definition: fbxarray.h:48
struct FbxArray::tData * mData
operator T * ( ) const
inline

Cast operator.

Definition at line 510 of file fbxarray.h.

510 { return GetArray(); }
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
void AddArray ( const FbxArray< T > &  pOther)
inline

Append another array at the end of this array.

Parameters
pOtherThe other array to append to this array.

Definition at line 514 of file fbxarray.h.

515  {
516  if( Grow(pOther.GetSize()) )
517  {
518  memcpy(&GetArray()[GetSize() - pOther.GetSize()], pOther.GetArray(), pOther.GetSize() * sizeof(T));
519  }
520  }
bool Grow(const int pSize)
Increase size of array by the specified size.
Definition: fbxarray.h:450
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
void AddArrayNoDuplicate ( const FbxArray< T > &  pOther)
inline

Append the elements of another array at the end of this array if they are not present.

Parameters
pOtherAnother array.

Definition at line 524 of file fbxarray.h.

525  {
526  for( int i = 0, c = pOther.GetSize(); i < c; ++i )
527  {
528  AddUnique(pOther[i]);
529  }
530  }
int AddUnique(const T &pElement)
Append an element at the end of array, if not already present, doubling the array if capacity is not ...
Definition: fbxarray.h:131
void RemoveArray ( const FbxArray< T > &  pOther)
inline

Remove the elements of another array from this array is they are present.

Parameters
pOtherAnother array.

Definition at line 534 of file fbxarray.h.

535  {
536  for( int i = 0, c = pOther.GetSize(); i < c; ++i )
537  {
538  RemoveIt(pOther[i]);
539  }
540  }
bool RemoveIt(const T &pElement)
Remove first matching element in the array.
Definition: fbxarray.h:329
FbxArray<T>& operator= ( const FbxArray< T > &  pOther)
inline

Operator to copy elements of an array.

Returns
this array containing a copy of pOther elements.

Definition at line 544 of file fbxarray.h.

545  {
546  if( this != &pOther )
547  {
548  if( Resize(pOther.GetSize()) )
549  {
550  memcpy(GetArray(), pOther.GetArray(), pOther.GetSize() * sizeof(T));
551  }
552  }
553  return *this;
554  }
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507
bool Resize(const int pSize, bool pPreserveCapacityIfPossible=false)
Inserts or erases elements at the end such that Size() becomes pSize, increasing capacity if needed...
Definition: fbxarray.h:412
bool operator== ( const FbxArray< T > &  pOther) const
inline

Operator to compare elements of an array.

Returns
true if the two arrays are equal, otherwise false.

Definition at line 558 of file fbxarray.h.

559  {
560  if( this == &pOther ) return true;
561  if( GetSize() != pOther.GetSize() ) return false;
562  return memcmp(GetArray(), pOther.GetArray(), sizeof(T) * GetSize()) == 0;
563  }
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:507

Member Data Documentation

struct FbxArray::tData * mData
protected

The documentation for this class was generated from the following file: