casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
casa::ObjectStack< T > Class Template Reference

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

#include <ObjectStack.h>

List of all members.

Public Member Functions

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

Static Public Member Functions

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

Private Member Functions

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

Private Attributes

vector< T * > stack_p
 The Stack.
Mutex mutex_p

Detailed Description

template<class T>
class casa::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 93 of file ObjectStack.h.


Constructor & Destructor Documentation

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

Destructor.

template<class T>
casa::ObjectStack< T >::ObjectStack ( ) [inline, private]

All ctor and assignment constructors and assignment (not implemented)

Definition at line 128 of file ObjectStack.h.

template<class T>
casa::ObjectStack< T >::ObjectStack ( const ObjectStack< T > &  other) [private]

Member Function Documentation

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

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

template<class T>
Bool casa::ObjectStack< T >::empty ( ) [inline]

Test if stack empty.

Definition at line 114 of file ObjectStack.h.

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

template<class T>
T* casa::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 casa::ObjectStack< T >::nelements ( ) const [inline]

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

Definition at line 117 of file ObjectStack.h.

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

Return an object to the stack for re-use.

Definition at line 108 of file ObjectStack.h.

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

template<class T>
static ObjectStack<T>& casa::ObjectStack< T >::stack ( ) [static]

Create a singleton stack.


Member Data Documentation

template<class T>
Mutex casa::ObjectStack< T >::mutex_p [private]

Definition at line 123 of file ObjectStack.h.

template<class T>
vector<T*> casa::ObjectStack< T >::stack_p [private]

The Stack.

Definition at line 117 of file ObjectStack.h.

Referenced by casa::ObjectStack< T >::empty(), and casa::ObjectStack< T >::put().


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