Orocos Real-Time Toolkit  2.9.0
Public Types | Public Member Functions | Public Attributes | List of all members
RTT::base::Buffer< T > Class Template Reference

This object represents the default thread-safe buffer implementation used by Orocos objects. More...

#include <rtt/base/Buffer.hpp>

Inheritance diagram for RTT::base::Buffer< T >:
RTT::base::BufferLockFree< T > RTT::base::BufferInterface< T > RTT::base::BufferBase

Public Types

typedef BufferInterface< T >::reference_t reference_t
 
typedef BufferInterface< T >::param_t param_t
 
typedef BufferInterface< T >::size_type size_type
 
typedef T value_t
 
typedef BufferBase::Options Options
 
typedef boost::shared_ptr< BufferInterface< T > > shared_ptr
 

Public Member Functions

 Buffer (int qsize, const T &initial_value=T())
 Create a fifo queue of fixed size. More...
 
virtual bool data_sample (param_t sample, bool reset=true)
 Initializes this buffer with a data sample, such that for dynamical allocated types T, the buffer can reserve place to hold these elements. More...
 
virtual value_t data_sample () const
 Reads back a data sample. More...
 
size_type capacity () const
 Returns the maximum number of items that can be stored in the buffer. More...
 
size_type size () const
 Returns the actual number of items that are stored in the buffer. More...
 
bool empty () const
 Check if this buffer is empty. More...
 
bool full () const
 Check if this buffer is full. More...
 
void clear ()
 Clears all contents of this buffer. More...
 
virtual size_type dropped () const
 Returns the number of dropped samples, because the buffer was full. More...
 
bool Push (param_t item)
 Write a single value to the buffer. More...
 
size_type Push (const std::vector< value_t > &items)
 Write a sequence of values to the buffer. More...
 
FlowStatus Pop (reference_t item)
 Read the oldest value from the buffer. More...
 
size_type Pop (std::vector< value_t > &items)
 Read the whole buffer. More...
 
value_tPopWithoutRelease ()
 Returns a pointer to the first element in the buffer. More...
 
void Release (value_t *item)
 Releases the pointer. More...
 

Public Attributes

const unsigned int MAX_THREADS
 The maximum number of threads. More...
 

Detailed Description

template<class T>
class RTT::base::Buffer< T >

This object represents the default thread-safe buffer implementation used by Orocos objects.

Definition at line 67 of file Buffer.hpp.

Member Typedef Documentation

template<class T>
typedef BufferBase::Options RTT::base::BufferLockFree< T >::Options
inherited

Definition at line 74 of file BufferLockFree.hpp.

template<class T >
typedef BufferInterface<T>::param_t RTT::base::Buffer< T >::param_t

Definition at line 76 of file Buffer.hpp.

template<class T >
typedef BufferInterface<T>::reference_t RTT::base::Buffer< T >::reference_t

Definition at line 75 of file Buffer.hpp.

template<class T>
typedef boost::shared_ptr< BufferInterface<T> > RTT::base::BufferInterface< T >::shared_ptr
inherited

Definition at line 63 of file BufferInterface.hpp.

template<class T >
typedef BufferInterface<T>::size_type RTT::base::Buffer< T >::size_type

Definition at line 77 of file Buffer.hpp.

template<class T >
typedef T RTT::base::Buffer< T >::value_t

Definition at line 78 of file Buffer.hpp.

Constructor & Destructor Documentation

template<class T >
RTT::base::Buffer< T >::Buffer ( int  qsize,
const T &  initial_value = T() 
)
inline

Create a fifo queue of fixed size.

Definition at line 84 of file Buffer.hpp.

Member Function Documentation

template<class T>
size_type RTT::base::BufferLockFree< T >::capacity ( ) const
inlinevirtualinherited

Returns the maximum number of items that can be stored in the buffer.

Returns
maximum number of items.

Implements RTT::base::BufferBase.

Definition at line 160 of file BufferLockFree.hpp.

References RTT::internal::AtomicQueue< T >::capacity().

Referenced by RTT::base::BufferLockFree< T >::Push().

template<class T>
void RTT::base::BufferLockFree< T >::clear ( )
inlinevirtualinherited
template<class T>
virtual bool RTT::base::BufferLockFree< T >::data_sample ( param_t  sample,
bool  reset = true 
)
inlinevirtualinherited

Initializes this buffer with a data sample, such that for dynamical allocated types T, the buffer can reserve place to hold these elements.

