The parameter table according to which the command line will be parsed by update() More...
#include <Pars.h>
Public Types | |
typedef std::shared_ptr< std::string > | ParsedCommandLine |
Type for passing the parsed command line throughout the framework. | |
Public Member Functions | |
void | printList () const |
Print a full list of Parameters in help with name, typeID, description, and (default) value. More... | |
std::stringstream & | getStream () |
The stream whereon parameter i/o occurs (an intermediary stringstream ) is exposed in order that i/o manipulators can be applied. | |
const ParsedCommandLine | getParsedCommandLine () const |
Getter for the full command line set by the update() function. | |
void | setParsedCommandLine (const std::string &s) |
Setter for the full command line used by the update() function. | |
Subscription | |
const ParameterBase & | operator[] (const std::string &) const |
Subscription by parameter name. | |
ParameterBase & | operator[] (const std::string &s) |
” non-const version | |
Adders | |
template<typename T > | |
T & | add (const std::string &s, const std::string &d, const T &v) |
generic version More... | |
bool & | add (const std::string &s, const std::string &d, bool v) |
Overload of add(const std::string &, const std::string &, const T &) for boolean. More... | |
template<typename T > | |
T & | addMod (const std::string &s, const std::string &mod, const std::string &d, const T &v) |
Adds the parameter with a modifier suffix – useful when many parameters are distinguished only by suffixes (e.g. numerical suffix) More... | |
ParameterTable & | addTitle (const std::string &s, const std::string &mod="") |
This adds a dummy “parameter” whose only effect is to cause a newline and a title to be printed for grouping parameters belonging to different modules in parameter listing. | |
Related Functions | |
(Note that these are not member functions.) | |
void | update (ParameterTable &p, int argc, char *argv[], const std::string &prefix="--") |
The function parsing the command line and putting the parameters into the ParameterTable. More... | |
The parameter table according to which the command line will be parsed by update()
T& parameters::ParameterTable::add | ( | const std::string & | s, |
const std::string & | d, | ||
const T & | v | ||
) |
generic version
In function scope, if p
is a ParameterTable, then, e.g. a call like
double & omega=p.add("omega","harmonic oscillator mode frequency",1.);
will add a parameter of type double
to the ParameterTable, so that if on the highest level of the application the command line gets parsed with the update() function like
int main(int argc, char* argv[]) { // ParameterTable p declared and filled with omega with p.add(...) as above // parsing the command line according to p update(p,argc,argv,"--"); // ... operations involving omega }
then, when starting the program from the command line, the value of omega
can be specified with e.g. --omega 10.
, while if unspecified, the value will be the default 1
. When starting the program with --help
, omega
, with all other parameters will be listed in a nice tabulated format with the specified description and default value.
In addition, the reference omega
serves as a convenient handle for further operations involving omega in the program.
s | parameter name (as appears in command line) |
d | parameter description (to be listed in help) |
v | parameter default value |
bool& parameters::ParameterTable::add | ( | const std::string & | s, |
const std::string & | d, | ||
bool | v | ||
) |
Overload of add(const std::string &, const std::string &, const T &) for boolean.
This will create a switch, that does not require any value. It will also add to the ParameterTable an additional parameter of type BooleanNegatedProxy which is the opposite switch with a no_
prefix.
--displayInfo
is present in the command line, the switch will have true
value, but if --no_displayInfo
is also present subsequently, the value will be false
.
|
inline |
void parameters::ParameterTable::printList | ( | ) | const |
Print a full list of Parameters in help with name, typeID, description, and (default) value.
Invoked by update() if the switch --help
is found in the command line
|
related |
The function parsing the command line and putting the parameters into the ParameterTable.
argc | number of words in the command line |
argv | content of the command line word by word |
prefix | prefix of parameters in the command line |