20 #ifndef JDFTX_COMMAND_PARAMLIST_H 21 #define JDFTX_COMMAND_PARAMLIST_H 38 void rewind() { iss.seekg(0, std::ios_base::beg); }
48 void get(T& t, T tDefault,
string paramName,
bool required=
false)
51 if(iss.bad())
throw string(
"I/O error while reading parameter <"+paramName+
">.");
54 if(required)
throw string(
"Parameter <"+paramName+
"> must be specified.");
57 if(iss.fail()) { t = tDefault;
throw string(
"Conversion of parameter <"+paramName+
"> failed."); }
68 void get(T& t, T tDefault,
const EnumStringMap<T>& tMap,
string paramName,
bool required=
false)
72 if(iss.bad())
throw string(
"I/O error while reading parameter <"+paramName+
">.");
75 if(required)
throw string(
"Parameter <"+paramName+
"> must be specified.");
78 if(!tMap.getEnum(key.c_str(), t))
80 throw string(
"Parameter <"+paramName+
"> must be one of "+tMap.optionList());
86 {
if(iss.eof())
return string();
87 size_t curPos = iss.tellg();
88 iss.seekg(0, std::ios_base::end);
89 size_t endPos = iss.tellg();
91 {
string buf(endPos-curPos, 0);
93 iss.read(&buf.at(0), buf.length());
101 #endif //JDFTX_COMMAND_PARAMLIST_H A template to ease option parsing (maps enums <–> strings)
Definition: Util.h:179
void rewind()
Rewind to beginning of stream (useful for commands with multiple alternate syntaxes) ...
Definition: ParamList.h:38
string getRemainder()
Get the section of the input string not yet parsed.
Definition: ParamList.h:85
void trim(string &s)
Remove leading and trailing spaces from a string.
Definition: string.h:45
Wrapper to std::istringstream that eases parsing of input file command lines.
Definition: ParamList.h:30
ParamList(string params)
Construct given the string with all the parameters.
Definition: ParamList.h:35
std::basic_string< char, ichar_traits > string
Case-insensitive string.
Definition: string.h:42