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

#include <Buffer.h>

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

Public Member Functions

 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

Memory data buffer

Generic buffer with a special memory-allocation strategy for effective append() operation

Constructor & Destructor Documentation

◆ Buffer() [1/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

◆ 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 ( Buffer &&  other)
defaultnoexcept

Move constructor

Moves a buffer from another buffer.

Parameters
otherData buffer

◆ ~Buffer()

sptk::Buffer::~Buffer ( )
overridedefaultnoexcept

Destructor

Member Function Documentation

◆ append() [1/7]

void sptk::Buffer::append ( char  ch)
inlineoverridevirtual

Appends a single char to the current buffer.

Allocates memory if needed.

Parameters
chSingle character

Reimplemented from sptk::BufferStorage.

References sptk::BufferStorage::append().

◆ append() [2/7]

void sptk::Buffer::append ( const Buffer buffer)
inline

Appends the string to the current buffer.

Allocates memory if needed.

Parameters
bufferData to append

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

◆ append() [3/7]

void sptk::Buffer::append ( const char *  data,
size_t  sz = 0 
)
inlineoverridevirtual

Appends the external data of size sz to the current buffer.

Allocates memory if needed.

Parameters
dataExternal data buffer
szRequired memory size

Reimplemented from sptk::BufferStorage.

References sptk::BufferStorage::append().

◆ append() [4/7]

void sptk::Buffer::append ( const std::string &  str)
inline

Appends the string to the current buffer.

Allocates memory if needed.

Parameters
strString to append

◆ append() [5/7]

void sptk::Buffer::append ( const String str)
inline

Appends the string to the current buffer.

Allocates memory if needed.

Parameters
strString to append

◆ append() [6/7]

void sptk::Buffer::append ( const uint8_t *  data,
size_t  sz 
)
inlineoverridevirtual

Appends the external data of size sz to the current buffer.

Allocates memory if needed.

Parameters
dataExternal data buffer
szRequired memory size

Reimplemented from sptk::BufferStorage.

References sptk::BufferStorage::append().

◆ append() [7/7]

template<class T >
void sptk::Buffer::append ( val)
inline

Append a value of primitive type or structure to the current buffer.

Allocates memory if needed.

Parameters
valPrimitive type or structure

◆ BufferStorage() [1/5]

sptk::BufferStorage::BufferStorage ( )
inline

Default constructor

Creates an empty buffer.

◆ BufferStorage() [2/5]

sptk::BufferStorage::BufferStorage ( BufferStorage &&  bufferStorage)
defaultnoexcept

Move constructor

Parameters
bufferStorageOther object

◆ BufferStorage() [3/5]

sptk::BufferStorage::BufferStorage ( const BufferStorage bufferStorage)
default

Copy constructor

Parameters
bufferStorageOther object

◆ BufferStorage() [4/5]

template<typename T >
sptk::BufferStorage::BufferStorage ( const T *  data,
size_t  sz 
)
inline

Constructor

Creates a buffer from void *data. The data is copied inside the buffer. The return of the bytes() method will be the input data size.

Parameters
dataData buffer
szData buffer size

◆ BufferStorage() [5/5]

sptk::BufferStorage::BufferStorage ( size_t  sz)
inlineexplicit

Constructor

Creates an empty buffer. The return of the bytes() method will be 0.

Parameters
szBuffer size to be pre-allocated

◆ loadFromFile()

void sptk::Buffer::loadFromFile ( const fs::path &  fileName)

Loads the buffer from file fileName.

Parameters
fileNameName of the input file

◆ operator String()

sptk::Buffer::operator String ( ) const
inlineexplicit

Convertor to std::string

◆ operator!=()

bool sptk::Buffer::operator!= ( const Buffer other) const

Compare operator

Parameters
otherOther buffer
Returns
True if buffer contents are not matching

◆ operator=() [1/4]

Buffer & sptk::Buffer::operator= ( Buffer &&  other)
default

Moves buffer from another buffer

Parameters
otherBuffer to move from
Returns
this object

◆ operator=() [2/4]

Buffer & sptk::Buffer::operator= ( const Buffer other)
default

Assigns from Buffer

Parameters
otherBuffer to assign from
Returns
this object

◆ operator=() [3/4]

Buffer & sptk::Buffer::operator= ( const char *  str)

Assigns from char *

Parameters
strconst char *, the string to assign from
Returns
this object

◆ operator=() [4/4]

Buffer & sptk::Buffer::operator= ( const String str)

Assigns from String

Parameters
strString to assign from
Returns
this object

◆ operator==()

bool sptk::Buffer::operator== ( const Buffer other) const

Compare operator

Parameters
otherOther buffer
Returns
True if buffer contents are identical

◆ operator[]() [1/2]

uint8_t & sptk::Buffer::operator[] ( size_t  index)
inline

Access the chars by index

Parameters
indexCharacter index

◆ operator[]() [2/2]

const uint8_t & sptk::Buffer::operator[] ( size_t  index) const
inline

Access the chars by index, const version

Parameters
indexCharacter index

◆ saveToFile()

void sptk::Buffer::saveToFile ( const fs::path &  fileName) const

Saves the buffer to the file fileName.

Parameters
fileNameName of the output file

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

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