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 read-only interface for accessing a shared buffer. More...
#include <consumer.hxx>
Public Member Functions | |
Consumer (const Consumer &other)=default | |
Deleted copy constructor. | |
Consumer (Consumer &&other) noexcept=default | |
Default move constructor. | |
~Consumer () noexcept=default | |
Destructor. | |
Consumer & | operator= (const Consumer &other)=default |
Deleted copy assignment operator. | |
Consumer & | operator= (Consumer &&other) noexcept=default |
Default move assignment operator. | |
std::size_t | AvailableBytes () const noexcept |
Retrieves the number of bytes available for reading. | |
Buffer::Data | Data () const noexcept |
Retrieves a copy of the buffer data. | |
void | Discard (const std::size_t &length, const Read::Position &mode) noexcept |
Discards data from the buffer. | |
bool | End () const noexcept |
Checks if the read position is at the end. | |
bool | Empty () const noexcept |
Checks if the shared buffer is empty. | |
ExpectedData< BufferOverflow > | Extract (const size_t &length) |
Extracts a specific size of data, taking ownership of the read data and removing it from the shared buffer. | |
Read::Status | ExtractInto (const size_t &length, Shared &output) noexcept |
Extracts a specific size of data and moves it directly into the provided buffer. | |
bool | HasEnoughData (const std::size_t &length) const |
Checks if the shared buffer has enough data starting from the current read position. | |
std::string | HexData (const std::size_t &column_size=16) const |
Retrieves the stored value as a hexadecimal string. | |
bool | IsEoF () const noexcept |
Checks if the buffer is at the end of the file/data. | |
bool | IsReadable () const noexcept |
Checks if the buffer is readable. | |
ExpectedByte< BufferOverflow > | Peek () const |
Peeks at the next byte in the shared buffer without advancing the read position. | |
std::size_t | Position () const noexcept |
Retrieves the read position. | |
ExpectedData< BufferOverflow > | Read (const size_t &length) const |
Reads a specific size of data starting from the current read position. | |
void | Seek (const std::ptrdiff_t &position, const Read::Position &mode) const |
Moves the read pointer within the shared buffer based on the specified position and mode. | |
std::size_t | Size () const noexcept |
Retrieves the length of the shared buffer. | |
enum Status | Status () const noexcept |
Gets the buffer status. | |
Friends | |
class | Producer |
A read-only interface for accessing a shared buffer.
Forward declaration of the Consumer
class.
The Consumer
class provides a thread-safe, read-only interface for accessing data in a shared buffer. Instances of Consumer
cannot be created directly; they are created and managed by their Producer
counterpart.
Key Features:
Consumer
cannot be copied to ensure data integrity.Shared
buffer.Consumer
instances are copied, they will share the same buffer. This is allowed, but it is up to the user to ensure that the produced-consumed data flow remains in sync. Deleted copy constructor.
The Consumer
class cannot be copied to ensure data integrity and prevent unintended sharing of the buffer.
|
defaultnoexcept |
Default move constructor.
Allows moving a Consumer
instance. The moved-from instance is left in a valid but unspecified state.
|
defaultnoexcept |
|
noexcept |
Retrieves the number of bytes available for reading.
|
noexcept |
Retrieves a copy of the buffer data.
|
noexcept |
Discards data from the buffer.
length | The number of bytes to discard. |
mode | The read position mode. |
|
noexcept |
Checks if the shared buffer is empty.
|
noexcept |
Checks if the read position is at the end.
ExpectedData< BufferOverflow > StormByte::Buffer::Consumer::Extract | ( | const size_t & | length | ) |
Extracts a specific size of data, taking ownership of the read data and removing it from the shared buffer.
length | The number of bytes to extract. |
|
noexcept |
Extracts a specific size of data and moves it directly into the provided buffer.
length | The number of bytes to extract. |
output | The buffer where the extracted data will be moved. |
Checks if the shared buffer has enough data starting from the current read position.
length | The number of bytes to check. |
std::string StormByte::Buffer::Consumer::HexData | ( | const std::size_t & | column_size = 16 | ) | const |
Retrieves the stored value as a hexadecimal string.
column_size | The number of bytes per column in the output. |
|
noexcept |
Checks if the buffer is at the end of the file/data.
|
noexcept |
Checks if the buffer is readable.
Deleted copy assignment operator.
The Consumer
class cannot be copied to ensure data integrity and prevent unintended sharing of the buffer.
Default move assignment operator.
Allows moving a Consumer
instance. The moved-from instance is left in a valid but unspecified state.
ExpectedByte< BufferOverflow > StormByte::Buffer::Consumer::Peek | ( | ) | const |
Peeks at the next byte in the shared buffer without advancing the read position.
|
noexcept |
Retrieves the read position.
ExpectedData< BufferOverflow > StormByte::Buffer::Consumer::Read | ( | const size_t & | length | ) | const |
Reads a specific size of data starting from the current read position.
length | The number of bytes to read. |
void StormByte::Buffer::Consumer::Seek | ( | const std::ptrdiff_t & | position, |
const Read::Position & | mode | ||
) | const |
Moves the read pointer within the shared buffer based on the specified position and mode.
position | The position to move to. |
mode | The read position mode. |
|
noexcept |
Retrieves the length of the shared buffer.
|
noexcept |
Gets the buffer status.