Parameters
samplethe data sample
resetenforce reinitialization even if this operation clears all data.
Returns
true if the buffer was successfully (re)initialized.
Postcondition
Calling this function causes all data in the buffer to be lost and the size being reset to zero.

Implements RTT::base::BufferInterface< T >.

Definition at line 136 of file BufferLockFree.hpp.

References RTT::internal::TsPool< T >::data_sample().

template<class T>
virtual value_t RTT::base::BufferLockFree< T >::data_sample ( ) const
inlinevirtualinherited
template<class T>
virtual size_type RTT::base::BufferLockFree< T >::dropped ( ) const
inlinevirtualinherited

Returns the number of dropped samples, because the buffer was full.

Implements RTT::base::BufferBase.

Definition at line 187 of file BufferLockFree.hpp.

References RTT::os::AtomicInt::read().

template<class T>
bool RTT::base::BufferLockFree< T >::empty ( ) const
inlinevirtualinherited

Check if this buffer is empty.

Returns
true if size() == 0

Implements RTT::base::BufferBase.

Definition at line 170 of file BufferLockFree.hpp.

References RTT::internal::AtomicQueue< T >::isEmpty().

template<class T>
bool RTT::base::BufferLockFree< T >::full ( ) const
inlinevirtualinherited

Check if this buffer is full.

Returns
true if size() == capacity()

Implements RTT::base::BufferBase.

Definition at line 175 of file BufferLockFree.hpp.

References RTT::internal::AtomicQueue< T >::isFull().

template<class T>
FlowStatus RTT::base::BufferLockFree< T >::Pop ( reference_t  item)
inlinevirtualinherited

Read the oldest value from the buffer.

Parameters
itemis to be set with a value from the buffer.
Returns
true if something was read.

Implements RTT::base::BufferInterface< T >.

Definition at line 261 of file BufferLockFree.hpp.

References RTT::internal::TsPool< T >::deallocate(), RTT::internal::AtomicQueue< T >::dequeue(), RTT::NewData, and RTT::NoData.

template<class T>
size_type RTT::base::BufferLockFree< T >::Pop ( std::vector< value_t > &  items)
inlinevirtualinherited

Read the whole buffer.

Parameters
itemsis to be filled with all values in the buffer, with items.begin() the oldest value.
Returns
the number of items read.

Implements RTT::base::BufferInterface< T >.

Definition at line 272 of file BufferLockFree.hpp.

References RTT::internal::TsPool< T >::deallocate(), and RTT::internal::AtomicQueue< T >::dequeue().

template<class T>
value_t* RTT::base::BufferLockFree< T >::PopWithoutRelease ( )
inlinevirtualinherited

Returns a pointer to the first element in the buffer.

The pointer is only garanteed to stay valid until the next pop operation.

Note the pointer needs the be released by calling Release on the buffer.

Returns
a pointer to a sample or Zero if buffer is empty

Implements RTT::base::BufferInterface< T >.

Definition at line 284 of file BufferLockFree.hpp.

References RTT::internal::AtomicQueue< T >::dequeue().

template<class T>
bool RTT::base::BufferLockFree< T >::Push ( param_t  item)
inlinevirtualinherited
template<class T>
size_type RTT::base::BufferLockFree< T >::Push ( const std::vector< value_t > &  items)
inlinevirtualinherited

Write a sequence of values to the buffer.

Parameters
itemsthe values to write
Returns
the number of values written (may be less than items.size())

Implements RTT::base::BufferInterface< T >.

Definition at line 244 of file BufferLockFree.hpp.

References RTT::os::AtomicInt::add(), and RTT::base::BufferLockFree< T >::Push().

template<class T>
void RTT::base::BufferLockFree< T >::Release ( value_t item)
inlinevirtualinherited

Releases the pointer.

Parameters
itempointer aquired using PopWithoutRelease()

Implements RTT::base::BufferInterface< T >.

Definition at line 292 of file BufferLockFree.hpp.

References RTT::internal::TsPool< T >::deallocate().

template<class T>
size_type RTT::base::BufferLockFree< T >::size ( ) const
inlinevirtualinherited

Returns the actual number of items that are stored in the buffer.

Returns
number of items.

Implements RTT::base::BufferBase.

Definition at line 165 of file BufferLockFree.hpp.

References RTT::internal::AtomicQueue< T >::size().

Member Data Documentation

template<class T>
const unsigned int RTT::base::BufferLockFree< T >::MAX_THREADS
inherited

The maximum number of threads.

Definition at line 83 of file BufferLockFree.hpp.


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