DataDirector API
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
DynamicPtrArray< T > Class Template Reference

A templated array of object pointers. The array dynamically resizes as needed. More...

#include <dynamic_ptr_array.h>

Public Member Functions

 DynamicPtrArray (int initialSize=0)
 
 ~DynamicPtrArray (void)
 
unsigned int Count () const
 
unsigned int Size () const
 
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)
 
bool RemoveAndDeallocateObjectAtIndex (unsigned int index)
 
int Position (const T &obj)
 
bool RemoveAndDeallocate (T &obj)
 
void Swap (unsigned int a, unsigned int b)
 
void EmptyList (void)
 
void ClearList (void)
 
T & operator[] (int index)
 
const T & operator[] (int index) const
 
T * InternalArray (void)
 
DynamicPtrArray< T > & operator= (const DynamicPtrArray< T > &right)
 
bool IsEmpty (void) const
 

Protected Member Functions

void GrowArray (void)
 
void Size (unsigned int newSize)
 

Protected Attributes

unsigned int _count
 
T * _objects
 

Detailed Description

template<class T>
class disti::DynamicPtrArray< T >

A templated array of object pointers. The array dynamically resizes as needed.

Constructor & Destructor Documentation

DynamicPtrArray ( int  initialSize = 0)
inline

DynamicPtrArray constructor

Parameters
Theinitial number of elements to be allocated for the array
~DynamicPtrArray ( void  )
inline

DynamicPtrArray 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

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
Apointer 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
Indexof 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
Apointer 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
DynamicPtrArray<T>& operator= ( const DynamicPtrArray< T > &  right)
inline

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

T& operator[] ( int  index)
inline

Overload of array operator to get element at desired index

const T& operator[] ( int  index) const
inline

Overload of array operator to get element at desired index - const safe version

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
Apointer to the object to add
bool RemoveAndDeallocate ( T &  obj)
inline

Remove the specified object from the array and then call delete on it

Parameters
objThe pointer to the object to remove
bool RemoveAndDeallocateObjectAtIndex ( unsigned int  index)
inline

Deletes the object at the specified index and frees it

Parameters
Indexof the object to delete
Returns
true if object was found and deleted else false
void Size ( unsigned int  newSize)
inlineprotected

Grows the array size to the new size given. Reallocates the array as needed. Will NOT ever shrink the array size.

Parameters
newSizeThe new number of elements in the array
unsigned int Size ( ) const
inline

Returns the current size of this dynamic array

Returns
The current size of the array (number of elements)
void Swap ( unsigned int  a,
unsigned int  b 
)
inline

Swap the objects at index a and b

Parameters
aIndex of first object
bIndex of second object

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: