StormByte C++ Library: Buffer module 0.0.9999
StormByte-Buffer is a StormByte library module for handling buffers
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
StormByte::Buffer::FIFO Class Reference

Byte-oriented FIFO buffer with grow-on-demand. More...

#include <fifo.hxx>

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

Public Member Functions

 FIFO () noexcept=default
 Construct FIFO.
 
 FIFO (const DataType &data) noexcept
 Construct FIFO with initial data.
 
 FIFO (DataType &&data) noexcept
 Construct FIFO with initial data using move semantics.
 
template<std::ranges::input_range R>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<R>>>) && requires(std::ranges::range_value_t<R> v) { static_cast<std::byte>(v); } && (!std::same_as<std::remove_cvref_t<R>, DataType>)
 FIFO (const R &r) noexcept
 Construct FIFO from an input range.
 
template<std::ranges::input_range Rr>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Rr>>>) && requires(std::ranges::range_value_t<Rr> v) { static_cast<std::byte>(v); }
 FIFO (Rr &&r) noexcept
 Construct FIFO from an rvalue range (moves when DataType rvalue).
 
 FIFO (std::string_view sv) noexcept
 Construct FIFO from a string view (does not include terminating NUL).
 
 FIFO (const char *s) noexcept
 Construct FIFO from a C string pointer (null-terminated).
 
 FIFO (const FIFO &other) noexcept
 Copy construct, preserving buffer state and initial capacity.
 
 FIFO (FIFO &&other) noexcept
 Move construct, preserving buffer state and initial capacity.
 
virtual ~FIFO () noexcept=default
 Virtual destructor.
 
FIFOoperator= (const FIFO &other)
 Copy assign, preserving buffer state and initial capacity.
 
FIFOoperator= (FIFO &&other) noexcept
 Move assign, preserving buffer state and initial capacity.
 
bool operator== (const FIFO &other) const noexcept
 Equality comparison.
 
bool operator!= (const FIFO &other) const noexcept
 Inequality comparison.
 
virtual std::size_t AvailableBytes () const noexcept
 Get the number of bytes available for reading.
 
virtual void Clean () noexcept override
 Clean buffer data (from start to readposition)
 
virtual void Clear () noexcept override
 Clear all buffer contents.
 
virtual const DataType & Data () const noexcept override
 Access the internal data buffer.
 
virtual bool Drop (const std::size_t &count) noexcept override
 Drop bytes in the buffer and updates read position.
 
virtual bool Empty () const noexcept override
 Check if the buffer is empty.
 
virtual bool EoF () const noexcept override
 Check if the reader has reached end-of-file.
 
bool Extract (const std::size_t &count, DataType &outBuffer) noexcept override
 Destructive read that removes data from the buffer into an existing vector.
 
bool Extract (const std::size_t &count, WriteOnly &outBuffer) noexcept override
 Destructive read that removes data from the buffer into a FIFO.
 
void ExtractUntilEoF (DataType &outBuffer) noexcept override
 Read all bytes until end-of-file into an existing buffer.
 
void ExtractUntilEoF (WriteOnly &outBuffer) noexcept override
 Read all bytes until end-of-file into a WriteOnly buffer.
 
virtual std::string HexDump (const std::size_t &collumns=16, const std::size_t &byte_limit=0) const noexcept
 Produce a hexdump of the unread contents starting at the current read position.
 
virtual bool IsReadable () const noexcept override
 Check if the buffer is readable.
 
virtual bool IsWritable () const noexcept override
 Check if the buffer is writable.
 
bool Peek (const std::size_t &count, DataType &outBuffer) const noexcept override
 Non-destructive peek at buffer data without advancing read position.
 
bool Peek (const std::size_t &count, WriteOnly &outBuffer) const noexcept override
 Non-destructive peek at buffer data without advancing read position.
 
bool Read (const std::size_t &count, DataType &outBuffer) const noexcept override
 Non destructive read that removes data from the buffer into an existing vector.
 
bool Read (const std::size_t &count, WriteOnly &outBuffer) const noexcept override
 Destructive read that removes data from the buffer into a vector.
 
void ReadUntilEoF (DataType &outBuffer) const noexcept override
 Read all bytes until end-of-file into an existing buffer.
 
void ReadUntilEoF (WriteOnly &outBuffer) const noexcept override
 Read all bytes until end-of-file into a WriteOnly buffer.
 
virtual void Seek (const std::ptrdiff_t &offset, const Position &mode) const noexcept override
 Move the read position for non-destructive reads.
 
virtual std::size_t Size () const noexcept override
 Get the current number of bytes stored in the buffer.
 
bool Write (const std::size_t &count, const DataType &data) noexcept override
 Write bytes from a vector to the buffer.
 
bool Write (const std::size_t &count, DataType &&data) noexcept override
 Move bytes from a vector to the buffer.
 
bool Write (const std::size_t &count, const ReadOnly &data) noexcept override
 Write bytes from a vector to the buffer.
 
bool Write (const std::size_t &count, ReadOnly &&data) noexcept override
 Move bytes from a vector to the buffer.
 
virtual bool Extract (const std::size_t &count, DataType &outBuffer) noexcept=0
 
bool Extract (DataType &outBuffer) noexcept
 
virtual bool Extract (const std::size_t &count, WriteOnly &outBuffer) noexcept=0
 
