Public Member Functions

KArrayTemplate< Type > Class Template Reference

This reference page is linked to from the following overview topics: List of Python FBX classes.


Search for all occurrences

Detailed Description

template<class Type>
class KArrayTemplate< Type >

Class for array of elements such as pointers and plain old data structures.

This class will not call constructor and destructor for elements.

Examples:

ExportScene03/main.cxx, ViewScene/InitScene.cxx, ViewScene/InitScene.h, and ViewScene/main.cxx.

Definition at line 839 of file karrayul.h.

#include <karrayul.h>

Inheritance diagram for KArrayTemplate< Type >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

  KArrayTemplate ()
  Constructor.
  KArrayTemplate (const KArrayTemplate &pArrayTemplate)
  Copy constructor.
  ~KArrayTemplate ()
  Destructor. The destructor of elements will not be called.
int  InsertAt (int pIndex, Type pItem)
  Insert a element.
Type  RemoveAt (int pIndex)
  Remove a element in the array.
Type  RemoveLast ()
  Remove the last element in the array.
bool  RemoveIt (Type pItem)
  Remove first matching element in the array.
Type &  operator[] (int pIndex) const
  Returns a reference to the element at given position in the array.
void  SetAt (int pIndex, Type pItem)
  Set the element at given position in the array.
void  SetLast (Type pItem)
  Set the value of the last element.
Type  GetAt (int pIndex) const
  Returns the value of the element at given position in the array.
Type  GetFirst () const
  Get the first element.
Type  GetLast () const
  Get the last element.
int  Find (Type pItem) const
  Find first matching element.
int  FindAfter (int pAfterIndex, Type pItem) const
  Find first matching element after given index.
int  FindBefore (int pBeforeIndex, Type pItem) const
  Find first matching pointer before given index.
int  Add (Type pItem)
  Append an element at the end of the array.
int  AddUnique (Type pItem)
  Add Element at the end of array if not present.
void  AddMultiple (kUInt pItemCount)
  Add multiple elements at the end of array, use SetAt or GetArray to set the value of the new elements.
void  AddArray (const KArrayTemplate< Type > &pArray)
  Append another array at the end of this array.
void  AddArrayNoDuplicate (const KArrayTemplate< Type > &pArray)
  Append the elements of another array at the end of this array if they are not present.
void  RemoveArray (const KArrayTemplate< Type > &pArray)
  Remove the elements of another array from this array is they are present.
Type *  GetArray () const
  Get pointer to internal array of elements.
KArrayTemplate< Type > &  operator= (const KArrayTemplate< Type > &pArrayTemplate)
  Copy array of elements.
  operator Type * ()
  Cast operator.

Constructor & Destructor Documentation

KArrayTemplate ( ) [inline]

Constructor.

Definition at line 858 of file karrayul.h.

            : ParentClass ()
        {
        }
KArrayTemplate ( const KArrayTemplate< Type > &  pArrayTemplate ) [inline]

Copy constructor.

Definition at line 864 of file karrayul.h.

            : ParentClass ()
        {
            *this = pArrayTemplate;
        }
~KArrayTemplate ( ) [inline]

Destructor. The destructor of elements will not be called.

Definition at line 871 of file karrayul.h.

{}

Member Function Documentation

int InsertAt ( int  pIndex,
Type  pItem 
) [inline]

Insert a element.

Parameters:
pIndex Position where to insert the pointer.
pItem Item to insert.
Returns:
Position of the inserted pointer in the array.
Remarks:
If the given index is out of range, the pointer is appended at the end. No error will be thrown if the index is out of bounds.

Definition at line 879 of file karrayul.h.

        {
            return ParentClass::InsertAt( pIndex,&pItem );
        }
Type RemoveAt ( int  pIndex ) [inline]

Remove a element in the array.

Parameters:
pIndex Position of the item to remove.
Returns:
Removed item.
Remarks:
No error will be thrown if the index is out of bounds.

Reimplemented from KBaseArrayFast< sizeof(Type) >.

Definition at line 889 of file karrayul.h.

        {
            Type tmpItem = GetAt(pIndex);
            ParentClass::RemoveAt( pIndex );
            return tmpItem;
        }
Type RemoveLast ( ) [inline]

Remove the last element in the array.

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

Definition at line 900 of file karrayul.h.

