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

Thread-safe FIFO built on top of FIFO. More...

#include <shared_fifo.hxx>

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

Public Member Functions

 SharedFIFO () noexcept=default
 Construct a SharedFIFO with optional initial capacity.
 
 SharedFIFO (const DataType &data)
 Construct a SharedFIFO with initial data.
 
 SharedFIFO (DataType &&data) noexcept
 Construct a SharedFIFO 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>)
 SharedFIFO (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); }
 SharedFIFO (Rr &&r) noexcept
 Construct FIFO from an rvalue range (moves when DataType rvalue).
 
 SharedFIFO (std::string_view sv) noexcept
 Construct FIFO from a string view (does not include terminating NUL).
 
 SharedFIFO (const FIFO &other)
 Construct a SharedFIFO by copying or moving from a FIFO.
 
 SharedFIFO (FIFO &&other) noexcept
 Construct a SharedFIFO by moving from a FIFO.
 
 SharedFIFO (const SharedFIFO &)=delete
 Copy constructors are deleted.
 
 SharedFIFO (SharedFIFO &&other) noexcept=default
 Move constructor.
 
virtual ~SharedFIFO () noexcept=default
 Virtual destructor.
 
SharedFIFOoperator= (const FIFO &other)
 Copy assignment from FIFO.
 
SharedFIFOoperator= (FIFO &&other) noexcept
 Move assignment from FIFO.
 
SharedFIFOoperator= (const SharedFIFO &)=delete
 Copy and move assignment operators are deleted.
 
SharedFIFOoperator= (SharedFIFO &&) noexcept
 Move assignment operator.
 
bool operator== (const SharedFIFO &other) const noexcept
 Equality comparison (thread-safe).
 
bool operator!= (const SharedFIFO &other) const noexcept
 Inequality comparison.
 
virtual std::size_t AvailableBytes () const noexcept override
 Get the number of bytes available for reading.
 
void Clean () noexcept override
 Thread-safe clean of buffer data from start to read position.
 
virtual void Clear () noexcept override
 Thread-safe clear of all buffer contents.
 
virtual const DataType & Data () const noexcept override
 Access the internal data buffer.
 
virtual void Close () noexcept
 Thread-safe close for further writes.
 
virtual bool Drop (const std::size_t &count) noexcept override
 Thread-safe drop operation.
 
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 HasError () const noexcept
 Check if the buffer is in an error state.
 
virtual std::string HexDump (const std::size_t &collumns=0, const std::size_t &byte_limit=0) const noexcept override
 Produce a thread-safe hexdump of the buffer.
 
virtual bool IsReadable () const noexcept override
 Check if the buffer is readable (not in error state).
 
virtual bool IsWritable () const noexcept override
 Check if the buffer is writable (not closed and not in error state).
 
virtual void Seek (const std::ptrdiff_t &offset, const Position &mode) const noexcept override
 Move the read position for non-destructive reads.
 
virtual void SetError () noexcept
 Thread-safe error state setting.
 
virtual std::size_t Size () const noexcept override
 Get the current number of bytes stored in the buffer.
 
- Public Member Functions inherited from StormByte::Buffer::FIFO
 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.
 
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.
 
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.
 
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 Attributes

bool m_closed {false}
 Whether the SharedFIFO is closed for further writes.
 
bool m_error {false}
 Whether the SharedFIFO is in an error state.
 
std::string m_error_message
 Optional error message associated with the error state.
 
- Protected Attributes inherited from StormByte::Buffer::FIFO
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.
 

Additional Inherited Members

- Protected Types inherited from StormByte::Buffer::FIFO
enum class  Operation { Extract , Read , Peek }
 Enumeration of read operation types. More...
 
- Protected Member Functions inherited from StormByte::Buffer::FIFO
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 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 inherited from StormByte::Buffer::FIFO
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.
 

Detailed Description

Thread-safe FIFO built on top of FIFO.

Overview
SharedFIFO wraps the non-thread-safe FIFO with a mutex and a condition variable to provide safe concurrent access from multiple producer/consumer threads. It preserves the byte-oriented FIFO semantics of FIFO while adding blocking behavior for reads and extracts.
Blocking semantics
  • Read(const std::size_t&) blocks until the requested number of bytes are available from the current non-destructive read position, or until the FIFO is closed via Close(). If count == 0, it returns immediately with all bytes available from the current read position.
  • Extract(const std::size_t&) blocks until at least count bytes exist in the buffer (destructive), or until closed. If count == 0, it returns immediately with all available data and clears the buffer.
