HosrDiretta
Loading...
Searching...
No Matches
ACQUA::Buffer Class Reference

Variable-length heap memory buffer. More...

#include <Buffer.hpp>

Inheritance diagram for ACQUA::Buffer:
DIRETTA::Receive DIRETTA::StreamReceive

Public Member Functions

 Buffer (Buffer &&b) noexcept
 Move constructor.
 
 Buffer (const Buffer &)=delete
 
Bufferoperator= (const Buffer &b)=delete
 
 Buffer () noexcept
 Default constructor that initializes the underlying byte vector to empty and sets NoRemapSize to 0.
 
 Buffer (std::uint8_t *s, std::uint8_t *e) noexcept
 Constructs a Buffer by copying bytes from the range [s, e) into the underlying std::vector and initializes NoRemapSize to 0.
 
 Buffer (size_t sz) noexcept
 Constructs a Buffer by allocating a byte vector of the specified size and initializing NoRemapSize to 0.
 
std::uint8_t * get ()
 Returns a pointer to the first byte by taking the address of front().
 
const std::uint8_t * get () const
 Returns a pointer to the first byte (the address of front()).
 
char * get_char ()
 Returns the result of get() reinterpreted as a pointer to char.
 
const char * get_char () const
 Returns the result of get() reinterpreted as a pointer to const char.
 
std::uint64_t * get_64 ()
 Returns a pointer to a 64-bit unsigned integer by reinterpret_casting the pointer returned by get().
 
const std::uint64_t * get_64 () const
 Returns a pointer to const std::uint64_t by reinterpreting the pointer returned by get(). This member function is const and does not modify the object.
 
std::uint32_t * get_32 ()
 Returns a pointer to a 32-bit unsigned integer by reinterpreting the pointer returned by get().
 
const std::uint32_t * get_32 () const
 Returns the object's underlying data reinterpreted as a pointer to const std::uint32_t.
 
std::uint16_t * get_16 ()
 Returns a pointer to a 16-bit unsigned integer by reinterpret_cast-ing the pointer returned by get(). No runtime checks are performed.
 
const std::uint16_t * get_16 () const
 Returns a pointer to the underlying data reinterpreted as a const std::uint16_t pointer.
 
std::uint8_t * get_8 ()
 Returns the pointer from get() reinterpreted as a pointer to std::uint8_t.
 
const std::uint8_t * get_8 () const
 Returns a pointer to the underlying data reinterpreted as a pointer to const std::uint8_t.
 
 operator BufferCS ()
 Implicit conversion operator that creates a BufferCS from the object's data pointer and size.
 
 operator BufferCS_const () const
 Implicit conversion operator that produces a const BufferCS view of the object's data.
 
bool get_string_list (std::list< std::string > &, bool tab=false) const
 Extracts lines of text from the buffer and populates a list of strings.
 
void fill (std::uint8_t)
 Fills all memory with the specified value.
 
void fill (std::uint8_t, std::size_t, std::size_t=0)
 Fills all memory with the specified value.
 
Bufferoperator= (BufferCS_const)
 assignment
 
std::string dump () const
 Returns a textual dump of the object's buffer by converting to BufferCS_const and invoking its dump() method.
 
std::string dump (std::size_t s) const
 Returns a textual dump of the object's buffer by converting to BufferCS_const and invoking its dump() method. Size specification.
 
std::string get_string () const
 Returns a std::string containing the buffer's contents.
 
Bufferoperator+= (BufferCS_const buf)
 Appends the contents of the given buffer to this buffer.
 
void resize (std::size_t si)
 Change the actual memory size.
 
bool resize ()
 Adjust the actual memory size to match the length.
 
void resize (std::size_t si, std::uint8_t fl)
 Resizes the underlying byte container to the specified size, fills its contents with the given byte value.
 
bool resize_noremap (std::size_t si)
 Change the length without altering the actual memory size. if the size is zero, free the memory.
 
bool resize_noremap (std::size_t si, std::uint8_t fl)
 Change the length without altering the actual memory size. if the size is zero, free the memory.
 
std::size_t size () const
 Returns the number of elements. If NoRemapSize is non-zero, that value is returned; otherwise the function returns the underlying std::vector<std::uint8_t>::size().
 
void clear ()
 Clears the object's contents or resets its state to a default/empty condition.
 
