StormByte C++ Library 0.0.9999
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
StormByte::Buffer::Simple Class Reference

A lightweight class for storing and manipulating simple byte buffers. More...

#include <simple.hxx>

Inheritance diagram for StormByte::Buffer::Simple:
Inheritance graph
[legend]

Public Member Functions

 Simple () noexcept
 Default constructor Initializes an empty simple buffer.
 
 Simple (const std::size_t &size)
 Constructor reserving initial size.
 
 Simple (const char *data, const std::size_t &length)
 Constructor.
 
 Simple (const std::string &data)
 Constructor.
 
 Simple (const Data &data)
 Constructor.
 
 Simple (Data &&data)
 Constructor.
 
 Simple (const std::span< const Byte > &data)
 Constructor.
 
 Simple (const Simple &other)=default
 Copy constructor.
 
 Simple (Simple &&other) noexcept=default
 Move constructor.
 
virtual ~Simple () noexcept=default
 Destructor Cleans up the simple buffer.
 
Simpleoperator= (const Simple &other)=default
 Copy assignment operator.
 
Simpleoperator= (Simple &&other) noexcept=default
 Move assignment operator.
 
virtual Simpleoperator<< (const Data &data)
 Appends a byte vector to the current simple buffer.
 
virtual Simpleoperator<< (Data &&data)
 Moves a byte vector and appends to the current simple buffer.
 
virtual Simpleoperator<< (const Simple &buffer)
 Appends a simple buffer to the current simple buffer.
 
virtual Simpleoperator<< (Simple &&buffer)
 Moves a simple buffer and appends to the current simple buffer.
 
virtual Simpleoperator<< (const std::string &data)
 Appends a string to the current simple buffer.
 
template<typename NumericType , typename = std::enable_if_t<std::is_arithmetic_v<std::decay_t<NumericType>>>>
Simpleoperator<< (const NumericType &value)
 Appends a numeric value to the current simple buffer.
 
virtual Simpleoperator>> (Simple &buffer)
 Appends current simple buffer to target simple buffer.
 
virtual size_t AvailableBytes () const noexcept
 Gets the available bytes to read from current position.
 
virtual size_t Capacity () const noexcept
 Retrieves the capacity of the simple buffer.
 
virtual void Clear ()
 Clears the simple buffer Removes all data and resets the read position.
 
virtual Buffer::Data Data () const noexcept
 Retrieves a copy of the buffer data.
 
virtual void Discard (const std::size_t &length, const Read::Position &mode=Read::Position::Relative) noexcept
 Discards data from the buffer.
 
virtual bool Empty () const noexcept
 Checks if the simple buffer is empty.
 
virtual bool End () const noexcept
 Checks if the read position is at the end.
 
virtual ExpectedData< BufferOverflowExtract (const size_t &length)
 Extracts a specific size of data, taking ownership of the read data and removing it from the simple buffer.
 
virtual Read::Status ExtractInto (const size_t &length, Simple &output) noexcept
 Extracts a specific size of data and moves it directly into the provided buffer.
 
virtual bool HasEnoughData (const std::size_t &length) const
 Checks if the simple buffer has enough data starting from the current read position.
 
virtual std::string HexData (const std::size_t &column_size=16) const
 Retrieves the stored value as a hexadecimal string.
 
virtual bool IsEoF () const noexcept
 Checks if the buffer is at the end of the file/data.
 
virtual ExpectedByte< BufferOverflowPeek () const
 Retrieves the next byte without incrementing the read position.
 
virtual std::size_t Position () const noexcept
 Retrieves the read position.
 
Read::Status Process (const std::size_t &length, Processor function, Simple &output) noexcept
 Extracts, processes, and stores the results in the provided buffer.
 
virtual ExpectedData< BufferOverflowRead (const size_t &length) const
 Reads a specific size of data starting from the current read position.
 
virtual void Reserve (const std::size_t &size)
 Reserves simple buffer size Ensures the simple buffer has enough capacity for the specified size.
 
