#include <colvarparse.h>
Inheritance diagram for colvarparse:
Public Types | |||||||||
enum | Parse_Mode { parse_null = 0, parse_echo = (1<<1), parse_echo_default = (1<<2), parse_deprecation_warning = (1<<3), parse_silent = 0, parse_required = (1<<16), parse_override = (1<<17), parse_restart = (1<<18), parse_normal = (1<<1) | (1<<2) | (1<<17), parse_deprecated = (1<<1) | (1<<3) | (1<<17) } | ||||||||
How a keyword is parsed in a string. More... | |||||||||
Public Methods | |||||||||
colvarparse () | |||||||||
Default constructor. More... | |||||||||
colvarparse (const std::string &conf) | |||||||||
Constructor that stores the object's config string. More... | |||||||||
void | clear () | ||||||||
Set the object ready to parse a new configuration string. More... | |||||||||
void | set_string (std::string const &conf) | ||||||||
Set a new config string for this object. More... | |||||||||
virtual | ~colvarparse () | ||||||||
Default destructor. More... | |||||||||
std::string const & | get_config () const | ||||||||
Get the configuration string (includes comments). More... | |||||||||
int | check_keywords (std::string &conf, char const *key) | ||||||||
\brief Check that all the keywords within "conf" are in the list of allowed keywords; this will invoke strip_values() first and then loop over all words. More... | |||||||||
void | clear_keyword_registry () | ||||||||
\brief Use this after parsing a config string (note that check_keywords() calls it already). More... | |||||||||
bool | get_keyval (std::string const &conf, char const *key, int &value, int const &def_value=(int) 0, Parse_Mode const parse_mode=parse_normal) | ||||||||
\fn get_keyval bool const get_keyval (std::string const &conf, char const *key, _type_ &value, _type_ const &def_value, Parse_Mode const parse_mode) \brief Helper function to parse keywords in the configuration and get their values In normal circumstances, you should use either version the get_keyval function. Both of them look for the C string "key" in the C++ string "conf", and assign the corresponding value (if available) to the variable "value" (first version), or assign as many values as found to the vector "values" (second version). If "key" is found but no value is associated to it, the default value is provided (either one copy or as many copies as the current length of the vector "values" specifies). A message will print, unless parse_mode is equal to parse_silent. The return value of both forms of get_keyval is true if "key" is found (with or without value), and false when "key" is absent in the string "conf". If there is more than one instance of the keyword, a warning will be raised; instead, to loop over multiple instances key_lookup() should be invoked directly. If you introduce a new data type, add two new instances of this functions, or insert this type in the colvarvalue wrapper class (colvarvalue.h). More... | |||||||||
bool | get_keyval (std::string const &conf, char const *key, size_t &value, size_t const &def_value=(size_t) 0, Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, long &value, long const &def_value=0, Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, cvm::step_number &value, cvm::step_number const &def_value=0, Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, std::string &value, std::string const &def_value=std::string(""), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, cvm::real &value, cvm::real const &def_value=(cvm::real) 0.0, Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, cvm::rvector &value, cvm::rvector const &def_value=cvm::rvector(), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, cvm::quaternion &value, cvm::quaternion const &def_value=cvm::quaternion(), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, colvarvalue &value, colvarvalue const &def_value=colvarvalue(colvarvalue::type_notset), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, bool &value, bool const &def_value=false, Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, std::vector< int > &values, std::vector< int > const &def_values=std::vector< int >(0,(int) 0), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, std::vector< size_t > &values, std::vector< size_t > const &def_values=std::vector< size_t >(0,(size_t) 0), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, std::vector< long > &values, std::vector< long > const &def_values=std::vector< long >(0,(long) 0), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, std::vector< std::string > &values, std::vector< std::string > const &def_values=std::vector< std::string >(0, std::string("")), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, std::vector< cvm::real > &values, std::vector< cvm::real > const &def_values=std::vector< cvm::real >(0,(cvm::real) 0.0), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, std::vector< cvm::rvector > &values, std::vector< cvm::rvector > const &def_values=std::vector< cvm::rvector >(0, cvm::rvector()), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, std::vector< cvm::quaternion > &values, std::vector< cvm::quaternion > const &def_values=std::vector< cvm::quaternion >(0, cvm::quaternion()), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | get_keyval (std::string const &conf, char const *key, std::vector< colvarvalue > &values, std::vector< colvarvalue > const &def_values=std::vector< colvarvalue >(0, colvarvalue(colvarvalue::type_notset)), Parse_Mode const parse_mode=parse_normal) | ||||||||
bool | key_lookup (std::string const &conf, char const *key, std::string *data=NULL, size_t *save_pos=NULL) | ||||||||
\brief Low-level function for parsing configuration strings; automatically adds the requested keyword to the list of valid ones.
| |||||||||
std::istream & | read_config_line (std::istream &is, std::string &line) | ||||||||
\brief Reads a configuration line, adds it to config_string, and returns the stream
| |||||||||
template<> int | _get_keyval_scalar_value_ (std::string const &key_str, std::string const &data, bool &value, bool const &) | ||||||||
template<> int | _get_keyval_scalar_novalue_ (std::string const &key_str, bool &value, Parse_Mode const &parse_mode) | ||||||||
Static Public Methods | |||||||||
std::string | to_lower_cppstr (std::string const &in) | ||||||||
\brief Return a lowercased copy of the string. More... | |||||||||
std::istream & | getline_nocomments (std::istream &is, std::string &s) | ||||||||
\brief Works as std::getline() but also removes everything between a comment character and the following newline. More... | |||||||||
int | check_braces (std::string const &conf, size_t const start_pos) | ||||||||
\brief Check if the content of a config string has matching braces
| |||||||||
int | check_ascii (std::string const &conf) | ||||||||
\brief Check that a config string contains non-ASCII characters
| |||||||||
void | split_string (const std::string &data, const std::string &delim, std::vector< std::string > &dest) | ||||||||
\brief Split a string with a specified delimiter into a vector
| |||||||||
Static Public Attributes | |||||||||
const char *const | white_space = " \t" | ||||||||
Accepted white space delimiters, used in key_lookup(). More... | |||||||||
Protected Types | |||||||||
enum | key_set_mode { key_not_set = 0, key_set_user = 1, key_set_default = 2 } | ||||||||
How a keyword has been set. More... | |||||||||
Protected Methods | |||||||||
bool | get_key_string_value (std::string const &conf, char const *key, std::string &data) | ||||||||
Get the string value of a keyword, and save it for later parsing. More... | |||||||||
bool | get_key_string_multi_value (std::string const &conf, char const *key, std::vector< std::string > &data) | ||||||||
Get multiple strings from repeated instances of a same keyword. More... | |||||||||
template<typename TYPE> bool | _get_keyval_scalar_ (std::string const &conf, char const *key, TYPE &value, TYPE const &def_value, Parse_Mode const &parse_mode) | ||||||||
Template for single-value keyword parsers. More... | |||||||||
template<typename TYPE> bool | _get_keyval_vector_ (std::string const &conf, char const *key, std::vector< TYPE > &values, std::vector< TYPE > const &def_values, Parse_Mode const &parse_mode) | ||||||||
Template for multiple-value keyword parsers. More... | |||||||||
template<typename TYPE> int | _get_keyval_scalar_value_ (std::string const &key_str, std::string const &data, TYPE &value, TYPE const &def_value) | ||||||||
Extract the value of a variable from a string. More... | |||||||||
template<typename TYPE> int | _get_keyval_scalar_novalue_ (std::string const &key_str, TYPE &value, Parse_Mode const &parse_mode) | ||||||||
Handle the case where the user provides a keyword without value. More... | |||||||||
template<typename TYPE> void | mark_key_set_user (std::string const &key_str, TYPE const &value, Parse_Mode const &parse_mode) | ||||||||
Record that the keyword has just been user-defined. More... | |||||||||
template<typename TYPE> void | mark_key_set_default (std::string const &key_str, TYPE const &def_value, Parse_Mode const &parse_mode) | ||||||||
Record that the keyword has just been set to its default value. More... | |||||||||
void | error_key_required (std::string const &key_str, Parse_Mode const &parse_mode) | ||||||||
Raise error condition due to the keyword being required! More... | |||||||||
bool | key_already_set (std::string const &key_str) | ||||||||
True if the keyword has been set already. More... | |||||||||
void | add_keyword (char const *key) | ||||||||
\brief Add a new valid keyword to the list. More... | |||||||||
void | strip_values (std::string &conf) | ||||||||
\brief Remove all the values from the config string. More... | |||||||||
Protected Attributes | |||||||||
std::string const | keyword_delimiters_left | ||||||||
Characters allowed immediately to the left of a kewyord. More... | |||||||||
std::string const | keyword_delimiters_right | ||||||||
Characters allowed immediately to the right of a kewyord. More... | |||||||||
std::list< std::string > | allowed_keywords | ||||||||
\brief List of legal keywords for this object: this is updated by each call to colvarparse::get_keyval() or colvarparse::key_lookup(). More... | |||||||||
std::map< std::string, key_set_mode > | key_set_modes | ||||||||
Track which keywords have been already set, and how. More... | |||||||||
std::list< size_t > | data_begin_pos | ||||||||
\brief List of delimiters for the values of each keyword in the configuration string; all keywords will be stripped of their values before the keyword check is performed. More... | |||||||||
std::list< size_t > | data_end_pos | ||||||||
\brief List of delimiters for the values of each keyword in the configuration string; all keywords will be stripped of their values before the keyword check is performed. More... | |||||||||
std::string | config_string | ||||||||
\brief Configuration string of the object (includes comments). More... |
Definition at line 26 of file colvarparse.h.
|
How a keyword has been set.
Definition at line 348 of file colvarparse.h. |
|
How a keyword is parsed in a string.
Definition at line 52 of file colvarparse.h. Referenced by colvardeps::get_keyval_feature, operator|, and colvar_grid< size_t >::parse_params. |
|
Default constructor.
Definition at line 35 of file colvarparse.C. References keyword_delimiters_right, n, and string. |
|
Constructor that stores the object's config string.
|
|
Default destructor.
Definition at line 67 of file colvarparse.C. |
|
Template for single-value keyword parsers.
Definition at line 241 of file colvarparse.C. References conf, data, colvarmodule::debug, error_key_required, get_key_string_value, key_already_set, colvarmodule::log, parse_override, and parse_required. |
|
Definition at line 230 of file colvarparse.C. References set_bool. |
|
Handle the case where the user provides a keyword without value.
Definition at line 221 of file colvarparse.C. References COLVARS_INPUT_ERROR, and colvarmodule::error. |
|
Definition at line 199 of file colvarparse.C. References COLVARS_INPUT_ERROR, data, colvarmodule::error, set_bool, and string. |
|
Extract the value of a variable from a string.
Definition at line 169 of file colvarparse.C. References COLVARS_INPUT_ERROR, data, and colvarmodule::error. |
|
Template for multiple-value keyword parsers.
Definition at line 287 of file colvarparse.C. References COLVARS_BUG_ERROR, COLVARS_INPUT_ERROR, conf, data, colvarmodule::error, error_key_required, get_key_string_value, key_already_set, parse_override, and parse_required. |
|
\brief Add a new valid keyword to the list.
Definition at line 534 of file colvarparse.C. References allowed_keywords, key_not_set, key_set_modes, and to_lower_cppstr. Referenced by key_lookup. |
|
\brief Check that a config string contains non-ASCII characters
Definition at line 939 of file colvarparse.C. References conf, colvarmodule::getline, and colvarmodule::log. Referenced by colvarmodule::parse_config. |
|
\brief Check if the content of a config string has matching braces
Definition at line 925 of file colvarparse.C. References COLVARS_INPUT_ERROR, and conf. Referenced by key_lookup, and colvarmodule::parse_config. |
|
\brief Check that all the keywords within "conf" are in the list of allowed keywords; this will invoke strip_values() first and then loop over all words.
Definition at line 592 of file colvarparse.C. References allowed_keywords, clear_keyword_registry, COLVARS_INPUT_ERROR, conf, colvarmodule::debug, colvarmodule::error, colvarmodule::getline, colvarmodule::log, strip_values, to_lower_cppstr, and white_space. Referenced by colvarbias_histogram::init, and colvarmodule::parse_config. |
|
Set the object ready to parse a new configuration string.
Reimplemented in colvarbias. Referenced by colvarbias_meta::read_state_data, and colvarmodule::reset. |
|
\brief Use this after parsing a config string (note that check_keywords() calls it already).
Definition at line 583 of file colvarparse.C. References allowed_keywords, data_begin_pos, data_end_pos, and key_set_modes. Referenced by check_keywords, and colvarmodule::read_restart. |
|
Raise error condition due to the keyword being required!
Definition at line 152 of file colvarparse.C. References COLVARS_INPUT_ERROR, colvarmodule::error, key_already_set, and parse_restart. Referenced by _get_keyval_scalar_, and _get_keyval_vector_. |
|
Get the configuration string (includes comments).
Definition at line 46 of file colvarparse.h. References config_string. Referenced by colvarmodule::get_config. |
|
Get multiple strings from repeated instances of a same keyword.
Definition at line 99 of file colvarparse.C. References conf, data, and key_lookup. |
|
Get the string value of a keyword, and save it for later parsing.
Definition at line 74 of file colvarparse.C. References COLVARS_INPUT_ERROR. Referenced by _get_keyval_scalar_, and _get_keyval_vector_. |
|
Definition at line 524 of file colvarparse.C. References conf. |
|
Definition at line 515 of file colvarparse.C. References conf. |
|
Definition at line 506 of file colvarparse.C. References conf. |
|
Definition at line 497 of file colvarparse.C. References conf. |
|
Definition at line 488 of file colvarparse.C. References conf. |
|
Definition at line 479 of file colvarparse.C. References conf. |
|
Definition at line 470 of file colvarparse.C. References conf. |
|
Definition at line 461 of file colvarparse.C. References conf. |
|
Definition at line 449 of file colvarparse.C. References conf. |
|
Definition at line 440 of file colvarparse.C. References conf. |
|
Definition at line 431 of file colvarparse.C. References conf. |
|
Definition at line 422 of file colvarparse.C. References conf. |
|
Definition at line 413 of file colvarparse.C. References conf. |
|
Definition at line 404 of file colvarparse.C. References conf. |
|
Definition at line 395 of file colvarparse.C. References conf. |
|
Definition at line 386 of file colvarparse.C. References conf. |
|
Definition at line 377 of file colvarparse.C. References conf. |
|
|
\brief Works as std::getline() but also removes everything between a comment character and the following newline.
Definition at line 652 of file colvarparse.C. References colvarmodule::getline. Referenced by colvarbias_restraint_histogram::init, operator>>, colvarmodule::read_traj, and colvarbias_meta::update_replicas_registry. |
|
True if the keyword has been set already.
Definition at line 548 of file colvarparse.C. References key_set_modes, and to_lower_cppstr. Referenced by _get_keyval_scalar_, _get_keyval_vector_, error_key_required, and colvar::init_grid_parameters. |
|
\brief Low-level function for parsing configuration strings; automatically adds the requested keyword to the list of valid ones.
Definition at line 664 of file colvarparse.C. References add_keyword, check_braces, COLVARS_INPUT_ERROR, conf, data, data_begin_pos, data_end_pos, colvarmodule::debug, colvarmodule::error, keyword_delimiters_left, keyword_delimiters_right, colvarmodule::log, NULL, to_lower_cppstr, and white_space. Referenced by colvar::alpha_angles::alpha_angles, colvar::distance_z::distance_z, get_key_string_multi_value, colvarbias_histogram::init, colvar::init_custom_function, colvarmodule::parse_colvars, colvarmodule::parse_global_params, and colvar::cvc::parse_group. |
|
Record that the keyword has just been set to its default value.
Definition at line 140 of file colvarparse.C. References key_set_default, key_set_modes, colvarmodule::log, parse_echo_default, and to_lower_cppstr. |
|
Record that the keyword has just been user-defined.
Definition at line 123 of file colvarparse.C. References key_set_modes, key_set_user, colvarmodule::log, parse_deprecation_warning, parse_echo, and to_lower_cppstr. |
|
\brief Reads a configuration line, adds it to config_string, and returns the stream
Definition at line 639 of file colvarparse.C. References config_string, and colvarmodule::getline. Referenced by colvarmodule::read_config_file, and colvarmodule::read_config_string. |
|
Set a new config string for this object.
Definition at line 58 of file colvarparse.C. Referenced by colvarbias::init, and colvar::init. |
|
\brief Split a string with a specified delimiter into a vector
Definition at line 958 of file colvarparse.C. References data. |
|
\brief Remove all the values from the config string.
Definition at line 560 of file colvarparse.C. References conf, data_begin_pos, and data_end_pos. Referenced by check_keywords. |
|
\brief Return a lowercased copy of the string.
Definition at line 261 of file colvarparse.h. Referenced by add_keyword, check_keywords, colvarbias::colvarbias, key_already_set, key_lookup, mark_key_set_default, mark_key_set_user, colvar::parse_analysis, colvarmodule::parse_global_params, pdb_field_str2enum, colvarmodule::read_restart, and colvarbias::read_state_data_key. |
|
\brief List of legal keywords for this object: this is updated by each call to colvarparse::get_keyval() or colvarparse::key_lookup().
Definition at line 345 of file colvarparse.h. Referenced by add_keyword, check_keywords, and clear_keyword_registry. |
|
\brief Configuration string of the object (includes comments).
Definition at line 374 of file colvarparse.h. Referenced by get_config, and read_config_line. |
|
\brief List of delimiters for the values of each keyword in the configuration string; all keywords will be stripped of their values before the keyword check is performed.
Definition at line 360 of file colvarparse.h. Referenced by clear_keyword_registry, key_lookup, and strip_values. |
|
\brief List of delimiters for the values of each keyword in the configuration string; all keywords will be stripped of their values before the keyword check is performed.
Definition at line 365 of file colvarparse.h. Referenced by clear_keyword_registry, key_lookup, and strip_values. |
|
Track which keywords have been already set, and how.
Definition at line 355 of file colvarparse.h. Referenced by add_keyword, clear_keyword_registry, key_already_set, mark_key_set_default, and mark_key_set_user. |
|
Characters allowed immediately to the left of a kewyord.
Definition at line 337 of file colvarparse.h. Referenced by key_lookup. |
|
Characters allowed immediately to the right of a kewyord.
Definition at line 340 of file colvarparse.h. Referenced by key_lookup. |
|
Accepted white space delimiters, used in key_lookup().
Definition at line 20 of file colvarparse.C. Referenced by check_keywords, key_lookup, colvarmodule::read_config_file, colvarmodule::read_config_string, and colvarmodule::read_traj. |