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 | Friends | List of all members
StormByte::Buffer::Consumer Class Referencefinal

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.
 
Consumeroperator= (const Consumer &other)=default
 Deleted copy assignment operator.
 
Consumeroperator= (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< BufferOverflowExtract (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< BufferOverflowPeek () 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< BufferOverflowRead (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
 

Detailed Description

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:

Constructor & Destructor Documentation

◆ Consumer() [1/2]

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

Deleted copy constructor.

The Consumer class cannot be copied to ensure data integrity and prevent unintended sharing of the buffer.

◆ Consumer() [2/2]

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

Default move constructor.

Allows moving a Consumer instance. The moved-from instance is left in a valid but unspecified state.

◆ ~Consumer()

StormByte::Buffer::Consumer::~Consumer ( )
defaultnoexcept

Destructor.

Cleans up the Consumer instance. The destructor ensures that any resources held by the Consumer are properly released.

Member Function Documentation

◆ AvailableBytes()

std::size_t StormByte::Buffer::Consumer::AvailableBytes ( ) const
noexcept

Retrieves the number of bytes available for reading.

Returns
The number of bytes available for reading.

◆ Data()

Buffer::Data StormByte::Buffer::Consumer::Data ( ) const
noexcept

Retrieves a copy of the buffer data.

Returns
A copy of the buffer data.

◆ Discard()

void StormByte::Buffer::Consumer::Discard ( const std::size_t &  length,
const Read::Position &  mode 
)
noexcept

Discards data from the buffer.

Parameters
lengthThe number of bytes to discard.
modeThe read position mode.

◆ Empty()

bool StormByte::Buffer::Consumer::Empty ( ) const
noexcept

Checks if the shared buffer is empty.

Returns
True if the buffer is empty, false otherwise.

◆ End()

bool StormByte::Buffer::Consumer::End ( ) const
noexcept

Checks if the read position is at the end.

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

◆ Extract()

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.

Parameters
lengthThe number of bytes to extract.
Returns
The extracted data.

◆ ExtractInto()

Read::Status StormByte::Buffer::Consumer::ExtractInto ( const size_t length,
Shared output 
)
noexcept

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

Parameters
lengthThe number of bytes to extract.
outputThe buffer where the extracted data will be moved.
Returns
The status of the operation.

◆ HasEnoughData()

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

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

Parameters
lengthThe number of bytes to check.
Returns
True if there is enough data, false otherwise.

◆ HexData()

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

Retrieves the stored value as a hexadecimal string.

Parameters
column_sizeThe number of bytes per column in the output.
Returns
The hexadecimal representation of the buffer data.

◆ IsEoF()

bool StormByte::Buffer::Consumer::IsEoF ( ) const
noexcept

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

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

◆ IsReadable()

bool StormByte::Buffer::Consumer::IsReadable ( ) const
noexcept

Checks if the buffer is readable.

Returns
True if the buffer is readable, false otherwise.

◆ operator=() [1/2]

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

Deleted copy assignment operator.

The Consumer class cannot be copied to ensure data integrity and prevent unintended sharing of the buffer.

◆ operator=() [2/2]

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

Default move assignment operator.

Allows moving a Consumer instance. The moved-from instance is left in a valid but unspecified state.

◆ Peek()

ExpectedByte< BufferOverflow > StormByte::Buffer::Consumer::Peek ( ) const

Peeks at the next byte in the shared buffer without advancing the read position.

Returns
The next byte in the buffer.

◆ Position()

std::size_t StormByte::Buffer::Consumer::Position ( ) const
noexcept

Retrieves the read position.

Returns
The current read position.

◆ Read()

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

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

Parameters
lengthThe number of bytes to read.
Returns
The read data.

◆ Seek()

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.

Parameters
positionThe position to move to.
modeThe read position mode.

◆ Size()

std::size_t StormByte::Buffer::Consumer::Size ( ) const
noexcept

Retrieves the length of the shared buffer.

Returns
The length of the buffer.

◆ Status()

enum Status StormByte::Buffer::Consumer::Status ( ) const
noexcept

Gets the buffer status.

Returns
The current status of the buffer.

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