INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

gbxiceutilacfr::Buffer< Type > Class Template Reference

A thread-safe data pipe with buffer semantics. More...

#include <buffer.h>

List of all members.

Public Member Functions

 Buffer (int depth=-1, BufferType type=BufferTypeQueue)
void configure (int depth, BufferType type=BufferTypeCircular)
int depth () const
 Returns buffer depth.
BufferType type () const
 Returns buffer type.
bool isEmpty () const
 Returns FALSE if there's something in the buffer.
int size () const
 Returns the number of items in the buffer.
void purge ()
 Deletes all entries, makes the buffer empty.
void push (const Type &obj)
void pop ()
void get (Type &obj) const
void get (Type &obj, unsigned int n) const
void getAndPop (Type &obj)
int getWithTimeout (Type &obj, int timeoutMs=-1)
int getAndPopWithTimeout (Type &obj, int timeoutMs=-1)


Detailed Description

template<class Type>
class gbxiceutilacfr::Buffer< Type >

A thread-safe data pipe with buffer semantics.

For a type-safe buffer, template over the specific object Type you want to put in it. You can use this container for storing smart pointers (e.g. IceUtil smart pointers). In this case the container will only store the pointers and will not perform a deep copy.

Note:
This implementation uses IceUtil threading classes. See example in sec. 28.9.2 of the Ice manual.
See also:
Notify, Proxy

Constructor & Destructor Documentation

template<class Type >
gbxiceutilacfr::Buffer< Type >::Buffer ( int  depth = -1,
BufferType  type = BufferTypeQueue 
) [inline]

Buffer depth, i.e. the maximum number of objects this buffer can hold:

  • positive numbers to specify finite depth,
  • negative numbers for infinite depth, limited by memory size
  • zero is undefined

References gbxiceutilacfr::Buffer< Type >::purge().


Member Function Documentation

template<class Type >
void gbxiceutilacfr::Buffer< Type >::configure ( int  depth,
BufferType  type = BufferTypeCircular 
) [inline]

Typically is called before the buffer is used, or if, for some reason, the configuration information was not available at the time when the constructor was called. Careful: all data currently in the buffer is lost, because purge() is calledfirst. NOTE: can do smarter by trancating queue only as much as needed.

References gbxiceutilacfr::Buffer< Type >::purge().

template<class Type>
void gbxiceutilacfr::Buffer< Type >::get ( Type &  obj,
unsigned int  n 
) const [inline]

Non-popping and non-blocking random-access read. Returns n-th element from the buffer. Indexing starts at 0.

template<class Type>
void gbxiceutilacfr::Buffer< Type >::get ( Type &  obj  )  const [inline]

Non-popping and non-blocking read from the front of the buffer.

Calls to get() on an empty buffer raises an gbxutilacfr::Exception exception. You can catch these and call getWithTimeout() which will block until new data arrives.

template<class Type>
void gbxiceutilacfr::Buffer< Type >::getAndPop ( Type &  obj  )  [inline]

Same as get() but calls pop() afterwards.

template<class Type>
int gbxiceutilacfr::Buffer< Type >::getAndPopWithTimeout ( Type &  obj,
int  timeoutMs = -1 
) [inline]

template<class Type>
int gbxiceutilacfr::Buffer< Type >::getWithTimeout ( Type &  obj,
int  timeoutMs = -1 
) [inline]

If there is an object in the buffer, sets the object and returns 0;

If the buffer is empty, getWithTimeout() blocks until a new object is pushed in and returns the new value. By default, there is an infinite timeout (negative value). Returns 0 if successful.

If timeout is set to a positive value and the wait times out, this function returns -1 and the object argument itself is not touched. In the rare event of spurious wakeup, the return value is 1.

Referenced by gbxiceutilacfr::Buffer< Type >::getAndPopWithTimeout().

template<class Type >
void gbxiceutilacfr::Buffer< Type >::pop (  )  [inline]

Pops the front element off and discards it (usually after calling get() ). If the buffer is empty this command is quietly ignored.

Referenced by gbxiceutilacfr::Buffer< Type >::getAndPopWithTimeout().

template<class Type>
void gbxiceutilacfr::Buffer< Type >::push ( const Type &  obj  )  [inline]

Adds an object to the end of the buffer. If there is no room left in a finite-depth circular buffer, the front element of the buffer is quietly deleted and the new data is added to the end. If there is no room left in a finite-depth queue buffer the new data is quietly ignored.

References gbxiceutilacfr::BufferTypeCircular.


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

Generated for GearBox by  doxygen 1.4.5