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

Circular buffer with a fixed size. More...

#include <>>

Public Types

typedef 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 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...
 
virtual ~CircularBuffer ()
 Destructor. More...
 
virtual void push_back (const Type &val)
 Insert an element at the end of the buffer and delete the first element if necessary. More...
 
virtual void pop_front ()
 Delete the first element. More...
 
virtual size_type get_max_size () const
 Get the maximum size of the buffer. More...
 
virtual std::deque< Type > get_deque () const
 Get the deque used to store the elements. More...
 
virtual const Type & operator[] (size_type n) const
 Element access. More...
 
virtual const Type & at (size_type n) const
 Element access. More...
 
virtual const Type & front () const
 Access the first element in the buffer. More...
 
virtual const Type & back () const
 Access the last element in the buffer. More...
 
virtual const_iterator begin () const
 Get iterator to the beginning. More...
 
virtual const_iterator end () const
 Get iterator to the end. More...
 
virtual 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 51 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 53 of file circular_buffer.h.

◆ size_type

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

The size_type of the buffer.

Definition at line 49 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 57 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>
virtual fawkes::CircularBuffer< Type >::~CircularBuffer ( )
inlinevirtual

Destructor.

Definition at line 71 of file circular_buffer.h.

Member Function Documentation

◆ at()

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

Element access.

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

Definition at line 121 of file circular_buffer.h.

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

◆ back()

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

Access the last element in the buffer.

Returns
reference to the last element

Definition at line 137 of file circular_buffer.h.

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

◆ begin()

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

Get iterator to the beginning.

Returns
iterator

Definition at line 145 of file circular_buffer.h.

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

◆ end()

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

Get iterator to the end.

Returns
iterator

Definition at line 153 of file circular_buffer.h.

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

◆ front()

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

Access the first element in the buffer.

Returns
reference to the first element

Definition at line 129 of file circular_buffer.h.

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

◆ get_deque()

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

Get the deque used to store the elements.

Returns
the deque

Definition at line 103 of file circular_buffer.h.

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

◆ get_max_size()

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

Get the maximum size of the buffer.

Returns
the maximum size

Definition at line 95 of file circular_buffer.h.

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

◆ operator[]()

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

Element access.

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

Definition at line 112 of file circular_buffer.h.

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

◆ pop_front()

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

Delete the first element.

Definition at line 87 of file circular_buffer.h.

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

◆ push_back()

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

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

Parameters
valthe value to insert

Definition at line 78 of file circular_buffer.h.

References fawkes::CircularBuffer< Type >::__deque, and fawkes::CircularBuffer< Type >::__max_size.

◆ size()

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

Get actual size of the buffer.

Returns
number of elements in the buffer

Definition at line 161 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 maximum size of the circular buffer.

Definition at line 170 of file circular_buffer.h.

Referenced by fawkes::CircularBuffer< Type >::get_max_size(), and fawkes::CircularBuffer< Type >::push_back().


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