summaryrefslogtreecommitdiffhomepage
path: root/serialize/json-helper.hpp
blob: e0e2c0cac9767417aaee09c1ce8adf3450f01fb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once
#include <nlohmann/json.hpp>
#include <filesystem>

namespace floormat {

struct json_helper final {
    using json = nlohmann::json;
    using fspath = std::filesystem::path;

    template<typename T> static T from_json(const fspath& pathname);
    template<typename T> 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<typename T> T json_helper::from_json(const fspath& pathname) { return from_json_(pathname); }
template<typename T> void json_helper::to_json(const T& self, const fspath& pathname, int indent) { to_json_(json(self), pathname, indent); }

} // namespace floormat