23 #ifndef ICL_CORE_RING_BUFFER_H_INCLUDED 24 #define ICL_CORE_RING_BUFFER_H_INCLUDED 32 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ 49 typedef typename std::vector<T>::size_type
size_type;
58 class const_iterator :
public std::iterator<std::random_access_iterator_tag, T>
234 void write(
const T& val,
bool overwrite=
false)
236 size_type new_write_pos =
m_write+1;
237 if (new_write_pos >=
m_buffer.size())
241 if (new_write_pos ==
m_read)
249 throw std::out_of_range(
"RingBuffer::write: capacity exceeded");
269 const T&
at(size_type pos)
const 282 throw std::out_of_range(
"RingBuffer::at: out of range");
304 throw std::out_of_range(
"RingBuffer::at: out of range");
316 throw std::out_of_range(
"RingBuffer::skip: buffer empty");
328 void skip(size_type count);
337 throw std::out_of_range(
"RingBuffer::read: buffer empty");
339 size_type read_pos =
m_read;
377 size_type old_size =
size();
378 size_type new_size = (capacity < old_size) ? capacity : old_size;
379 std::vector<T> old_buffer(
m_buffer);
380 size_type old_read =
m_read;
385 old_read += old_size-new_size;
386 if (old_read >= old_buffer.size())
388 old_read -= old_buffer.size();
391 for (size_type i=0; i<new_size; i++)
395 if (old_read >= old_buffer.size())
476 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ const T & at(size_type pos) const
Read an arbitrary element from the ring buffer without removing it.
size_type capacity() const
Returns the capacity of the ring buffer.
bool operator==(const const_iterator &other) const
#define ICL_CORE_VC_DEPRECATE_STYLE
void fakeWrite(size_t count)
bool operator!=(const const_iterator &other) const
size_type size() const
Returns the current number of elements in the ring buffer.
Contains macros to deprecate classes, types, functions and variables.
void skip()
Removes an element from the ring buffer without returning it.
std::vector< T >::size_type size_type
const T * m_cbegin
Beginning of the container.
bool empty() const
Returns true if the buffer is empty.
T read()
Removes an element from the ring buffer provided there is one present.
const T * m_cend
End of the container.
void clear()
Clears the ring buffer.
void setCapacity(size_type capacity)
Changes the capacity of the ring buffer.
void write(const T &val, bool overwrite=false)
Adds an element to the ring buffer provided there is room.
const_iterator & operator++()
const_iterator & operator-=(difference_type offset)
RingBuffer(const RingBuffer< T > &other)
Copy constructor.
const_iterator operator-(difference_type offset) const
static const size_type cDEFAULT_CAPACITY
const T * operator->() const
const_iterator & operator=(const const_iterator &other)
const T & operator*() const
Const iterator for RingBuffers.
const_iterator(const T *current, const T *cbegin, const T *cend, const T *begin)
std::vector< T >::difference_type difference_type
iterator(const iterator &other)
const_iterator & operator--()
std::vector< T > m_buffer
const_iterator(const const_iterator &other)
size_type reserve() const
Returns the remaining reserve (free space) of the ring buffer.
const_iterator & operator+=(difference_type offset)
std::pair< const T *, size_type > const_array_range
Array range as in boost::circular_buffer::const_array_range.
Contains Interface base classes and base types.
T & at(size_type pos)
Access an arbitrary element in the ring buffer without removing it.
RingBuffer(size_type capacity=cDEFAULT_CAPACITY)
Default constructor.
const_iterator end() const
const T * m_begin
Actual first value in the container.
array_range emptyArrayOne()
iterator(const T *current, const T *cbegin, const T *cend, const T *begin)
std::pair< T *, size_type > array_range
Array range as in boost::circular_buffer::array_range.
array_range emptyArrayTwo()
#define ICL_CORE_GCC_DEPRECATE_STYLE
A simple ring buffer implementation based on std::vector.
bool full() const
Returns true if the buffer is full.
const_iterator operator+(difference_type offset) const
const_iterator begin() const