6#if !defined(CXTEMPLATE_INCLUDE_H)
7#define CXTEMPLATE_INCLUDE_H
15BEGIN_MOOTOOLS_NAMESPACE
20template <
class TYPE,
class ARG_TYPE>
class CXArray;
32template<
class TYPE,
class ARG_TYPE = const TYPE&>
46 CXArray(
bool enableMemcpy =
true);
50 int GetSizeOfElement()
const;
71 const TYPE& operator[](
int index)
const;
72 TYPE& operator[](
int index);
95#ifndef MOOTOOLS_NO_ARCHIVE_SUPPORT
106template<
class TYPE,
class ARG_TYPE>
112template<
class TYPE,
class ARG_TYPE>
118template<
class TYPE,
class ARG_TYPE>
124 SetSize(0,
keepBuffer ? GROW_KEEP_MODE : GROW_DEFAULT);
128template<
class TYPE,
class ARG_TYPE>
131 return (
const TYPE*)buffer;
134template<
class TYPE,
class ARG_TYPE>
137 return (
TYPE*)buffer;
140template<
class TYPE,
class ARG_TYPE>
143 int index = elementCount;
148template<
class TYPE,
class ARG_TYPE>
151 XASSERT(index >= 0 && index < elementCount);
152 if(index >= 0 && index < elementCount)
153 return buffer[index];
155 XThrowException(CXInvalidArgException);
158template<
class TYPE,
class ARG_TYPE>
161 XASSERT(index >= 0 && index < elementCount);
162 if(index >= 0 && index < elementCount)
163 return buffer[index];
165 XThrowException(CXInvalidArgException);
177 while (elementCount--)
192template<
class TYPE,
class ARG_TYPE>
196 elementCount = maxElementCount = 0;
197 growElementCount = GROW_DEFAULT;
201template<
class TYPE,
class ARG_TYPE>
205 elementCount = maxElementCount = 0;
206 growElementCount =
copyFrom.growElementCount;
207 this->enableMemcpy =
copyFrom.enableMemcpy;
211template<
class TYPE,
class ARG_TYPE>
218#ifndef MOOTOOLS_FOR_UNREAL
222 for (
int i = 0;
i < elementCount;
i++ )
223 (buffer +
i)->~TYPE();
225 xDeallocateArray((
unsigned char *)buffer);
226#ifndef MOOTOOLS_FOR_UNREAL
230 XTRACE(
_T(
"Array: exception in destructor occured.\n"));
236template<
class TYPE,
class ARG_TYPE>
239 if (size == maxElementCount && elementCount == 0)
244 maxElementCount = size;
248template<
class TYPE,
class ARG_TYPE>
255 XThrowException(CXInvalidArgException);
265 for (
int i = 0;
i < elementCount;
i++ )
266 (buffer +
i)->~TYPE();
270 xDeallocateArray((
unsigned char *)buffer);
279 else if (buffer ==
NULL)
290 xConstruct(
TYPE, (
void*)(buffer+
i));
295 else if (
newCount <= maxElementCount)
301 memset((
void*)(buffer + elementCount), 0, (
size_t)(
newCount-elementCount) *
sizeof(
TYPE));
303 xConstruct(
TYPE, (
void*)(buffer+elementCount+
i));
336 XThrowException(CXInvalidArgException);
353 for (
i = 0;
i < elementCount;
i++)
356 for (
i = 0;
i < elementCount;
i++)
359 for (
i = 0;
i < elementCount;
i++)
360 (buffer +
i)->~TYPE();
371 xDeallocateArray((
unsigned char *)buffer);
379template<
class TYPE,
class ARG_TYPE>
391template<
class TYPE,
class ARG_TYPE>
398 enableMemcpy =
src.enableMemcpy;
400 SetSize(
src.elementCount);
405template<
class TYPE,
class ARG_TYPE>
419template<
class TYPE,
class ARG_TYPE>
424 if (elementCount != maxElementCount)
431 if (elementCount != 0)
438 xmemcpy_s(
newBuffer, elementCount *
sizeof(
TYPE), buffer, elementCount *
sizeof(
TYPE));
445 for (
i = 0;
i < elementCount;
i++)
448 for (
i = 0;
i < elementCount;
i++)
451 for (
i = 0;
i < elementCount;
i++)
452 (buffer +
i)->~TYPE();
456 xDeallocateArray((
unsigned char *)buffer);
460 maxElementCount = elementCount;
464template<
class TYPE,
class ARG_TYPE>
471 XThrowException(CXInvalidArgException);
473 if (index >= elementCount)
478template<
class TYPE,
class ARG_TYPE>
486 XThrowException(CXInvalidArgException);
488 if (index >= elementCount)
511 xConstruct(
TYPE, (
void*)(buffer + index +
i));
531template<
class TYPE,
class ARG_TYPE>
541 XThrowException(CXInvalidArgException);
546 (buffer + index +
i)->~TYPE();
567template<
class TYPE,
class ARG_TYPE>
571 int i, size = GetSize();
572 for (
i = 0;
i < size;
i++)
591#ifndef MOOTOOLS_NO_ARCHIVE_SUPPORT
592template<> DLL_TOOLSFUNCTION
void CXStringArray::Serialize(
CXArchive&
ar);
596template<
class TYPE,
class ARG_TYPE>
601 XTRACE(
_T(
"with %d elements\n"));
606END_MOOTOOLS_NAMESPACE
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
CXArray is an array of simple data information which does not requires to call a constructor / destru...
Definition XTemplate.h:34
GrowMode
Definition XTemplate.h:39
@ GROW_DEFAULT
A default grow mode which increase the array size by 1024 bytes each times its needed....
Definition XTemplate.h:40
@ GROW_DOUBLE_SIZE
Double size the array for fast element growing (required when the final element number is not known,...
Definition XTemplate.h:42
@ GROW_KEEP_MODE
Keep the default grow size (SetAtGrow, SetSize)
Definition XTemplate.h:41
void PreAllocate(int size, int newGrowCount=GROW_KEEP_MODE)
Preallocate size elements. GetSize() return 0 after the call.
Definition XTemplate.h:237
bool Remove(ARG_TYPE newElement, bool firstonly=true)
Remove newElement and return true if found. If firstonly = true, the return return once the first new...
Definition XTemplate.h:568
void SetSize(int newCount, int newGrowCount=GROW_KEEP_MODE)
The buffer always grows unless FreeExtra / RemoveAll(false) is called.
Definition XTemplate.h:249
const TYPE * GetData() const
Get raw array const data access.
Definition XTemplate.h:129
void RemoveAll(bool keepBuffer=false)
Remove all data and set size to 0.
Definition XTemplate.h:119
TYPE * GetData()
Get raw array data access for modifying data directly.
Definition XTemplate.h:135
int AddArray(const CXArray< TYPE, ARG_TYPE > &src)
Add an array to another array. There might be duplicated items.
Definition XTemplate.h:406
void FreeExtra()
Remove extra data allocated when adding data.
Definition XTemplate.h:420
CXStringArray implement an array of CXString.
Definition XStringArray.h:25