aboutsummaryrefslogtreecommitdiff
path: root/src/base/platform
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-09-08 01:46:00 +0800
committerYuqian Yang <crupest@crupest.life>2025-09-08 21:34:37 +0800
commit593b658eb1491d4b3103971aba6592aff2765f0e (patch)
tree526bc88c6a895c215015926c90ff38c106a94604 /src/base/platform
parentdf550874cd546a85074edc35bebeb3cd0530622b (diff)
downloadcru-593b658eb1491d4b3103971aba6592aff2765f0e.tar.gz
cru-593b658eb1491d4b3103971aba6592aff2765f0e.tar.bz2
cru-593b658eb1491d4b3103971aba6592aff2765f0e.zip
Fix some compile errors on Windows.
Diffstat (limited to 'src/base/platform')
-rw-r--r--src/base/platform/win/DebugLogTarget.cpp6
-rw-r--r--src/base/platform/win/Exception.cpp6
-rw-r--r--src/base/platform/win/Win32FileStream.cpp37
3 files changed, 16 insertions, 33 deletions
diff --git a/src/base/platform/win/DebugLogTarget.cpp b/src/base/platform/win/DebugLogTarget.cpp
index 89bd3d19..afbab620 100644
--- a/src/base/platform/win/DebugLogTarget.cpp
+++ b/src/base/platform/win/DebugLogTarget.cpp
@@ -1,10 +1,12 @@
#include "cru/base/platform/win/DebugLogTarget.h"
+#include "cru/base/String.h"
+
namespace cru::platform::win {
-void WinDebugLogTarget::Write(::cru::log::LogLevel level, StringView s) {
+void WinDebugLogTarget::Write(::cru::log::LogLevel level, std::string s) {
CRU_UNUSED(level)
- String m = s.ToString();
+ String m = String::FromUtf8(s);
::OutputDebugStringW(reinterpret_cast<const wchar_t*>(m.c_str()));
}
} // namespace cru::platform::win
diff --git a/src/base/platform/win/Exception.cpp b/src/base/platform/win/Exception.cpp
index 5ff6146b..941875f7 100644
--- a/src/base/platform/win/Exception.cpp
+++ b/src/base/platform/win/Exception.cpp
@@ -14,12 +14,12 @@ inline String HResultMakeMessage(HRESULT h_result,
}
HResultError::HResultError(HRESULT h_result)
- : PlatformException(HResultMakeMessage(h_result, std::nullopt)),
+ : Exception(HResultMakeMessage(h_result, std::nullopt)),
h_result_(h_result) {}
HResultError::HResultError(HRESULT h_result,
std::string_view additional_message)
- : PlatformException(HResultMakeMessage(
+ : Exception(HResultMakeMessage(
h_result, String::FromUtf8(additional_message.data(),
additional_message.size()))),
h_result_(h_result) {}
@@ -33,6 +33,6 @@ Win32Error::Win32Error(String message)
: Win32Error(::GetLastError(), message) {}
Win32Error::Win32Error(DWORD error_code, String message)
- : PlatformException(Win32MakeMessage(error_code, message)),
+ : Exception(Win32MakeMessage(error_code, message)),
error_code_(error_code) {}
} // namespace cru::platform::win
diff --git a/src/base/platform/win/Win32FileStream.cpp b/src/base/platform/win/Win32FileStream.cpp
index 54e6ae45..f3809b3e 100644
--- a/src/base/platform/win/Win32FileStream.cpp
+++ b/src/base/platform/win/Win32FileStream.cpp
@@ -14,7 +14,8 @@ namespace cru::platform::win {
using namespace cru::io;
Win32FileStream::Win32FileStream(String path, OpenFileFlag flags)
- : path_(std::move(path)),
+ : Stream(true, true, true),
+ path_(std::move(path)),
flags_(flags),
p_(new details::Win32FileStreamPrivate()) {
DWORD grfMode = STGM_SHARE_DENY_NONE;
@@ -46,15 +47,11 @@ Win32FileStream::Win32FileStream(String path, OpenFileFlag flags)
}
Win32FileStream::~Win32FileStream() {
- Close();
+ DoClose();
delete p_;
}
-bool Win32FileStream::CanSeek() { return true; }
-
-Index Win32FileStream::Seek(Index offset, SeekOrigin origin) {
- CheckClosed();
-
+Index Win32FileStream::DoSeek(Index offset, SeekOrigin origin) {
DWORD dwOrigin = 0;
if (origin == SeekOrigin::Current) {
@@ -74,23 +71,13 @@ Index Win32FileStream::Seek(Index offset, SeekOrigin origin) {
return n_new_offset.QuadPart;
}
-bool Win32FileStream::CanRead() { return true; }
-
-Index Win32FileStream::Read(std::byte* buffer, Index offset, Index size) {
- if (size < 0) {
- throw Exception(u"Size must be greater than 0.");
- }
-
- CheckClosed();
-
+Index Win32FileStream::DoRead(std::byte* buffer, Index offset, Index size) {
ULONG n_read;
ThrowIfFailed(p_->stream_->Read(buffer + offset, size, &n_read));
return n_read;
}
-bool Win32FileStream::CanWrite() { return true; }
-
-Index Win32FileStream::Write(const std::byte* buffer, Index offset,
+Index Win32FileStream::DoWrite(const std::byte* buffer, Index offset,
Index size) {
if (size < 0) {
throw Exception(u"Size must be greater than 0.");
@@ -104,19 +91,13 @@ Index Win32FileStream::Write(const std::byte* buffer, Index offset,
return n_written;
}
-void Win32FileStream::Close() {
- if (closed_) return;
+void Win32FileStream::DoClose() {
+ CRU_STREAM_BEGIN_CLOSE
- if (p_->stream_) {
+ if (p_->stream_) {
p_->stream_->Release();
p_->stream_ = nullptr;
}
- closed_ = true;
}
-
-void Win32FileStream::CheckClosed() {
- if (closed_) throw Exception(u"Stream is closed.");
-}
-
} // namespace cru::platform::win