casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::ObjectStack< T > Class Template Reference

A stack of re-usable objects. More...

#include <ObjectStack.h>

Public Member Functions

 ~ObjectStack ()
 Destructor. More...
 
T * get ()
 Get a pointer to an object in the stack. More...
 
void put (T *obj)
 Return an object to the stack for re-use. More...
 
void clear ()
 Decimate the stack by getting rid of all unused elements in it. More...
 
Bool empty ()
 Test if stack empty. More...
 
uInt nelements () const
 return the stack extend (for debugging use and checking mainly) More...
 

Static Public Member Functions

static ObjectStack< T > & stack ()
 Create a singleton stack. More...
 

Private Member Functions

 ObjectStack ()
 All ctor and assignment constructors and assignment (not implemented) More...
 
 ObjectStack (const ObjectStack< T > &other)
 
ObjectStack< T > & operator= (const ObjectStack< T > &other)
 

Private Attributes

std::vector< T * > stack_p
 The Stack. More...
 
std::mutex mutex_p
 

Detailed Description

template<class T>
class casacore::ObjectStack< T >

A stack of re-usable objects.

Intended use:

Public interface

Review Status

Reviewed By:
Ger van Diepen
Date Reviewed:
2001/07/03
Test programs:
tObjectStack

Prerequisite

Synopsis

An ObjectStack contains a set of pre-allocated Objects of the type T. The stack is a very simple stack, without the linking/unlinking of a normal Stack implementation. This lightweight implementation was especially designed for use with the AutoDiff classes, but can be used independently. The stack works best with small object sizes, or letter/envelope classes.

The class is fully thread-safe, thus the same object can be used safely in multiple threads.

Example

{
// Get an element (and create stack!)
SparseDiff<Double> elem;
// Use it
elem.value() = 27;
// Release it (automatic by dtor on elem)
}

Motivation

To improve the speed for the auto differentiating classes.

Template Type Argument Requirements (T)

Definition at line 94 of file ObjectStack.h.

Constructor & Destructor Documentation

template<class T>
casacore::ObjectStack< T >::~ObjectStack ( )

Destructor.

template<class T>
casacore::ObjectStack< T >::ObjectStack ( )
inlineprivate

All ctor and assignment constructors and assignment (not implemented)

Definition at line 129 of file ObjectStack.h.

template<class T>
casacore::ObjectStack< T >::ObjectStack ( const ObjectStack< T > &  other)
private

Member Function Documentation

template<class T>
void casacore::ObjectStack< T >::clear ( )

Decimate the stack by getting rid of all unused elements in it.

template<class T>
Bool casacore::ObjectStack< T >::empty ( )
inline

Test if stack empty.

Definition at line 115 of file ObjectStack.h.

References casacore::ObjectStack< T >::stack_p.

template<class T>
T* casacore::ObjectStack< T >::get ( )

Get a pointer to an object in the stack.

The stack will be extended if no objects left.

template<class T>
uInt casacore::ObjectStack< T >::nelements ( ) const
inline

return the stack extend (for debugging use and checking mainly)

Definition at line 118 of file ObjectStack.h.

template<class T>
ObjectStack<T>& casacore::ObjectStack< T >::operator= ( const ObjectStack< T > &  other)
private
template<class T>
void casacore::ObjectStack< T >::put ( T *  obj)
inline

Return an object to the stack for re-use.

Definition at line 109 of file ObjectStack.h.

References casacore::ObjectStack< T >::stack_p.

template<class T>
static ObjectStack<T>& casacore::ObjectStack< T >::stack ( )
static

Create a singleton stack.

Member Data Documentation

template<class T>
std::mutex casacore::ObjectStack< T >::mutex_p
private

Definition at line 124 of file ObjectStack.h.

template<class T>
std::vector<T*> casacore::ObjectStack< T >::stack_p
private

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