From 1e8d16fe10917664f9520008f224f19692c3a668 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 15 Oct 2022 21:51:33 +0200 Subject: a --- serialize/json-helper.hpp | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'serialize') diff --git a/serialize/json-helper.hpp b/serialize/json-helper.hpp index b8e290b7..b1502295 100644 --- a/serialize/json-helper.hpp +++ b/serialize/json-helper.hpp @@ -9,46 +9,36 @@ struct json_helper final { template [[nodiscard]] - static std::tuple from_json(const std::filesystem::path& pathname); + static t from_json(const std::filesystem::path& pathname); template - [[nodiscard]] - static bool to_json(const t& self, const std::filesystem::path& pathname); + static void to_json(const t& self, const std::filesystem::path& pathname); }; template -std::tuple json_helper::from_json(const std::filesystem::path& pathname) { +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); - try { - s.open(pathname, std::ios_base::in); - } catch (const std::ios::failure& e) { - Error{} << "failed to open" << pathname << "for reading:" << e.what(); - return {}; - } + s.open(pathname, std::ios_base::in); t ret; nlohmann::json j; s >> j; ret = j; - return { std::move(ret), true }; + return ret; } template -bool json_helper::to_json(const t& self, const std::filesystem::path& pathname) { +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); - try { - s.open(pathname, std::ios_base::out | std::ios_base::trunc); - } catch (const std::ios::failure& e) { - Error{} << "failed to open" << pathname << "for writing:" << e.what(); - return false; - } + s.open(pathname, std::ios_base::out | std::ios_base::trunc); s << j.dump(4); s << '\n'; s.flush(); - return true; } -- cgit v1.2.3