Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
json_utility_nlohmann.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <fstream>
8#include <nlohmann/json.hpp>
10#include <string>
11
13namespace jsonio {
14
17class NlohmannJsonUtility : public JsonUtility<NlohmannJsonUtility> {
18public:
19 template <typename T>
20 void ImplementImport(T &object, const std::string file_path) {
21 nlohmann::json j = ImportToSerializedJson(file_path);
22 object = j.get<T>();
23 };
24
25 template <typename T>
26 void ImplementExport(T &object, const std::string file_path) {
27 nlohmann::json j;
28 j = object;
29 ExportSerializedJson(j, file_path);
30 };
31
32 void ImplementImport(piecepoints::BPOPointsSKeys &bpo_points, const std::string file_path);
33 void ImplementExport(piecepoints::BPOPointsSKeys &bpo_points, const std::string file_path);
34
35private:
36 void ExportSerializedJson(nlohmann::json serialized_json, const std::string file_path);
37 nlohmann::json ImportToSerializedJson(const std::string file_path);
38 void Deserialize(
39 nlohmann::json serialized_json,
41 );
42 nlohmann::json Serialize(piecepoints::BPOPointsSKeys &bpo_points);
43};
44
45} // namespace jsonio
Definitions of classes used for storing piece points in Base Points Offset form.
CRTP interface with methods of importing / exporting objects from / to json files (concrete example =...
Implements JsonUtility interface; imports / exports objects from / to json files using the Nlohmann j...
void ImplementExport(T &object, const std::string file_path)
nlohmann::json Serialize(piecepoints::BPOPointsSKeys &bpo_points)
nlohmann::json ImportToSerializedJson(const std::string file_path)
void ExportSerializedJson(nlohmann::json serialized_json, const std::string file_path)
void ImplementImport(piecepoints::BPOPointsSKeys &bpo_points, const std::string file_path)
void ImplementExport(piecepoints::BPOPointsSKeys &bpo_points, const std::string file_path)
void ImplementImport(T &object, const std::string file_path)
void Deserialize(nlohmann::json serialized_json, piecepoints::BPOPointsSKeys &bpo_points)
Piece Points spec in "Base Points Offset" form with string keys in member unordered_map objects for e...
Definition of JsonUtility CRTP interface.
Importing / exporting objects from / to json files.