From c7caf58e53975ad0f1d2da88708697c7b1bb5c32 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 9 Feb 2024 23:46:45 +0100 Subject: loader, serialize: clean up a bit --- serialize/anim.cpp | 1 + serialize/ground-atlas.cpp | 1 + serialize/magnum-vector.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'serialize') diff --git a/serialize/anim.cpp b/serialize/anim.cpp index 4b5dee77..cd1f5e5c 100644 --- a/serialize/anim.cpp +++ b/serialize/anim.cpp @@ -152,6 +152,7 @@ void adl_serializer::from_json(const json& j, anim_scale& val) { fm_soft_assert(j.is_array()); fm_soft_assert(j.size() == 2); + val = {}; StringView type = j[0]; if (type == "factor"_s) { diff --git a/serialize/ground-atlas.cpp b/serialize/ground-atlas.cpp index 11ef40ef..6844019c 100644 --- a/serialize/ground-atlas.cpp +++ b/serialize/ground-atlas.cpp @@ -26,6 +26,7 @@ void adl_serializer::to_json(json& j, const ground_def& x) void adl_serializer::from_json(const json& j, ground_def& val) { using nlohmann::from_json; + val = {}; val.name = j["name"]; val.size = j["size"]; if (j.contains("pass-mode")) diff --git a/serialize/magnum-vector.cpp b/serialize/magnum-vector.cpp index 2a31877e..8e9bfaeb 100644 --- a/serialize/magnum-vector.cpp +++ b/serialize/magnum-vector.cpp @@ -1,6 +1,7 @@ #include "magnum-vector.hpp" #include "compat/format.hpp" #include "compat/exception.hpp" +#include "corrade-string.hpp" #include #include #include @@ -10,12 +11,12 @@ namespace floormat::Serialize { namespace { -[[noreturn]] void throw_failed_to_parse_vector2(const std::string& str) +[[noreturn]] void throw_failed_to_parse_vector2(StringView str) { fm_throw("failed to parse Vector2 '{}'"_cf, str); } -[[noreturn]] void throw_vector2_overflow(const std::string& str) +[[noreturn]] void throw_vector2_overflow(StringView str) { fm_throw("numeric overflow in Vector2 '{}'"_cf, str); } @@ -63,7 +64,7 @@ struct vec2_serializer static void from_json(const json& j, Vector<2, T>& val) { using namespace floormat; - std::string str = j; + StringView 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; -- cgit v1.2.3