/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/common/config_tree.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/common/config_tree.hh Source File
DiFfRG
Discretization Framework for functional Renormalization Group flows
config_tree.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
13 namespace internal
14 {
20 bool has_toml_extension(const std::string &filename);
21 } // namespace internal
22
32 {
33 public:
39
47 ConfigTree(const std::string filename);
48
57 ConfigTree(const char *filename);
58
64 ConfigTree(const json::value &v);
65
71 static ConfigTree from_json_string(const std::string &content);
72
78 static ConfigTree from_toml_string(const std::string &content);
79
83 json::value &operator()();
84
88 operator json::value() const;
89
93 bool operator==(const ConfigTree &other) const;
94
103 double get_double(const std::string &key) const;
104
111 int get_int(const std::string &key) const;
112
119 uint get_uint(const std::string &key) const;
120
127 std::string get_string(const std::string &key) const;
128
135 bool get_bool(const std::string &key) const;
136
146 double get_double(const std::string &key, const double def) const;
147
155 int get_int(const std::string &key, const int def) const;
156
164 uint get_uint(const std::string &key, const uint def) const;
165
173 std::string get_string(const std::string &key, const std::string &def) const;
174
182 bool get_bool(const std::string &key, const bool def) const;
183
189 bool contains(const std::string &key) const;
190
203 double get_double_or_warn(const std::string &key, const double def) const;
204 int get_int_or_warn(const std::string &key, const int def) const;
205 uint get_uint_or_warn(const std::string &key, const uint def) const;
206 std::string get_string_or_warn(const std::string &key, const std::string &def) const;
207 bool get_bool_or_warn(const std::string &key, const bool def) const;
216 void set_double(const std::string &key, double value);
217
224 void set_int(const std::string &key, int value);
225
232 void set_uint(const std::string &key, uint value);
233
240 void set_string(const std::string &key, const std::string &value);
241
248 void set_bool(const std::string &key, bool value);
249
253 void print(std::ostream &os) const;
254
258 void print_toml(std::ostream &os) const;
259
260 private:
261 json::value value;
262
263 void pretty_print(std::ostream &os, json::value const &v, std::string *indent = nullptr) const;
264 };
265
269 using JSONValue [[deprecated("JSONValue was renamed. Use DiFfRG::ConfigTree instead.")]] = ConfigTree;
270} // namespace DiFfRG
A hierarchical configuration tree, readable from JSON and TOML files.
Definition config_tree.hh:32
void set_bool(const std::string &key, bool value)
Set the value of a key in the configuration object.
bool contains(const std::string &key) const
Whether the configuration object has an entry at the given key.
int get_int(const std::string &key) const
Get the value of a key in the configuration object.
bool get_bool_or_warn(const std::string &key, const bool def) const
bool get_bool(const std::string &key, const bool def) const
Get the value of a key in the configuration object, with a default value.
ConfigTree(const std::string filename)
Construct a new ConfigTree object from a file.
void set_double(const std::string &key, double value)
Set the value of a key in the configuration object.
void print_toml(std::ostream &os) const
Print the configuration tree as TOML to a stream.
void set_int(const std::string &key, int value)
Set the value of a key in the configuration object.
double get_double_or_warn(const std::string &key, const double def) const
ConfigTree(const char *filename)
Construct a new ConfigTree object from a file.
json::value value
Definition config_tree.hh:261
int get_int_or_warn(const std::string &key, const int def) const
uint get_uint(const std::string &key, const uint def) const
Get the value of a key in the configuration object, with a default value.
bool operator==(const ConfigTree &other) const
Equality operator. Checks all values in the configuration object to be equal.
ConfigTree(const json::value &v)
Construct a new ConfigTree object.
uint get_uint(const std::string &key) const
Get the value of a key in the configuration object.
static ConfigTree from_json_string(const std::string &content)
Construct a ConfigTree from the contents of a JSON document.
void print(std::ostream &os) const
Pretty-print the configuration tree as JSON to a stream.
void set_uint(const std::string &key, uint value)
Set the value of a key in the configuration object.
uint get_uint_or_warn(const std::string &key, const uint def) const
std::string get_string(const std::string &key) const
Get the value of a key in the configuration object.
void set_string(const std::string &key, const std::string &value)
Set the value of a key in the configuration object.
ConfigTree()
Construct an empty ConfigTree object.
std::string get_string_or_warn(const std::string &key, const std::string &def) const
double get_double(const std::string &key) const
Get the value of a key in the configuration object.
bool get_bool(const std::string &key) const
Get the value of a key in the configuration object.
std::string get_string(const std::string &key, const std::string &def) const
Get the value of a key in the configuration object, with a default value.
json::value & operator()()
The call operator gives access to the wrapped json value.
int get_int(const std::string &key, const int def) const
Get the value of a key in the configuration object, with a default value.
double get_double(const std::string &key, const double def) const
Get the value of a key in the configuration object, with a default value.
static ConfigTree from_toml_string(const std::string &content)
Construct a ConfigTree from the contents of a TOML document.
void pretty_print(std::ostream &os, json::value const &v, std::string *indent=nullptr) const
bool has_toml_extension(const std::string &filename)
Whether a file name denotes a TOML file, i.e. ends in ".toml" or ".tml".
Definition complex_math.hh:10
unsigned int uint
Definition utils.hh:24