Fawkes API  Fawkes Development Version
fawkes::CircularBuffer< Type > Class Template Reference

Circular buffer with a fixed size. More...

#include <>>

Inheritance diagram for fawkes::CircularBuffer< Type >:

Public Types

typedef std::size_t size_type
 The size_type of the buffer. More...
 
typedef std::deque< Type >::const_iterator const_iterator
 The CircularBuffer's iterator is a std::deque iterator. More...
 
typedef std::deque< Type >::const_reverse_iterator const_reverse_iterator
 The CircularBuffer's reverse iterator is a std::deque reverse iterator. More...
 
typedef const_iterator iterator
 iterator is also const, we don't want to manipulate any elements More...
 

Public Member Functions

 CircularBuffer (size_type n)
 Constructor. More...
 
 CircularBuffer (const CircularBuffer< Type > &other)
 Copy constructor. More...
 
 ~CircularBuffer ()
 Destructor. More...
 
CircularBuffer< Type > & operator= (const CircularBuffer< Type > &other)
 Assignment operator. More...
 
void push_back (const Type &val)
 Insert an element at the end of the buffer and delete the first element if necessary. More...
 
void pop_front ()
 Delete the first element. More...
 
size_type get_max_size () const
 Get the maximum size of the buffer. More...
 
std::deque< Type > get_deque () const
 Get the deque used to store the elements. More...
 
const Type & operator[] (size_type n) const
 Element access. More...
 
const Type & at (size_type n) const
 Element access. More...
 
const Type & front () const
 Access the first element in the buffer. More...
 
const Type & back () const
 Access the last element in the buffer. More...
 
const_iterator begin () const
 Get iterator to the beginning. More...
 
const_iterator end () const
 Get iterator to the end. More...
 
const_reverse_iterator rbegin () const
 Get reverse iterator to the beginning. More...
 
const_reverse_iterator rend () const
 Get reverse iterator to the end. More...
 
size_type size () const
 Get actual size of the buffer. More...
 

Protected Attributes

std::deque< Type > deque_
 The deque used to store the data. More...
 
size_type max_size_
 The maximum size of the circular buffer. More...
 

Detailed Description

template<typename Type>
class fawkes::CircularBuffer< Type >

Circular buffer with a fixed size.

This class provides a a circular buffer. A circular buffer is a container with a fixed (maximum) size. It automatically maintains its size by removing elements from the front, if necessary. This implementation does not allow any element manipulation other than push_back() and pop_front(). All returned references to elements are constant.

Author
Till Hofmann

Definition at line 44 of file circular_buffer.h.

Member Typedef Documentation

◆ const_iterator

template<typename Type >
typedef std::deque<Type>::const_iterator fawkes::CircularBuffer< Type >::const_iterator

The CircularBuffer's iterator is a std::deque iterator.

Definition at line 50 of file circular_buffer.h.

◆ const_reverse_iterator

template<typename Type >
typedef std::deque<Type>::const_reverse_iterator fawkes::CircularBuffer< Type >::const_reverse_iterator

The CircularBuffer's reverse iterator is a std::deque reverse iterator.

Definition at line 52 of file circular_buffer.h.

◆ iterator

template<typename Type >
typedef const_iterator fawkes::CircularBuffer< Type >::iterator

iterator is also const, we don't want to manipulate any elements

Definition at line 54 of file circular_buffer.h.

◆ size_type

template<typename Type >
typedef std::size_t fawkes::CircularBuffer< Type >::size_type

The size_type of the buffer.

Definition at line 48 of file circular_buffer.h.

Constructor & Destructor Documentation

◆ CircularBuffer() [1/2]

template<typename Type >
fawkes::CircularBuffer< Type >::CircularBuffer ( size_type  n)
inline

Constructor.

Parameters
nthe maximum size of the buffer

Definition at line 58 of file circular_buffer.h.

◆ CircularBuffer() [2/2]

template<typename Type >
fawkes::CircularBuffer< Type >::CircularBuffer ( const CircularBuffer< Type > &  other)
inline

