42 #ifndef ORO_CORELIB_BUFFER_LOCKED_HPP 43 #define ORO_CORELIB_BUFFER_LOCKED_HPP 45 #include "../os/Mutex.hpp" 46 #include "../os/MutexLock.hpp" 76 : cap(size), buf(), mcircular(options.circular()), initialized(false), droppedSamples(0)
86 : cap(size), buf(), mcircular(options.circular()), droppedSamples(0)
94 if (!initialized || reset) {
95 buf.resize(cap, sample);
118 if ( cap == (size_type)buf.size() ) {
128 buf.push_back( item );
132 size_type
Push(
const std::vector<value_t>& items)
135 typename std::vector<value_t>::const_iterator itl( items.begin() );
136 if (mcircular && (size_type)items.size() >= cap ) {
140 droppedSamples += cap;
141 itl = items.begin() + ( items.size() - cap );
142 }
else if ( mcircular && (size_type)(buf.size() + items.size()) > cap) {
144 assert( (size_type)items.size() < cap );
145 while ( (size_type)(buf.size() + items.size()) > cap )
152 while ( ((size_type)buf.size() != cap) && (itl != items.end()) ) {
153 buf.push_back( *itl );
157 size_type writtenSamples = itl - items.begin();
160 assert( writtenSamples == (size_type)items.size() );
162 droppedSamples += items.size() - writtenSamples;
164 return writtenSamples;
178 size_type
Pop(std::vector<value_t>& items )
183 while ( !buf.empty() ) {
184 items.push_back( buf.front() );
200 lastSample = buf.front();
209 assert(item == &lastSample &&
"Wrong pointer given back to buffer");
234 return (size_type)buf.size() == cap;
239 return droppedSamples;
243 std::deque<value_t> buf;
246 const bool mcircular;
248 size_type droppedSamples;
252 #endif // BUFFERSIMPLE_HPP BufferLocked(size_type size, const Options &options=Options())
Create an unitialized buffer of size size, with preallocated data storage.
virtual bool data_sample(param_t sample, bool reset=true)
Initializes this buffer with a data sample, such that for dynamical allocated types T...
size_type Push(const std::vector< value_t > &items)
Write a sequence of values to the buffer.
boost::call_traits< T >::reference reference_t
A Buffer is an object which is used to store (Push) and retrieve (Pop) values from.
FlowStatus
Returns the status of a data flow read operation.
boost::call_traits< T >::param_type param_t
size_type dropped() const
Returns the number of dropped samples, because the buffer was full.
BufferBase::Options Options
void Release(value_t *item)
Releases the pointer.
value_t * PopWithoutRelease()
Returns a pointer to the first element in the buffer.
bool Push(param_t item)
Write a single value to the buffer.
bool empty() const
Check if this buffer is empty.
BufferBase::size_type size_type
BufferInterface< T >::size_type size_type
size_type Pop(std::vector< value_t > &items)
Read the whole buffer.
BufferInterface< T >::param_t param_t
bool full() const
Check if this buffer is full.
BufferInterface< T >::reference_t reference_t
size_type size() const
Returns the actual number of items that are stored in the buffer.
Implements a very simple blocking thread-safe buffer, using mutexes (locks).
virtual value_t data_sample() const
Reads back a data sample.
~BufferLocked()
Destructor.
void clear()
Clears all contents of this buffer.
size_type capacity() const
Returns the maximum number of items that can be stored in the buffer.
BufferLocked(size_type size, param_t initial_value, const Options &options=Options())
Create a buffer of size size, with preallocated data storage.
An object oriented wrapper around a non recursive mutex.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
FlowStatus Pop(reference_t item)
Read the oldest value from the buffer.
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...