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::Producer Class Referencefinal

Producer interface for writing data to a shared FIFO buffer. More...

#include <producer.hxx>

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

Public Member Functions

 Producer () noexcept
 Construct a Producer with a new SharedFIFO buffer.
 
 Producer (std::shared_ptr< SharedFIFO > buffer)
 Construct a Producer with an existing SharedFIFO buffer.
 
 Producer (const Consumer &consumer)
 Construct a Producer from a Consumer's buffer.
 
 Producer (const Producer &other) noexcept
 Copy constructor.
 
 Producer (Producer &&other) noexcept
 Move constructor.
 
 ~Producer () noexcept=default
 Destructor.
 
Produceroperator= (const Producer &other) noexcept
 Copy assignment operator.
 
Produceroperator= (Producer &&other) noexcept
 Move assignment operator.
 
bool operator== (const Producer &other) const noexcept
 Equality comparison.
 
bool operator!= (const Producer &other) const noexcept
 Inequality comparison.
 
void Close () noexcept
 Thread-safe close for further writes.
 
bool IsWritable () const noexcept override
 Check if the buffer is writable.
 
void SetError () noexcept
 Thread-safe error state setting.
 
bool Write (const std::size_t &count, const DataType &data) noexcept override
 Write bytes from a vector to the buffer.
 
bool Write (const DataType &data) noexcept
 Write all 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 (DataType &&data) noexcept
 Move all 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.
 
class Consumer Consumer ()
 Create a Consumer for reading from this Producer's buffer.
 
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::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.
 
- 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.
 

Protected Attributes

std::shared_ptr< SharedFIFOm_buffer
 
- Protected Attributes inherited from StormByte::Buffer::Generic
DataType m_buffer
 Internal buffer storage.
 

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.
 

Detailed Description

Producer interface for writing data to a shared FIFO buffer.

Overview
Producer provides a write-only interface to a SharedFIFO buffer. Multiple Producer instances can share the same underlying buffer, allowing multiple producers to write data concurrently in a thread-safe manner.
Thread safety
All write operations are thread-safe as they delegate to the underlying SharedFIFO which is fully thread-safe.

Constructor & Destructor Documentation

◆ Producer() [1/5]

StormByte::Buffer::Producer::Producer ( )
inlinenoexcept

Construct a Producer with a new SharedFIFO buffer.

Creates a new Producer instance with its own underlying SharedFIFO buffer for writing data.

◆ Producer() [2/5]

StormByte::Buffer::Producer::Producer ( std::shared_ptr< SharedFIFO buffer)
inline

Construct a Producer with an existing SharedFIFO buffer.

Parameters
bufferShared pointer to the SharedFIFO buffer to produce to.

Private constructor only accessible by Consumer (friend class). Creates a new Producer instance that shares the given buffer.

◆ Producer() [3/5]

StormByte::Buffer::Producer::Producer ( const Consumer consumer)
inline

Construct a Producer from a Consumer's buffer.

Creates a new Producer instance sharing the same underlying SharedFIFO buffer as the provided Consumer.

◆ Producer() [4/5]

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

Copy constructor.

Parameters
otherSource Producer to copy from.

Copies the Producer instance, sharing the same underlying buffer. Both instances will write to the same SharedFIFO.

◆ Producer() [5/5]

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

Move constructor.

Parameters
otherSource Producer to move from.

Transfers ownership of the buffer from the moved-from Producer.

Member Function Documentation

◆ Close()

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

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

◆ Consumer()

class Consumer StormByte::Buffer::Producer::Consumer ( )
inline

Create a Consumer for reading from this Producer's buffer.

Returns
A Consumer instance sharing the underlying buffer.

Enables producer-consumer pattern. Consumer has read-only access to the same SharedFIFO buffer this Producer writes to.

See also
Consumer

◆ IsWritable()

bool StormByte::Buffer::Producer::IsWritable ( ) const
inlineoverridevirtualnoexcept

Check if the buffer is writable.

Returns
true if the buffer can accept write operations, false if closed or in error state.

Implements StormByte::Buffer::WriteOnly.

◆ operator!=()

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

Inequality comparison.

Returns
true if Producers have different underlying buffers.

◆ operator=() [1/2]

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

Copy assignment operator.

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

◆ operator=() [2/2]

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

Move assignment operator.

Returns
Reference to this Producer.

◆ operator==()

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

Equality comparison.

Returns
true if both Producers share the same underlying buffer.

◆ SetError()

void StormByte::Buffer::Producer::SetError ( )
inlinenoexcept

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

◆ Write() [1/23]

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

Expose the rest of overloads

◆ Write() [2/23]

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

Expose the rest of overloads

◆ Write() [3/23]

bool StormByte::Buffer::Producer::Write ( const DataType &  data)
inlinenoexcept

Write all bytes from a vector to the buffer.

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

◆ Write() [4/23]

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() [5/23]

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

Expose the rest of overloads

◆ Write() [6/23]

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

Expose the rest of overloads

◆ Write() [7/23]

bool StormByte::Buffer::Producer::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() [8/23]

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() [9/23]

bool StormByte::Buffer::Producer::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() [10/23]

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() [11/23]

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() [12/23]

bool StormByte::Buffer::Producer::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() [13/23]

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

Expose the rest of overloads

Implements StormByte::Buffer::WriteOnly.

◆ Write() [14/23]

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() [15/23]

bool StormByte::Buffer::Producer::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() [16/23]

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

Expose the rest of overloads

Implements StormByte::Buffer::WriteOnly.

◆ Write() [17/23]

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() [18/23]

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

Expose the rest of overloads

◆ Write() [19/23]

bool StormByte::Buffer::Producer::Write ( DataType &&  data)
inlinenoexcept

Move all bytes from a vector to the buffer.

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

◆ Write() [20/23]

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() [21/23]

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

Expose the rest of overloads

◆ Write() [22/23]

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() [23/23]

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

Expose the rest of overloads


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