StreamUtils.h 521 B

12345678910111213141516171819
  1. #pragma once
  2. #include <cstddef>
  3. #include <istream>
  4. #include <streambuf>
  5. namespace bell {
  6. struct MemoryBuffer : std::streambuf {
  7. MemoryBuffer(std::byte const* base, size_t size) {
  8. std::byte* p(const_cast<std::byte*>(base));
  9. this->setg((char*)p, (char*)p, (char*)p + size);
  10. }
  11. };
  12. struct IMemoryStream : virtual MemoryBuffer, std::istream {
  13. IMemoryStream(std::byte const* base, size_t size)
  14. : MemoryBuffer(base, size),
  15. std::istream(static_cast<std::streambuf*>(this)) {}
  16. };
  17. } // namespace bell