aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/platform/Base.h78
-rw-r--r--include/cru/platform/Check.h36
-rw-r--r--include/cru/platform/Exception.h55
-rw-r--r--include/cru/platform/win/Exception.h1
-rw-r--r--src/platform/Base.cpp30
-rw-r--r--src/platform/CMakeLists.txt1
-rw-r--r--src/platform/Exception.cpp34
-rw-r--r--src/platform/graphics/Geometry.cpp1
-rw-r--r--src/platform/graphics/SvgGeometryBuilderMixin.cpp1
-rw-r--r--src/platform/graphics/cairo/CairoImageFactory.cpp1
-rw-r--r--src/platform/graphics/cairo/CairoPainter.cpp2
-rw-r--r--src/platform/graphics/cairo/PangoTextLayout.cpp1
-rw-r--r--src/platform/graphics/direct2d/ImageFactory.cpp1
-rw-r--r--src/platform/graphics/direct2d/Painter.cpp1
-rw-r--r--src/platform/graphics/direct2d/TextLayout.cpp1
-rw-r--r--src/platform/graphics/quartz/Factory.cpp1
-rw-r--r--src/platform/graphics/quartz/ImageFactory.cpp1
-rw-r--r--src/platform/graphics/quartz/Painter.cpp2
-rw-r--r--src/platform/graphics/quartz/TextLayout.cpp1
-rw-r--r--src/platform/graphics/web_canvas/Painter.cpp1
-rw-r--r--src/platform/gui/osx/Window.mm1
-rw-r--r--src/platform/gui/sdl/Window.cpp1
-rw-r--r--src/platform/gui/win/Window.cpp1
-rw-r--r--src/platform/gui/xcb/InputMethod.cpp1
-rw-r--r--src/platform/gui/xcb/Window.cpp1
25 files changed, 108 insertions, 147 deletions
diff --git a/include/cru/platform/Base.h b/include/cru/platform/Base.h
index 9a8540f2..a31e8e08 100644
--- a/include/cru/platform/Base.h
+++ b/include/cru/platform/Base.h
@@ -1,9 +1,13 @@
#pragma once
#include <cru/base/Base.h>
+#include <cru/base/Exception.h>
#include <string>
+#include <optional>
+#include <string_view>
+
#ifdef CRU_IS_DLL
#ifdef CRU_PLATFORM_EXPORT_API
#define CRU_PLATFORM_API __declspec(dllexport)
@@ -20,4 +24,78 @@ struct CRU_PLATFORM_API IPlatformResource : virtual Interface {
virtual std::string GetPlatformId() const = 0;
virtual std::string GetDebugString();
};
+
+// 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.
+class CRU_PLATFORM_API PlatformNotMatchException : public PlatformException {
+ public:
+ PlatformNotMatchException(
+ std::string resource_platform, std::string target_platform,
+ std::optional<std::string_view> additional_message = std::nullopt);
+
+ ~PlatformNotMatchException() override;
+
+ std::string GetResourcePlatformUtf8() const { return resource_platform_; }
+ std::string GetTargetPlatformUtf8() const { return target_platform_; }
+
+ private:
+ std::string resource_platform_;
+ std::string target_platform_;
+};
+
+// This exception is thrown when a resource has been disposed and not usable
+// again.
+// For example, calling Build twice on a GeometryBuilder::Build will lead to
+// this exception.
+class CRU_PLATFORM_API ReuseException : public Exception {
+ public:
+ using Exception::Exception; // inherit constructors
+
+ CRU_DEFAULT_DESTRUCTOR(ReuseException)
+};
+
+class CRU_PLATFORM_API PlatformUnsupportedException : public PlatformException {
+ public:
+ PlatformUnsupportedException(
+ std::string platform, std::string operation,
+ std::optional<std::string_view> additional_message);
+
+ ~PlatformUnsupportedException() override;
+
+ std::string GetPlatformUtf8() const { return platform_; }
+ std::string GetOperationUtf8() const { return operation_; }
+
+ private:
+ std::string platform_;
+ std::string operation_;
+};
+
+template <typename TTarget>
+TTarget* CheckPlatform(IPlatformResource* resource,
+ std::string target_platform) {
+ if (resource == nullptr) return nullptr;
+ const auto result = dynamic_cast<TTarget*>(resource);
+ if (result == nullptr) {
+ throw PlatformNotMatchException(
+ resource->GetPlatformId(), target_platform,
+ "Try to convert resource to target platform failed.");
+ }
+ return result;
+}
+
+template <typename TTarget, typename TSource>
+std::shared_ptr<TTarget> CheckPlatform(const std::shared_ptr<TSource>& resource,
+ std::string target_platform) {
+ if (resource == nullptr) return nullptr;
+ static_assert(std::is_base_of_v<IPlatformResource, TSource>,
+ "TSource must be a subclass of IPlatformResource.");
+ const auto result = std::dynamic_pointer_cast<TTarget>(resource);
+ if (result == nullptr) {
+ throw PlatformNotMatchException(
+ resource->GetPlatformId(), target_platform,
+ "Try to convert resource to target platform failed.");
+ }
+ return result;
+}
} // namespace cru::platform
diff --git a/include/cru/platform/Check.h b/include/cru/platform/Check.h
deleted file mode 100644
index 5b6cd2be..00000000
--- a/include/cru/platform/Check.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#pragma once
-#include "Base.h"
-#include "Exception.h"
-
-#include <memory>
-#include <type_traits>
-
-namespace cru::platform {
-template <typename TTarget>
-TTarget* CheckPlatform(IPlatformResource* resource,
- std::string target_platform) {
- if (resource == nullptr) return nullptr;
- const auto result = dynamic_cast<TTarget*>(resource);
- if (result == nullptr) {
- throw PlatformNotMatchException(
- resource->GetPlatformId(), target_platform,
- "Try to convert resource to target platform failed.");
- }
- return result;
-}
-
-template <typename TTarget, typename TSource>
-std::shared_ptr<TTarget> CheckPlatform(const std::shared_ptr<TSource>& resource,
- std::string target_platform) {
- if (resource == nullptr) return nullptr;
- static_assert(std::is_base_of_v<IPlatformResource, TSource>,
- "TSource must be a subclass of IPlatformResource.");
- const auto result = std::dynamic_pointer_cast<TTarget>(resource);
- if (result == nullptr) {
- throw PlatformNotMatchException(
- resource->GetPlatformId(), target_platform,
- "Try to convert resource to target platform failed.");
- }
- return result;
-}
-} // namespace cru::platform
diff --git a/include/cru/platform/Exception.h b/include/cru/platform/Exception.h
deleted file mode 100644
index f43162d1..00000000
--- a/include/cru/platform/Exception.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#pragma once
-#include "Base.h"
-#include "cru/base/Base.h"
-#include "cru/base/Exception.h"
-
-#include <optional>
-#include <string_view>
-
-namespace cru::platform {
-// 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.
-class CRU_PLATFORM_API PlatformNotMatchException : public PlatformException {
- public:
- PlatformNotMatchException(
- std::string resource_platform, std::string target_platform,
- std::optional<std::string_view> additional_message = std::nullopt);
-
- ~PlatformNotMatchException() override;
-
- std::string GetResourcePlatformUtf8() const { return resource_platform_; }
- std::string GetTargetPlatformUtf8() const { return target_platform_; }
-
- private:
- std::string resource_platform_;
- std::string target_platform_;
-};
-
-// This exception is thrown when a resource has been disposed and not usable
-// again.
-// For example, calling Build twice on a GeometryBuilder::Build will lead to
-// this exception.
-class CRU_PLATFORM_API ReuseException : public Exception {
- public:
- using Exception::Exception; // inherit constructors
-
- CRU_DEFAULT_DESTRUCTOR(ReuseException)
-};
-
-class CRU_PLATFORM_API PlatformUnsupportedException : public PlatformException {
- public:
- PlatformUnsupportedException(
- std::string platform, std::string operation,
- std::optional<std::string_view> additional_message);
-
- ~PlatformUnsupportedException() override;
-
- std::string GetPlatformUtf8() const { return platform_; }
- std::string GetOperationUtf8() const { return operation_; }
-
- private:
- std::string platform_;
- std::string operation_;
-};
-} // namespace cru::platform
diff --git a/include/cru/platform/win/Exception.h b/include/cru/platform/win/Exception.h
index 353c2dab..e6c65016 100644
--- a/include/cru/platform/win/Exception.h
+++ b/include/cru/platform/win/Exception.h
@@ -1,3 +1,2 @@
#pragma once
#include "cru/base/platform/win/Exception.h"
-#include "cru/platform/Exception.h"
diff --git a/src/platform/Base.cpp b/src/platform/Base.cpp
index c660ad13..fd1dec4e 100644
--- a/src/platform/Base.cpp
+++ b/src/platform/Base.cpp
@@ -1,5 +1,35 @@
#include "cru/platform/Base.h"
+#include <format>
+#include <optional>
+#include <string_view>
+
namespace cru::platform {
std::string IPlatformResource::GetDebugString() { return {}; }
+
+PlatformNotMatchException::PlatformNotMatchException(
+ std::string resource_platform, std::string target_platform,
+ std::optional<std::string_view> additional_message)
+ : PlatformException(std::format(
+ "Resource platform '{}' does not match target platform '{}'.",
+ resource_platform_, target_platform_)),
+ resource_platform_(std::move(resource_platform)),
+ target_platform_(std::move(target_platform)) {
+ AppendMessage(additional_message);
+}
+
+PlatformNotMatchException::~PlatformNotMatchException() {}
+
+PlatformUnsupportedException::PlatformUnsupportedException(
+ std::string platform, std::string operation,
+ std::optional<std::string_view> additional_message)
+ : PlatformException(
+ std::format("Operation '{}' is not supported on platform '{}'.",
+ operation, platform)),
+ platform_(std::move(platform)),
+ operation_(std::move(operation)) {
+ AppendMessage(additional_message);
+}
+
+PlatformUnsupportedException::~PlatformUnsupportedException() {}
} // namespace cru::platform
diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt
index 4cb6b9e8..d577d79c 100644
--- a/src/platform/CMakeLists.txt
+++ b/src/platform/CMakeLists.txt
@@ -1,7 +1,6 @@
add_library(CruPlatformBase
Base.cpp
Color.cpp
- Exception.cpp
GraphicsBase.cpp
)
target_link_libraries(CruPlatformBase PUBLIC CruBase)
diff --git a/src/platform/Exception.cpp b/src/platform/Exception.cpp
deleted file mode 100644
index 6a718f63..00000000
--- a/src/platform/Exception.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "cru/platform/Exception.h"
-#include "cru/base/Exception.h"
-
-#include <format>
-#include <optional>
-#include <string_view>
-
-namespace cru::platform {
-PlatformNotMatchException::PlatformNotMatchException(
- std::string resource_platform, std::string target_platform,
- std::optional<std::string_view> additional_message)
- : PlatformException(std::format(
- "Resource platform '{}' does not match target platform '{}'.",
- resource_platform_, target_platform_)),
- resource_platform_(std::move(resource_platform)),
- target_platform_(std::move(target_platform)) {
- AppendMessage(additional_message);
-}
-
-PlatformNotMatchException::~PlatformNotMatchException() {}
-
-PlatformUnsupportedException::PlatformUnsupportedException(
- std::string platform, std::string operation,
- std::optional<std::string_view> additional_message)
- : PlatformException(
- std::format("Operation '{}' is not supported on platform '{}'.",
- operation, platform)),
- platform_(std::move(platform)),
- operation_(std::move(operation)) {
- AppendMessage(additional_message);
-}
-
-PlatformUnsupportedException::~PlatformUnsupportedException() {}
-} // namespace cru::platform
diff --git a/src/platform/graphics/Geometry.cpp b/src/platform/graphics/Geometry.cpp
index 4189ef72..3d88a644 100644
--- a/src/platform/graphics/Geometry.cpp
+++ b/src/platform/graphics/Geometry.cpp
@@ -2,7 +2,6 @@
#include "cru/base/Exception.h"
#include "cru/base/StringUtil.h"
-#include "cru/platform/Exception.h"
#include "cru/platform/graphics/Factory.h"
#include <cmath>
diff --git a/src/platform/graphics/SvgGeometryBuilderMixin.cpp b/src/platform/graphics/SvgGeometryBuilderMixin.cpp
index 0863e5eb..35faaf4b 100644
--- a/src/platform/graphics/SvgGeometryBuilderMixin.cpp
+++ b/src/platform/graphics/SvgGeometryBuilderMixin.cpp
@@ -1,5 +1,4 @@
#include "cru/platform/graphics/SvgGeometryBuilderMixin.h"
-#include "cru/platform/Exception.h"
#include <string>
diff --git a/src/platform/graphics/cairo/CairoImageFactory.cpp b/src/platform/graphics/cairo/CairoImageFactory.cpp
index 070eb245..a634d135 100644
--- a/src/platform/graphics/cairo/CairoImageFactory.cpp
+++ b/src/platform/graphics/cairo/CairoImageFactory.cpp
@@ -1,6 +1,5 @@
#include "cru/platform/graphics/cairo/CairoImageFactory.h"
#include "cru/base/Exception.h"
-#include "cru/platform/Check.h"
#include "cru/platform/graphics/cairo/Base.h"
#include "cru/platform/graphics/cairo/CairoImage.h"
diff --git a/src/platform/graphics/cairo/CairoPainter.cpp b/src/platform/graphics/cairo/CairoPainter.cpp
index f2a2ce50..a0a28337 100644
--- a/src/platform/graphics/cairo/CairoPainter.cpp
+++ b/src/platform/graphics/cairo/CairoPainter.cpp
@@ -1,7 +1,5 @@
#include "cru/platform/graphics/cairo/CairoPainter.h"
#include "cru/base/log/Logger.h"
-#include "cru/platform/Check.h"
-#include "cru/platform/Exception.h"
#include "cru/platform/graphics/cairo/Base.h"
#include "cru/platform/graphics/cairo/CairoBrush.h"
#include "cru/platform/graphics/cairo/CairoGeometry.h"
diff --git a/src/platform/graphics/cairo/PangoTextLayout.cpp b/src/platform/graphics/cairo/PangoTextLayout.cpp
index f8ed20c7..9d301031 100644
--- a/src/platform/graphics/cairo/PangoTextLayout.cpp
+++ b/src/platform/graphics/cairo/PangoTextLayout.cpp
@@ -1,5 +1,4 @@
#include "cru/platform/graphics/cairo/PangoTextLayout.h"
-#include "cru/platform/Check.h"
#include "cru/platform/GraphicsBase.h"
#include "cru/platform/graphics/Base.h"
#include "cru/platform/graphics/cairo/CairoGraphicsFactory.h"
diff --git a/src/platform/graphics/direct2d/ImageFactory.cpp b/src/platform/graphics/direct2d/ImageFactory.cpp
index aff411c4..df162561 100644
--- a/src/platform/graphics/direct2d/ImageFactory.cpp
+++ b/src/platform/graphics/direct2d/ImageFactory.cpp
@@ -1,7 +1,6 @@
#include "cru/platform/graphics/direct2d/ImageFactory.h"
#include "cru/base/platform/win/Exception.h"
#include "cru/base/platform/win/StreamConvert.h"
-#include "cru/platform/Check.h"
#include "cru/platform/graphics/direct2d/Exception.h"
#include "cru/platform/graphics/direct2d/Factory.h"
#include "cru/platform/graphics/direct2d/Image.h"
diff --git a/src/platform/graphics/direct2d/Painter.cpp b/src/platform/graphics/direct2d/Painter.cpp
index fabcdafd..c62947e0 100644
--- a/src/platform/graphics/direct2d/Painter.cpp
+++ b/src/platform/graphics/direct2d/Painter.cpp
@@ -1,7 +1,6 @@
#include "cru/platform/graphics/direct2d/Painter.h"
#include "cru/base/log/Logger.h"
-#include "cru/platform/Check.h"
#include "cru/platform/graphics/direct2d/Brush.h"
#include "cru/platform/graphics/direct2d/ConvertUtil.h"
#include "cru/platform/graphics/direct2d/Exception.h"
diff --git a/src/platform/graphics/direct2d/TextLayout.cpp b/src/platform/graphics/direct2d/TextLayout.cpp
index 906d64ec..1abaa383 100644
--- a/src/platform/graphics/direct2d/TextLayout.cpp
+++ b/src/platform/graphics/direct2d/TextLayout.cpp
@@ -3,7 +3,6 @@
#include "cru/base/StringUtil.h"
#include "cru/base/log/Logger.h"
-#include "cru/platform/Check.h"
#include "cru/platform/graphics/direct2d/Exception.h"
#include "cru/platform/graphics/direct2d/Factory.h"
#include "cru/platform/graphics/direct2d/Font.h"
diff --git a/src/platform/graphics/quartz/Factory.cpp b/src/platform/graphics/quartz/Factory.cpp
index 69e9c607..3a489212 100644
--- a/src/platform/graphics/quartz/Factory.cpp
+++ b/src/platform/graphics/quartz/Factory.cpp
@@ -1,6 +1,5 @@
#include "cru/platform/graphics/quartz/Factory.h"
-#include "cru/platform/Check.h"
#include "cru/platform/graphics/ImageFactory.h"
#include "cru/platform/graphics/quartz/Brush.h"
#include "cru/platform/graphics/quartz/Font.h"
diff --git a/src/platform/graphics/quartz/ImageFactory.cpp b/src/platform/graphics/quartz/ImageFactory.cpp
index 69fa502d..87b2ff36 100644
--- a/src/platform/graphics/quartz/ImageFactory.cpp
+++ b/src/platform/graphics/quartz/ImageFactory.cpp
@@ -1,7 +1,6 @@
#include "cru/platform/graphics/quartz/ImageFactory.h"
#include "cru/base/Exception.h"
#include "cru/base/Osx.h"
-#include "cru/platform/Check.h"
#include "cru/platform/graphics/Image.h"
#include "cru/platform/graphics/quartz/Convert.h"
#include "cru/platform/graphics/quartz/Image.h"
diff --git a/src/platform/graphics/quartz/Painter.cpp b/src/platform/graphics/quartz/Painter.cpp
index 45dee716..b825f28c 100644
--- a/src/platform/graphics/quartz/Painter.cpp
+++ b/src/platform/graphics/quartz/Painter.cpp
@@ -5,9 +5,7 @@
#include "cru/platform/graphics/quartz/Geometry.h"
#include "cru/platform/graphics/quartz/Image.h"
#include "cru/platform/graphics/quartz/TextLayout.h"
-#include "cru/platform/Check.h"
#include "cru/platform/Color.h"
-#include "cru/platform/Exception.h"
namespace cru::platform::graphics::quartz {
QuartzCGContextPainter::QuartzCGContextPainter(
diff --git a/src/platform/graphics/quartz/TextLayout.cpp b/src/platform/graphics/quartz/TextLayout.cpp
index 87f85b77..b7a015c1 100644
--- a/src/platform/graphics/quartz/TextLayout.cpp
+++ b/src/platform/graphics/quartz/TextLayout.cpp
@@ -2,7 +2,6 @@
#include "cru/base/Base.h"
#include "cru/base/Osx.h"
#include "cru/base/StringUtil.h"
-#include "cru/platform/Check.h"
#include "cru/platform/graphics/Base.h"
#include "cru/platform/graphics/quartz/Convert.h"
#include "cru/platform/graphics/quartz/Resource.h"
diff --git a/src/platform/graphics/web_canvas/Painter.cpp b/src/platform/graphics/web_canvas/Painter.cpp
index c9184165..e875b0cd 100644
--- a/src/platform/graphics/web_canvas/Painter.cpp
+++ b/src/platform/graphics/web_canvas/Painter.cpp
@@ -1,4 +1,3 @@
-#include "cru/platform/Check.h"
#include "cru/platform/graphics/Brush.h"
#include "cru/platform/graphics/web_canvas/WebCanvasBrush.h"
#include "cru/platform/graphics/web_canvas/WebCanvasGraphicsFactory.h"
diff --git a/src/platform/gui/osx/Window.mm b/src/platform/gui/osx/Window.mm
index 65d31ab8..ca2de573 100644
--- a/src/platform/gui/osx/Window.mm
+++ b/src/platform/gui/osx/Window.mm
@@ -6,7 +6,6 @@
#include "cru/base/Osx.h"
#include "cru/base/Range.h"
#include "cru/base/log/Logger.h"
-#include "cru/platform/Check.h"
#include "cru/platform/graphics/NullPainter.h"
#include "cru/platform/graphics/quartz/Convert.h"
#include "cru/platform/graphics/quartz/Painter.h"
diff --git a/src/platform/gui/sdl/Window.cpp b/src/platform/gui/sdl/Window.cpp
index 3737cae0..1c2d53bc 100644
--- a/src/platform/gui/sdl/Window.cpp
+++ b/src/platform/gui/sdl/Window.cpp
@@ -1,6 +1,5 @@
#include "cru/platform/gui/sdl/Window.h"
#include "cru/base/Base.h"
-#include "cru/platform/Check.h"
#include "cru/platform/GraphicsBase.h"
#include "cru/platform/graphics/NullPainter.h"
#include "cru/platform/graphics/Painter.h"
diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp
index 9a9a7275..35f79a66 100644
--- a/src/platform/gui/win/Window.cpp
+++ b/src/platform/gui/win/Window.cpp
@@ -3,7 +3,6 @@
#include "WindowManager.h"
#include "cru/base/StringUtil.h"
#include "cru/base/log/Logger.h"
-#include "cru/platform/Check.h"
#include "cru/platform/graphics/NullPainter.h"
#include "cru/platform/graphics/direct2d/WindowPainter.h"
#include "cru/platform/gui/DebugFlags.h"
diff --git a/src/platform/gui/xcb/InputMethod.cpp b/src/platform/gui/xcb/InputMethod.cpp
index 5ee06ab4..d6d4b9e7 100644
--- a/src/platform/gui/xcb/InputMethod.cpp
+++ b/src/platform/gui/xcb/InputMethod.cpp
@@ -1,6 +1,5 @@
#include "cru/platform/gui/xcb/InputMethod.h"
#include "cru/base/log/Logger.h"
-#include "cru/platform/Check.h"
#include "cru/platform/gui/xcb/Input.h"
#include "cru/platform/gui/xcb/UiApplication.h"
#include "cru/platform/gui/xcb/Window.h"
diff --git a/src/platform/gui/xcb/Window.cpp b/src/platform/gui/xcb/Window.cpp
index 003afc40..96483e04 100644
--- a/src/platform/gui/xcb/Window.cpp
+++ b/src/platform/gui/xcb/Window.cpp
@@ -2,7 +2,6 @@
#include "cru/base/Base.h"
#include "cru/base/Guard.h"
#include "cru/base/log/Logger.h"
-#include "cru/platform/Check.h"
#include "cru/platform/GraphicsBase.h"
#include "cru/platform/graphics/NullPainter.h"
#include "cru/platform/graphics/Painter.h"