19 #include <rapidjson/document.h>
23 namespace foreign_storage {
26 namespace json_utils {
32 const std::string&
name,
33 rapidjson::Document::AllocatorType& allocator);
37 const std::string&
name);
41 void set_value(rapidjson::Value& json_val,
42 const long unsigned int& value,
43 rapidjson::Document::AllocatorType& allocator);
44 void get_value(
const rapidjson::Value& json_val,
long unsigned int& value);
46 void set_value(rapidjson::Value& json_val,
48 rapidjson::Document::AllocatorType& allocator);
49 void get_value(
const rapidjson::Value& json_val,
int& value);
51 void set_value(rapidjson::Value& json_val,
52 const std::string& value,
53 rapidjson::Document::AllocatorType& allocator);
54 void get_value(
const rapidjson::Value& json_val, std::string& value);
59 const std::vector<T>& vector_value,
60 rapidjson::Document::AllocatorType& allocator) {
62 for (
const auto& value : vector_value) {
63 rapidjson::Value json_obj;
65 json_val.PushBack(json_obj, allocator);
70 void get_value(
const rapidjson::Value& json_val, std::vector<T>& vector_value) {
71 CHECK(json_val.IsArray());
72 CHECK(vector_value.size() == 0);
73 for (
const auto& json_obj : json_val.GetArray()) {
76 vector_value.push_back(val);
81 template <
class T,
class V>
83 const std::map<T, V>& map_value,
84 rapidjson::Document::AllocatorType& allocator) {
86 for (
const auto& pair : map_value) {
87 rapidjson::Value pair_obj;
91 json_val.PushBack(pair_obj, allocator);
95 template <
class T,
class V>
96 void get_value(
const rapidjson::Value& json_val, std::map<T, V>& map_value) {
97 CHECK(json_val.IsArray());
98 CHECK(map_value.size() == 0);
99 for (
const auto& json_obj : json_val.GetArray()) {
100 CHECK(json_obj.IsObject());
105 map_value[key] = value;
113 const std::string&
name,
114 rapidjson::Document::AllocatorType& allocator) {
115 CHECK(
object.IsObject());
116 CHECK(!
object.HasMember(name));
117 rapidjson::Value json_val;
119 rapidjson::Value json_name;
120 json_name.SetString(name, allocator);
121 object.AddMember(json_name, json_val, allocator);
128 const std::string&
name) {
129 CHECK(
object.IsObject());
130 CHECK(
object.HasMember(name));
138 void write_to_file(
const rapidjson::Document& document,
const std::string& file_path);
void set_value(rapidjson::Value &json_val, const long unsigned int &value, rapidjson::Document::AllocatorType &allocator)
void get_value(const rapidjson::Value &json_val, long unsigned int &value)
void get_value_from_object(const rapidjson::Value &object, T &value, const std::string &name)
rapidjson::Document read_from_file(const std::string &file_path)
void add_value_to_object(rapidjson::Value &object, const T &value, const std::string &name, rapidjson::Document::AllocatorType &allocator)
void write_to_file(const rapidjson::Document &document, const std::string &filepath)