TinyRobotics
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
SingleBuffer< T > Class Template Reference

A simple Buffer implementation which just uses a (dynamically sized) array. More...

#include <Buffers.h>

Inheritance diagram for SingleBuffer< T >:
Inheritance graph
[legend]
Collaboration diagram for SingleBuffer< T >:
Collaboration graph
[legend]

Public Member Functions

 SingleBuffer (int size)
 Construct a new Single Buffer object.
 
 SingleBuffer (SingleBuffer &)=default
 
SingleBufferoperator= (SingleBuffer &)=default
 
 SingleBuffer ()
 Construct a new Single Buffer w/o allocating any memory.
 
void onExternalBufferRefilled (void *data, int len)
 notifies that the external buffer has been refilled
 
int writeArray (const T data[], int len) override
 Fills the buffer data.
 
bool write (T sample) override
 write add an entry to the buffer
 
bool read (T &result) override
 reads a single value
 
bool peek (T &result) override
 peeks the actual entry from the buffer
 
int available () override
 provides the number of entries that are available to read
 
int availableForWrite () override
 provides the number of entries that are available to write
 
bool isFull () override
 checks if the buffer is full
 
int peekArray (uint8_t *data, int len)
 
int clearArray (int len) override
 consumes len bytes and moves current data to the beginning
 
void trim ()
 Moves the unprocessed data to the beginning of the buffer.
 
T * address () override
 Provides address to beginning of the buffer.
 
T * data ()
 Provides address of actual data.
 
void reset () override
 clears the buffer
 
size_t setAvailable (size_t available_size)
 
size_t size () override
 
bool resize (int size)
 Resizes the buffer if supported: returns false if not supported.
 
void setClearWithZero (bool flag)
 Sets the buffer to 0 on clear.
 
void setWritePos (int pos)
 Updates the actual available data size.
 
- Public Member Functions inherited from BaseBuffer< T >
 BaseBuffer (BaseBuffer &)=default
 
BaseBufferoperator= (BaseBuffer &)=default
 
virtual bool read (T &result)=0
 reads a single value
 
virtual int readArray (T data[], int len)
 reads multiple values
 
virtual int clearArray (int len)
 Removes the next len entries.
 
virtual int writeArray (const T data[], int len)
 Fills the buffer data.
 
virtual int writeArrayOverwrite (const T data[], int len)
 Fills the buffer data and overwrites the oldest data if the buffer is full.
 
virtual bool peek (T &result)=0
 peeks the actual entry from the buffer
 
virtual bool isFull ()
 checks if the buffer is full
 
bool isEmpty ()
 
virtual bool write (T data)=0
 write add an entry to the buffer
 
virtual void reset ()=0
 clears the buffer
 
void clear ()
 same as reset
 
virtual int available ()=0
 provides the number of entries that are available to read
 
virtual int availableForWrite ()=0
 provides the number of entries that are available to write
 
virtual T * address ()=0
 returns the address of the start of the physical read buffer
 
virtual size_t size ()=0
 
virtual float levelPercent ()
 Returns the level of the buffer in %.
 
virtual bool resize (int bytes)
 Resizes the buffer if supported: returns false if not supported.
 

Public Attributes

int id = 0
 Optional ID.
 
bool active = true
 Optional active/inactive status.
 
uint64_t timestamp = 0
 Optional timestamp.
 

Protected Attributes

int current_read_pos = 0
 
int current_write_pos = 0
 
bool owns_buffer = true
 
bool is_clear_with_zero = false
 
std::vector< T > buffer {0}
 

Detailed Description

template<typename T = int16_t>
class tinyrobotics::SingleBuffer< T >

A simple Buffer implementation which just uses a (dynamically sized) array.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ SingleBuffer()

SingleBuffer ( int  size)
inline

Construct a new Single Buffer object.

Parameters
sizein entries

Member Function Documentation

◆ address()

T * address ( )
inlineoverridevirtual

Provides address to beginning of the buffer.

Implements BaseBuffer< T >.

◆ available()

int available ( )
inlineoverridevirtual

provides the number of entries that are available to read

Implements BaseBuffer< T >.

◆ availableForWrite()

int availableForWrite ( )
inlineoverridevirtual

provides the number of entries that are available to write

Implements BaseBuffer< T >.

◆ clearArray()

int clearArray ( int  len)
inlineoverridevirtual

consumes len bytes and moves current data to the beginning

Reimplemented from BaseBuffer< T >.

◆ isFull()

bool isFull ( )
inlineoverridevirtual

checks if the buffer is full

Reimplemented from BaseBuffer< T >.

◆ peek()

bool peek ( T &  result)
inlineoverridevirtual

peeks the actual entry from the buffer

Implements BaseBuffer< T >.

◆ read()

bool read ( T &  result)
inlineoverridevirtual

reads a single value

Implements BaseBuffer< T >.

◆ reset()

void reset ( )
inlineoverridevirtual

clears the buffer

Implements BaseBuffer< T >.

◆ resize()

bool resize ( int  bytes)
inlinevirtual

Resizes the buffer if supported: returns false if not supported.

Reimplemented from BaseBuffer< T >.

◆ setAvailable()

size_t setAvailable ( size_t  available_size)
inline

If we load values directly into the address we need to set the avialeble size

◆ size()

size_t size ( )
inlineoverridevirtual

Implements BaseBuffer< T >.

◆ write()

bool write ( data)
inlineoverridevirtual

write add an entry to the buffer

Implements BaseBuffer< T >.

◆ writeArray()

int writeArray ( const T  data[],
int  len 
)
inlineoverridevirtual

Fills the buffer data.

Reimplemented from BaseBuffer< T >.


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