Murl::RingBuffer< DataType > Class Template Reference

A ringbuffer template class. More...

#include "murl_ring_buffer.h"

Public Types

typedef DataType ValueType
 The template parameter value type. More...
 

Public Member Functions

 RingBuffer ()
 The default constructor. More...
 
 RingBuffer (UInt32 count)
 Constructor taking a capacity. More...
 
 RingBuffer (UInt32 count, Bool overwrite)
 Constructor taking a capacity and overwrite mode. More...
 
UInt32 GetCapacity () const
 Get the ringbuffer's capacity. More...
 
void SetCapacity (UInt32 count)
 Set the ringbuffer's capacity. More...
 
Bool IsOverwrite () const
 Check if the ringbuffer is operating in overwrite mode. More...
 
void SetOverwrite (Bool overwrite)
 Set the ringbuffer overwrite operation mode. More...
 
UInt32 GetCount () const
 Get the number of used items in the ringbuffer. More...
 
void Clear ()
 Clear the ringbuffer. More...
 
Bool IsEmpty () const
 Check if the ringbuffer is empty. More...
 
Bool IsFull () const
 Check if the ringbuffer is full. More...
 
Bool Add (const DataType &item)
 Add a used item at the end of the ringbuffer. More...
 
DataType & Get ()
 Retrieve the first used item from the ringbuffer. More...
 
const DataType & Get () const
 Retrieve the first used item from the ringbuffer. More...
 
DataType & operator[] (SInt32 index)
 Retrieve an item at a given position from the ringbuffer. More...
 
const DataType & operator[] (SInt32 index) const
 Retrieve an item at a given position from the ringbuffer. More...
 
void Remove ()
 Remove the first used item from the ringbuffer. More...
 

Detailed Description

template<class DataType>
class Murl::RingBuffer< DataType >

A ringbuffer template class.

The RingBuffer template provides simple ringbuffer functionality including the option to overwrite the first item or to skip adding if the ringbuffer is full.

The ringbuffer holds a fixed array of default items which are replaced by used items when calling Add(). Used items can be requested by calling GetCount(), Get() or using the array operator[](). Used items can be removed (replaced by default items) by calling Remove().

Member Typedef Documentation

◆ ValueType

template<class DataType>
typedef DataType Murl::RingBuffer< DataType >::ValueType

The template parameter value type.

Constructor & Destructor Documentation

◆ RingBuffer() [1/3]

template<class DataType>
Murl::RingBuffer< DataType >::RingBuffer ( )
inline

The default constructor.

Create an empty ringbuffer with capacity 10 and overwrite mode off. All items are initialized using the value type's default constructor.

◆ RingBuffer() [2/3]

template<class DataType>
Murl::RingBuffer< DataType >::RingBuffer ( UInt32  count)
inline

Constructor taking a capacity.

Create an empty ringbuffer with a specified capacity and overwrite mode off. All items are initialized using the value type's default constructor.

Parameters
countThe number of available items in the ringbuffer.

◆ RingBuffer() [3/3]

template<class DataType>
Murl::RingBuffer< DataType >::RingBuffer ( UInt32  count,
Bool  overwrite 
)
inline

Constructor taking a capacity and overwrite mode.

Create an empty ringbuffer with a specified capacity and specified overwrite mode. The overwrite mode specifies the behaviour of the Add() operation if the ringbuffer IsFull(). All items are initialized using the value type's default constructor.

Parameters
countThe number of available items in the ringbuffer.
overwriteIf true Add() overwrites the first item, if false Add() returns false.

Member Function Documentation

◆ GetCapacity()

template<class DataType>
UInt32 Murl::RingBuffer< DataType >::GetCapacity ( ) const
inline

Get the ringbuffer's capacity.

Returns
The number of available items in the ringbuffer.

◆ SetCapacity()

template<class DataType>
void Murl::RingBuffer< DataType >::SetCapacity ( UInt32  count)
inline

Set the ringbuffer's capacity.

