Exponent::Collections::TPointerCollection< TypeName > Class Template Reference

Inheritance diagram for Exponent::Collections::TPointerCollection< TypeName >:

Exponent::Basics::CCountedObject Exponent::Basics::ICountedObject Exponent::Collections::TCountedPointerArray< TypeName > List of all members.

Detailed Description

template<class TypeName>
class Exponent::Collections::TPointerCollection< TypeName >

Template'd pointer array that will grow and shrink as necessary.

Stores an internal array of pointer objects. Deletion is handled by the object deleter
that you provide during construction. These templates allow you to handle deletion of
objects in any way you require in a type safe way
Because of the object management system, you are fully safe to do something like the following

 // Notice we add a new object directly, just like in java. The internal reference counting, depending on the pointer deleter
 // Will delete this directly
 array.addElement(new CString("Hello World"));

*However* the object array does not expect array elements (ie you cant make a matrix) so therefore

 array.addElement(new double[32]);

will not work without leaking memory like a bastard!
The insert index is the current index the newly added objects will be assigned. It will always be <= m_arraySize
To save time on loop, rather than doing

 for (long i = 0; i < array.getArraySize(); i++)

You can do something like

 for (long i = 0; i < array.getInsertIndex(); i++)

However, please mke sure that you check the validity of any pointer you get back, (as you should anyway!) as there
is always the possibility of object positions being null. A good example is shown below

 TPointerCollection<CBool> boolArray;
 boolArray.addElement(new CBool(true));
 boolArray.addElement(new CBool(false));
 boolArray.addElement(new CBool(false));

 // Now we step through and print the results
 for (long i = 0; i < boolArray.getInsertIndex(); i++)
 {
       // Get the pointer
       CBool *boolean = boolArray.elementAtIndex(i);

       // Check its valid
       if (boolean == NULL) continue;

       // Now you can process with the item
       // ...
 }

See also:
TPointerDeleter
Date:
23/01/2006
Author:
Paul Chana
Version:
1.0.0 Initial version
Note:
All contents of this source code are copyright 2005 Exp Digital Uk.
This source file is covered by the licence conditions of the Infinity API. You should have recieved a copy
with the source code. If you didnt, please refer to http://www.expdigital.co.uk All content is the Intellectual property of Exp Digital Uk.
Certain sections of this code may come from other sources. They are credited where applicable.
If you have comments, suggestions or bug reports please visit http://support.expdigital.co.uk
Id
TPointerCollection.hpp,v 1.11 2007/02/08 21:06:44 paul Exp

Definition at line 93 of file TPointerCollection.hpp.

Public Types

Public Member Functions

Static Public Attributes

Protected Member Functions

Protected Attributes


Member Typedef Documentation

template<class TypeName>
Exponent::Collections::TPointerCollection< TypeName >::qsortCompare

Comparison function pointer. This is an example of the implementation of a comparison function.
To enable this to work properly with the qsort algorithm embedded inside the sort function you need to be capable of passing in double deferenced pointers
This is a legal conversion from void *. A couple of words about the parameters:
obj1 The first object to compare
obj2 The second object
You should return -1 if obj1 < obj2, 0 if obj1==obj2, +1 if obj1 > obj2
To call this comparision using the default sorting of the pointer collection, do something like this:.

 array.sortArray((TPointerCollection<CClass>::qsortCompare)CClass::compareClasses);

Definition at line 128 of file TPointerCollection.hpp.


Constructor & Destructor Documentation

template<class TypeName>
Exponent::Collections::TPointerCollection< TypeName >::TPointerCollection ( TPointerDeleter< TypeName > *  pointerDeleter = &TPOINTER_COLLECTION_DEFAULT_DELETER  ) 

Construction

Parameters:
pointerDeleter The object that handles deletions

template<class TypeName>
virtual Exponent::Collections::TPointerCollection< TypeName >::~TPointerCollection (  )  [virtual]

Destruction


Member Function Documentation

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::addElement ( TypeName *  pointer  ) 

Add a pointer to the array

Parameters:
pointer The pointer to add

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::addElementAtIndex ( const long  index,
TypeName *  pointer 
)

Insert a pointer at a specific index

Parameters:
index The index to store at, if an object is there it is deleted
pointer The pointer to add

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::clearArray (  ) 

Clear the array

template<class TypeName>
const TypeName* Exponent::Collections::TPointerCollection< TypeName >::constElementAtIndex ( const long  index  )  const

Get the element at a specific index

Parameters:
index The index of the pointer
Return values:
TypeName* The object requested or NULL on error

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::deletePointerAtIndex ( const long  index  ) 

Delete a pointer at an index

Parameters:
index Index of the pointer to delete

template<class TypeName>
TypeName* Exponent::Collections::TPointerCollection< TypeName >::elementAtIndex ( const long  index  ) 

Get the element at a specific index

Parameters:
index The index of the pointer
Return values:
TypeName* The object requested or NULL on error

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::expand (  )  [protected]

Expand the array

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::freePointers (  )  [protected]

Free pointers -> deleteds (but not allways) all pointers

template<class TypeName>
long Exponent::Collections::TPointerCollection< TypeName >::getArraySize (  )  const

Get the size of the array

Return values:
long The size of the array

template<class TypeName>
long Exponent::Collections::TPointerCollection< TypeName >::getIndexOfPointer ( const TypeName *  pointer  ) 

Get the index of a pointer

