Classes | Public Member Functions | Protected Member Functions | Protected Attributes

FbxArrayBase< TypeSize > Class Template Reference

Search for all occurrences

Detailed Description

template<size_t TypeSize>
class FbxArrayBase< TypeSize >

Definition at line 22 of file fbxarray.h.

#include <fbxarray.h>

List of all members.

Classes

struct   Header

Public Member Functions

int  GetCount () const
  Get number of pointers in the array.
void  Clear ()
  Remove all pointers without deleting the associated objects.
void  Empty ()
  Fast empty, set object count to zero but don't free any memory.
int  Reserve (int pCapacity)
  Set array capacity to contain at least the specified number of elements without reallocating.
void  SetCount (int pCount)
  Set arrayCount to specified number of elements. The array capacity is adjusted accordingly.
void  Resize (int pItemCount)
void  AddMultiple (int pItemCount)

Protected Member Functions

  FbxArrayBase ()
  Constructor.
  ~FbxArrayBase ()
  Destructor.
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.
Header *const  GetHeader () const
Header GetHeader ()
int  GetHeaderOffset () const
int  GetArrayCount () const
void  SetArrayCount (int pArrayCount)
int  GetBlockCount () const
void  SetBlockCount (int pArrayCount)

Protected Attributes

int  mArrayCount
char *  mBaseArray

Constructor & Destructor Documentation

FbxArrayBase ( ) [inline, protected]

Constructor.

Definition at line 204 of file fbxarray.h.

~FbxArrayBase ( ) [inline, protected]

Destructor.

Definition at line 209 of file fbxarray.h.

                          {
        Clear ();
    }

Member Function Documentation

int GetCount ( ) const [inline]

Get number of pointers in the array.

Returns:
The number of items in the array.

Definition at line 28 of file fbxarray.h.

{ return GetArrayCount(); }
void Clear ( ) [inline]

Remove all pointers without deleting the associated objects.

Definition at line 31 of file fbxarray.h.

void Empty ( ) [inline]

Fast empty, set object count to zero but don't free any memory.

Definition at line 43 of file fbxarray.h.

    {
    #ifdef _DEBUG
        memset( mBaseArray+ GetHeaderOffset() ,0,GetArrayCount()*TypeSize);
    #endif
        SetArrayCount(0);
    }
int Reserve ( int  pCapacity ) [inline]

Set array capacity to contain at least the specified number of elements without reallocating.

Parameters:
pCapacity Number of items that can be stored in the array before reallocating the memory.
Returns:
The number of available slots in the array.
Remarks:
If capacity is lower than arrayCount, arrayCount is lowered to capacity.

Definition at line 57 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*TypeSize;
            const FbxUInt lNewArraySize = lNewBlockCount*FBXSDK_ARRAY_BLOCKSIZE*TypeSize;

            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*TypeSize, 0, (size_t) (lNewArraySize-pCapacity*TypeSize) );
                SetArrayCount(pCapacity);
            }

            SetBlockCount(lNewBlockCount);
        }

        return GetBlockCount()*FBXSDK_ARRAY_BLOCKSIZE;
    }
void SetCount ( int  pCount ) [inline]

Set arrayCount to specified number of elements. The array capacity is adjusted accordingly.

Force the array of elements to a given size.

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 104 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]

Definition at line 124 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*TypeSize;
        const FbxUInt lNewArraySize = lNewBlockCount*FBXSDK_ARRAY_BLOCKSIZE*TypeSize;

        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*TypeSize, 0, (size_t) (lNewArraySize-pItemCount*TypeSize) );
        }

        SetBlockCount(lNewBlockCount);
        SetArrayCount(pItemCount);
    }
void AddMultiple ( int  pItemCount ) [inline]

Definition at line 158 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*TypeSize;
            const FbxUInt lNewArraySize = lNewBlockCount*FBXSDK_ARRAY_BLOCKSIZE*TypeSize;

            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]

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.

Reimplemented in FbxArray< void * >.

