psemek/libs/io/source/memory_stream.cpp
lisyarus 664b1d613e
All checks were successful
Run tests / Run tests (push) Successful in 7m34s
Add io::expanding_memory_ostream that writes to std::vector<char>
2026-07-06 22:41:38 +03:00

32 lines
701 B
C++

#include <psemek/io/memory_stream.hpp>
#include <algorithm>
namespace psemek::io
{
std::size_t memory_istream::read(char * p, std::size_t size)
{
if (!begin_) throw null_istream{};
size = std::min<std::size_t>(size, end_ - begin_);
std::copy(begin_, begin_ + size, p);
begin_ += size;
return size;
}
std::size_t memory_ostream::write(char const * p, std::size_t size)
{
if (!begin_) throw null_ostream{};
size = std::min<std::size_t>(size, end_ - begin_);
std::copy(p, p + size, begin_);
begin_ += size;
return size;
}
std::size_t expanding_memory_ostream::write(char const * p, std::size_t size)
{
buffer_->insert(buffer_->end(), p, p + size);
return size;
}
}