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

Generic class providing a buffer that can be read but not written to. More...

#include <generic.hxx>

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

Public Member Functions

 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.
 
virtual std::size_t AvailableBytes () const noexcept=0
 Gets available bytes for reading.
 
virtual void Clean () noexcept=0
 Clean buffer data from start to read position.
 
virtual void Clear () noexcept=0
 Clear all buffer contents.
 
virtual const DataType & Data () const noexcept
 Access the internal data buffer.
 
virtual bool Drop (const std::size_t &count) noexcept=0
 Drop bytes in the buffer.
 
virtual bool Empty () const noexcept=0
 Check if the buffer is empty.
 
virtual bool EoF () const noexcept=0
 Check if the reader has reached end-of-file.
 
virtual bool Extract (const std::size_t &count, DataType &outBuffer) noexcept=0
 Destructive read that removes data from the buffer into an existing vector.
 
bool Extract (DataType &outBuffer) noexcept
 Destructive read that removes all data from the buffer into an existing vector.
 
virtual bool Extract (const std::size_t &count, WriteOnly &outBuffer) noexcept=0
 Destructive read that removes data from the buffer into a FIFO.
 
bool Extract (WriteOnly &outBuffer) noexcept
 Destructive read that removes all data from the buffer into a FIFO.
 
virtual void ExtractUntilEoF (DataType &outBuffer) noexcept=0
 Read all bytes until end-of-file into an existing buffer.
 
virtual void ExtractUntilEoF (WriteOnly &outBuffer) noexcept=0
 Read all bytes until end-of-file into a WriteOnly buffer.
 
virtual bool IsReadable () const noexcept=0
 Check if the buffer is readable.
 
virtual bool Peek (const std::size_t &count, DataType &outBuffer) const noexcept=0
 Non-destructive peek at buffer data without advancing read position.
 
virtual bool Peek (const std::size_t &count, WriteOnly &outBuffer) const noexcept=0
 Non-destructive peek at buffer data without advancing read position.
 
virtual bool Read (const std::size_t &count, DataType &outBuffer) const noexcept=0
 Read bytes into an existing buffer.
 
bool Read (DataType &outBuffer) const noexcept
 Read bytes into an existing buffer.
 
virtual bool Read (const std::size_t &count, WriteOnly &outBuffer) const noexcept=0
 Read bytes into a WriteOnly buffer.
 
bool Read (WriteOnly &outBuffer) const noexcept
 Read bytes into a WriteOnly buffer.
 
virtual void ReadUntilEoF (DataType &outBuffer) const noexcept=0
 Read all bytes until end-of-file into an existing buffer.
 
virtual void ReadUntilEoF (WriteOnly &outBuffer) const noexcept=0
 Read all bytes until end-of-file into a WriteOnly buffer.
 
virtual void Seek (const std::ptrdiff_t &offset, const Position &mode) const noexcept=0
 Move the read position for non-destructive reads.
 
virtual std::size_t Size () const noexcept=0
 Get the current number of bytes stored in the 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.
 

Additional Inherited Members

- 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 inherited from StormByte::Buffer::Generic
DataType m_buffer
 Internal buffer storage.
 

Detailed Description

Generic class providing a buffer that can be read but not written to.

Overview
ReadOnly extends Generic to provide a read-only buffer interface. It allows reading data from the buffer while preventing any modifications. This is useful for scenarios where data integrity must be maintained and only read access is required.

Constructor & Destructor Documentation

◆ ReadOnly() [1/2]

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

Construct ReadOnly.

Parameters
dataInitial byte vector to populate the ReadOnly.

◆ ReadOnly() [2/2]

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

Construct ReadOnly with initial data using move semantics.

Parameters
dataInitial byte vector to move into the ReadOnly.

Member Function Documentation

◆ AvailableBytes()

virtual std::size_t StormByte::Buffer::ReadOnly::AvailableBytes ( ) const
pure virtualnoexcept

Gets available bytes for reading.

Returns
Number of bytes available from the current read position.

Implemented in StormByte::Buffer::FIFO, StormByte::Buffer::Consumer, and StormByte::Buffer::SharedFIFO.

◆ Clean()

virtual void StormByte::Buffer::ReadOnly::Clean ( )
pure virtualnoexcept

Clean buffer data from start to read position.

See also
Size(), Empty()

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::SharedFIFO.

◆ Clear()

virtual void StormByte::Buffer::ReadOnly::Clear ( )
pure virtualnoexcept

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()

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::SharedFIFO.