Copy constructor.

Parameters
otherCircularBuffer to copy

Definition at line 65 of file circular_buffer.h.

◆ ~CircularBuffer()

template<typename Type >
fawkes::CircularBuffer< Type >::~CircularBuffer ( )
inline

Destructor.

Definition at line 71 of file circular_buffer.h.

Member Function Documentation

◆ at()

template<typename Type >
const Type& fawkes::CircularBuffer< Type >::at ( size_type  n) const
inline

Element access.

Parameters
nposition of the element
Returns
reference to the n-th element

Definition at line 140 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_.

◆ back()

template<typename Type >
const Type& fawkes::CircularBuffer< Type >::back ( ) const
inline

Access the last element in the buffer.

Returns
reference to the last element

Definition at line 158 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_.

◆ begin()

template<typename Type >
const_iterator fawkes::CircularBuffer< Type >::begin ( ) const
inline

Get iterator to the beginning.

Returns
iterator

Definition at line 167 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_.

◆ end()

template<typename Type >
const_iterator fawkes::CircularBuffer< Type >::end ( ) const
inline

Get iterator to the end.

Returns
iterator

Definition at line 176 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_.

◆ front()

template<typename Type >
const Type& fawkes::CircularBuffer< Type >::front ( ) const
inline

Access the first element in the buffer.

Returns
reference to the first element

Definition at line 149 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_.

◆ get_deque()

template<typename Type >
std::deque<Type> fawkes::CircularBuffer< Type >::get_deque ( ) const
inline

Get the deque used to store the elements.

Returns
the deque

Definition at line 120 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_.

Referenced by fawkes::CircularBuffer< Type >::operator=().

◆ get_max_size()

template<typename Type >
size_type fawkes::CircularBuffer< Type >::get_max_size ( ) const
inline

Get the maximum size of the buffer.

Returns
the maximum size

Definition at line 111 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::max_size_.

Referenced by fawkes::CircularBuffer< Type >::operator=().

◆ operator=()

template<typename Type >
CircularBuffer<Type>& fawkes::CircularBuffer< Type >::operator= ( const CircularBuffer< Type > &  other)
inline

Assignment operator.

Parameters
otherCircularBuffer to copy
Returns
reference to this instance

Definition at line 80 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_, fawkes::CircularBuffer< Type >::get_deque(), fawkes::CircularBuffer< Type >::get_max_size(), and fawkes::CircularBuffer< Type >::max_size_.

◆ operator[]()

template<typename Type >
const Type& fawkes::CircularBuffer< Type >::operator[] ( size_type  n) const
inline

Element access.

Parameters
nposition of the element
Returns
reference to the n-th element

Definition at line 130 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_.

◆ pop_front()

template<typename Type >
void fawkes::CircularBuffer< Type >::pop_front ( )
inline

Delete the first element.

Definition at line 102 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_.

◆ push_back()

template<typename Type >
void fawkes::CircularBuffer< Type >::push_back ( const Type &  val)
inline

Insert an element at the end of the buffer and delete the first element if necessary.

Parameters
valthe value to insert

Definition at line 92 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_, and fawkes::CircularBuffer< Type >::max_size_.

Referenced by fawkes::SyncPoint::wait().

◆ rbegin()

template<typename Type >
const_reverse_iterator fawkes::CircularBuffer< Type >::rbegin ( ) const
inline

Get reverse iterator to the beginning.

Returns
iterator

Definition at line 185 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_.

◆ rend()

template<typename Type >
const_reverse_iterator fawkes::CircularBuffer< Type >::rend ( ) const
inline

Get reverse iterator to the end.

Returns
iterator

Definition at line 194 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_.

◆ size()

template<typename Type >
size_type fawkes::CircularBuffer< Type >::size ( ) const
inline

Get actual size of the buffer.

Returns
number of elements in the buffer

Definition at line 203 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::deque_.

Member Data Documentation

◆ deque_

◆ max_size_

template<typename Type >
size_type fawkes::CircularBuffer< Type >::max_size_
protected

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