A ringbuffer template class. More...
#include "murl_ring_buffer.h"
Public Types | |
using | ValueType = DataType |
The template parameter value type. | |
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().
Constructor & Destructor Documentation
◆ RingBuffer() [1/3]
|
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]
|
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
-
count The number of available items in the ringbuffer.
References Murl::RingBuffer< DataType >::SetCapacity().
◆ RingBuffer() [3/3]
|
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
-
count The number of available items in the ringbuffer. overwrite If true Add() overwrites the first item, if false Add() returns false.
References Murl::RingBuffer< DataType >::SetCapacity().
Member Function Documentation
◆ GetCapacity()
|
inline |
Get the ringbuffer's capacity.
- Returns
- The number of available items in the ringbuffer.
◆ SetCapacity()
|
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
-
count The number of available items in the ringbuffer.
References Murl::RingBuffer< DataType >::Clear().
Referenced by Murl::RingBuffer< DataType >::RingBuffer().
◆ IsOverwrite()
|
inline |
Check if the ringbuffer is operating in overwrite mode.
See SetOverwrite().
- Returns
- true if the ringbuffer is operating in overwrite mode.
◆ SetOverwrite()
|
inline |
◆ GetCount()
|
inline |
Get the number of used items in the ringbuffer.
- Returns
- The number of used items in the ringbuffer.
◆ Clear()
|
inline |
Clear the ringbuffer.
All items are initialized using the value type's default constructor.
References Murl::RingBuffer< DataType >::IsEmpty().
Referenced by Murl::RingBuffer< DataType >::SetCapacity().
◆ IsEmpty()
|
inline |
Check if the ringbuffer is empty.
- Returns
- true if the ringbuffer is empty.
Referenced by Murl::RingBuffer< DataType >::Clear(), and Murl::RingBuffer< DataType >::Remove().
◆ IsFull()
|
inline |
Check if the ringbuffer is full.
- Returns
- true if the ringbuffer is full.
Referenced by Murl::RingBuffer< DataType >::Add().
◆ Add()
|
inline |
Add a used item at the end of the ringbuffer.
The item entry is initialized using the given item's copy constructor.
- Parameters
-
item The 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.
References Murl::RingBuffer< DataType >::IsFull().
◆ Get() [1/2]
|
inline |
Retrieve the first used item from the ringbuffer.
- Returns
- A reference to the item.
◆ Get() [2/2]
|
inline |
Retrieve the first used item from the ringbuffer.
- Returns
- A const reference to the item.
◆ operator[]() [1/2]
|
inline |
Retrieve an item at a given position from the ringbuffer.
A valid index is [0 .. GetCount()].
- Parameters
-
index The zero-based index of the item to retrieve.
- Returns
- A reference to the specified item.
◆ operator[]() [2/2]
|
inline |
Retrieve an item at a given position from the ringbuffer.
A valid index is [0 .. GetCount()].
- Parameters
-
index The zero-based index of the item to retrieve.
- Returns
- A const reference to the specified item.
◆ Remove()
|
inline |
Remove the first used item from the ringbuffer.
The item is initialized using the value type's default constructor.
References Murl::RingBuffer< DataType >::IsEmpty().
The documentation for this class was generated from the following file:
- murl_ring_buffer.h