AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AByteBuffer Class Referencefinal

std::vector-like growing array for byte storage. More...

#include <AUI/Common/AByteBuffer.h>

Public Types

using iterator = char*
 

Public Member Functions

 AByteBuffer (const char *buffer, size_t size)
 
 AByteBuffer (size_t initialCapacity)
 
 AByteBuffer (const unsigned char *buffer, size_t size)
 
 AByteBuffer (AByteBufferView other)
 
 AByteBuffer (const AByteBuffer &other)
 
 AByteBuffer (AByteBuffer &&other) noexcept
 
void write (const char *src, size_t size) override
 Writes exact size bytes to stream. Blocking (waiting for write all data) is allowed.
 
AByteBufferView slice (std::size_t offset, std::size_t size) const noexcept
 
AByteBufferView slice (std::size_t offset) const noexcept
 
void write (IInputStream &stream, size_t size)
 
 operator AByteBufferView () const noexcept
 
void clear ()
 
void reserve (size_t size)
 Resizes internal buffer.
 
void increaseInternalBuffer (size_t size)
 Increases internal buffer.
 
void grow (size_t size)
 If getReserved() - getSize() is less than size increases internal buffer size enough to store size bytes.
 
size_t getAvailableToWrite () const
 
char * data () const
 
template<typename T>
T & at (size_t byteIndex)
 Gets value of specified type by byte index relative to the beginning of internal buffer.
 
template<typename T>
const T & at (size_t byteIndex) const
 Gets value of specified type by byte index relative to the beginning of internal buffer.
 
void setSize (size_t s)
 
void increaseSize (size_t s)
 
void resize (size_t s)
 
void reallocate (size_t s)
 
size_t getSize () const noexcept
 
bool empty () const noexcept
 
size_t size () const noexcept
 
size_t capacity () const noexcept
 
size_t getReserved () const noexcept
 
AByteBufferoperator= (AByteBuffer &&other) noexcept
 
AByteBufferoperator= (const AByteBuffer &other)
 
bool operator== (const AByteBuffer &r) const
 
bool operator!= (const AByteBuffer &r) const
 
char * begin ()
 
char * end ()
 
char * endReserved ()
 
const char * begin () const
 
const char * end () const
 
template<typename T>
as () const
 
AString toHexString () const
 
AString toBase64String () const
 
iterator erase (iterator begin, iterator end) noexcept
 
bool ownsIterator (iterator i) const noexcept
 
- Public Member Functions inherited from IOutputStream
template<typename T>
void write (const T &t)
 
template<typename T>
IOutputStreamoperator<< (const T &t)
 

Static Public Member Functions

static AByteBuffer fromStream (aui::no_escape< IInputStream > is)
 
static AByteBuffer fromStream (aui::no_escape< IInputStream > is, size_t sizeRestriction)
 
static AByteBuffer fromString (const AString &string)
 
static AByteBuffer fromHexString (const AString &string)
 
static AByteBuffer fromBase64String (const AString &encodedString)
 

Detailed Description

std::vector-like growing array for byte storage.

Member Function Documentation

◆ at() [1/2]

template<typename T>
T & AByteBuffer::at ( size_t byteIndex)
inline

Gets value of specified type by byte index relative to the beginning of internal buffer.

Template Parameters
Tdata type
Parameters
byteIndexbyte offset realtive to the beginning of internal buffer
Returns
data

◆ at() [2/2]

template<typename T>
const T & AByteBuffer::at ( size_t byteIndex) const
inline

Gets value of specified type by byte index relative to the beginning of internal buffer.

Template Parameters
Tdata type
Parameters
byteIndexbyte offset realtive to the beginning of internal buffer
Returns
data

◆ capacity()

size_t AByteBuffer::capacity ( ) const
inlinenoexcept
Returns
size of whole buffer (including possibly invalid data)

◆ data()

char * AByteBuffer::data ( ) const
inline
Returns
Internal buffer.

◆ empty()

bool AByteBuffer::empty ( ) const
inlinenoexcept
Returns
true if size == 0

◆ getAvailableToWrite()

size_t AByteBuffer::getAvailableToWrite ( ) const
inline
Returns
delta between internal buffer size and payload size.

◆ getReserved()

size_t AByteBuffer::getReserved ( ) const
inlinenoexcept
Returns
size of internal buffer. Must be greater that getSize()

◆ getSize()

size_t AByteBuffer::getSize ( ) const
inlinenoexcept
Returns
size of payload (valid data)

◆ increaseSize()

void AByteBuffer::increaseSize ( size_t s)
inline

Forces new size of the buffer.

Sneaky assert:
Assert fails when new size is greater that reserved buffer size. Use AByteBuffer::resize to avoid this.
Parameters
snew size of the payload

◆ reallocate()

void AByteBuffer::reallocate ( size_t s)
inline

Resizes the buffer WITHOUT keeping it's contents. When reserved buffer size is differs from the new size, buffer is reallocated with new size.

Parameters
snew size of the payload

◆ resize()

void AByteBuffer::resize ( size_t s)
inline

Resizes the buffer keeping it's contents. When reserved buffer size is less than the new size, buffer is reallocated with new size.

Parameters
snew size of the payload

◆ setSize()

void AByteBuffer::setSize ( size_t s)
inline

Forces new size of the buffer.

Sneaky assert:
Assert fails when new size is greater that reserved buffer size. Use AByteBuffer::resize to avoid this.
Parameters
snew size of the payload

◆ size()

size_t AByteBuffer::size ( ) const
inlinenoexcept
Returns
size of payload (valid data)

◆ write() [1/2]

void AByteBuffer::write ( const char * src,
size_t size )
overridevirtual

Writes exact size bytes to stream. Blocking (waiting for write all data) is allowed.

Sneaky exceptions
An implementation can throw any exception that subclasses AIOException.
Parameters
srcsource buffer
sizesource buffer's size. > 0

Implements IOutputStream.

◆ write() [2/2]

void AByteBuffer::write ( IInputStream & stream,
size_t size )

Reads exact size bytes from stream.

Parameters
stream
size

The documentation for this class was generated from the following files:
Inheritance diagram for AByteBuffer:
Collaboration diagram for AByteBuffer: