TrinityCore
CASC_ARRAY Class Reference

#include <Array.h>

Public Member Functions

 CASC_ARRAY ()
 
 ~CASC_ARRAY ()
 
template<typename TYPE >
int Create (size_t ItemCountMax)
 
int Create (size_t ItemSize, size_t ItemCountMax)
 
void * Insert (size_t NewItemCount, bool bEnlargeAllowed=true)
 
void * Insert (const void *NewItems, size_t NewItemCount, bool bEnlargeAllowed=true)
 
void * ItemAt (size_t ItemIndex)
 
void * LastItem ()
 
void * InsertAt (size_t ItemIndex)
 
size_t IndexOf (const void *pItem)
 
void * ItemArray ()
 
size_t ItemCount ()
 
size_t ItemCountMax ()
 
size_t ItemSize ()
 
bool IsInitialized ()
 
void Reset ()
 
void Free ()
 

Protected Member Functions

bool EnlargeArray (size_t NewItemCount, bool bEnlargeAllowed)
 

Protected Attributes

LPBYTE m_pItemArray
 
size_t m_ItemCountMax
 
size_t m_ItemCount
 
size_t m_ItemSize
 

Constructor & Destructor Documentation

◆ CASC_ARRAY()

CASC_ARRAY::CASC_ARRAY ( )
inline
23  {
24  m_pItemArray = NULL;
25  m_ItemCountMax = 0;
26  m_ItemCount = 0;
27  m_ItemSize = 0;
28  }
size_t m_ItemCount
Definition: Array.h:208
size_t m_ItemCountMax
Definition: Array.h:207
LPBYTE m_pItemArray
Definition: Array.h:206
size_t m_ItemSize
Definition: Array.h:209

◆ ~CASC_ARRAY()

CASC_ARRAY::~CASC_ARRAY ( )
inline
31  {
32  Free();
33  }
void Free()
Definition: Array.h:164
+ Here is the call graph for this function:

Member Function Documentation

◆ Create() [1/2]

template<typename TYPE >
int CASC_ARRAY::Create ( size_t  ItemCountMax)
inline
38  {
39  return Create(sizeof(TYPE), ItemCountMax);
40  }
Definition: inflate.h:32
int Create(size_t ItemCountMax)
Definition: Array.h:37
size_t ItemCountMax()
Definition: Array.h:141
+ Here is the caller graph for this function:

◆ Create() [2/2]

int CASC_ARRAY::Create ( size_t  ItemSize,
size_t  ItemCountMax 
)
inline
44  {
45  // Create the array
46  if ((m_pItemArray = CASC_ALLOC<BYTE>(ItemSize * ItemCountMax)) == NULL)
48 
50  m_ItemCount = 0;
52  return ERROR_SUCCESS;
53  }
#define ERROR_NOT_ENOUGH_MEMORY
Definition: CascPort.h:235
size_t m_ItemCount
Definition: Array.h:208
size_t ItemSize()
Definition: Array.h:146
size_t m_ItemCountMax
Definition: Array.h:207
LPBYTE m_pItemArray
Definition: Array.h:206
size_t ItemCountMax()
Definition: Array.h:141
#define ERROR_SUCCESS
Definition: CascPort.h:230
size_t m_ItemSize
Definition: Array.h:209
+ Here is the call graph for this function:

◆ EnlargeArray()