bool Extract (WriteOnly &outBuffer) noexcept
 
virtual bool Read (const std::size_t &count, DataType &outBuffer) const noexcept=0
 
bool Read (DataType &outBuffer) const noexcept
 
virtual bool Read (const std::size_t &count, WriteOnly &outBuffer) const noexcept=0
 
bool Read (WriteOnly &outBuffer) const noexcept
 
virtual bool Write (const std::size_t &count, const DataType &data) noexcept=0
 
bool Write (std::string_view sv) noexcept
 
bool Write (const char *s) noexcept
 
bool Write (const std::size_t &count, std::string_view sv) noexcept
 
bool Write (const std::size_t &count, const char *s) noexcept
 
template<std::size_t N>
bool Write (const char(&s)[N]) noexcept
 
template<std::ranges::input_range R>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<R>>>) && requires(std::ranges::range_value_t<R> v) { static_cast<std::byte>(v); }
bool Write (const R &r) noexcept
 
template<std::ranges::input_range Rw>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Rw>>>) && requires(std::ranges::range_value_t<Rw> v) { static_cast<std::byte>(v); }
bool Write (const std::size_t &count, const Rw &r) noexcept
 
template<std::ranges::input_range Rrw>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Rrw>>>) && requires(std::ranges::range_value_t<Rrw> v) { static_cast<std::byte>(v); }
bool Write (const std::size_t &count, Rrw &&r) noexcept
 
template<std::ranges::input_range Rr>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Rr>>>) && requires(std::ranges::range_value_t<Rr> v) { static_cast<std::byte>(v); }
bool Write (Rr &&r) noexcept
 
template<std::input_iterator I, std::sentinel_for< I > S>
requires (!std::is_class_v<std::remove_cv_t<std::iter_value_t<I>>>) && requires(std::iter_value_t<I> v) { static_cast<std::byte>(v); }
bool Write (I first, S last) noexcept
 
template<std::input_iterator I2, std::sentinel_for< I2 > S2>
requires (!std::is_class_v<std::remove_cv_t<std::iter_value_t<I2>>>) && requires(std::iter_value_t<I2> v) { static_cast<std::byte>(v); }
bool Write (const std::size_t &count, I2 first, S2 last) noexcept
 
virtual bool Write (const std::size_t &count, DataType &&data) noexcept=0
 
virtual bool Write (const std::size_t &count, const ReadOnly &data) noexcept=0
 
bool Write (const ReadOnly &data) noexcept
 
virtual bool Write (const std::size_t &count, ReadOnly &&data) noexcept=0
 
bool Write (ReadOnly &&data) noexcept
 
- Public Member Functions inherited from StormByte::Buffer::ReadWrite
 ReadWrite () noexcept
 Construct ReadWrite.
 
 ReadWrite (const DataType &data) noexcept
 Construct ReadWrite.
 
 ReadWrite (DataType &&data) noexcept
 Construct ReadWrite with initial data using move semantics.
 
 ReadWrite (const ReadWrite &other) noexcept=default
 Copy construct deleted.
 
 ReadWrite (ReadWrite &&other) noexcept=default
 Move construct deleted.
 
virtual ~ReadWrite () noexcept=default
 Virtual destructor.
 
ReadWriteoperator= (const ReadWrite &other)=default
 Copy assign deleted.
 
ReadWriteoperator= (ReadWrite &&other) noexcept=default
 Move assign deleted.
 
- Public Member Functions inherited from StormByte::Buffer::ReadOnly
 ReadOnly () noexcept
 Construct ReadOnly.
 
 ReadOnly (const DataType &data) noexcept
 Construct ReadOnly.
 
 ReadOnly (DataType &&data) noexcept
 Construct ReadOnly with initial data using move semantics.
 
 ReadOnly (const ReadOnly &) noexcept=default
 Copy construct deleted.
 
 ReadOnly (ReadOnly &&) noexcept=default
 Move construct deleted.
 
virtual ~ReadOnly () noexcept=default
 Virtual destructor.
 
ReadOnlyoperator= (const ReadOnly &)=default
 Copy assign deleted.
 
ReadOnlyoperator= (ReadOnly &&) noexcept=default
 Move assign deleted.
 
bool Extract (DataType &outBuffer) noexcept
 Destructive read that removes all data from the buffer into an existing vector.
 
bool Extract (WriteOnly &outBuffer) noexcept
 Destructive read that removes all data from the buffer into a FIFO.
 
bool Read (DataType &outBuffer) const noexcept
 Read bytes into an existing buffer.
 
bool Read (WriteOnly &outBuffer) const noexcept
 Read bytes into a WriteOnly buffer.
 
- Public Member Functions inherited from StormByte::Buffer::Generic
 Generic () noexcept=default
 Construct Generic.
 
 Generic (const DataType &data) noexcept
 Construct Generic.
 
 Generic (DataType &&data) noexcept
 Construct Generic with initial data using move semantics.
 
 Generic (const Generic &) noexcept=default
 Copy construct deleted.
 
 Generic (Generic &&) noexcept=default
 Move construct deleted.
 
virtual ~Generic () noexcept=0
 Virtual destructor.
 
Genericoperator= (const Generic &other)=default
 Copy assign deleted.
 
Genericoperator= (Generic &&) noexcept=default
 Move assign deleted.
 
