Classes | Public Types | Public Member Functions | Static Public Attributes | Private Attributes
icl_core::RingBuffer< T > Class Template Reference

A simple ring buffer implementation based on std::vector. More...

#include <RingBuffer.h>

List of all members.

Classes

class  const_iterator
 Const iterator for RingBuffers. More...
class  iterator
 Iterator for RingBuffers. More...

Public Types

typedef std::pair< T *, size_typearray_range
 Array range as in boost::circular_buffer::array_range.
typedef std::pair< const T
*, size_type
const_array_range
 Array range as in boost::circular_buffer::const_array_range.
typedef std::vector< T >
::difference_type 
difference_type
typedef std::vector< T >::size_type size_type
typedef T value_type

Public Member Functions

array_range arrayOne ()
const_array_range arrayOne () const
array_range arrayTwo ()
const_array_range arrayTwo () const
const T & at (size_type pos) const
 Read an arbitrary element from the ring buffer without removing it.
T & at (size_type pos)
 Access an arbitrary element in the ring buffer without removing it.
const_iterator begin () const
iterator begin ()
size_type capacity () const
 Returns the capacity of the ring buffer.
void clear ()
 Clears the ring buffer.
bool empty () const
 Returns true if the buffer is empty.
array_range emptyArrayOne ()
const_array_range emptyArrayOne () const
array_range emptyArrayTwo ()
const_array_range emptyArrayTwo () const
const_iterator end () const
iterator end ()
void fakeWrite (size_t count)
const T & front () const
T & front ()
bool full () const
 Returns true if the buffer is full.
RingBufferoperator= (const RingBuffer< T > &other)
 Assignment operator.
read ()
 Removes an element from the ring buffer provided there is one present.
size_type reserve () const
 Returns the remaining reserve (free space) of the ring buffer.
 RingBuffer (size_type capacity=cDEFAULT_CAPACITY)
 Default constructor.
 RingBuffer (const RingBuffer< T > &other)
 Copy constructor.
void setCapacity (size_type capacity)
 Changes the capacity of the ring buffer.
size_type size () const
 Returns the current number of elements in the ring buffer.
void skip ()
 Removes an element from the ring buffer without returning it.
void skip (size_type count)
void write (const T &val, bool overwrite=false)
 Adds an element to the ring buffer provided there is room.
 ~RingBuffer ()

Static Public Attributes

static const size_type cDEFAULT_CAPACITY = 32

Private Attributes

std::vector< T > m_buffer
size_type m_read
size_type m_write

Detailed Description

template<typename T>
class icl_core::RingBuffer< T >

A simple ring buffer implementation based on std::vector.

Note:
This ring buffer is only suitable for scalar or POD data types! This is because elements are not deconstructed upon removal, except when the RingBuffer itself is destroyed.

Definition at line 45 of file RingBuffer.h.


Member Typedef Documentation

template<typename T>
typedef std::pair<T*, size_type> icl_core::RingBuffer< T >::array_range

Array range as in boost::circular_buffer::array_range.

Definition at line 52 of file RingBuffer.h.

template<typename T>
typedef std::pair<const T*, size_type> icl_core::RingBuffer< T >::const_array_range

Array range as in boost::circular_buffer::const_array_range.

Definition at line 54 of file RingBuffer.h.

template<typename T>
typedef std::vector<T>::difference_type icl_core::RingBuffer< T >::difference_type

Definition at line 50 of file RingBuffer.h.

template<typename T>
typedef std::vector<T>::size_type icl_core::RingBuffer< T >::size_type

Definition at line 49 of file RingBuffer.h.

template<typename T>
typedef T icl_core::RingBuffer< T >::value_type

Definition at line 48 of file RingBuffer.h.


Constructor & Destructor Documentation

template<typename T>
icl_core::RingBuffer< T >::RingBuffer ( size_type  capacity = cDEFAULT_CAPACITY) [inline]

Default constructor.

Definition at line 198 of file RingBuffer.h.

template<typename T>
icl_core::RingBuffer< T >::RingBuffer ( const RingBuffer< T > &  other) [inline]

Copy constructor.