virtual void Seek (const std::ptrdiff_t &position, const Read::Position &mode) const
 Moves the read pointer within the simple buffer based on the specified position and mode.
 
virtual std::size_t Size () const noexcept
 Retrieves the length of the simple buffer.
 
const std::span< const Byte > Span () const noexcept
 Retrieves a const view (span) to the stored value.
 
std::span< Byte > Span () noexcept
 Retrieves a view (span) to the stored value.
 
virtual Write::Status Write (const Buffer::Data &data)
 Writes a byte vector to the current simple buffer.
 
virtual Write::Status Write (Buffer::Data &&data)
 Moves a byte vector and writes it to the current simple buffer.
 
virtual Write::Status Write (const Simple &buffer)
 Writes a simple buffer to the current simple buffer.
 
virtual Write::Status Write (Simple &&buffer)
 Moves a simple buffer and writes it to the current simple buffer.
 
virtual Write::Status Write (const std::string &data)
 Writes a string to the current simple buffer.
 

Protected Attributes

std::vector< std::byte > m_data
 Stored value.
 
std::size_t m_position
 Read position.
 
std::size_t m_minimum_chunk_size
 Minimum chunk size for buffer operations.
 

Detailed Description

A lightweight class for storing and manipulating simple byte buffers.

Forward declaration of the Simple class.

The Simple class provides a lightweight and efficient way to store and manipulate byte data. It supports various operations such as appending, extracting, reading, and seeking within the buffer.

Key Features:

This class is ideal for scenarios where performance is critical, and thread safety is not required.

Constructor & Destructor Documentation

◆ Simple() [1/8]

StormByte::Buffer::Simple::Simple ( const std::size_t &  size)
explicit

Constructor reserving initial size.

Parameters
sizeSize of the buffer to reserve.

◆ Simple() [2/8]

StormByte::Buffer::Simple::Simple ( const char data,
const std::size_t &  length 
)

Constructor.

Parameters
dataPointer to the data to set.
lengthLength of the data.
Note
The data is copied into the buffer.

◆ Simple() [3/8]

StormByte::Buffer::Simple::Simple ( const std::string &  data)

Constructor.

Parameters
dataString to set as buffer content.

◆ Simple() [4/8]

StormByte::Buffer::Simple::Simple ( const Data data)

Constructor.

Parameters
dataVector of bytes to set as buffer content.

◆ Simple() [5/8]

StormByte::Buffer::Simple::Simple ( Data &&  data)

Constructor.

Parameters
dataVector of bytes to move into the buffer.

◆ Simple() [6/8]

StormByte::Buffer::Simple::Simple ( const std::span< const Byte > &  data)

Constructor.

Parameters
dataSpan of bytes to set as buffer content.

◆ Simple() [7/8]

StormByte::Buffer::Simple::Simple ( const Simple other)
default

Copy constructor.

Parameters
otherSimple buffer to copy from.

◆ Simple() [8/8]

StormByte::Buffer::Simple::Simple ( Simple &&  other)
defaultnoexcept

Move constructor.

Parameters
otherSimple buffer to move from.

Member Function Documentation

◆ AvailableBytes()

virtual size_t StormByte::Buffer::Simple::AvailableBytes ( ) const
virtualnoexcept

Gets the available bytes to read from current position.

Returns
Number of bytes available to read.

Reimplemented in StormByte::Buffer::Shared.

◆ Capacity()

virtual size_t StormByte::Buffer::Simple::Capacity ( ) const
virtualnoexcept

Retrieves the capacity of the simple buffer.

Returns
The total capacity of the buffer.

Reimplemented in StormByte::Buffer::Shared.

◆ Clear()

virtual void StormByte::Buffer::Simple::Clear ( )
virtual

Clears the simple buffer Removes all data and resets the read position.

Reimplemented in StormByte::Buffer::Shared.

◆ Data()

virtual Buffer::Data StormByte::Buffer::Simple::Data ( ) const
virtualnoexcept

Retrieves a copy of the buffer data.

This method returns a copy of the data stored in the buffer. It is suitable for scenarios where the caller needs to work with an independent copy of the buffer's contents.

