aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/common/Exception.h5
-rw-r--r--include/cru/platform/Check.h15
-rw-r--r--include/cru/platform/Exception.h33
-rw-r--r--include/cru/platform/graphics/SvgGeometry.h13
4 files changed, 49 insertions, 17 deletions
diff --git a/include/cru/common/Exception.h b/include/cru/common/Exception.h
index d7e32a5a..06a10030 100644
--- a/include/cru/common/Exception.h
+++ b/include/cru/common/Exception.h
@@ -1,6 +1,8 @@
#pragma once
#include "String.h"
+#include <optional>
+
namespace cru {
#ifdef _MSC_VER
#pragma warning(disable : 4275)
@@ -23,6 +25,9 @@ class CRU_BASE_API Exception : public std::exception {
protected:
void SetMessage(String message) { message_ = std::move(message); }
+ void AppendMessage(StringView additional_message);
+ void AppendMessage(std::optional<StringView> additional_message);
+
private:
String message_;
mutable std::string utf8_message_;
diff --git a/include/cru/platform/Check.h b/include/cru/platform/Check.h
index 8dc4faac..453521cc 100644
--- a/include/cru/platform/Check.h
+++ b/include/cru/platform/Check.h
@@ -2,7 +2,6 @@
#include "Exception.h"
#include "Resource.h"
-#include "cru/common/Format.h"
#include "cru/common/String.h"
#include <memory>
@@ -15,10 +14,9 @@ TTarget* CheckPlatform(IPlatformResource* resource,
if (resource == nullptr) return nullptr;
const auto result = dynamic_cast<TTarget*>(resource);
if (result == nullptr) {
- throw UnsupportPlatformException(Format(
- u"Try to convert resource to target platform failed. Platform id of "
- "resource to convert: {} . Target platform id: {} .",
- resource->GetPlatformId(), target_platform));
+ throw PlatformNotMatchException(
+ resource->GetPlatformId(), target_platform,
+ u"Try to convert resource to target platform failed.");
}
return result;
}
@@ -31,10 +29,9 @@ std::shared_ptr<TTarget> CheckPlatform(const std::shared_ptr<TSource>& resource,
"TSource must be a subclass of INativeResource.");
const auto result = std::dynamic_pointer_cast<TTarget>(resource);
if (result == nullptr) {
- throw UnsupportPlatformException(Format(
- u"Try to convert resource to target platform failed. Platform id of "
- "resource to convert: {} . Target platform id: {} .",
- resource->GetPlatformId(), target_platform));
+ throw PlatformNotMatchException(
+ resource->GetPlatformId(), target_platform,
+ u"Try to convert resource to target platform failed.");
}
return result;
}
diff --git a/include/cru/platform/Exception.h b/include/cru/platform/Exception.h
index 7d194d41..d6cda815 100644
--- a/include/cru/platform/Exception.h
+++ b/include/cru/platform/Exception.h
@@ -4,18 +4,26 @@
#include "cru/common/Exception.h"
#include "cru/common/platform/Exception.h"
+#include <optional>
+
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 UnsupportPlatformException : public Exception {
+class CRU_PLATFORM_API PlatformNotMatchException : public PlatformException {
public:
- using Exception::Exception; // inherit constructors
+ PlatformNotMatchException(
+ String resource_platform, String target_platform,
+ std::optional<StringView> additional_message = std::nullopt);
+
+ ~PlatformNotMatchException() override;
- CRU_DEFAULT_COPY(UnsupportPlatformException)
- CRU_DEFAULT_MOVE(UnsupportPlatformException)
+ String GetResourcePlatform() const;
+ String GetTargetPlatform() const;
- CRU_DEFAULT_DESTRUCTOR(UnsupportPlatformException)
+ private:
+ String resource_platform_;
+ String target_platform_;
};
// This exception is thrown when a resource has been disposed and not usable
@@ -31,4 +39,19 @@ class CRU_PLATFORM_API ReuseException : public Exception {
CRU_DEFAULT_DESTRUCTOR(ReuseException)
};
+
+class CRU_PLATFORM_API PlatformUnsupportedException : public PlatformException {
+ public:
+ PlatformUnsupportedException(String platform, String operation,
+ std::optional<StringView> additional_message);
+
+ ~PlatformUnsupportedException() override;
+
+ String GetPlatform() const;
+ String GetOperation() const;
+
+ private:
+ String platform_;
+ String operation_;
+};
} // namespace cru::platform
diff --git a/include/cru/platform/graphics/SvgGeometry.h b/include/cru/platform/graphics/SvgGeometry.h
index 281158f0..742a68ca 100644
--- a/include/cru/platform/graphics/SvgGeometry.h
+++ b/include/cru/platform/graphics/SvgGeometry.h
@@ -3,8 +3,15 @@
#include "Geometry.h"
namespace cru::platform::graphics {
-class CRU_PLATFORM_GRAPHICS_API SvgGeometryBuilder : public virtual IGeometryBuilder {
+class CRU_PLATFORM_GRAPHICS_API SvgGeometryBuilder
+ : public Object,
+ public virtual IGeometryBuilder {
+ public:
+ SvgGeometryBuilder();
-};
-}
+ ~SvgGeometryBuilder() override;
+ private:
+ String current_;
+};
+} // namespace cru::platform::graphics