40 #ifndef INCLUDED_DISTI_DYNAMIC_ARRAY_H
41 #define INCLUDED_DISTI_DYNAMIC_ARRAY_H
50 #if defined( _MSC_VER )
51 # pragma warning( push, 3 )
61 template<
class T,
bool TypeIsSimple = true>
72 if( !_objects || _size == 0 )
79 typedef T ElementType;
115 void Count(
const unsigned int count )
133 inline unsigned int Size()
const {
return _size; }
138 void Size(
unsigned int newSize )
147 _objects =
new T[ newSize ];
148 DistiAssert( _objects );
151 memset( _objects, 0, newSize *
sizeof( T ) );
157 if( newSize == _size )
160 newobjs =
new T[ newSize ];
161 DistiAssert( newobjs );
163 if( newSize > _size )
169 memcpy( newobjs, _objects, _size *
sizeof( T ) );
173 for(
unsigned int i = 0; i < _size; i++ )
175 newobjs[ i ] = _objects[ i ];
180 memset( newobjs + _size, 0, ( newSize - _size ) *
sizeof( T ) );
188 memcpy( newobjs, _objects, newSize *
sizeof( T ) );
192 for(
unsigned int i = 0; i < newSize; i++ )
194 newobjs[ i ] = _objects[ i ];
243 for(
unsigned int i = _count - 1; i > loc; i-- )
245 _objects[ i ] = _objects[ i - 1 ];
248 _objects[ loc ] = obj;
304 if( index >= _count )
310 for(
unsigned int j = index; j < ( _count - 1u ); j++ )
312 _objects[ j ] = _objects[ j + 1u ];
326 for(
unsigned int i = 0; i <
_count; i++ )
327 if( obj == _objects[ i ] )
337 for(
unsigned int i = 0; i <
Count(); i++ )
338 delete _objects[ i ];
351 memset( _objects, 0,
sizeof( T ) * _size );
369 DistiAssert(
int( index ) >= 0 );
378 else if( index >= _count )
383 return _objects[ index ];
389 GLS_ASSERT( index < _size && index < _count );
390 return _objects[ index ];
411 for(
unsigned int i = 0; i <
Size(); i++ )
413 _objects[ i ] = right.
_objects[ i ];
415 _count = right.
Count();
422 return ( _count == 0 );
427 template<
class T,
bool TypeIsSimple>
430 if( array.
Count() == 0 )
438 template<
class T,
bool TypeIsSimple>
441 if( array.
Count() == 0 )
449 template<
class T,
bool TypeIsSimple>
456 template<
class T,
bool TypeIsSimple>
462 #if defined( _MSC_VER )
463 # pragma warning( pop )
void ClearList(void)
Definition: dynamic_array.h:344
DynamicArray< T, TypeIsSimple > & operator=(const DynamicArray< T, TypeIsSimple > &right)
Definition: dynamic_array.h:408
unsigned int Count() const
Definition: dynamic_array.h:128
Definition: dynamic_array.h:62
T & operator[](unsigned int index)
Definition: dynamic_array.h:367
T * begin(DynamicArray< T, TypeIsSimple > &array)
Overload begin() so that range-for loops and other constructs work with DynamicArray.
Definition: dynamic_array.h:428
int Position(const T &obj)
Definition: dynamic_array.h:324
void EmptyList(void)
Definition: dynamic_array.h:335
void InsertObjectAfter(const T &obj, unsigned int loc)
Definition: dynamic_array.h:279
unsigned int InsertObject(const T &obj)
Definition: dynamic_array.h:255
bool IsEmpty(void) const
Definition: dynamic_array.h:420
bool DeleteObjectAtIndex(unsigned int index)
Definition: dynamic_array.h:302
void InsertObject(const T &obj, unsigned int loc)
Definition: dynamic_array.h:225
A file for all GL Studio files to include.
void GrowArray(void)
Definition: dynamic_array.h:70
bool DeleteObject(const T &obj)
Definition: dynamic_array.h:288
void Count(const unsigned int count)
Definition: dynamic_array.h:115
T * end(DynamicArray< T, TypeIsSimple > &array)
Overload end() so that range-for loops and other constructs work with DynamicArray.
Definition: dynamic_array.h:450
~DynamicArray(void)
Definition: dynamic_array.h:105
unsigned int _count
Definition: dynamic_array.h:66
T * InternalArray()
Definition: dynamic_array.h:395
void PushObject(const T &obj)
Definition: dynamic_array.h:270
DynamicArray(int initialSize=0)
Definition: dynamic_array.h:84
void Size(unsigned int newSize)
Definition: dynamic_array.h:138
const T * InternalArray() const
Definition: dynamic_array.h:402
const T & operator[](const unsigned int index) const
Definition: dynamic_array.h:387
Contains the DistiAssert macro.
unsigned int Size() const
Definition: dynamic_array.h:133
Definition: bmpimage.h:46
T * _objects
Definition: dynamic_array.h:67
#define GLS_ASSERT(exp)
Definition: disti_assert.h:135