Close behavior
Close() marks the FIFO as closed and notifies all waiting threads. Subsequent calls to Write() are ignored. Waiters will wake and complete using whatever data is presently available (which may be none).
Seek behavior
Seek() updates the internal non-destructive read position and notifies waiters so blocked readers can re-evaluate their predicates relative to the new position.
Thread safety
All public member functions of SharedFIFO are thread-safe. Methods that mutate internal state (Write/Extract/Clear/Close/Seek/Reserve) acquire the internal mutex. Read accessors also acquire the mutex to maintain consistency with the current head/tail/read-position state.

Constructor & Destructor Documentation

◆ SharedFIFO() [1/9]

StormByte::Buffer::SharedFIFO::SharedFIFO ( )
defaultnoexcept

Construct a SharedFIFO with optional initial capacity.

Parameters
capacityInitial number of bytes to allocate in the buffer. Behaves like FIFO and may grow as needed.

◆ SharedFIFO() [2/9]

StormByte::Buffer::SharedFIFO::SharedFIFO ( const DataType &  data)
inline

Construct a SharedFIFO with initial data.

Parameters
dataInitial byte vector to populate the FIFO.

◆ SharedFIFO() [3/9]

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

Construct a SharedFIFO with initial data using move semantics.

Parameters
dataInitial byte vector to move into the FIFO.

◆ SharedFIFO() [4/9]

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::SharedFIFO::SharedFIFO ( 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.

◆ SharedFIFO() [5/9]

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::SharedFIFO::SharedFIFO ( 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.

◆ SharedFIFO() [6/9]

StormByte::Buffer::SharedFIFO::SharedFIFO ( const FIFO other)
inline

Construct a SharedFIFO by copying or moving from a FIFO.

Parameters
otherSource FIFO to copy or move from.

◆ SharedFIFO() [7/9]

StormByte::Buffer::SharedFIFO::SharedFIFO ( FIFO &&  other)
inlinenoexcept

Construct a SharedFIFO by moving from a FIFO.

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

◆ SharedFIFO() [8/9]

StormByte::Buffer::SharedFIFO::SharedFIFO ( const SharedFIFO )
delete

Copy constructors are deleted.

SharedFIFO contains synchronization primitives and shared internal state (mutex, condition variable, etc.). Copying or moving instances would require careful transfer or duplication of these primitives which is unsafe and error-prone. To avoid accidental misuse and subtle concurrency bugs these constructors are explicitly deleted. If duplication of the stored bytes is required, copy the data via the base FIFO and construct a new SharedFIFO.

◆ SharedFIFO() [9/9]

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

Move constructor.

Parameters
otherSource SharedFIFO to move from; left in a valid but

Member Function Documentation

◆ AvailableBytes()

virtual std::size_t StormByte::Buffer::SharedFIFO::AvailableBytes ( ) const
overridevirtualnoexcept

Get the number of bytes available for reading.

Returns
Number of bytes available from the current read position.

Reimplemented from StormByte::Buffer::FIFO.

◆ Clean()

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

Thread-safe clean of buffer data from start to read position.

See also
FIFO::Clean()

Reimplemented from StormByte::Buffer::FIFO.

◆ Clear()

virtual void StormByte::Buffer::SharedFIFO::Clear ( )
overridevirtualnoexcept

Thread-safe clear of all buffer contents.

See also
FIFO::Clear()

Reimplemented from StormByte::Buffer::FIFO.

◆ Close()

virtual void StormByte::Buffer::SharedFIFO::Close ( )
virtualnoexcept

Thread-safe close for further writes.

Marks buffer as closed, notifies all waiting threads. Subsequent writes are ignored. The buffer remains readable until all data is consumed.

See also
FIFO::Close(), IsWritable()

◆ Data()

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

Access the internal data buffer.

Note
Warning: Not thread-safe. Caller must ensure exclusive access.
Returns
Constant reference to the internal DataType buffer.

Reimplemented from StormByte::Buffer::FIFO.

◆ Drop()

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

Thread-safe drop operation.

Returns
true if the bytes were successfully dropped, false otherwise.

Notifies waiting readers after dropping.

See also
FIFO::Drop()

Reimplemented from StormByte::Buffer::FIFO.

◆ Empty()

virtual bool StormByte::Buffer::SharedFIFO::Empty ( ) const
overridevirtualnoexcept

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

Reimplemented from StormByte::Buffer::FIFO.

◆ EoF()

virtual bool StormByte::Buffer::SharedFIFO::EoF ( ) const
overridevirtualnoexcept

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.

Reimplemented from StormByte::Buffer::FIFO.

◆ HasError()

bool StormByte::Buffer::SharedFIFO::HasError ( ) const
noexcept

Check if the buffer is in an error state.

Returns
true if the buffer is in error state, false otherwise.

◆ HexDump()

virtual std::string StormByte::Buffer::SharedFIFO::HexDump ( const std::size_t &  collumns = 0,
const std::size_t &  byte_limit = 0 
) const
overridevirtualnoexcept

Produce a thread-safe hexdump of the buffer.

Parameters
collumnsNumber of columns per line (0 -> default 16).
byte_limitMaximum number of bytes to include (0 -> no limit).
Returns
A formatted dump string. Does not append a trailing newline.

Acquires the internal mutex for reading so the dump represents a consistent snapshot. The returned string begins with a status line of the form Status: opened|closed, ready|error
followed by the same output produced by FIFO::HexDump(). Example output:

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

Reimplemented from StormByte::Buffer::FIFO.

◆ IsReadable()

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

Check if the buffer is readable (not in error state).

Returns
true if readable, false if buffer is in error state.

A buffer becomes unreadable when SetError() is called. Use in combination with AvailableBytes() to check if there is data pending to read.

See also
SetError(), IsWritable(), AvailableBytes(), EoF()

Reimplemented from StormByte::Buffer::FIFO.

◆ IsWritable()

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

Check if the buffer is writable (not closed and not in error state).

Returns
true if writable, false if closed or in error state.

A buffer becomes unwritable when Close() or SetError() is called.

See also
Close(), SetError(), IsReadable()

Reimplemented from StormByte::Buffer::FIFO.

◆ operator!=()

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

Inequality comparison.

Negates operator==.

◆ operator=() [1/4]

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

Copy assignment from FIFO.

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

◆ operator=() [2/4]

SharedFIFO & StormByte::Buffer::SharedFIFO::operator= ( const SharedFIFO )
delete

Copy and move assignment operators are deleted.

Assigning one SharedFIFO to another would imply transferring or duplicating ownership of internal synchronization primitives (mutex/condition variable) and internal buffer state. This is unsafe and therefore these operators are explicitly deleted. Use explicit data-copy via FIFO if needed.

◆ operator=() [3/4]

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

Move assignment from FIFO.

Parameters
otherSource FIFO to move from.
Returns
Reference to this SharedFIFO.

◆ operator=() [4/4]

SharedFIFO & StormByte::Buffer::SharedFIFO::operator= ( SharedFIFO &&  )
noexcept

Move assignment operator.

Parameters
otherSource SharedFIFO to move from; left in a valid but unspecified state.
Returns
Reference to this SharedFIFO.

◆ operator==()

bool StormByte::Buffer::SharedFIFO::operator== ( const SharedFIFO other) const
noexcept

Equality comparison (thread-safe).

Compares this SharedFIFO with other while holding both internal mutexes. The comparison delegates to the base FIFO::operator==, so equality semantics follow the FIFO implementation.

◆ Seek()

virtual void StormByte::Buffer::SharedFIFO::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

Reimplemented from StormByte::Buffer::FIFO.

◆ SetError()

virtual void StormByte::Buffer::SharedFIFO::SetError ( )
virtualnoexcept

Thread-safe error state setting.

Marks buffer as erroneous (unreadable and unwritable), notifies all waiting threads. Subsequent writes are ignored and reads will fail.

See also
FIFO::SetError(), IsReadable(), IsWritable()

◆ Size()

virtual std::size_t StormByte::Buffer::SharedFIFO::Size ( ) const
overridevirtualnoexcept

Get the current number of bytes stored in the buffer.

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

Reimplemented from StormByte::Buffer::FIFO.


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