Parameters:
pointer The pointer to find
Return values:
long The index of the pointer or TPOINTERCOLLECTION_FAILED_TO_FIND_POINTER on error

template<class TypeName>
long Exponent::Collections::TPointerCollection< TypeName >::getInsertIndex (  )  const

Get the insert index

Return values:
long The current end pointer of the array

template<class TypeName>
TypeName** Exponent::Collections::TPointerCollection< TypeName >::getMutableInternalBuffer (  )  [inline]

Get the internal buffer

Return values:
const TypeName ** The internal buffer

Definition at line 274 of file TPointerCollection.hpp.

template<class TypeName>
long Exponent::Collections::TPointerCollection< TypeName >::getNumberOfElementsUntilNextGrow (  ) 

Get number of elements until next grow

Return values:
long The number of elements that can be added before the array has to grow

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::initialise (  )  [protected]

Initialise the unit

template<class TypeName>
bool Exponent::Collections::TPointerCollection< TypeName >::isArrayEmpty (  )  const

Is the array empty?

Return values:
bool True if array size is zero

template<class TypeName>
bool Exponent::Collections::TPointerCollection< TypeName >::isPointerInArray ( const TypeName *  pointer  ) 

Is pointer in array

Parameters:
pointer The object to look for
Return values:
bool True if this object is stored in the array, false otherwise

template<class TypeName>
TypeName* Exponent::Collections::TPointerCollection< TypeName >::operator[] ( const long  index  ) 

Index operator

Return values:
TypeName* The object or null on error

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::registerPointerDeleter ( TPointerDeleter< TypeName > *  pointerDeleter = &TPOINTER_COLLECTION_DEFAULT_DELETER  )  [inline]

Set the pointer deleter

Parameters:
pointerDeleter The object that handles deletions

Definition at line 266 of file TPointerCollection.hpp.

template<class TypeName>
TypeName* Exponent::Collections::TPointerCollection< TypeName >::removeElementAtIndexWithoutDeletion ( const long  index  ) 

Remove the pointer at the index without deletion

Parameters:
index The index of the pointer to remove
Return values:
TypeName* The object removed from the array
Note:
This NEVER, EVER deletes the object, it simply nulls its position, you become responsible for deletion

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::reorder ( const bool  resize = true  ) 

Reorder the array to remove dead pointers, resize shrinks the array

Parameters:
resize If true will remove any remaining null pointers at the end of the array, if false array may be bigger than usage

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::setGrowSize ( const long  growSize = TPOINTERCOLLECTION_DEFAULT_GROW_SIZE  ) 

Set the grow size

Parameters:
growSize The amount that the array size should be increased by

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::sortArray ( qsortCompare  compareFunction  ) 

Sort the array

Parameters:
compareFunction The comparison function to use

template<class TypeName>
void Exponent::Collections::TPointerCollection< TypeName >::swapIndexes ( const long  index1,
const long  index2 
)

Swap two pointers

Parameters:
index1 The index of the first pointer
index2 The index of the second pointer


Member Data Documentation

template<class TypeName>
TypeName** Exponent::Collections::TPointerCollection< TypeName >::m_array [protected]

The internal array

Definition at line 305 of file TPointerCollection.hpp.

Referenced by Exponent::Collections::TPointerCollection< Exponent::GUI::Controls::CMenuItem >::getMutableInternalBuffer().

template<class TypeName>
long Exponent::Collections::TPointerCollection< TypeName >::m_arraySize [protected]

The size of the array

Definition at line 307 of file TPointerCollection.hpp.

template<class TypeName>
long Exponent::Collections::TPointerCollection< TypeName >::m_growSize [protected]

how many extra area do we require when we run out

Definition at line 308 of file TPointerCollection.hpp.

template<class TypeName>
long Exponent::Collections::TPointerCollection< TypeName >::m_insertIndex [protected]

The current end point of the array < m_arraySize

Definition at line 309 of file TPointerCollection.hpp.

template<class TypeName>
TPointerDeleter<TypeName>* Exponent::Collections::TPointerCollection< TypeName >::m_pointerDeletionHandler [protected]

Deletion handler

Definition at line 306 of file TPointerCollection.hpp.

Referenced by Exponent::Collections::TPointerCollection< Exponent::GUI::Controls::CMenuItem >::registerPointerDeleter().

template<class TypeName>
TObjectDeleter<TypeName> Exponent::Collections::TPointerCollection< TypeName >::TPOINTER_COLLECTION_DEFAULT_DELETER [static]

The default handler for pointer deletion

Definition at line 105 of file TPointerCollection.hpp.

template<class TypeName>
TObjectNuller<TypeName> Exponent::Collections::TPointerCollection< TypeName >::TPOINTER_COLLECTION_DEFAULT_NULLER [static]

The defulat handler for nulling pointers

Definition at line 106 of file TPointerCollection.hpp.

template<class TypeName>
const long Exponent::Collections::TPointerCollection< TypeName >::TPOINTERCOLLECTION_DEFAULT_GROW_SIZE = 32 [static]

Default amount to grow the array by

Definition at line 110 of file TPointerCollection.hpp.

template<class TypeName>
const long Exponent::Collections::TPointerCollection< TypeName >::TPOINTERCOLLECTION_FAILED_TO_FIND_POINTER = -1 [static]

We failed to find a pointer

Definition at line 111 of file TPointerCollection.hpp.


Infinity API - Exponent::Collections::TPointerCollection< TypeName > Class Template Reference generated on 7 Mar 2007