#pragma once #include #include #include #include #include struct json_helper final { template [[nodiscard]] static t from_json(const std::filesystem::path& pathname); template static void to_json(const t& self, const std::filesystem::path& pathname); }; template t json_helper::from_json(const std::filesystem::path& pathname) { using Corrade::Utility::Error; std::ifstream s; s.exceptions(s.exceptions() | std::ios::failbit | std::ios::badbit); s.open(pathname, std::ios_base::in); t ret; nlohmann::json j; s >> j; ret = j; return ret; } template void json_helper::to_json(const t& self, const std::filesystem::path& pathname) { using Corrade::Utility::Error; nlohmann::json j = self; std::ofstream s; s.exceptions(s.exceptions() | std::ios::failbit | std::ios::badbit); s.open(pathname, std::ios_base::out | std::ios_base::trunc); s << j.dump(4); s << '\n'; s.flush(); }