Go to the documentation of this file.
9 #ifndef EAGINE_SERIALIZE_ISTREAM_SOURCE_HPP
10 #define EAGINE_SERIALIZE_ISTREAM_SOURCE_HPP
12 #include "../assert.hpp"
13 #include "../memory/buffer.hpp"
14 #include "../memory/span_algo.hpp"
30 if(_cur_size < req_size) {
31 while(_storage.
size() < _cur_size + req_size) {
32 _storage.
resize(_storage.
size() + _chunk_size());
36 head(
skip(
cover(_storage), _cur_size), req_size - _cur_size));
43 if(_cur_size <= del_size) {
45 if(_storage.
size() > _chunk_size()) {
46 _storage.
resize(_chunk_size());
49 auto sw =
head(
cover(_storage), _cur_size);
51 _cur_size -= del_size;
53 EAGINE_ASSERT(_cur_size >= 0);
57 static constexpr
auto _chunk_size() noexcept ->
span_size_t {
63 memory::buffer _storage{};
68 #endif // EAGINE_SERIALIZE_ISTREAM_SOURCE_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
istream_data_source(std::istream &in) noexcept
Constructor setting the source stream.
Definition: istream_source.hpp:26
static constexpr auto span_size(T v) noexcept
Converts argument to span size type.
Definition: types.hpp:59
Common code is placed in this namespace.
Definition: eagine.hpp:21
static constexpr auto cover(T *addr, S size) noexcept -> span_if_mutable< T >
Creates a span starting at the specified pointer and specified length.
Definition: span.hpp:465
static constexpr auto view(T *addr, S size) noexcept -> const_span< T >
Creates a view starting at the specified pointer and specified length.
Definition: span.hpp:458
static constexpr auto head(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Returns the first l elements from the front of a span.
Definition: span_algo.hpp:99
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
static constexpr auto skip(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Skips a specified count of elements from the front of a span.
Definition: span_algo.hpp:60
Abstract base class for deserialization data sources.
Definition: data_source.hpp:25
void pop(span_size_t del_size) final
Returns the specified amount of data of the top of the source.
Definition: istream_source.hpp:42
auto top(span_size_t req_size) -> memory::const_block final
Returns a block covering the specified amount of data of the top.
Definition: istream_source.hpp:29
auto size() const noexcept -> span_size_t
Returns the size of the buffer in bytes.
Definition: buffer.hpp:81
auto resize(span_size_t new_size) -> auto &
Resizes the buffer to the specified number of bytes.
Definition: buffer.hpp:114
static auto copy(const_block source, block dest) -> block
Copies the content of source block to destination block.
Definition: copy.hpp:23
Deserialization data source backed by an input stream.
Definition: istream_source.hpp:23