64 const std::string & parameterName,
65 std::map<std::string, std::string>& params)
67 return (params.find(parameterName) != params.end() && !
TextTools::isEmpty(params[parameterName]));
71 const std::string & parameterName,
72 std::vector<std::string>& params)
74 for (
size_t i = 0; i < params.size(); ++i)
75 if (params[i] == parameterName)
87 map<string, string>::iterator it;
88 for (it=params.begin(); it!=params.end(); it++)
92 string parn = it->first;
102 pos2 = parn.find(g, pos1);
103 if (pos2 == string::npos)
108 pos1 = pos2 + g.length();
111 ((g.length() == 0) || (pos1 == parn.length()) || (parn.rfind(g) == parn.length() - g.length())))
112 retv.push_back(parn);
122 for (
size_t i=0;i<params.size();i++)
126 string parn = params[i];
136 pos2 = parn.find(g, pos1);
137 if (pos2 == string::npos)
142 pos1 = pos2 + g.length();
145 ((g.length() == 0) || (pos1 == parn.length()) || (parn.rfind(g) == parn.length() - g.length())))
146 retv.push_back(parn);
155 const string& parameter,
156 map<string, string>& params,
159 const string& suffix,
160 bool suffixIsOptional,
161 const string& defaultPath,
164 string filePath = getStringParameter(parameter, params, defaultPath, suffix, suffixIsOptional, warn);
165 if (filePath ==
"") filePath =
"none";
166 if (filePath ==
"none" && isRequired)
168 throw Exception(
"You must specify a file for this parameter: " + parameter + (suffixIsOptional ?
"" : suffix));
170 if(filePath ==
"none")
return filePath;
173 throw Exception(
"File does not exists: " + filePath);
181 const std::string& parameterName,
182 std::map<std::string, std::string>& params,
184 const std::string& suffix,
185 bool suffixIsOptional,
188 double dParam = defaultValue;
189 if (parameterExists(parameterName + suffix, params))
193 else if (suffixIsOptional && parameterExists(parameterName, params))
197 else if(warn <= warningLevel)
199 displayWarning(
"Parameter " + parameterName + suffix +
" not specified. Default used instead: " +
TextTools::toString(defaultValue));
207 const std::string & parameterName,
208 std::map<std::string, std::string> & params,
210 const std::string & suffix,
211 bool suffixIsOptional,
214 int iParam = defaultValue;
215 if (parameterExists(parameterName + suffix, params)) {
217 }
else if(suffixIsOptional && parameterExists(parameterName, params)) {
219 }
else if (warn <= warningLevel) {
220 displayWarning(
"Parameter " + parameterName + suffix +
" not specified. Default used instead: " +
TextTools::toString(defaultValue));
228 const std::string& parameterName,
229 std::map<std::string, std::string>& params,
230 const std::string& defaultValue,
231 const std::string& suffix,
232 bool suffixIsOptional,
235 string sParam = defaultValue;
236 if (parameterExists(parameterName + suffix, params)) {
237 sParam = params[parameterName + suffix];
238 }
else if (suffixIsOptional && parameterExists(parameterName, params)) {
239 sParam = params[parameterName];
240 }
else if (warn <= warningLevel) {
241 displayWarning(
"Parameter " + parameterName +
" not specified. Default used instead: " + defaultValue);
249 const std::string& parameterName,
250 std::map<std::string, std::string>& params,
252 const std::string& suffix,
253 bool suffixIsOptional,
257 bool bParam = defaultValue;
258 if (parameterExists(parameterName + suffix, params))
260 sParam = params[parameterName + suffix];
262 else if (suffixIsOptional && parameterExists(parameterName, params))
264 sParam = params[parameterName];
267 if (warn <= warningLevel)
269 displayWarning(
"Parameter " + parameterName +
" not specified. Default used instead: " +
TextTools::toString(defaultValue));
273 if ((sParam ==
"true")
274 || (sParam ==
"TRUE")
283 else if ((sParam ==
"false")
284 || (sParam ==
"FALSE")
293 else throw Exception(
"ApplicationTools::getBooleanParameter. Wrong description:" + sParam);
310 *message << TextTools::resizeRight(text, static_cast<size_t>(
static_cast<float>(terminalWidth) * terminalSplit - 1),
'.') <<
": ";
311 if (eof) message->endLine();
312 else message->flush();
322 if (!message)
return;
323 if (total == 0)
return;
324 size_t width =
static_cast<size_t>(
static_cast<float>(terminalWidth) * terminalSplit - 2);
325 string gauge = string(static_cast<size_t>((1. * static_cast<double>(iter) / static_cast<double>(total)) * static_cast<double>(width)), symbol);
327 size_t step =
static_cast<size_t>(ceil(1. * static_cast<double>(total) / static_cast<double>(width)));
328 size_t x = iter % step;
331 string fill = string(width - gauge.length(),
' ');
333 if (mes.size() > terminalWidth - gauge.size())
335 if (x == 0 || iter == total) { *message <<
'\r' + info + gauge; message->flush(); }
347 size_t fill =
static_cast<size_t>(
static_cast<float>(terminalWidth) * terminalSplit) - (total - 1) / step - 1;
352 if (x == 0) { *message << symbol; message->flush(); }
360 if (!message)
return;
361 string chars =
"-/-\\";
365 unsigned int i = iter % 4;
387 double nsec = difftime(endTime, startTime);
388 double nmin = floor(nsec/60.);
389 double nhou = floor(nmin/60.);
390 double nday = floor(nhou/24.);
391 nhou = nhou - nday * 24;
392 nmin = nmin - (nday * 24 + nhou) * 60;
393 nsec = nsec - ((nday * 24 + nhou) * 60 + nmin) * 60;
394 *message << msg <<
" ";
395 *message << nday <<
"d, ";
396 *message << nhou <<
"h, ";
397 *message << nmin <<
"m, ";
398 *message << nsec <<
"s.";
409 return difftime(endTime, startTime);
static std::string resizeLeft(const std::string &s, size_t newSize, char fill=' ')
Send a string of size 'newSize', which is a copy of 's' truncated or filled with character 'fill' at ...
This class allows to perform a correspondence analysis.
bool hasMoreToken() const
Tell if some tokens are still available.
static std::string resizeRight(const std::string &s, size_t newSize, char fill=' ')
Send a string of size 'newSize', which is a copy of 's' truncated or filled with character 'fill' at ...
const std::string & nextToken()
Get the next available token. If no token is availbale, throw an Exception.
static std::string toString(T t)
General template method to convert to a string.
static int toInt(const std::string &s, char scientificNotation='e')
Convert from string to int.
static bool isEmpty(const std::string &s)
Tell if a string is empty.
static double toDouble(const std::string &s, char dec='.', char scientificNotation='e')
Convert from string to double.