Chemical Data Processing Library C++ API - Version 1.2.0
Classes | Public Types | Public Member Functions | List of all members
CDPL::Util::ObjectPool< T > Class Template Reference

A data structure that caches instances of type T up to a user specified amount. More...

#include <ObjectPool.hpp>

+ Inheritance diagram for CDPL::Util::ObjectPool< T >:

Classes

struct  DefaultConstructor
 
struct  DefaultDestructor
 

Public Types

typedef T ObjectType
 
typedef std::shared_ptr< ObjectTypeSharedObjectPointer
 
typedef std::function< ObjectType *()> ConstructorFunction
 
typedef std::function< void(ObjectType *)> DestructorFunction
 
typedef std::function< void(ObjectType &)> ObjectFunction
 

Public Member Functions

 ObjectPool (const ObjectPool &pool)
 
 ObjectPool (std::size_t max_size=0)
 
template<typename C , typename D >
 ObjectPool (const C &ctor_func, const D &dtor_func, std::size_t max_size=0)
 
 ~ObjectPool ()
 
SharedObjectPointer get ()
 
std::size_t getSize () const
 
std::size_t getMaxSize () const
 
void setMaxSize (std::size_t max_size)
 
void freeMemory ()
 
void setInitFunction (const ObjectFunction &func)
 
void setCleanupFunction (const ObjectFunction &func)
 
ObjectPooloperator= (const ObjectPool &pool)
 

Detailed Description

template<typename T>
class CDPL::Util::ObjectPool< T >

A data structure that caches instances of type T up to a user specified amount.

Instances of type T that are allocated via this pool (see get()) are preferentially taken from an internally maintained list of previously allocated but now unused objects. If there are no free objects a new object instance will be created on the fly. Allocated objects are returned as smart pointers which keep track of all current references to the object. If the reference count drops to zero at some point, the object is automatically returned to the pool it was allocated from.

Warning: Due to this automatic return of unused objects it is necessary that all objects have returned to their source pool before the pool instance gets destroyed!!!!

Member Typedef Documentation

◆ ObjectType

template<typename T >
typedef T CDPL::Util::ObjectPool< T >::ObjectType

◆ SharedObjectPointer

template<typename T >
typedef std::shared_ptr<ObjectType> CDPL::Util::ObjectPool< T >::SharedObjectPointer

◆ ConstructorFunction

template<typename T >
typedef std::function<ObjectType*()> CDPL::Util::ObjectPool< T >::ConstructorFunction

◆ DestructorFunction

template<typename T >
typedef std::function<void(ObjectType*)> CDPL::Util::ObjectPool< T >::DestructorFunction

◆ ObjectFunction

template<typename T >
typedef std::function<void(ObjectType&)> CDPL::Util::ObjectPool< T >::ObjectFunction

Constructor & Destructor Documentation

◆ ObjectPool() [1/3]

template<typename T >
CDPL::Util::ObjectPool< T >::ObjectPool ( const ObjectPool< T > &  pool)
inline

◆ ObjectPool() [2/3]

template<typename T >
CDPL::Util::ObjectPool< T >::ObjectPool ( std::size_t  max_size = 0)
inline

◆ ObjectPool() [3/3]

template<typename T >
template<typename C , typename D >
CDPL::Util::ObjectPool< T >::ObjectPool ( const C &  ctor_func,
const D &  dtor_func,
std::size_t  max_size = 0 
)
inline

◆ ~ObjectPool()

template<typename T >
CDPL::Util::ObjectPool< T >::~ObjectPool ( )
inline

Member Function Documentation

◆ get()

template<typename T >
SharedObjectPointer CDPL::Util::ObjectPool< T >::get ( )
inline

◆ getSize()

template<typename T >
std::size_t CDPL::Util::ObjectPool< T >::getSize ( ) const
inline

◆ getMaxSize()

template<typename T >
std::size_t CDPL::Util::ObjectPool< T >::getMaxSize ( ) const
inline

◆ setMaxSize()

template<typename T >
void CDPL::Util::ObjectPool< T >::setMaxSize ( std::size_t  max_size)
inline

◆ freeMemory()

template<typename T >
void CDPL::Util::ObjectPool< T >::freeMemory ( )
inline

◆ setInitFunction()

template<typename T >
void CDPL::Util::ObjectPool< T >::setInitFunction ( const ObjectFunction func)
inline

◆ setCleanupFunction()

template<typename T >
void CDPL::Util::ObjectPool< T >::setCleanupFunction ( const ObjectFunction func)
inline

◆ operator=()

template<typename T >
ObjectPool& CDPL::Util::ObjectPool< T >::operator= ( const ObjectPool< T > &  pool)
inline

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