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 specialized buffer that extends the functionality of the Shared
buffer by integrating an external Reader
class.
More...
#include <external.hxx>
Public Member Functions | |
External (const Reader &reader) noexcept | |
Constructs an External buffer with a specified Reader instance. | |
External (Reader &&reader) noexcept | |
Constructs an External buffer taking ownership of a specified Reader instance. | |
External (const External &other)=default | |
Copy constructor. | |
External (External &&other) noexcept=default | |
Move constructor. | |
~External () noexcept override=default | |
Destructor. Cleans up the buffer and releases any associated resources. | |
External & | operator= (const External &other)=default |
Copy assignment operator. | |
External & | operator= (External &&other) noexcept=default |
Move assignment operator. | |
External & | operator<< (const Buffer::Status &status) |
Sets the buffer status. | |
External & | operator<< (const Simple &buffer) |
Appends data from another buffer to this buffer. | |
External & | operator<< (Simple &&buffer) |
Moves data from another buffer and appends it to this buffer. | |
External & | operator<< (const std::string &data) |
Appends a string to the buffer. | |
External & | operator<< (const Buffer::Data &data) |
Appends a byte vector to the buffer. | |
External & | operator<< (Buffer::Data &&data) |
Moves a byte vector and appends it to the buffer. | |
template<typename NumericType , typename = std::enable_if_t<std::is_arithmetic_v<std::decay_t<NumericType>>>> | |
External & | operator<< (const NumericType &value) |
Appends a numeric value to the buffer. | |
External & | operator>> (External &buffer) |
Appends the current buffer's data to another buffer. | |
void | Reader (const class Reader &reader) noexcept |
Sets the external Reader instance. | |
void | Reader (class Reader &&reader) noexcept |
Sets the external Reader instance taking ownership of it. | |
bool | HasEnoughData (const std::size_t &length) override |
Checks if the buffer has enough data to satisfy a read request. | |
ExpectedData< BufferOverflow > | Read (const size_t &length) const override |
Reads a specific size of data from the buffer. | |
![]() | |
Shared () noexcept | |
Default constructor Initializes an empty shared buffer. | |
Shared (const std::size_t &size) | |
Constructor reserving initial size. | |
Shared (const char *data, const std::size_t &length) | |
Constructor. | |
Shared (const std::string &data) | |
Constructor. | |
Shared (const Buffer::Data &data) | |
Constructor. | |
Shared (Buffer::Data &&data) | |
Constructor. | |
Shared (const std::span< const Byte > &data) | |
Constructor. | |
Shared (const Shared &other) | |
Copy constructor. | |
Shared (Shared &&other) noexcept | |
Move constructor. | |
Shared (const Simple &other) | |
Constructor. | |
Shared (Simple &&other) noexcept | |
Move constructor. | |
virtual | ~Shared () noexcept override=default |
Destructor Cleans up the shared buffer. | |
Shared & | operator= (const Shared &other) |
Copy assignment operator. | |
Shared & | operator= (Shared &&other) noexcept |
Move assignment operator. | |
Shared & | operator<< (const Status &status) |
Sets the buffer status. | |
Shared & | operator<< (const Simple &buffer) |
Appends a buffer to the current buffer Thread-safe version of. | |
Shared & | operator<< (Simple &&buffer) |
Moves a buffer and appends to the current buffer Thread-safe version of. | |
Shared & | operator<< (const std::string &data) |
Appends a string to the current shared buffer Thread-safe version of. | |
Shared & | operator<< (const Buffer::Data &data) |
Appends a byte vector to the current shared buffer Thread-safe version of. | |
Shared & | operator<< (Buffer::Data &&data) |
Moves a byte vector and appends to the current shared buffer Thread-safe version of. | |
template<typename NumericType , typename = std::enable_if_t<std::is_arithmetic_v<std::decay_t<NumericType>>>> | |
Shared & | operator<< (const NumericType &value) |
Appends a numeric value to the current simple buffer. | |
Shared & | operator>> (Shared &buffer) |
Appends current shared buffer to target shared buffer Thread-safe version of. | |
virtual size_t | AvailableBytes () const noexcept |
Gets the available bytes to read from current position. | |
size_t | Capacity () const noexcept override |
Retrieves the capacity of the shared buffer Thread-safe version of. | |
void | Clear () noexcept override |
Clears the shared buffer Thread-safe version of. | |
Buffer::Data | Data () const noexcept override |
Retrieves a copy of the buffer data Thread-safe version of. | |
void | Discard (const std::size_t &length, const Read::Position &mode) noexcept override |
Discards data from the buffer Thread-safe version of. | |
bool | End () const noexcept override |
Checks if the read position is at the end Thread-safe version of. | |
bool | Empty () const noexcept override |
Checks if the shared buffer is empty Thread-safe version of. | |
virtual ExpectedData< BufferOverflow > | Extract (const size_t &length) override |
Extracts a specific size of data, taking ownership of the read data and removing it from the shared buffer. | |
virtual Read::Status | ExtractInto (const size_t &length, Shared &output) noexcept |
Extracts a specific size of data and moves it directly into the provided buffer. | |
std::string | HexData (const std::size_t &column_size=16) const override |
Retrieves the stored value as a hexadecimal string Thread-safe version of. | |
bool | IsEoF () const noexcept override |
Checks if the buffer is at the end of the file/data in case its write end have been closed. | |
bool | IsReadable () const noexcept |
Checks if the buffer is readable. | |
bool | IsWritable () const noexcept |
Checks if the buffer is writable. | |
void | Lock () |
Locks the shared buffer for exclusive access Prevents other threads from reading or writing to the buffer until Unlock() is called. | |
ExpectedByte< BufferOverflow > | Peek () const override |
Peeks at the next byte in the shared buffer without advancing the read position Thread-safe version of. | |
std::size_t | Position () const noexcept override |
Retrieves the read position Thread-safe version of. | |
void | Reserve (const std::size_t &size) override |
Reserves shared buffer size Thread-safe version of. | |
void | Seek (const std::ptrdiff_t &position, const Read::Position &mode) const override |
Moves the read pointer within the shared buffer based on the specified position and mode Thread-safe version of. | |
std::size_t | Size () const noexcept override |
Retrieves the length of the shared buffer Thread-safe version of. | |
enum Status | Status () const noexcept |
Gets the buffer status. | |
void | Unlock () |
Unlocks the shared buffer, releasing exclusive access Allows other threads to access the buffer after it has been locked using Lock() . | |
Write::Status | Write (const Simple &buffer) override |
Writes a simple buffer to the current shared buffer Thread-safe version of. | |
Write::Status | Write (Simple &&buffer) override |
Moves a simple buffer and writes it to the current shared buffer Thread-safe version of. | |
Write::Status | Write (const std::string &data) override |
Writes a string to the current shared buffer Thread-safe version of. | |
Write::Status | Write (const Buffer::Data &data) override |
Writes a byte vector to the current shared buffer Thread-safe version of. | |
Write::Status | Write (Buffer::Data &&data) override |
Moves a byte vector and writes it to the current shared buffer Thread-safe version of. | |
![]() | |
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. | |
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 Read::Status | ExtractInto (const size_t &length, Simple &output) noexcept |
Extracts a specific size of data and moves it directly into the provided buffer. | |
Read::Status | Process (const std::size_t &length, Processor function, Simple &output) noexcept |
Extracts, processes, and stores the results in the provided 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. | |
Additional Inherited Members | |
![]() | |
std::shared_mutex | m_data_mutex |
Mutex for thread safety. | |
std::atomic< enum Status > | m_status |
Buffer status. | |
![]() | |
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 specialized buffer that extends the functionality of the Shared
buffer by integrating an external Reader
class.
The External
buffer builds upon the Shared
buffer by allowing an external Reader
class to dynamically fetch or generate data before every read operation. This enables integration with external sources such as files, network streams, or other producers.
Key Features:
Reader
class when needed.Shared
buffer.EoF
(End of File) or Error
based on the Reader
's return value.Behavior: This class expects to have an external Reader
to fill its internal buffer. The AvailableBytes()
method will only return the number of bytes currently available in the buffer without invoking the Reader
. To ensure the Reader
is called and the buffer is populated with the latest data, use HasEnoughData()
or Wait()
.
The HasEnoughData(size_t length)
and Wait(size_t length)
methods take a parameter specifying the number of bytes required. These methods will invoke the Reader
repeatedly until the specified number of bytes is available in the buffer or the Reader
returns an error. If an error occurs, the buffer is marked as read-only.
This class is ideal for scenarios where data is not readily available in memory and must be fetched or generated dynamically during read operations.
Constructs an External
buffer with a specified Reader
instance.
reader | The external Reader instance to be used for dynamic data retrieval. |
The Reader
class provides the Read()
method, which dynamically fetches or generates data to populate the buffer before read operations. For more details, see the Reader
class documentation.
|
noexcept |
Constructs an External
buffer taking ownership of a specified Reader
instance.
reader | The external Reader instance to be used for dynamic data retrieval. |
The Reader
class provides the Read()
method, which dynamically fetches or generates data to populate the buffer before read operations. For more details, see the Reader
class documentation.
|
defaultnoexcept |
|
overridedefaultnoexcept |
Checks if the buffer has enough data to satisfy a read request.
length | The number of bytes to check for. |
true
if enough data is available, false
otherwise.This method transparently calls the Reader
's Read()
method to ensure the buffer is populated with the latest data before performing the check.
Reimplemented from StormByte::Buffer::Shared.
|
virtual |
Moves a byte vector and appends it to the buffer.
data | The byte vector to move and append. |
Extends the Shared
buffer's appending functionality to support external reader integration.
Reimplemented from StormByte::Buffer::Simple.
|
virtual |
Appends a byte vector to the buffer.
data | The byte vector to append. |
Extends the Shared
buffer's appending functionality to support external reader integration.
Reimplemented from StormByte::Buffer::Simple.
External & StormByte::Buffer::External::operator<< | ( | const Buffer::Status & | status | ) |
Sets the buffer status.
status | The new status to set. |
Extends the Shared
buffer's status management by supporting external reader integration.
|
inline |
Appends a numeric value to the buffer.
NumericType | The type of the numeric value to append. |
value | The numeric value to append. |
The numeric value is serialized into its binary representation and appended to the buffer. Extends the Shared
buffer's appending functionality to support external reader integration.
Appends data from another buffer to this buffer.
buffer | The source buffer to append from. |
Extends the Shared
buffer's appending functionality to support external reader integration.
Reimplemented from StormByte::Buffer::Simple.
Appends a string to the buffer.
data | The string to append. |
Extends the Shared
buffer's appending functionality to support external reader integration.
Reimplemented from StormByte::Buffer::Simple.
Moves data from another buffer and appends it to this buffer.
buffer | The source buffer to move from. |
Extends the Shared
buffer's appending functionality to support external reader integration.
Reimplemented from StormByte::Buffer::Simple.
Appends the current buffer's data to another buffer.
buffer | The target buffer to append to. |
Extends the Shared
buffer's appending functionality to support external reader integration.
|
overridevirtual |
Reads a specific size of data from the buffer.
length | The number of bytes to read. |
BufferOverflow
error if insufficient data exists.This method waits for the requested data to become available while the buffer is readable.
Reimplemented from StormByte::Buffer::Shared.
Sets the external Reader
instance taking ownership of it.
reader | The external Reader instance to set. |
The Reader
class provides the Read()
method, which dynamically fetches or generates data to populate the buffer before read operations. For more details, see the Reader
class documentation.