|
libeblearntools
|
#include <configuration.h>
Public Member Functions | |
| configuration () | |
| empty constructor. | |
| configuration (const configuration &other) | |
| copy constructor. | |
| configuration (const char *filename, bool replquotes=false, bool silent=false, bool resolve=true) | |
| configuration (const string &filename, bool replquotes=false, bool silent=false, bool resolve=true) | |
| configuration (string_map_t &smap, textlist &txt, string &name, string &output_dir) | |
| virtual | ~configuration () |
| destructor. | |
| bool | read (const char *fname, bool resolve=true, bool replquotes=true, bool silent=false, const char *outdir=NULL) |
| bool | write (const char *fname) |
| save configuration into file fname. | |
| void | resolve (bool replquotes=false) |
| void | resolve_bq () |
| only resolve backquotes blocs. | |
| const string & | get_name () |
| return the name of the configuration | |
| void | set_name (const string &name) |
| set name of the configuration | |
| const string & | get_output_dir () |
| return output directory. | |
| void | set_output_dir (const string &d) |
| set output directory. | |
| template<typename T > | |
| void | get (T &v, const char *varname) |
| template<typename T > | |
| void | get (T &v, const std::string &varname) |
| void | get (intg &v, const char *varname) |
| Get variable with name varname as an intg into v. | |
| void | get (uint &v, const char *varname) |
| Get variable with name varname as an uint into v. | |
| void | get (double &v, const char *varname) |
| Get variable with name varname as a double into v. | |
| void | get (float &v, const char *varname) |
| Get variable with name varname as a double into v. | |
| void | get (string &v, const char *varname) |
| Get variable with name varname as a string into v. | |
| void | get (bool &v, const char *varname) |
| Get variable with name varname as a string into v. | |
| const string & | get_string (const char *varname) |
| const string & | get_string (const string &varname) |
| const char * | get_cstring (const char *varname) |
| double | get_double (const char *varname) |
| uint | try_get_uint (const char *varname, uint default_val) |
| int | try_get_int (const char *varname, int default_val) |
| intg | try_get_intg (const char *varname, intg default_val) |
| float | try_get_float (const char *varname, float default_val) |
| double | try_get_double (const char *varname, double default_val) |
| string | try_get_string (const char *varname, const char *default_val="") |
| float | get_float (const char *varname) |
| uint | get_uint (const char *varname) |
| int | get_int (const char *varname) |
| intg | get_intg (const char *varname) |
| bool | get_bool (const char *varname) |
| char | get_char (const char *varname) |
| bool | exists_bool (const char *varname) |
| Returns true if variable exists and its value is true, false otherwise. | |
| bool | exists_true (const char *varname) |
| Returns true if variable exists and its value is true, false otherwise. | |
| bool | exists_true (const string &varname) |
| Returns true if variable exists and its value is true, false otherwise. | |
| bool | exists_false (const char *varname) |
| Returns true if variable exists and its value is false, true otherwise. | |
| void | exists_throw (const char *varname) |
| void | set (const char *varname, const char *value) |
| set variable 'varname' to value 'value' | |
| const char * | get_cstr (const char *varname, bool silent=false) |
| vector< string > | get_all_strings (const string &s) |
| Return a vector of all variable names that begin with 's'. | |
| bool | exists (const char *varname) |
| returns true if the variable exists, false otherwise. | |
| bool | exists (const std::string &varname) |
| returns true if the variable exists, false otherwise. | |
| virtual void | pretty () |
| print loaded variables | |
| virtual void | pretty_match (const string &s) |
| Print all variables who's name is contained in string 's'. | |
Protected Member Functions | |
| void | resolve_variables (string_map_t &m, bool replquotes=false) |
| Resolve all variables in map m. | |
| string | resolve0 (string_map_t &m, const string &variable, const string &v, bool firstonly=false) |
| Resolve double quotes blocs, or entire string if not present. | |
| string | resolve_backquotes (string_map_t &m, const string &variable, const string &v, bool firstonly=false) |
| Resolve back quotes blocs only. | |
| string | resolve_string (string_map_t &m, const string &variable, const string &v, bool firstonly=false) |
| Resolve an unquoted string (just variables). | |
| bool | extract_variables (const char *fname, string_map_t &smap, textlist &txt, string_map_t *meta_smap=NULL, bool bresolve=true, bool replquotes=false, bool silent=false) |
Protected Attributes | |
| string_map_t | smap |
| map between variables and values | |
| string_map_t | tmp_smap |
| map between variables and values | |
| string | name |
| name of configuration | |
| string | output_dir |
| output directory | |
| textlist | otxt |
| original text | |
| bool | silent |
configuration class. handle files containing variable definitions.
| ebl::configuration::configuration | ( | const char * | filename, |
| bool | replquotes = false, |
||
| bool | silent = false, |
||
| bool | resolve = true |
||
| ) |
load configuration found in filename.
| resolve | If true, replace all referenced variables by their value. |
| ebl::configuration::configuration | ( | const string & | filename, |
| bool | replquotes = false, |
||
| bool | silent = false, |
||
| bool | resolve = true |
||
| ) |
load configuration found in filename.
| resolve | If true, replace all referenced variables by their value. |
| ebl::configuration::configuration | ( | string_map_t & | smap, |
| textlist & | txt, | ||
| string & | name, | ||
| string & | output_dir | ||
| ) |
Load configuration from already loaded map of variables, name and output directory.
| txt | Original text lines of configuration. |
| void ebl::configuration::exists_throw | ( | const char * | varname | ) |
Checks that variable varname exists in the map, if not throw an exception.
| void ebl::configuration::get | ( | T & | v, |
| const char * | varname | ||
| ) |
Generic template get, return the value associated with varname, if varname exists, otherwise throws an execption.
| void ebl::configuration::get | ( | T & | v, |
| const std::string & | varname | ||
| ) |
Generic template get, return the value associated with varname, if varname exists, otherwise throws an execption.
| bool ebl::configuration::get_bool | ( | const char * | varname | ) |
returns a bool conversion of the string contained in the variable with name varname. if varname does not exist or the bool conversion fails, this throws an exception.
| char ebl::configuration::get_char | ( | const char * | varname | ) |
returns a char conversion of the string contained in the variable with name varname. if varname does not exist or the char conversion fails, this throws an exception.
| const char * ebl::configuration::get_cstr | ( | const char * | varname, |
| bool | silent = false |
||
| ) |
get variable 'varname'.
| silent | If false, warn when using env variable. |
| const char * ebl::configuration::get_cstring | ( | const char * | varname | ) |
returns the string contained the variable with name varname. if varname does not exist, this throws an exception.
| double ebl::configuration::get_double | ( | const char * | varname | ) |
returns a double conversion of the string contained in the variable with name varname. if varname does not exist or the double conversion fails, this throws an exception.
| float ebl::configuration::get_float | ( | const char * | varname | ) |
returns a float conversion of the string contained in the variable with name varname. if varname does not exist or the float conversion fails, this throws an exception.
| int ebl::configuration::get_int | ( | const char * | varname | ) |
returns an int conversion of the string contained in the variable with name varname. if varname does not exist or the int conversion fails, this throws an exception.
| intg ebl::configuration::get_intg | ( | const char * | varname | ) |
Returns an intg conversion of the string contained in the variable with name varname. if varname does not exist or the int conversion fails, this throws an exception.
| const string & ebl::configuration::get_string | ( | const char * | varname | ) |
returns the string contained the variable with name varname. if varname does not exist, this throws an exception.
| const string & ebl::configuration::get_string | ( | const string & | varname | ) |
returns the string contained the variable with name varname. if varname does not exist, this throws an exception.
| uint ebl::configuration::get_uint | ( | const char * | varname | ) |
returns a uint conversion of the string contained in the variable with name varname. if varname does not exist or the uint conversion fails, this throws an exception.
| bool ebl::configuration::read | ( | const char * | fname, |
| bool | resolve = true, |
||
| bool | replquotes = true, |
||
| bool | silent = false, |
||
| const char * | outdir = NULL |
||
| ) |
load configuration from file fname.
| resolve | If true, replace all referenced variables by their value. |
| void ebl::configuration::resolve | ( | bool | replquotes = false | ) |
resolve variables names in variables
| replquotes | Remove quotes or not from variable strings. |
| string ebl::configuration::resolve_backquotes | ( | string_map_t & | m, |
| const string & | variable, | ||
| const string & | v, | ||
| bool | firstonly = false |
||
| ) | [protected] |
Resolve back quotes blocs only.
Resolve single quotes blocs, or entire string if not present.
| double ebl::configuration::try_get_double | ( | const char * | varname, |
| double | default_val | ||
| ) |
If variable "varname" exists, return its value in double, otherwise return 'default_val'. If double conversion fails, it throws an exception.
| float ebl::configuration::try_get_float | ( | const char * | varname, |
| float | default_val | ||
| ) |
If variable "varname" exists, return its value in float, otherwise return 'default_val'. If float conversion fails, it throws an exception.
| int ebl::configuration::try_get_int | ( | const char * | varname, |
| int | default_val | ||
| ) |
If variable "varname" exists, return its value in int, otherwise return 'default_val'. If int conversion fails, it throws an exception.
| intg ebl::configuration::try_get_intg | ( | const char * | varname, |
| intg | default_val | ||
| ) |
If variable "varname" exists, return its value in float, otherwise return 'default_val'. If float conversion fails, it throws an exception.
| string ebl::configuration::try_get_string | ( | const char * | varname, |
| const char * | default_val = "" |
||
| ) |
If variable "varname" exists, return its value in float, otherwise return 'default_val'. If float conversion fails, it throws an exception.
| uint ebl::configuration::try_get_uint | ( | const char * | varname, |
| uint | default_val | ||
| ) |
If variable "varname" exists, return its value in uint, otherwise return 'default_val'. If uint conversion fails, it throws an exception.