- Main Page
- Classes
- Files
- Directories
- Examples

- Class List
- Class Hierarchy
- Class Members

Classes | Protected Member Functions | Protected Attributes

# FbxArrayBase_< TypeSize > Class Template Reference

Search for all occurrences

## Detailed Description

### template<class TypeSize>
class FbxArrayBase_< TypeSize >

Template version base class used to store an array of fixed-size elements.

This class is used internally and only contains interfaces used for memory management of array elements.

Definition at line 705 of file fbxarray.h.

`#include <fbxarray.h>`

List of all members.

## Classes
struct | Header
## Protected Member Functions
| FbxArrayBase_ (TypeSize pTypeSize)
| Constructor.
| ~FbxArrayBase_ ()
| Destructor.
int | GetTypeSize () const
int | GetCount () const
| Get the number of elements in the array.
void | Clear ()
| All the elements of the array are removed and the memory of content is released.
void | Empty ()
| All the elements of the array are removed, but the memory of content is not released.
int | Reserve (int pCapacity)
| Set the capacity of the allocated storage space for the elements of the array.
void | SetCount (int pCount)
| Resizes the array to contain the specific elements.
void | Resize (int pItemCount)
| Resizes the array to contain the specific elements.
void | AddMultiple (int pItemCount)
| Append the specific number of elements to the end the array.
int | InsertAt (int pIndex, void *pItem)
| Insert an item at the given position.
void * | GetAt (int pIndex)
| Get the item at the given position.
void | RemoveAt (int pIndex)
| Removes the item at the given position.
bool | ValidateIndex (int pIndex) const
| Check that the given position is inside the array boundaries.
const Header * | GetHeader () const
Header * | GetHeader ()
int | GetHeaderOffset () const
int | GetArrayCount () const
void | SetArrayCount (int pArrayCount)
int | GetBlockCount () const
void | SetBlockCount (int pArrayCount)
## Protected Attributes
char * | mBaseArray
TypeSize | mTypeSize

## Constructor & Destructor Documentation

FbxArrayBase_ | ( | TypeSize | pTypeSize | ) | `[inline, protected]`

Constructor.

Parameters:

  pTypeSize | Size of one item of the array.

Definition at line 717 of file fbxarray.h.

                                                     : mTypeSize(pTypeSize)
            {
                mBaseArray = NULL;
            }

~FbxArrayBase_ | ( |  | ) | `[inline, protected]`

Destructor.

Definition at line 723 of file fbxarray.h.

            {
                Clear();
            }

## Member Function Documentation

int GetTypeSize | ( |  | ) | const `[inline, protected]`

Search for all occurrences

Definition at line 728 of file fbxarray.h.

    { return mTypeSize.GetTypeSize(); }

int GetCount | ( |  | ) | const `[inline, protected]`

Search for all occurrences

Get the number of elements in the array.

Returns:
  The number of elements that conform the array's content.

Definition at line 733 of file fbxarray.h.

    { return GetArrayCount(); }

void Clear | ( |  | ) | `[inline, protected]`

Search for all occurrences

All the elements of the array are removed and the memory of content is released.

Remarks:
  The destructor of the elements are not called.

Definition at line 738 of file fbxarray.h.

            {
                if (mBaseArray!=NULL)
                {
                    FbxFree(mBaseArray);
                    mBaseArray = NULL;
                }
            }

void Empty | ( |  | ) | `[inline, protected]`

Search for all occurrences

All the elements of the array are removed, but the memory of content is not released.

Remarks:
  The destructor of the elements are not called.

Definition at line 750 of file fbxarray.h.

            {
            #ifdef _DEBUG
                memset(mBaseArray+ GetHeaderOffset(), 0, GetArrayCount()*GetTypeSize());
            #endif
                SetArrayCount(0);
            }

int Reserve | ( | int | pCapacity | ) | `[inline, protected]`

Search for all occurrences

Set the capacity of the allocated storage space for the elements of the array.

Parameters:

  pCapacity | Minimum amount desired as capacity of allocated storage.

Returns:
  The number of available slots in the array.

Remarks:
  If capacity is lower than arrayCount, arrayCount is lowered to capacity.

