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