#pragma once #include "Exception.hpp" #include "Resource.hpp" #include "cru/common/StringUtil.hpp" #include #include #include namespace cru::platform { template TTarget* CheckPlatform(INativeResource* resource, const std::u16string_view& target_platform) { Expects(resource); const auto result = dynamic_cast(resource); if (result == nullptr) { throw UnsupportPlatformException(fmt::format( "Try to convert resource to target platform failed. Platform id of " "resource to convert: {} . Target platform id: {} .", ToUtf8(resource->GetPlatformId()), ToUtf8(target_platform))); } return result; } template std::shared_ptr CheckPlatform( const std::shared_ptr& resource, const std::u16string_view& 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(fmt::format( "Try to convert resource to target platform failed. Platform id of " "resource to convert: {} . Target platform id: {} .", ToUtf8(resource->GetPlatformId()), ToUtf8(target_platform))); } return result; } } // namespace cru::platform