Particle Universe  1.2
ParticleUniverse::Pool< T > Class Template Reference

#include <ParticleUniversePool.h>

Public Types

typedef list< T * > PoolList
 
typedef PoolList::iterator PoolIterator
 

Public Member Functions

 Pool (bool managed=false)
 
virtual ~Pool (void)
 
bool isEmpty (void)
 
size_t getSize (void)
 
void resetIterator (void)
 
T * getFirst (void)
 
T * getNext (void)
 
bool end (void)
 
void clear (void)
 
void addElement (T *element)
 
T * releaseElement (void)
 
void releaseAllElements (void)
 
void lockLatestElement (void)
 
void lockAllElements (void)
 
PoolListgetActiveElementsList (void)
 

Public Attributes

PoolIterator mPoolIterator
 

Protected Attributes

bool mManaged
 
PoolList mReleased
 
PoolList mLocked
 

Detailed Description

template<typename T>
class ParticleUniverse::Pool< T >

Simple pool, use to store and retrieve precreated objects.

Remarks
This templated pool stores objects in a list and offers a few functions to retrieve objects and traverse through the pool.

Member Typedef Documentation

template<typename T>
typedef PoolList::iterator ParticleUniverse::Pool< T >::PoolIterator
template<typename T>
typedef list<T*> ParticleUniverse::Pool< T >::PoolList

Constructor & Destructor Documentation

template<typename T>
ParticleUniverse::Pool< T >::Pool ( bool  managed = false)
inline
template<typename T>
virtual ParticleUniverse::Pool< T >::~Pool ( void  )
inlinevirtual

Member Function Documentation

template<typename T>
void ParticleUniverse::Pool< T >::addElement ( T *  element)
inline
template<typename T>
void ParticleUniverse::Pool< T >::clear ( void  )
inline

Clear the pool.

Remarks
The elements in the pool are all removed but not deleted. Clearing a pool is only interesting if the pool doesn´t manage the elements itself (creation and destruction of elements is done outside the pool).
template<typename T>
bool ParticleUniverse::Pool< T >::end ( void  )
inline

Determines whether the end of the pool has been reached.

Remarks
This function is often used in a while-expression to traverses through the 'released' elements of the pool.
template<typename T>
PoolList& ParticleUniverse::Pool< T >::getActiveElementsList ( void  )
inline

Returns the complete list with active elements.

template<typename T>
T* ParticleUniverse::Pool< T >::getFirst ( void  )
inline

Return the first 'released' element in the pool.

Remarks
Together with the function getNext(), this function is a convenient function that is used to iterate through the pool.
template<typename T>
T* ParticleUniverse::Pool< T >::getNext ( void  )
inline

Return the next 'released' element in the pool.

Remarks
Together with the functions resetIterator() and end(), this function is a convenient function that is used to iterate through the pool.
template<typename T>
size_t ParticleUniverse::Pool< T >::getSize ( void  )
inline

Returns the number of all released elements.

template<typename T>
bool ParticleUniverse::Pool< T >::isEmpty ( void  )
inline

Returns true if the number of released elements is 0.

template<typename T>
void ParticleUniverse::Pool< T >::lockAllElements ( void  )
inline

Lock all elements in the pool.

Remarks
All released objects are locked.
template<typename T>
void ParticleUniverse::Pool< T >::lockLatestElement ( void  )
inline

Lock the element to which the internal iterator points.

Remarks
Relased elements that are not used anymore should be locked again. This means that they are skipped in the next iteration. This is a major performance saver if a large number of elements are involved. Performance is also the reason that there is no lockElement() function with an element as argument, since this would include a search for each element that will be locked. The alternative is the lockLatestElement() function. This function can be used while iterating the pool. In the iteration-loop every ´released´ element is validated and if a certain condition exists, the element can be locked by means of lockLatestElement().
template<typename T>
void ParticleUniverse::Pool< T >::releaseAllElements ( void  )
inline

Release all elements in the pool.

Remarks
All precreated objects in the pool are exposed to the outside world.
template<typename T>
T* ParticleUniverse::Pool< T >::releaseElement ( void  )
inline

Retrieve an object from the pool.

Remarks
This function does not only retrieve an object, but the object is also marked as ´released´. This means that the object is exposed to the outside world. If objects in pool are traversed, only the released objects are taken into account.
template<typename T>
void ParticleUniverse::Pool< T >::resetIterator ( void  )
inline

Reset the iterator, so that traversing through the pool starts from the beginning.

Remarks
Objects in the pool are ´locked´ (unused) by default. If an object is released (´unlocked´) it is exposed to the outside world. Traversing through the pool implies traversing through the 'released' objects.

Member Data Documentation

template<typename T>
PoolList ParticleUniverse::Pool< T >::mLocked
protected
template<typename T>
bool ParticleUniverse::Pool< T >::mManaged
protected
template<typename T>
PoolIterator ParticleUniverse::Pool< T >::mPoolIterator
template<typename T>
PoolList ParticleUniverse::Pool< T >::mReleased
protected

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