C++QEDCore  2.100.2 (v2 Milestone 10 Development branch)
a framework for simulating open quantum dynamics – core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
parameters::ParameterTable Class Reference

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 ParameterBaseoperator[] (const std::string &) const
 Subscription by parameter name.
 
ParameterBaseoperator[] (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...
 
ParameterTableaddTitle (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...
 

Detailed Description

The parameter table according to which the command line will be parsed by update()

See also
userguideelementaryparameters in the userguide

Definition at line 134 of file Pars.h.

Member Function Documentation

template<typename T >
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.

See also
e.g. the implementation of trajectory::ParsEvolved::ParsEvolved()
Parameters
sparameter name (as appears in command line)
dparameter description (to be listed in help)
vparameter 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.

See also
trajectory::ParsRun::displayInfo – if --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.
template<typename T >
T& parameters::ParameterTable::addMod ( const std::string &  s,
const std::string &  mod,
const std::string &  d,
const T &  v 
)
inline

Adds the parameter with a modifier suffix – useful when many parameters are distinguished only by suffixes (e.g. numerical suffix)

See also
This and this section of the userguide

Definition at line 191 of file Pars.h.

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

Friends And Related Function Documentation

void update ( ParameterTable p,
int  argc,
char *  argv[],
const std::string &  prefix = "--" 
)
related

The function parsing the command line and putting the parameters into the ParameterTable.

Todo:
Somehow echo the whole command line into the output file – difficulty: the parameter-bundle has no knowledge about the output file
Parameters
argcnumber of words in the command line
argvcontent of the command line word by word
prefixprefix of parameters in the command line

The documentation for this class was generated from the following file: