StormByte C++ Library: Buffer module 1.2.0
StormByte-Buffer is the buffer module of the StormByte C++ suite.
Loading...
Searching...
No Matches
Friends | List of all members
StormByte::Buffer::Consumer Class Referencefinal

Read-oriented handle over a shared Ring. More...

#include <StormByte/buffer/consumer.hxx>

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

Public Member Functions

Copy / move / assignment
 Consumer (const Consumer &other) noexcept
 Copy constructor.
 
 Consumer (Consumer &&other) noexcept
 Move constructor.
 
 ~Consumer () noexcept override
 Destructor.
 
Consumeroperator= (const Consumer &other) noexcept
 Copy assignment.
 
Consumeroperator= (Consumer &&other) noexcept
 Move assignment.
 
Comparison
bool operator== (const Consumer &other) const noexcept
 Equality comparison.
 
bool operator!= (const Consumer &other) const noexcept
 Inequality comparison.
 
Queries
std::size_t AvailableBytes () const noexcept override
 Number of bytes available for reading from the current position.
 
const DataTypeData () const noexcept override
 Access a snapshot of the underlying data (implementation-defined).
 
bool Empty () const noexcept override
 Whether the shared Ring holds no stored bytes.
 
bool EoF () const noexcept override
 End-of-stream condition.
 
bool IsReadable () const noexcept override
 Whether the shared Ring can still be read.
 
bool IsWritable () const noexcept
 Whether the shared Ring still accepts writes.
 
bool HasError () const noexcept
 Whether the shared Ring is in a permanent error state.
 
std::size_t Size () const noexcept override
 Total number of bytes stored in the shared Ring.
 
Maintenance / lifecycle
void Clean () noexcept override
 Discard already-consumed data (from start up to the read position).
 
void Clear () noexcept override
 Clear all buffer contents.
 
void Close () noexcept
 Close the shared Ring for further writes.
 
bool Drop (const std::size_t &count) noexcept override
 Discard count bytes from the current read position.
 
void Seek (const std::ptrdiff_t &offset, const Position &mode) const noexcept override
 Move the logical read position for non-destructive reads.
 
Extract (destructive read)
bool Extract (const std::size_t &count, DataType &out) noexcept override
 Extract bytes into a DataType (consumes data from the Ring).
 
bool Extract (const std::size_t &count, WriteOnly &out) noexcept override
 Extract bytes into a WriteOnly sink (consumes data from the Ring).
 
void ExtractUntilEoF (DataType &out) noexcept override
 Extract all remaining bytes until EoF into a DataType.
 
void ExtractUntilEoF (WriteOnly &out) noexcept override
 Extract all remaining bytes until EoF into a WriteOnly.
 
Read (non-destructive)
bool Read (const std::size_t &count, DataType &out) const noexcept override
 Non-destructive read into a DataType (advances logical position).
 
bool Read (const std::size_t &count, WriteOnly &out) const noexcept override
 Non-destructive read into a WriteOnly (advances logical position).
 
void ReadUntilEoF (DataType &out) const noexcept override
 Read all remaining bytes until EoF into a DataType.
 
void ReadUntilEoF (WriteOnly &out) const noexcept override
 Read all remaining bytes until EoF into a WriteOnly.
 
Peek (non-destructive, does not advance position)
bool Peek (const std::size_t &count, DataType &out) const noexcept override
 Peek bytes into a DataType without advancing the read position.
 
bool Peek (const std::size_t &count, WriteOnly &out) const noexcept override
 Peek bytes into a WriteOnly without advancing the read position.
 
- Public Member Functions inherited from StormByte::Buffer::ReadOnly
 ReadOnly () noexcept
 Default construct.
 
 ReadOnly (const ReadOnly &) noexcept=default
 Copy construct.
 
 ReadOnly (ReadOnly &&) noexcept=default
 Move construct.
 
virtual ~ReadOnly () noexcept
 Virtual destructor.
 
ReadOnlyoperator= (const ReadOnly &)=default
 Copy assign.
 
ReadOnlyoperator= (ReadOnly &&) noexcept=default
 Move assign.
 
bool Extract (DataType &outBuffer) noexcept
 Extract all available bytes into a DataType.
 
bool Extract (WriteOnly &outBuffer) noexcept
 Extract all available bytes into a WriteOnly.
 
bool Read (DataType &outBuffer) const noexcept
 Read all available bytes into a DataType.
 
bool Read (WriteOnly &outBuffer) const noexcept
 Read all available bytes into a WriteOnly.
 
- Public Member Functions inherited from StormByte::Buffer::Generic
 Generic () noexcept=default
 Default construct.
 
 Generic (const Generic &) noexcept=default
 Copy construct.
 
 Generic (Generic &&) noexcept=default
 Move construct.
 
virtual ~Generic () noexcept=0
 Pure virtual destructor (keeps the class abstract).
 
Genericoperator= (const Generic &other)=default
 Copy assign.
 
Genericoperator= (Generic &&) noexcept=default
 Move assign.
 

Friends

class Producer
 

Additional Inherited Members

- Static Protected Member Functions inherited from StormByte::Buffer::Generic
template<Type::ByteInputRange Src>
static DataType DataConvert (const Src &src) noexcept
 Convert an lvalue input range to DataType.
 
template<Type::ByteInputRange Src>
static DataType DataConvert (Src &&src) noexcept
 Convert an rvalue input range to DataType (moves when already DataType).
 
static DataType DataConvert (std::string_view sv) noexcept
 Convert a string view to DataType (no trailing NUL).
 
static DataType DataConvert (const char *s) noexcept
 Convert a null-terminated C string to DataType.
 

Detailed Description

Read-oriented handle over a shared Ring.

Multiple Consumer instances may share the same underlying Ring, allowing concurrent reads in a fully thread-safe manner. Consumers can only be created through a Producer (see Producer::Consumer()).

All operations are thread-safe and delegate to the shared Ring. Blocking semantics match Ring: Read / Extract / Peek block until data is available or the buffer is closed / in error.

Lifecycle signalling
Although Consumer is primarily a ReadOnly view, it also exposes:
See also
Producer, Ring, ReadOnly

Constructor & Destructor Documentation

◆ Consumer() [1/2]

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

Copy constructor.

Parameters
otherSource Consumer; both share the same Ring.

◆ Consumer() [2/2]

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

Move constructor.

Parameters
otherSource Consumer (left in a valid but unspecified state).

◆ ~Consumer()

StormByte::Buffer::Consumer::~Consumer ( )
overridenoexcept

Destructor.

Member Function Documentation

◆ AvailableBytes()

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

Number of bytes available for reading from the current position.

Returns
Available byte count.

Implements StormByte::Buffer::ReadOnly.

◆ Clean()

void StormByte::Buffer::Consumer::Clean ( )
overridevirtualnoexcept

Discard already-consumed data (from start up to the read position).

Implements StormByte::Buffer::ReadOnly.

◆ Clear()

void StormByte::Buffer::Consumer::Clear ( )
overridevirtualnoexcept

Clear all buffer contents.

Does not clear closed / error flags on the shared Ring.

Implements StormByte::Buffer::ReadOnly.

◆ Close()

void StormByte::Buffer::Consumer::Close ( )
inlinenoexcept

Close the shared Ring for further writes.

Equivalent to Producer::Close on the same underlying buffer. Readers may still drain remaining data until EoF.

◆ Data()

const DataType & StormByte::Buffer::Consumer::Data ( ) const
overridevirtualnoexcept

Access a snapshot of the underlying data (implementation-defined).

Returns
Constant reference to the Ring’s data view.
Warning
Not intended for concurrent mutation; prefer Read / Extract.

Implements StormByte::Buffer::ReadOnly.

◆ Drop()

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

Discard count bytes from the current read position.

Parameters
countNumber of bytes to drop.
Returns
true on success, false if fewer bytes were available.

Implements StormByte::Buffer::ReadOnly.

◆ Empty()

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

Whether the shared Ring holds no stored bytes.

Returns
true if empty.
Note
With a non-zero read position, Empty() may still be false even when AvailableBytes() is zero.

Implements StormByte::Buffer::ReadOnly.

◆ EoF()

bool StormByte::Buffer::Consumer::EoF ( ) const
overridevirtualnoexcept

End-of-stream condition.

Returns
true when the Ring is closed (or in error) and no bytes remain.

Implements StormByte::Buffer::ReadOnly.

◆ Extract() [1/2]

bool StormByte::Buffer::Consumer::Extract ( const std::size_t &  count,
DataType out 
)
overridevirtualnoexcept

Extract bytes into a DataType (consumes data from the Ring).

Parameters
countNumber of bytes to extract; 0 extracts all available.
outDestination buffer (appended to / filled by the Ring).
Returns
true on success, false on insufficient data or error.

Implements StormByte::Buffer::ReadOnly.

◆ Extract() [2/2]

bool StormByte::Buffer::Consumer::Extract ( const std::size_t &  count,
WriteOnly out 
)
overridevirtualnoexcept

Extract bytes into a WriteOnly sink (consumes data from the Ring).

Parameters
countNumber of bytes to extract; 0 extracts all available.
outDestination writer.
Returns
true on success, false on insufficient data or error.

