Allolib  1.0
C++ Components For Interactive Multimedia
al::RingBuffer< T, Alloc > Class Template Reference

Ring buffer. More...

#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/types/al_Buffer.hpp>

Inheritance diagram for al::RingBuffer< T, Alloc >:

Public Member Functions

 RingBuffer ()
 Default constructor; does not allocate memory.
 
 RingBuffer (unsigned size, const T &v=T())
 
size_t size () const
 Get number of elements.
 
int pos () const
 Get absolute index of most recently written element.
 
int fill () const
 Get fill amount of buffer.
 
T & operator[] (int i)
 Get element at absolute index.
 
const T & operator[] (int i) const
 Get element at absolute index (read-only)
 
T & next ()
 Obtain next element in buffer. More...
 
void write (const T &v)
 Write new element.
 
T & read (int i)
 Get reference to element relative to newest element.
 
const T & read (int i) const
 Get reference to element relative to newest element (read-only)
 
const T & readFrom (int from, int dist) const
 Get reference to older element relative to some newer element (read-only) More...
 
T & newest ()
 
const T & newest () const
 
void reset ()
 Set write position to start of array and zero fill amount.
 
void resize (int n, const T &v=T())
 Resize buffer. More...
 

Static Protected Member Functions

static int wrapOnce (int v, int max)
 

Protected Attributes

std::vector< T, Alloc > mElems
 
int mPos
 
int mFill
 
elements
 STL member.
 

Detailed Description

template<class T, class Alloc = std::allocator<T>>
class al::RingBuffer< T, Alloc >

Ring buffer.

This buffer allows potentially large amounts of data to be buffered without moving memory. This is accomplished by use of a moving write tap.

Definition at line 195 of file al_Buffer.hpp.

Constructor & Destructor Documentation

◆ RingBuffer()

template<class T , class Alloc = std::allocator<T>>
al::RingBuffer< T, Alloc >::RingBuffer ( unsigned  size,
const T &  v = T() 
)
inlineexplicit
Parameters
[in]sizenumber of elements
[in]vvalue to initialize elements to

Definition at line 202 of file al_Buffer.hpp.

Member Function Documentation

◆ newest() [1/2]

template<class T , class Alloc = std::allocator<T>>
T& al::RingBuffer< T, Alloc >::newest ( )
inline
Returns
reference to newest element

Definition at line 256 of file al_Buffer.hpp.

◆ newest() [2/2]

template<class T , class Alloc = std::allocator<T>>
const T& al::RingBuffer< T, Alloc >::newest ( ) const
inline
Returns
reference to newest element (read-only)

Definition at line 259 of file al_Buffer.hpp.

◆ next()

template<class T , class Alloc = std::allocator<T>>
T& al::RingBuffer< T, Alloc >::next ( )
inline

Obtain next element in buffer.

This method returns a reference to the next available element in the buffer. This is an alternative to calling write() that does not require constructing a new object, but instead returns the oldest element in the buffer. The returned reference should be assumed to be in an unknown state, thus should be initialized properly.

Definition at line 228 of file al_Buffer.hpp.

◆ readFrom()

template<class T , class Alloc = std::allocator<T>>
const T& al::RingBuffer< T, Alloc >::readFrom ( int  from,
int  dist 
) const
inline

Get reference to older element relative to some newer element (read-only)

Parameters
[in]fromabsolute index the read is relative to
[in]distdistance into past relative to 'from' of the returned element

Definition at line 251 of file al_Buffer.hpp.

◆ resize()

template<class T , class Alloc = std::allocator<T>>
void al::RingBuffer< T, Alloc >::resize ( int  n,
const T &  v = T() 
)
inline

Resize buffer.

Parameters
[in]nnumber of elements
[in]vinitialization value of newly allocated elements

Definition at line 271 of file al_Buffer.hpp.


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