SctData::ObjectPool< T > Class Template Reference

This class is an object pool. More...

#include <ObjectPool.h>


Public Member Functions

shared_ptr< T > get ()
 Gets an object from the pool.
void clear ()
 Releases all unused objects.
unsigned int poolSize () const
 Returns the number of elements in the Pool Not thread safe - should be used as an indication only!
void resize (unsigned int n)
 Ensures there are at least n objects in the pool.

Private Member Functions

shared_ptr< T > wrap (T *ptr)
 Wraps a ptr with an appropriate shared_ptr.
T * create ()
 Creates a T.

Private Attributes

list< T * > pool
 The pool of unused objects.
mutex poolMutex
 Used to lock access to the pool.

Friends

class ObjectPoolDeleter< T >
 The custom deleter class.


Detailed Description

template<typename T>
class SctData::ObjectPool< T >

This class is an object pool.

It requires that its type, T is default constructible and has a reset() method. It will maintain a list of created but unused objects then return shared_ptr to them when asked. If there are no objects, then it will create one. All the nothrow guarentees are based on the default constructor and reset methods not throwing.

The ObjectPool must outlive all the objects that it is used to create. It is probably best if it is statically created!

This class is thread-safe.

Note:
That it isn't possible to reliably find out the total assigned and un-assigned pool size - is this a problem?
Author:
Matthew Palmer

Definition at line 32 of file ObjectPool.h.


Member Function Documentation

template<typename T>
void SctData::ObjectPool< T >::clear  ) 
 

Releases all unused objects.

Note that objects currently in use will still be returned to the pool

Note:
nothrow

template<typename T>
T* SctData::ObjectPool< T >::create  )  [private]
 

Creates a T.

template<typename T>
shared_ptr<T> SctData::ObjectPool< T >::get  ) 
 

Gets an object from the pool.

Will call reset on the object first

Note:
nothrow

Referenced by SctData::ErfcFitObject::create().

template<typename T>
unsigned int SctData::ObjectPool< T >::poolSize  )  const
 

Returns the number of elements in the Pool Not thread safe - should be used as an indication only!

template<typename T>
void SctData::ObjectPool< T >::resize unsigned int  n  ) 
 

Ensures there are at least n objects in the pool.

Note:
nothrow

template<typename T>
shared_ptr<T> SctData::ObjectPool< T >::wrap T *  ptr  )  [private]
 

Wraps a ptr with an appropriate shared_ptr.

Note:
nothrow


Friends And Related Function Documentation

template<typename T>
friend class ObjectPoolDeleter< T > [friend]
 

The custom deleter class.

Definition at line 73 of file ObjectPool.h.


Field Documentation

template<typename T>
list<T*> SctData::ObjectPool< T >::pool [private]
 

The pool of unused objects.

Definition at line 74 of file ObjectPool.h.

template<typename T>
mutex SctData::ObjectPool< T >::poolMutex [private]
 

Used to lock access to the pool.

Definition at line 75 of file ObjectPool.h.


The documentation for this class was generated from the following file:
Generated on Mon Feb 6 14:07:32 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6