Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
json_utility_nlohmann.cpp
Go to the documentation of this file.
1
3
4#include <fstream>
5#include <iostream>
8
9using namespace std;
10
13 const string file_path
14) {
15 ifstream input{file_path};
16 auto serialized_json = nlohmann::json::parse(input);
17 Deserialize(serialized_json, bpo_points);
18}
19
22 const string file_path
23) {
24 auto serialized_json = Serialize(bpo_points);
25 ExportSerializedJson(serialized_json, file_path);
26}
27
29 nlohmann::json serialized_json,
30 const string file_path
31) {
32 ofstream fout{file_path};
33 fout << setw(4) << serialized_json << endl;
34}
35
36nlohmann::json jsonio::NlohmannJsonUtility::ImportToSerializedJson(const string file_path
37) {
38 ifstream input{file_path};
39 return nlohmann::json::parse(input);
40}
41
43 nlohmann::json serialized_json,
45) {
46 serialized_json.at("black_base").get_to(bpo_points.black_base_);
47 serialized_json.at("red_base_offsets").get_to(bpo_points.red_base_offsets_);
48 serialized_json.at("black_position").get_to(bpo_points.black_position_);
49 serialized_json.at("red_position_offsets").get_to(bpo_points.red_position_offsets_);
50}
51
54) {
55 nlohmann::json j;
56 j["black_base"] = bpo_points.black_base_;
57 j["red_base_offsets"] = bpo_points.red_base_offsets_;
58 j["black_position"] = bpo_points.black_position_;
59 j["red_position_offsets"] = bpo_points.red_position_offsets_;
60 return j;
61}
62
Definitions of classes used for storing piece points in Base Points Offset form.
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(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...
Declaration and implementation of templated portions of jsonio::NlohmannJsonUtility.