aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/Check.h
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-09-10 01:30:59 +0800
committerYuqian Yang <crupest@crupest.life>2025-09-10 01:30:59 +0800
commitfe6e1686ce484cb0dd9a69f130e82f647c30016f (patch)
treef5e020e6a46d9a36a7952d1785cf20467e413159 /include/cru/platform/Check.h
parent18e330f9f4a673da78e6503c697619ad99b4bdbf (diff)
downloadcru-fe6e1686ce484cb0dd9a69f130e82f647c30016f.tar.gz
cru-fe6e1686ce484cb0dd9a69f130e82f647c30016f.tar.bz2
cru-fe6e1686ce484cb0dd9a69f130e82f647c30016f.zip
xcb window reparent.
Diffstat (limited to 'include/cru/platform/Check.h')
-rw-r--r--include/cru/platform/Check.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/cru/platform/Check.h b/include/cru/platform/Check.h
index 270150e8..202ee86e 100644
--- a/include/cru/platform/Check.h
+++ b/include/cru/platform/Check.h
@@ -35,4 +35,32 @@ std::shared_ptr<TTarget> CheckPlatform(const std::shared_ptr<TSource>& resource,
}
return result;
}
+
+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->GetPlatformIdUtf8(), 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->GetPlatformIdUtf8(), target_platform,
+ "Try to convert resource to target platform failed.");
+ }
+ return result;
+}
} // namespace cru::platform