stmm-games-doc  0.32.0
Public Member Functions | List of all members
stmg::CircularBuffer< T > Class Template Reference
Inheritance diagram for stmg::CircularBuffer< T >:
Inheritance graph
[legend]

Public Member Functions

 CircularBuffer (int32_t nSize) noexcept
 Constructor. More...
 
int32_t capacity () const noexcept
 The (fixed) capacity of the buffer. More...
 
void clear () noexcept
 Clears the buffer. More...
 
bool isEmpty () const noexcept
 Whether the buffer is empty. More...
 
bool isFull () const noexcept
 Whether the buffer is full. More...
 
read () noexcept
 Remove a value from the fifo buffer. More...
 
void write (const T &oT) noexcept
 Add a value to the buffer. More...
 
void write (T &&oT) noexcept
 Add a value to the buffer. More...
 
int32_t size () const noexcept
 Total number of buffered values. More...
 
const T & peekValue (int32_t nIdx) const noexcept
 Peek the buffered value. More...
 
T & peekValue (int32_t nIdx) noexcept
 Peek the buffered value. More...
 

Constructor & Destructor Documentation

◆ CircularBuffer()

template<class T >
stmg::CircularBuffer< T >::CircularBuffer ( int32_t  nSize)
noexcept

Constructor.

Parameters
nSizeThe capacity of the buffer. Must be positive.

Member Function Documentation

◆ capacity()

template<class T >
int32_t stmg::CircularBuffer< T >::capacity ( ) const
inlinenoexcept

The (fixed) capacity of the buffer.

Returns
The capacity of the buffer.

◆ clear()

template<class T >
void stmg::CircularBuffer< T >::clear ( )
inlinenoexcept

Clears the buffer.

Removes all its values.

◆ isEmpty()

template<class T >
bool stmg::CircularBuffer< T >::isEmpty ( ) const
inlinenoexcept

Whether the buffer is empty.

Shortcut for (size() == 0).

Returns
Whether the buffer is empty.

◆ isFull()

template<class T >
bool stmg::CircularBuffer< T >::isFull ( ) const
inlinenoexcept

Whether the buffer is full.

Shortcut for (size() == capacity()).

Returns
Whether buffer is full.

◆ peekValue() [1/2]

template<class T >
const T & stmg::CircularBuffer< T >::peekValue ( int32_t  nIdx) const
noexcept

Peek the buffered value.

Index 0 corresponds to the value that would be returned by a call to read().

Parameters
nIdxThe index. Must be >= 0 and < size().
Returns
The buffered value.

◆ peekValue() [2/2]

template<class T >
T & stmg::CircularBuffer< T >::peekValue ( int32_t  nIdx)
noexcept

Peek the buffered value.

Index 0 corresponds to the value that would be returned by a call to read().

Parameters
nIdxThe index. Must be >= 0 and < size().
Returns
The buffered value.

◆ read()

template<class T >
T stmg::CircularBuffer< T >::read ( )
noexcept

Remove a value from the fifo buffer.

The buffer must not be empty.

Returns
The read value.

◆ size()

template<class T >
int32_t stmg::CircularBuffer< T >::size ( ) const
inlinenoexcept

Total number of buffered values.

Returns
Number of stored values. Always <= capacity().

◆ write() [1/2]

template<class T>
void stmg::CircularBuffer< T >::write ( const T &  oT)
noexcept

Add a value to the buffer.

The buffer must not be full.

Parameters
oTThe value to add.

◆ write() [2/2]

template<class T>
void stmg::CircularBuffer< T >::write ( T &&  oT)
noexcept

Add a value to the buffer.

The buffer must not be full.

Parameters
oTThe value to add.