aboutsummaryrefslogtreecommitdiff
path: root/src/common/io/BufferStream.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-02-12 15:47:31 +0800
committercrupest <crupest@outlook.com>2024-03-24 20:03:58 +0800
commit944ea0e5b613d901ba834dc225eb9d379b750bd3 (patch)
tree9cdeae736bc635481b4cd3d6024d1d5d0c5072df /src/common/io/BufferStream.cpp
parentb2051e28cd36c49b7c5d49b511646a3856d7eaf0 (diff)
downloadcru-944ea0e5b613d901ba834dc225eb9d379b750bd3.tar.gz
cru-944ea0e5b613d901ba834dc225eb9d379b750bd3.tar.bz2
cru-944ea0e5b613d901ba834dc225eb9d379b750bd3.zip
WORKING: make Buffer track two sides.
Diffstat (limited to 'src/common/io/BufferStream.cpp')
-rw-r--r--src/common/io/BufferStream.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/common/io/BufferStream.cpp b/src/common/io/BufferStream.cpp
new file mode 100644
index 00000000..d4780f7a
--- /dev/null
+++ b/src/common/io/BufferStream.cpp
@@ -0,0 +1,45 @@
+#include "cru/common/io/BufferStream.h"
+#include <memory>
+#include "cru/common/io/Stream.h"
+
+namespace cru::io {
+BufferStream::BufferStream(const BufferStreamOptions& options) {
+ block_size_ =
+ options.block_size <= 0 ? kDefaultBlockSize : options.block_size;
+ total_size_limit_ = options.total_size_limit < 0 ? kDefaultTotalSizeLimit
+ : options.total_size_limit;
+ block_count_limit_ = total_size_limit_ / block_size_;
+
+ eof_ = false;
+}
+
+bool BufferStream::CanSeek() {
+ CheckClosed();
+ return false;
+}
+
+Index BufferStream::Seek(Index offset, SeekOrigin origin) {
+ CheckClosed();
+ throw StreamOperationNotSupportedException(
+ u"BufferStream does not support seeking.");
+}
+
+bool BufferStream::CanRead() {
+ CheckClosed();
+ return true; }
+
+Index BufferStream::Read(std::byte* buffer, Index offset, Index size) {
+ std::unique_lock lock(mutex_);
+
+ Index written_size = 0;
+
+ if (eof_ && buffer_list_.empty()) {
+ return 0;
+ }
+
+ while (!buffer_list_.empty()) {
+
+ }
+}
+
+} // namespace cru::io