88 Config(
const std::string& filename_in);
94 void write(
const std::string& filename)
const;
100 void addFile(
const std::string& filename_in);
109 void addKey(std::string key, std::string section,
const std::string& value);
116 void deleteKey(std::string key, std::string section);
128 void deleteKeys(std::string keymatch, std::string section,
const bool& anywhere=
false);
148 bool keyExists(std::string key, std::string section)
const;
149 bool keyExistsRegex(std::string key_pattern, std::string section)
const;
167 template <
typename T> std::vector<T>
getValue(
const std::string& key, std::string& section,
185 template <
typename T>
void getValue(
const std::string& key,
186 std::vector<T>& vecT,
189 getValue(key,
"GENERAL", vecT, opt);
203 template <
typename T>
void getValue(std::string key, std::string section,
211 IOUtils::getValueForKey<T>(properties, section +
"::" + key, vecT, opt);
212 }
catch(
const std::exception&){
231 const ConfigProxy
get(
const std::string& key,
const std::string& section)
const;
247 template <
typename T> T
get(
const std::string& key,
const std::string& section,
const T& dflt)
const;
265 std::string
get(
const std::string& key,
const std::string& section,
const std::string& dflt)
const;
266 std::string
get(
const std::string& key,
const std::string& section,
const char dflt[])
const;
267 double get(
const std::string& key,
const std::string& section,
const double& dflt)
const;
268 bool get(
const std::string& key,
const std::string& section,
const bool& dflt)
const;
289 template <
typename T>
void getValue(std::string key, std::string section, T& t,
296 IOUtils::getValueForKey<T>(properties, section +
"::" + key, t, opt);
297 }
catch(
const std::exception&){
310 void getValue(std::string key, std::string section,
Date& t,
const double& time_zone,
319 IOUtils::getValueForKey<std::string>(properties, section +
"::" + key, tmp, opt);
320 }
catch(
const std::exception&){
324 bool parse_ok =
false;
327 }
catch(
const std::exception&){
343 template <
typename T>
void getValues(std::string keymatch, std::string section, std::vector<T>& vecT)
const
348 const std::vector< std::string > vecKeys(
getKeys(keymatch, section) );
350 for (
const std::string& key : vecKeys) {
351 const std::string full_key( section +
"::" + key );
355 }
catch(
const std::exception&){
358 vecT.push_back( tmp );
362 template <
typename T>
void getValues(std::string keymatch, std::string section, std::vector<T>& vecT, std::vector<std::string>& vecKeys)
const
367 vecKeys =
getKeys(keymatch, section);
369 for (
const std::string& key : vecKeys) {
370 const std::string full_key = section +
"::" + key;
374 }
catch(
const std::exception&){
377 vecT.push_back( tmp );
392 std::vector< std::pair<std::string, std::string> >
getValues(std::string keymatch, std::string section,
const bool& anywhere=
false)
const;
394 std::vector< std::pair<std::string, std::string> >
getValuesRegex(
const std::string& regex_str, std::string section)
const;
407 std::vector<std::string>
getKeys(std::string keymatch, std::string section,
const bool& anywhere=
false)
const;
408 std::vector<std::string>
getKeysRegex(
const std::string& regex_str, std::string section)
const;
421 void moveSection(std::string org, std::string dest,
const bool& overwrite);
435 static unsigned int getCommandNr(
const std::string& section,
const std::string& cmd_pattern,
const std::string& cmd_key);
452 std::vector< std::pair<std::string, std::string> >
parseArgs(
const std::string& section,
const std::string& cmd_id,
const unsigned int& cmd_nr,
const std::string& arg_pattern)
const;
462 std::vector< std::pair<std::string, std::string> >
getArgumentsForAlgorithm(
const std::string& parname,
const std::string& algorithm,
463 const std::string& section =
"Interpolations1d")
const;
465 std::vector< std::pair<std::string, std::string> >
getArgumentsForAlgorithm(
const std::string& parname,
const std::string& algorithm,
const size_t& algo_index,
466 const std::string& section =
"Interpolations1d")
const;
471 std::map<std::string, std::string> properties;
472 std::set<std::string> sections;
473 std::string sourcename;
474 std::string configRootDir;
479 const Config& proxycfg;
480 const std::string& key;
481 const std::string& section;
483 ConfigProxy(
const Config& i_cfg,
const std::string& i_key,
484 const std::string& i_section)
485 : proxycfg(i_cfg), key(i_key),section(i_section) { }
487 template<
typename T>
operator T()
const {
496 ConfigParser(
const std::string& filename, std::map<std::string, std::string> &i_properties, std::set<std::string> &i_sections);
498 static std::string
extract_section(
const std::string& key,
const bool& provide_default=
false);
500 void parseFile(
const std::string& filename);
501 void parseLine(
const unsigned int& linenr, std::vector<std::string> &import_after,
bool &accept_import_before, std::string &line, std::string §ion);
502 static bool onlyOneEqual(
const std::string& str);
503 static void processEnvVars(std::string& value);
504 static bool processExpr(std::string& value);
505 bool processVars(std::string& value,
const std::string& section)
const;
506 bool processSectionHeader(
const std::string& line, std::string §ion,
const unsigned int& linenr);
507 std::string clean_import_path(
const std::string& in_path)
const;
508 bool processImports(
const std::string& key,
const std::string& value, std::vector<std::string> &import_after,
const bool &accept_import_before);
509 void handleNonKeyValue(
const std::string& line_backup,
const std::string& section,
const unsigned int& linenr,
bool &accept_import_before);
511 std::map<std::string, std::string> properties;
512 std::set<std::string> imported;
513 std::set<std::string> sections;
514 std::set<std::string> deferred_vars;
515 std::set<std::string> deferred_exprs;
516 std::string sourcename;
#define AT
Definition: IOExceptions.h:28
ConfigParser(const std::string &filename, std::map< std::string, std::string > &i_properties, std::set< std::string > &i_sections)
Definition: Config.cc:593
static std::string extract_section(const std::string &key, const bool &provide_default=false)
Definition: Config.cc:920
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:77
std::string getSourceName() const
Returns the filename that the Config object was constructed with.
Definition: Config.h:134
void getValue(const std::string &key, T &t, const IOUtils::ThrowOptions &opt=IOUtils::dothrow) const
Template function to retrieve a value of class T for a certain key.
Definition: Config.h:277
void getValues(std::string keymatch, std::string section, std::vector< T > &vecT, std::vector< std::string > &vecKeys) const
Definition: Config.h:362
void getValues(std::string keymatch, std::string section, std::vector< T > &vecT) const
Template function to retrieve a vector of values of class T for a certain key pattern.
Definition: Config.h:343
friend std::ostream & operator<<(std::ostream &os, const Config &cfg)
Definition: Config.cc:454
void deleteKey(std::string key, std::string section)
Delete a specific key/value pair from the internal map object, key/section are case insensitive.
Definition: Config.cc:131
const ConfigProxy get(const std::string &key, const std::string §ion) const
A function that allows to retrieve a value for a key as return parameter (vectors of values too).
Definition: Config.cc:56
const std::string toString() const
Print the content of the Config object (useful for debugging) The Config is bound by "<Config>" and "...
Definition: Config.cc:443
Config()
Empty constructor. The user MUST later one fill the internal key/value map object.
Definition: Config.cc:49
std::vector< std::string > getKeys(std::string keymatch, std::string section, const bool &anywhere=false) const
Function that searches for a given string within the keys of a given section (default: GENERAL) it re...
Definition: Config.cc:388
static unsigned int getCommandNr(const std::string §ion, const std::string &cmd_pattern, const std::string &cmd_key)
Extract the command number from a given command string, given the command pattern.
Definition: Config.cc:533
std::set< std::string > getSections() const
Returns all the sections that are present in the config object.
Definition: Config.h:413
void getValue(const std::string &key, std::vector< T > &vecT, const IOUtils::ThrowOptions &opt=IOUtils::dothrow) const
Template function to retrieve a vector of values of class T for a certain key.
Definition: Config.h:185
std::vector< std::string > getKeysRegex(const std::string ®ex_str, std::string section) const
Definition: Config.cc:376
void addFile(const std::string &filename_in)
Add the content of a file to the internal key/value map object.
Definition: Config.cc:117
void getValue(std::string key, std::string section, Date &t, const double &time_zone, const IOUtils::ThrowOptions &opt=IOUtils::dothrow) const
Function to retrieve a Date value for a certain key.
Definition: Config.h:310
std::vector< std::pair< std::string, std::string > > parseArgs(const std::string §ion, const std::string &cmd_id, const unsigned int &cmd_nr, const std::string &arg_pattern) const
Extract the arguments for a given command and store them into a vector of key / value pairs.
Definition: Config.cc:551
friend std::istream & operator>>(std::istream &is, Config &cfg)
Definition: Config.cc:489
void addKey(std::string key, std::string section, const std::string &value)
Add a specific key/value pair to the internal key/value map object. key and section are case insensit...
Definition: Config.cc:124
void write(const std::string &filename) const
Write the Config object to a file.
Definition: Config.cc:402
bool keyExists(std::string key, std::string section) const
Return if a given key exists in a given section (matching is case insensitive)
Definition: Config.cc:168
std::vector< T > getValue(const std::string &key, std::string §ion, const IOUtils::ThrowOptions &opt=IOUtils::dothrow) const
Definition: Config.h:167
void getValue(std::string key, std::string section, T &t, const IOUtils::ThrowOptions &opt=IOUtils::dothrow) const
Template function to retrieve a value of class T for a certain key.
Definition: Config.h:289
void getValue(std::string key, std::string section, std::vector< T > &vecT, const IOUtils::ThrowOptions &opt=IOUtils::dothrow) const
Template function to retrieve a vector of values of class T for a certain key.
Definition: Config.h:203
bool sectionExists(std::string section) const
Return if a given section exists in the Config object.
Definition: Config.cc:189
bool keyExistsRegex(std::string key_pattern, std::string section) const
Definition: Config.cc:178
std::string getConfigRootDir() const
Returns the directory where the root configuration file is (needed to resolv relative paths).
Definition: Config.h:140
void moveSection(std::string org, std::string dest, const bool &overwrite)
Move all keys of the org section to the dest section.
Definition: Config.cc:201
std::vector< std::pair< std::string, std::string > > getValuesRegex(const std::string ®ex_str, std::string section) const
Definition: Config.cc:240
std::vector< std::pair< std::string, std::string > > getArgumentsForAlgorithm(const std::string &parname, const std::string &algorithm, const std::string §ion="Interpolations1d") const
retrieve the resampling algorithm to be used for the 1D interpolation of meteo parameters....
Definition: Config.cc:567
void deleteKeys(std::string keymatch, std::string section, const bool &anywhere=false)
Delete keys matching a specific pattern from the internal map object, key/section are case insensitiv...
Definition: Config.cc:138
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
void setUndef(const bool &flag=true)
Definition: Date.cc:193
thrown when encountered an unexpected value (e.g. unknown name or key)
Definition: IOExceptions.h:142
bool convertString(Date &t, std::string str, const double &time_zone, std::ios_base &(*f)(std::ios_base &))
Convert a string to a date (template specialization of convertString)
Definition: IOUtils.cc:653
void toUpper(std::string &str)
Definition: IOUtils.cc:285
ThrowOptions
Definition: IOUtils.h:74
@ dothrow
Definition: IOUtils.h:74