Definition at line 763 of file fbxarray.h.

            {
                FBX_ASSERT( pCapacity > 0 );
                if( pCapacity )
                {
                    const FbxUInt lTempNewBlockCount = ( (FbxUInt) (pCapacity + FBXSDK_ARRAY_BLOCKSIZE - 1 ) / FBXSDK_ARRAY_BLOCKSIZE );
                    const FbxUInt lNewBlockCount = (lTempNewBlockCount > 1 ? lTempNewBlockCount : 1);

                    int lArrayCount = GetArrayCount();
                    int lBlockCount = GetBlockCount();

                    const FbxUInt lOldArraySize = lArrayCount*GetTypeSize();
                    const FbxUInt lNewArraySize = lNewBlockCount*FBXSDK_ARRAY_BLOCKSIZE*GetTypeSize();

                    if (lNewBlockCount != (FbxUInt) lBlockCount)
                    {
                        char* lBaseArray = (char*)FbxRealloc(mBaseArray, (size_t) lNewArraySize+ GetHeaderOffset()  );
                        if (!lBaseArray)
                            return GetBlockCount()*FBXSDK_ARRAY_BLOCKSIZE;
                        mBaseArray = lBaseArray;
                    }

                    if( lNewBlockCount > (FbxUInt) lBlockCount ) {
                        memset( ((char*)mBaseArray+ GetHeaderOffset() ) + lOldArraySize, 0, (size_t) (lNewArraySize-lOldArraySize) );
                        SetArrayCount(lArrayCount);
                    }
                    else if (pCapacity < lArrayCount)
                    {
                        memset( ((char*)mBaseArray+ GetHeaderOffset() ) + pCapacity*GetTypeSize(), 0, (size_t) (lNewArraySize-pCapacity*GetTypeSize()) );
                        SetArrayCount(pCapacity);
                    }

                    SetBlockCount(lNewBlockCount);
                }

                return GetBlockCount()*FBXSDK_ARRAY_BLOCKSIZE;
            }

void SetCount | ( | int | pCount | ) | `[inline, protected]`

Search for all occurrences

Resizes the array to contain the specific elements.

Parameters:

  pCount | New array size, expressed in elements.

Remarks:
  If the array is upsized, the memory allocated is set to 0 and no constructor is called. Thus, this function is not appropriate for types of elements requiring initialization.

Definition at line 807 of file fbxarray.h.

            {
            #ifdef _DEBUG
                if (pCount<0)
                {
                    FBX_ASSERT_NOW ("ArrayUL : Item count can't be negative");
                    return ;
                }
            #endif
                int lArrayCount = GetArrayCount();
                if (pCount > lArrayCount)
                {
                    AddMultiple( pCount-lArrayCount);
                }
                else
                {
                    SetArrayCount(pCount);
                }
            }

void Resize | ( | int | pItemCount | ) | `[inline, protected]`

Search for all occurrences

Resizes the array to contain the specific elements.

Parameters:

  pItemCount | New array size, expressed in elements.

Remarks:
  If the array is upsized, the memory allocated is set to 0 and no constructor is called. Thus, this function is not appropriate for types of elements requiring initialization.

Definition at line 833 of file fbxarray.h.

            {
                FBX_ASSERT( pItemCount >= 0 );

                const FbxUInt lTempNewBlockCount = ( (FbxUInt) (pItemCount + FBXSDK_ARRAY_BLOCKSIZE - 1 ) / FBXSDK_ARRAY_BLOCKSIZE );
                const FbxUInt lNewBlockCount = (lTempNewBlockCount > 1 ? lTempNewBlockCount : 1);

                int lArrayCount = GetArrayCount();
                int lBlockCount = GetBlockCount();

                const FbxUInt lOldArraySize = lArrayCount*GetTypeSize();
                const FbxUInt lNewArraySize = lNewBlockCount*FBXSDK_ARRAY_BLOCKSIZE*GetTypeSize();

                if (lNewBlockCount != (FbxUInt) lBlockCount)
                {
                    char* lBaseArray = (char*)FbxRealloc(mBaseArray, (size_t) lNewArraySize+ GetHeaderOffset()  );
                    if (!lBaseArray)
                        return;
                    mBaseArray = lBaseArray;
                }

                if( lNewBlockCount > (FbxUInt) lBlockCount )
                {
                    memset( ((char*)mBaseArray+ GetHeaderOffset() ) + lOldArraySize, 0, (size_t) (lNewArraySize-lOldArraySize) );
                }
                else if (pItemCount < lArrayCount)
                {
                    memset( ((char*)mBaseArray+ GetHeaderOffset() ) + pItemCount*GetTypeSize(), 0, (size_t) (lNewArraySize-pItemCount*GetTypeSize()) );
                }

                SetBlockCount(lNewBlockCount);
                SetArrayCount(pItemCount);
            }