bool CASC_ARRAY::EnlargeArray ( size_t  NewItemCount,
bool  bEnlargeAllowed 
)
inlineprotected
173  {
174  LPBYTE NewItemArray;
175  size_t ItemCountMax;
176 
177  // We expect the array to be already allocated
178  assert(m_pItemArray != NULL);
179  assert(m_ItemCountMax != 0);
180 
181  // Shall we enlarge the table?
182  if (NewItemCount > m_ItemCountMax)
183  {
184  // Deny enlarge if not allowed
185  if(bEnlargeAllowed == false)
186  return false;
187 
188  // Calculate new table size
189  ItemCountMax = m_ItemCountMax;
190  while (ItemCountMax < NewItemCount)
191  ItemCountMax = ItemCountMax << 1;
192 
193  // Allocate new table
194  NewItemArray = CASC_REALLOC(BYTE, m_pItemArray, (ItemCountMax * m_ItemSize));
195  if (NewItemArray == NULL)
196  return false;
197 
198  // Set the new table size
200  m_pItemArray = NewItemArray;
201  }
202 
203  return true;
204  }
#define assert(e)
Definition: assert.h:9
BYTE * LPBYTE
Definition: CascPort.h:173
size_t m_ItemCountMax
Definition: Array.h:207
LPBYTE m_pItemArray
Definition: Array.h:206
size_t ItemCountMax()
Definition: Array.h:141
#define CASC_REALLOC(type, ptr, count)
Definition: Common.h:143
unsigned char BYTE
Definition: CascPort.h:159
size_t m_ItemSize
Definition: Array.h:209
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Free()

void CASC_ARRAY::Free ( )
inline
165  {
168  }
size_t m_ItemCount
Definition: Array.h:208
size_t m_ItemCountMax
Definition: Array.h:207
LPBYTE m_pItemArray
Definition: Array.h:206
void CASC_FREE(T *&ptr)
Definition: Common.h:162
size_t m_ItemSize
Definition: Array.h:209
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IndexOf()

size_t CASC_ARRAY::IndexOf ( const void *  pItem)
inline
122  {
123  LPBYTE pbItem = (LPBYTE)pItem;
124 
125  assert((m_pItemArray <= pbItem) && (pbItem <= m_pItemArray + (m_ItemCount * m_ItemSize)));
126  assert(((pbItem - m_pItemArray) % m_ItemSize) == 0);
127 
128  return ((pbItem - m_pItemArray) / m_ItemSize);
129  }
#define assert(e)
Definition: assert.h:9
size_t m_ItemCount
Definition: Array.h:208
BYTE * LPBYTE
Definition: CascPort.h:173
LPBYTE m_pItemArray
Definition: Array.h:206
size_t m_ItemSize
Definition: Array.h:209
+ Here is the caller graph for this function:

◆ Insert() [1/2]

void* CASC_ARRAY::Insert ( size_t  NewItemCount,
bool  bEnlargeAllowed = true 
)
inline
57  {
58  void * pNewItems;
59 
60  // Try to enlarge the buffer, if needed
61  if (!EnlargeArray(m_ItemCount + NewItemCount, bEnlargeAllowed))
62  return NULL;
63  pNewItems = m_pItemArray + (m_ItemCount * m_ItemSize);
64 
65  // Increment the size of the array
66  m_ItemCount += NewItemCount;
67 
68  // Return pointer to the new item
69  return pNewItems;
70  }
size_t m_ItemCount
Definition: Array.h:208
LPBYTE m_pItemArray
Definition: Array.h:206
bool EnlargeArray(size_t NewItemCount, bool bEnlargeAllowed)
Definition: Array.h:172
size_t m_ItemSize
Definition: Array.h:209
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Insert() [2/2]

void* CASC_ARRAY::Insert ( const void *  NewItems,
size_t  NewItemCount,
bool  bEnlargeAllowed = true 
)
inline
74  {
75  void * pNewItem = Insert(NewItemCount, bEnlargeAllowed);
76 
77  // Copy the item(s) to the array, if any
78  if (pNewItem && NewItems)
79  memcpy(pNewItem, NewItems, (NewItemCount * m_ItemSize));
80  return pNewItem;
81  }
void * Insert(size_t NewItemCount, bool bEnlargeAllowed=true)
Definition: Array.h:56
size_t m_ItemSize
Definition: Array.h:209
+ Here is the call graph for this function:

◆ InsertAt()