Returns
A copy of the buffer data as a vector of bytes.

Reimplemented in StormByte::Buffer::Shared.

◆ Discard()

virtual void StormByte::Buffer::Simple::Discard ( const std::size_t &  length,
const Read::Position &  mode = Read::Position::Relative 
)
virtualnoexcept

Discards data from the buffer.

Removes data from the buffer starting from the beginning up to the current read position. The discard operation can be performed in different modes:

  • Relative: Discards data relative to the current read position.
  • Absolute: Discards data up to the specified absolute position.
Parameters
lengthThe number of bytes to discard.
modeThe mode to use for discarding (default is Read::Position::Relative).
Note
If the specified length exceeds the buffer size, the entire buffer is discarded.

Reimplemented in StormByte::Buffer::Shared.

◆ Empty()

virtual bool StormByte::Buffer::Simple::Empty ( ) const
virtualnoexcept

Checks if the simple buffer is empty.

Returns
True if the simple buffer is empty, false otherwise.

Reimplemented in StormByte::Buffer::Shared.

◆ End()

virtual bool StormByte::Buffer::Simple::End ( ) const
virtualnoexcept

Checks if the read position is at the end.

Returns
True if the read position is at the end, false otherwise.

Reimplemented in StormByte::Buffer::Shared.

◆ Extract()

virtual ExpectedData< BufferOverflow > StormByte::Buffer::Simple::Extract ( const size_t length)
virtual

Extracts a specific size of data, taking ownership of the read data and removing it from the simple buffer.

Parameters
lengthLength of the data to read and remove from the simple buffer.
Returns
ExpectedDataType containing the requested data, or an Unexpected with a BufferOverflow error if insufficient data exists.

Reimplemented in StormByte::Buffer::Shared.

◆ ExtractInto()

virtual Read::Status StormByte::Buffer::Simple::ExtractInto ( const size_t length,
Simple output 
)
virtualnoexcept

Extracts a specific size of data and moves it directly into the provided buffer.

Thread-safe version of

See also
Extract. This function is a more efficient alternative to Extract, as it avoids copying data by moving it directly into the target buffer. The read position is advanced by the specified length.
Parameters
lengthLength of the data to extract.
outputBuffer where the extracted data will be moved.
Returns
Read::Status indicating the success or failure of the operation.

◆ HasEnoughData()

virtual bool StormByte::Buffer::Simple::HasEnoughData ( const std::size_t &  length) const
virtual

Checks if the simple buffer has enough data starting from the current read position.

Parameters
lengthLength of the data to check.
Returns
True if the simple buffer has enough data starting from the current position, false otherwise.

Reimplemented in StormByte::Buffer::Shared.

◆ HexData()

virtual std::string StormByte::Buffer::Simple::HexData ( const std::size_t &  column_size = 16) const
virtual

Retrieves the stored value as a hexadecimal string.

Converts the buffer's contents into a human-readable hexadecimal string representation. This is useful for debugging or logging purposes.

Parameters
column_sizeNumber of bytes per column in the output. Defaults to 16.
Returns
Hexadecimal string representation of the stored value.

Reimplemented in StormByte::Buffer::Shared.

◆ IsEoF()

virtual bool StormByte::Buffer::Simple::IsEoF ( ) const
virtualnoexcept

Checks if the buffer is at the end of the file/data.

Returns
True if the buffer is at the end, false otherwise.

Reimplemented in StormByte::Buffer::Shared.

◆ operator<<() [1/6]

virtual Simple & StormByte::Buffer::Simple::operator<< ( const Data data)
virtual

Appends a byte vector to the current simple buffer.

Parameters
dataByte vector to append.
Returns
Reference to the updated simple buffer.
Note
This operation does not modify the read position.

Reimplemented in StormByte::Buffer::Shared.

◆ operator<<() [2/6]

template<typename NumericType , typename = std::enable_if_t<std::is_arithmetic_v<std::decay_t<NumericType>>>>
Simple & StormByte::Buffer::Simple::operator<< ( const NumericType value)
inline

