18#include "colvarvalue.h"
110 bool get_keyval(std::string
const &conf,
113 int const &def_value = 0,
115 bool get_keyval(std::string
const &conf,
118 size_t const &def_value = 0,
120 bool get_keyval(std::string
const &conf,
123 long const &def_value = 0,
125 bool get_keyval(std::string
const &conf,
130 bool get_keyval(std::string
const &conf,
133 std::string
const &def_value = std::string(
""),
135 bool get_keyval(std::string
const &conf,
140 bool get_keyval(std::string
const &conf,
145 bool get_keyval(std::string
const &conf,
150 bool get_keyval(std::string
const &conf,
155 bool get_keyval(std::string
const &conf,
158 bool const &def_value =
false,
160 bool get_keyval(std::string
const &conf,
162 std::vector<int> &values,
163 std::vector<int>
const &def_values = std::vector<int>(0, 0),
165 bool get_keyval(std::string
const &conf,
167 std::vector<size_t> &values,
168 std::vector<size_t>
const &def_values = std::vector<size_t>(0, 0),
170 bool get_keyval(std::string
const &conf,
172 std::vector<long> &values,
173 std::vector<long>
const &def_values = std::vector<long>(0, 0),
175 bool get_keyval(std::string
const &conf,
177 std::vector<std::string> &values,
178 std::vector<std::string>
const &def_values = std::vector<std::string>(0, std::string(
"")),
180 bool get_keyval(std::string
const &conf,
182 std::vector<cvm::real> &values,
183 std::vector<cvm::real>
const &def_values = std::vector<cvm::real>(0, 0.0),
185 bool get_keyval(std::string
const &conf,
187 std::vector<cvm::rvector> &values,
188 std::vector<cvm::rvector>
const &def_values = std::vector<cvm::rvector>(0,
cvm::rvector()),
190 bool get_keyval(std::string
const &conf,
192 std::vector<cvm::quaternion> &values,
193 std::vector<cvm::quaternion>
const &def_values = std::vector<cvm::quaternion>(0,
cvm::quaternion()),
195 bool get_keyval(std::string
const &conf,
197 std::vector<colvarvalue> &values,
205 char const *key, std::string &data);
209 char const *key, std::vector<std::string>& data);
212 template<
typename TYPE>
216 TYPE
const &def_value,
220 template<
typename TYPE>
223 std::vector<TYPE> &values,
224 std::vector<TYPE>
const &def_values,
228 template<
typename TYPE>
230 std::string
const &data,
232 TYPE
const &def_value);
235 template<
typename TYPE>
241 template<
typename TYPE>
247 template<
typename TYPE>
249 TYPE
const &def_value,
264 std::string out =
"";
265 for (
size_t i = 0; i < in.size(); i++) {
266 out.append(1,
static_cast<char>( ::tolower(in[i])) );
316 std::string *data =
nullptr,
317 size_t *save_pos =
nullptr);
331 static int check_braces(std::string
const &conf,
size_t const start_pos);
341 static void split_string(
const std::string& data,
const std::string& delim, std::vector<std::string>& dest);
393 static_cast<int>(mode2));
1-dimensional vector of real numbers with four components and a quaternion algebra
Definition: colvartypes.h:958
vector of real numbers with three components
Definition: colvartypes.h:727
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:95
long long step_number
Use a 64-bit integer to store the step number.
Definition: colvarmodule.h:92
Definition: colvarparams.h:18
Definition: colvarparse.h:276
std::string const key
Keyword that identifies the block.
Definition: colvarparse.h:292
friend std::istream & operator>>(std::istream &is, read_block const &rb)
Read block from stream, first check that key matches, then call read_contents()
Definition: colvarparse.cpp:867
std::string *const data
Where to keep the data.
Definition: colvarparse.h:295
std::istream & read_block_contents(std::istream &is, bool block_only=false) const
Definition: colvarparse.cpp:900
Base class containing parsing functions; all objects which need to parse input inherit from this.
Definition: colvarparse.h:27
bool key_already_set(std::string const &key_str)
True if the keyword has been set already.
Definition: colvarparse.cpp:547
bool key_lookup(std::string const &conf, char const *key, std::string *data=nullptr, size_t *save_pos=nullptr)
Low-level function for parsing configuration strings; automatically adds the requested keyword to the...
Definition: colvarparse.cpp:663
static void split_string(const std::string &data, const std::string &delim, std::vector< std::string > &dest)
Split a string with a specified delimiter into a vector.
Definition: colvarparse.cpp:1007
static int check_ascii(std::string const &conf)
Check that a config string contains non-ASCII characters.
Definition: colvarparse.cpp:988
~colvarparse() override
Default destructor.
Definition: colvarparse.cpp:67
std::string const keyword_delimiters_right
Characters allowed immediately to the right of a kewyord.
Definition: colvarparse.h:349
std::list< size_t > data_begin_pos
List of delimiters for the values of each keyword in the configuration string; all keywords will be s...
Definition: colvarparse.h:369
void set_string(std::string const &conf)
Set a new config string for this object.
Definition: colvarparse.cpp:58
std::string const keyword_delimiters_left
Characters allowed immediately to the left of a kewyord.
Definition: colvarparse.h:346
std::string config_string
Configuration string of the object (includes comments)
Definition: colvarparse.h:383
key_set_mode
How a keyword has been set.
Definition: colvarparse.h:357
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.
Definition: colvarparse.cpp:240
void add_keyword(char const *key)
Add a new valid keyword to the list.
Definition: colvarparse.cpp:533
static int check_braces(std::string const &conf, size_t const start_pos)
Check if the content of a config string has matching braces.
Definition: colvarparse.cpp:974
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.
Definition: colvarparse.cpp:99
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.
Definition: colvarparse.cpp:122
int check_keywords(std::string &conf, char const *key)
Check that all the keywords within "conf" are in the list of allowed keywords; this will invoke strip...
Definition: colvarparse.cpp:591
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.
Definition: colvarparse.cpp:220
static std::string to_lower_cppstr(std::string const &in)
Return a lowercased copy of the string.
Definition: colvarparse.h:262
std::istream & read_config_line(std::istream &is, std::string &line)
Reads a configuration line, adds it to config_string, and returns the stream.
Definition: colvarparse.cpp:638
static const char *const white_space
Accepted white space delimiters, used in key_lookup()
Definition: colvarparse.h:305
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.
Definition: colvarparse.cpp:286
std::list< size_t > data_end_pos
List of delimiters for the values of each keyword in the configuration string; all keywords will be s...
Definition: colvarparse.h:374
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.
Definition: colvarparse.cpp:168
void clear()
Set the object ready to parse a new configuration string.
Definition: colvarparse.cpp:43
std::list< std::string > allowed_keywords
List of legal keywords for this object: this is updated by each call to colvarparse::get_keyval() or ...
Definition: colvarparse.h:354
static std::istream & getline_nocomments(std::istream &is, std::string &s)
Works as std::getline() but also removes everything between a comment character and the following new...
Definition: colvarparse.cpp:651
Parse_Mode
How a keyword is parsed in a string.
Definition: colvarparse.h:53
@ parse_deprecation_warning
Print a deprecation warning if the keyword is given.
Definition: colvarparse.h:61
@ parse_echo_default
Print the default value of a keyword, if it is NOT given.
Definition: colvarparse.h:59
@ parse_echo
Print the value of a keyword if it is given.
Definition: colvarparse.h:57
@ parse_normal
Alias for old default behavior (should be phased out)
Definition: colvarparse.h:72
@ parse_deprecated
Settings for a deprecated keyword.
Definition: colvarparse.h:74
@ parse_restart
The call is being executed from a read_restart() function.
Definition: colvarparse.h:70
@ parse_null
Zero for all flags.
Definition: colvarparse.h:55
@ parse_override
Definition: colvarparse.h:68
@ parse_silent
Do not print the keyword.
Definition: colvarparse.h:63
@ parse_required
Raise error if the keyword is not provided.
Definition: colvarparse.h:65
void error_key_required(std::string const &key_str, Parse_Mode const &parse_mode)
Raise error condition due to the keyword being required!
Definition: colvarparse.cpp:151
void clear_keyword_registry()
Use this after parsing a config string (note that check_keywords() calls it already)
Definition: colvarparse.cpp:582
void strip_values(std::string &conf)
Remove all the values from the config string.
Definition: colvarparse.cpp:559
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.
Definition: colvarparse.cpp:74
colvarparse()
Default constructor.
Definition: colvarparse.cpp:35
std::map< std::string, key_set_mode > key_set_modes
Track which keywords have been already set, and how.
Definition: colvarparse.h:364
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.
Definition: colvarparse.cpp:139
std::string const & get_config() const
Get the configuration string (includes comments)
Definition: colvarparse.h:47
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:43
@ type_notset
Undefined type.
Definition: colvarvalue.h:54
Definition: colvars_memstream.h:30
Collective variables main module.
Functions to handle scalar parameters used in objects.
colvarparse::Parse_Mode operator|(colvarparse::Parse_Mode const &mode1, colvarparse::Parse_Mode const &mode2)
Bitwise OR between two Parse_mode flags.
Definition: colvarparse.h:389