Definition at line 203 of file RingBuffer.h.

template<typename T>
icl_core::RingBuffer< T >::~RingBuffer ( ) [inline]

Destructor documentation which Jan Oberlaender hasn't done till now!

Definition at line 404 of file RingBuffer.h.


Member Function Documentation

template<typename T >
RingBuffer< T >::array_range icl_core::RingBuffer< T >::arrayOne ( )

Returns a pointer to the first contiguous filled block of data in the RingBuffer, and the block length. Since the RingBuffer is a contiguous block of memory, but its filled area may wrap around from the end of that block to the beginning, there may be two separate blocks to consider. arrayOne() provides access to the first block, while arrayTwo() provides access to the second block. Similarly, there may be two empty blocks: the first at the end of the internal buffer, after the RingBuffer's last element, and the second at the beginning of the internal buffer, before the RingBuffer's first element. emptyArrayOne() and emptyArrayTwo() provide access to those blocks.

These access methods are provided for old C APIs and external routines which need raw buffer pointers to write into.

Definition at line 29 of file RingBuffer.hpp.

template<typename T >
RingBuffer< T >::const_array_range icl_core::RingBuffer< T >::arrayOne ( ) const

Returns a pointer to the first contiguous filled block of data in the RingBuffer, and the block length.

See also:
arrayOne()

Definition at line 42 of file RingBuffer.hpp.

template<typename T >
RingBuffer< T >::array_range icl_core::RingBuffer< T >::arrayTwo ( )

Returns a pointer to the second contiguous filled block of data in the RingBuffer, and the block length.

See also:
arrayOne()

Definition at line 55 of file RingBuffer.hpp.

template<typename T >
RingBuffer< T >::const_array_range icl_core::RingBuffer< T >::arrayTwo ( ) const

Returns a pointer to the second contiguous filled block of data in the RingBuffer, and the block length.

See also:
arrayOne()

Definition at line 68 of file RingBuffer.hpp.

template<typename T>
const T& icl_core::RingBuffer< T >::at ( size_type  pos) const [inline]

Read an arbitrary element from the ring buffer without removing it.

Throws an exception if the index is out of range.

Parameters:
posThe position into the buffer. 0 is the oldest element currently present.

Definition at line 265 of file RingBuffer.h.

template<typename T>
T& icl_core::RingBuffer< T >::at ( size_type  pos) [inline]

Access an arbitrary element in the ring buffer without removing it.

Throws an exception if the index is out of range.

Parameters:
posThe position into the buffer. 0 is the oldest element currently present.

Definition at line 287 of file RingBuffer.h.

template<typename T>
const_iterator icl_core::RingBuffer< T >::begin ( ) const [inline]

Definition at line 407 of file RingBuffer.h.

template<typename T>
iterator icl_core::RingBuffer< T >::begin ( ) [inline]

Definition at line 409 of file RingBuffer.h.

template<typename T>
size_type icl_core::RingBuffer< T >::capacity ( ) const [inline]

Returns the capacity of the ring buffer.

Definition at line 358 of file RingBuffer.h.

template<typename T>
void icl_core::RingBuffer< T >::clear ( ) [inline]

Clears the ring buffer.

Definition at line 217 of file RingBuffer.h.

template<typename T>
bool icl_core::RingBuffer< T >::empty ( ) const [inline]

Returns true if the buffer is empty.

Definition at line 220 of file RingBuffer.h.

template<typename T >
RingBuffer< T >::array_range icl_core::RingBuffer< T >::emptyArrayOne ( )

Returns a pointer to the first contiguous empty block of data in the RingBuffer, and the block length.

See also:
arrayOne()

Definition at line 81 of file RingBuffer.hpp.

template<typename T >
RingBuffer< T >::const_array_range icl_core::RingBuffer< T >::emptyArrayOne ( ) const

Returns a pointer to the first contiguous empty block of data in the RingBuffer, and the block length.

See also:
arrayOne()

Definition at line 101 of file RingBuffer.hpp.

template<typename T >
RingBuffer< T >::array_range icl_core::RingBuffer< T >::emptyArrayTwo ( )

