aboutsummaryrefslogtreecommitdiff
path: root/include/cru/base/platform/win/Stream.h
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-11-15 16:43:25 +0800
committerYuqian Yang <crupest@crupest.life>2025-11-16 00:01:49 +0800
commit246eb9266b9349b44cbe96f3f839124ab30cbb89 (patch)
tree31604c8a4764d3a601d56599e56c98d91bd97758 /include/cru/base/platform/win/Stream.h
parentb92aa78ac19476049ab881b49c51b1a970a4a973 (diff)
downloadcru-246eb9266b9349b44cbe96f3f839124ab30cbb89.tar.gz
cru-246eb9266b9349b44cbe96f3f839124ab30cbb89.tar.bz2
cru-246eb9266b9349b44cbe96f3f839124ab30cbb89.zip
Impl win subprocess.
Diffstat (limited to 'include/cru/base/platform/win/Stream.h')
-rw-r--r--include/cru/base/platform/win/Stream.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/include/cru/base/platform/win/Stream.h b/include/cru/base/platform/win/Stream.h
new file mode 100644
index 00000000..e49bf48b
--- /dev/null
+++ b/include/cru/base/platform/win/Stream.h
@@ -0,0 +1,66 @@
+#pragma once
+
+#ifndef _WIN32
+#error "This file can only be included on Windows."
+#endif
+
+#include "../../io/Base.h"
+#include "../../io/Stream.h"
+#include "Base.h"
+
+#include <objidlbase.h>
+
+namespace cru::platform::win {
+class CRU_BASE_API Win32HandleStream : public io::Stream {
+ public:
+ Win32HandleStream(std::string_view path, io::OpenFileFlag flags);
+ Win32HandleStream(HANDLE handle, bool auto_close, bool can_seek,
+ bool can_read, bool can_write);
+ Win32HandleStream(Win32Handle&& handle, bool can_seek, bool can_read,
+ bool can_write);
+ ~Win32HandleStream() override;
+
+ 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;
+
+ public:
+ const Win32Handle& GetHandle() { return handle_; }
+
+ CRU_STREAM_IMPLEMENT_CLOSE_BY_DO_CLOSE
+
+ private:
+ void DoClose();
+
+ private:
+ Win32Handle handle_;
+};
+
+CRU_BASE_API IStream* ToComStream(io::Stream* stream);
+
+class CRU_BASE_API ComStream : public io::Stream {
+ public:
+ ComStream(std::string_view path, io::OpenFileFlag flags);
+ ComStream(IStream* com_stream, bool auto_release, bool can_seek,
+ bool can_read, bool can_write);
+ ~ComStream() override;
+
+ 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;
+
+ public:
+ IStream* GetComStream() { return stream_; }
+
+ CRU_STREAM_IMPLEMENT_CLOSE_BY_DO_CLOSE
+
+ private:
+ void DoClose();
+
+ private:
+ IStream* stream_;
+ bool auto_release_;
+};
+} // namespace cru::platform::win