void* CASC_ARRAY::InsertAt ( size_t  ItemIndex)
inline
97  {
98  LPBYTE pbLastItem;
99  LPBYTE pbNewItem;
100 
101  // Make sure we have array large enough
102  if(!EnlargeArray(ItemIndex + 1, true))
103  return NULL;
104 
105  // Get the items range
106  pbLastItem = m_pItemArray + (m_ItemCount * m_ItemSize);
107  pbNewItem = m_pItemArray + (ItemIndex * m_ItemSize);
108  m_ItemCount = CASCLIB_MAX(m_ItemCount, ItemIndex+1);
109 
110  // If we inserted an item past the current end, we need to clear the items in-between
111  if (pbNewItem > pbLastItem)
112  {
113  memset(pbLastItem, 0, (pbNewItem - pbLastItem));
114  m_ItemCount = ItemIndex + 1;
115  }
116 
117  return pbNewItem;
118  }
size_t m_ItemCount
Definition: Array.h:208
BYTE * LPBYTE
Definition: CascPort.h:173
LPBYTE m_pItemArray
Definition: Array.h:206
#define CASCLIB_MAX(a, b)
Definition: Common.h:27
bool EnlargeArray(size_t NewItemCount, bool bEnlargeAllowed)
Definition: Array.h:172
size_t m_ItemSize
Definition: Array.h:209
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsInitialized()

bool CASC_ARRAY::IsInitialized ( )
inline
152  {
153  return (m_pItemArray && m_ItemCountMax);
154  }
size_t m_ItemCountMax
Definition: Array.h:207
LPBYTE m_pItemArray
Definition: Array.h:206
+ Here is the caller graph for this function:

◆ ItemArray()

void* CASC_ARRAY::ItemArray ( )
inline
132  {
133  return m_pItemArray;
134  }
LPBYTE m_pItemArray
Definition: Array.h:206
+ Here is the caller graph for this function:

◆ ItemAt()

void* CASC_ARRAY::ItemAt ( size_t  ItemIndex)
inline
85  {
86  return (ItemIndex < m_ItemCount) ? (m_pItemArray + (ItemIndex * m_ItemSize)) : NULL;
87  }
size_t m_ItemCount
Definition: Array.h:208
LPBYTE m_pItemArray
Definition: Array.h:206
size_t m_ItemSize
Definition: Array.h:209
+ Here is the caller graph for this function:

◆ ItemCount()

size_t CASC_ARRAY::ItemCount ( )
inline
137  {
138  return m_ItemCount;
139  }
size_t m_ItemCount
Definition: Array.h:208
+ Here is the caller graph for this function:

◆ ItemCountMax()

size_t CASC_ARRAY::ItemCountMax ( )
inline
142  {
143  return m_ItemCountMax;
144  }
size_t m_ItemCountMax
Definition: Array.h:207
+ Here is the caller graph for this function:

◆ ItemSize()

size_t CASC_ARRAY::ItemSize ( )
inline
147  {
148  return m_ItemSize;
149  }
size_t m_ItemSize
Definition: Array.h:209
+ Here is the caller graph for this function:

◆ LastItem()

void* CASC_ARRAY::LastItem ( )
inline
90  {
91  return m_pItemArray + (m_ItemCount * m_ItemSize);
92  }
size_t m_ItemCount
Definition: Array.h:208
LPBYTE m_pItemArray
Definition: Array.h:206
size_t m_ItemSize
Definition: Array.h:209

◆ Reset()

void CASC_ARRAY::Reset ( )
inline
158  {
159  memset(m_pItemArray, 0, m_ItemCountMax * m_ItemSize);
160  m_ItemCount = 0;
161  }
size_t m_ItemCount
Definition: Array.h:208
size_t m_ItemCountMax
Definition: Array.h:207
LPBYTE m_pItemArray
Definition: Array.h:206
size_t m_ItemSize
Definition: Array.h:209
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_ItemCount

size_t CASC_ARRAY::m_ItemCount
protected

◆ m_ItemCountMax

size_t CASC_ARRAY::m_ItemCountMax
protected

◆ m_ItemSize

size_t CASC_ARRAY::m_ItemSize
protected

◆ m_pItemArray

LPBYTE CASC_ARRAY::m_pItemArray
protected

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