Appends a numeric value to the current simple buffer.

This templated method allows appending numeric values (e.g., integers, floating-point numbers) to the buffer. The numeric value is serialized into its binary representation and appended to the buffer.

Template Parameters
NumericTypeThe type of the numeric value to append.
Parameters
valueThe numeric value to append.
Returns
Reference to the updated simple buffer.

◆ operator<<() [3/6]

virtual Simple & StormByte::Buffer::Simple::operator<< ( const Simple buffer)
virtual

Appends a simple buffer to the current simple buffer.

Parameters
bufferSimple buffer to append.
Returns
Reference to the updated simple buffer.

Reimplemented in StormByte::Buffer::Shared.

◆ operator<<() [4/6]

virtual Simple & StormByte::Buffer::Simple::operator<< ( const std::string &  data)
virtual

Appends a string to the current simple buffer.

Parameters
dataString to append.
Returns
Reference to the updated simple buffer.

Reimplemented in StormByte::Buffer::Shared.

◆ operator<<() [5/6]

virtual Simple & StormByte::Buffer::Simple::operator<< ( Data &&  data)
virtual

Moves a byte vector and appends to the current simple buffer.

Parameters
dataByte vector to append.
Returns
Reference to the updated simple buffer.

Reimplemented in StormByte::Buffer::Shared.

◆ operator<<() [6/6]

virtual Simple & StormByte::Buffer::Simple::operator<< ( Simple &&  buffer)
virtual

Moves a simple buffer and appends to the current simple buffer.

Parameters
bufferSimple buffer to append.
Returns
Reference to the updated simple buffer.

Reimplemented in StormByte::Buffer::Shared.

◆ operator=() [1/2]

Simple & StormByte::Buffer::Simple::operator= ( const Simple other)
default

Copy assignment operator.

Parameters
otherSimple buffer to copy from.
Returns
Reference to the updated simple buffer.

◆ operator=() [2/2]

Simple & StormByte::Buffer::Simple::operator= ( Simple &&  other)
defaultnoexcept

Move assignment operator.

Parameters
otherSimple buffer to move from.
Returns
Reference to the updated simple buffer.

◆ operator>>()

virtual Simple & StormByte::Buffer::Simple::operator>> ( Simple buffer)
virtual

Appends current simple buffer to target simple buffer.

Parameters
bufferTarget simple buffer to append to.
Returns
Reference to the updated simple buffer.

◆ Peek()

virtual ExpectedByte< BufferOverflow > StormByte::Buffer::Simple::Peek ( ) const
virtual

Retrieves the next byte without incrementing the read position.

This method allows peeking at the next byte in the buffer without advancing the read position. It is useful for inspecting the next value without modifying the state of the buffer.

Returns
ExpectedByte containing the next byte, or an Unexpected with a BufferOverflow error if there is no more data.

Reimplemented in StormByte::Buffer::Shared.

◆ Position()

virtual std::size_t StormByte::Buffer::Simple::Position ( ) const
virtualnoexcept

Retrieves the read position.

Returns
Current read position in the simple buffer.

Reimplemented in StormByte::Buffer::Shared.

◆ Process()

Read::Status StormByte::Buffer::Simple::Process ( const std::size_t &  length,
Processor  function,
Simple output 
)
noexcept

Extracts, processes, and stores the results in the provided buffer.

This method performs three operations in a single step:

  • Extracts a specific size of data from the buffer.
  • Applies a user-provided processing function to the extracted data.
  • Stores the processed results in the provided output buffer.

This approach is much more efficient than performing the three operations separately, as it minimizes intermediate copies and reduces overhead.

Parameters
lengthThe number of bytes to extract and process.
functionA user-provided processing function to apply to the extracted data.
outputThe buffer where the processed results will be stored.
Returns
Read::Status indicating the success or failure of the operation.

◆ Read()

virtual ExpectedData< BufferOverflow > StormByte::Buffer::Simple::Read ( const size_t length) const
virtual

Reads a specific size of data starting from the current read position.

