diff options
author | crupest <crupest@outlook.com> | 2024-10-06 13:57:39 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2024-10-06 13:57:39 +0800 |
commit | dfe62dcf8bcefc523b466e127c3edc4dc2756629 (patch) | |
tree | 1c751a14ba0da07ca2ff805633f97568060aa4c9 /src/base/io/ProxyStream.cpp | |
parent | f51eb955e188858272230a990565931e7403f23b (diff) | |
download | cru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.tar.gz cru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.tar.bz2 cru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.zip |
Rename common to base.
Diffstat (limited to 'src/base/io/ProxyStream.cpp')
-rw-r--r-- | src/base/io/ProxyStream.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/base/io/ProxyStream.cpp b/src/base/io/ProxyStream.cpp new file mode 100644 index 00000000..de66169e --- /dev/null +++ b/src/base/io/ProxyStream.cpp @@ -0,0 +1,37 @@ +#include "cru/base/io/ProxyStream.h" +#include "cru/base/io/Stream.h" + +namespace cru::io { +ProxyStream::ProxyStream(ProxyStreamHandlers handlers) + : Stream(static_cast<bool>(handlers.seek), static_cast<bool>(handlers.read), + static_cast<bool>(handlers.write)), + handlers_(std::move(handlers)) {} + +ProxyStream::~ProxyStream() { DoClose(); } + +Index ProxyStream::DoSeek(Index offset, SeekOrigin origin) { + return handlers_.seek(offset, origin); +} + +Index ProxyStream::DoRead(std::byte* buffer, Index offset, Index size) { + return handlers_.read(buffer, offset, size); +} + +Index ProxyStream::DoWrite(const std::byte* buffer, Index offset, Index size) { + return handlers_.write(buffer, offset, size); +} + +void ProxyStream::DoFlush() { + if (handlers_.flush) { + handlers_.flush(); + } +} + +void ProxyStream::DoClose() { + CRU_STREAM_BEGIN_CLOSE + if (handlers_.close) { + handlers_.close(); + } + handlers_ = {}; +} +} // namespace cru::io |