21 #include <rapidjson/istreamwrapper.h> 22 #include <rapidjson/ostreamwrapper.h> 23 #include <rapidjson/writer.h> 26 namespace json_utils {
30 const long unsigned int& value,
31 rapidjson::Document::AllocatorType& allocator) {
32 json_val.SetUint64(value);
34 void get_value(
const rapidjson::Value& json_val,
long unsigned int& value) {
35 CHECK(json_val.IsUint64());
36 value = json_val.GetUint64();
41 rapidjson::Document::AllocatorType& allocator) {
42 json_val.SetInt(value);
45 void get_value(
const rapidjson::Value& json_val,
int& value) {
46 CHECK(json_val.IsInt());
47 value = json_val.GetInt();
51 const std::string& value,
52 rapidjson::Document::AllocatorType& allocator) {
53 json_val.SetString(value, allocator);
56 void get_value(
const rapidjson::Value& json_val, std::string& value) {
57 CHECK(json_val.IsString());
58 value = json_val.GetString();
62 std::ifstream ifs(file_path);
64 throw std::runtime_error{
"Error trying to open file \"" + file_path +
65 "\". The error was: " + std::strerror(errno)};
68 rapidjson::IStreamWrapper isw(ifs);
69 rapidjson::Document d;
74 void write_to_file(
const rapidjson::Document& document,
const std::string& filepath) {
75 std::ofstream ofs(filepath);
77 throw std::runtime_error{
"Error trying to create file \"" + filepath +
78 "\". The error was: " + std::strerror(errno)};
80 rapidjson::OStreamWrapper osw(ofs);
81 rapidjson::Writer<rapidjson::OStreamWrapper> writer(osw);
82 document.Accept(writer);
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)
rapidjson::Document read_from_file(const std::string &file_path)
void write_to_file(const rapidjson::Document &document, const std::string &filepath)