diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-12-02 16:01:28 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-12-02 18:58:28 +0100 |
commit | db50c7a6a38eff251a14d57dcb9ae551ffe3a1d6 (patch) | |
tree | c7d6aba45e63dbbf94ff0f888d00f9da78093bb7 /serialize | |
parent | 08e6c03c2864657ae24faec8dde2389d640aaa23 (diff) |
loader, serialize: use more exception handling
Diffstat (limited to 'serialize')
-rw-r--r-- | serialize/magnum-vector2i.hpp | 5 | ||||
-rw-r--r-- | serialize/scenery.cpp | 11 |
2 files changed, 9 insertions, 7 deletions
diff --git a/serialize/magnum-vector2i.hpp b/serialize/magnum-vector2i.hpp index a57429dc..f63bd130 100644 --- a/serialize/magnum-vector2i.hpp +++ b/serialize/magnum-vector2i.hpp @@ -1,5 +1,5 @@ #pragma once -#include "compat/assert.hpp" +#include "compat/exception.hpp" #include <cstdio> #include <string> #include <Magnum/Math/Vector2.h> @@ -21,6 +21,7 @@ struct adl_serializer<Magnum::Math::Vector2<t>> final } static void from_json(const json& j, Magnum::Math::Vector2<t>& val) { + using namespace floormat; std::string str = j; using type = std::conditional_t<std::is_signed_v<t>, std::intmax_t, std::uintmax_t>; constexpr auto format_string = std::is_signed_v<t> ? "%jd x %jd%n" : "%ju x %ju%n"; @@ -28,7 +29,7 @@ struct adl_serializer<Magnum::Math::Vector2<t>> final int n = 0; int ret = std::sscanf(str.data(), format_string, &x, &y, &n); if (ret != 2 || (std::size_t)n != str.size() || x != (t)x || y != (t)y) - fm_abort("failed to parse Vector2 '%s'", str.data()); + fm_throw("failed to parse Vector2 '{}'"_cf, str); val = { (t)x, (t)y }; } }; diff --git a/serialize/scenery.cpp b/serialize/scenery.cpp index ccc80270..434ffefa 100644 --- a/serialize/scenery.cpp +++ b/serialize/scenery.cpp @@ -1,4 +1,5 @@ #include "scenery.hpp" +#include "compat/exception.hpp" #include "anim-atlas.hpp" #include "compat/assert.hpp" #include "loader/loader.hpp" @@ -42,7 +43,7 @@ auto foo_from_string(StringView str, const T(&map)[N], const char* desc) for (const auto& [value, str2] : map) if (str2 == str) return value; - fm_abort("wrong %s string '%s'", desc, str.data()); + fm_throw("wrong {} string '{}'"_cf, desc, str); } template<std::size_t N, typename T> @@ -51,7 +52,7 @@ StringView foo_to_string(auto type, const T(&map)[N], const char* desc) for (const auto& [type2, str] : map) if (type2 == type) return str; - fm_abort("wrong %s enum '%zu'", desc, (std::size_t)type); + fm_throw("wrong {} enum '{}'"_cf, desc, (std::size_t)type); } } // namespace @@ -101,7 +102,7 @@ void adl_serializer<scenery_proto>::from_json(const json& j, scenery_proto& val) }; StringView atlas_name = j["atlas-name"]; - fm_assert(!atlas_name.isEmpty()); + fm_soft_assert(!atlas_name.isEmpty()); val.atlas = loader.anim_atlas(atlas_name, loader_::SCENERY_PATH); auto& f = val.frame; f = {}; @@ -115,7 +116,7 @@ void adl_serializer<scenery_proto>::from_json(const json& j, scenery_proto& val) switch (type) { default: - fm_abort("unhandled scenery type '%u'", (unsigned)type); + fm_throw("unhandled scenery type '{}'"_cf, (unsigned)type); case scenery_type::generic: f = { scenery::generic, *val.atlas, r, frame, pass, active }; break; @@ -126,7 +127,7 @@ void adl_serializer<scenery_proto>::from_json(const json& j, scenery_proto& val) void adl_serializer<serialized_scenery>::to_json(json& j, const serialized_scenery& val) { - fm_assert(val.proto.atlas); + fm_soft_assert(val.proto.atlas); j = val.proto; const auto name = !val.name.isEmpty() ? StringView{val.name} : val.proto.atlas->name(); j["name"] = name; |