- Public Member Functions inherited from StormByte::Buffer::WriteOnly
 WriteOnly () noexcept
 Construct WriteOnly.
 
 WriteOnly (const DataType &data) noexcept
 Construct WriteOnly.
 
 WriteOnly (DataType &&data) noexcept
 Construct WriteOnly with initial data using move semantics.
 
 WriteOnly (const WriteOnly &)=default
 Copy construct deleted.
 
 WriteOnly (WriteOnly &&) noexcept=default
 Move construct deleted.
 
virtual ~WriteOnly () noexcept=default
 Virtual destructor.
 
WriteOnlyoperator= (const WriteOnly &)=default
 Copy assign deleted.
 
WriteOnlyoperator= (WriteOnly &&) noexcept=default
 Move assign deleted.
 
bool Write (std::string_view sv) noexcept
 Write from a string view (does not include terminating NUL).
 
bool Write (const char *s) noexcept
 Write from a C string pointer (null-terminated). Uses std::string_view.
 
bool Write (const std::size_t &count, std::string_view sv) noexcept
 Write up-to count bytes from a string view (0 => all available).
 
bool Write (const std::size_t &count, const char *s) noexcept
 Write up-to count bytes from a C string pointer (null-terminated).
 
template<std::size_t N>
bool Write (const char(&s)[N]) noexcept
 Write from a string literal (array) and avoid copying the trailing NUL.
 
template<std::ranges::input_range R>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<R>>>) && requires(std::ranges::range_value_t<R> v) { static_cast<std::byte>(v); }
bool Write (const R &r) noexcept
 Write all elements from an input range to the buffer.
 
template<std::ranges::input_range Rw>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Rw>>>) && requires(std::ranges::range_value_t<Rw> v) { static_cast<std::byte>(v); }
bool Write (const std::size_t &count, const Rw &r) noexcept
 Write up-to count elements from an input range.
 
template<std::ranges::input_range Rrw>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Rrw>>>) && requires(std::ranges::range_value_t<Rrw> v) { static_cast<std::byte>(v); }
bool Write (const std::size_t &count, Rrw &&r) noexcept
 Write up-to count elements from an rvalue range.
 
template<std::ranges::input_range Rr>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Rr>>>) && requires(std::ranges::range_value_t<Rr> v) { static_cast<std::byte>(v); }
bool Write (Rr &&r) noexcept
 Write from an rvalue input range.
 
template<std::input_iterator I, std::sentinel_for< I > S>
requires (!std::is_class_v<std::remove_cv_t<std::iter_value_t<I>>>) && requires(std::iter_value_t<I> v) { static_cast<std::byte>(v); }
bool Write (I first, S last) noexcept
 Write from iterator pair whose value_type is convertible to std::byte.
 
template<std::input_iterator I2, std::sentinel_for< I2 > S2>
requires (!std::is_class_v<std::remove_cv_t<std::iter_value_t<I2>>>) && requires(std::iter_value_t<I2> v) { static_cast<std::byte>(v); }
bool Write (const std::size_t &count, I2 first, S2 last) noexcept
 Write up-to count bytes from an iterator pair (0 => all available).
 
bool Write (const ReadOnly &data) noexcept
 Write bytes from a vector to the buffer.
 
bool Write (ReadOnly &&data) noexcept
 Move bytes from a vector to the buffer.
 

Protected Types

enum class  Operation { Extract , Read , Peek }
 Enumeration of read operation types. More...
 

Protected Member Functions

virtual std::ostringstream HexDumpHeader () const noexcept
 Produce a hexdump header with size and read position.
 
virtual bool ReadInternal (const std::size_t &count, DataType &outBuffer, const Operation &flag) noexcept
 Internal helper for read operations.
 
virtual bool ReadInternal (const std::size_t &count, WriteOnly &outBuffer, const Operation &flag) noexcept
 Internal helper for read operations.
 
virtual void ReadUntilEoFInternal (DataType &outBuffer, const Operation &flag) noexcept
 Internal helper for reading until end-of-file.
 
virtual void ReadUntilEoFInternal (WriteOnly &outBuffer, const Operation &flag) noexcept
 Internal helper for reading until end-of-file.
 
virtual bool WriteInternal (const std::size_t &count, const DataType &src) noexcept
 Internal helper for write operations.
 
virtual bool WriteInternal (const std::size_t &count, DataType &&src) noexcept
 Internal helper for write operations.
 
virtual bool WriteInternal (const std::size_t &count, const ReadOnly &src) noexcept
 Internal helper for write operations.
 
virtual bool WriteInternal (const std::size_t &count, ReadOnly &&src) noexcept
 Internal helper for write operations.
 

Static Protected Member Functions

static std::string FormatHexLines (std::span< const std::byte > &data, std::size_t start_offset, std::size_t collumns) noexcept
 Produce a hexdump of the given data span.
 
- Static Protected Member Functions inherited from StormByte::Buffer::Generic
template<std::ranges::input_range Src>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Src>>>) && requires(std::ranges::range_value_t<Src> v) { static_cast<std::byte>(v); }
static DataType DataConvert (const Src &src) noexcept
 Convert various source types into the library DataType.
 
template<std::ranges::input_range Src>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Src>>>) && requires(std::ranges::range_value_t<Src> v) { static_cast<std::byte>(v); }
static DataType DataConvert (Src &&src) noexcept
 
