aboutsummaryrefslogtreecommitdiff
path: root/include/cru/base/platform
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/base/platform')
-rw-r--r--include/cru/base/platform/win/DebugLogTarget.h15
-rw-r--r--include/cru/base/platform/win/Exception.h23
-rw-r--r--include/cru/base/platform/win/Win32FileStream.h27
3 files changed, 18 insertions, 47 deletions
diff --git a/include/cru/base/platform/win/DebugLogTarget.h b/include/cru/base/platform/win/DebugLogTarget.h
index 5f000d94..cabfa7e5 100644
--- a/include/cru/base/platform/win/DebugLogTarget.h
+++ b/include/cru/base/platform/win/DebugLogTarget.h
@@ -1,6 +1,8 @@
#pragma once
-#ifdef CRU_PLATFORM_WINDOWS
+#ifndef _WIN32
+#error "This file can only be used on Windows."
+#endif
#include "WinPreConfig.h"
@@ -10,15 +12,6 @@ namespace cru::platform::win {
class CRU_BASE_API WinDebugLogTarget : public ::cru::log::ILogTarget {
public:
- WinDebugLogTarget() = default;
-
- CRU_DELETE_COPY(WinDebugLogTarget)
- CRU_DELETE_MOVE(WinDebugLogTarget)
-
- ~WinDebugLogTarget() = default;
-
- void Write(::cru::log::LogLevel level, StringView s) override;
+ void Write(::cru::log::LogLevel level, std::string s) override;
};
} // namespace cru::platform::win
-
-#endif
diff --git a/include/cru/base/platform/win/Exception.h b/include/cru/base/platform/win/Exception.h
index 04bdd32c..12f3d108 100644
--- a/include/cru/base/platform/win/Exception.h
+++ b/include/cru/base/platform/win/Exception.h
@@ -1,25 +1,21 @@
#pragma once
-#ifndef CRU_PLATFORM_WINDOWS
+
+#ifndef _WIN32
#error "This file can only be used on Windows."
#endif
#include "WinPreConfig.h"
-#include "../Exception.h"
+#include "../../Exception.h"
#include <stdexcept>
#include <string_view>
namespace cru::platform::win {
-class CRU_BASE_API HResultError : public platform::PlatformException {
+class CRU_BASE_API HResultError : public Exception {
public:
explicit HResultError(HRESULT h_result);
- explicit HResultError(HRESULT h_result, std::string_view message);
-
- CRU_DEFAULT_COPY(HResultError)
- CRU_DEFAULT_MOVE(HResultError)
-
- ~HResultError() override = default;
+ HResultError(HRESULT h_result, std::string_view message);
HRESULT GetHResult() const { return h_result_; }
@@ -35,23 +31,16 @@ inline void ThrowIfFailed(const HRESULT h_result, std::string_view message) {
if (FAILED(h_result)) throw HResultError(h_result, message);
}
-class CRU_BASE_API Win32Error : public platform::PlatformException {
+class CRU_BASE_API Win32Error : public Exception {
public:
// ::GetLastError is automatically called to get the error code.
// The same as Win32Error(::GetLastError(), message)
explicit Win32Error(String message);
Win32Error(DWORD error_code, String message);
- CRU_DEFAULT_COPY(Win32Error)
- CRU_DEFAULT_MOVE(Win32Error)
-
- ~Win32Error() override = default;
-
DWORD GetErrorCode() const { return error_code_; }
private:
DWORD error_code_;
};
} // namespace cru::platform::win
-
-#endif
diff --git a/include/cru/base/platform/win/Win32FileStream.h b/include/cru/base/platform/win/Win32FileStream.h
index 961076de..61f1a33d 100644
--- a/include/cru/base/platform/win/Win32FileStream.h
+++ b/include/cru/base/platform/win/Win32FileStream.h
@@ -14,38 +14,27 @@ class Win32FileStreamPrivate;
class CRU_BASE_API Win32FileStream : public io::Stream {
public:
Win32FileStream(String path, io::OpenFileFlag flags);
-
- CRU_DELETE_COPY(Win32FileStream)
- CRU_DELETE_MOVE(Win32FileStream)
-
~Win32FileStream() override;
- public:
- bool CanSeek() override;
- Index Seek(Index offset, SeekOrigin origin = SeekOrigin::Current) override;
-
- bool CanRead() override;
- Index Read(std::byte* buffer, Index offset, Index size) override;
- using Stream::Read;
-
- bool CanWrite() override;
- Index Write(const std::byte* buffer, Index offset, Index size) override;
- using Stream::Write;
-
- void Close() 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:
String GetPath() const { return path_; }
io::OpenFileFlag GetOpenFileFlags() const { return flags_; }
details::Win32FileStreamPrivate* GetPrivate_() { return p_; }
+ CRU_STREAM_IMPLEMENT_CLOSE_BY_DO_CLOSE
+
private:
- void CheckClosed();
+ void DoClose();
private:
String path_;
io::OpenFileFlag flags_;
- bool closed_ = false;
details::Win32FileStreamPrivate* p_;
};