If the given capacity is smaller than the current capacity, the ringbuffer is cleared. If the given capacity is higher, new items are initialized via the value type's default constructor. If the given capacity is zero, a capacity of 1 is set.

Parameters
countThe number of available items in the ringbuffer.

Referenced by Murl::RingBuffer< Murl::SharedPointer >::RingBuffer().

◆ IsOverwrite()

template<class DataType>
Bool Murl::RingBuffer< DataType >::IsOverwrite ( ) const
inline

Check if the ringbuffer is operating in overwrite mode.

See SetOverwrite().

Returns
true if the ringbuffer is operating in overwrite mode.

◆ SetOverwrite()

template<class DataType>
void Murl::RingBuffer< DataType >::SetOverwrite ( Bool  overwrite)
inline

Set the ringbuffer overwrite operation mode.

Set the behaviour of the Add() operation if the ringbuffer IsFull().

Parameters
overwriteIf true Add() overwrites the first item, if false Add() returns false.

◆ GetCount()

template<class DataType>
UInt32 Murl::RingBuffer< DataType >::GetCount ( ) const
inline

Get the number of used items in the ringbuffer.

Returns
The number of used items in the ringbuffer.

◆ Clear()

template<class DataType>
void Murl::RingBuffer< DataType >::Clear ( )
inline

Clear the ringbuffer.

All items are initialized using the value type's default constructor.

Referenced by Murl::RingBuffer< Murl::SharedPointer >::SetCapacity().

◆ IsEmpty()

template<class DataType>
Bool Murl::RingBuffer< DataType >::IsEmpty ( ) const
inline

Check if the ringbuffer is empty.

Returns
true if the ringbuffer is empty.

Referenced by Murl::RingBuffer< Murl::SharedPointer >::Clear(), and Murl::RingBuffer< Murl::SharedPointer >::Remove().

◆ IsFull()

template<class DataType>
Bool Murl::RingBuffer< DataType >::IsFull ( ) const
inline

Check if the ringbuffer is full.

Returns
true if the ringbuffer is full.

Referenced by Murl::RingBuffer< Murl::SharedPointer >::Add().

◆ Add()

template<class DataType>
Bool Murl::RingBuffer< DataType >::Add ( const DataType &  item)
inline

Add a used item at the end of the ringbuffer.

The item entry is initialized using the given item's copy constructor.

Parameters
itemThe item to be added at the end of the ringbuffer.
Returns
true if the item was added successful, false if the overwrite mode is off and the ringbuffer is full.

◆ Get() [1/2]

template<class DataType>
DataType& Murl::RingBuffer< DataType >::Get ( )
inline

Retrieve the first used item from the ringbuffer.

Returns
A reference to the item.

◆ Get() [2/2]

template<class DataType>
const DataType& Murl::RingBuffer< DataType >::Get ( ) const
inline

Retrieve the first used item from the ringbuffer.

Returns
A const reference to the item.

◆ operator[]() [1/2]

template<class DataType>
DataType& Murl::RingBuffer< DataType >::operator[] ( SInt32  index)
inline

Retrieve an item at a given position from the ringbuffer.

A valid index is [0 .. GetCount()].

Parameters
indexThe zero-based index of the item to retrieve.
Returns
A reference to the specified item.

◆ operator[]() [2/2]

template<class DataType>
const DataType& Murl::RingBuffer< DataType >::operator[] ( SInt32  index) const
inline

Retrieve an item at a given position from the ringbuffer.

A valid index is [0 .. GetCount()].

Parameters
indexThe zero-based index of the item to retrieve.
Returns
A const reference to the specified item.

◆ Remove()

template<class DataType>
void Murl::RingBuffer< DataType >::Remove ( )
inline

Remove the first used item from the ringbuffer.

The item is initialized using the value type's default constructor.


The documentation for this class was generated from the following file:
  • murl_ring_buffer.h


Copyright © 2011-2018 Spraylight GmbH.