StuBS
BBuffer< T, CAP > Class Template Reference

The class BBuffer implements a bounded buffer, that is a circular buffer with a fixed capacity. More...

#include <object/bbuffer.h>

Public Member Functions

 BBuffer ()
 Constructor that initialized an empty buffer.
 
bool produce (T val)
 Add an element to the buffer.
 
bool consume (T &val)
 Remove an element from the buffer.
 

Private Member Functions

 BBuffer (const BBuffer &)=delete
 
BBufferoperator= (const BBuffer &)=delete
 

Private Attributes

data [CAP]
 
volatile unsigned in
 
volatile unsigned out
 

Detailed Description

template<typename T, unsigned CAP>
class BBuffer< T, CAP >

The class BBuffer implements a bounded buffer, that is a circular buffer with a fixed capacity.

Template Parameters
Tthe type of data to be stored
CAPthe buffers capacity (must be greater than 1)

Constructor & Destructor Documentation

◆ BBuffer() [1/2]

template<typename T , unsigned CAP>
BBuffer< T, CAP >::BBuffer ( const BBuffer< T, CAP > &  )
privatedelete

◆ BBuffer() [2/2]

template<typename T , unsigned CAP>
BBuffer< T, CAP >::BBuffer ( )
inline

Constructor that initialized an empty buffer.

Member Function Documentation

◆ operator=()

template<typename T , unsigned CAP>
BBuffer & BBuffer< T, CAP >::operator= ( const BBuffer< T, CAP > &  )
privatedelete

◆ produce()

template<typename T , unsigned CAP>
bool BBuffer< T, CAP >::produce ( val)
inline

Add an element to the buffer.

Parameters
valThe element to be added.
Returns
false if the buffer is full and no element can be added; true otherwise.

◆ consume()

template<typename T , unsigned CAP>
bool BBuffer< T, CAP >::consume ( T &  val)
inline

Remove an element from the buffer.

Parameters
valOutput parameter that receives the next element. If there is (currently) no next element, val will not be modified.
Returns
false if the buffer was empty; true if the buffer was not empty and an element was written to val.

Member Data Documentation

◆ data

template<typename T , unsigned CAP>
T BBuffer< T, CAP >::data[CAP]
private

◆ in

template<typename T , unsigned CAP>
volatile unsigned BBuffer< T, CAP >::in
private

◆ out

template<typename T , unsigned CAP>
volatile unsigned BBuffer< T, CAP >::out
private

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