RingBuffer< ARRAYTYPE, RINGSIZE > Class Template Reference

#include <ringbuffer.h>

Inheritance diagram for RingBuffer< ARRAYTYPE, RINGSIZE >:

Detailed Description

template<typename ARRAYTYPE, Int RINGSIZE>
class maxon::RingBuffer< ARRAYTYPE, RINGSIZE >

Ring buffer array template. This class implements a ring buffer using your preferred ARRAY type.

Template Parameters
ARRAYTYPEType of the array.
RINGSIZEMaximum number of elements in the ring buffer.

Classes

class  IteratorTemplate
 

Public Types

using T = typename ARRAYTYPE::ValueType
 
using Iterator = IteratorTemplate< false >
 
using ConstIterator = IteratorTemplate< true >
 

Public Member Functions

template<typename... ARGS>
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< TAppend (ARGS &&... args)
 
MAXON_ATTRIBUTE_FORCE_INLINE ResultPtr< TAppend (const std::initializer_list< T > &values)
 
MAXON_ATTRIBUTE_FORCE_INLINE const Toperator[] (Int idx) const
 
MAXON_ATTRIBUTE_FORCE_INLINE Toperator[] (Int idx)
 
MAXON_ATTRIBUTE_FORCE_INLINE const TGetFirst () const
 
MAXON_ATTRIBUTE_FORCE_INLINE TGetFirst ()
 
MAXON_ATTRIBUTE_FORCE_INLINE const TGetLast () const
 
MAXON_ATTRIBUTE_FORCE_INLINE TGetLast ()
 
void Reset ()
 
void Flush ()
 
ConstIterator Begin () const
 
Iterator Begin ()
 
ConstIterator End () const
 
Iterator End ()
 

Private Attributes

Int _ringPos
 

Member Typedef Documentation

◆ T

using T = typename ARRAYTYPE::ValueType

◆ Iterator

using Iterator = IteratorTemplate<false>

◆ ConstIterator

Member Function Documentation

◆ Append() [1/2]

MAXON_ATTRIBUTE_FORCE_INLINE ResultRef<T> Append ( ARGS &&...  args)

Adds a new element at the end of the buffer and moves the content of x to it.

Parameters
[in]argsValues to be forwarded.
Returns
Element reference or OutOfMemoryError if the initial allocation failed.

◆ Append() [2/2]

MAXON_ATTRIBUTE_FORCE_INLINE ResultPtr<T> Append ( const std::initializer_list< T > &  values)

Appends new elements at the end of the array.

Parameters
[in]valuesInitializer list with values to be copied.
Returns
Element pointer or OutOfMemoryError if the allocation failed.

◆ operator[]() [1/2]

MAXON_ATTRIBUTE_FORCE_INLINE const T& operator[] ( Int  idx) const

Array (subscript) operator for non-const objects. Index 0 is the oldest entry.

Parameters
[in]idxElement index (if it's out of bounds you will get an error in debug code only, otherwise it will crash).
Returns
Array element.

◆ operator[]() [2/2]

MAXON_ATTRIBUTE_FORCE_INLINE T& operator[] ( Int  idx)

Array (subscript) operator for non-const objects. Index 0 is the oldest entry.

Parameters
[in]idxElement index (if it's out of bounds you will get an error in debug code only, otherwise it will crash).
Returns
Array element.

◆ GetFirst() [1/2]

MAXON_ATTRIBUTE_FORCE_INLINE const T* GetFirst ( ) const

Returns a pointer to the first element in the ring buffer (which is different from the first element in the array).

Returns
Pointer to the first element (nullptr if the buffer is empty).

◆ GetFirst() [2/2]

Returns a pointer to the first element in the ring buffer (which is different from the first element in the array).

Returns
Pointer to the first element (nullptr if the buffer is empty).

◆ GetLast() [1/2]

MAXON_ATTRIBUTE_FORCE_INLINE const T* GetLast ( ) const

Returns a pointer to the last element in the ring buffer (which is different from the last element in the array).

Returns
Pointer to the last element (nullptr if the buffer is empty).

◆ GetLast() [2/2]

Returns a pointer to the last element in the ring buffer (which is different from the last element in the array).

Returns
Pointer to the last element (nullptr if the buffer is empty).

◆ Reset()

void Reset ( void  )

Deletes all elements (calls destructors and frees memory).

◆ Flush()

void Flush ( void  )

Deletes all elements, but doesn't free memory (calls destructors though).

◆ Begin() [1/2]

ConstIterator Begin ( ) const

Gets an iterator for the first element. When you modify the array Begin() will change, it is not a constant value.

Returns
Iterator for the first element (equal to End() if the array is empty).

◆ Begin() [2/2]

Iterator Begin ( )

Gets an iterator for the first element. When you modify the array Begin() will change, it is not a constant value.

Returns
Iterator for the first element (equal to End() if the array is empty).

◆ End() [1/2]

ConstIterator End ( ) const

Gets an iterator for the end (End() - 1 is the last element if the array is not empty). When you modify the array End() will change, it is not a constant value.

Returns
Iterator for the array end (this is behind the last element).

◆ End() [2/2]

Iterator End ( )

Gets an iterator for the end (End() - 1 is the last element if the array is not empty). When you modify the array End() will change, it is not a constant value.

Returns
Iterator for the array end (this is behind the last element).

Member Data Documentation

◆ _ringPos

Int _ringPos
private