◆ Data()

virtual const DataType & StormByte::Buffer::ReadOnly::Data ( ) const
inlinevirtualnoexcept

Access the internal data buffer.

Returns
Constant reference to the internal DataType buffer.

Reimplemented in StormByte::Buffer::FIFO, and StormByte::Buffer::SharedFIFO.

◆ Drop()

virtual bool StormByte::Buffer::ReadOnly::Drop ( const std::size_t &  count)
pure virtualnoexcept

Drop bytes in the buffer.

Parameters
countNumber of bytes to drop.
See also
Read()

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::SharedFIFO.

◆ Empty()

virtual bool StormByte::Buffer::ReadOnly::Empty ( ) const
pure virtualnoexcept

Check if the buffer is empty.

Returns
true if the buffer contains no data, false otherwise.
See also
Size()

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::SharedFIFO.

◆ EoF()

virtual bool StormByte::Buffer::ReadOnly::EoF ( ) const
pure virtualnoexcept

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.

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::SharedFIFO.

◆ Extract() [1/4]

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

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.
Note
For base class is the same than Read

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::FIFO.

◆ Extract() [2/4]

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

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.

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::FIFO.

◆ Extract() [3/4]

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

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

Parameters
outBufferVector to fill with extracted bytes; resized as needed.
Returns
bool indicating success or failure.
Note
For base class is the same than Read

◆ Extract() [4/4]

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

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

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

◆ ExtractUntilEoF() [1/2]

virtual void StormByte::Buffer::ReadOnly::ExtractUntilEoF ( DataType &  outBuffer)
pure virtualnoexcept

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

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

Implemented in StormByte::Buffer::Consumer, and StormByte::Buffer::FIFO.

◆ ExtractUntilEoF() [2/2]

virtual void StormByte::Buffer::ReadOnly::ExtractUntilEoF ( WriteOnly outBuffer)
pure virtualnoexcept

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.

Implemented in StormByte::Buffer::Consumer, and StormByte::Buffer::FIFO.

◆ IsReadable()

virtual bool StormByte::Buffer::ReadOnly::IsReadable ( ) const
pure virtualnoexcept

Check if the buffer is readable.

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

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::SharedFIFO.

◆ Peek() [1/2]

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

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

Parameters
countNumber of bytes to peek; 0 peeks all available from read position.
Returns
ExpectedData<ReadError> containing the requested bytes, or error if insufficient data.

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()

Implemented in StormByte::Buffer::Consumer, and StormByte::Buffer::FIFO.

◆ Peek() [2/2]

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

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()

Implemented in StormByte::Buffer::Consumer, and StormByte::Buffer::FIFO.

◆ Read() [1/4]

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

Read bytes into an existing buffer.

Parameters
countNumber of bytes to read; 0 reads all available from read position.
outBufferVector to fill with read bytes; resized as needed.
Returns
bool indicating success or failure.

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::FIFO.

◆ Read() [2/4]

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

Read bytes into a WriteOnly buffer.

Parameters
countNumber of bytes to read; 0 reads all available from read position.
outBufferWriteOnly to fill with read bytes; resized as needed.
Returns
bool indicating success or failure.

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::FIFO.

◆ Read() [3/4]

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

Read bytes into an existing buffer.

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

◆ Read() [4/4]

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

Read bytes into a WriteOnly buffer.

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

◆ ReadUntilEoF() [1/2]

virtual void StormByte::Buffer::ReadOnly::ReadUntilEoF ( DataType &  outBuffer) const
pure virtualnoexcept

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

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

Implemented in StormByte::Buffer::Consumer, and StormByte::Buffer::FIFO.

◆ ReadUntilEoF() [2/2]

virtual void StormByte::Buffer::ReadOnly::ReadUntilEoF ( WriteOnly outBuffer) const
pure virtualnoexcept

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.

Implemented in StormByte::Buffer::Consumer, and StormByte::Buffer::FIFO.

◆ Seek()

virtual void StormByte::Buffer::ReadOnly::Seek ( const std::ptrdiff_t &  offset,
const Position &  mode 
) const
pure virtualnoexcept

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

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::SharedFIFO.

◆ Size()

virtual std::size_t StormByte::Buffer::ReadOnly::Size ( ) const
pure virtualnoexcept

Get the current number of bytes stored in the buffer.

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

Implemented in StormByte::Buffer::Consumer, StormByte::Buffer::FIFO, and StormByte::Buffer::SharedFIFO.


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