From 8dfa3d885b34f9d9cc20b47890268cedb9fb217f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 10 Nov 2022 16:04:57 +0100 Subject: flush it --- serialize/json-helper.cpp | 15 +++++++-------- serialize/json-helper.hpp | 15 +++++++-------- 2 files changed, 14 insertions(+), 16 deletions(-) (limited to 'serialize') diff --git a/serialize/json-helper.cpp b/serialize/json-helper.cpp index dae3ad96..538bcdcb 100644 --- a/serialize/json-helper.cpp +++ b/serialize/json-helper.cpp @@ -1,28 +1,27 @@ #include "json-helper.hpp" #include -#include namespace floormat { -template -static T open_stream(const std::remove_cvref_t

& filename) +template +static T open_stream(StringView filename) { T s; s.exceptions(s.exceptions() | std::ios::failbit | std::ios::badbit); - s.open(filename, open_mode); + s.open(filename, mode); return s; } -auto json_helper::from_json_(const fspath& pathname) -> json +auto json_helper::from_json_(StringView filename) -> json { json j; - open_stream(pathname) >> j; + open_stream(filename) >> j; return j; } -void json_helper::to_json_(const json& j, const fspath& pathname, int indent) +void json_helper::to_json_(const json& j, StringView filename, int indent) { - (open_stream(pathname) << j.dump(indent, '\t') << '\n').flush(); + (open_stream(filename) << j.dump(indent, '\t') << '\n').flush(); } } // namespace floormat diff --git a/serialize/json-helper.hpp b/serialize/json-helper.hpp index e0e2c0ca..90ce2e9a 100644 --- a/serialize/json-helper.hpp +++ b/serialize/json-helper.hpp @@ -1,20 +1,19 @@ #pragma once #include -#include +#include namespace floormat { struct json_helper final { using json = nlohmann::json; - using fspath = std::filesystem::path; - template static T from_json(const fspath& pathname); - template static void to_json(const T& self, const fspath& pathname, int indent = 1); - static json from_json_(const fspath& pathname); - static void to_json_(const json& j, const fspath& pathname, int indent); + template static T from_json(StringView pathname); + template static void to_json(const T& self, StringView pathname, int indent = 1); + static json from_json_(StringView pathname); + static void to_json_(const json& j, StringView pathname, int indent); }; -template T json_helper::from_json(const fspath& pathname) { return from_json_(pathname); } -template void json_helper::to_json(const T& self, const fspath& pathname, int indent) { to_json_(json(self), pathname, indent); } +template T json_helper::from_json(StringView pathname) { return from_json_(pathname); } +template void json_helper::to_json(const T& self, StringView pathname, int indent) { to_json_(json(self), pathname, indent); } } // namespace floormat -- cgit v1.2.3