InstancePool< T > Class Template Reference

#include <InstancePool.h>


Detailed Description

template<typename T>
class InstancePool< T >

A pool of resuable instances.

Definition at line 45 of file InstancePool.h.


Public Member Functions

void addFreeInstance (T *instance)
 Adds a free, reusable instance.
void addFreeInstances (const std::vector< T * > instances)
 Adds some free, reusable instances.
T * getFreeInstance ()
 Returns a free instance or 0 if no such exists.
 InstancePool (bool deleteOnQuit)
 Constructor.
 ~InstancePool ()
 Destructor.

Private Attributes

bool myDeleteOnQuit
 Information whether the stored instances shall be deleted.
std::vector< T * > myFreeInstances
 List of reusable instances.

Constructor & Destructor Documentation

template<typename T>
InstancePool< T >::InstancePool ( bool  deleteOnQuit  )  [inline]

Constructor.

Parameters:
[in] deleteOnQuit Information whether stored instances shall be deleted when this container is deleted

Definition at line 51 of file InstancePool.h.

00051 : myDeleteOnQuit(deleteOnQuit) { }

template<typename T>
InstancePool< T >::~InstancePool (  )  [inline]

Destructor.

Definition at line 55 of file InstancePool.h.

00055                     {
00056         typedef typename std::vector<T*>::iterator It;
00057         if (myDeleteOnQuit) {
00058             for (It i=myFreeInstances.begin(); i!=myFreeInstances.end(); i++) {
00059                 delete *i;
00060             }
00061         }
00062     }


Member Function Documentation

template<typename T>
void InstancePool< T >::addFreeInstance ( T *  instance  )  [inline]

Adds a free, reusable instance.

Parameters:
[in] instance An instance to add

Definition at line 87 of file InstancePool.h.

Referenced by TraCIDijkstraRouter< E >::clearTemporaryStorages().

00087                                       {
00088         myFreeInstances.push_back(instance);
00089     }

template<typename T>
void InstancePool< T >::addFreeInstances ( const std::vector< T * >  instances  )  [inline]

Adds some free, reusable instances.

Parameters:
[in] instances A vector of instances to add

Definition at line 96 of file InstancePool.h.

00096                                                          {
00097         std::copy(instances.begin(), instances.end(),
00098                   std::back_inserter(myFreeInstances));
00099     }

template<typename T>
T* InstancePool< T >::getFreeInstance (  )  [inline]

Returns a free instance or 0 if no such exists.

If any free instance is stored, it is returned and removed from the storage. If no one is stored, 0 is returned.

Returns:
A free instance or 0 if no such exists

Definition at line 72 of file InstancePool.h.

Referenced by TraCIDijkstraRouter< E >::compute().

00072                          {
00073         if (myFreeInstances.size()==0) {
00074             return 0;
00075         } else {
00076             T *instance = myFreeInstances.back();
00077             myFreeInstances.pop_back();
00078             return instance;
00079         }
00080     }


Field Documentation

template<typename T>
bool InstancePool< T >::myDeleteOnQuit [private]

Information whether the stored instances shall be deleted.

Definition at line 107 of file InstancePool.h.

Referenced by InstancePool< std::vector< bool > >::~InstancePool().

template<typename T>
std::vector<T*> InstancePool< T >::myFreeInstances [private]


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

Generated on Wed May 5 00:06:46 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6