40 #ifndef ORO_CORELIB_BUFFER_UNSYNC_HPP 41 #define ORO_CORELIB_BUFFER_UNSYNC_HPP 71 : cap(size), buf(), mcircular(circular), droppedSamples(0)
78 buf.resize(cap, sample);
94 if (cap == (size_type)buf.size() ) {
106 buf.push_back( item );
110 size_type
Push(
const std::vector<T>& items)
112 typename std::vector<T>::const_iterator itl( items.begin() );
113 if (mcircular && (size_type)items.size() >= cap ) {
117 droppedSamples += cap;
118 itl = items.begin() + ( items.size() - cap );
119 }
else if ( mcircular && (size_type)(buf.size() + items.size()) > cap) {
121 assert( (size_type)items.size() < cap );
122 while ( (size_type)(buf.size() + items.size()) > cap )
129 while ( ((size_type)buf.size() != cap) && (itl != items.end()) ) {
130 buf.push_back( *itl );
134 size_type written = (itl - items.begin());
136 droppedSamples += items.size() - written;
141 bool Pop( reference_t item )
151 size_type
Pop(std::vector<T>& items )
155 while ( !buf.empty() ) {
156 items.push_back( buf.front() );
171 lastSample = buf.front();
182 assert(item == &lastSample &&
"Wrong pointer given back to buffer");
202 return (size_type)buf.size() == cap;
207 return droppedSamples;
213 const bool mcircular;
214 size_type droppedSamples;
218 #endif // BUFFERSIMPLE_HPP value_t * PopWithoutRelease()
Returns a pointer to the first element in the buffer.
size_type size() const
Returns the actual number of items that are stored in the buffer.
BufferInterface< T >::size_type size_type
virtual T data_sample() const
Reads back a data sample.
bool empty() const
Check if this buffer is empty.
BufferInterface< T >::param_t param_t
boost::call_traits< T >::reference reference_t
A Buffer is an object which is used to store (Push) and retrieve (Pop) values from.
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
BufferUnSync(size_type size, const T &initial_value=T(), bool circular=false)
Create a buffer of size size.
BufferInterface< T >::reference_t reference_t
~BufferUnSync()
Destructor.
Implements a not threadsafe buffer.
BufferBase::size_type size_type
virtual void data_sample(const T &sample)
Initializes this buffer with a data sample, such that for dynamical allocated types T...
size_type Push(const std::vector< T > &items)
Write a sequence of values to the buffer.
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.
size_type Pop(std::vector< T > &items)
Read the whole buffer.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
bool Pop(reference_t item)
Read the oldest value from the buffer.
virtual size_type dropped() const
Returns the number of dropped samples, because the buffer was full.
void Release(value_t *item)
Releases the pointer.