TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DynamicArray.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _DYNAMIC_ARRAY
 

Macros

#define Array_Create(pArray, type, ItemCountMax)   Array_Create_(pArray, sizeof(type), ItemCountMax)
 

Typedefs

typedef struct _DYNAMIC_ARRAY DYNAMIC_ARRAY
 
typedef struct _DYNAMIC_ARRAYPDYNAMIC_ARRAY
 

Functions

int Array_Create_ (PDYNAMIC_ARRAY pArray, size_t ItemSize, size_t ItemCountMax)
 
void * Array_Insert (PDYNAMIC_ARRAY pArray, const void *NewItems, size_t NewItemCount)
 
void * Array_ItemAt (PDYNAMIC_ARRAY pArray, size_t ItemIndex)
 
size_t Array_IndexOf (PDYNAMIC_ARRAY pArray, const void *ArrayPtr)
 
void Array_Free (PDYNAMIC_ARRAY pArray)
 

Macro Definition Documentation

#define Array_Create (   pArray,
  type,
  ItemCountMax 
)    Array_Create_(pArray, sizeof(type), ItemCountMax)

Typedef Documentation

typedef struct _DYNAMIC_ARRAY DYNAMIC_ARRAY
typedef struct _DYNAMIC_ARRAY * PDYNAMIC_ARRAY

Function Documentation

int Array_Create_ ( PDYNAMIC_ARRAY  pArray,
size_t  ItemSize,
size_t  ItemCountMax 
)
52 {
53  pArray->ItemArray = CASC_ALLOC(char, (ItemSize * ItemCountMax));
54  if(pArray->ItemArray == NULL)
56 
57  pArray->ItemCountMax = ItemCountMax;
58  pArray->ItemCount = 0;
59  pArray->ItemSize = ItemSize;
60  return ERROR_SUCCESS;
61 }
#define CASC_ALLOC(type, count)
Definition: CascCommon.h:302
size_t ItemSize
Definition: DynamicArray.h:22
#define ERROR_NOT_ENOUGH_MEMORY
Definition: CascPort.h:208
arena_t NULL
Definition: jemalloc_internal.h:624
char * ItemArray
Definition: DynamicArray.h:19
size_t ItemCountMax
Definition: DynamicArray.h:20
#define ERROR_SUCCESS
Definition: CascPort.h:204
size_t ItemCount
Definition: DynamicArray.h:21
void Array_Free ( PDYNAMIC_ARRAY  pArray)
96 {
97  if(pArray != NULL && pArray->ItemArray != NULL)
98  {
99  CASC_FREE(pArray->ItemArray);
100  }
101 }
arena_t NULL
Definition: jemalloc_internal.h:624
#define CASC_FREE(ptr)
Definition: CascCommon.h:303
char * ItemArray
Definition: DynamicArray.h:19

+ Here is the caller graph for this function:

size_t Array_IndexOf ( PDYNAMIC_ARRAY  pArray,
const void *  ArrayPtr 
)
88 {
89  char * ArrayItem = (char *)ArrayPtr;
90 
91  assert(pArray->ItemArray <= ArrayItem && ArrayItem <= pArray->ItemArray + (pArray->ItemCount * pArray->ItemSize));
92  return ((ArrayItem - pArray->ItemArray) / pArray->ItemSize);
93 }
size_t ItemSize
Definition: DynamicArray.h:22
char * ItemArray
Definition: DynamicArray.h:19
size_t ItemCount
Definition: DynamicArray.h:21

+ Here is the caller graph for this function:

void* Array_Insert ( PDYNAMIC_ARRAY  pArray,
const void *  NewItems,
size_t  NewItemCount 
)
64 {
65  char * NewItemPtr;
66 
67  // Try to enlarge the buffer, if needed
68  if(!EnlargeArray(pArray, pArray->ItemCount + NewItemCount))
69  return NULL;
70  NewItemPtr = pArray->ItemArray + (pArray->ItemCount * pArray->ItemSize);
71 
72  // Copy the old item(s), if any
73  if(NewItems != NULL)
74  memcpy(NewItemPtr, NewItems, (NewItemCount * pArray->ItemSize));
75 
76  // Increment the size of the array
77  pArray->ItemCount += NewItemCount;
78  return NewItemPtr;
79 }
size_t ItemSize
Definition: DynamicArray.h:22
static bool EnlargeArray(PDYNAMIC_ARRAY pArray, size_t NewItemCount)
Definition: DynamicArray.cpp:18
arena_t NULL
Definition: jemalloc_internal.h:624
char * ItemArray
Definition: DynamicArray.h:19
size_t ItemCount
Definition: DynamicArray.h:21

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* Array_ItemAt ( PDYNAMIC_ARRAY  pArray,
size_t  ItemIndex 
)
82 {
83  assert(ItemIndex < pArray->ItemCount);
84  return pArray->ItemArray + (ItemIndex * pArray->ItemSize);
85 }
size_t ItemSize
Definition: DynamicArray.h:22
char * ItemArray
Definition: DynamicArray.h:19

+ Here is the caller graph for this function: