hpp::pinocchio::Pool< T > Class Template Reference

Pool of objects. More...

#include <hpp/pinocchio/pool.hh>

Public Member Functions

T * acquire ()
 Get an object from the pool. More...
 
void release (T *t)
 Release a previously acquired object. More...
 
bool available () const
 Returns true is at least one object is not locked. More...
 
std::size_t size () const
 
void clear ()
 Deletes all internal objects. More...
 
void push_back (T *t)
 Adds an object to the pool The pool takes ownership of the object. More...
 
template<class InputIterator >
void push_back (InputIterator first, InputIterator last)
 Add objects to the pool The pool takes ownership of the object. More...
 
 ~Pool ()
 Destructor Calls Pool::clear() More...
 
 Pool ()
 Constructor. More...
 

Detailed Description

template<typename T>
class hpp::pinocchio::Pool< T >

Pool of objects.

Usage:

Pool<Foo> pool;
std::vector<Foo*> temporary_foos;
// Fill temporary_foos new objects.
// The ownership is passed to the pool.
pool.push_back (foo.begin(), foo.end());
Foo* foo = pool.acquire();
// Access to foo is thread safe.
pool.release(foo);

Constructor & Destructor Documentation

template<typename T>
hpp::pinocchio::Pool< T >::~Pool ( )
inline

Destructor Calls Pool::clear()

template<typename T>
hpp::pinocchio::Pool< T >::Pool ( )
inline

Constructor.

Member Function Documentation

template<typename T>
T* hpp::pinocchio::Pool< T >::acquire ( )
inline

Get an object from the pool.

If the pool is empty, wait until one element becomes available.

template<typename T>
bool hpp::pinocchio::Pool< T >::available ( ) const
inline

Returns true is at least one object is not locked.

template<typename T>
void hpp::pinocchio::Pool< T >::clear ( )
inline

Deletes all internal objects.

template<typename T>
void hpp::pinocchio::Pool< T >::push_back ( T *  t)
inline

Adds an object to the pool The pool takes ownership of the object.

template<typename T>
template<class InputIterator >
void hpp::pinocchio::Pool< T >::push_back ( InputIterator  first,
InputIterator  last 
)
inline

Add objects to the pool The pool takes ownership of the object.

template<typename T>
void hpp::pinocchio::Pool< T >::release ( T *  t)
inline

Release a previously acquired object.

Warning
There is no check that the object was actually one returned by Pool::acquire
template<typename T>
std::size_t hpp::pinocchio::Pool< T >::size ( ) const
inline