[ GAMB | Source | Keywords | Summary | Ancestors | All Members | Descendants ]
public: | |
enum | ParamType ; |
static void | readParameters(istream& paramStream); |
static bool | empty(); |
// Setting parameters | |
static void | addParameter(const string& paramName, const int value); |
static void | addParameter(const string& paramName, const double value); |
static void | addParameter(const string& paramName, const string& value); |
static void | updateParameter(const string& paramName, const char* const value); |
// Getting parameters values. | |
static ParamType | paramType(const string& paramName); |
static int | getInt(const string& paramName, const int& defaultValue ); |
static float | getFloat(const string& paramName, const float& defaultValue ); |
static string getString(const string& paramName, const string& | defaultValue )); |
// Other methods | |
static void | dump(ostream& out); |
static void | dump(DebugStream& out, const unsigned int msgLevel); |
static void | dump(FILE* outputFile); |
static string | nextToken(string& str); |
protected: | |
Parameters(); |
Copyright: SAMBA group, Tel-Aviv Univ. Israel, 1997.
Parameters::addParameter("Dummy", 3); Parameters::updateParameter("Dummy", "This should set it to zero"); cout << Parameters::getstring("Dummy");
Note also that when setting defuault values of float parameters always use a decimal point or else these parameters will be added as intgers. For example:
Parameters::addParameter("CubeSize", 1.0); OK Parameters::addParameter("CubeSize", 1); Not OK. Integer parameter
Parameters::addParameter("CubeSize", 1.0); Parameters::addParameter("MinVote", 8); ifstream params("params"); Parameters::readParameters(params); params.close(); Parameters::dump(cout);With the following parameters file:
CubeSize 0.5 File pdb4hhb.entThe following output should result:
CubeSize (Float) 0.5 File (Str) pdb4hhb.ent MinVote (Int) 8
Parameters::addParameter("MaxMix", 1); OK added an integer parameter cout << Parameters::getInt("MaxMix"); cout << Parameters::getFloat("MaxMix"); cout << Parameters::getstring("MaxMix");Also note that parameters names are case sensitive.
static int min_vote = 8; // Default values static float cube_size = 1.0; class ProgParams : protected Parameters { int minVote() { return min_vote }; float cubeSize() { return cube_size }; // file name is not held in static variable. Don't care about parameter // access time. string fileName() { return getstring("FileName"); } int readParameters(char* paramsfile) { addParameter("MinVote", min_vote); addParameter("CubeSize", cube_size); ifstream params(paramsfile); Parameters::readParameters(params); params.close(); min_vote = getInt("MinVote"); cube_size = getFloat("CubeSize"); } }
enum ParamType ;
Used by the paramType method. See below.
enum ParamType { Undef, Int, Float, Str };
void readParameters(istream& paramStream);
readParameters recieves an input stream and reads parameters off this
input stream. See the usage section for details of how a parameters
file may be structured.
static void readParameters(istream& paramStream);
Returns true if no parameters are defined.
static bool empty();
void addParameter(const string& paramName, const int value);
Adds an integer parameter. The integer value added will actually be
stored as an integer. Subsequent updates to the same parameter using
updateParameter will all be stored as integers.
static void addParameter(const string& paramName, const int value);
void addParameter(const string& paramName, const double value);
Adds a float parameter. The float value added will actually be
stored as a float. Subsequent updates to the same parameter using
updateParameter will all be stored as floats.
static void addParameter(const string& paramName, const double value);
void addParameter(const string& paramName, const string& value);
Adds a string parameter. The string value added will actually be
stored as a string. Subsequent updates to the same parameter using
updateParameter will all be stored as strings.
static void addParameter(const string& paramName, const string& value);
void updateParameter(const string& paramName, const char* const value);
Update the parameter value without changing the parameter type. The
value parameter is converted to the parameter's type if this parameter
already exists. If the parameter is not yet listed then updateParameter
adds a new parameter of string type.
static void updateParameter(const string& paramName, const char* const value);
ParamType paramType(const string& paramName);
Returns the storage type of the given parameter. If a parameter
of the given name does not exist then Undef is returned. See enum
ParamType above for possible return values.
static ParamType paramType(const string& paramName);
int getInt(const string& paramName, const int& defaultValue );
Gets the integer value of a given parameter. If parameter is not of
integer type then its value is converted to integer. If parameter does
not exist a 0 is returned.
static int getInt(const string& paramName, const int& defaultValue=0);
float getFloat(const string& paramName, const float& defaultValue );
Gets the float value of a given parameter. If parameter is not of
float type then its value is converted to float. If parameter does
not exist a 0 is returned.
static float getFloat(const string& paramName, const float& defaultValue=0.0);
string getString(const string& paramName, const string& defaultValue ));
Gets the string value of a given parameter. If parameter is not of
string type then its value is converted to string. If parameter does
not exist an empty string is returned.
static string getString(const string& paramName, const string& defaultValue=string());
void dump(ostream& out);
Output all listed parameters. Used for debugging.
static void dump(ostream& out);
void dump(DebugStream& out, const unsigned int msgLevel);
Output all listed parameters. Used for debugging.
static void dump(DebugStream& out, const unsigned int msgLevel);
Output all listed parameters.
static void dump(FILE* outputFile);
string nextToken(string& str);
A utility method. nextToken recieves an argument string, finds the first
white-space delimited token in this string and returns it while cutting
this token off of the argument string (It it passed by reference). Tokens
are returned without any spaces. This method may be used repetitively to
tokenize a string.
static string nextToken(string& str);
Parameters();
Constructor is protected since all methods are static. No need to
actually form an instance of this class.
Parameters();
public: | ||
---|---|---|
enum | ParamType ; | |
static void | readParameters(istream& paramStream); | |
static bool | empty(); | |
// Setting parameters | ||
static void | addParameter(const string& paramName, const int value); | |
static void | addParameter(const string& paramName, const double value); | |
static void | addParameter(const string& paramName, const string& value); | |
static void | updateParameter(const string& paramName, const char* const value); | |
// Getting parameters values. | ||
static ParamType | paramType(const string& paramName); | |
static int | getInt(const string& paramName, const int& defaultValue ); | |
static float | getFloat(const string& paramName, const float& defaultValue ); | |
static string getString(const string& paramName, const string& | defaultValue )); | |
// Other methods | ||
static void | dump(ostream& out); | |
static void | dump(DebugStream& out, const unsigned int msgLevel); | |
static void | dump(FILE* outputFile); | |
static string | nextToken(string& str); | |
protected: |
Report problems to jkotula@unimax.com