bool RemoveIt ( Type  pItem ) [inline]

Remove first matching element in the array.

Parameters:
pItem Item to be removed.
Returns:
true if a matching pointer is found and removed, false otherwise.

Definition at line 909 of file karrayul.h.

        {
            int Index = Find (pItem);
            if (Index>=0)
            {
                RemoveAt (Index);
                return true;
            }
            return false;
        }
Type& operator[] ( int  pIndex ) const [inline]

Returns a reference to the element at given position in the array.

Parameters:
pIndex Position of element in the array.
Returns:
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 925 of file karrayul.h.

        {
        #if defined(_DEBUG) && !defined(KARCH_ENV_MACOSX)
            if (!ParentClass::ValidateIndex( pIndex ))
            {
                return (Type &)(ParentClass::mBaseArray[(0)*sizeof(Type)+ ParentClass::GetHeaderOffset() ]);
            }
        #endif
            return (Type &)(ParentClass::mBaseArray[(pIndex)*sizeof(Type)+ ParentClass::GetHeaderOffset() ]);
        }
void SetAt ( int  pIndex,
Type  pItem 
) [inline]

Set the element at given position in the array.

Parameters:
pIndex Position of element in the array.
pItem The new element.
Remarks:
No error will be thrown if the index is out of bounds.

Definition at line 941 of file karrayul.h.

        {
        #if defined(_DEBUG) && !defined(KARCH_ENV_MACOSX)
            if (!ParentClass::ValidateIndex( pIndex ))
            {
                return;
            }
        #endif
            GetArray()[pIndex] = pItem;
        }
void SetLast ( Type  pItem ) [inline]

Set the value of the last element.

Parameters:
pItem The 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 956 of file karrayul.h.

        {
            SetAt (ParentClass::GetArrayCount()-1, pItem);
        }
Type GetAt ( int  pIndex ) const [inline]

Returns the value of the element at given position in the array.

Parameters:
pIndex Position 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 966 of file karrayul.h.

        {
        #if defined(_DEBUG) && !defined(KARCH_ENV_MACOSX)
            if (!ParentClass::ValidateIndex( pIndex ))
            {
                return (Type &)(ParentClass::mBaseArray[(0)*sizeof(Type)+ ParentClass::GetHeaderOffset() ]);
            }
        #endif
            return (Type &)(ParentClass::mBaseArray[(pIndex)*sizeof(Type)+ ParentClass::GetHeaderOffset() ]);
        }
Type GetFirst ( ) const [inline]

Get the first element.

Returns:
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 981 of file karrayul.h.

        {
        #ifdef KFBX_PRIVATE
            K_ASSERT( ParentClass::GetArrayCount() >= 1 );
        #endif
            return GetAt(0);
        }
Type GetLast ( ) const [inline]

Get the last element.

Returns:
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 993 of file karrayul.h.

        {
        #ifdef KFBX_PRIVATE
            K_ASSERT( ParentClass::GetArrayCount() >= 1 );
        #endif
            return GetAt(ParentClass::GetArrayCount()-1);
        }
int Find ( Type  pItem ) const [inline]

Find first matching element.

Parameters:
pItem The item to be compared to each of the elements.
Returns:
Index of first matching element or -1 if there is no matching element.

Definition at line 1005 of file karrayul.h.

        {
            return FindAfter( -1, pItem );
        }
int FindAfter ( int  pAfterIndex,
Type  pItem 
) const [inline]

Find first matching element after given index.

Parameters:
pAfterIndex The index after which the finding begins.
pItem The item to be compared to each of the elements.
Returns:
Index of first matching pointer found after given index or -1 if there is no matching pointer.
Remarks:
The index must be within valid range and no error will be thrown if it is invalid.

Definition at line 1016 of file karrayul.h.

        {
        #ifdef KFBX_PRIVATE
        #ifdef _DEBUG
            if ( pAfterIndex > ParentClass::GetArrayCount() || pAfterIndex < -1 )
            {
                K_ASSERT_MSG_NOW (_T("ArrayUL : Search Begin Index out of range"));
                return -1;
            }
        #endif
        #endif
            int Count;
            for ( Count=pAfterIndex+1; Count<ParentClass::GetArrayCount(); Count++)
            {
                if (GetAt(Count)==pItem)
                {
                    return Count;
                }
            }
            return -1;
        }
