ionflux.org | Impressum

Ionflux::Tools::ObjectPool Class Reference
[Memory management]

Object pool. More...

#include <ObjectPool.hpp>

Collaboration diagram for Ionflux::Tools::ObjectPool:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ObjectPool ()
 Constructor.
virtual ~ObjectPool ()
 Destructor.
virtual bool findObject (ManagedObject *searchObject)
 Find object.
virtual bool addObject (ManagedObject *newObject)
 Add object.
virtual void removeObject (ManagedObject *rmObject)
 Remove object.
virtual void cleanup ()
 Cleanup pool.
virtual void clear ()
 Clear pool.
virtual Ionflux::Tools::ReportergetLog ()
 Get Console output/logging facility.
virtual void setWatchMode (bool newWatchMode)
 Set watch mode flag.
virtual bool getWatchMode () const
 Get watch mode flag.

Protected Member Functions

virtual void unrefAll ()
 Unreference all objects.
virtual void removeUnused (unsigned int threshold=0)
 Remove unused objects.

Protected Attributes

Ionflux::Tools::Reporter log
 Console output/logging.
std::map< ManagedObject *,
bool > 
objects
 Objects managed by the pool.
bool watchMode
 Watch mode flag.

Detailed Description

Object pool.

A pool of reference counted objects. The purpose of the pool is to delete objects at the end of the lifetime, or on a forced cleanup of the pool, if they are not needed anymore. An object managed by the pool will be deleted if its reference count is zero upon cleanup of the pool.

Note:
To avoid confusion, pools are not intended for explicitly managed objects, that is, objects which have their parent memory management flag set to true. Such objects will never be added to a pool and a warning message may be issued if an attempt is made to add an explicitly managed object to a pool.


Constructor & Destructor Documentation

Ionflux::Tools::ObjectPool::ObjectPool  ) 
 

Constructor.

Construct new ObjectPool object.

Ionflux::Tools::ObjectPool::~ObjectPool  )  [virtual]
 

Destructor.

Destruct ObjectPool object.


Member Function Documentation

bool Ionflux::Tools::ObjectPool::addObject ManagedObject newObject  )  [virtual]
 

Add object.

Add an object to the pool.

Note:
This function will make sure that the object to be added to the pool is not yet managed explicitly by another object. In this case, the object will not be added and the function will return false. The pool will reference the object, but it will not alter the management flag for the object. Thus, objects may be added to several pools.
Parameters:
newObject Object to be added to the pool.
Returns:
true if this object will be managed by the pool after the call, false otherwise.

void Ionflux::Tools::ObjectPool::cleanup  )  [virtual]
 

Cleanup pool.

Clean up the pool. All objects that are not in use by any object (besides the pool itself) are removed from the pool and deleted.

void Ionflux::Tools::ObjectPool::clear  )  [virtual]
 

Clear pool.

Clear the pool. All objects in the pool will be unreferenced and removed from the pool. Objects will also be deleted if their reference count is zero.

bool Ionflux::Tools::ObjectPool::findObject ManagedObject searchObject  )  [virtual]
 

Find object.

Check whether an object is in the pool.

Parameters:
searchObject Managed object.
Returns:
true if the specified object is in the pool, false otherwise.

Ionflux::Tools::Reporter & Ionflux::Tools::ObjectPool::getLog  )  [virtual]
 

Get Console output/logging facility.

The console output/logging facility used by this object.

Returns:
Console output/logging facility.

bool Ionflux::Tools::ObjectPool::getWatchMode  )  const [virtual]
 

Get watch mode flag.

Returns:
Current value of watch mode flag.

void Ionflux::Tools::ObjectPool::removeObject ManagedObject rmObject  )  [virtual]
 

Remove object.

Remove an object from the pool.

Parameters:
rmObject Object to be removed from the pool.

void Ionflux::Tools::ObjectPool::removeUnused unsigned int  threshold = 0  )  [protected, virtual]
 

Remove unused objects.

Remove all objects for which the reference count has dropped to zero (or to specified value).

Parameters:
threshold Threshold.

void Ionflux::Tools::ObjectPool::setWatchMode bool  newWatchMode  )  [virtual]
 

Set watch mode flag.

Set new value of watch mode flag.

Parameters:
newWatchMode New value of watch mode flag.

void Ionflux::Tools::ObjectPool::unrefAll  )  [protected, virtual]
 

Unreference all objects.

Remove the reference held by the pool for all objects.


Member Data Documentation

Ionflux::Tools::Reporter Ionflux::Tools::ObjectPool::log [protected]
 

Console output/logging.

std::map<ManagedObject*, bool> Ionflux::Tools::ObjectPool::objects [protected]
 

Objects managed by the pool.

bool Ionflux::Tools::ObjectPool::watchMode [protected]
 

Watch mode flag.


The documentation for this class was generated from the following files:
Generated on Tue Mar 14 21:09:15 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6