38 string paramfile::get_valstr(
const string &key)
const 40 params_type::const_iterator loc=params.find(key);
41 if (loc!=params.end())
return loc->second;
45 bool paramfile::param_unread (
const string &key)
const 46 {
return (read_params.find(key)==read_params.end()); }
48 paramfile::paramfile (
const string &filename,
bool verbose_)
52 paramfile::paramfile (
const params_type &par,
bool verbose_)
53 : params (par), verbose(verbose_)
56 paramfile::~paramfile()
59 for (params_type::const_iterator loc=params.begin();
60 loc!=params.end(); ++loc)
61 if (param_unread(loc->first))
62 cout <<
"Parser warning: unused parameter '" 63 << loc->first <<
"'" << endl;
67 {
return (params.find(key)!=params.end()); }
69 void paramfile::findhelper (
const string &key,
const string &value,
NDT type,
72 string output = value;
73 if (type==NAT_STRING) output =
"'"+output+
"'";
74 if (verbose && param_unread(key))
75 cout <<
"Parser: " << key <<
" = " << output
76 << (deflt ?
" <default>" :
"") << endl;
77 read_params.insert(key);
82 T result = stringToData<T>(get_valstr(key));
83 findhelper (key,
dataToString(result), nativeType<T>(),
false);
103 template<
typename T> T
paramfile::find (
const string &key,
const T &deflt)
107 findhelper (key, sdeflt, nativeType<T>(),
true);
113 const unsigned char &deflt);
115 const signed char &deflt);
117 const unsigned short &deflt);
118 template short paramfile::find (
const string &key,
const short &deflt);
120 const unsigned int &deflt);
123 const unsigned long &deflt);
126 const unsigned long long &deflt);
127 template long long paramfile::find (
const string &key,
const long long &deflt);
128 template float paramfile::find (
const string &key,
const float &deflt);
129 template double paramfile::find (
const string &key,
const double &deflt);
131 const long double &deflt);
133 template string paramfile::find (
const string &key,
const string &deflt);
135 void paramfile::setParamString (
const string &key,
const string &value)
139 if (params[key]!=value)
142 cout <<
"Parser: altering value of key '"<<key<<
"' to '"<<value<<
"'." 150 cout <<
"Parser: setting new key '"<<key<<
"' to '"<<value<<
"'."<<endl;
158 if ((argc==2) && (
string(argv[1]).find(
"=")==string::npos))
160 map<string,string> pmap;
161 parse_cmdline_equalsign(argc,argv,pmap);
T find(const std::string &key) const
paramfile getParamsFromCmdline(int argc, const char **argv, bool verbose=true)
bool param_present(const std::string &key) const
void parse_file(const std::string &filename, std::map< std::string, std::string > &dict)
string dataToString(const T &x)
#define planck_assert(testval, msg)