RAVENNAKIT
Loading...
Searching...
No Matches
rav::FifoBuffer< T, F > Class Template Reference

A classic FIFO buffer implementation with different strategies F. More...

#include <fifo_buffer.hpp>

Public Member Functions

 FifoBuffer ()=default
 FifoBuffer (const size_t capacity)
 Constructs a queue with a given number of elements.
 FifoBuffer (const FifoBuffer &other)=delete
FifoBuffer & operator= (const FifoBuffer &other)=delete
 FifoBuffer (FifoBuffer &&other) noexcept=delete
FifoBuffer & operator= (FifoBuffer &&other) noexcept=delete
bool push (T value)
 Pushes a value to the buffer.
std::optional< T > pop ()
 Pops a value from the buffer.
void pop_all ()
 Convenience function to pop all available data.
template<typename U = T, std::enable_if_t< std::is_trivially_copyable_v< U >, int > = 0>
bool write (const T *src, const size_t number_of_elements)
 Writes data to the buffer.
template<typename U = T, std::enable_if_t< std::is_trivially_copyable_v< U >, int > = 0>
bool read (T *dst, const size_t number_of_elements)
 Reads data from the buffer.
void resize (size_t size)
 Resizes this buffer, clearing existing data.
void reset ()
 Clears the buffer.
size_t size ()

Detailed Description

template<class T, class F>
class rav::FifoBuffer< T, F >

A classic FIFO buffer implementation with different strategies F.

Definition at line 39 of file fifo_buffer.hpp.

Constructor & Destructor Documentation

◆ FifoBuffer() [1/4]

template<class T, class F>
rav::FifoBuffer< T, F >::FifoBuffer ( )
default

◆ FifoBuffer() [2/4]

template<class T, class F>
rav::FifoBuffer< T, F >::FifoBuffer ( const size_t capacity)
inlineexplicit

Constructs a queue with a given number of elements.

Parameters
capacityThe number of elements the queue can hold.

Definition at line 47 of file fifo_buffer.hpp.

◆ FifoBuffer() [3/4]

template<class T, class F>
rav::FifoBuffer< T, F >::FifoBuffer ( const FifoBuffer< T, F > & other)
delete

◆ FifoBuffer() [4/4]

template<class T, class F>
rav::FifoBuffer< T, F >::FifoBuffer ( FifoBuffer< T, F > && other)
deletenoexcept

Member Function Documentation

◆ operator=() [1/2]

template<class T, class F>
FifoBuffer & rav::FifoBuffer< T, F >::operator= ( const FifoBuffer< T, F > & other)
delete

◆ operator=() [2/2]

template<class T, class F>
FifoBuffer & rav::FifoBuffer< T, F >::operator= ( FifoBuffer< T, F > && other)
deletenoexcept

◆ pop()

template<class T, class F>
std::optional< T > rav::FifoBuffer< T, F >::pop ( )
inlinenodiscard

Pops a value from the buffer.

Returns
The value that was popped, or std::nullopt if the buffer is empty.

Definition at line 75 of file fifo_buffer.hpp.

◆ pop_all()

template<class T, class F>
void rav::FifoBuffer< T, F >::pop_all ( )
inline

Convenience function to pop all available data.

Thread safe when called from the consumer thread.

Definition at line 88 of file fifo_buffer.hpp.

◆ push()

template<class T, class F>
bool rav::FifoBuffer< T, F >::push ( T value)
inlinenodiscard

Pushes a value to the buffer.

Parameters
valueThe value to push.
Returns
True if the value was pushed, false if the buffer is full.

Definition at line 62 of file fifo_buffer.hpp.

◆ read()

template<class T, class F>
template<typename U = T, std::enable_if_t< std::is_trivially_copyable_v< U >, int > = 0>
bool rav::FifoBuffer< T, F >::read ( T * dst,
const size_t number_of_elements )
inlinenodiscard

Reads data from the buffer.

Parameters
dstThe destination to write the data to.
number_of_elementsThe number of elements to read (not bytes).
Returns
True if reading was successful, false if there was not enough data to read.

Definition at line 124 of file fifo_buffer.hpp.

◆ reset()

template<class T, class F>
void rav::FifoBuffer< T, F >::reset ( )
inline

Clears the buffer.

Definition at line 152 of file fifo_buffer.hpp.

◆ resize()

template<class T, class F>
void rav::FifoBuffer< T, F >::resize ( size_t size)
inline

Resizes this buffer, clearing existing data.

Parameters
sizeThe new capacity of the buffer.

Definition at line 144 of file fifo_buffer.hpp.

◆ size()

template<class T, class F>
size_t rav::FifoBuffer< T, F >::size ( )
inlinenodiscard
Returns
The number of elements in the buffer.

Definition at line 160 of file fifo_buffer.hpp.

◆ write()

template<class T, class F>
template<typename U = T, std::enable_if_t< std::is_trivially_copyable_v< U >, int > = 0>
bool rav::FifoBuffer< T, F >::write ( const T * src,
const size_t number_of_elements )
inlinenodiscard

Writes data to the buffer.

Parameters
srcThe source data to write to the buffer.
number_of_elementsThe number of elements to write (not bytes).
Returns
True if writing was successful, false if there was not enough space to write all data.

Definition at line 101 of file fifo_buffer.hpp.


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