sptk2 logo
SPTK Home Page
Public Member Functions | List of all members
sptk::ReadBuffer Class Reference

#include <ReadBuffer.h>

Inheritance diagram for sptk::ReadBuffer:
sptk::Buffer sptk::BufferStorage

Public Member Functions

template<typename T >
bool read (T &data)
 
bool read (uint8_t *data, size_t size)
 
bool read (String &data, size_t length)
 
bool read (Buffer &data, size_t length)
 
uint8_t * head ()
 
size_t available () const
 
bool eof () const
 
size_t readOffset () const
 
 Buffer (const String &str)
 
 Buffer (const Buffer &other)=default
 
 Buffer (Buffer &&other) noexcept=default
 
- Public Member Functions inherited from sptk::Buffer
 Buffer (const String &str)
 
 Buffer (const Buffer &other)=default
 
 Buffer (Buffer &&other) noexcept=default
 
 ~Buffer () noexcept override=default
 
Bufferoperator= (Buffer &&other) DOESNT_THROW=default
 
Bufferoperator= (const Buffer &other)=default
 
void append (char ch) override
 
void append (const char *data, size_t sz=0) override
 
void append (const uint8_t *data, size_t sz) override
 
template<class T >
void append (T val)
 
void append (const std::string &str)
 
void append (const String &str)
 
void append (const Buffer &buffer)
 
uint8_t & operator[] (size_t index)
 
const uint8_t & operator[] (size_t index) const
 
bool operator== (const Buffer &other) const
 
bool operator!= (const Buffer &other) const
 
void loadFromFile (const fs::path &fileName)
 
void saveToFile (const fs::path &fileName) const
 
Bufferoperator= (const String &str)
 
Bufferoperator= (const char *str)
 
 operator String () const
 
 BufferStorage ()
 
 BufferStorage (size_t sz)
 
 BufferStorage (const BufferStorage &bufferStorage)=default
 
 BufferStorage (BufferStorage &&bufferStorage) noexcept=default
 
template<typename T >
 BufferStorage (const T *data, size_t sz)
 
- Public Member Functions inherited from sptk::BufferStorage
 BufferStorage ()
 
 BufferStorage (size_t sz)
 
 BufferStorage (const BufferStorage &bufferStorage)=default
 
 BufferStorage (BufferStorage &&bufferStorage) noexcept=default
 
virtual ~BufferStorage ()=default
 
BufferStorageoperator= (const BufferStorage &bufferStorage)=default
 
BufferStorageoperator= (BufferStorage &&bufferStorage) noexcept=default
 
template<typename T >
 BufferStorage (const T *data, size_t sz)
 
uint8_t * data ()
 
const uint8_t * data () const
 
const char * c_str () const
 
bool empty () const
 
virtual void checkSize (size_t sz)
 
template<typename T >
void set (const T *data, size_t sz)
 
void set (const BufferStorage &data)
 
void set (const String &data)
 
size_t capacity () const
 
size_t length () const
 
size_t bytes () const
 
void bytes (size_t b)
 
virtual void append (char ch)
 
virtual void append (const char *data, size_t sz=0)
 
virtual void append (const uint8_t *data, size_t sz)
 
void reset (size_t sz=0)
 
void fill (char ch, size_t count)
 
void erase (size_t offset, size_t length)
 

Additional Inherited Members

- Protected Member Functions inherited from sptk::BufferStorage
void adjustSize (size_t sz)
 
void allocate (size_t size)
 
void allocate (const uint8_t *data, size_t size)
 
void reallocate (size_t size)
 
void deallocate () noexcept
 
void init (const uint8_t *data, size_t size, size_t bytes)
 

Detailed Description

Generic read buffer.

Data is added to the buffer the usual way, using ctors and/or append operations. Any read operations copy data into external buffer, then advance internal read offset.

Member Function Documentation

◆ available()

size_t sptk::ReadBuffer::available ( ) const
inline

Get number of bytes, available for read

Returns
number of bytes, available for read

References sptk::BufferStorage::bytes(), and readOffset().

◆ Buffer() [1/3]

sptk::Buffer::Buffer ( Buffer &&  other)
defaultnoexcept

Move constructor

Moves a buffer from another buffer.

Parameters
otherData buffer

◆ Buffer() [2/3]

sptk::Buffer::Buffer ( const Buffer other)
default

Copy constructor

Creates a buffer from another buffer.

Parameters
otherData buffer

◆ Buffer() [3/3]

sptk::Buffer::Buffer ( const String str)
explicit

Constructor

Creates a buffer from string. The string is copied inside the buffer. The return of the bytes() method will be the input string length.

Parameters
strInput string

◆ eof()

bool sptk::ReadBuffer::eof ( ) const
inline
Returns
true if there are no available bytes to read

References sptk::BufferStorage::bytes(), and readOffset().

◆ head()

uint8_t * sptk::ReadBuffer::head ( )
inline

The start of un-read data

Returns

References sptk::BufferStorage::data().

◆ read() [1/4]

bool sptk::ReadBuffer::read ( Buffer data,
size_t  length 
)

Read into buffer

Parameters
dataData
lengthData size
Returns
true if read was successful

◆ read() [2/4]

bool sptk::ReadBuffer::read ( String data,
size_t  length 
)

Read into string

Parameters
dataData
lengthData size
Returns
true if read was successful

◆ read() [3/4]

template<typename T >
bool sptk::ReadBuffer::read ( T &  data)
inline

Read into data of primitive type (int, double, etc).

Parameters
dataData
Returns
true if read was successful

References sptk::BufferStorage::data(), and read().

Referenced by read().

◆ read() [4/4]

bool sptk::ReadBuffer::read ( uint8_t *  data,
size_t  size 
)

Read data. Internal read offset is advanced by length.

Parameters
dataData
sizeData size
Returns
true if read was successful

◆ readOffset()

size_t sptk::ReadBuffer::readOffset ( ) const
inline

Get internal read offset

Returns
internal read offset

Referenced by available(), and eof().


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

Fri Oct 14 2022 09:58:44: SPTK 5.4.1