aboutsummaryrefslogtreecommitdiff
path: root/dep/CascLib/src/common/DynamicArray.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2019-06-06 16:48:21 +0200
committerShauren <shauren.trinity@gmail.com>2019-06-08 17:09:24 +0200
commitfc330fd8ff0115804d9c4b53a1f810c00dd63de9 (patch)
treecfa10998fed66779834bf0b7a9b8b799d33d91d4 /dep/CascLib/src/common/DynamicArray.cpp
parent82c7b6c5688495d90c4ee5995a4ff74039348296 (diff)
Dep/CascLib: Update to ladislav-zezula/CascLib@a1197edf0b3bd4d52c3f39be7fa7b44bb0b98012
Diffstat (limited to 'dep/CascLib/src/common/DynamicArray.cpp')
-rw-r--r--dep/CascLib/src/common/DynamicArray.cpp101
1 files changed, 0 insertions, 101 deletions
diff --git a/dep/CascLib/src/common/DynamicArray.cpp b/dep/CascLib/src/common/DynamicArray.cpp
deleted file mode 100644
index e744fbe3912..00000000000
--- a/dep/CascLib/src/common/DynamicArray.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/*****************************************************************************/
-/* DynamicArray.cpp Copyright (c) Ladislav Zezula 2015 */
-/*---------------------------------------------------------------------------*/
-/* Description: */
-/*---------------------------------------------------------------------------*/
-/* Date Ver Who Comment */
-/* -------- ---- --- ------- */
-/* 30.10.15 1.00 Lad The first version of DynamicArray.cpp */
-/*****************************************************************************/
-
-#define __CASCLIB_SELF__
-#include "../CascLib.h"
-#include "../CascCommon.h"
-
-//-----------------------------------------------------------------------------
-// Local functions
-
-static bool EnlargeArray(PDYNAMIC_ARRAY pArray, size_t NewItemCount)
-{
- char * NewItemArray;
- size_t ItemCountMax;
-
- // We expect the array to be already allocated
- assert(pArray->ItemArray != NULL);
- assert(pArray->ItemCountMax != 0);
-
- // Shall we enlarge the table?
- if(NewItemCount > pArray->ItemCountMax)
- {
- // Calculate new table size
- ItemCountMax = pArray->ItemCountMax;
- while(ItemCountMax < NewItemCount)
- ItemCountMax = ItemCountMax << 1;
-
- // Allocate new table
- NewItemArray = CASC_REALLOC(char, pArray->ItemArray, pArray->ItemSize * ItemCountMax);
- if(NewItemArray == NULL)
- return false;
-
- // Set the new table size
- pArray->ItemCountMax = ItemCountMax;
- pArray->ItemArray = NewItemArray;
- }
-
- return true;
-}
-
-//-----------------------------------------------------------------------------
-// Public functions
-
-int Array_Create_(PDYNAMIC_ARRAY pArray, size_t ItemSize, size_t ItemCountMax)
-{
- pArray->ItemArray = CASC_ALLOC(char, (ItemSize * ItemCountMax));
- if(pArray->ItemArray == NULL)
- return ERROR_NOT_ENOUGH_MEMORY;
-
- pArray->ItemCountMax = ItemCountMax;
- pArray->ItemCount = 0;
- pArray->ItemSize = ItemSize;
- return ERROR_SUCCESS;
-}
-
-void * Array_Insert(PDYNAMIC_ARRAY pArray, const void * NewItems, size_t NewItemCount)
-{
- char * NewItemPtr;
-
- // Try to enlarge the buffer, if needed
- if(!EnlargeArray(pArray, pArray->ItemCount + NewItemCount))
- return NULL;
- NewItemPtr = pArray->ItemArray + (pArray->ItemCount * pArray->ItemSize);
-
- // Copy the old item(s), if any
- if(NewItems != NULL)
- memcpy(NewItemPtr, NewItems, (NewItemCount * pArray->ItemSize));
-
- // Increment the size of the array
- pArray->ItemCount += NewItemCount;
- return NewItemPtr;
-}
-
-void * Array_ItemAt(PDYNAMIC_ARRAY pArray, size_t ItemIndex)
-{
- assert(ItemIndex < pArray->ItemCount);
- return pArray->ItemArray + (ItemIndex * pArray->ItemSize);
-}
-
-size_t Array_IndexOf(PDYNAMIC_ARRAY pArray, const void * ArrayPtr)
-{
- char * ArrayItem = (char *)ArrayPtr;
-
- assert(pArray->ItemArray <= ArrayItem && ArrayItem <= pArray->ItemArray + (pArray->ItemCount * pArray->ItemSize));
- return ((ArrayItem - pArray->ItemArray) / pArray->ItemSize);
-}
-
-void Array_Free(PDYNAMIC_ARRAY pArray)
-{
- if(pArray != NULL && pArray->ItemArray != NULL)
- {
- CASC_FREE(pArray->ItemArray);
- }
-}