This method retrieves a copy of the requested data from the buffer, starting at the current read position. The read position is advanced by the specified length. If the buffer does not contain enough data, a BufferOverflow error is returned.

Parameters
lengthLength of the data to read.
Returns
ExpectedDataType containing a copy of the requested data, or an Unexpected with a BufferOverflow error if insufficient data exists.

Reimplemented in StormByte::Buffer::Shared.

◆ Reserve()

virtual void StormByte::Buffer::Simple::Reserve ( const std::size_t &  size)
virtual

Reserves simple buffer size Ensures the simple buffer has enough capacity for the specified size.

Parameters
sizeSize to reserve.

Reimplemented in StormByte::Buffer::Shared.

◆ Seek()

virtual void StormByte::Buffer::Simple::Seek ( const std::ptrdiff_t &  position,
const Read::Position &  mode 
) const
virtual

Moves the read pointer within the simple buffer based on the specified position and mode.

Parameters
positionThe position to move to, interpreted based on the specified mode.
modeThe mode to use for seeking (e.g., Begin, End, Relative, Absolute).

Reimplemented in StormByte::Buffer::Shared.

◆ Size()

virtual std::size_t StormByte::Buffer::Simple::Size ( ) const
virtualnoexcept

Retrieves the length of the simple buffer.

Returns
Length of the simple buffer.

Reimplemented in StormByte::Buffer::Shared.

◆ Span() [1/2]

const std::span< const Byte > StormByte::Buffer::Simple::Span ( ) const
noexcept

Retrieves a const view (span) to the stored value.

This method provides a lightweight, read-only view of the buffer's contents without copying the data. The returned span remains valid as long as the buffer is not modified.

Returns
A read-only span of the stored value.
Note
Modifying the buffer invalidates the returned span.

◆ Span() [2/2]

std::span< Byte > StormByte::Buffer::Simple::Span ( )
noexcept

Retrieves a view (span) to the stored value.

This method provides a lightweight, mutable view of the buffer's contents without copying the data. The returned span remains valid as long as the buffer is not modified.

Returns
A mutable span of the stored value.
Note
Modifying the buffer invalidates the returned span.

◆ Write() [1/5]

virtual Write::Status StormByte::Buffer::Simple::Write ( Buffer::Data &&  data)
virtual

Moves a byte vector and writes it to the current simple buffer.

This function is provided for polymorphic use cases where operator<< cannot be used.

Parameters
dataByte vector to write.
Returns
Write::Status of the operation.

Reimplemented in StormByte::Buffer::Shared.

◆ Write() [2/5]

virtual Write::Status StormByte::Buffer::Simple::Write ( const Buffer::Data &  data)
virtual

Writes a byte vector to the current simple buffer.

This function is provided for polymorphic use cases where operator<< cannot be used.

Parameters
dataByte vector to write.
Returns
Write::Status of the operation.

Reimplemented in StormByte::Buffer::Shared.

◆ Write() [3/5]

virtual Write::Status StormByte::Buffer::Simple::Write ( const Simple buffer)
virtual

Writes a simple buffer to the current simple buffer.

This function is provided for polymorphic use cases where operator<< cannot be used.

Parameters
bufferSimple buffer to write.
Returns
Write::Status of the operation.

Reimplemented in StormByte::Buffer::Shared.

◆ Write() [4/5]

virtual Write::Status StormByte::Buffer::Simple::Write ( const std::string &  data)
virtual

Writes a string to the current simple buffer.

This function is provided for polymorphic use cases where operator<< cannot be used.

Parameters
dataString to write.
Returns
Write::Status of the operation.

Reimplemented in StormByte::Buffer::Shared.

◆ Write() [5/5]

virtual Write::Status StormByte::Buffer::Simple::Write ( Simple &&  buffer)
virtual

Moves a simple buffer and writes it to the current simple buffer.

This function is provided for polymorphic use cases where operator<< cannot be used.

Parameters
bufferSimple buffer to write.
Returns
Write::Status of the operation.

Reimplemented in StormByte::Buffer::Shared.


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