static DataType DataConvert (std::string_view sv) noexcept
 Convert a std::string_view to DataType.
 
static DataType DataConvert (const char *s) noexcept
 Convert a null-terminated C string to DataType.
 

Protected Attributes

std::size_t m_position_offset {0}
 Current read position for read operations.
 
- Protected Attributes inherited from StormByte::Buffer::Generic
DataType m_buffer
 Internal buffer storage.
 

Detailed Description

Byte-oriented FIFO buffer with grow-on-demand.

Overview
A contiguous growable buffer implemented atop DataType that tracks a logical read position. It grows automatically to fit writes and supports efficient non-destructive reads and destructive extracts.
Thread safety
This class is not thread-safe. For concurrent access, use SharedFIFO.
Buffer behavior
The buffer supports clearing and cleaning operations, a movable read position for non-destructive reads, and a closed state to signal end-of-writes.
See also
SharedFIFO for thread-safe version
Producer and Consumer for higher-level producer-consumer pattern

Member Enumeration Documentation

◆ Operation

enum class StormByte::Buffer::FIFO::Operation
strongprotected

Enumeration of read operation types.

Enumerator
Extract 

Destructive read.

Read 

Non-destructive read.

Peek 

Non-destructive peek.

Constructor & Destructor Documentation

◆ FIFO() [1/6]

StormByte::Buffer::FIFO::FIFO ( const DataType &  data)
inlinenoexcept

Construct FIFO with initial data.

Parameters
dataInitial byte vector to populate the FIFO.

◆ FIFO() [2/6]

StormByte::Buffer::FIFO::FIFO ( DataType &&  data)
inlinenoexcept

Construct FIFO with initial data using move semantics.

Parameters
dataInitial byte vector to move into the FIFO.

◆ FIFO() [3/6]

template<std::ranges::input_range R>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<R>>>) && requires(std::ranges::range_value_t<R> v) { static_cast<std::byte>(v); } && (!std::same_as<std::remove_cvref_t<R>, DataType>)
StormByte::Buffer::FIFO::FIFO ( const R &  r)
inlinenoexcept

Construct FIFO from an input range.

Template Parameters
RInput range whose elements are convertible to std::byte.
Parameters
rThe input range to copy from.
Note
This overload is constrained so that it does not participate when the argument type is the library DataType to avoid ambiguity with the existing DataType overloads.

◆ FIFO() [4/6]

template<std::ranges::input_range Rr>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Rr>>>) && requires(std::ranges::range_value_t<Rr> v) { static_cast<std::byte>(v); }
StormByte::Buffer::FIFO::FIFO ( Rr &&  r)
inlinenoexcept

Construct FIFO from an rvalue range (moves when DataType rvalue).

Template Parameters
RrInput range type; if it's DataType this will be moved into the internal buffer, otherwise elements are converted.

◆ FIFO() [5/6]

StormByte::Buffer::FIFO::FIFO ( const FIFO other)
noexcept

Copy construct, preserving buffer state and initial capacity.

Parameters
otherSource FIFO to copy from.

◆ FIFO() [6/6]

StormByte::Buffer::FIFO::FIFO ( FIFO &&  other)
noexcept

Move construct, preserving buffer state and initial capacity.

Parameters
otherSource FIFO to move from; left empty after move.

Member Function Documentation

◆ AvailableBytes()

virtual std::size_t StormByte::Buffer::FIFO::AvailableBytes ( ) const
inlinevirtualnoexcept

Get the number of bytes available for reading.

Returns
The number of bytes that can be read from the current read position
See also
Size(), Read(), Extract() Seek()

Implements StormByte::Buffer::ReadOnly.

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ Clean()

virtual void StormByte::Buffer::FIFO::Clean ( )
overridevirtualnoexcept

Clean buffer data (from start to readposition)

Implements StormByte::Buffer::ReadOnly.

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ Clear()

virtual void StormByte::Buffer::FIFO::Clear ( )
inlineoverridevirtualnoexcept

Clear all buffer contents.

Removes all data from the buffer, resets head/tail/read positions, and restores capacity to the initial value requested in the constructor.

See also
Size(), Empty()

Implements StormByte::Buffer::ReadOnly.

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ Data()

virtual const DataType & StormByte::Buffer::FIFO::Data ( ) const
inlineoverridevirtualnoexcept

Access the internal data buffer.

Returns
Constant reference to the internal DataType buffer.

Reimplemented from StormByte::Buffer::ReadOnly.

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ Drop()

virtual bool StormByte::Buffer::FIFO::Drop ( const std::size_t &  count)
overridevirtualnoexcept

Drop bytes in the buffer and updates read position.

Parameters
countNumber of bytes to drop.
Returns
bool indicating success or failure.
See also
Read(), Seek()

Implements StormByte::Buffer::ReadOnly.

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ Empty()

virtual bool StormByte::Buffer::FIFO::Empty ( ) const
inlineoverridevirtualnoexcept

Check if the buffer is empty.

Returns
true if the buffer contains no data, false otherwise.
See also
Size(), AvailableBytes()
Note
Since buffer works with read positions, Empty() might return false even if there is no unread data (i.e., when read position is at the end of the buffer).

Implements StormByte::Buffer::ReadOnly.

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ EoF()

virtual bool StormByte::Buffer::FIFO::EoF ( ) const
inlineoverridevirtualnoexcept

Check if the reader has reached end-of-file.

