From 9b2b5c5fd5880f35e2e952bb89fc709f4b814364 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 6 Oct 2022 06:13:05 +0200 Subject: a --- magnum-integration | 2 +- magnum-plugins | 2 +- main.cpp | 2 ++ serialize/anim.cpp | 2 +- serialize/magnum-vector.hpp | 41 +++++++++++++++++++++++++++++++++++++++++ serialize/tile-atlas.hpp | 27 +++++++++++++++++++++++++++ serialize/vector.hpp | 41 ----------------------------------------- 7 files changed, 73 insertions(+), 44 deletions(-) create mode 100644 serialize/magnum-vector.hpp create mode 100644 serialize/tile-atlas.hpp delete mode 100644 serialize/vector.hpp diff --git a/magnum-integration b/magnum-integration index 2c273762..8fdf1479 160000 --- a/magnum-integration +++ b/magnum-integration @@ -1 +1 @@ -Subproject commit 2c2737621f3f7bb17bba4e5342f68e68476a5677 +Subproject commit 8fdf1479bf01109d4171ba43496eea9578c120b0 diff --git a/magnum-plugins b/magnum-plugins index 1c9d360a..6da185c7 160000 --- a/magnum-plugins +++ b/magnum-plugins @@ -1 +1 @@ -Subproject commit 1c9d360aa21a3788f32b2d94ad45c39841702a39 +Subproject commit 6da185c7069a224b9d10a8863c4a9148d4d5df42 diff --git a/main.cpp b/main.cpp index f58228c6..208579fb 100644 --- a/main.cpp +++ b/main.cpp @@ -16,6 +16,8 @@ #include #include +#include "serialize/tile-atlas.hpp" //test + namespace Magnum::Examples { template 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