Menu

object::RingBuffer< T, N > Class Template Reference

Ring buffer (constant size). More...

#include <RingBuffer.h>

Inheritance diagram for object::RingBuffer< T, N >:
famouso::mw::afp::defrag::detail::Queue< T, N >

Public Types

typedef
SmallestUnsignedTypeSelector
< N >::type 
SizeT
 Type used for internal indexing.

Public Member Functions

 RingBuffer ()
 Constructor.
SizeT get_count () const
 Returns current count of elements.
bool is_empty () const
 Returns true if there are no elements inside.
bool is_full () const
 Returns true if no more elements can be added.
T & front ()
 Returns reference to the first element.
const T & front () const
 Returns reference to the first element.
T & back ()
 Returns reference to the last element.
const T & back () const
 Returns reference to the last element.
T & operator[] (SizeT i)
 Returns reference to element i.
const T & operator[] (SizeT i) const
 Returns reference to element i.
void push_front (const T &obj)
 Adds an element in front of the first one.
void push_back (const T &obj)
 Adds an element behind the last one.
void pop_front ()
 Removes the first element.
void pop_back ()
 Removes the last element.

Protected Types

typedef
ExpandedRangeTypeSelector
< SizeT >::type 
DoubleSizeT
 Type with larger range than SizeT to handle overflows.

Protected Member Functions

SizeT get_idx (SizeT num) const
 Get index of element.
void increment_first ()
 Increments first.
void decrement_first ()
 Decrements first.
SizeT get_last () const
 Return index of last element.
SizeT get_behind_last () const
 Return index of element behind last element.
SizeT get_infront_first () const
 Return index of element in front of first element.

Protected Attributes

buffer [N]
 Array containing elements
SizeT first
 Array index of first element (always < N)
SizeT count
 Number of elements currently used (always <= N).

Detailed Description

template<class T, unsigned int N>
class object::RingBuffer< T, N >

Ring buffer (constant size).

Template Parameters:
T Type of elements
N Maximum count of elements
Author:
Philipp Werner

Member Typedef Documentation

template<class T, unsigned int N>
typedef ExpandedRangeTypeSelector<SizeT>::type object::RingBuffer< T, N >::DoubleSizeT [protected]

Type with larger range than SizeT to handle overflows.

template<class T, unsigned int N>
typedef SmallestUnsignedTypeSelector<N>::type object::RingBuffer< T, N >::SizeT

Type used for internal indexing.


Constructor & Destructor Documentation

template<class T, unsigned int N>
object::RingBuffer< T, N >::RingBuffer (  )  [inline]

Constructor.


Member Function Documentation

template<class T, unsigned int N>
const T& object::RingBuffer< T, N >::back (  )  const [inline]

Returns reference to the last element.

Precondition:
is_empty() returns false
template<class T, unsigned int N>
T& object::RingBuffer< T, N >::back (  )  [inline]

Returns reference to the last element.

Precondition:
is_empty() returns false
template<class T, unsigned int N>
void object::RingBuffer< T, N >::decrement_first (  )  [inline, protected]
template<class T, unsigned int N>
const T& object::RingBuffer< T, N >::front (  )  const [inline]

Returns reference to the first element.

Precondition:
is_empty() returns false
template<class T, unsigned int N>
T& object::RingBuffer< T, N >::front (  )  [inline]

Returns reference to the first element.

Precondition:
is_empty() returns false
template<class T, unsigned int N>
SizeT object::RingBuffer< T, N >::get_behind_last (  )  const [inline, protected]

Return index of element behind last element.

Referenced by object::RingBuffer< Event< KeyType > *, N >::push_back().

template<class T, unsigned int N>
SizeT object::RingBuffer< T, N >::get_count (  )  const [inline]

Returns current count of elements.

template<class T, unsigned int N>
SizeT object::RingBuffer< T, N >::get_idx ( SizeT  num  )  const [inline, protected]

Get index of element.

Parameters:
num Number of element behind first (first = 0, last = count-1) Must be smaller than N.
Returns:
Index of element in buffer

Referenced by object::RingBuffer< Event< KeyType > *, N >::get_behind_last(), object::RingBuffer< Event< KeyType > *, N >::get_infront_first(), object::RingBuffer< Event< KeyType > *, N >::get_last(), and object::RingBuffer< Event< KeyType > *, N >::operator[]().

template<class T, unsigned int N>
SizeT object::RingBuffer< T, N >::get_infront_first (  )  const [inline, protected]

Return index of element in front of first element.

Referenced by object::RingBuffer< Event< KeyType > *, N >::push_front().

template<class T, unsigned int N>
SizeT object::RingBuffer< T, N >::get_last (  )  const [inline, protected]

Return index of last element.

Referenced by object::RingBuffer< Event< KeyType > *, N >::back().

template<class T, unsigned int N>
void object::RingBuffer< T, N >::increment_first (  )  [inline, protected]
template<class T, unsigned int N>
bool object::RingBuffer< T, N >::is_full (  )  const [inline]
template<class T, unsigned int N>
const T& object::RingBuffer< T, N >::operator[] ( SizeT  i  )  const [inline]

Returns reference to element i.

Parameters:
i Index of element. Zero for the first element, count-1 for the last.
template<class T, unsigned int N>
T& object::RingBuffer< T, N >::operator[] ( SizeT  i  )  [inline]

Returns reference to element i.

Parameters:
i Index of element. Zero for the first element, count-1 for the last.
template<class T, unsigned int N>
void object::RingBuffer< T, N >::pop_back (  )  [inline]

Removes the last element.

Precondition:
is_empty() returns false
template<class T, unsigned int N>
void object::RingBuffer< T, N >::pop_front (  )  [inline]
template<class T, unsigned int N>
void object::RingBuffer< T, N >::push_back ( const T &  obj  )  [inline]

Adds an element behind the last one.

Parameters:
obj Object to insert
Precondition:
is_full() returns false

Referenced by famouso::mw::afp::defrag::detail::Queue< T, dynamic >::push(), and famouso::mw::afp::defrag::detail::Queue< Event< KeyType > *, DCP::old_event_ids >::push().

template<class T, unsigned int N>
void object::RingBuffer< T, N >::push_front ( const T &  obj  )  [inline]

Adds an element in front of the first one.

Parameters:
obj Object to insert
Precondition:
is_full() returns false

Field Documentation


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