Implements StormByte::Buffer::ReadOnly.

◆ ExtractUntilEoF() [1/2]

void StormByte::Buffer::Consumer::ExtractUntilEoF ( DataType out)
overridevirtualnoexcept

Extract all remaining bytes until EoF into a DataType.

Parameters
outDestination buffer.

Implements StormByte::Buffer::ReadOnly.

◆ ExtractUntilEoF() [2/2]

void StormByte::Buffer::Consumer::ExtractUntilEoF ( WriteOnly out)
overridevirtualnoexcept

Extract all remaining bytes until EoF into a WriteOnly.

Parameters
outDestination writer.

Implements StormByte::Buffer::ReadOnly.

◆ HasError()

bool StormByte::Buffer::Consumer::HasError ( ) const
inlinenoexcept

Whether the shared Ring is in a permanent error state.

Returns
true after SetError() on any handle to the same Ring.

◆ IsReadable()

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

Whether the shared Ring can still be read.

Returns
false if the Ring is in a permanent error state.

Implements StormByte::Buffer::ReadOnly.

◆ IsWritable()

bool StormByte::Buffer::Consumer::IsWritable ( ) const
inlinenoexcept

Whether the shared Ring still accepts writes.

Returns
false if closed or in error.

Observes producer-side lifecycle on the same Ring (e.g. wait until a pipeline stage calls Close()).

◆ operator!=()

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

Inequality comparison.

Parameters
otherOther Consumer.
Returns
true if the underlying Ring instances differ.

◆ operator=() [1/2]

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

Copy assignment.

Parameters
otherSource Consumer; both share the same Ring afterwards.
Returns
Reference to this Consumer.

◆ operator=() [2/2]

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

Move assignment.

Parameters
otherSource Consumer.
Returns
Reference to this Consumer.

◆ operator==()

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

Equality comparison.

Parameters
otherOther Consumer.
Returns
true if both refer to the same underlying Ring instance.

◆ Peek() [1/2]

bool StormByte::Buffer::Consumer::Peek ( const std::size_t &  count,
DataType out 
) const
overridevirtualnoexcept

Peek bytes into a DataType without advancing the read position.

Parameters
countNumber of bytes to peek; 0 peeks all available.
outDestination buffer.
Returns
true on success, false on insufficient data or error.

Implements StormByte::Buffer::ReadOnly.

◆ Peek() [2/2]

bool StormByte::Buffer::Consumer::Peek ( const std::size_t &  count,
WriteOnly out 
) const
overridevirtualnoexcept

Peek bytes into a WriteOnly without advancing the read position.

Parameters
countNumber of bytes to peek; 0 peeks all available.
outDestination writer.
Returns
true on success, false on insufficient data or error.

Implements StormByte::Buffer::ReadOnly.

◆ Read() [1/2]

bool StormByte::Buffer::Consumer::Read ( const std::size_t &  count,
DataType out 
) const
overridevirtualnoexcept

Non-destructive read into a DataType (advances logical position).

Parameters
countNumber of bytes to read; 0 reads all available.
outDestination buffer.
Returns
true on success, false on insufficient data or error.

Implements StormByte::Buffer::ReadOnly.

◆ Read() [2/2]

bool StormByte::Buffer::Consumer::Read ( const std::size_t &  count,
WriteOnly out 
) const
overridevirtualnoexcept

Non-destructive read into a WriteOnly (advances logical position).

Parameters
countNumber of bytes to read; 0 reads all available.
outDestination writer.
Returns
true on success, false on insufficient data or error.

Implements StormByte::Buffer::ReadOnly.

◆ ReadUntilEoF() [1/2]

void StormByte::Buffer::Consumer::ReadUntilEoF ( DataType out) const
overridevirtualnoexcept

Read all remaining bytes until EoF into a DataType.

Parameters
outDestination buffer.

Implements StormByte::Buffer::ReadOnly.

◆ ReadUntilEoF() [2/2]

void StormByte::Buffer::Consumer::ReadUntilEoF ( WriteOnly out) const
overridevirtualnoexcept

Read all remaining bytes until EoF into a WriteOnly.

Parameters
outDestination writer.

Implements StormByte::Buffer::ReadOnly.

◆ Seek()

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

Move the logical read position for non-destructive reads.

Parameters
offsetOffset value.
modePosition::Absolute or Position::Relative.

Implements StormByte::Buffer::ReadOnly.

◆ Size()

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

Total number of bytes stored in the shared Ring.

Returns
Size in bytes.

Implements StormByte::Buffer::ReadOnly.

Friends And Related Symbol Documentation

◆ Producer

friend class Producer
friend

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