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().
◆ ValueType
The template parameter value type.
◆ RingBuffer() [1/3]
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]
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]
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()
Get the ringbuffer's capacity.
- Returns
- The number of available items in the ringbuffer.
◆ SetCapacity()
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()
Check if the ringbuffer is operating in overwrite mode.
See SetOverwrite().
- Returns
- true if the ringbuffer is operating in overwrite mode.
◆ SetOverwrite()
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()
Get the number of used items in the ringbuffer.
- Returns
- The number of used items in the ringbuffer.
◆ Clear()
Clear the ringbuffer.
All items are initialized using the value type's default constructor.
◆ IsEmpty()
Check if the ringbuffer is empty.
- Returns
- true if the ringbuffer is empty.
◆ IsFull()
Check if the ringbuffer is full.
- Returns
- true if the ringbuffer is full.
◆ Add()
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]
Retrieve the first used item from the ringbuffer.
- Returns
- A reference to the item.
◆ Get() [2/2]
Retrieve the first used item from the ringbuffer.
- Returns
- A const reference to the item.
◆ operator[]() [1/2]
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]
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()
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: