libzed 1.9.9
A general-purpose library for quick and simple data manipulation.
 
Loading...
Searching...
No Matches
z::core::circularBuffer< TYPE, LEN > Class Template Reference

A circular buffer of fixed size. Appending can be done indefinitely, as the index will just loop back around to the beginning. More...

#include <circularBuffer.hpp>

Inheritance diagram for z::core::circularBuffer< TYPE, LEN >:
z::core::sizable z::core::arrayLike< const TYPE &, circularIterator< TYPE, LEN > > z::core::indexable< T > z::core::iterable< ITER >

Public Member Functions

 circularBuffer () noexcept
 Default constructor.
 
template<typename... ARGS>
 circularBuffer (const ARGS &...args) noexcept
 Initialize the buffer with the contents of an array.
 
 circularBuffer (TYPE default_value) noexcept
 Initialize all elements with a single value.
 
size_t size () const noexcept override
 Get the size of the object in memory.
 
int length () const noexcept override
 Get the length of the array.
 
const TYPEat (const int index) const noexcept override
 Get an element from the buffer.
 
TYPEat (const int index) noexcept
 Get a modifiable element from the buffer.
 
void append (const TYPE value) noexcept
 Add a value to the buffer, and increment the current index.
 
int index () const noexcept
 Get the index of the current top of the buffer.
 
TYPEcurrent () noexcept
 Get a reference to the topmost item in the buffer.
 
int count () const noexcept
 Get the total number of items in the buffer.
 
void prev () noexcept
 Move current "top" to the previous spot in the buffer.
 
void next () noexcept
 Move current "top" to the next spot in the buffer.
 
circularIterator< TYPE, LENbegin () const noexcept override
 Get an iterator for the first element in this object.
 
circularIterator< TYPE, LENend () const noexcept override
 Get an iterator after the last element of this object.
 
template<typename... ARGS>
void populate (const TYPE &first, const ARGS &...args) noexcept
 Append an arbitrary number of elements to the buffer.
 
void populate (const TYPE &arg) noexcept
 Append an element to the buffer.
 
TYPE minimum () const noexcept
 Get the minimum value contained in this buffer.
 
TYPE maximum () const noexcept
 Get the maximum value contained in this buffer.
 
- Public Member Functions inherited from z::core::sizable
virtual ~sizable () noexcept
 Virtual destructor.
 
- Public Member Functions inherited from z::core::indexable< T >
virtual ~indexable () noexcept
 Virtual destructor.
 
virtual T operator[] (int index) const
 Function to get the object at the given index.
 
- Public Member Functions inherited from z::core::iterable< ITER >
virtual ~iterable () noexcept
 Virtual destructor.
 

Detailed Description

template<typename TYPE, unsigned int LEN>
class z::core::circularBuffer< TYPE, LEN >

A circular buffer of fixed size. Appending can be done indefinitely, as the index will just loop back around to the beginning.

Constructor & Destructor Documentation

◆ circularBuffer() [1/2]

template<typename TYPE , unsigned int LEN>
template<typename... ARGS>
z::core::circularBuffer< TYPE, LEN >::circularBuffer ( const ARGS &...  args)
inlinenoexcept

Initialize the buffer with the contents of an array.

This allows for brace-enclosed initialization e.g. circularBuffer<int, 3> buffer = {1, 2, 3};

Parameters
argsA list of elements to append to the buffer.

◆ circularBuffer() [2/2]

template<typename TYPE , unsigned int LEN>
z::core::circularBuffer< TYPE, LEN >::circularBuffer ( TYPE  default_value)
inlinenoexcept

Initialize all elements with a single value.

Parameters
default_valueThe value to initialize elements with.

Member Function Documentation

◆ append()

template<typename TYPE , unsigned int LEN>
void z::core::circularBuffer< TYPE, LEN >::append ( const TYPE  value)
inlinenoexcept

Add a value to the buffer, and increment the current index.

Parameters
valueThe value to append.

◆ at() [1/2]

template<typename TYPE , unsigned int LEN>
const TYPE & z::core::circularBuffer< TYPE, LEN >::at ( const int  index) const
inlineoverridevirtualnoexcept

Get an element from the buffer.

This method is used when we're not modifying the resultant value.

Parameters
indexThe index of the value we want.
Returns
The value at that index.

Implements z::core::indexable< T >.

◆ at() [2/2]

template<typename TYPE , unsigned int LEN>
TYPE & z::core::circularBuffer< TYPE, LEN >::at ( const int  index)
inlinenoexcept

Get a modifiable element from the buffer.

This method is used when we ARE modifying the resultant value. The compiler knows the difference and will use this function only when needed.

Parameters
indexThe index of the value we want.
Returns
The value at that index.

◆ begin()

template<typename TYPE , unsigned int LEN>
circularIterator< TYPE, LEN > z::core::circularBuffer< TYPE, LEN >::begin ( ) const
inlineoverridevirtualnoexcept

Get an iterator for the first element in this object.

This member function should not be used directly. It is meant for C++11's range-based for loop syntax.

Returns
An iterator on the first element.

Implements z::core::iterable< ITER >.

◆ count()

template<typename TYPE , unsigned int LEN>
int z::core::circularBuffer< TYPE, LEN >::count ( ) const
inlinenoexcept

Get the total number of items in the buffer.

This will return at most the maximum buffer size.

Returns
The number of items in the buffer.

◆ current()

template<typename TYPE , unsigned int LEN>
TYPE & z::core::circularBuffer< TYPE, LEN >::current ( )
inlinenoexcept

Get a reference to the topmost item in the buffer.

Returns
The topmost item.

◆ end()

template<typename TYPE , unsigned int LEN>
circularIterator< TYPE, LEN > z::core::circularBuffer< TYPE, LEN >::end ( ) const
inlineoverridevirtualnoexcept

Get an iterator after the last element of this object.

This member function should not be used directly. It is meant for C++11's range-based for loop syntax.

Returns
An iterator after the last element.

Implements z::core::iterable< ITER >.

◆ index()

template<typename TYPE , unsigned int LEN>
int z::core::circularBuffer< TYPE, LEN >::index ( ) const
inlinenoexcept

Get the index of the current top of the buffer.

This index will always be a value from 0 to the length of the buffer.

Returns
The current index.

◆ length()

template<typename TYPE , unsigned int LEN>
int z::core::circularBuffer< TYPE, LEN >::length ( ) const
inlineoverridevirtualnoexcept

Get the length of the array.

Returns
The number of objects in the array.

Implements z::core::arrayLike< const TYPE &, circularIterator< TYPE, LEN > >.

◆ maximum()

template<typename TYPE , unsigned int LEN>
TYPE z::core::circularBuffer< TYPE, LEN >::maximum ( ) const
inlinenoexcept

Get the maximum value contained in this buffer.

Note
This method is only available for arithmetic types.
Returns
The maximum value in the buffer.

◆ minimum()

template<typename TYPE , unsigned int LEN>
TYPE z::core::circularBuffer< TYPE, LEN >::minimum ( ) const
inlinenoexcept

Get the minimum value contained in this buffer.

Note
This method is only available for arithmetic types.
Returns
The minimum value in the buffer.

◆ populate() [1/2]

template<typename TYPE , unsigned int LEN>
void z::core::circularBuffer< TYPE, LEN >::populate ( const TYPE arg)
inlinenoexcept

Append an element to the buffer.

This is the tail end of calling populate() with 2 or more arguments.

Parameters
argThe element to append.

◆ populate() [2/2]

template<typename TYPE , unsigned int LEN>
template<typename... ARGS>
void z::core::circularBuffer< TYPE, LEN >::populate ( const TYPE first,
const ARGS &...  args 
)
inlinenoexcept

Append an arbitrary number of elements to the buffer.

Parameters
firstThe first element to append.
argsAll other elements to append.

◆ size()

template<typename TYPE , unsigned int LEN>
size_t z::core::circularBuffer< TYPE, LEN >::size ( ) const
inlineoverridevirtualnoexcept

Get the size of the object in memory.

Returns
The number of bytes in memory this object currently consumes.

Implements z::core::sizable.


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