void swap (Buffer &in)
 Swaps the contents of the specified Buffer.
 
void move (Buffer &in)
 Movde the contents of the specified Buffer.
 
std::vector< std::uint8_t >::iterator end ()
 Returns a non-const iterator to one past the last element of the std::vector<std::uint8_t>.
 
std::vector< std::uint8_t >::const_iterator end () const
 Returns a const iterator to the element following the last byte in the container.
 
std::vector< std::uint8_t >::iterator insert (std::vector< std::uint8_t >::const_iterator i, std::vector< std::uint8_t >::const_iterator s, std::vector< std::uint8_t >::const_iterator e)
 Inserts a range of bytes into the vector before the specified position.
 
std::vector< std::uint8_t >::iterator insert (std::vector< std::uint8_t >::const_iterator i, const std::uint8_t *s, const std::uint8_t *e)
 Inserts the bytes in the half-open range [s, e) into a std::vector<std::uint8_t> before the position i.
 
std::vector< std::uint8_t >::iterator erase (std::vector< std::uint8_t >::iterator s, std::vector< std::uint8_t >::iterator e)
 Erases the elements in the half-open range [s, e) from a std::vector<std::uint8_t> and returns an iterator to the element that followed the last removed element.
 

Detailed Description

Variable-length heap memory buffer.

Constructor & Destructor Documentation

◆ Buffer() [1/3]

ACQUA::Buffer::Buffer ( Buffer && b)
inlinenoexcept

Move constructor.

Parameters
b

◆ Buffer() [2/3]

ACQUA::Buffer::Buffer ( std::uint8_t * s,
std::uint8_t * e )
inlinenoexcept

Constructs a Buffer by copying bytes from the range [s, e) into the underlying std::vector and initializes NoRemapSize to 0.

Parameters
sPointer to the first byte of the input range.
ePointer one past the last byte of the input range.

◆ Buffer() [3/3]

ACQUA::Buffer::Buffer ( size_t sz)
inlinenoexcept

Constructs a Buffer by allocating a byte vector of the specified size and initializing NoRemapSize to 0.

Parameters
szThe number of bytes to allocate in the underlying std::vector<std::uint8_t>.

Member Function Documentation

◆ dump() [1/2]

std::string ACQUA::Buffer::dump ( ) const
inline

Returns a textual dump of the object's buffer by converting to BufferCS_const and invoking its dump() method.

Returns
A std::string containing the buffer dump.

◆ dump() [2/2]

std::string ACQUA::Buffer::dump ( std::size_t s) const
inline

Returns a textual dump of the object's buffer by converting to BufferCS_const and invoking its dump() method. Size specification.

Parameters
sThe number of bytes (or elements) to include in the dump.
Returns
std::string containing the buffer dump.

◆ end() [1/2]

std::vector< std::uint8_t >::iterator ACQUA::Buffer::end ( )
inline

Returns a non-const iterator to one past the last element of the std::vector<std::uint8_t>.

Returns
A std::vector<std::uint8_t>::iterator pointing to the element following the last element (one-past-the-end).

◆ end() [2/2]

std::vector< std::uint8_t >::const_iterator ACQUA::Buffer::end ( ) const
inline

Returns a const iterator to the element following the last byte in the container.

Returns
A std::vector<std::uint8_t>::const_iterator that points one past the last element (computed as begin() + size()). The function is const and does not allow modification of the elements; complexity is O(1).

◆ erase()

std::vector< std::uint8_t >::iterator ACQUA::Buffer::erase ( std::vector< std::uint8_t >::iterator s,
std::vector< std::uint8_t >::iterator e )

Erases the elements in the half-open range [s, e) from a std::vector<std::uint8_t> and returns an iterator to the element that followed the last removed element.

Parameters
sIterator pointing to the first element to be removed (inclusive).
eIterator pointing past the last element to be removed (exclusive).
Returns
A std::vector<std::uint8_t>::iterator that points to the element that followed the last removed element, or std::vector<std::uint8_t>::end() if the removal reached the end of the container.

◆ fill() [1/2]

void ACQUA::Buffer::fill ( std::uint8_t )

Fills all memory with the specified value.

Parameters
Thebyte value used to fill.

◆ fill() [2/2]

void ACQUA::Buffer::fill ( std::uint8_t ,
std::size_t ,
std::size_t = 0 )

