GL Studio C++ Runtime API
DynamicArray< T, TypeIsSimple > Class Template Reference

#include <dynamic_array.h>

Public Member Functions

 DynamicArray (int initialSize=0)
 
 ~DynamicArray (void)
 
void Count (const unsigned int count)
 
unsigned int Count () const
 
unsigned int Size () const
 
void Size (unsigned int newSize)
 
void InsertObject (const T &obj, unsigned int loc)
 
unsigned int InsertObject (const T &obj)
 
void PushObject (const T &obj)
 
void InsertObjectAfter (const T &obj, unsigned int loc)
 
bool DeleteObject (const T &obj)
 
bool DeleteObjectAtIndex (unsigned int index)
 
int Position (const T &obj)
 
void EmptyList (void)
 
void ClearList (void)
 
T & operator[] (unsigned int index)
 
T * InternalArray (void)
 
DynamicArray< T, TypeIsSimple > & operator= (const DynamicArray< T, TypeIsSimple > &right)
 
bool IsEmpty (void) const
 

Protected Member Functions

void GrowArray (void)
 

Protected Attributes

unsigned int _count
 
T * _objects
 

Detailed Description

template<class T, bool TypeIsSimple = true>
class disti::DynamicArray< T, TypeIsSimple >

A templated array of objects. The array dynamically resizes as needed.

Parameters
TypeIsSimpleset to true for types which can be initialized to all zero using memset. If T is a class with a default constructor, a working '=' operator, set TypeIsSimple to false.

Constructor & Destructor Documentation

DynamicArray ( int  initialSize = 0)
inline

DynamicArray constructor

Parameters
initialSizeThe initial number of elements to be allocated for the array
~DynamicArray ( void  )
inline

DynamicArray destructor. Clears the array but does not delete the objects being pointed to by the array

Member Function Documentation

void ClearList ( void  )
inline

Clears the list so Count() is zero. Does not attempt to delete the objects data

void Count ( const unsigned int  count)
inline

Set the "Count" value for this array

unsigned int Count ( ) const
inline

Returns the number of elements used of this dynamic array

Returns
The number of elements used of the array (number of elements)
bool DeleteObject ( const T &  obj)
inline

Deletes the specified object from the list. Does not free it

Parameters
objA pointer to the object to delete
Returns
true if object was found and deleted else false
bool DeleteObjectAtIndex ( unsigned int  index)
inline

Deletes the object at the specified index. Does not free it

Parameters
indexIndex of the object to delete
Returns
true if object was found and deleted else false
void EmptyList ( void  )
inline

Empties the list, calling delete on all of its elements This method is intended for pointer data types only.

void GrowArray ( void  )
inlineprotected

Dynamic array is an array of objects Grow the array. If nothing has been allocated yet, set the size to 2 elements. Otherwise double the array size.

void InsertObject ( const T &  obj,
unsigned int  loc 
)
inline

Attempts to insert the object into the list at the specified location. If the specified location is beyond the array bounds, the object is inserted at the next position in the array.

Parameters
objThe object to insert
locThe index location to insert into
unsigned int InsertObject ( const T &  obj)
inline

Adds the specified object into the list, at the end of the list

Parameters
objA pointer to the object to add
Returns
Where the object was inserted
void InsertObjectAfter ( const T &  obj,
unsigned int  loc 
)
inline

Insert the object into the list at the specified location

Parameters
objThe object to insert
locThe index location to insert into
T* InternalArray ( void  )
inline

Return the internal array pointer If you call any other methods on this object it invalidates the pointer.

bool IsEmpty ( void  ) const
inline
Returns
true if the list is empty
DynamicArray<T, TypeIsSimple>& operator= ( const DynamicArray< T, TypeIsSimple > &  right)
inline

Overload the assignment operator to create a duplicate of the righthand operand

T& operator[] ( unsigned int  index)
inline

Overload of array operator to get element at desired index

int Position ( const T &  obj)
inline

Get the index position of the specified object in the list

Parameters
objThe object to find
Returns
The index of the object in the list, -1 if it isn't in the list
void PushObject ( const T &  obj)
inline

Adds the specified object into the list, at the head of the list Treats the list like a stack, hence the name Push

Parameters
objA pointer to the object to add
unsigned int Size ( ) const
inline

Returns the current size of this dynamic array

Returns
The current size of the array (number of elements)
void Size ( unsigned int  newSize)
inline

Sets the array size to the new size given. Reallocates the array as needed

Parameters
newSizeThe new number of elements in the array

Member Data Documentation

unsigned int _count
protected

Number of elements in the array

T* _objects
protected

Number of elements used


The documentation for this class was generated from the following file: