UCommon
Public Member Functions
ucommon::stackof< T > Class Template Reference

A templated typed class for thread-safe stack of object pointers. More...

#include <containers.h>

Inheritance diagram for ucommon::stackof< T >:
Inheritance graph
[legend]
Collaboration diagram for ucommon::stackof< T >:
Collaboration graph
[legend]

Public Member Functions

const T & at (unsigned offset=0)
 Examine past item in the stack. More...
 
T * operator() (unsigned offset=0)
 
const T & operator[] (unsigned offset)
 Examine past item in the stack. More...
 
const T * peek (timeout_t timeout=0)
 Examine last typed object posted to the stack. More...
 
T * pull (timeout_t timeout=0)
 Get and remove last typed object posted to the stack. More...
 
bool push (T *object, timeout_t timeout=0)
 Push a typed object into the stack by it's pointer. More...
 
bool remove (T *object)
 Remove a specific typed object pointer for the stack. More...
 
 stackof (mempager *memory, size_t size=0)
 Create templated stack of typed objects. More...
 
- Public Member Functions inherited from ucommon::Stack
size_t count (void)
 Get number of object points currently in the stack. More...
 
ObjectProtocolget (unsigned offset=0)
 Examine an existing object on the stack. More...
 
const ObjectProtocolpeek (timeout_t timeout=0)
 
ObjectProtocolpull (timeout_t timeout=0)
 Get and remove last object pushed on the stack. More...
 
bool push (ObjectProtocol *object, timeout_t timeout=0)
 Push an object into the stack by it's pointer. More...
 
bool remove (ObjectProtocol *object)
 Remove a specific object pointer for the queue. More...
 
 Stack (mempager *pager=((void *) 0), size_t number=0)
 Create a stack that uses a memory pager for internally managed member objects for a specified maximum number of object pointers. More...
 
virtual ~Stack ()
 Destroy queue. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ucommon::Stack
virtual ObjectProtocolinvalid (void) const
 
- Protected Member Functions inherited from ucommon::Conditional
void broadcast (void)
 Signal the conditional to release all waiting threads.
 
 Conditional ()
 Initialize and construct conditional.
 
void lock (void)
 Lock the conditional's supporting mutex.
 
void signal (void)
 Signal the conditional to release one waiting thread.
 
void unlock (void)
 Unlock the conditional's supporting mutex.
 
bool wait (timeout_t timeout)
 Conditional wait for signal on millisecond timeout. More...
 
bool wait (struct timespec *timeout)
 Conditional wait for signal on timespec timeout. More...
 
void wait (void)
 Wait (block) until signalled.
 
 ~Conditional ()
 Destroy conditional, release any blocked threads.
 
- Static Protected Member Functions inherited from ucommon::Conditional
static pthread_condattr_t * initializer (void)
 Support function for getting conditional attributes for realtime scheduling. More...
 
static void set (struct timespec *hires, timeout_t timeout)
 Convert a millisecond timeout into use for high resolution conditional timers. More...
 
- Protected Attributes inherited from ucommon::Stack
size_t limit
 

Detailed Description

template<class T>
class ucommon::stackof< T >

A templated typed class for thread-safe stack of object pointers.

This allows one to use the stack class in a typesafe manner for a specific object type derived from Object rather than generically for any derived object class.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 524 of file containers.h.

Constructor & Destructor Documentation

template<class T >
ucommon::stackof< T >::stackof ( mempager memory,
size_t  size = 0 
)
inline

Create templated stack of typed objects.

Parameters
memorypool for internal use of stack.
sizeof stack to construct. Uses 0 if no size limit.

Definition at line 532 of file containers.h.

Member Function Documentation

template<class T >
const T& ucommon::stackof< T >::at ( unsigned  offset = 0)
inline

Examine past item in the stack.

This is a typecast of the peek operation.

Parameters
offsetin stack.
Returns
item pointer if valid or NULL.

Definition at line 583 of file containers.h.

template<class T >
const T& ucommon::stackof< T >::operator[] ( unsigned  offset)
inline

Examine past item in the stack.

This is a typecast of the peek operation.

Parameters
offsetin stack.
Returns
item pointer if valid or NULL.

Definition at line 592 of file containers.h.

template<class T >
const T* ucommon::stackof< T >::peek ( timeout_t  timeout = 0)
inline

Examine last typed object posted to the stack.

This can wait for a specified timeout of the stack is empty.

Parameters
timeoutto wait if empty in milliseconds.
Returns
object in queue or NULL if empty and timed out.

Definition at line 571 of file containers.h.

template<class T >
T* ucommon::stackof< T >::pull ( timeout_t  timeout = 0)
inline

Get and remove last typed object posted to the stack.

This can wait for a specified timeout of the stack is empty. The object is still retained and must be released or deleted by the receiving function.

Parameters
timeoutto wait if empty in milliseconds.
Returns
object from queue or NULL if empty and timed out.

Definition at line 562 of file containers.h.

template<class T >
bool ucommon::stackof< T >::push ( T *  object,
timeout_t  timeout = 0 
)
inline

Push a typed object into the stack by it's pointer.

This can wait for a specified timeout if the queue is full, for example, for another thread to remove an object pointer. This retains the object.

Parameters
objectto push.
timeoutto wait if queue is full in milliseconds.
Returns
true if object pushed, false if queue full and timeout expired.

Definition at line 552 of file containers.h.

template<class T >
bool ucommon::stackof< T >::remove ( T *  object)
inline

Remove a specific typed object pointer for the stack.

This can remove a member from any location in the stack, whether beginning, end, or somewhere in the middle. This releases the object.

Parameters
objectto remove.
Returns
true if object was removed, false if not found.

Definition at line 541 of file containers.h.


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