Om  1.0.0
A universal framework for multimedia simulation
Classes | Public Member Functions | List of all members
om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType > Class Template Reference

A class that manages a pool of objects that are stored at persistent locations in memory. More...

#include <omObjectPool.h>

Classes

class  Iterator
 A class that iterates over the valid objects in an object pool. More...
 

Public Member Functions

 ObjectPool ()
 Create a new empty object pool without any memory allocated. More...
 
 ObjectPool (const ObjectPool &other)
 Create a new empty object pool that copies the state of another pool. More...
 
 ~ObjectPool ()
 Destroy an object pool, releasing any allocated memory and destructing all objects. More...
 
ObjectPooloperator= (const ObjectPool &other)
 Assign the state of another ObjectPool to this one, copying its elements. More...
 
SizeType getSize () const
 Return the current number of valid objects there are in the pool. More...
 
SizeType getCapacity () const
 Return the current number of objects that the pool can store without allocating more memory. More...
 
T & operator[] (SizeType objectIndex)
 Return a reference to the array element at the specified index. More...
 
const T & operator[] (SizeType objectIndex) const
 Return a const reference to the array element at the specified index. More...
 
Bool isUsed (SizeType objectIndex) const
 Return whether or not the object with the given index is currently constructed. More...
 
Bool isUnused (SizeType objectIndex) const
 Return whether or not the object with the given index is currently not constructed. More...
 
SizeType add (const T &prototype)
 Copy an object and add the copy to the object pool, returning the object's index in the pool. More...
 
SizeType addNew ()
 Construct an object in-place using the given parameters, returning the object's index in the pool. More...
 
template<typename P1 >
SizeType addNew (const P1 &p1)
 Construct an object in-place using the given parameters, returning the object's index in the pool. More...
 
template<typename P1 , typename P2 >
SizeType addNew (const P1 &p1, const P2 &p2)
 Construct an object in-place using the given parameters, returning the object's index in the pool. More...
 
template<typename P1 , typename P2 , typename P3 >
SizeType addNew (const P1 &p1, const P2 &p2, const P3 &p3)
 Construct an object in-place using the given parameters, returning the object's index in the pool. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 >
SizeType addNew (const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4)
 Construct an object in-place using the given parameters, returning the object's index in the pool. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 >
SizeType addNew (const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5)
 Construct an object in-place using the given parameters, returning the object's index in the pool. More...
 
void remove (SizeType objectIndex)
 Remove and destroy the object with the specified index in this pool. More...
 
void clear ()
 Remove all objects from the pool. More...
 
Iterator getIterator ()
 Return an object that iterates over the valid objects in this object pool. More...
 

Detailed Description

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
class om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >

A class that manages a pool of objects that are stored at persistent locations in memory.

The object pool allocates blocks of objects of a fixed power-of-two size contiguously in memory for better cache performance than if each object were allocated separately. A single contiguous array of objects cannot be used because it would cause objects to be reallocated if the array grows in size.

Constructor & Destructor Documentation

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::ObjectPool ( )
inline

Create a new empty object pool without any memory allocated.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::ObjectPool ( const ObjectPool< T, blockSizeLog2, SizeType, AllocatorType > &  other)
inline

Create a new empty object pool that copies the state of another pool.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::~ObjectPool ( )
inline

Destroy an object pool, releasing any allocated memory and destructing all objects.

Member Function Documentation

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
ObjectPool& om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::operator= ( const ObjectPool< T, blockSizeLog2, SizeType, AllocatorType > &  other)
inline

Assign the state of another ObjectPool to this one, copying its elements.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
SizeType om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::getSize ( ) const
inline

Return the current number of valid objects there are in the pool.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
SizeType om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::getCapacity ( ) const
inline

Return the current number of objects that the pool can store without allocating more memory.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
T& om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::operator[] ( SizeType  objectIndex)
inline

Return a reference to the array element at the specified index.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
const T& om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::operator[] ( SizeType  objectIndex) const
inline

Return a const reference to the array element at the specified index.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
Bool om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::isUsed ( SizeType  objectIndex) const
inline

Return whether or not the object with the given index is currently constructed.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
Bool om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::isUnused ( SizeType  objectIndex) const
inline

Return whether or not the object with the given index is currently not constructed.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
SizeType om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::add ( const T &  prototype)
inline

Copy an object and add the copy to the object pool, returning the object's index in the pool.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
SizeType om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::addNew ( )
inline

Construct an object in-place using the given parameters, returning the object's index in the pool.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
template<typename P1 >
SizeType om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::addNew ( const P1 &  p1)
inline

Construct an object in-place using the given parameters, returning the object's index in the pool.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
template<typename P1 , typename P2 >
SizeType om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::addNew ( const P1 &  p1,
const P2 &  p2 
)
inline

Construct an object in-place using the given parameters, returning the object's index in the pool.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
template<typename P1 , typename P2 , typename P3 >
SizeType om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::addNew ( const P1 &  p1,
const P2 &  p2,
const P3 &  p3 
)
inline

Construct an object in-place using the given parameters, returning the object's index in the pool.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
template<typename P1 , typename P2 , typename P3 , typename P4 >
SizeType om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::addNew ( const P1 &  p1,
const P2 &  p2,
const P3 &  p3,
const P4 &  p4 
)
inline

Construct an object in-place using the given parameters, returning the object's index in the pool.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 >
SizeType om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::addNew ( const P1 &  p1,
const P2 &  p2,
const P3 &  p3,
const P4 &  p4,
const P5 &  p5 
)
inline

Construct an object in-place using the given parameters, returning the object's index in the pool.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
void om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::remove ( SizeType  objectIndex)
inline

Remove and destroy the object with the specified index in this pool.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
void om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::clear ( )
inline

Remove all objects from the pool.

template<typename T, Size blockSizeLog2 = Size(3), typename SizeType = Size, typename AllocatorType = Allocator>
Iterator om::util::ObjectPool< T, blockSizeLog2, SizeType, AllocatorType >::getIterator ( )
inline

Return an object that iterates over the valid objects in this object pool.


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