1 #ifndef _DYNAMIC_ARRAY_H
2 #define _DYNAMIC_ARRAY_H
50 #if defined (_MSC_VER)
51 #pragma warning( push, 3 )
60 template <
class T,
bool TypeIsSimple = true>
73 if (!_objects || _size == 0)
81 typedef T ElementType;
118 void Count(
const unsigned int count)
136 inline unsigned int Size()
const {
return _size; }
141 void Size(
unsigned int newSize)
150 _objects =
new T[newSize];
154 memset(_objects,0,newSize*
sizeof(T));
160 if (newSize == _size)
163 newobjs =
new T[newSize];
172 memcpy(newobjs,_objects,_size*
sizeof(T));
176 for(
unsigned int i=0; i < _size; i++)
178 newobjs[i] = _objects[i];
183 memset(newobjs+_size,0,(newSize-_size)*
sizeof(T));
192 memcpy(newobjs,_objects,newSize*
sizeof(T));
196 for(
unsigned int i=0; i < newSize; i++)
198 newobjs[i] = _objects[i];
247 for (
unsigned int i=_count-1; i > loc; i--)
249 _objects[i] = _objects[i-1];
314 for (
unsigned int j=index; j < (_count - 1u); j++)
316 _objects[j] = _objects[j+1u];
330 for (
unsigned int i=0;i <
_count; i++)
331 if (obj==_objects[i])
341 for (
unsigned int i=0; i <
Count(); i++)
355 memset(_objects,0,
sizeof(T) * _size);
373 assert(
int(index) >= 0);
382 else if (index >= _count)
387 return _objects[index];
393 assert(
int(index) >= 0);
402 else if (index >= _count)
407 return _objects[index];
422 for(
unsigned int i = 0; i <
Size(); i++)
426 _count = right.
Count();
437 #if defined (_MSC_VER)
438 #pragma warning( pop )
void ClearList(void)
Definition: dynamic_array.h:348
unsigned int Count() const
Definition: dynamic_array.h:131
A templated array of objects. The array dynamically resizes as needed.
Definition: dynamic_array.h:61
T & operator[](unsigned int index)
Definition: dynamic_array.h:371
int Position(const T &obj)
Definition: dynamic_array.h:328
void EmptyList(void)
Definition: dynamic_array.h:339
void InsertObjectAfter(const T &obj, unsigned int loc)
Definition: dynamic_array.h:283
unsigned int InsertObject(const T &obj)
Definition: dynamic_array.h:259
bool IsEmpty(void) const
Definition: dynamic_array.h:431
bool DeleteObjectAtIndex(unsigned int index)
Definition: dynamic_array.h:306
void InsertObject(const T &obj, unsigned int loc)
Definition: dynamic_array.h:229
void GrowArray(void)
Definition: dynamic_array.h:71
bool DeleteObject(const T &obj)
Definition: dynamic_array.h:292
void Count(const unsigned int count)
Definition: dynamic_array.h:118
~DynamicArray(void)
Definition: dynamic_array.h:107
unsigned int _count
Definition: dynamic_array.h:66
T * InternalArray(void)
Definition: dynamic_array.h:413
void PushObject(const T &obj)
Definition: dynamic_array.h:274
DynamicArray(int initialSize=0)
Definition: dynamic_array.h:86
void Size(unsigned int newSize)
Definition: dynamic_array.h:141
DynamicArray< T, TypeIsSimple > & operator=(const DynamicArray< T, TypeIsSimple > &right)
Definition: dynamic_array.h:419
unsigned int Size() const
Definition: dynamic_array.h:136
Definition: AttributeChangedEmitter.h:46
T * _objects
Definition: dynamic_array.h:67