aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-12-25 22:27:41 +0800
committercrupest <crupest@outlook.com>2023-12-25 22:27:41 +0800
commite372810d67ae21dbc60aad71696290dad1c5e34a (patch)
treee215a10e05810659f3740d528ab4b5eba6b2300e /src/common
parent29bef137f5c33a599f2629fecc0b756611dd126b (diff)
downloadcru-e372810d67ae21dbc60aad71696290dad1c5e34a.tar.gz
cru-e372810d67ae21dbc60aad71696290dad1c5e34a.tar.bz2
cru-e372810d67ae21dbc60aad71696290dad1c5e34a.zip
Develop ProxyStream.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/io/ProxyStream.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/common/io/ProxyStream.cpp b/src/common/io/ProxyStream.cpp
index 9fd6be76..df8e7dcc 100644
--- a/src/common/io/ProxyStream.cpp
+++ b/src/common/io/ProxyStream.cpp
@@ -7,6 +7,52 @@ ProxyStream::ProxyStream(ProxyStreamHandlers handlers)
ProxyStream::~ProxyStream() { DoClose(); }
+bool ProxyStream::CanSeek() {
+ CheckClosed();
+ return static_cast<bool>(handlers_.seek);
+}
+
+Index ProxyStream::Seek(Index offset, SeekOrigin origin) {
+ CheckClosed();
+ StreamOperationNotSupportedException::CheckSeek(CanSeek());
+ return handlers_.seek(offset, origin);
+}
+
+bool ProxyStream::CanRead() {
+ CheckClosed();
+ return static_cast<bool>(handlers_.read);
+}
+
+Index ProxyStream::Read(std::byte* buffer, Index offset, Index size) {
+ CheckClosed();
+ StreamOperationNotSupportedException::CheckRead(CanRead());
+ return handlers_.read(buffer, offset, size);
+}
+
+bool ProxyStream::CanWrite() {
+ CheckClosed();
+ return static_cast<bool>(handlers_.write);
+}
+
+Index ProxyStream::Write(const std::byte* buffer, Index offset, Index size) {
+ CheckClosed();
+ StreamOperationNotSupportedException::CheckWrite(CanWrite());
+ return handlers_.write(buffer, offset, size);
+}
+
+void ProxyStream::Flush() {
+ CheckClosed();
+ if (handlers_.flush) {
+ handlers_.flush();
+ }
+}
+
+void ProxyStream::Close() { DoClose(); }
+
+void ProxyStream::CheckClosed() {
+ StreamAlreadyClosedException::Check(closed_);
+}
+
void ProxyStream::DoClose() {
if (!closed_) {
if (handlers_.close) {