Returns
true if buffer is closed or in error state and no bytes available.

Returns true when the buffer has been closed or set to error and there are no available bytes remaining.

Implements StormByte::Buffer::ReadOnly.

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ Extract() [1/6]

bool StormByte::Buffer::FIFO::Extract ( const std::size_t &  count,
DataType &  outBuffer 
)
inlineoverridevirtualnoexcept

Destructive read that removes data from the buffer into an existing vector.

Parameters
countNumber of bytes to extract; 0 extracts all available.
outBufferVector to fill with extracted bytes; resized as needed.
Returns
bool indicating success or failure.

Implements StormByte::Buffer::ReadOnly.

◆ Extract() [2/6]

virtual bool StormByte::Buffer::ReadOnly::Extract ( const std::size_t &  count,
DataType &  outBuffer 
)
inlinevirtualnoexcept

Expose the rest of overloads

Implements StormByte::Buffer::ReadOnly.

◆ Extract() [3/6]

bool StormByte::Buffer::FIFO::Extract ( const std::size_t &  count,
WriteOnly outBuffer 
)
inlineoverridevirtualnoexcept

Destructive read that removes data from the buffer into a FIFO.

Parameters
countNumber of bytes to extract; 0 extracts all available.
outBufferWriteOnly to fill with extracted bytes; resized as needed.
Returns
bool indicating success or failure.

Implements StormByte::Buffer::ReadOnly.

◆ Extract() [4/6]

virtual bool StormByte::Buffer::ReadOnly::Extract ( const std::size_t &  count,
WriteOnly outBuffer 
)
inlinevirtualnoexcept

Expose the rest of overloads

Implements StormByte::Buffer::ReadOnly.

◆ Extract() [5/6]

bool StormByte::Buffer::ReadOnly::Extract ( DataType &  outBuffer)
inlinenoexcept

Expose the rest of overloads

◆ Extract() [6/6]

bool StormByte::Buffer::ReadOnly::Extract ( WriteOnly outBuffer)
inlinenoexcept

Expose the rest of overloads

◆ ExtractUntilEoF() [1/2]

void StormByte::Buffer::FIFO::ExtractUntilEoF ( DataType &  outBuffer)
inlineoverridevirtualnoexcept

Read all bytes until end-of-file into an existing buffer.

Parameters
outBufferVector to fill with read bytes; resized as needed.

Implements StormByte::Buffer::ReadOnly.

◆ ExtractUntilEoF() [2/2]

void StormByte::Buffer::FIFO::ExtractUntilEoF ( WriteOnly outBuffer)
inlineoverridevirtualnoexcept

Read all bytes until end-of-file into a WriteOnly buffer.

Parameters
outBufferWriteOnly to fill with read bytes; resized as needed.

Implements StormByte::Buffer::ReadOnly.

◆ FormatHexLines()

static std::string StormByte::Buffer::FIFO::FormatHexLines ( std::span< const std::byte > &  data,
std::size_t  start_offset,
std::size_t  collumns 
)
staticprotectednoexcept

Produce a hexdump of the given data span.

Parameters
dataSpan of bytes to format.
start_offsetStarting offset for line addresses.
collumnsNumber of bytes per line.
Returns
Formatted hexdump string.

Formats the provided byte span into a hexdump string with specified number of columns per line. Each line begins with the absolute offset (from start_offset), followed by hexadecimal byte values and ASCII representation.

◆ HexDump()

virtual std::string StormByte::Buffer::FIFO::HexDump ( const std::size_t &  collumns = 16,
const std::size_t &  byte_limit = 0 
) const
virtualnoexcept

Produce a hexdump of the unread contents starting at the current read position.

Parameters
collumnsNumber of bytes per line (0 -> default 16).
byte_limitMaximum number of bytes to include (0 -> no limit).
Returns
A formatted string that begins with Read Position: <offset> followed by the hex/ASCII lines. The returned string does not include a trailing newline.

The hexdump is produced from a snapshot of the unread bytes and does not modify the FIFO's read position. Offsets printed on each line are absolute offsets (from the start of the underlying buffer). Formatting of the hex/ASCII lines is performed by FormatHexLines() to ensure consistent output between FIFO and SharedFIFO. Example output:

Size: 13 bytes
Read Position: 0
00000000: 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 Hello, world!

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ HexDumpHeader()

virtual std::ostringstream StormByte::Buffer::FIFO::HexDumpHeader ( ) const
protectedvirtualnoexcept

Produce a hexdump header with size and read position.

Returns
ostringstream containing the hexdump header.

◆ IsReadable()

virtual bool StormByte::Buffer::FIFO::IsReadable ( ) const
inlineoverridevirtualnoexcept

Check if the buffer is readable.

Returns
true if the buffer can be read from, false otherwise.

Implements StormByte::Buffer::ReadOnly.

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ IsWritable()

virtual bool StormByte::Buffer::FIFO::IsWritable ( ) const
inlineoverridevirtualnoexcept

Check if the buffer is writable.

Returns
true if the buffer can accept write operations, false otherwise.

Implements StormByte::Buffer::WriteOnly.

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ operator!=()

bool StormByte::Buffer::FIFO::operator!= ( const FIFO other) const
inlinenoexcept

Inequality comparison.

Negates operator==.

◆ operator=() [1/2]

FIFO & StormByte::Buffer::FIFO::operator= ( const FIFO other)