Fills all memory with the specified value.

Parameters
Thebyte value used to fill.
filllength
filloffset

◆ get() [1/2]

std::uint8_t * ACQUA::Buffer::get ( )
inline

Returns a pointer to the first byte by taking the address of front().

Returns
A non-owning std::uint8_t* pointing to the first element (the address of front()). The pointer may be invalidated if the object is modified or destroyed; calling this when the object has no elements has the same undefined behavior as front().

◆ get() [2/2]

const std::uint8_t * ACQUA::Buffer::get ( ) const
inline

Returns a pointer to the first byte (the address of front()).

Returns
A pointer to the first element (const std::uint8_t*). The pointer is valid while the object is not modified or destroyed. Calling this when the container is empty (making front() undefined) is undefined behavior.

◆ get_16() [1/2]

std::uint16_t * ACQUA::Buffer::get_16 ( )
inline

Returns a pointer to a 16-bit unsigned integer by reinterpret_cast-ing the pointer returned by get(). No runtime checks are performed.

Returns
A std::uint16_t* that points to the same address as get(), reinterpreted as a pointer to std::uint16_t. The pointer may be null or invalid if the original pointer is null or not correctly aligned/compatible.

◆ get_16() [2/2]

const std::uint16_t * ACQUA::Buffer::get_16 ( ) const
inline

Returns a pointer to the underlying data reinterpreted as a const std::uint16_t pointer.

Returns
A const std::uint16_t* that points to the same memory as get(), obtained via reinterpret_cast<const std::uint16_t*>(get()). May be nullptr if get() returns nullptr. No ownership is transferred.

◆ get_32() [1/2]

std::uint32_t * ACQUA::Buffer::get_32 ( )
inline

Returns a pointer to a 32-bit unsigned integer by reinterpreting the pointer returned by get().

Returns
A std::uint32_t* obtained via reinterpret_cast<std::uint32_t*>(get()). The caller must ensure the underlying object returned by get() is suitable to be accessed as a std::uint32_t to avoid undefined behavior.

◆ get_32() [2/2]

const std::uint32_t * ACQUA::Buffer::get_32 ( ) const
inline

Returns the object's underlying data reinterpreted as a pointer to const std::uint32_t.

Returns
A pointer to const std::uint32_t obtained by reinterpret_cast from get(). The pointer aliases the same memory as returned by get(); ownership and lifetime are unchanged and it may be nullptr if get() returns nullptr.

◆ get_64() [1/2]

std::uint64_t * ACQUA::Buffer::get_64 ( )
inline

Returns a pointer to a 64-bit unsigned integer by reinterpret_casting the pointer returned by get().

Returns
A std::uint64_t* that points to the same memory as get(), reinterpreted as a pointer to std::uint64_t. The caller must ensure the underlying memory is valid and properly aligned for access as a std::uint64_t.

◆ get_64() [2/2]

const std::uint64_t * ACQUA::Buffer::get_64 ( ) const
inline

Returns a pointer to const std::uint64_t by reinterpreting the pointer returned by get(). This member function is const and does not modify the object.

Returns
A pointer to const std::uint64_t obtained via reinterpret_cast from get(). May be null if get() returns null. The caller must ensure the underlying storage is properly aligned and actually contains uint64_t values; otherwise the behavior is undefined.

◆ get_8() [1/2]

std::uint8_t * ACQUA::Buffer::get_8 ( )
inline

Returns the pointer from get() reinterpreted as a pointer to std::uint8_t.

Returns
A std::uint8_t* that points to the same address as the pointer returned by get(), obtained via reinterpret_cast. May be null if get() returns null; no ownership is transferred.

◆ get_8() [2/2]

const std::uint8_t * ACQUA::Buffer::get_8 ( ) const
inline

Returns a pointer to the underlying data reinterpreted as a pointer to const std::uint8_t.

Returns
A const std::uint8_t* pointing to the same data as get(), obtained via reinterpret_cast. The pointer is valid as long as the underlying object or its data remain valid.

◆ get_char() [1/2]

char * ACQUA::Buffer::get_char ( )
inline

Returns the result of get() reinterpreted as a pointer to char.

Returns
A char* pointing to the same address as the value returned by get(), obtained via reinterpret_cast<char*>. The validity, alignment, and lifetime of the pointer depend on the return value of get().

