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 | List of all members
StormByte::Buffer::External Class Reference

A specialized buffer that extends the functionality of the Shared buffer by integrating an external Reader class. More...

#include <external.hxx>

Inheritance diagram for StormByte::Buffer::External:
Inheritance graph
[legend]
Collaboration diagram for StormByte::Buffer::External:
Collaboration graph
[legend]

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.
 
Externaloperator= (const External &other)=default
 Copy assignment operator.
 
Externaloperator= (External &&other) noexcept=default
 Move assignment operator.
 
Externaloperator<< (const Buffer::Status &status)
 Sets the buffer status.
 
Externaloperator<< (const Simple &buffer)
 Appends data from another buffer to this buffer.
 
Externaloperator<< (Simple &&buffer)
 Moves data from another buffer and appends it to this buffer.
 
Externaloperator<< (const std::string &data)
 Appends a string to the buffer.
 
Externaloperator<< (const Buffer::Data &data)
 Appends a byte vector to the buffer.
 
Externaloperator<< (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>>>>
Externaloperator<< (const NumericType &value)
 Appends a numeric value to the buffer.
 
Externaloperator>> (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< BufferOverflowRead (const size_t &length) const override
 Reads a specific size of data from the buffer.
 
- Public Member Functions inherited from StormByte::Buffer::Shared
 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.
 
Sharedoperator= (const Shared &other)
 Copy assignment operator.
 
Sharedoperator= (Shared &&other) noexcept
 Move assignment operator.
 
Sharedoperator<< (const Status &status)
 Sets the buffer status.
 
Sharedoperator<< (const Simple &buffer)
 Appends a buffer to the current buffer Thread-safe version of.
 
Sharedoperator<< (Simple &&buffer)
 Moves a buffer and appends to the current buffer Thread-safe version of.
 
Sharedoperator<< (const std::string &data)
 Appends a string to the current shared buffer Thread-safe version of.
 
Sharedoperator<< (const Buffer::Data &data)
 Appends a byte vector to the current shared buffer Thread-safe version of.
 
Sharedoperator<< (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>>>>
Sharedoperator<< (const NumericType &value)
 Appends a numeric value to the current simple buffer.
 
Sharedoperator>> (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< BufferOverflowExtract (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< BufferOverflowPeek () 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.
 
- Public Member Functions inherited from StormByte::Buffer::Simple
 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.
 
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 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 ByteSpan () const noexcept
 Retrieves a const view (span) to the stored value.
 
std::span< ByteSpan () noexcept
 Retrieves a view (span) to the stored value.
 

Additional Inherited Members

- Protected Attributes inherited from StormByte::Buffer::Shared
std::shared_mutex m_data_mutex
 Mutex for thread safety.
 
std::atomic< enum Statusm_status
 Buffer status.
 
- Protected Attributes inherited from StormByte::Buffer::Simple
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 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:

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.

See also
Reader

Constructor & Destructor Documentation

◆ External() [1/4]

StormByte::Buffer::External::External ( const Reader reader)
noexcept

Constructs an External buffer with a specified Reader instance.

Parameters
readerThe 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.

See also
Reader

◆ External() [2/4]

StormByte::Buffer::External::External ( Reader &&  reader)
noexcept

Constructs an External buffer taking ownership of a specified Reader instance.

Parameters
readerThe 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.

See also
Reader

◆ External() [3/4]

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

Copy constructor.

Parameters
otherThe External buffer to copy from.

Copies the state of the External buffer, including its Shared buffer functionality and the associated Reader.

◆ External() [4/4]

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

Move constructor.

Parameters
otherThe External buffer to move from.

Moves the state of the External buffer, including its Shared buffer functionality and the associated Reader.

◆ ~External()

StormByte::Buffer::External::~External ( )
overridedefaultnoexcept

Destructor. Cleans up the buffer and releases any associated resources.

Extends the Shared buffer's cleanup process to include the external Reader instance.

Member Function Documentation

◆ HasEnoughData()

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

Checks if the buffer has enough data to satisfy a read request.

Parameters
lengthThe number of bytes to check for.
Returns
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.

See also
Reader

Reimplemented from StormByte::Buffer::Shared.

◆ operator<<() [1/7]

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

Moves a byte vector and appends it to the buffer.

Parameters
dataThe byte vector to move and append.
Returns
Reference to the updated buffer.

Extends the Shared buffer's appending functionality to support external reader integration.

Reimplemented from StormByte::Buffer::Simple.

◆ operator<<() [2/7]

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

Appends a byte vector to the buffer.

Parameters
dataThe byte vector to append.
Returns
Reference to the updated buffer.

Extends the Shared buffer's appending functionality to support external reader integration.

Reimplemented from StormByte::Buffer::Simple.

◆ operator<<() [3/7]

External & StormByte::Buffer::External::operator<< ( const Buffer::Status status)

Sets the buffer status.

Parameters
statusThe new status to set.
Returns
Reference to the updated buffer.
See also
Buffer::Status

Extends the Shared buffer's status management by supporting external reader integration.

◆ operator<<() [4/7]

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

Appends a numeric value to the buffer.

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

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.

◆ operator<<() [5/7]

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

Appends data from another buffer to this buffer.

Parameters
bufferThe source buffer to append from.
Returns
Reference to the updated buffer.

Extends the Shared buffer's appending functionality to support external reader integration.

Reimplemented from StormByte::Buffer::Simple.

◆ operator<<() [6/7]

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

Appends a string to the buffer.

Parameters
dataThe string to append.
Returns
Reference to the updated buffer.

Extends the Shared buffer's appending functionality to support external reader integration.

Reimplemented from StormByte::Buffer::Simple.

◆ operator<<() [7/7]

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

Moves data from another buffer and appends it to this buffer.

Parameters
bufferThe source buffer to move from.
Returns
Reference to the updated buffer.

Extends the Shared buffer's appending functionality to support external reader integration.

Reimplemented from StormByte::Buffer::Simple.

◆ operator=() [1/2]

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

Copy assignment operator.

Parameters
otherThe External buffer to copy from.
Returns
Reference to the updated buffer.

Copies the state of the External buffer, including its Shared buffer functionality and the associated Reader.

◆ operator=() [2/2]

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

Move assignment operator.

Parameters
otherThe External buffer to move from.
Returns
Reference to the updated buffer.

Moves the state of the External buffer, including its Shared buffer functionality and the associated Reader.

◆ operator>>()

External & StormByte::Buffer::External::operator>> ( External buffer)

Appends the current buffer's data to another buffer.

Parameters
bufferThe target buffer to append to.
Returns
Reference to the updated buffer.

Extends the Shared buffer's appending functionality to support external reader integration.

◆ Read()

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

Reads a specific size of data from the buffer.

Parameters
lengthThe number of bytes to read.
Returns
The requested data or a BufferOverflow error if insufficient data exists.

This method waits for the requested data to become available while the buffer is readable.

See also
Reader

Reimplemented from StormByte::Buffer::Shared.

◆ Reader() [1/2]

void StormByte::Buffer::External::Reader ( class Reader &&  reader)
noexcept

Sets the external Reader instance taking ownership of it.

Parameters
readerThe 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.

See also
Reader

◆ Reader() [2/2]

void StormByte::Buffer::External::Reader ( const class Reader reader)
noexcept

Sets the external Reader instance.

Parameters
readerThe 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.

See also
Reader

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