1 ///////////////////////////////////////////////////////////////////////////
5 // This file is part of starlight.
7 // starlight is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
12 // starlight is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with starlight. If not, see <http://www.gnu.org/licenses/>.
20 ///////////////////////////////////////////////////////////////////////////
22 // File and Version Information:
23 // $Rev:: $: revision of last commit
24 // $Author:: $: author of last commit
25 // $Date:: $: date of last commit
31 ///////////////////////////////////////////////////////////////////////////
42 #include <reportingUtils.h>
55 int parseFile(std::string filename);
58 int parseString(std::string str);
60 /** Add parameter to pass */
61 void addIntParameter(std::string name, int *var, bool required = true);
63 /** Add parameter to pass */
64 void addUintParameter(std::string name, unsigned int *var, bool required = true);
66 /** Add parameter to pass */
67 void addFloatParameter(std::string name, float *var, bool required = true);
69 /** Add parameter to pass */
70 void addDoubleParameter(std::string name, double *var, bool required = true);
72 /** Add parameter to pass */
73 void addBoolParameter(std::string name, bool *var, bool required = true);
75 /** Add parameter to pass */
76 void addStringParameter(std::string name, std::string *var, bool required = true);
79 void printParameterInfo(std::ostream &out = std::cout);
82 bool validateParameters(std::ostream &warnOut = std::cout, std::ostream &errOut = std::cerr);
84 /** Add a parameter */
86 inline void addParameter(S ¶m);
88 /** Add a parameter */
90 inline void addParameter(const std::string &name, P *varPtr, bool required = false);
98 _parameter(std::string name, T *val, bool required = true, bool found = false) : _name(name), _val(val), _required(required), _found(found){}
100 bool operator==(const _parameter &rhs) const { return _name == rhs._name; }
102 bool operator<(const _parameter &rhs) const { return _name.c_str()[0] < rhs._name.c_str()[0]; }
104 void printParameterInfo(std::ostream &out = std::cout)
106 out << std::boolalpha << _name << "\t\t";
109 out << *_val << std::endl;
113 out << "NOT FOUND" << std::endl;
115 out << std::noboolalpha;
125 std::map<std::string, _parameter<int> > _intParameters;
126 std::map<std::string, _parameter<unsigned int> > _uintParameters;
127 std::map<std::string, _parameter<float> > _floatParameters;
128 std::map<std::string, _parameter<double> > _doubleParameters;
129 std::map<std::string, _parameter<bool> > _boolParameters;
130 std::map<std::string, _parameter<std::string> > _stringParameters;
135 void inputParser::addParameter(S& param)
137 addParameter(param.name(), param.ptr(), param.required());
142 void inputParser::addParameter(const std::string& name, P* /*varPtr*/, bool /*required*/)
144 printWarn << "Trying to add unknown parameter type with name: " << name;
148 #endif // INPUTPARSER_H