1 #ifndef CORELIB___OBJ_POOL__HPP
2 #define CORELIB___OBJ_POOL__HPP
63 template <
class TObjType,
89 size_t max_storage_size =
size_t(-1))
103 TObjType* obj =
NULL;
196 template <
class TObjPool>
305 template <
class TObjType>
311 return new TObjType();
322 template <
class TObjType,
class TParamType>
350 template <
class TObjType,
class TMethodClass>
354 typedef TObjType* (TMethodClass::*
TMethod)(
void);
Object factory for creation implemented by method of some class and simple deletion.
Object factory for simple creation and deletion of the object with one parameter passed to object's c...
Object factory for simple creation and deletion of the object.
Guard that can be used to automatically return object to the pool after leaving some scope.
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
deque< TObjType * > TObjectsList
size_t GetMaxStorageSize(void) const
Get maximum number of unused objects that can be stored in the pool.
CObjPoolGuard & operator=(const CObjPoolGuard &)
TObjType * Release(void)
Release protected object without returning it to the pool.
CObjPoolGuard(TObjPool &pool)
Create guard and automatically acquire object from the pool.
void Acquire(TObjType *object=NULL)
Return protected object (if any) to the pool and acquire new object for protection.
TMethodClass * m_MethodObj
Object which method will be called to create new object.
CObjFactory_NewMethod(TMethodClass *method_obj, TMethod method)
TMethod m_Method
Method to call to create new object.
void Return(TObjType *obj)
Return object to the pool for future use.
TObjFactory m_Factory
Object factory.
TObjType * CreateObject(void)
TObjType * Get(void)
Get object from the pool, create if necessary.
void Return(void)
Return protected object (if any) to the pool.
TObjType * CreateObject(void)
TObjType *(TMethodClass::* TMethod)(void)
CObjPool(size_t max_storage_size=size_t(-1))
Create object pool.
void DeleteObject(TObjType *obj)
TObjType * GetObject(void) const
Get pointer to protected object.
TObjPool::TObjectType TObjType
Type of object to protect.
TObjType * m_Object
Protected object.
TObjType & operator*(void) const
Automatic dereference to the protected object.
CObjPoolGuard(const CObjPoolGuard &)
CObjPool(const TObjFactory &factory, size_t max_storage_size=size_t(-1))
Create object pool.
CSpinLock m_ObjLock
Lock object to change the pool.
TObjType * operator->(void) const
Automatic dereference to the protected object.
~CObjPool(void)
Destroy object pool and all objects it owns.
size_t m_MaxStorage
Maximum number of unused objects that can be stored in the pool.
CObjFactory_NewParam(const TParamType ¶m)
void Clear(void)
Delete all objects returned to the pool so far and clean it.
TObjPool & m_Pool
Pool this guard is attached to.
void SetMaxStorageSize(size_t max_storage_size)
Set maximum number of unused objects that can be stored in the pool.
CObjPoolGuard(TObjPool &pool, TObjType *object)
Create guard to automatically return given object to the pool.
TObjType * CreateObject(void)
void DeleteObject(TObjType *obj)
void DeleteObject(TObjType *obj)
TParamType m_Param
Parameter value that will be passed to constructor of every new object.
TObjType TObjectType
Synonym to be able to use outside of the pool.
CObjPool(const CObjPool &)
TObjectsList m_FreeObjects
List of unused objects.
CObjPool & operator=(const CObjPool &)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
void Unlock(void)
Unlock the mutex.
void Lock(void)
Lock the mutex.
const TYPE & Get(const CNamedParameterList *param)
Multi-threading – mutexes; rw-locks; semaphore.