Returns a pointer to the second contiguous empty block of data in the RingBuffer, and the block length.

See also:
arrayOne()

Definition at line 121 of file RingBuffer.hpp.

template<typename T >
RingBuffer< T >::const_array_range icl_core::RingBuffer< T >::emptyArrayTwo ( ) const

Returns a pointer to the second contiguous empty block of data in the RingBuffer, and the block length.

See also:
arrayOne()

Definition at line 134 of file RingBuffer.hpp.

template<typename T>
const_iterator icl_core::RingBuffer< T >::end ( ) const [inline]

Definition at line 412 of file RingBuffer.h.

template<typename T>
iterator icl_core::RingBuffer< T >::end ( ) [inline]

Definition at line 414 of file RingBuffer.h.

template<typename T >
void icl_core::RingBuffer< T >::fakeWrite ( size_t  count)

Increases ring buffer size by count, at most up to its capacity. The added elements are not overwritten. Use this if you have filled buffer elements (from emptyArrayOne() and emptyArrayTwo()) manually, to adjust the ring buffer's write pointer.

Definition at line 160 of file RingBuffer.hpp.

template<typename T>
const T& icl_core::RingBuffer< T >::front ( ) const [inline]

Definition at line 304 of file RingBuffer.h.

template<typename T>
T& icl_core::RingBuffer< T >::front ( ) [inline]

Definition at line 305 of file RingBuffer.h.

template<typename T>
bool icl_core::RingBuffer< T >::full ( ) const [inline]

Returns true if the buffer is full.

Definition at line 223 of file RingBuffer.h.

template<typename T>
RingBuffer& icl_core::RingBuffer< T >::operator= ( const RingBuffer< T > &  other) [inline]

Assignment operator.

Definition at line 208 of file RingBuffer.h.

template<typename T>
T icl_core::RingBuffer< T >::read ( ) [inline]

Removes an element from the ring buffer provided there is one present.

Throws an exception if the buffer is empty.

Definition at line 329 of file RingBuffer.h.

template<typename T>
size_type icl_core::RingBuffer< T >::reserve ( ) const [inline]

Returns the remaining reserve (free space) of the ring buffer.

Definition at line 361 of file RingBuffer.h.

template<typename T>
void icl_core::RingBuffer< T >::setCapacity ( size_type  capacity) [inline]

Changes the capacity of the ring buffer.

If the new capacity is less than the current buffer size, only the latest capacity elements are kept, the rest are destroyed.

Definition at line 371 of file RingBuffer.h.

template<typename T>
size_type icl_core::RingBuffer< T >::size ( ) const [inline]

Returns the current number of elements in the ring buffer.

Definition at line 345 of file RingBuffer.h.

template<typename T>
void icl_core::RingBuffer< T >::skip ( ) [inline]

Removes an element from the ring buffer without returning it.

Definition at line 308 of file RingBuffer.h.

template<typename T >
void icl_core::RingBuffer< T >::skip ( size_type  count)

Removes a number of elements from the ring buffer without returning them. If the ring buffer is empty, nothing happens.

Definition at line 147 of file RingBuffer.hpp.

template<typename T>
void icl_core::RingBuffer< T >::write ( const T &  val,
bool  overwrite = false 
) [inline]

Adds an element to the ring buffer provided there is room.

If overwrite == false, throws an exception if the element can not be added. If overwrite == true, old elements are discarded to make room for new ones.

Definition at line 230 of file RingBuffer.h.


Member Data Documentation

template<typename T>
const size_type icl_core::RingBuffer< T >::cDEFAULT_CAPACITY = 32 [static]

Definition at line 55 of file RingBuffer.h.

template<typename T>
std::vector<T> icl_core::RingBuffer< T >::m_buffer [private]

Definition at line 537 of file RingBuffer.h.

template<typename T>
size_type icl_core::RingBuffer< T >::m_read [private]

Definition at line 539 of file RingBuffer.h.

template<typename T>
size_type icl_core::RingBuffer< T >::m_write [private]

Definition at line 538 of file RingBuffer.h.


The documentation for this class was generated from the following files:


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:20