A ringbuffer template class.
More...
#include <murl_ring_buffer.h>
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().
|
using | ValueType = DataType |
| The template parameter value type.
|
|
◆ RingBuffer() [1/3]
template<class DataType >
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 >
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. |
◆ RingBuffer() [3/3]
template<class DataType >
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. |
◆ GetCapacity()
template<class DataType >
Get the ringbuffer's capacity.
- Returns
- The number of available items in the ringbuffer.
◆ SetCapacity()
template<class DataType >
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. |
◆ IsOverwrite()
template<class DataType >
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 >
Set the ringbuffer overwrite operation mode.
Set the behaviour of the Add() operation if the ringbuffer IsFull().
- Parameters
-
overwrite | If true Add() overwrites the first item, if false Add() returns false. |
◆ GetCount()
template<class DataType >
Get the number of used items in the ringbuffer.
- Returns
- The number of used items in the ringbuffer.
◆ Clear()
template<class DataType >
Clear the ringbuffer.
All items are initialized using the value type's default constructor.
◆ IsEmpty()
template<class DataType >
Check if the ringbuffer is empty.
- Returns
- true if the ringbuffer is empty.
◆ IsFull()
template<class DataType >
Check if the ringbuffer is full.
- Returns
- true if the ringbuffer is full.
◆ Add()
template<class DataType >
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.
◆ Get() [1/2]
template<class DataType >
Retrieve the first used item from the ringbuffer.
- Returns
- A reference to the item.
◆ Get() [2/2]
template<class DataType >
Retrieve the first used item from the ringbuffer.
- Returns
- A const reference to the item.
◆ operator[]() [1/2]
template<class DataType >
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]
template<class DataType >
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()
template<class DataType >
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: