aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-25 17:30:46 +0800
committercrupest <crupest@outlook.com>2022-01-25 17:30:46 +0800
commit2ed65999ef6f3e1156427dd3efe04353ae657882 (patch)
tree1c6618099e42887e96351c87cc8ce6b7c61b01f7
parenta77fb1aaa4aa765ae51b3cb5a1f8d9c8c233b01a (diff)
downloadcru-2ed65999ef6f3e1156427dd3efe04353ae657882.tar.gz
cru-2ed65999ef6f3e1156427dd3efe04353ae657882.tar.bz2
cru-2ed65999ef6f3e1156427dd3efe04353ae657882.zip
...
-rw-r--r--include/cru/common/io/Resource.hpp10
-rw-r--r--include/cru/common/platform/Exception.hpp15
-rw-r--r--include/cru/common/platform/osx/Convert.hpp17
-rw-r--r--include/cru/common/platform/osx/Exception.hpp14
-rw-r--r--include/cru/common/platform/win/Exception.hpp56
-rw-r--r--include/cru/common/platform/win/WinPreConfig.hpp21
-rw-r--r--include/cru/osx/Convert.hpp12
-rw-r--r--include/cru/osx/Exception.hpp9
-rw-r--r--include/cru/platform/Exception.hpp11
-rw-r--r--include/cru/win/Exception.hpp51
-rw-r--r--include/cru/win/WinPreConfig.hpp17
-rw-r--r--src/common/CMakeLists.txt13
-rw-r--r--src/common/io/Resource.cpp20
-rw-r--r--src/common/platform/Exception.cpp1
-rw-r--r--src/common/platform/osx/Convert.cpp (renamed from src/osx/Convert.cpp)6
-rw-r--r--src/common/platform/osx/Exception.cpp1
-rw-r--r--src/common/platform/win/Exception.cpp (renamed from src/win/Exception.cpp)2
-rw-r--r--src/osx/CMakeLists.txt2
-rw-r--r--src/osx/Exception.cpp1
-rw-r--r--src/win/CMakeLists.txt3
-rw-r--r--src/win/HeapDebug.cpp9
21 files changed, 175 insertions, 116 deletions
diff --git a/include/cru/common/io/Resource.hpp b/include/cru/common/io/Resource.hpp
new file mode 100644
index 00000000..d1343d8e
--- /dev/null
+++ b/include/cru/common/io/Resource.hpp
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "../Base.hpp"
+#include "Stream.hpp"
+
+#include <memory>
+
+namespace cru::io {
+std::unique_ptr<Stream> CreateStreamFromResourcePath(const String& path);
+}
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 <CoreFoundation/CFString.h>
+
+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 <stdexcept>
+#include <string_view>
+
+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 <Windows.h>
+#undef CreateWindow
+#undef DrawText
+#undef CreateFont
+#undef CreateEvent
+
+#include <d2d1_2.h>
+#include <d3d11.h>
+#include <dwrite.h>
+#include <dxgi1_2.h>
+#include <wrl/client.h>
+
+#endif
diff --git a/include/cru/osx/Convert.hpp b/include/cru/osx/Convert.hpp
index 6d2c0327..ec1d5d6b 100644
--- a/include/cru/osx/Convert.hpp
+++ b/include/cru/osx/Convert.hpp
@@ -1,12 +1,2 @@
#pragma once
-#include "Resource.hpp"
-
-#include <CoreFoundation/CFString.h>
-
-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
+#include "cru/common/platform/osx/Convert.hpp"
diff --git a/include/cru/osx/Exception.hpp b/include/cru/osx/Exception.hpp
index 5d057c65..4123778b 100644
--- a/include/cru/osx/Exception.hpp
+++ b/include/cru/osx/Exception.hpp
@@ -1,9 +1,2 @@
#pragma once
-#include "cru/platform/Exception.hpp"
-
-namespace cru::platform::osx {
-class OsxException : public PlatformException {
- public:
- using PlatformException::PlatformException;
-};
-} // namespace cru::platform::osx
+#include "cru/common/platform/osx/Exception.hpp"
diff --git a/include/cru/platform/Exception.hpp b/include/cru/platform/Exception.hpp
index 379753d4..b50e8c67 100644
--- a/include/cru/platform/Exception.hpp
+++ b/include/cru/platform/Exception.hpp
@@ -2,18 +2,9 @@
#include "Base.hpp"
#include "cru/common/Base.hpp"
#include "cru/common/Exception.hpp"
+#include "cru/common/platform/Exception.hpp"
namespace cru::platform {
-class CRU_PLATFORM_API PlatformException : public Exception {
- public:
- using Exception::Exception; // inherit constructors
-
- CRU_DEFAULT_COPY(PlatformException)
- CRU_DEFAULT_MOVE(PlatformException)
-
- CRU_DEFAULT_DESTRUCTOR(PlatformException)
-};
-
// This exception is thrown when a resource is used on another platform.
// Of course, you can't mix resources of two different platform.
// For example, Win32 Brush (may add in the future) with Direct Painter.
diff --git a/include/cru/win/Exception.hpp b/include/cru/win/Exception.hpp
index 3a95aa5d..d3ac69a7 100644
--- a/include/cru/win/Exception.hpp
+++ b/include/cru/win/Exception.hpp
@@ -1,51 +1,2 @@
#pragma once
-#include "WinPreConfig.hpp"
-
-#include "cru/platform/Exception.hpp"
-
-#include <stdexcept>
-#include <string_view>
-
-namespace cru::platform::win {
-class 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 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
+#include "cru/common/platform/win/Exception.hpp"
diff --git a/include/cru/win/WinPreConfig.hpp b/include/cru/win/WinPreConfig.hpp
index 1bd494f2..1658e45d 100644
--- a/include/cru/win/WinPreConfig.hpp
+++ b/include/cru/win/WinPreConfig.hpp
@@ -1,17 +1,2 @@
#pragma once
-
-#include "cru/common/PreConfig.hpp"
-
-#define NOMINMAX
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
-#undef CreateWindow
-#undef DrawText
-#undef CreateFont
-#undef CreateEvent
-
-#include <d2d1_2.h>
-#include <d3d11.h>
-#include <dwrite.h>
-#include <dxgi1_2.h>
-#include <wrl/client.h>
+#include "cru/common/platform/win/WinPreConfig.hpp"
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index d8462abf..0316d9e6 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -7,7 +7,9 @@ add_library(cru_base SHARED
String.cpp
StringUtil.cpp
io/Stream.cpp
+ io/Resource.cpp
io/MemoryStream.cpp
+ platform/Exception.cpp
)
target_compile_definitions(cru_base PRIVATE CRU_BASE_EXPORT_API)
target_include_directories(cru_base PUBLIC ${CRU_INCLUDE_DIR})
@@ -20,9 +22,20 @@ if (UNIX)
)
endif()
+if (APPLE)
+ find_library(CORE_FOUNDATION CoreFoundation REQUIRED)
+ target_link_libraries(cru_base PUBLIC ${CORE_FOUNDATION})
+
+ target_sources(cru_base PRIVATE
+ platform/osx/Convert.cpp
+ platform/osx/Exception.cpp
+ )
+endif()
+
if (WIN32)
target_sources(cru_base PRIVATE
io/Win32FileStream.cpp
+ platform/win/Exception.cpp
)
endif()
diff --git a/src/common/io/Resource.cpp b/src/common/io/Resource.cpp
new file mode 100644
index 00000000..e2ff8004
--- /dev/null
+++ b/src/common/io/Resource.cpp
@@ -0,0 +1,20 @@
+#include "cru/common/io/Resource.hpp"
+#include "cru/common/Exception.hpp"
+
+#if defined(CRU_PLATFORM_OSX)
+#include <CoreFoundation/CoreFoundation.h>
+#elif defined(CRU_PLATFORM_WINDOWS)
+#endif
+
+namespace cru::io {
+std::unique_ptr<Stream> CreateStreamFromResourcePath(const String& path) {
+#if defined(CRU_PLATFORM_OSX)
+ // CFBundleRef main_bundle = CFBundleGetMainBundle();
+ throw Exception(u"Not implemented.");
+#elif defined(CRU_PLATFORM_WINDOWS)
+ throw Exception(u"Not implemented.");
+#else
+ throw Exception(u"Not implemented.");
+#endif
+}
+} // namespace cru::io
diff --git a/src/common/platform/Exception.cpp b/src/common/platform/Exception.cpp
new file mode 100644
index 00000000..c13c8b1e
--- /dev/null
+++ b/src/common/platform/Exception.cpp
@@ -0,0 +1 @@
+#include "cru/common/platform/Exception.hpp"
diff --git a/src/osx/Convert.cpp b/src/common/platform/osx/Convert.cpp
index 6e9692f2..e5105698 100644
--- a/src/osx/Convert.cpp
+++ b/src/common/platform/osx/Convert.cpp
@@ -1,8 +1,4 @@
-#include "cru/osx/Convert.hpp"
-
-#include "cru/common/StringUtil.hpp"
-
-#include <string>
+#include "cru/common/platform/osx/Convert.hpp"
namespace cru::platform::osx {
CFStringRef Convert(const String& string) {
diff --git a/src/common/platform/osx/Exception.cpp b/src/common/platform/osx/Exception.cpp
new file mode 100644
index 00000000..b02fd458
--- /dev/null
+++ b/src/common/platform/osx/Exception.cpp
@@ -0,0 +1 @@
+#include "cru/common/platform//osx/Exception.hpp"
diff --git a/src/win/Exception.cpp b/src/common/platform/win/Exception.cpp
index fb46f184..34ae8955 100644
--- a/src/win/Exception.cpp
+++ b/src/common/platform/win/Exception.cpp
@@ -1,4 +1,4 @@
-#include "cru/win/Exception.hpp"
+#include "cru/common/platform/win/Exception.hpp"
#include "cru/common/Format.hpp"
#include <optional>
diff --git a/src/osx/CMakeLists.txt b/src/osx/CMakeLists.txt
index 7f6a7538..ad591478 100644
--- a/src/osx/CMakeLists.txt
+++ b/src/osx/CMakeLists.txt
@@ -1,6 +1,4 @@
add_library(cru_osx_base SHARED
- Convert.cpp
- Exception.cpp
Resource.cpp
)
diff --git a/src/osx/Exception.cpp b/src/osx/Exception.cpp
deleted file mode 100644
index c7eef64b..00000000
--- a/src/osx/Exception.cpp
+++ /dev/null
@@ -1 +0,0 @@
-#include "cru/osx/Exception.hpp"
diff --git a/src/win/CMakeLists.txt b/src/win/CMakeLists.txt
index fe2cd635..e190e9a0 100644
--- a/src/win/CMakeLists.txt
+++ b/src/win/CMakeLists.txt
@@ -1,9 +1,6 @@
add_library(cru_win_base STATIC
DebugLogger.hpp
StdOutLogger.hpp
-
- Exception.cpp
- HeapDebug.cpp
)
target_compile_definitions(cru_win_base PUBLIC UNICODE _UNICODE) # use unicode
target_link_libraries(cru_win_base PUBLIC cru_base)
diff --git a/src/win/HeapDebug.cpp b/src/win/HeapDebug.cpp
deleted file mode 100644
index b1b9fe1a..00000000
--- a/src/win/HeapDebug.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "cru/win/WinPreConfig.hpp"
-
-#include <crtdbg.h>
-
-namespace cru::platform {
-void SetupHeapDebug() {
- _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
-}
-} // namespace cru::platform