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).
|
A lightweight class for storing and manipulating simple byte buffers. More...
#include <simple.hxx>
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. | |
Simple & | operator= (const Simple &other)=default |
Copy assignment operator. | |
Simple & | operator= (Simple &&other) noexcept=default |
Move assignment operator. | |
virtual Simple & | operator<< (const Data &data) |
Appends a byte vector to the current simple buffer. | |
virtual Simple & | operator<< (Data &&data) |
Moves a byte vector and appends to the current simple buffer. | |
virtual Simple & | operator<< (const Simple &buffer) |
Appends a simple buffer to the current simple buffer. | |
virtual Simple & | operator<< (Simple &&buffer) |
Moves a simple buffer and appends to the current simple buffer. | |
virtual Simple & | operator<< (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>>>> | |
Simple & | operator<< (const NumericType &value) |
Appends a numeric value to the current simple buffer. | |
virtual Simple & | operator>> (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< BufferOverflow > | Extract (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< BufferOverflow > | Peek () 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< BufferOverflow > | Read (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. | |
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.
|
explicit |
Constructor reserving initial size.
size | Size of the buffer to reserve. |
Constructor.
data | Pointer to the data to set. |
length | Length of the data. |
StormByte::Buffer::Simple::Simple | ( | const std::string & | data | ) |
Constructor.
data | String to set as buffer content. |
Constructor.
data | Vector of bytes to set as buffer content. |
StormByte::Buffer::Simple::Simple | ( | Data && | data | ) |
Constructor.
data | Vector of bytes to move into the buffer. |
Constructor.
data | Span of bytes to set as buffer content. |
Copy constructor.
other | Simple buffer to copy from. |
|
defaultnoexcept |
Move constructor.
other | Simple buffer to move from. |
Gets the available bytes to read from current position.
Reimplemented in StormByte::Buffer::Shared.
Retrieves the capacity of the simple buffer.
Reimplemented in StormByte::Buffer::Shared.
Clears the simple buffer Removes all data and resets the read position.
Reimplemented in StormByte::Buffer::Shared.
|
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.
Reimplemented in StormByte::Buffer::Shared.
|
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:
length | The number of bytes to discard. |
mode | The mode to use for discarding (default is Read::Position::Relative ). |
Reimplemented in StormByte::Buffer::Shared.
Checks if the simple buffer is empty.
Reimplemented in StormByte::Buffer::Shared.
Checks if the read position is at the end.
Reimplemented in StormByte::Buffer::Shared.
|
virtual |
Extracts a specific size of data, taking ownership of the read data and removing it from the simple buffer.
length | Length of the data to read and remove from the simple buffer. |
ExpectedDataType
containing the requested data, or an Unexpected
with a BufferOverflow
error if insufficient data exists. Reimplemented in StormByte::Buffer::Shared.
|
virtualnoexcept |
Extracts a specific size of data and moves it directly into the provided buffer.
Thread-safe version of
Extract
, as it avoids copying data by moving it directly into the target buffer. The read position is advanced by the specified length.length | Length of the data to extract. |
output | Buffer where the extracted data will be moved. |
Read::Status
indicating the success or failure of the operation. Checks if the simple buffer has enough data starting from the current read position.
length | Length of the data to check. |
Reimplemented in StormByte::Buffer::Shared.
|
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.
column_size | Number of bytes per column in the output. Defaults to 16. |
Reimplemented in StormByte::Buffer::Shared.
Checks if the buffer is at the end of the file/data.
Reimplemented in StormByte::Buffer::Shared.
Appends a byte vector to the current simple buffer.
data | Byte vector to append. |
Reimplemented in StormByte::Buffer::Shared.
|
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.
NumericType | The type of the numeric value to append. |
value | The numeric value to append. |
Appends a simple buffer to the current simple buffer.
buffer | Simple buffer to append. |
Reimplemented in StormByte::Buffer::Shared.
Appends a string to the current simple buffer.
data | String to append. |
Reimplemented in StormByte::Buffer::Shared.
Moves a byte vector and appends to the current simple buffer.
data | Byte vector to append. |
Reimplemented in StormByte::Buffer::Shared.
Moves a simple buffer and appends to the current simple buffer.
buffer | Simple buffer to append. |
Reimplemented in StormByte::Buffer::Shared.
Copy assignment operator.
other | Simple buffer to copy from. |
Move assignment operator.
other | Simple buffer to move from. |
Appends current simple buffer to target simple buffer.
buffer | Target simple buffer to append to. |
|
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.
ExpectedByte
containing the next byte, or an Unexpected
with a BufferOverflow
error if there is no more data. Reimplemented in StormByte::Buffer::Shared.
|
virtualnoexcept |
Retrieves the read position.
Reimplemented in StormByte::Buffer::Shared.
|
noexcept |
Extracts, processes, and stores the results in the provided buffer.
This method performs three operations in a single step:
This approach is much more efficient than performing the three operations separately, as it minimizes intermediate copies and reduces overhead.
length | The number of bytes to extract and process. |
function | A user-provided processing function to apply to the extracted data. |
output | The buffer where the processed results will be stored. |
Read::Status
indicating the success or failure of the operation.
|
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.
length | Length of the data to read. |
ExpectedDataType
containing a copy of the requested data, or an Unexpected
with a BufferOverflow
error if insufficient data exists. Reimplemented in StormByte::Buffer::Shared.
Reserves simple buffer size Ensures the simple buffer has enough capacity for the specified size.
size | Size to reserve. |
Reimplemented in StormByte::Buffer::Shared.
|
virtual |
Moves the read pointer within the simple buffer based on the specified position and mode.
position | The position to move to, interpreted based on the specified mode. |
mode | The mode to use for seeking (e.g., Begin , End , Relative , Absolute ). |
Reimplemented in StormByte::Buffer::Shared.
|
virtualnoexcept |
Retrieves the length of the simple buffer.
Reimplemented in StormByte::Buffer::Shared.
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.
|
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.
|
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.
data | Byte vector to write. |
Reimplemented in StormByte::Buffer::Shared.
Writes a byte vector to the current simple buffer.
This function is provided for polymorphic use cases where operator<<
cannot be used.
data | Byte vector to write. |
Reimplemented in StormByte::Buffer::Shared.
Writes a simple buffer to the current simple buffer.
This function is provided for polymorphic use cases where operator<<
cannot be used.
buffer | Simple buffer to write. |
Reimplemented in StormByte::Buffer::Shared.
Writes a string to the current simple buffer.
This function is provided for polymorphic use cases where operator<<
cannot be used.
data | String to write. |
Reimplemented in StormByte::Buffer::Shared.
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.
buffer | Simple buffer to write. |
Reimplemented in StormByte::Buffer::Shared.