40 #ifndef ORO_CORELIB_BUFFER_UNSYNC_HPP 41 #define ORO_CORELIB_BUFFER_UNSYNC_HPP 72 : cap(size), buf(), mcircular(options.circular()), initialized(false), droppedSamples(0)
80 : cap(size), buf(), mcircular(options.circular()), initialized(false), droppedSamples(0)
87 if (!initialized || reset) {
88 buf.resize(cap, sample);
108 if (cap == (size_type)buf.size() ) {
120 buf.push_back( item );
124 size_type
Push(
const std::vector<value_t>& items)
126 typename std::vector<value_t>::const_iterator itl( items.begin() );
127 if (mcircular && (size_type)items.size() >= cap ) {
131 droppedSamples += cap;
132 itl = items.begin() + ( items.size() - cap );
133 }
else if ( mcircular && (size_type)(buf.size() + items.size()) > cap) {
135 assert( (size_type)items.size() < cap );
136 while ( (size_type)(buf.size() + items.size()) > cap )
143 while ( ((size_type)buf.size() != cap) && (itl != items.end()) ) {
144 buf.push_back( *itl );
148 size_type written = (itl - items.begin());
150 droppedSamples += items.size() - written;
165 size_type
Pop(std::vector<value_t>& items )
169 while ( !buf.empty() ) {
170 items.push_back( buf.front() );
185 lastSample = buf.front();
194 assert(item == &lastSample &&
"Wrong pointer given back to buffer");
214 return (size_type)buf.size() == cap;
219 return droppedSamples;
223 std::deque<value_t> buf;
225 const bool mcircular;
227 size_type droppedSamples;
231 #endif // BUFFERSIMPLE_HPP value_t * PopWithoutRelease()
Returns a pointer to the first element in the buffer.
FlowStatus Pop(reference_t item)
Read the oldest value from the buffer.
BufferUnSync(size_type size, const Options &options=Options())
Create an uninitialized buffer of size size.
size_type size() const
Returns the actual number of items that are stored in the buffer.
BufferInterface< T >::size_type size_type
bool empty() const
Check if this buffer is empty.
BufferInterface< T >::param_t param_t
boost::call_traits< T >::reference reference_t
BufferUnSync(size_type size, param_t initial_value, const Options &options=Options())
Create a buffer of size size.
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.
size_type capacity() const
Returns the maximum number of items that can be stored in the buffer.
boost::call_traits< T >::param_type param_t
BufferBase::Options Options
BufferInterface< T >::reference_t reference_t
~BufferUnSync()
Destructor.
size_type Pop(std::vector< value_t > &items)
Read the whole buffer.
Implements a not threadsafe buffer.
BufferBase::size_type size_type
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.
virtual value_t data_sample() const
Reads back a data sample.
bool Push(param_t item)
Write a single value to the buffer.
bool full() const
Check if this buffer is full.
void clear()
Clears all contents of this buffer.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
virtual size_type dropped() const
Returns the number of dropped samples, because the buffer was full.
void Release(value_t *item)
Releases the pointer.