binary_io::any_istream class final

A polymorphic stream which can be used to abstract other streams.

Base classes

template<class StreamBase, template<class> class StreamErased>
class any_stream_base<detail::erased_istream_base, detail::erased_istream>
Implements the common interface of every any_stream.
template<class Derived>
class istream_interface<binary_io::any_istream>
A CRTP utility which can be used to flesh out the interface of a given stream.

Buffering

void flush() noexcept
Flushes the underlying stream's buffers, if applicable.

Formatting

auto endian() const -> std::endian noexcept
Gets the current default endian format.
void endian(std::endian a_endian) noexcept
Sets the default endian format.

Modifiers

void emplace(Args && ... a_args)
Constructs the given underlying stream in-place, using the given arguments.
void reset() noexcept
Destroys the underlying buffer, if there is any.

Observers

auto get() -> S&
Attempts to get the underlying stream as the given type.
auto get() const -> const S&
Attempts to get the underlying stream as the given type.
auto get_if() -> S* noexcept
Attempts to get the underlying stream as the given type.
auto get_if() const -> const S* noexcept
Attempts to get the underlying stream as the given type.
auto has_value() const -> bool noexcept
Checks if there is an active underlying buffer.

Position

void seek_absolute(binary_io::streamoff a_pos) noexcept
Seek to an absolute position in the stream (i.e. from the beginning).
void seek_relative(binary_io::streamoff a_off) noexcept
Seek to a position in the stream relative to the current position.
auto tell() const -> binary_io::streamoff noexcept
Gets the current stream position.

Reading

auto read() -> std::tuple<Args...>
Batch reads the given values from the input stream.
auto read(std::endian a_endian) -> std::tuple<Args...>
Batch reads the given values with the given endian format from the input stream.
void read(Args&... a_args)
Batch reads the given values from the input stream.
void read(std::endian a_endian, Args&... a_args)
Batch reads the given values with the given endian format from the input stream.
void read_bytes(std::span<std::byte> a_dst)
Reads bytes into the given buffer.

Function documentation

void binary_io::any_istream::read_bytes(std::span<std::byte> a_dst)

Reads bytes into the given buffer.

Parameters
a_dst The buffer to read bytes into.
Exceptions
binary_io::buffer_exhausted Thrown when the buffer has less than the requested number of bytes.