ConfigTree Class Reference#

DiFfRG: DiFfRG::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.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
defThe default value to return if the key is not found.
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
filenameThe 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
filenameThe name of the file to read.

◆ ConfigTree() [4/4]

DiFfRG::ConfigTree::ConfigTree ( const json::value & v)

Construct a new ConfigTree object.

Parameters
vThe 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
keyThe key to look for. Format: "/category/subcategory/.../key".

◆ from_json_string()

static ConfigTree DiFfRG::ConfigTree::from_json_string ( const std::string & content)
static

Construct a ConfigTree from the contents of a JSON document.

Parameters
contentThe JSON document.

◆ from_toml_string()

static ConfigTree DiFfRG::ConfigTree::from_toml_string ( const std::string & content)
static

Construct a ConfigTree from the contents of a TOML document.

Parameters
contentThe 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
keyThe 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
keyThe key to get the value for. Format: "/category/subcategory/.../key".
defThe 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
keyThe 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
keyThe key to get the value for. Format: "/category/subcategory/.../key".
defThe 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
keyThe 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
keyThe key to get the value for. Format: "/category/subcategory/.../key".
defThe 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
keyThe 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
keyThe key to get the value for. Format: "/category/subcategory/.../key".
defThe 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
keyThe key to get the value for. Format: "/category/subcategory/.../key".
Returns
uint The value.

◆ get_uint() [2/2]

uint DiFfRG::ConfigTree::get_uint ( const std::string & key,
const uint def ) const

Get the value of a key in the configuration object, with a default value.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
defThe default value to return if the key is not found.
Returns
uint The value.

◆ get_uint_or_warn()

uint DiFfRG::ConfigTree::get_uint_or_warn ( const std::string & key,
const uint def ) const

◆ 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()

void DiFfRG::ConfigTree::pretty_print ( std::ostream & os,
json::value const & v,
std::string * indent = nullptr ) const
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
keyThe key to set the value for. Format: "/category/subcategory/.../key".
valueThe 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
keyThe key to set the value for. Format: "/category/subcategory/.../key".
valueThe 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
keyThe key to set the value for. Format: "/category/subcategory/.../key".
valueThe 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
keyThe key to set the value for. Format: "/category/subcategory/.../key".
valueThe 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
keyThe key to set the value for. Format: "/category/subcategory/.../key".
valueThe value to set.

Member Data Documentation

◆ value

json::value DiFfRG::ConfigTree::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