11 #define DAINLINE inline
14 namespace VK_NoStepInto_Namespace {
16 template <
class _Type>
25 bool InitItems (
unsigned long dwStartIndex,
unsigned long dwNumStructs);
49 bool Delete (
unsigned long dwStartIndex,
unsigned long dwNumStructs);
57 bool Insert (
unsigned long dwStartIndex,
unsigned long dwNumStructs);
63 bool Swap (
unsigned long dwIndex1,
unsigned long dwIndex2);
74 DAINLINE _Type &
Get(
unsigned long index) {
return (*
this)[index]; }
75 DAINLINE const _Type &
Get(
unsigned long index)
const {
return (*
this)[index]; }
96 template <
class _Type>
109 template <
class _Type>
124 template <
class _Type>
127 dwAllocBy = _dwAllocBy;
137 template <
class _Type>
143 template <
class _Type>
149 template <
class _Type>
159 dwAlloc = dwNum = dwInited = 0;
165 template <
class _Type>
168 unsigned long dw = dwAlloc - dwNum;
173 if (!Delete (dwNum, dw))
178 tmpMem = (_Type*)malloc (dwNum *
sizeof (_Type));
179 if (!tmpMem && dwNum)
181 memcpy (tmpMem, lpBuffer, dwNum *
sizeof (_Type));
183 lpBuffer = (_Type*)tmpMem;
191 template <
class _Type>
195 unsigned long dwNN = dwNum + _dwNum;
197 if (dwNN <= dwInited)
200 if (dwNN > dwAlloc) {
203 unsigned long dwLAlloc = dwAlloc;
206 dw = ((dwNN + dwAllocBy - 1) / dwAllocBy) * dwAllocBy;
208 dw = dwNN + dwAllocBy - 1;
209 dw = dw - (dw % dwAllocBy);
213 tmpMem = (_Type*)malloc (dw *
sizeof (_Type));
218 memcpy (tmpMem, lpBuffer, dwInited *
sizeof (_Type));
224 lpBuffer = (_Type*)tmpMem;
228 if (!InitItems (dwInited, dwNN - dwInited))
236 template <
class _Type>
241 for (dw = dwStartIndex; dw < dwStartIndex + dwNumStructs; dw++) {
242 new ((
void*)(lpBuffer + dw)) _Type;
249 template <
class _Type>
252 if ((dwStartIndex >= dwAlloc) || (dwStartIndex >= dwInited) || (!dwNumStructs))
257 if (dwStartIndex + dwNumStructs > dwInited)
258 dwNumStructs = dwInited - dwStartIndex;
260 for (dw = dwStartIndex; dw < dwStartIndex + dwNumStructs; dw++)
261 ((_Type*)(lpBuffer + dw))->~_Type ();
264 memcpy (lpBuffer + dwStartIndex, lpBuffer + dwStartIndex + dwNumStructs, (dwInited - dwNumStructs - dwStartIndex) *
sizeof (_Type));
266 dwInited -= dwNumStructs;
268 if (dwStartIndex < dwNum) {
269 if (dwStartIndex + dwNumStructs < dwNum)
270 dwNum -= dwNumStructs;
272 dwNum = dwStartIndex;
279 template <
class _Type>
282 return Delete (0, dwAlloc);
286 template <
class _Type>
289 if (dwInited <= dwNum)
292 return Delete (dwNum, dwInited - dwNum);
296 template <
class _Type>
302 if (!PrepareNext (dwNumStructs))
305 if (dwStartIndex >= dwNum) {
306 dwNum += dwNumStructs;
310 _Type *tmpObjs = NULL;
311 if (!(tmpObjs = (_Type*)malloc (dwNumStructs *
sizeof (_Type))))
313 memcpy (tmpObjs, lpBuffer + dwNum, dwNumStructs *
sizeof (_Type));
316 for (dw = dwNum + dwNumStructs - 1; dw >= dwStartIndex + dwNumStructs; dw--)
317 lpBuffer[dw] = lpBuffer[dw - dwNumStructs];
318 dwNum += dwNumStructs;
320 memcpy (lpBuffer + dwStartIndex, tmpObjs, dwNumStructs *
sizeof (_Type));
327 template <
class _Type>
334 lpBuffer = (_Type*)malloc (src->
dwNum * sizeof (_Type));
338 dwNum = dwAlloc = dwInited = src->
dwNum;
341 for (dw = 0; dw < src->
dwNum; dw++) {
342 new ((
void*)(lpBuffer + dw)) _Type (src->
lpBuffer[dw]);
349 template <
class _Type>
352 if (dwIndex1 == dwIndex2)
355 if ((dwIndex1 >= dwInited) || (dwIndex2 >= dwInited))
360 memcpy (&tmp, lpBuffer + dwIndex1,
sizeof (_Type));
361 memcpy (lpBuffer + dwIndex1, lpBuffer + dwIndex2,
sizeof (_Type));
362 memcpy (lpBuffer + dwIndex2, &tmp,
sizeof (_Type));
368 template <
class _Type>
371 if (!PrepareNext (1))
373 lpBuffer[dwNum++] = newItem;
378 template <
class _Type>
384 OutputDebugStringA (
"ERROR: DynArray: index error: dw >= dwAlloc\n");
386 OutputDebugStringA (
"ERROR: DynArray: index error: dw >= dwInited\n");
393 template <
class _Type>
399 OutputDebugStringA (
"ERROR: DynArray: index error: dw >= dwAlloc\n");
401 OutputDebugStringA (
"ERROR: DynArray: index error: dw >= dwInited\n");
408 template <
class _Type>
413 unsigned long dw = dwNum - 1;
415 OutputDebugStringA (
"ERROR: DynArray: index error: dw >= dwAlloc\n");
417 OutputDebugStringA (
"ERROR: DynArray: index error: dw >= dwInited\n");
421 return (lpBuffer[dwNum - 1]);
425 template <
class _Type>
430 unsigned long dw = dwNum;
432 OutputDebugStringA (
"ERROR: DynArray: index error: dw >= dwAlloc\n");
434 OutputDebugStringA (
"ERROR: DynArray: index error: dw >= dwInited\n");
438 return (lpBuffer[dwNum]);
441 template <
class _Type>
444 return (*((
unsigned long*)(lpBuffer + dwNum)));
447 template <
class _Type>
450 return (*((
int*)(lpBuffer + dwNum)));
453 template <
class _Type>
456 if (
sizeof (_Type) != 1)
459 if (!PrepareNext (1))
462 *((
unsigned char*)(lpBuffer + dwNum)) = bData;
468 template <
class _Type>
471 if ((4 %
sizeof (_Type)) != 0)
473 if (!PrepareNext (4 /
sizeof (_Type)))
476 *((
unsigned long*)(lpBuffer + dwNum)) = dwData;
477 dwNum += 4 /
sizeof (_Type);
482 template <
class _Type>
485 return *((
unsigned char*)(lpBuffer + (dwNum++)));
488 template <
class _Type>
491 unsigned long dw = *((
unsigned long*)(lpBuffer + dwNum));
492 dwNum += 4 /
sizeof (_Type);
504 #endif // DYNAMICARRAY_H