From e7d672ec1578319bad8e944e37c91fbcb8371e75 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 23 Nov 2023 18:31:03 +0100 Subject: use explicit instantiation for vector serializers --- serialize/magnum-vector2i.cpp | 56 ------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 serialize/magnum-vector2i.cpp (limited to 'serialize/magnum-vector2i.cpp') diff --git a/serialize/magnum-vector2i.cpp b/serialize/magnum-vector2i.cpp deleted file mode 100644 index 0b52d508..00000000 --- a/serialize/magnum-vector2i.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "magnum-vector2i.hpp" -#include "compat/exception.hpp" -#include - -using namespace floormat; - -void floormat::Serialize::throw_failed_to_parse_vector2(const std::string& str) -{ - fm_throw("failed to parse Vector2 '{}'"_cf, str); -} - -void floormat::Serialize::throw_vector2_overflow(const std::string& str) -{ - fm_throw("numeric overflow in Vector2 '{}'"_cf, str); -} - -using namespace nlohmann; - -template -requires std::is_integral_v -void nlohmann::adl_serializer>::to_json(json& j, const Magnum::Math::Vector2& val) -{ - char buf[64]; - using type = std::conditional_t, intmax_t, uintmax_t>; - constexpr auto format_string = std::is_signed_v ? "%jd x %jd" : "%ju x %ju"; - snprintf(buf, sizeof(buf), format_string, (type)val[0], (type)val[1]); - j = buf; -} - -template -requires std::is_integral_v -void nlohmann::adl_serializer>::from_json(const json& j, Magnum::Math::Vector2& val) -{ - using namespace floormat; - std::string str = j; - using type = std::conditional_t, intmax_t, uintmax_t>; - constexpr auto format_string = std::is_signed_v ? "%jd x %jd%n" : "%ju x %ju%n"; - type x = 0, y = 0; - int n = 0; - int ret = std::sscanf(str.data(), format_string, &x, &y, &n); - if (ret != 2 || (size_t)n != str.size() || x != (T)x || y != (T)y) - floormat::Serialize::throw_failed_to_parse_vector2(str); - if constexpr(sizeof(T) < sizeof(type)) - if (x != (type)(T)x || y != (type)(T)y) - floormat::Serialize::throw_vector2_overflow(str); - val = { (T)x, (T)y }; -} - -template struct nlohmann::adl_serializer>; -template struct nlohmann::adl_serializer>; -template struct nlohmann::adl_serializer>; -template struct nlohmann::adl_serializer>; -template struct nlohmann::adl_serializer>; -template struct nlohmann::adl_serializer>; -template struct nlohmann::adl_serializer>; -template struct nlohmann::adl_serializer>; -- cgit v1.2.3