INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

gbxsickacfr::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, BufferType type)
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 getNext (Type &obj, int timeoutMs=-1)
int getAndPopNext (Type &obj, int timeoutMs=-1)


Detailed Description

template<class Type>
class gbxsickacfr::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. Buffering Ice smart pointers requires a specialized class PtrBuffer.

You should always try to get() data before blocking with getNext() because closely spaced push events may be lost. For example:

gbxiceutilacfr::Buffer<double> buffer( 10, gbxiceutilacfr::BufferTypeCircular );
double data;
while (1)
{
    int ret = 0;
    try {
        buffer.getAndPop( data );
    }
    catch ( const gbxutilacfr::Exception & e ) {
        ret = buffer.getAndPopNext( data, TIMEOUT_MS );
    }
    if ( ret == 0 )
    {
        // do something with data
    }
}

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


Constructor & Destructor Documentation

template<class Type>
gbxsickacfr::gbxiceutilacfr::Buffer< Type >::Buffer ( int  depth,
BufferType  type 
)

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


Member Function Documentation

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

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.

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

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

template<class Type>
void gbxsickacfr::gbxiceutilacfr::Buffer< Type >::get ( Type &  obj  )  const

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 trap these and call getNext() which will block until new data arrives.

template<class Type>
void gbxsickacfr::gbxiceutilacfr::Buffer< Type >::getAndPop ( Type &  obj  ) 

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

template<class Type>
int gbxsickacfr::gbxiceutilacfr::Buffer< Type >::getAndPopNext ( Type &  obj,
int  timeoutMs = -1 
)

Same as getNext but calls pop afterwards.

template<class Type>
int gbxsickacfr::gbxiceutilacfr::Buffer< Type >::getNext ( Type &  obj,
int  timeoutMs = -1 
)

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

If the buffer is empty, getNext() blocks until a new object is pushed in and returns the new value. By default, there is no 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.

template<class Type>
void gbxsickacfr::gbxiceutilacfr::Buffer< Type >::pop (  ) 

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

template<class Type>
void gbxsickacfr::gbxiceutilacfr::Buffer< Type >::push ( const Type &  obj  ) 

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.


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

Generated for GearBox by  doxygen 1.4.5