int FindBefore ( int  pBeforeIndex,
Type  pItem 
) const [inline]

Find first matching pointer before given index.

Parameters:
pBeforeIndex The index before which the finding begins.
pItem The item to be compared to each of the elements.
Returns:
Index of first matching pointer found before given index or -1 if there is no matching pointer.
Remarks:
The index must be within valid range and no error will be thrown if it is invalid.

Definition at line 1044 of file karrayul.h.

        {
        #ifdef KFBX_PRIVATE
        #ifdef _DEBUG
            if ( pBeforeIndex > ParentClass::GetArrayCount() || pBeforeIndex <= 0 )
            {
                K_ASSERT_MSG_NOW (_T("ArrayUL : Search Begin Index out of range"));
                return -1;
            }
        #endif
        #endif
            int Count;
            for ( Count=pBeforeIndex-1; Count>=0; Count--)
            {
                if (GetAt(Count)==pItem)
                {
                    return Count;
                }
            }
            return -1;
        }
int Add ( Type  pItem ) [inline]

Append an element at the end of the array.

Parameters:
pItem Value to be copied to the new element.
Returns:
Index of appended element.

Definition at line 1070 of file karrayul.h.

        {
            return InsertAt(ParentClass::GetArrayCount(), pItem);
        }
int AddUnique ( Type  pItem ) [inline]

Add Element at the end of array if not present.

Parameters:
pItem Value to be copied to the new element.
Returns:
Index of appended element.

Definition at line 1079 of file karrayul.h.

        {
            int lReturnIndex = Find(pItem);
            if (lReturnIndex == -1)
            {
                lReturnIndex = Add(pItem);
            }
            return lReturnIndex;
        }
void AddMultiple ( kUInt  pItemCount ) [inline]

Add multiple elements at the end of array, use SetAt or GetArray to set the value of the new elements.

Parameters:
pItemCount How many new elements you want to add.

Definition at line 1092 of file karrayul.h.

        {
            ParentClass::AddMultiple(pItemCount);
        }
void AddArray ( const KArrayTemplate< Type > &  pArray ) [inline]

Append another array at the end of this array.

Parameters:
pArray Another array.

Definition at line 1100 of file karrayul.h.

        {
            int lSourceIndex, lCount = pArray.GetCount();
            if( lCount == 0 ) return;
            int lDestinationIndex = ParentClass::GetCount();
            AddMultiple(lCount);
            for( lSourceIndex = 0; lSourceIndex < lCount; lSourceIndex++)
            {
                SetAt(lDestinationIndex++, pArray[lSourceIndex]);
            }
        }
void AddArrayNoDuplicate ( const KArrayTemplate< Type > &  pArray ) [inline]

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

Parameters:
pArray Another array.

Definition at line 1115 of file karrayul.h.

        {
            int i, lCount = pArray.GetCount();
            for( i = 0; i < lCount; i++)
            {
                Type lItem = pArray[i];
                if (Find(lItem) == -1)
                {
                    Add(lItem);
                }
            }
        }
void RemoveArray ( const KArrayTemplate< Type > &  pArray ) [inline]

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

Parameters:
pArray Another array.

Definition at line 1131 of file karrayul.h.

        {
            int lRemoveIndex, lRemoveCount = pArray.GetCount();
            for( lRemoveIndex = 0; lRemoveIndex < lRemoveCount; lRemoveIndex++)
            {
                RemoveIt(pArray[lRemoveIndex]);
            }
        }
Type* GetArray ( ) const [inline]

Get pointer to internal array of elements.

Definition at line 1141 of file karrayul.h.

KArrayTemplate<Type>& operator= ( const KArrayTemplate< Type > &  pArrayTemplate ) [inline]

Copy array of elements.

Definition at line 1150 of file karrayul.h.

        {
            if ( this != &pArrayTemplate )
            {
                ParentClass::Clear();

                int i, lCount = pArrayTemplate.GetCount();

                for (i = 0; i < lCount; i++)
                {
                    Add(pArrayTemplate[i]);
                }
            }

            return (*this);
        }
operator Type * ( ) [inline]

Cast operator.

Definition at line 1168 of file karrayul.h.

        {
            return GetArray();
        }

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