◆ get_char() [2/2]

const char * ACQUA::Buffer::get_char ( ) const
inline

Returns the result of get() reinterpreted as a pointer to const char.

Returns
A const char* pointer obtained by reinterpret_cast from the value returned by get(). The function is a const member and does not modify object state.

◆ get_string()

std::string ACQUA::Buffer::get_string ( ) const
inline

Returns a std::string containing the buffer's contents.

Returns
A std::string

◆ get_string_list()

bool ACQUA::Buffer::get_string_list ( std::list< std::string > & ,
bool tab = false ) const

Extracts lines of text from the buffer and populates a list of strings.

Parameters
liReference to a std::list<std::string> that will be filled with the extracted lines.
tabIf true, tab characters are preserved; otherwise, they are treated as invalid control characters.

◆ insert() [1/2]

std::vector< std::uint8_t >::iterator ACQUA::Buffer::insert ( std::vector< std::uint8_t >::const_iterator i,
const std::uint8_t * s,
const std::uint8_t * e )

Inserts the bytes in the half-open range [s, e) into a std::vector<std::uint8_t> before the position i.

Parameters
iIterator specifying the position in the target vector before which the bytes will be inserted (a std::vector<std::uint8_t>::const_iterator).
sPointer to the first byte to insert (inclusive).
ePointer one past the last byte to insert (exclusive).
Returns
A std::vector<std::uint8_t>::iterator pointing to the first of the newly inserted bytes, or to the insertion position if no elements were inserted. Note: inserting into the vector may reallocate and invalidate existing iterators and references.

◆ insert() [2/2]

std::vector< std::uint8_t >::iterator ACQUA::Buffer::insert ( std::vector< std::uint8_t >::const_iterator i,
std::vector< std::uint8_t >::const_iterator s,
std::vector< std::uint8_t >::const_iterator e )

Inserts a range of bytes into the vector before the specified position.

Parameters
iIterator specifying the position in the vector before which the new elements will be inserted.
sConst iterator to the first element of the source range to insert (inclusive).
eConst iterator one past the last element of the source range to insert (exclusive).
Returns
Iterator pointing to the first inserted element. If no elements are inserted, returns an iterator equivalent to the insertion position i.

◆ operator+=()

Buffer & ACQUA::Buffer::operator+= ( BufferCS_const buf)

Appends the contents of the given buffer to this buffer.

Parameters
bufThe buffer whose contents will be appended to this buffer.
Returns
A reference to this Buffer object after the append (i.e., *this).

◆ operator=()

Buffer & ACQUA::Buffer::operator= ( BufferCS_const )

assignment

Parameters
Originaldata to be overwritten
Returns
myself

◆ resize() [1/2]

void ACQUA::Buffer::resize ( std::size_t si)
inline

Change the actual memory size.

Parameters
siThe new size for the container (number of bytes).

◆ resize() [2/2]

void ACQUA::Buffer::resize ( std::size_t si,
std::uint8_t fl )
inline

Resizes the underlying byte container to the specified size, fills its contents with the given byte value.

Parameters
siThe new size for the container (number of bytes).
flThe byte value used to fill the container after resizing.

◆ resize_noremap() [1/2]

bool ACQUA::Buffer::resize_noremap ( std::size_t si)
inline

Change the length without altering the actual memory size. if the size is zero, free the memory.

Parameters
siSpecified size
Returns
true when the size has been changed (vector::resize)

◆ resize_noremap() [2/2]

bool ACQUA::Buffer::resize_noremap ( std::size_t si,
std::uint8_t fl )
inline

Change the length without altering the actual memory size. if the size is zero, free the memory.

Parameters
siSpecified size
flThe byte value used to fill the container after resizing.
Returns
true when the size has been changed

◆ size()

std::size_t ACQUA::Buffer::size ( ) const
inline

Returns the number of elements. If NoRemapSize is non-zero, that value is returned; otherwise the function returns the underlying std::vector<std::uint8_t>::size().

Returns
The number of elements as std::size_t. Preferentially returns NoRemapSize when it is non-zero; otherwise returns the vector's size.

◆ swap()

void ACQUA::Buffer::swap ( Buffer & in)

Swaps the contents of the specified Buffer.

Parameters
inReference to the Buffer whose contents will be swapped. The buffer is modified by this call.

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