#include "json-helper.hpp" #include #include namespace floormat { template static T open_stream(const std::remove_cvref_t

& filename) { T s; s.exceptions(s.exceptions() | std::ios::failbit | std::ios::badbit); s.open(filename, open_mode); return s; } auto json_helper::from_json_(const fspath& pathname) -> json { json j; open_stream(pathname) >> j; return j; } void json_helper::to_json_(const json& j, const fspath& pathname, int indent) { (open_stream(pathname) << j.dump(indent, '\t') << '\n').flush(); } #define FORMAT cbor #define JOIN2(prefix, fmt) prefix ## fmt #define JOIN(prefix, fmt) JOIN2(prefix, fmt) #define FROM JOIN(from_, FORMAT) #define TO JOIN(to_, FORMAT) auto json_helper::from_binary_(const fspath& pathname) -> json { return json::FROM(open_stream(pathname)); } void json_helper::to_binary_(const json& j, const fspath& pathname) { auto s = open_stream(pathname); json::TO(j, s); s.flush(); } } // namespace floormat