#pragma once #include "Stream.h" #include namespace cru::io { struct ProxyStreamHandlers { std::function seek; std::function read; std::function write; std::function flush; /** * @brief This method will be only called once when `Close` is called or the * stream is destructed. */ std::function close; }; class ProxyStream : public Stream { public: explicit ProxyStream(ProxyStreamHandlers handlers); ~ProxyStream() override; public: CRU_STREAM_IMPLEMENT_CLOSE_BY_DO_CLOSE protected: Index DoSeek(Index offset, SeekOrigin origin) override; Index DoRead(std::byte* buffer, Index offset, Index size) override; Index DoWrite(const std::byte* buffer, Index offset, Index size) override; void DoFlush() override; private: void DoClose(); private: ProxyStreamHandlers handlers_; }; } // namespace cru::io