From 9b2b5c5fd5880f35e2e952bb89fc709f4b814364 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 6 Oct 2022 06:13:05 +0200 Subject: a --- serialize/anim.cpp | 2 +- serialize/magnum-vector.hpp | 41 +++++++++++++++++++++++++++++++++++++++++ serialize/tile-atlas.hpp | 27 +++++++++++++++++++++++++++ serialize/vector.hpp | 41 ----------------------------------------- 4 files changed, 69 insertions(+), 42 deletions(-) create mode 100644 serialize/magnum-vector.hpp create mode 100644 serialize/tile-atlas.hpp delete mode 100644 serialize/vector.hpp (limited to 'serialize') diff --git a/serialize/anim.cpp b/serialize/anim.cpp index c65c24a6..78c871a8 100644 --- a/serialize/anim.cpp +++ b/serialize/anim.cpp @@ -1,4 +1,4 @@ -#include "serialize/vector.hpp" +#include "serialize/magnum-vector.hpp" #include "serialize/helper.hpp" #include "serialize/anim.hpp" diff --git a/serialize/magnum-vector.hpp b/serialize/magnum-vector.hpp new file mode 100644 index 00000000..39924a9b --- /dev/null +++ b/serialize/magnum-vector.hpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include + +namespace nlohmann { + +template +struct adl_serializer> final { + static void to_json(json& j, const Magnum::Math::Vector2& x); + static void from_json(const json& j, Magnum::Math::Vector2& x); +}; + +template +void adl_serializer>::to_json(json& j, const Magnum::Math::Vector2& val) +{ + char buf[64]; + snprintf(buf, sizeof(buf), "%d x %d", val[0], val[1]); + j = buf; +} + +template +void adl_serializer>::from_json(const json& j, Magnum::Math::Vector2& val) +{ + std::string str = j; + int x = 0, y = 0, n = 0; + int ret = std::sscanf(str.c_str(), "%d x %d%n", &x, &y, &n); + if (ret != 2 || (std::size_t)n != str.size()) + { + std::string msg; msg.reserve(64 + str.size()); + msg += "failed to parse string '"; + msg += str; + msg += "' as Magnum::Vector2i"; + throw std::invalid_argument(msg); + } + val = { x, y }; +} + +} // namespace nlohmann diff --git a/serialize/tile-atlas.hpp b/serialize/tile-atlas.hpp new file mode 100644 index 00000000..af279251 --- /dev/null +++ b/serialize/tile-atlas.hpp @@ -0,0 +1,27 @@ +#pragma once +#include "../tile-atlas.hpp" +#include + +namespace nlohmann { + +template<> +struct adl_serializer final { + static void to_json(json& j, const Magnum::Examples::tile_atlas& x); + static void from_json(const json& j, Magnum::Examples::tile_atlas& x); +}; + +void adl_serializer::to_json(json& j, const Magnum::Examples::tile_atlas& x) +{ +} + +void adl_serializer::from_json(const json& j, Magnum::Examples::tile_atlas& x) +{ +} + +} // namespace nlohmann + +namespace Magnum::Examples::Serialize { + + + +} // namespace Magnum::Examples::Serialize diff --git a/serialize/vector.hpp b/serialize/vector.hpp deleted file mode 100644 index 39924a9b..00000000 --- a/serialize/vector.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include -#include -#include - -namespace nlohmann { - -template -struct adl_serializer> final { - static void to_json(json& j, const Magnum::Math::Vector2& x); - static void from_json(const json& j, Magnum::Math::Vector2& x); -}; - -template -void adl_serializer>::to_json(json& j, const Magnum::Math::Vector2& val) -{ - char buf[64]; - snprintf(buf, sizeof(buf), "%d x %d", val[0], val[1]); - j = buf; -} - -template -void adl_serializer>::from_json(const json& j, Magnum::Math::Vector2& val) -{ - std::string str = j; - int x = 0, y = 0, n = 0; - int ret = std::sscanf(str.c_str(), "%d x %d%n", &x, &y, &n); - if (ret != 2 || (std::size_t)n != str.size()) - { - std::string msg; msg.reserve(64 + str.size()); - msg += "failed to parse string '"; - msg += str; - msg += "' as Magnum::Vector2i"; - throw std::invalid_argument(msg); - } - val = { x, y }; -} - -} // namespace nlohmann -- cgit v1.2.3