Copy assign, preserving buffer state and initial capacity.

Parameters
otherSource FIFO to copy from.
Returns
Reference to this FIFO.

◆ operator=() [2/2]

FIFO & StormByte::Buffer::FIFO::operator= ( FIFO &&  other)
noexcept

Move assign, preserving buffer state and initial capacity.

Parameters
otherSource FIFO to move from; left empty after move.
Returns
Reference to this FIFO.

◆ operator==()

bool StormByte::Buffer::FIFO::operator== ( const FIFO other) const
inlinenoexcept

Equality comparison.

Compares this FIFO with other by comparing their internal buffers. Equality is defined as having identical byte contents in the buffer and same read position.

◆ Peek() [1/2]

bool StormByte::Buffer::FIFO::Peek ( const std::size_t &  count,
DataType &  outBuffer 
) const
inlineoverridevirtualnoexcept

Non-destructive peek at buffer data without advancing read position.

Parameters
countNumber of bytes to peek; 0 peeks all available from read position.
Returns
bool indicating success or failure.

Similar to Read(), but does not advance the read position. Allows inspecting upcoming data without consuming it.

Semantics:

  • If count == 0: the call returns all available bytes. If no bytes are available, a ReadError is returned.
  • If count > 0: the call returns exactly count bytes when that many bytes are available. If zero bytes are available, or if count is greater than the number of available bytes, a ReadError is returned.
See also
Read(), Seek()

Implements StormByte::Buffer::ReadOnly.

◆ Peek() [2/2]

bool StormByte::Buffer::FIFO::Peek ( const std::size_t &  count,
WriteOnly outBuffer 
) const
inlineoverridevirtualnoexcept

Non-destructive peek at buffer data without advancing read position.

Parameters
countNumber of bytes to peek; 0 peeks all available from read position.
Returns
bool indicating success or failure.

Similar to Read(), but does not advance the read position. Allows inspecting upcoming data without consuming it.

Semantics:

  • If count == 0: the call returns all available bytes. If no bytes are available, a ReadError is returned.
  • If count > 0: the call returns exactly count bytes when that many bytes are available. If zero bytes are available, or if count is greater than the number of available bytes, a ReadError is returned.
See also
Read(), Seek()

Implements StormByte::Buffer::ReadOnly.

◆ Read() [1/6]

bool StormByte::Buffer::FIFO::Read ( const std::size_t &  count,
DataType &  outBuffer 
) const
inlineoverridevirtualnoexcept

Non destructive read that removes data from the buffer into an existing vector.

Parameters
countNumber of bytes to extract; 0 extracts all available.
outBufferVector to fill with extracted bytes; resized as needed.
Returns
bool indicating success or failure.

Implements StormByte::Buffer::ReadOnly.

◆ Read() [2/6]

virtual bool StormByte::Buffer::ReadOnly::Read ( const std::size_t &  count,
DataType &  outBuffer 
) const
virtualnoexcept

Expose the rest of overloads

Implements StormByte::Buffer::ReadOnly.

◆ Read() [3/6]

bool StormByte::Buffer::FIFO::Read ( const std::size_t &  count,
WriteOnly outBuffer 
) const
inlineoverridevirtualnoexcept

Destructive read that removes data from the buffer into a vector.

Parameters
countNumber of bytes to extract; 0 extracts all available.
outBufferWriteOnly to fill with extracted bytes; resized as needed.
Returns
bool indicating success or failure.

Implements StormByte::Buffer::ReadOnly.

◆ Read() [4/6]

virtual bool StormByte::Buffer::ReadOnly::Read ( const std::size_t &  count,
WriteOnly outBuffer 
) const
virtualnoexcept

Expose the rest of overloads

Implements StormByte::Buffer::ReadOnly.

◆ Read() [5/6]

bool StormByte::Buffer::ReadOnly::Read ( DataType &  outBuffer) const
inlinenoexcept

Expose the rest of overloads

◆ Read() [6/6]

bool StormByte::Buffer::ReadOnly::Read ( WriteOnly outBuffer) const
inlinenoexcept

Expose the rest of overloads

◆ ReadInternal() [1/2]

virtual bool StormByte::Buffer::FIFO::ReadInternal ( const std::size_t &  count,
DataType &  outBuffer,
const Operation flag 
)
protectedvirtualnoexcept

Internal helper for read operations.

Parameters
countNumber of bytes to read.
outBufferOutput buffer to store read bytes.
flagAdditional flag for read operation (1: copy, 2: move)
Returns
bool indicating success or failure.

Shared logic for read operations that first checks the internal buffer, then calls the external read function if needed.

◆ ReadInternal() [2/2]

virtual bool StormByte::Buffer::FIFO::ReadInternal ( const std::size_t &  count,
WriteOnly outBuffer,
const Operation flag 
)
protectedvirtualnoexcept

Internal helper for read operations.

Parameters
countNumber of bytes to read.
outBufferOutput buffer to store read bytes.
flagAdditional flag for read operation (1: copy, 2: move)
Returns
bool indicating success or failure.

Shared logic for read operations that first checks the internal buffer, then calls the external read function if needed.

◆ ReadUntilEoF() [1/2]

void StormByte::Buffer::FIFO::ReadUntilEoF ( DataType &  outBuffer) const
inlineoverridevirtualnoexcept

