#include <BufferLocked.hpp>
Public Types | |
typedef BufferInterface< T > ::param_t | param_t |
typedef BufferInterface< T > ::reference_t | reference_t |
typedef BufferInterface< T > ::size_type | size_type |
typedef T | value_t |
Public Member Functions | |
BufferLocked (size_type size, const T &initial_value=T(), bool circular=false) | |
size_type | capacity () const |
void | clear () |
virtual void | data_sample (const T &sample) |
virtual T | data_sample () const |
bool | empty () const |
bool | full () const |
bool | Pop (reference_t item) |
size_type | Pop (std::vector< T > &items) |
value_t * | PopWithoutRelease () |
bool | Push (param_t item) |
size_type | Push (const std::vector< T > &items) |
void | Release (value_t *item) |
size_type | size () const |
~BufferLocked () | |
Private Attributes | |
std::deque< T > | buf |
size_type | cap |
value_t | lastSample |
os::Mutex | lock |
const bool | mcircular |
Implements a very simple blocking thread-safe buffer, using mutexes (locks).
Definition at line 61 of file BufferLocked.hpp.
typedef BufferInterface<T>::param_t RTT::base::BufferLocked< T >::param_t |
Reimplemented from RTT::base::BufferInterface< T >.
Definition at line 67 of file BufferLocked.hpp.
typedef BufferInterface<T>::reference_t RTT::base::BufferLocked< T >::reference_t |
Reimplemented from RTT::base::BufferInterface< T >.
Definition at line 66 of file BufferLocked.hpp.
typedef BufferInterface<T>::size_type RTT::base::BufferLocked< T >::size_type |
Reimplemented from RTT::base::BufferInterface< T >.
Definition at line 68 of file BufferLocked.hpp.
typedef T RTT::base::BufferLocked< T >::value_t |
Reimplemented from RTT::base::BufferInterface< T >.
Definition at line 69 of file BufferLocked.hpp.
RTT::base::BufferLocked< T >::BufferLocked | ( | size_type | size, |
const T & | initial_value = T() , |
||
bool | circular = false |
||
) | [inline] |
Create a buffer of size size, with preallocated data storage.
size | The number of elements this buffer can hold. |
initial_value | A data sample with which each preallocated data element is initialized. |
circular | Set flag to true to make this buffer circular. If not circular, new values are discarded on full. |
Definition at line 77 of file BufferLocked.hpp.
RTT::base::BufferLocked< T >::~BufferLocked | ( | ) | [inline] |
Destructor
Definition at line 98 of file BufferLocked.hpp.
size_type RTT::base::BufferLocked< T >::capacity | ( | ) | const [inline, virtual] |
Returns the maximum number of items that can be stored in the buffer.
Implements RTT::base::BufferBase.
Definition at line 183 of file BufferLocked.hpp.
void RTT::base::BufferLocked< T >::clear | ( | ) | [inline, virtual] |
Clears all contents of this buffer.
Implements RTT::base::BufferBase.
Definition at line 193 of file BufferLocked.hpp.
virtual void RTT::base::BufferLocked< T >::data_sample | ( | const T & | sample | ) | [inline, virtual] |
Initializes this buffer with a data sample, such that for dynamical allocated types T, the buffer can reserve place to hold these elements.
Implements RTT::base::BufferInterface< T >.
Definition at line 83 of file BufferLocked.hpp.
virtual T RTT::base::BufferLocked< T >::data_sample | ( | ) | const [inline, virtual] |
Reads back a data sample.
Implements RTT::base::BufferInterface< T >.
Definition at line 90 of file BufferLocked.hpp.
bool RTT::base::BufferLocked< T >::empty | ( | ) | const [inline, virtual] |
Check if this buffer is empty.
Implements RTT::base::BufferBase.
Definition at line 198 of file BufferLocked.hpp.
bool RTT::base::BufferLocked< T >::full | ( | ) | const [inline, virtual] |
Check if this buffer is full.
Implements RTT::base::BufferBase.
Definition at line 203 of file BufferLocked.hpp.
bool RTT::base::BufferLocked< T >::Pop | ( | reference_t | item | ) | [inline, virtual] |
Read the oldest value from the buffer.
item | is to be set with a value from the buffer. |
Implements RTT::base::BufferInterface< T >.
Definition at line 138 of file BufferLocked.hpp.
size_type RTT::base::BufferLocked< T >::Pop | ( | std::vector< T > & | items | ) | [inline, virtual] |
Read the whole buffer.
items | is to be filled with all values in the buffer, with items.begin() the oldest value. |
Implements RTT::base::BufferInterface< T >.
Definition at line 149 of file BufferLocked.hpp.
value_t* RTT::base::BufferLocked< T >::PopWithoutRelease | ( | ) | [inline, virtual] |
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.
Implements RTT::base::BufferInterface< T >.
Definition at line 162 of file BufferLocked.hpp.
bool RTT::base::BufferLocked< T >::Push | ( | param_t | item | ) | [inline, virtual] |
Write a single value to the buffer.
item | the value to write |
Implements RTT::base::BufferInterface< T >.
Definition at line 100 of file BufferLocked.hpp.
size_type RTT::base::BufferLocked< T >::Push | ( | const std::vector< T > & | items | ) | [inline, virtual] |
Write a sequence of values to the buffer.
items | the values to write |
Implements RTT::base::BufferInterface< T >.
Definition at line 113 of file BufferLocked.hpp.
void RTT::base::BufferLocked< T >::Release | ( | value_t * | item | ) | [inline, virtual] |
Releases the pointer
item | pointer aquired using PopWithoutRelease() |
Implements RTT::base::BufferInterface< T >.
Definition at line 176 of file BufferLocked.hpp.
size_type RTT::base::BufferLocked< T >::size | ( | ) | const [inline, virtual] |
Returns the actual number of items that are stored in the buffer.
Implements RTT::base::BufferBase.
Definition at line 188 of file BufferLocked.hpp.
std::deque<T> RTT::base::BufferLocked< T >::buf [private] |
Definition at line 209 of file BufferLocked.hpp.
size_type RTT::base::BufferLocked< T >::cap [private] |
Definition at line 208 of file BufferLocked.hpp.
value_t RTT::base::BufferLocked< T >::lastSample [private] |
Definition at line 210 of file BufferLocked.hpp.
os::Mutex RTT::base::BufferLocked< T >::lock [mutable, private] |
Definition at line 211 of file BufferLocked.hpp.
const bool RTT::base::BufferLocked< T >::mcircular [private] |
Definition at line 212 of file BufferLocked.hpp.