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::WriteOnly Class Referenceabstract

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

#include <generic.hxx>

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

Public Member Functions

 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.
 
virtual bool IsWritable () const noexcept=0
 Check if the buffer is writable.
 
virtual bool Write (const std::size_t &count, const DataType &data) noexcept=0
 Write bytes from a vector to the buffer.
 
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).
 
virtual bool Write (const std::size_t &count, DataType &&data) noexcept=0
 Move bytes from a vector to the buffer.
 
virtual bool Write (const std::size_t &count, const ReadOnly &data) noexcept=0
 Write bytes from a vector to the buffer.
 
bool Write (const ReadOnly &data) noexcept
 Write bytes from a vector to the buffer.
 
virtual bool Write (const std::size_t &count, ReadOnly &&data) noexcept=0
 Move 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.
 

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 written to but not read from.

Overview
WriteOnly extends Generic to provide a write-only buffer interface. It allows writing data to the buffer while preventing any read operations. This is useful for scenarios where data needs to be collected or buffered without exposing it for reading.

Constructor & Destructor Documentation

◆ WriteOnly() [1/2]

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

Construct WriteOnly.

Parameters
dataInitial byte vector to populate the WriteOnly.

◆ WriteOnly() [2/2]

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

Construct WriteOnly with initial data using move semantics.

Parameters
dataInitial byte vector to move into the WriteOnly.

Member Function Documentation

◆ IsWritable()

virtual bool StormByte::Buffer::WriteOnly::IsWritable ( ) const
pure virtualnoexcept

Check if the buffer is writable.

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

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

◆ Write() [1/13]

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

Write all elements from an input range to the buffer.

Template Parameters
RAn input range whose element type is convertible to std::byte.
Parameters
rThe input range to write from. Elements are converted element-wise using static_cast<std::byte>.
Returns
bool indicating success or failure.

The entire range is converted into a DataType (the library's std::vector<std::byte>) and then forwarded to the canonical Write(count, DataType) entry point.

◆ Write() [2/13]

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

Write 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() [3/13]

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

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

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

◆ Write() [4/13]

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

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

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

◆ Write() [5/13]

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

Write up-to count elements from an input range.

Template Parameters
RwAn input range whose value_type is convertible to std::byte.
Parameters
countMaximum number of elements to write; pass 0 to write the entire range.
rThe input range to read from.
Returns
bool with the number of bytes actually written (may be less than count if the range is shorter).

Elements are copied and converted into an internal DataType buffer before invoking the canonical Write(count, DataType).

◆ Write() [6/13]

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

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

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

◆ Write() [7/13]

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

Write up-to count bytes from an iterator pair (0 => all available).

Write up-to count elements from an iterator pair.

Template Parameters
I2Input iterator type whose value_type is convertible to std::byte.
S2Corresponding sentinel type for I2.
Parameters
countMaximum number of elements to write; pass 0 to write all.
firstIterator to the beginning of the sequence.
lastSentinel/iterator marking the end of the sequence.
Returns
bool indicating success or failure.

Iterates until count elements are consumed or first == last.

◆ Write() [8/13]

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

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

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

◆ Write() [9/13]

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

Write up-to count elements from an rvalue range.

Template Parameters
RrwAn input range type that may be an rvalue DataType.
Parameters
countMaximum number of elements to write; pass 0 to write the entire range.
rThe rvalue range to consume. If r is a DataType rvalue the implementation will move it into the write fast-path and trim it to count if necessary. Otherwise elements are converted and copied into a temporary DataType.
Returns
bool indicating success or failure.

◆ Write() [10/13]

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

Write from iterator pair whose value_type is convertible to std::byte.

Write all elements from an iterator pair.

Template Parameters
IInput iterator type whose value_type is convertible to std::byte.
SCorresponding sentinel type for I.
Parameters
firstIterator to the beginning of the sequence.
lastSentinel/iterator marking the end of the sequence.
Returns
bool indicating success or failure.

Elements are converted via static_cast<std::byte> into an internal DataType buffer which is then forwarded to the canonical Write(count, DataType).

◆ Write() [11/13]

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

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

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

Write from an rvalue input range.

Template Parameters
RrInput range type; this overload prefers moving when the range type is the library DataType (i.e. std::vector<std::byte>).
Parameters
rThe rvalue range to write from. If r is a DataType rvalue it will be forwarded into the move-write fast-path; otherwise elements are converted and copied into a temporary DataType.
Returns
bool indicating success or failure.

◆ Write() [13/13]

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

Write from a string view (does not include terminating NUL).

Note
String convenience overloads

These non-template overloads exist to ensure std::string / C-string inputs bind to a stable, well-defined implementation instead of the generic input-range template above. Without these entries, calls like Write("abc") or Write(std::string{}) may select the range template which can lead to surprising template instantiation differences and SFINAE interactions. The overloads also avoid copying the trailing NUL for string-literal arrays by explicitly constructing a std::string_view of size N-1.


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