ConfigTree Class Reference#
|
DiFfRG
Discretization Framework for functional Renormalization Group flows
|
A hierarchical configuration tree, readable from JSON and TOML files. More...
#include <config_tree.hh>
Public Member Functions | |||||
| ConfigTree () | |||||
| Construct an empty ConfigTree object. | |||||
| ConfigTree (const std::string filename) | |||||
| Construct a new ConfigTree object from a file. | |||||
| ConfigTree (const char *filename) | |||||
| Construct a new ConfigTree object from a file. | |||||
| ConfigTree (const json::value &v) | |||||
| Construct a new ConfigTree object. | |||||
| json::value & | operator() () | ||||
| The call operator gives access to the wrapped json value. | |||||
| operator json::value () const | |||||
| The call operator gives access to the wrapped json value. | |||||
| bool | operator== (const ConfigTree &other) const | ||||
| Equality operator. Checks all values in the configuration object to be equal. | |||||
| double | get_double (const std::string &key) const | ||||
| Get the value of a key in the configuration object. | |||||
| int | get_int (const std::string &key) const | ||||
| Get the value of a key in the configuration object. | |||||
| uint | get_uint (const std::string &key) const | ||||
| Get the value of a key in the configuration object. | |||||
| std::string | get_string (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. | |||||
| 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. | |||||
| 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. | |||||
| 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. | |||||
| 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. | |||||
| 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. | |||||
| bool | contains (const std::string &key) const | ||||
| Whether the configuration object has an entry at the given key. | |||||
| void | set_double (const std::string &key, double value) | ||||
| Set the value of a key in the configuration object. | |||||
| void | set_int (const std::string &key, int value) | ||||
| Set the value of a key in the configuration object. | |||||
| void | set_uint (const std::string &key, uint value) | ||||
| Set 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. | |||||
| void | set_bool (const std::string &key, bool value) | ||||
| Set the value of a key in the configuration object. | |||||
| void | print (std::ostream &os) const | ||||
| Pretty-print the configuration tree as JSON to a stream. | |||||
| void | print_toml (std::ostream &os) const | ||||
| Print the configuration tree as TOML to a stream. | |||||
Defaulted getters that warn when the default is used. | |||||
These behave exactly like the two-argument getters above, but additionally print a warning to stderr (once per key and process) whenever the fallback is taken. They are meant for parameters whose default is a guess rather than a safe choice: quadrature orders, solver tolerances, grids, the cutoff scale. A run that silently takes such a default is likely producing results the user did not intend.
| |||||
| double | get_double_or_warn (const std::string &key, const double def) const | ||||
| int | get_int_or_warn (const std::string &key, const int def) const | ||||
| uint | get_uint_or_warn (const std::string &key, const uint def) const | ||||
| std::string | get_string_or_warn (const std::string &key, const std::string &def) const | ||||
| bool | get_bool_or_warn (const std::string &key, const bool def) const | ||||
Static Public Member Functions | |
| static ConfigTree | from_json_string (const std::string &content) |
| Construct a ConfigTree from the contents of a JSON document. | |
| static ConfigTree | from_toml_string (const std::string &content) |
| Construct a ConfigTree from the contents of a TOML document. | |
Private Member Functions | |
| void | pretty_print (std::ostream &os, json::value const &v, std::string *indent=nullptr) const |
Private Attributes | |
| json::value | value |
Detailed Description
A hierarchical configuration tree, readable from JSON and TOML files.
This class allows to easily access and modify the values stored in a configuration object. Internally the tree is held as a boost json value, independently of the file format it was read from; keys are therefore always JSON pointers of the form "/category/subcategory/.../key".
Constructor & Destructor Documentation
◆ ConfigTree() [1/4]
| DiFfRG::ConfigTree::ConfigTree | ( | ) |
Construct an empty ConfigTree object.
◆ ConfigTree() [2/4]
| DiFfRG::ConfigTree::ConfigTree | ( | const std::string | filename | ) |
Construct a new ConfigTree object from a file.
Files ending in ".toml" or ".tml" are read as TOML, everything else as JSON.
- Parameters
-
filename The name of the file to read.
◆ ConfigTree() [3/4]
| DiFfRG::ConfigTree::ConfigTree | ( | const char * | filename | ) |
Construct a new ConfigTree object from a file.
Without this overload a string literal is ambiguous between the file name and the json value constructor, as boost json values are constructible from a char pointer.
- Parameters
-
filename The name of the file to read.
◆ ConfigTree() [4/4]
| DiFfRG::ConfigTree::ConfigTree | ( | const json::value & | v | ) |
Construct a new ConfigTree object.
- Parameters
-
v The json value to wrap.
Member Function Documentation
◆ contains()
| bool DiFfRG::ConfigTree::contains | ( | const std::string & | key | ) | const |
Whether the configuration object has an entry at the given key.
- Parameters
-
key The key to look for. Format: "/category/subcategory/.../key".
◆ from_json_string()
|
static |
Construct a ConfigTree from the contents of a JSON document.
- Parameters
-
content The JSON document.
◆ from_toml_string()
|
static |
Construct a ConfigTree from the contents of a TOML document.
- Parameters
-
content The TOML document.
◆ get_bool() [1/2]
| bool DiFfRG::ConfigTree::get_bool | ( | const std::string & | key | ) | const |
Get the value of a key in the configuration object.
- Parameters
-
key The key to get the value for. Format: "/category/subcategory/.../key".
- Returns
- bool The value.
◆ get_bool() [2/2]
| bool DiFfRG::ConfigTree::get_bool | ( | const std::string & | key, |
| const bool | def ) const |
Get the value of a key in the configuration object, with a default value.
- Parameters
-
key The key to get the value for. Format: "/category/subcategory/.../key". def The default value to return if the key is not found.
- Returns
- bool The value.
◆ get_bool_or_warn()
| bool DiFfRG::ConfigTree::get_bool_or_warn | ( | const std::string & | key, |
| const bool | def ) const |
◆ get_double() [1/2]
| double DiFfRG::ConfigTree::get_double | ( | const std::string & | key | ) | const |
Get the value of a key in the configuration object.
Integer entries are accepted and converted, so that both 2 and 2.0 can be read.
- Parameters
-
key The key to get the value for. Format: "/category/subcategory/.../key".
- Returns
- double The value.
◆ get_double() [2/2]
| double DiFfRG::ConfigTree::get_double | ( | const std::string & | key, |
| const double | def ) const |
Get the value of a key in the configuration object, with a default value.
Integer entries are accepted and converted, so that both 2 and 2.0 can be read.
- Parameters
-
key The key to get the value for. Format: "/category/subcategory/.../key". def The default value to return if the key is not found.
- Returns
- double The value.
◆ get_double_or_warn()
| double DiFfRG::ConfigTree::get_double_or_warn | ( | const std::string & | key, |
| const double | def ) const |
◆ get_int() [1/2]
| int DiFfRG::ConfigTree::get_int | ( | const std::string & | key | ) | const |
Get the value of a key in the configuration object.
- Parameters
-
key The key to get the value for. Format: "/category/subcategory/.../key".
- Returns
- int The value.
◆ get_int() [2/2]
| int DiFfRG::ConfigTree::get_int | ( | const std::string & | key, |
| const int | def ) const |
Get the value of a key in the configuration object, with a default value.
- Parameters
-
key The key to get the value for. Format: "/category/subcategory/.../key". def The default value to return if the key is not found.
- Returns
- int The value.
◆ get_int_or_warn()
| int DiFfRG::ConfigTree::get_int_or_warn | ( | const std::string & | key, |
| const int | def ) const |
◆ get_string() [1/2]
| std::string DiFfRG::ConfigTree::get_string | ( | const std::string & | key | ) | const |
Get the value of a key in the configuration object.
- Parameters
-
key The key to get the value for. Format: "/category/subcategory/.../key".
- Returns
- std::string The value.
◆ get_string() [2/2]
| std::string DiFfRG::ConfigTree::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.
- Parameters
-
key The key to get the value for. Format: "/category/subcategory/.../key". def The default value to return if the key is not found.
- Returns
- std::string The value.
◆ get_string_or_warn()
| std::string DiFfRG::ConfigTree::get_string_or_warn | ( | const std::string & | key, |
| const std::string & | def ) const |
◆ get_uint() [1/2]
| uint DiFfRG::ConfigTree::get_uint | ( | const std::string & | key | ) | const |
Get the value of a key in the configuration object.
- Parameters
-
key The key to get the value for. Format: "/category/subcategory/.../key".
- Returns
- uint The value.
◆ get_uint() [2/2]
Get the value of a key in the configuration object, with a default value.
- Parameters
-
key The key to get the value for. Format: "/category/subcategory/.../key". def The default value to return if the key is not found.
- Returns
- uint The value.
◆ get_uint_or_warn()
◆ operator json::value()
| DiFfRG::ConfigTree::operator json::value | ( | ) | const |
The call operator gives access to the wrapped json value.
◆ operator()()
| json::value & DiFfRG::ConfigTree::operator() | ( | ) |
The call operator gives access to the wrapped json value.
◆ operator==()
| bool DiFfRG::ConfigTree::operator== | ( | const ConfigTree & | other | ) | const |
Equality operator. Checks all values in the configuration object to be equal.
◆ pretty_print()
|
private |
◆ print()
| void DiFfRG::ConfigTree::print | ( | std::ostream & | os | ) | const |
Pretty-print the configuration tree as JSON to a stream.
◆ print_toml()
| void DiFfRG::ConfigTree::print_toml | ( | std::ostream & | os | ) | const |
Print the configuration tree as TOML to a stream.
◆ set_bool()
| void DiFfRG::ConfigTree::set_bool | ( | const std::string & | key, |
| bool | value ) |
Set the value of a key in the configuration object.
- Parameters
-
key The key to set the value for. Format: "/category/subcategory/.../key". value The value to set.
◆ set_double()
| void DiFfRG::ConfigTree::set_double | ( | const std::string & | key, |
| double | value ) |
Set the value of a key in the configuration object.
- Parameters
-
key The key to set the value for. Format: "/category/subcategory/.../key". value The value to set.
◆ set_int()
| void DiFfRG::ConfigTree::set_int | ( | const std::string & | key, |
| int | value ) |
Set the value of a key in the configuration object.
- Parameters
-
key The key to set the value for. Format: "/category/subcategory/.../key". value The value to set.
◆ set_string()
| void DiFfRG::ConfigTree::set_string | ( | const std::string & | key, |
| const std::string & | value ) |
Set the value of a key in the configuration object.
- Parameters
-
key The key to set the value for. Format: "/category/subcategory/.../key". value The value to set.
◆ set_uint()
| void DiFfRG::ConfigTree::set_uint | ( | const std::string & | key, |
| uint | value ) |
Set the value of a key in the configuration object.
- Parameters
-
key The key to set the value for. Format: "/category/subcategory/.../key". value The value to set.
Member Data Documentation
◆ value
|
private |
The documentation for this class was generated from the following file:
- /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/common/config_tree.hh
Generated by