30#include "binary_stream.hpp"
44 stream.
read(
reinterpret_cast<char *
>(&size),
sizeof(size));
47 std::vector<char> buffer(size);
48 stream.
read(buffer.data(), size);
49 data.assign(buffer.data(), size);
66 std::size_t size = data.size();
67 stream.
write(
reinterpret_cast<const char *
>(&size),
sizeof(size));
70 stream.
write(data.c_str(), size);
89 : m_size(0), m_pos(0), m_chunkSize(1)
117 open(buffer, capacity);
130 open(buffer.data(), buffer.size());
144 m_buffer.assign(buffer, buffer + size);
193 return m_buffer.data();
203 return m_buffer.data();
225 if ((way == std::ios_base::beg) && (offset < (
long)
getSize())) {
227 }
else if ((way == std::ios_base::cur) && (m_pos + offset <
getSize())) {
229 }
else if ((way == std::ios_base::end) && ((
long)
getSize() - offset >= 0)) {
275 std::size_t nChunks = capacity;
276 while (nChunks > (std::size_t) std::numeric_limits<int>::max()) {
277 m_chunkSize = 2 * m_chunkSize;
278 nChunks = (1 + ((capacity - 1) / m_chunkSize));
281 m_buffer.resize(nChunks * m_chunkSize);
334 return m_buffer.size();
424 if ((m_pos + size) >
getSize()) {
425 throw std::runtime_error(
"Bad memory access!");
428 std::memcpy(
data, m_buffer.data() + m_pos, size);
481 m_expandable = (size == 0);
494 throw std::runtime_error(
"Stream is not expandable.");
506 bool expandableFlag = m_expandable;
515 m_expandable = expandableFlag;
527 if (
getSize() - m_pos < size) {
530 std::size_t bufferSize =
getSize() + size;
534 std::memcpy(m_buffer.data() + m_pos,
data, size);
Base class for defining input and output binary streams.
std::streampos tellg() const
std::size_t getCapacity() const
void open(const char *buffer, std::size_t capacity)
bool seekg(std::size_t pos)
void setCapacity(std::size_t capacity)
virtual void setSize(std::size_t size)
std::size_t getSize() const
void read(char *data, std::size_t size)
void open(const char *buffer, std::size_t size)
void write(const char *data, std::size_t size)
void open(std::size_t size)
void setSize(std::size_t size) override
Logger & operator<<(Logger &logger, LoggerManipulator< T > &&m)