Nebula
Loading...
Searching...
No Matches
Util::RingBuffer< TYPE > Class Template Reference

#include <ringbuffer.h>

Detailed Description

template<class TYPE>
class Util::RingBuffer< TYPE >

A ring buffer stores up to a maximum number of elements in a circular fashion.

If the buffer is full, the newest element overwrites the oldest element.

Public Member Functions

 RingBuffer ()
 default constructor
 RingBuffer (SizeT capacity)
 constructor with size
 RingBuffer (const RingBuffer< TYPE > &rhs)
 copy constructor
 RingBuffer (RingBuffer< TYPE > &&rhs)
 move constructor
 ~RingBuffer ()
 destructor
void operator= (const RingBuffer< TYPE > &rhs)
 assignment operator
void operator= (RingBuffer< TYPE > &&rhs)
 mover operator
TYPE & operator[] (IndexT index) const
 index operator
void SetCapacity (SizeT newCapacity)
 set capacity (clear previous content)
SizeT Capacity () const
 get capacity
SizeT Size () const
 get number of elements in ring buffer
void Add (const TYPE &elm)
 add an element to the ring buffer
bool IsEmpty () const
 return true if ring buffer is empty
void Reset ()
 reset ring buffer, just reset the head/base indices without calling destructors
TYPE & Front () const
 return reference to first element
TYPE & Back () const
 return reference to last element
Array< TYPE > AsArray () const
 return all values as array
TYPE * GetBuffer ()
 get real linear underlying buffer
const TYPE * GetBuffer () const
 get real linear underlying buffer

Private Member Functions

void Allocate (SizeT capacity)
 allocate element buffer
void Delete ()
 delete content
void Copy (const RingBuffer< TYPE > &src)
 copy content

Private Attributes

SizeT capacity
SizeT size
IndexT baseIndex
IndexT headIndex
TYPE * elements

Constructor & Destructor Documentation

◆ RingBuffer() [1/4]

template<class TYPE>
Util::RingBuffer< TYPE >::RingBuffer ( )

default constructor

◆ RingBuffer() [2/4]

template<class TYPE>
Util::RingBuffer< TYPE >::RingBuffer ( SizeT capacity)

constructor with size

◆ RingBuffer() [3/4]

template<class TYPE>
Util::RingBuffer< TYPE >::RingBuffer ( const RingBuffer< TYPE > & rhs)

copy constructor

◆ RingBuffer() [4/4]

template<class TYPE>
Util::RingBuffer< TYPE >::RingBuffer ( RingBuffer< TYPE > && rhs)

move constructor

◆ ~RingBuffer()

template<class TYPE>
Util::RingBuffer< TYPE >::~RingBuffer ( )

destructor

Member Function Documentation

◆ Add()

template<class TYPE>
void Util::RingBuffer< TYPE >::Add ( const TYPE & elm)

add an element to the ring buffer

◆ Allocate()

template<class TYPE>
void Util::RingBuffer< TYPE >::Allocate ( SizeT capacity)
private

allocate element buffer

◆ AsArray()

template<class TYPE>
Array< TYPE > Util::RingBuffer< TYPE >::AsArray ( ) const

return all values as array

◆ Back()

template<class TYPE>
TYPE & Util::RingBuffer< TYPE >::Back ( ) const

return reference to last element

◆ Capacity()

template<class TYPE>
SizeT Util::RingBuffer< TYPE >::Capacity ( ) const

get capacity

◆ Copy()

template<class TYPE>
void Util::RingBuffer< TYPE >::Copy ( const RingBuffer< TYPE > & src)
private

copy content

◆ Delete()

template<class TYPE>
void Util::RingBuffer< TYPE >::Delete ( )
private

delete content

◆ Front()

template<class TYPE>
TYPE & Util::RingBuffer< TYPE >::Front ( ) const

return reference to first element

◆ GetBuffer() [1/2]

template<class TYPE>
TYPE * Util::RingBuffer< TYPE >::GetBuffer ( )

get real linear underlying buffer

◆ GetBuffer() [2/2]

template<class TYPE>
const TYPE * Util::RingBuffer< TYPE >::GetBuffer ( ) const

get real linear underlying buffer

◆ IsEmpty()

template<class TYPE>
bool Util::RingBuffer< TYPE >::IsEmpty ( ) const

return true if ring buffer is empty

◆ operator=() [1/2]

template<class TYPE>
void Util::RingBuffer< TYPE >::operator= ( const RingBuffer< TYPE > & rhs)

assignment operator

◆ operator=() [2/2]

template<class TYPE>
void Util::RingBuffer< TYPE >::operator= ( RingBuffer< TYPE > && rhs)

mover operator

◆ operator[]()

template<class TYPE>
TYPE & Util::RingBuffer< TYPE >::operator[] ( IndexT index) const

index operator

◆ Reset()

template<class TYPE>
void Util::RingBuffer< TYPE >::Reset ( )

reset ring buffer, just reset the head/base indices without calling destructors

◆ SetCapacity()

template<class TYPE>
void Util::RingBuffer< TYPE >::SetCapacity ( SizeT newCapacity)

set capacity (clear previous content)

◆ Size()

template<class TYPE>
SizeT Util::RingBuffer< TYPE >::Size ( ) const

get number of elements in ring buffer

Member Data Documentation

◆ baseIndex

template<class TYPE>
IndexT Util::RingBuffer< TYPE >::baseIndex
private

◆ capacity

template<class TYPE>
SizeT Util::RingBuffer< TYPE >::capacity
private

◆ elements

template<class TYPE>
TYPE* Util::RingBuffer< TYPE >::elements
private

◆ headIndex

template<class TYPE>
IndexT Util::RingBuffer< TYPE >::headIndex
private

◆ size

template<class TYPE>
SizeT Util::RingBuffer< TYPE >::size
private

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