Read all bytes until end-of-file into an existing buffer.

Parameters
outBufferVector to fill with read bytes; resized as needed.

Implements StormByte::Buffer::ReadOnly.

◆ ReadUntilEoF() [2/2]

void StormByte::Buffer::FIFO::ReadUntilEoF ( WriteOnly outBuffer) const
inlineoverridevirtualnoexcept

Read all bytes until end-of-file into a WriteOnly buffer.

Parameters
outBufferWriteOnly to fill with read bytes; resized as needed.
Returns
bool indicating success or failure.

Implements StormByte::Buffer::ReadOnly.

◆ ReadUntilEoFInternal() [1/2]

virtual void StormByte::Buffer::FIFO::ReadUntilEoFInternal ( DataType &  outBuffer,
const Operation flag 
)
protectedvirtualnoexcept

Internal helper for reading until end-of-file.

Parameters
outBufferOutput buffer to store read bytes.
flagAdditional flag for read operation (1: copy, 2: move)

◆ ReadUntilEoFInternal() [2/2]

virtual void StormByte::Buffer::FIFO::ReadUntilEoFInternal ( WriteOnly outBuffer,
const Operation flag 
)
protectedvirtualnoexcept

Internal helper for reading until end-of-file.

Parameters
outBufferOutput buffer to store read bytes.
flagAdditional flag for read operation (1: copy, 2: move)
Returns
bool indicating success or failure.

◆ Seek()

virtual void StormByte::Buffer::FIFO::Seek ( const std::ptrdiff_t &  offset,
const Position &  mode 
) const
overridevirtualnoexcept

Move the read position for non-destructive reads.

Parameters
positionThe offset value to apply.
modeUnused for base class; included for API consistency.

Changes where subsequent Read() operations will start reading from. Position is clamped to [0, Size()]. Does not affect stored data.

See also
Read(), Position If Position is set to Absolute and offset is negative the operation is noop

Implements StormByte::Buffer::ReadOnly.

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ Size()

virtual std::size_t StormByte::Buffer::FIFO::Size ( ) const
inlineoverridevirtualnoexcept

Get the current number of bytes stored in the buffer.

Returns
The total number of bytes available for reading.
See also
Empty(), AvailableBytes()

Implements StormByte::Buffer::ReadOnly.

Reimplemented in StormByte::Buffer::SharedFIFO.

◆ Write() [1/21]

bool StormByte::Buffer::WriteOnly::Write ( const char *  s)
inlinenoexcept

Expose the rest of overloads

◆ Write() [2/21]

template<std::size_t N>
bool StormByte::Buffer::WriteOnly::Write ( const char(&)  s[N])
inlinenoexcept

Expose the rest of overloads

◆ Write() [3/21]

template<std::ranges::input_range R>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<R>>>) && requires(std::ranges::range_value_t<R> v) { static_cast<std::byte>(v); }
bool StormByte::Buffer::WriteOnly::Write ( const R &  r)
inlinenoexcept

Expose the rest of overloads

◆ Write() [4/21]

bool StormByte::Buffer::WriteOnly::Write ( const ReadOnly data)
inlinenoexcept

Expose the rest of overloads

◆ Write() [5/21]

bool StormByte::Buffer::WriteOnly::Write ( const std::size_t &  count,
const char *  s 
)
inlinenoexcept

Expose the rest of overloads

◆ Write() [6/21]

bool StormByte::Buffer::FIFO::Write ( const std::size_t &  count,
const DataType &  data 
)
inlineoverridevirtualnoexcept

Write bytes from a vector to the buffer.

Parameters
countNumber of bytes to write.
dataByte vector to append to the WriteOnly.
Returns
bool indicating success or failure.

Appends data to the buffer, growing capacity automatically if needed. Handles wrap-around efficiently. Ignores writes if buffer is closed.

See also
IsClosed()

Implements StormByte::Buffer::WriteOnly.

◆ Write() [7/21]

virtual bool StormByte::Buffer::WriteOnly::Write ( const std::size_t &  count,
const DataType &  data 
)
virtualnoexcept

Expose the rest of overloads

Implements StormByte::Buffer::WriteOnly.

◆ Write() [8/21]

bool StormByte::Buffer::FIFO::Write ( const std::size_t &  count,
const ReadOnly data 
)
inlineoverridevirtualnoexcept

Write bytes from a vector to the buffer.

Parameters
countNumber of bytes to write.
dataByte vector to append to the WriteOnly.
Returns
bool indicating success or failure.

Appends data to the buffer, growing capacity automatically if needed. Handles wrap-around efficiently. Ignores writes if buffer is closed.

See also
IsClosed()

Implements StormByte::Buffer::WriteOnly.

◆ Write() [9/21]

virtual bool StormByte::Buffer::WriteOnly::Write ( const std::size_t &  count,
const ReadOnly data 
)
virtualnoexcept

Expose the rest of overloads

Implements StormByte::Buffer::WriteOnly.

◆ Write() [10/21]

template<std::ranges::input_range Rw>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Rw>>>) && requires(std::ranges::range_value_t<Rw> v) { static_cast<std::byte>(v); }
bool StormByte::Buffer::WriteOnly::Write ( const std::size_t &  count,
const Rw &  r 
)
inlinenoexcept

Expose the rest of overloads

◆ Write() [11/21]

