A simple class for reading some parameter values from a stream. More...
#include "mutator.h"
#include <iosfwd>
#include <string>
Go to the source code of this file.
Classes | |
class | MutableVars |
Functions | |
template<class T > | |
void | AddVar (MutableVars &MV, const std::string &name, T &v) |
template<class T > | |
void | AddVar (MutableVars &MV, const char *name, T &v) |
A simple class for reading some parameter values from a stream.
Purpose: say you have a number of numerical parameters declared in your program, i.e. an instance of a class for which you want sometimes to read in a different value than the predefined one. Then you could set up a huge parameter file which is scanned at startup time and where you give a value for each variable you want to be able to change sometimes. This is very errorprone, because you have to remember the ordering of the variables, the parameter file is not well readable (you cannot associate values with variables) and is larger then it has to be.
MutableVars MV; // define one instance of the bookkeeping class double x; myclass A; // a variable of some class readable with >> A AddVar(MV, "x",x); // add x to database AddVar(MV, "A",A); // add A to database ... MV.ReadValues(param_file); // read a parameter file ...
x 0.123456 ... A <data of A>
void AddVar | ( | MutableVars & | MV, | |
const char * | name, | |||
T & | v | |||
) | [inline] |
References AddVar().
void AddVar | ( | MutableVars & | MV, | |
const std::string & | name, | |||
T & | v | |||
) | [inline] |
References MutableVars::AddVariable(), and GetMutator().
Referenced by AddVar().