44#include <StormByte/type_traits/safe.hxx>
47#include <StormByte/byte_size.hxx>
48#include <StormByte/safe/binary.hxx>
49#include <StormByte/type_traits.hxx>
155 template<
Type::ByteInputRange Src>
158 if constexpr (
requires { std::ranges::size(src); }) {
159 auto s = std::ranges::size(src);
163 std::transform(std::ranges::begin(src), std::ranges::end(src), std::back_inserter(out),
164 [](
auto&& e)
noexcept {
return static_cast<std::byte
>(e); });
174 template<Type::ByteInputRange Src>
177 return std::move(src);
180 if constexpr (
requires { std::ranges::size(src); }) {
181 auto s = std::ranges::size(src);
185 std::transform(std::ranges::begin(src), std::ranges::end(src), std::back_inserter(out),
186 [](
auto&& e)
noexcept {
return static_cast<std::byte
>(e); });
282 virtual const
Safe::Binary&
Data() const noexcept = 0;
289 virtual
bool Empty() const noexcept = 0;
295 virtual
bool EoF() const noexcept = 0;
340 virtual
void Seek(const
std::ptrdiff_t& offset, const
Position& mode) const noexcept = 0;
625 return Write(data.Available(), data);
634 return Write(data.Available(), std::move(data));
651 bool Write(std::string_view sv)
noexcept;
682 template<std::
size_t N>
683 bool Write(
const char (&s)[N])
noexcept {
686 return Write(std::string_view(s, (N > 0) ? (N - 1) : 0));
704 template<Type::ByteInputRange R>
707 if constexpr (
requires { std::ranges::size(r); }) {
708 auto dist = std::ranges::size(r);
712 std::transform(std::ranges::begin(r), std::ranges::end(r), std::back_inserter(tmp),
713 [](
auto&& e)
noexcept {
return static_cast<std::byte
>(e); });
714 return Write(tmp.
size(), std::move(tmp));
724 template<Type::ByteInputRange Rw>
730 auto it = std::ranges::begin(r);
731 auto end = std::ranges::end(r);
734 tmp.
push_back(
static_cast<std::byte
>(*it));
735 return Write(written, std::move(tmp));
745 template<Type::ByteInputRange Rrw>
748 return Write(std::forward<Rrw>(r));
751 if (tmp.
size() > count)
753 return Write(tmp.
size(), std::move(tmp));
757 auto it = std::ranges::begin(r);
758 auto end = std::ranges::end(r);
761 tmp.
push_back(
static_cast<std::byte
>(*it));
762 return Write(written, std::move(tmp));
772 template<Type::ByteInputRange Rr>
775 return Write(r.size(), std::move(r));
778 if constexpr (
requires { std::ranges::size(r); }) {
779 auto dist = std::ranges::size(r);
783 std::transform(std::ranges::begin(r), std::ranges::end(r), std::back_inserter(tmp),
784 [](
auto&& e)
noexcept {
return static_cast<std::byte
>(e); });
785 return Write(tmp.
size(), std::move(tmp));
797 template<Type::ByteInputIterator I,
typename S>
801 std::transform(first, last, std::back_inserter(tmp),
802 [](
auto&& e)
noexcept {
return static_cast<std::byte
>(e); });
803 return Write(tmp.
size(), std::move(tmp));
815 template<Type::ByteInputIterator I2,
typename S2>
819 return Write(first, last);
822 for (; first != last && written < count; ++first, written = written +
StormByte::ByteSize{1})
823 tmp.
push_back(
static_cast<std::byte
>(*first));
824 return Write(written, std::move(tmp));
Abstract root of the byte-buffer interfaces.
Definition generic.hxx:81
Generic() noexcept
Default constructor.
static STORMBYTE_FORCE_INLINE Safe::Binary DataConvert(Src &&src) noexcept
Convert an rvalue input range to StormByte::Safe::Binary.
Definition generic.hxx:175
static STORMBYTE_FORCE_INLINE Safe::Binary DataConvert(const Src &src) noexcept
Convert an lvalue input range to StormByte::Safe::Binary.
Definition generic.hxx:156
static Safe::Binary DataConvert(const char *s) noexcept
Convert a C string to StormByte::Safe::Binary.
virtual StormByte::ByteSize Size() const noexcept=0
Total number of bytes stored.
static Safe::Binary DataConvert(std::string_view sv) noexcept
Convert a string view to StormByte::Safe::Binary.
Buffer that can be read and not written.
Definition generic.hxx:220
virtual bool EoF() const noexcept=0
End of stream.
virtual bool IsReadable() const noexcept=0
Whether the buffer can still be read.
virtual void ExtractUntilEoF(WriteOnly &outBuffer) noexcept=0
Extract until EoF into a WriteOnly.
virtual const Safe::Binary & Data() const noexcept=0
View of internal storage.
virtual bool Empty() const noexcept=0
Whether the store holds no bytes.
virtual void Clean() noexcept=0
Drop bytes from the start up to the current read position.
virtual bool Extract(const StormByte::ByteSize &count, WriteOnly &outBuffer) noexcept=0
Extract bytes into a WriteOnly.
virtual bool Drop(const StormByte::ByteSize &count) noexcept=0
Discard count unread bytes.
virtual void ExtractUntilEoF(StormByte::Safe::Binary &outBuffer) noexcept=0
Extract until EoF into a StormByte::Safe::Binary.
virtual StormByte::ByteSize Available() const noexcept=0
Bytes available from the current read position.
virtual bool Peek(const StormByte::ByteSize &count, WriteOnly &outBuffer) const noexcept=0
Peek into a WriteOnly.
bool Read(StormByte::Safe::Binary &outBuffer) const noexcept
Read all available bytes into a StormByte::Safe::Binary.
Definition generic.hxx:449
bool Read(WriteOnly &outBuffer) const noexcept
Read all available bytes into a WriteOnly.
Definition generic.hxx:466
virtual bool Read(const StormByte::ByteSize &count, StormByte::Safe::Binary &outBuffer) const noexcept=0
Read into a StormByte::Safe::Binary.
virtual void Seek(const std::ptrdiff_t &offset, const Position &mode) const noexcept=0
Move the logical read position.
virtual bool Read(const StormByte::ByteSize &count, WriteOnly &outBuffer) const noexcept=0
Read into a WriteOnly.
virtual bool Peek(const StormByte::ByteSize &count, StormByte::Safe::Binary &outBuffer) const noexcept=0
Peek into a StormByte::Safe::Binary.
virtual void ReadUntilEoF(StormByte::Safe::Binary &outBuffer) const noexcept=0
Read until EoF into a StormByte::Safe::Binary.
ReadOnly() noexcept
Default constructor.
bool Extract(WriteOnly &outBuffer) noexcept
Extract all available bytes into a WriteOnly.
Definition generic.hxx:381
virtual void Clear() noexcept=0
Clear stored bytes and reset logical positions.
virtual bool Extract(const StormByte::ByteSize &count, StormByte::Safe::Binary &outBuffer) noexcept=0
Extract bytes into a StormByte::Safe::Binary.
virtual void ReadUntilEoF(WriteOnly &outBuffer) const noexcept=0
Read until EoF into a WriteOnly.
ReadWrite() noexcept
Default constructor.
Buffer that can be written and not read.
Definition generic.hxx:497
virtual void Close() noexcept=0
Stop further writes.
virtual bool IsWritable() const noexcept=0
Whether the buffer accepts writes.
bool Write(const char *s) noexcept
Write a C string.
virtual bool Write(const StormByte::ByteSize &count, const Safe::Binary &data) noexcept=0
Append bytes from a StormByte::Safe::Binary (copy).
STORMBYTE_FORCE_INLINE bool Write(const R &r) noexcept
Write all elements from an input range.
Definition generic.hxx:705
STORMBYTE_FORCE_INLINE bool Write(I first, S last) noexcept
Write all elements from an iterator pair.
Definition generic.hxx:799
bool Write(const char(&s)[N]) noexcept
Write a string literal without the trailing NUL.
Definition generic.hxx:683
bool Write(ReadOnly &&data) noexcept
Append all available bytes from a ReadOnly (extract).
Definition generic.hxx:633
virtual void SetError() noexcept=0
Permanent error.
bool Write(const StormByte::ByteSize &count, std::string_view sv) noexcept
Write up to count characters of a string view.
WriteOnly() noexcept
Default constructor.
STORMBYTE_FORCE_INLINE bool Write(const StormByte::ByteSize &count, Rrw &&r) noexcept
Write up to count elements from an rvalue range.
Definition generic.hxx:746
STORMBYTE_FORCE_INLINE bool Write(Rr &&r) noexcept
Write all elements from an rvalue range.
Definition generic.hxx:773
bool Write(const StormByte::ByteSize &count, const char *s) noexcept
Write up to count characters of a C string.
bool Write(std::string_view sv) noexcept
Write a string view.
STORMBYTE_FORCE_INLINE bool Write(const StormByte::ByteSize &count, I2 first, S2 last) noexcept
Write up to count elements from an iterator pair.
Definition generic.hxx:817
STORMBYTE_FORCE_INLINE bool Write(const StormByte::ByteSize &count, const Rw &r) noexcept
Write up to count elements from an input range.
Definition generic.hxx:725
void resize(const ByteSize &new_size)
void reserve(const ByteSize &new_cap)
void push_back(std::byte value)
ByteSize size() const noexcept
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
Buffer module of the StormByte suite.
Position
Forward declaration of the WriteOnly interface.
Definition typedefs.hxx:74
Root namespace of the StormByte C++ suite.
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:54