DiFfRG
Loading...
Searching...
No Matches
json.hh
Go to the documentation of this file.
1#pragma once
2
3// standard library
4#include <string>
5
6// external libraries
7#include <boost/json.hpp>
8
9namespace DiFfRG
10{
11 namespace json = boost::json;
12
19 {
20 public:
26
32 JSONValue(const std::string filename);
33
39 JSONValue(const json::value &v);
40
44 json::value &operator()();
45
49 operator json::value() const;
50
54 bool operator==(const JSONValue &other) const;
55
62 double get_double(const std::string &key) const;
63
70 int get_int(const std::string &key) const;
71
78 uint get_uint(const std::string &key) const;
79
86 std::string get_string(const std::string &key) const;
87
94 bool get_bool(const std::string &key) const;
95
103 double get_double(const std::string &key, const double def) const;
104
112 int get_int(const std::string &key, const int def) const;
113
121 uint get_uint(const std::string &key, const uint def) const;
122
130 std::string get_string(const std::string &key, const std::string &def) const;
131
139 bool get_bool(const std::string &key, const bool def) const;
140
147 void set_double(const std::string &key, double value);
148
155 void set_int(const std::string &key, int value);
156
163 void set_uint(const std::string &key, uint value);
164
171 void set_string(const std::string &key, const std::string &value);
172
179 void set_bool(const std::string &key, bool value);
180
184 void print(std::ostream &os) const;
185
186 private:
187 json::value value;
188
189 void pretty_print(std::ostream &os, json::value const &v, std::string *indent = nullptr) const;
190 };
191} // namespace DiFfRG
A wrapper around the boost json value class.
Definition json.hh:19
std::string get_string(const std::string &key, const std::string &def) const
Get the value of a key in the json object, with a default value.
bool operator==(const JSONValue &other) const
Equality operator. Checks all values in the json object to be equal.
JSONValue(const std::string filename)
Construct a new JSONValue object from a json file.
JSONValue()
Construct an empty JSONValue object.
void set_double(const std::string &key, double value)
Set the value of a key in the json object.
void print(std::ostream &os) const
Pretty-print the json value to a stream.
void set_bool(const std::string &key, bool value)
Set the value of a key in the json object.
void set_string(const std::string &key, const std::string &value)
Set the value of a key in the json object.
void set_int(const std::string &key, int value)
Set the value of a key in the json object.
int get_int(const std::string &key, const int def) const
Get the value of a key in the json object, with a default value.
json::value & operator()()
The call operator gives access to the wrapped json value.
json::value value
Definition json.hh:187
void pretty_print(std::ostream &os, json::value const &v, std::string *indent=nullptr) const
double get_double(const std::string &key) const
Get the value of a key in the json object.
std::string get_string(const std::string &key) const
Get the value of a key in the json object.
bool get_bool(const std::string &key) const
Get the value of a key in the json object.
bool get_bool(const std::string &key, const bool def) const
Get the value of a key in the json object, with a default value.
int get_int(const std::string &key) const
Get the value of a key in the json object.
uint get_uint(const std::string &key, const uint def) const
Get the value of a key in the json object, with a default value.
uint get_uint(const std::string &key) const
Get the value of a key in the json object.
void set_uint(const std::string &key, uint value)
Set the value of a key in the json object.
double get_double(const std::string &key, const double def) const
Get the value of a key in the json object, with a default value.
JSONValue(const json::value &v)
Construct a new JSONValue object.
Definition complex_math.hh:14
unsigned int uint
Definition utils.hh:22