31 #include <AK/Tools/Common/AkObject.h>
32 #include <AK/Tools/Common/AkAssert.h>
33 #include <AK/Tools/Common/AkPlatformFuncs.h>
35 #define AK_DEFINE_ARRAY_POOL( _name_, _poolID_ ) \
38 static AkMemPoolId Get() \
44 AK_DEFINE_ARRAY_POOL( _ArrayPoolDefault, g_DefaultPoolId )
45 AK_DEFINE_ARRAY_POOL( _ArrayPoolLEngineDefault, g_LEngineDefaultPoolId )
47 template <
class U_POOL>
50 AkForceInline
void *
Alloc(
size_t in_uSize )
55 AkForceInline
void *
ReAlloc(
void * in_pCurrent,
size_t in_uOldSize,
size_t in_uNewSize )
60 AkForceInline
void Free(
void * in_pAddress )
71 template <
class U_POOL>
74 AkForceInline
void *
Alloc(
size_t in_uSize )
79 AkForceInline
void *
ReAlloc(
void * in_pCurrent,
size_t in_uOldSize,
size_t in_uNewSize)
81 void* pNew =
Alloc(in_uNewSize);
82 if (pNew && in_pCurrent)
90 AkForceInline
void Free(
void * in_pAddress )
106 template< AkUInt32 uBufferSizeBytes, AkUInt8 uAlignmentSize = AK_OS_STRUCT_ALIGN>
111 AkForceInline
void *
Alloc(
size_t in_uSize)
113 if (in_uSize <= uBufferSizeBytes)
114 return (
void *)&m_buffer;
119 AkForceInline
void *
ReAlloc(
void * in_pCurrent,
size_t in_uOldSize,
size_t in_uNewSize )
121 void* pNew =
Alloc(in_uNewSize);
122 if (pNew != in_pCurrent && pNew && in_pCurrent)
130 AkForceInline
void Free(
void * in_pAddress)
132 if (&m_buffer != in_pAddress)
138 if (&in_srcAlloc.m_buffer == in_pSrc)
149 AK_ALIGN(
char m_buffer[uBufferSizeBytes], uAlignmentSize);
157 static AkForceInline
void Move( T& in_Dest, T& in_Src )
172 static AkForceInline
void Move( T& in_Dest, T& in_Src )
174 in_Dest.Transfer(in_Src);
189 template <
class T,
class ARG_T,
class TAlloc = ArrayPoolDefault,
unsigned long TGrowBy = 1,
class TMovePolicy = AkAssignmentMovePolicy<T> >
class AkArray :
public TAlloc
267 #endif // #ifndef SWIG
288 Iterator it =
Begin();
290 for ( Iterator itEnd =
End(); it != itEnd; ++it )
292 if ( *it == in_Item )
303 AkUInt32 uNumToSearch =
Length();
307 while ( uNumToSearch > 0 )
309 pPivot = pBase + ( uNumToSearch >> 1 );
310 if ( in_Item == *pPivot )
313 result.pItem = pPivot;
317 if ( in_Item > *pPivot )
329 Iterator
Erase( Iterator& in_rIter )
337 for ( T * pItem = in_rIter.pItem; pItem < pItemLast; pItem++ )
338 TMovePolicy::Move( pItem[ 0 ], pItem[ 1 ] );
350 void Erase(
unsigned int in_uIndex )
358 for ( T * pItem =
m_pItems+in_uIndex; pItem < pItemLast; pItem++ )
359 TMovePolicy::Move( pItem[ 0 ], pItem[ 1 ] );
377 TMovePolicy::Move( *in_rIter.pItem,
Last( ) );
381 AKASSERT(
Length( ) > 0 );
393 AKASSERT( in_ulReserve || TGrowBy );
397 m_pItems = (T *) TAlloc::Alloc(
sizeof( T ) * in_ulReserve );
399 return AK_InsufficientMemory;
440 AkForceInline T*
Exists(ARG_T in_Item)
const
442 Iterator it =
FindEx( in_Item );
443 return ( it !=
End() ) ? it.pItem : 0;
452 #if defined(_MSC_VER)
453 #pragma warning( push )
454 #pragma warning( disable : 4127 )
461 #if defined(_MSC_VER)
462 #pragma warning( pop )
469 AkPlacementNew( pEnd ) T;
504 Iterator it =
FindEx( in_rItem );
518 Iterator it =
FindEx( in_rItem );
531 for ( Iterator it =
Begin(), itEnd =
End(); it != itEnd; ++it )
540 AKASSERT( uiIndex <
Length() );
548 AKASSERT( in_uIndex <=
Length() );
552 #if defined(_MSC_VER)
553 #pragma warning( push )
554 #pragma warning( disable : 4127 )
561 #if defined(_MSC_VER)
562 #pragma warning( pop )
569 AkPlacementNew( pItemLast ) T;
573 for ( T * pItem = pItemLast; pItem > (
m_pItems + in_uIndex ); --pItem )
574 TMovePolicy::Move( pItem[ 0 ], pItem[ -1 ] );
579 AkPlacementNew(
m_pItems + in_uIndex ) T;
590 AKASSERT( in_uGrowBy );
593 T * pNewItems = NULL;
595 if (TMovePolicy::IsTrivial())
597 pNewItems = (T *)TAlloc::ReAlloc(
m_pItems,
sizeof(T) * cItems,
sizeof(T) * ulNewReserve);
603 pNewItems = (T *)TAlloc::Alloc(
sizeof(T) * ulNewReserve);
610 for (
size_t i = 0; i < cItems; ++i)
612 AkPlacementNew(pNewItems + i) T;
614 TMovePolicy::Move(pNewItems[i],
m_pItems[i]);
631 AkUInt32 cItems =
Length();
632 if (in_uiSize < cItems)
635 for(AkUInt32 i = in_uiSize - 1 ; i < cItems; i++)
650 for(
size_t i = cItems; i < in_uiSize; i++)
663 TAlloc::TransferMem( (
void*&)
m_pItems, in_rSource, (
void*)in_rSource.
m_pItems );
678 for (AkUInt32 i = 0; i < in_rSource.
Length(); ++i)