42 #include <kaydaradef.h>
47 #define FBSDK_DLL K_DLLIMPORT
50 #include <fbsdk/fbversion.h>
55 #ifdef FBSDKUseNamespace
56 namespace FBSDKNamespace {
88 mItemPerBlock = pItemPerBlock;
99 *
this = pArrayTemplate;
115 if (pIndex>mArrayCount)
117 pIndex = mArrayCount;
120 if (mArrayCount>= mBlockCount*mItemPerBlock)
124 mArray = (Type *)
FBRealloc( mArray,(
size_t)(mBlockCount*mItemPerBlock*
sizeof(Type)));
127 if (pIndex<mArrayCount)
130 memmove (&(mArray[pIndex+1]),&(mArray[pIndex]),
sizeof(Type)*(mArrayCount-pIndex));
133 mArray[pIndex] = pItem;
144 assert( pIndex<mArrayCount );
145 if (pIndex+1<mArrayCount) {
146 memmove (&(mArray[pIndex]),&(mArray[pIndex+1]),
sizeof(Type)*(mArrayCount-pIndex-1));
149 memset (&(mArray[mArrayCount]),0,
sizeof(Type));
162 int Index = Find( pItem );
176 int Index = Find( pItem );
201 assert( pIndex<mArrayCount );
202 return mArray[pIndex];
209 inline void SetAt(
int pIndex,Type pItem)
211 assert( pIndex<mArrayCount );
212 mArray[pIndex] = pItem;
221 SetAt(mArrayCount-1,pItem );
236 if (pCount > mArrayCount)
240 const int lTempNewBlockCount = ( (int) (mArrayCount+pCount + mItemPerBlock - 1 ) / mItemPerBlock );
241 const int lNewBlockCount = (lTempNewBlockCount > 1 ? lTempNewBlockCount : 1);
243 const int lOldArraySize = mArrayCount*
sizeof(Type);
244 const int lNewArraySize = lNewBlockCount*mItemPerBlock*
sizeof(Type);
246 if( lNewBlockCount > (
int) mBlockCount )
248 mArray = (Type *)
FBRealloc( mArray, (
size_t) lNewArraySize );
249 mBlockCount = lNewBlockCount;
252 memset( ((
char *)mArray) + lOldArraySize, 0, (
size_t) (lNewArraySize-lOldArraySize) );
253 mArrayCount += pCount;
257 mArrayCount = pCount;
267 assert( pIndex<mArrayCount );
268 return mArray[pIndex];
276 return mArray[mArrayCount-1];
286 for (Count=0; Count<mArrayCount; Count++) {
287 if (mArray[Count]==pItem) {
298 inline int Add( Type pItem )
300 return InsertAt( mArrayCount,pItem );
318 if (
this != &pArrayTemplate)
322 mItemPerBlock = pArrayTemplate.mItemPerBlock;
324 SetCount(pArrayTemplate.
GetCount());
325 memcpy(mArray, pArrayTemplate.mArray,
sizeof(Type) * pArrayTemplate.
GetCount());
360 #define FB_DEFINE_ARRAY( DllTag, Type ) \
361 typedef class DllTag FBArrayTemplate< FB##Type* > FBArray##Type;
368 #define FBImplementArray( DllTag, Type ) \
369 template class DllTag FBSDKNamespaceFunc( FBArrayTemplate ) < FB##Type* >;
371 #ifdef FBSDKUseNamespace
Template class to contain an array of items.
int Find(Type pItem)
Find the index of pItem in the array.
int GetCount() const
Get the number of items in the array.
void SetLast(Type pItem)
Set the last item of the array.
~FBArrayTemplate()
Destructor.
int Add(Type pItem)
Add an item to the end of the array.
int InsertAt(int pIndex, Type pItem)
Insert pItem at pIndex.
void SetCount(int pCount)
Set the number of items in the array.
bool RemoveIt(Type pItem)
Remove pItem from the array.
bool Remove(Type &pItem)
Remove pItem from the array.
FBArrayTemplate(int pItemPerBlock=10)
Constructor.
void RemoveAt(int pIndex)
Remove item at pIndex.
void SetAt(int pIndex, Type pItem)
Set item at pIndex to pItem.
FBArrayTemplate(const FBArrayTemplate< Type > &pArrayTemplate)
Copy constructor.
FBArrayTemplate< Type > & operator=(const FBArrayTemplate< Type > &pArrayTemplate)
Copy array of pointers without copying the associated objects.
void Clear()
Empty the array of all items.
Type GetLast()
Get last item of the array.
Type * GetArray()
Get a pointer to the array of items.
Type & operator[](int pIndex) const
[] operator overload.
void RemoveLast()
Remove the last item in the array.
Type GetAt(int pIndex)
Get item at pIndex.
#define FBSDK_DLL
Ensure that FBSDK_DLL is defined only once...
K_DLLIMPORT void FBFree(void *memblock)
General free function, actually calling standard function "free".
class K_DLLIMPORT FBArrayTemplate< bool * > FBArrayHBool
Pre-defined common used array types.
K_DLLIMPORT void * FBRealloc(void *memblock, size_t size)
General allocation function, actually calling standard function "realloc".