From 2ed65999ef6f3e1156427dd3efe04353ae657882 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 25 Jan 2022 17:30:46 +0800 Subject: ... --- include/cru/common/platform/Exception.hpp | 15 +++++++ include/cru/common/platform/osx/Convert.hpp | 17 +++++++ include/cru/common/platform/osx/Exception.hpp | 14 ++++++ include/cru/common/platform/win/Exception.hpp | 56 ++++++++++++++++++++++++ include/cru/common/platform/win/WinPreConfig.hpp | 21 +++++++++ 5 files changed, 123 insertions(+) create mode 100644 include/cru/common/platform/Exception.hpp create mode 100644 include/cru/common/platform/osx/Convert.hpp create mode 100644 include/cru/common/platform/osx/Exception.hpp create mode 100644 include/cru/common/platform/win/Exception.hpp create mode 100644 include/cru/common/platform/win/WinPreConfig.hpp (limited to 'include/cru/common/platform') diff --git a/include/cru/common/platform/Exception.hpp b/include/cru/common/platform/Exception.hpp new file mode 100644 index 00000000..0241947b --- /dev/null +++ b/include/cru/common/platform/Exception.hpp @@ -0,0 +1,15 @@ +#pragma once +#include "../Base.hpp" +#include "../Exception.hpp" + +namespace cru::platform { +class CRU_BASE_API PlatformException : public Exception { + public: + using Exception::Exception; // inherit constructors + + CRU_DEFAULT_COPY(PlatformException) + CRU_DEFAULT_MOVE(PlatformException) + + CRU_DEFAULT_DESTRUCTOR(PlatformException) +}; +} // namespace cru::platform diff --git a/include/cru/common/platform/osx/Convert.hpp b/include/cru/common/platform/osx/Convert.hpp new file mode 100644 index 00000000..a583e8da --- /dev/null +++ b/include/cru/common/platform/osx/Convert.hpp @@ -0,0 +1,17 @@ +#pragma once +#include "../../PreConfig.hpp" +#ifdef CRU_PLATFORM_OSX + +#include "../../String.hpp" + +#include + +namespace cru::platform::osx { +CFStringRef Convert(const String& string); +String Convert(CFStringRef string); + +CFRange Convert(const Range& range); +Range Convert(const CFRange& range); +} // namespace cru::platform::osx + +#endif diff --git a/include/cru/common/platform/osx/Exception.hpp b/include/cru/common/platform/osx/Exception.hpp new file mode 100644 index 00000000..49527c69 --- /dev/null +++ b/include/cru/common/platform/osx/Exception.hpp @@ -0,0 +1,14 @@ +#pragma once +#include "../../PreConfig.hpp" +#ifdef CRU_PLATFORM_OSX + +#include "../Exception.hpp" + +namespace cru::platform::osx { +class OsxException : public PlatformException { + public: + using PlatformException::PlatformException; +}; +} // namespace cru::platform::osx + +#endif diff --git a/include/cru/common/platform/win/Exception.hpp b/include/cru/common/platform/win/Exception.hpp new file mode 100644 index 00000000..f90efe0a --- /dev/null +++ b/include/cru/common/platform/win/Exception.hpp @@ -0,0 +1,56 @@ +#pragma once +#include "../../PreConfig.hpp" +#ifdef CRU_PLATFORM_WINDOWS + +#include "WinPreConfig.hpp" + +#include "../Exception.hpp" + +#include +#include + +namespace cru::platform::win { +class CRU_BASE_API HResultError : public platform::PlatformException { + 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; + + HRESULT GetHResult() const { return h_result_; } + + private: + HRESULT h_result_; +}; + +inline void ThrowIfFailed(const HRESULT h_result) { + if (FAILED(h_result)) throw HResultError(h_result); +} + +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 { + public: + // ::GetLastError is automatically called to get the error code. + // The same as Win32Error(::GetLastError(), message) + explicit Win32Error(std::string_view message); + Win32Error(DWORD error_code, std::string_view 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/common/platform/win/WinPreConfig.hpp b/include/cru/common/platform/win/WinPreConfig.hpp new file mode 100644 index 00000000..881b5f6b --- /dev/null +++ b/include/cru/common/platform/win/WinPreConfig.hpp @@ -0,0 +1,21 @@ +#pragma once +#include "../../PreConfig.hpp" +#ifdef CRU_PLATFORM_WINDOWS + + + +#define NOMINMAX +#define WIN32_LEAN_AND_MEAN +#include +#undef CreateWindow +#undef DrawText +#undef CreateFont +#undef CreateEvent + +#include +#include +#include +#include +#include + +#endif -- cgit v1.2.3