#pragma once #include "Exception.hpp" #include "Resource.hpp" #include "cru/common/StringUtil.hpp" #include #include #include namespace cru::platform { template TTarget* CheckPlatform(IPlatformResource* resource, const String& target_platform) { Expects(resource); const auto result = dynamic_cast(resource); if (result == nullptr) { throw UnsupportPlatformException(String::FromUtf8(fmt::format( "Try to convert resource to target platform failed. Platform id of " "resource to convert: {} . Target platform id: {} .", resource->GetPlatformId().ToUtf8(), target_platform.ToUtf8()))); } return result; } template std::shared_ptr CheckPlatform(const std::shared_ptr& resource, const String& target_platform) { static_assert(std::is_base_of_v, "TSource must be a subclass of INativeResource."); Expects(resource); const auto result = std::dynamic_pointer_cast(resource); if (result == nullptr) { throw UnsupportPlatformException(String::FromUtf8(fmt::format( "Try to convert resource to target platform failed. Platform id of " "resource to convert: {} . Target platform id: {} .", resource->GetPlatformId().ToUtf8(), target_platform.ToUtf8()))); } return result; } } // namespace cru::platform