void AddMultiple | ( | int | pItemCount | ) | `[inline, protected]`

Search for all occurrences

Append the specific number of elements to the end the array.

Parameters:

  pItemCount | The number of elements appended in elements.

Remarks:
  The memory of new elements is set to 0 and no constructor is called. Thus, this function is not appropriate for types of elements requiring initialization.

Definition at line 873 of file fbxarray.h.

            {
                FBX_ASSERT( pItemCount > 0 );
                if( pItemCount )
                {
                    int lArrayCount = GetArrayCount();
                    int lBlockCount = GetBlockCount();
                    const FbxUInt lTempNewBlockCount = ( (FbxUInt) (lArrayCount+pItemCount + FBXSDK_ARRAY_BLOCKSIZE - 1 ) / FBXSDK_ARRAY_BLOCKSIZE );
                    const FbxUInt lNewBlockCount = (lTempNewBlockCount > 1 ? lTempNewBlockCount : 1);

                    const FbxUInt lOldArraySize = lArrayCount*GetTypeSize();
                    const FbxUInt lNewArraySize = lNewBlockCount*FBXSDK_ARRAY_BLOCKSIZE*GetTypeSize();

                    FBX_ASSERT( lOldArraySize < lNewArraySize );

                    if( lNewBlockCount > (FbxUInt) lBlockCount )
                    {
                        char* lBaseArray = (char*)FbxRealloc(mBaseArray, (size_t) lNewArraySize+ GetHeaderOffset()  );
                        if (!lBaseArray)
                            return;
                        mBaseArray = lBaseArray;
                        lBlockCount = lNewBlockCount;
                    }

                    memset( ((char*)mBaseArray+ GetHeaderOffset() ) + lOldArraySize, 0, (size_t) (lNewArraySize-lOldArraySize) );
                    SetArrayCount ( lArrayCount + pItemCount );
                    SetBlockCount (lBlockCount);
                }
            }

int InsertAt | ( | int | pIndex,
|  | void * | pItem
| ) |  | `[inline, protected]`

Search for all occurrences

Insert an item at the given position.

Parameters:

  pIndex | Position where to insert the item.
  pItem | Pointer to the item to be inserted.

Remarks:
  if pIndex is greater than the number of items already in the array, the item will be appended at the end.

Returns:
  The actual position where the item as been inserted.

Definition at line 910 of file fbxarray.h.

            {
                int lArrayCount = GetArrayCount();
                int lBlockCount = GetBlockCount();

                FBX_ASSERT( pIndex >= 0 );

                if (pIndex>lArrayCount) {
                    pIndex = GetArrayCount();
                }

                if (lArrayCount>= lBlockCount*FBXSDK_ARRAY_BLOCKSIZE)
                {
                    // must Alloc.Realloc some new space

                    // double the number of blocks.
                    lBlockCount = ( 0 == lBlockCount ) ? 1 : lBlockCount * 2;
                    char* lBaseArray = (char*)FbxRealloc(mBaseArray, (size_t) (lBlockCount*FBXSDK_ARRAY_BLOCKSIZE*GetTypeSize()) + GetHeaderOffset() );
                    if(!lBaseArray)
                        return -1;
                    mBaseArray = lBaseArray;
                }

                if (pIndex<lArrayCount)
                {
                    // This is an insert
                    memmove (&(mBaseArray[(pIndex+1)*GetTypeSize()+ GetHeaderOffset() ]), &(mBaseArray[(pIndex)*GetTypeSize()+ GetHeaderOffset()] ), GetTypeSize()*(lArrayCount-pIndex));
                }

                memmove (&(mBaseArray[(pIndex)*GetTypeSize()+ GetHeaderOffset() ]), pItem, GetTypeSize());

                SetArrayCount(lArrayCount+1);
                SetBlockCount(lBlockCount);

                return pIndex;
            }