Definition at line 220 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*TypeSize) + GetHeaderOffset() );
            if(!lBaseArray)
                return -1;
            mBaseArray = lBaseArray;
        }

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

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

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

        return pIndex;
    }
void* GetAt ( int  pIndex ) [inline, protected]

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 264 of file fbxarray.h.

{ return &(mBaseArray[(pIndex)*TypeSize+ GetHeaderOffset() ]); }
void RemoveAt ( int  pIndex ) [inline, protected]

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.

Reimplemented in FbxArray< Type >, FbxArray< FbxNode * >, FbxArray< FbxAnimCurveNode * >, FbxArray< FbxProperty >, FbxArray< double >, FbxArray< FbxDocument * >, FbxArray< FbxArray< Element > * >, FbxArray< int >, FbxArray< AESequence * >, FbxArray< FbxDataType >, FbxArray< ReaderPluginEntry * >, FbxArray< FbxLayerElement * >, FbxArray< WriterPluginEntry * >, FbxArray< FbxPropertyPage * >, FbxArray< FbxXRefManagerProject * >, FbxArray< InputData >, FbxArray< FbxArray< int > * >, FbxArray< FbxTakeInfo * >, FbxArray< FbxString * >, FbxArray< FbxAccumulatorEntry * >, FbxArray< Type * >, FbxArray< PolygonDef >, FbxArray< void * >, FbxArray< FbxPoseInfo * >, FbxArray< FbxTakeLayerInfo * >, FbxArray< char >, FbxArray< ModifiedPropertyInfo * >, FbxArray< FbxObject * >, FbxArray< FbxMesh * >, FbxArray< NameCell * >, FbxArray< FbxStringListItem * >, FbxArray< FbxTexture * >, FbxArray< FbxLayer * >, FbxArray< FbxVector4 >, FbxArray< FbxConnectionPoint * >, FbxArray< ListItem * >, FbxArray< FbxSceneReference * >, FbxArray< xmlNode * >, and FbxArray< FbxLocalizationManager * >.

Definition at line 272 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)*TypeSize+ GetHeaderOffset() ]), &(mBaseArray[(pIndex+1)*TypeSize+ GetHeaderOffset() ]), TypeSize*(lArrayCount-pIndex-1));
        }

        SetArrayCount( lArrayCount-1 );

    #ifdef _DEBUG
        memset( &(mBaseArray[(GetArrayCount())*TypeSize+ GetHeaderOffset() ]),0,TypeSize);
    #endif
    }
bool ValidateIndex ( int  pIndex ) const [inline, protected]

Check that the given position is inside the array boundaries.

Parameters:
pIndex Index value to validate.
Returns:
true if the index value is within the array boundaries. false otherwise.

Definition at line 300 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;
        }
    }
Header* const GetHeader ( ) const [inline, protected]

Definition at line 314 of file fbxarray.h.

    {
        return (Header* const)mBaseArray;
    }
Header* GetHeader ( ) [inline, protected]

Definition at line 318 of file fbxarray.h.

    {
        return (Header*)mBaseArray;
    }
int GetHeaderOffset ( ) const [inline, protected]

Definition at line 322 of file fbxarray.h.

    {
        return sizeof(Header);
    }
int GetArrayCount ( ) const [inline, protected]

Definition at line 326 of file fbxarray.h.

    {
        return mArrayCount;
    }
void SetArrayCount ( int  pArrayCount ) [inline, protected]

Definition at line 330 of file fbxarray.h.

    {
        mArrayCount = pArrayCount;
    }
int GetBlockCount ( ) const [inline, protected]

Definition at line 334 of file fbxarray.h.

    {
        return GetHeader() ? GetHeader()->mBlockCount : 0;
    }
void SetBlockCount ( int  pArrayCount ) [inline, protected]

Definition at line 338 of file fbxarray.h.

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

Member Data Documentation

int mArrayCount [protected]

Definition at line 343 of file fbxarray.h.

char* mBaseArray [protected]

Definition at line 344 of file fbxarray.h.


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