152 template<
Type::ByteInputRange Src>
155 if constexpr (
requires { std::ranges::size(src); }) {
156 auto s = std::ranges::size(src);
160 std::transform(std::ranges::begin(src), std::ranges::end(src), std::back_inserter(out),
161 [](
auto&& e)
noexcept {
return static_cast<std::byte
>(e); });
171 template<Type::ByteInputRange Src>
174 return std::move(src);
177 if constexpr (
requires { std::ranges::size(src); }) {
178 auto s = std::ranges::size(src);
182 std::transform(std::ranges::begin(src), std::ranges::end(src), std::back_inserter(out),
183 [](
auto&& e)
noexcept {
return static_cast<std::byte
>(e); });
197 std::transform(sv.begin(), sv.end(), std::back_inserter(out),
198 [](
char c)
noexcept { return static_cast<std::byte>(c); });
210 return DataConvert(std::string_view(s));
297 virtual
bool Empty() const noexcept = 0;
303 virtual
bool EoF() const noexcept = 0;
309 virtual
bool IsReadable() const noexcept = 0;
324 virtual
void Clean() noexcept = 0;
331 virtual
void Clear() noexcept = 0;
348 virtual
void Seek(const
std::ptrdiff_t& offset, const
Position& mode) const noexcept = 0;
561 virtual
bool IsWritable() const noexcept = 0;
566 virtual
void Close() noexcept = 0;
571 virtual
void SetError() noexcept = 0;
633 return Write(data.Available(), data);
642 return Write(data.Available(), std::move(data));
659 bool Write(std::string_view sv)
noexcept {
663 std::transform(sv.begin(), sv.end(), std::back_inserter(tmp),
664 [](
char e)
noexcept { return static_cast<std::byte>(e); });
665 return Write(tmp.
size(), std::move(tmp));
673 bool Write(
const char* s)
noexcept {
676 return Write(std::string_view(s));
692 std::transform(sv.begin(), sv.begin() +
static_cast<std::ptrdiff_t
>(
static_cast<std::size_t
>(to_write)),
693 std::back_inserter(tmp),
694 [](
char e)
noexcept { return static_cast<std::byte>(e); });
695 return Write(to_write, std::move(tmp));
707 return Write(count, std::string_view(s));
716 template<std::
size_t N>
717 bool Write(
const char (&s)[N])
noexcept {
720 return Write(std::string_view(s, (N > 0) ? (N - 1) : 0));
738 template<Type::ByteInputRange R>
741 if constexpr (
requires { std::ranges::size(r); }) {
742 auto dist = std::ranges::size(r);
746 std::transform(std::ranges::begin(r), std::ranges::end(r), std::back_inserter(tmp),
747 [](
auto&& e)
noexcept {
return static_cast<std::byte
>(e); });
748 return Write(tmp.
size(), std::move(tmp));
758 template<Type::ByteInputRange Rw>
764 auto it = std::ranges::begin(r);
765 auto end = std::ranges::end(r);
768 tmp.
push_back(
static_cast<std::byte
>(*it));
769 return Write(written, std::move(tmp));
779 template<Type::ByteInputRange Rrw>
782 return Write(std::forward<Rrw>(r));
785 if (tmp.
size() > count)
787 return Write(tmp.
size(), std::move(tmp));
791 auto it = std::ranges::begin(r);
792 auto end = std::ranges::end(r);
795 tmp.
push_back(
static_cast<std::byte
>(*it));
796 return Write(written, std::move(tmp));
806 template<Type::ByteInputRange Rr>
809 return Write(r.size(), std::move(r));
812 if constexpr (
requires { std::ranges::size(r); }) {
813 auto dist = std::ranges::size(r);
817 std::transform(std::ranges::begin(r), std::ranges::end(r), std::back_inserter(tmp),
818 [](
auto&& e)
noexcept {
return static_cast<std::byte
>(e); });
819 return Write(tmp.
size(), std::move(tmp));
831 template<Type::ByteInputIterator I,
typename S>
833 bool Write(I first, S last)
noexcept {
835 std::transform(first, last, std::back_inserter(tmp),
836 [](
auto&& e)
noexcept {
return static_cast<std::byte
>(e); });
837 return Write(tmp.
size(), std::move(tmp));
849 template<Type::ByteInputIterator I2,
typename S2>
853 return Write(first, last);
856 for (; first != last && written < count; ++first, written = written +
StormByte::ByteSize{1})
857 tmp.
push_back(
static_cast<std::byte
>(*first));
858 return Write(written, std::move(tmp));
void reserve(const StormByte::ByteSize &new_cap)
void resize(const StormByte::ByteSize &new_size)
void push_back(std::byte value)
StormByte::ByteSize size() const noexcept
Abstract root of the byte-buffer interfaces.
Definition generic.hxx:78
static BinaryData DataConvert(const char *s) noexcept
Convert a C string to StormByte::BinaryData.
Definition generic.hxx:207
static BinaryData DataConvert(Src &&src) noexcept
Convert an rvalue input range to StormByte::BinaryData.
Definition generic.hxx:172
Generic() noexcept=default
Default constructor.
static BinaryData DataConvert(std::string_view sv) noexcept
Convert a string view to StormByte::BinaryData.
Definition generic.hxx:193
Buffer that can be read and not written.
Definition generic.hxx:228
virtual void ExtractUntilEoF(WriteOnly &outBuffer) noexcept=0
Extract until EoF into a WriteOnly.
ReadOnly(ReadOnly &&other) noexcept=default
Move constructor.
virtual void ReadUntilEoF(StormByte::BinaryData &outBuffer) const noexcept=0
Read until EoF into a StormByte::BinaryData.
virtual bool Extract(const StormByte::ByteSize &count, WriteOnly &outBuffer) noexcept=0
Extract bytes into a WriteOnly.
virtual bool Peek(const StormByte::ByteSize &count, WriteOnly &outBuffer) const noexcept=0
Peek into a WriteOnly.
bool Read(WriteOnly &outBuffer) const noexcept
Read all available bytes into a WriteOnly.
Definition generic.hxx:474
ReadOnly(const ReadOnly &other) noexcept=default
Copy constructor.
virtual bool Peek(const StormByte::ByteSize &count, StormByte::BinaryData &outBuffer) const noexcept=0
Peek into a StormByte::BinaryData.
virtual bool Read(const StormByte::ByteSize &count, WriteOnly &outBuffer) const noexcept=0
Read into a WriteOnly.
ReadOnly() noexcept
Default constructor.
Definition generic.hxx:238
bool Read(StormByte::BinaryData &outBuffer) const noexcept
Read all available bytes into a StormByte::BinaryData.
Definition generic.hxx:457
bool Extract(WriteOnly &outBuffer) noexcept
Extract all available bytes into a WriteOnly.
Definition generic.hxx:389
virtual void ExtractUntilEoF(StormByte::BinaryData &outBuffer) noexcept=0
Extract until EoF into a StormByte::BinaryData.
virtual ~ReadOnly() noexcept
Destructor.
virtual bool Read(const StormByte::ByteSize &count, StormByte::BinaryData &outBuffer) const noexcept=0
Read into a StormByte::BinaryData.
virtual void ReadUntilEoF(WriteOnly &outBuffer) const noexcept=0
Read until EoF into a WriteOnly.
Read and write interface.
Definition generic.hxx:872
ReadWrite() noexcept
Default constructor.
Definition generic.hxx:882
ReadWrite(const ReadWrite &other) noexcept=default
Copy constructor.
ReadWrite(ReadWrite &&other) noexcept=default
Move constructor.
virtual ~ReadWrite() noexcept
Destructor.
Buffer that can be written and not read.
Definition generic.hxx:505
bool Write(const char *s) noexcept
Write a C string.
Definition generic.hxx:673
WriteOnly(const WriteOnly &other)=default
Copy constructor.
virtual ~WriteOnly() noexcept
Destructor.
bool Write(const char(&s)[N]) noexcept
Write a string literal without the trailing NUL.
Definition generic.hxx:717
bool Write(ReadOnly &&data) noexcept
Append all available bytes from a ReadOnly (extract).
Definition generic.hxx:641
bool Write(Rr &&r) noexcept
Write all elements from an rvalue range.
Definition generic.hxx:807
bool Write(const StormByte::ByteSize &count, const Rw &r) noexcept
Write up to count elements from an input range.
Definition generic.hxx:759
bool Write(const StormByte::ByteSize &count, std::string_view sv) noexcept
Write up to count characters of a string view.
Definition generic.hxx:685
WriteOnly() noexcept
Default constructor.
Definition generic.hxx:515
bool Write(const StormByte::ByteSize &count, Rrw &&r) noexcept
Write up to count elements from an rvalue range.
Definition generic.hxx:780
WriteOnly(WriteOnly &&other) noexcept=default
Move constructor.
bool Write(const StormByte::ByteSize &count, const char *s) noexcept
Write up to count characters of a C string.
Definition generic.hxx:704
bool Write(std::string_view sv) noexcept
Write a string view.
Definition generic.hxx:659
bool Write(const StormByte::ByteSize &count, I2 first, S2 last) noexcept
Write up to count elements from an iterator pair.
Definition generic.hxx:851
bool Write(const R &r) noexcept
Write all elements from an input range.
Definition generic.hxx:739
bool Write(I first, S last) noexcept
Write all elements from an iterator pair.
Definition generic.hxx:833
Position
Forward declaration of the WriteOnly interface.
Definition typedefs.hxx:73
Root namespace of the StormByte C++ suite.
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:54