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

#include <BufferStorage.h>

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

Public Member Functions

 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)
 

Protected Member Functions

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 storage

Constructor & Destructor Documentation

◆ BufferStorage() [1/5]

sptk::BufferStorage::BufferStorage ( )
inline

Default constructor

Creates an empty buffer.

◆ BufferStorage() [2/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

◆ BufferStorage() [3/5]

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

Copy constructor

Parameters
bufferStorageOther object

◆ BufferStorage() [4/5]

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

Move constructor

Parameters
bufferStorageOther object

◆ ~BufferStorage()

virtual sptk::BufferStorage::~BufferStorage ( )
virtualdefault

Destructor

◆ BufferStorage() [5/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

Member Function Documentation

◆ adjustSize()

void sptk::BufferStorage::adjustSize ( size_t  sz)
protected

Resizes current buffer

Parameters
szRequired memory size

◆ allocate() [1/2]

void sptk::BufferStorage::allocate ( const uint8_t *  data,
size_t  size 
)
inlineprotected

Allocate memory

Parameters
sizeNumber of bytes for new buffer

◆ allocate() [2/2]

void sptk::BufferStorage::allocate ( size_t  size)
inlineprotected

Allocate memory

Parameters
sizeNumber of bytes for new buffer

◆ append() [1/3]

virtual void sptk::BufferStorage::append ( char  ch)
virtual

Appends a single char to the current buffer.

Allocates memory if needed.

Parameters
chSingle character

Reimplemented in sptk::Buffer.

Referenced by sptk::Buffer::append().

◆ append() [2/3]

virtual void sptk::BufferStorage::append ( const char *  data,
size_t  sz = 0 
)
virtual

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

Allocates memory if needed.

Parameters
dataExternal data buffer
szRequired memory size

Reimplemented in sptk::Buffer.

◆ append() [3/3]

virtual void sptk::BufferStorage::append ( const uint8_t *  data,
size_t  sz 
)
virtual

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

Allocates memory if needed.

Parameters
dataExternal data buffer
szRequired memory size

Reimplemented in sptk::Buffer.

◆ bytes() [1/2]

size_t sptk::BufferStorage::bytes ( ) const
inline

◆ bytes() [2/2]

void sptk::BufferStorage::bytes ( size_t  b)
inline

Sets the size of the data stored

Doesn't check anything so use it this caution.

Parameters
bNew size of the buffer

◆ c_str()

const char * sptk::BufferStorage::c_str ( ) const
inline

Returns const char pointer on the data buffer.

◆ capacity()

size_t sptk::BufferStorage::capacity ( ) const
inline

Returns the size of memory allocated for the data buffer

Returns
buffer size

◆ checkSize()

virtual void sptk::BufferStorage::checkSize ( size_t  sz)
inlinevirtual

Checks if the current buffer size is enough

Allocates memory if needed.

Parameters
szRequired memory size

◆ data() [1/2]

uint8_t * sptk::BufferStorage::data ( )
inline

◆ data() [2/2]

const uint8_t * sptk::BufferStorage::data ( ) const
inline

Returns pointer on the data buffer.

◆ deallocate()

void sptk::BufferStorage::deallocate ( )
inlineprotectednoexcept

Free memory

◆ empty()

bool sptk::BufferStorage::empty ( ) const
inline

Returns true if number of bytes in buffer is zero.

◆ erase()

void sptk::BufferStorage::erase ( size_t  offset,
size_t  length 
)

Remove fragment from buffer's content

Parameters
offsetFragment start offset
lengthFragment length

◆ fill()

void sptk::BufferStorage::fill ( char  ch,
size_t  count 
)

Fills the bytes() characters in buffer with character ch.

Parameters
chThe character to fill the buffer
countHow many characters are to be filled. If counter is greater than capacity, then buffer is extended.

◆ length()

size_t sptk::BufferStorage::length ( ) const
inline

Returns the size of data in the data buffer

Returns
data size

◆ reallocate()

void sptk::BufferStorage::reallocate ( size_t  size)
inlineprotected

Reallocate memory

Parameters
sizeNumber of bytes for new buffer

◆ reset()

void sptk::BufferStorage::reset ( size_t  sz = 0)

Truncates the current buffer to the size sz.

Deallocates unused memory if needed.

Parameters
szRequired data size in bytes

◆ set() [1/3]

void sptk::BufferStorage::set ( const BufferStorage data)
inline

Copies the external data of size sz into the current buffer.

Allocates memory if needed.

Parameters
dataExternal data buffer

◆ set() [2/3]

void sptk::BufferStorage::set ( const String data)
inline

Copies the external data of size sz into the current buffer.

Allocates memory if needed.

Parameters
dataExternal data

◆ set() [3/3]

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

Copies the external data of size sz into the current buffer.

Allocates memory if needed.

Parameters
dataExternal data buffer
szRequired memory size

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

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