bool StormByte::Buffer::FIFO::Write ( const std::size_t &  count,
DataType &&  data 
)
inlineoverridevirtualnoexcept

Move bytes from a vector to the buffer.

Parameters
countNumber of bytes to write.
dataByte vector to append to the WriteOnly.
Returns
bool indicating success or failure.

Appends data to the buffer, growing capacity automatically if needed. Handles wrap-around efficiently. Ignores writes if buffer is closed.

See also
IsClosed()

Implements StormByte::Buffer::WriteOnly.

◆ Write() [12/21]

virtual bool StormByte::Buffer::WriteOnly::Write ( const std::size_t &  count,
DataType &&  data 
)
virtualnoexcept

Expose the rest of overloads

Implements StormByte::Buffer::WriteOnly.

◆ Write() [13/21]

template<std::input_iterator I2, std::sentinel_for< I2 > S2>
requires (!std::is_class_v<std::remove_cv_t<std::iter_value_t<I2>>>) && requires(std::iter_value_t<I2> v) { static_cast<std::byte>(v); }
bool StormByte::Buffer::WriteOnly::Write ( const std::size_t &  count,
I2  first,
S2  last 
)
inlinenoexcept

Expose the rest of overloads

◆ Write() [14/21]

bool StormByte::Buffer::FIFO::Write ( const std::size_t &  count,
ReadOnly &&  data 
)
inlineoverridevirtualnoexcept

Move bytes from a vector to the buffer.

Parameters
countNumber of bytes to write.
dataByte vector to append to the WriteOnly.
Returns
bool indicating success or failure.

Appends data to the buffer, growing capacity automatically if needed. Handles wrap-around efficiently. Ignores writes if buffer is closed.

See also
IsClosed()

Implements StormByte::Buffer::WriteOnly.

◆ Write() [15/21]

virtual bool StormByte::Buffer::WriteOnly::Write ( const std::size_t &  count,
ReadOnly &&  data 
)
virtualnoexcept

Expose the rest of overloads

Implements StormByte::Buffer::WriteOnly.

◆ Write() [16/21]

template<std::ranges::input_range Rrw>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Rrw>>>) && requires(std::ranges::range_value_t<Rrw> v) { static_cast<std::byte>(v); }
bool StormByte::Buffer::WriteOnly::Write ( const std::size_t &  count,
Rrw &&  r 
)
inlinenoexcept

Expose the rest of overloads

◆ Write() [17/21]

bool StormByte::Buffer::WriteOnly::Write ( const std::size_t &  count,
std::string_view  sv 
)
inlinenoexcept

Expose the rest of overloads

◆ Write() [18/21]

template<std::input_iterator I, std::sentinel_for< I > S>
requires (!std::is_class_v<std::remove_cv_t<std::iter_value_t<I>>>) && requires(std::iter_value_t<I> v) { static_cast<std::byte>(v); }
bool StormByte::Buffer::WriteOnly::Write ( first,
last 
)
inlinenoexcept

Expose the rest of overloads

◆ Write() [19/21]

bool StormByte::Buffer::WriteOnly::Write ( ReadOnly &&  data)
inlinenoexcept

Expose the rest of overloads

◆ Write() [20/21]

template<std::ranges::input_range Rr>
requires (!std::is_class_v<std::remove_cv_t<std::ranges::range_value_t<Rr>>>) && requires(std::ranges::range_value_t<Rr> v) { static_cast<std::byte>(v); }
bool StormByte::Buffer::WriteOnly::Write ( Rr &&  r)
inlinenoexcept

Expose the rest of overloads

◆ Write() [21/21]

bool StormByte::Buffer::WriteOnly::Write ( std::string_view  sv)
inlinenoexcept

Expose the rest of overloads

◆ WriteInternal() [1/4]

virtual bool StormByte::Buffer::FIFO::WriteInternal ( const std::size_t &  count,
const DataType &  src 
)
protectedvirtualnoexcept

Internal helper for write operations.

Parameters
dstDestination buffer to write into.
countNumber of bytes to write.
srcSource buffer to write from.
Returns
bool indicating success or failure.

◆ WriteInternal() [2/4]

virtual bool StormByte::Buffer::FIFO::WriteInternal ( const std::size_t &  count,
const ReadOnly src 
)
protectedvirtualnoexcept

Internal helper for write operations.

Parameters
countNumber of bytes to write.
srcSource ReadOnly buffer to write from.
Returns
bool indicating success or failure.

◆ WriteInternal() [3/4]

virtual bool StormByte::Buffer::FIFO::WriteInternal ( const std::size_t &  count,
DataType &&  src 
)
protectedvirtualnoexcept

Internal helper for write operations.

Parameters
dstDestination buffer to write into.
countNumber of bytes to write.
srcSource buffer to write from.
Returns
bool indicating success or failure.

◆ WriteInternal() [4/4]

virtual bool StormByte::Buffer::FIFO::WriteInternal ( const std::size_t &  count,
ReadOnly &&  src 
)
protectedvirtualnoexcept

Internal helper for write operations.

Parameters
countNumber of bytes to write.
srcSource ReadOnly buffer to write from.
Returns
bool indicating success or failure.

Member Data Documentation

◆ m_position_offset

std::size_t StormByte::Buffer::FIFO::m_position_offset {0}
mutableprotected

Current read position for read operations.

Tracks the offset from the start of the buffer for all read operations.


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