void* GetAt | ( | int | pIndex | ) | `[inline, protected]`

Search for all occurrences

Get the item at the given position.

Parameters:

  pIndex | The position of the item to access.

Returns:
  Pointer to the item.

Remarks:
  This method assumes that the passed index is in the valid range of the array. No checks are made.

Definition at line 954 of file fbxarray.h.

    { return &(mBaseArray[(pIndex)*GetTypeSize()+ GetHeaderOffset()]); }

void RemoveAt | ( | int | pIndex | ) | `[inline, protected]`

Search for all occurrences

Removes the item at the given position.

Parameters:

  pIndex | The position of the item to remove.

Remarks:
  If the index is not valid, nothing is performed. Otherwise, the item is removed from the array and the items are shifted to fill the empty slot.

Definition at line 962 of file fbxarray.h.

            {
            #if defined(_DEBUG) && !defined(FBXSDK_ENV_MAC)
                if (!ValidateIndex( pIndex ))
                {
                    return;
                }
            #endif
                int lArrayCount = GetArrayCount();
                if (pIndex+1<lArrayCount)
                {
                    memmove (&(mBaseArray[(pIndex)*GetTypeSize()+ GetHeaderOffset() ]), &(mBaseArray[(pIndex+1)*GetTypeSize()+ GetHeaderOffset() ]), GetTypeSize()*(lArrayCount-pIndex-1));
                }

                SetArrayCount( lArrayCount-1 );

            #ifdef _DEBUG
                memset( &(mBaseArray[(GetArrayCount())*GetTypeSize()+ GetHeaderOffset() ]),0,GetTypeSize());
            #endif
            }

bool ValidateIndex | ( | int | pIndex | ) | const `[inline, protected]`

Search for all occurrences

Check that the given position is inside the array boundaries.

Parameters:

  pIndex | Index value to be validated.

Returns:
  `true` if the index value is within the array boundaries. `false` otherwise.

Definition at line 988 of file fbxarray.h.

            {
                int lArrayCount = GetArrayCount();
                if (pIndex>=0 && pIndex<lArrayCount)
                {
                    return true;
                }
                else
                {
                    FBX_ASSERT_NOW("Array : Index out of range");
                    return false;
                }
            }

const Header* GetHeader | ( |  | ) | const `[inline, protected]`

Search for all occurrences

Definition at line 1002 of file fbxarray.h.

            {
                return (const Header*)mBaseArray;
            }

Header* GetHeader | ( |  | ) | `[inline, protected]`

Search for all occurrences

Definition at line 1007 of file fbxarray.h.

            {
                return (Header*)mBaseArray;
            }

int GetHeaderOffset | ( |  | ) | const `[inline, protected]`

Search for all occurrences

Definition at line 1012 of file fbxarray.h.

            {
                return sizeof(Header);
            }

int GetArrayCount | ( |  | ) | const `[inline, protected]`

Search for all occurrences

Definition at line 1017 of file fbxarray.h.

            {
                return GetHeader() ? GetHeader()->mArrayCount : 0;
            }

void SetArrayCount | ( | int | pArrayCount | ) | `[inline, protected]`

Search for all occurrences

Definition at line 1022 of file fbxarray.h.

            {
                if (GetHeader()) GetHeader()->mArrayCount = pArrayCount;
            }

int GetBlockCount | ( |  | ) | const `[inline, protected]`

Search for all occurrences

Definition at line 1027 of file fbxarray.h.

            {
                return GetHeader() ? GetHeader()->mBlockCount : 0;
            }

void SetBlockCount | ( | int | pArrayCount | ) | `[inline, protected]`

Search for all occurrences

Definition at line 1032 of file fbxarray.h.

            {
                if (GetHeader()) GetHeader()->mBlockCount=pArrayCount;
            }

## Member Data Documentation

char* mBaseArray `[protected]`

Search for all occurrences

Definition at line 1037 of file fbxarray.h.

TypeSize mTypeSize `[protected]`

Search for all occurrences

Definition at line 1038 of file fbxarray.h.

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

- fbxsdk/core/base/fbxarray.h