DISTRHO Plugin Framework
Public Member Functions | Protected Member Functions | List of all members
RingBufferControl< BufferStruct > Class Template Reference

#include <RingBuffer.hpp>

Public Member Functions

bool isDataAvailableForReading () const noexcept
 
bool isEmpty () const noexcept
 
uint32_t getSize () const noexcept
 
uint32_t getReadableDataSize () const noexcept
 
uint32_t getWritableDataSize () const noexcept
 
void clearData () noexcept
 
void flush () noexcept
 
bool readBool () noexcept
 
uint8_t readByte () noexcept
 
int16_t readShort () noexcept
 
uint16_t readUShort () noexcept
 
int32_t readInt () noexcept
 
uint32_t readUInt () noexcept
 
int64_t readLong () noexcept
 
uint64_t readULong () noexcept
 
float readFloat () noexcept
 
double readDouble () noexcept
 
bool readCustomData (void *const data, const uint32_t size) noexcept
 
template<typename T >
bool readCustomType (T &type) noexcept
 
bool writeBool (const bool value) noexcept
 
bool writeByte (const uint8_t value) noexcept
 
bool writeShort (const int16_t value) noexcept
 
bool writeUShort (const uint16_t value) noexcept
 
bool writeInt (const int32_t value) noexcept
 
bool writeUInt (const uint32_t value) noexcept
 
bool writeLong (const int64_t value) noexcept
 
bool writeULong (const uint64_t value) noexcept
 
bool writeFloat (const float value) noexcept
 
bool writeDouble (const double value) noexcept
 
bool writeCustomData (const void *const data, const uint32_t size) noexcept
 
template<typename T >
bool writeCustomType (const T &type) noexcept
 
bool commitWrite () noexcept
 
void setRingBuffer (BufferStruct *const ringBuf, const bool clearRingBufferData) noexcept
 

Protected Member Functions

bool tryRead (void *const buf, const uint32_t size) noexcept
 
bool tryWrite (const void *const buf, const uint32_t size) noexcept
 

Detailed Description

template<class BufferStruct>
class RingBufferControl< BufferStruct >

DPF built-in RingBuffer class. RingBufferControl takes one buffer struct to take control over, and operates over it.

This is meant for single-writer, single-reader type of control. Writing and reading is wait and lock-free.

Typically usage involves:

// definition
HeapRingBuffer myHeapBuffer; // or RingBufferControl<HeapBuffer> class for more control
// construction, only needed for heap buffers
myHeapBuffer.createBuffer(8192);
// writing data
myHeapBuffer.writeUInt(size);
myHeapBuffer.writeCustomData(someOtherData, size);
myHeapBuffer.commitWrite();
// reading data
if (myHeapBuffer.isDataAvailableForReading())
{
uint32_t size;
if (myHeapBuffer.readUInt(size) && readCustomData(&anotherData, size))
{
// do something with "anotherData"
}
}
Definition: RingBuffer.hpp:711
bool createBuffer(const uint32_t size) noexcept
Definition: RingBuffer.hpp:733
bool writeCustomData(const void *const data, const uint32_t size) noexcept
Definition: RingBuffer.hpp:494
bool readCustomData(void *const data, const uint32_t size) noexcept
Definition: RingBuffer.hpp:378
bool commitWrite() noexcept
Definition: RingBuffer.hpp:518
See also
HeapBuffer

Member Function Documentation

◆ readCustomData()

template<class BufferStruct >
bool RingBufferControl< BufferStruct >::readCustomData ( void *const  data,
const uint32_t  size 
)
inlinenoexcept

Read an arbitrary amount of data, specified by size. data pointer must be non-null, and size > 0.

Returns true if reading succeeds. In case of failure, data pointer is automatically cleared by size bytes.

◆ readCustomType()

template<class BufferStruct >
template<typename T >
bool RingBufferControl< BufferStruct >::readCustomType ( T &  type)
inlinenoexcept

Read a custom data type specified by the template typename used, with size being automatically deduced by the compiler (through the use of sizeof).

Returns true if reading succeeds. In case of failure, type value is automatically cleared by its deduced size.

◆ writeCustomData()

template<class BufferStruct >
bool RingBufferControl< BufferStruct >::writeCustomData ( const void *const  data,
const uint32_t  size 
)
inlinenoexcept

Write an arbitrary amount of data, specified by size. data pointer must be non-null, and size > 0.

◆ writeCustomType()

template<class BufferStruct >
template<typename T >
bool RingBufferControl< BufferStruct >::writeCustomType ( const T &  type)
inlinenoexcept

Write a custom data type specified by the template typename used, with size being automatically deduced by the compiler (through the use of sizeof).

◆ commitWrite()

template<class BufferStruct >
bool RingBufferControl< BufferStruct >::commitWrite ( )
inlinenoexcept

Commit all previous write operations to the ringbuffer. If a write operation has previously failed, this will reset/invalidate the previous write attempts.


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