~ubuntu-branches/ubuntu/saucy/libbpp-core/saucy

« back to all changes in this revision

Viewing changes to src/Bpp/App/ApplicationTools.cpp

  • Committer: Package Import Robot
  • Author(s): Julien Dutheil
  • Date: 2012-02-09 13:00:00 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120209130000-je7bujslsp6ixsaw
Tags: 2.0.3-1
* New range classes
* Linear assigment method
* Improved string tokenizer and text tools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
  bool suffixIsOptional) throw (Exception)
78
78
{
79
79
  string filePath = getStringParameter(parameter, params, "none", suffix, suffixIsOptional, false);
80
 
  if(filePath == "") filePath = "none";
81
 
  if(filePath == "none" && isRequired)
 
80
  if (filePath == "") filePath = "none";
 
81
  if (filePath == "none" && isRequired)
82
82
  {
83
 
    throw Exception("You must specify a file for this parameter: " + parameter);
 
83
    throw Exception("You must specify a file for this parameter: " + parameter + (suffixIsOptional ? "" : suffix));
84
84
  }
85
85
  if(filePath == "none") return filePath;
86
86
  if(mustExist && !FileTools::fileExists(filePath))
101
101
  bool warn)
102
102
{
103
103
  double dParam = defaultValue;
104
 
  if(parameterExists(parameterName + suffix, params))
 
104
  if (parameterExists(parameterName + suffix, params))
105
105
  {
106
106
    dParam = TextTools::toDouble(params[parameterName + suffix]);
107
107
  }
108
 
  else if(suffixIsOptional && parameterExists(parameterName, params))
 
108
  else if (suffixIsOptional && parameterExists(parameterName, params))
109
109
  {
110
110
    dParam = TextTools::toDouble(params[parameterName]);
111
111
  }
127
127
  bool warn)
128
128
{
129
129
  int iParam = defaultValue;
130
 
  if(parameterExists(parameterName + suffix, params)) {
 
130
  if (parameterExists(parameterName + suffix, params)) {
131
131
    iParam = TextTools::toInt(params[parameterName + suffix]);
132
132
  } else if(suffixIsOptional && parameterExists(parameterName, params)) {
133
133
    iParam = TextTools::toInt(params[parameterName]);
134
 
  } else if(warn) {
 
134
  } else if (warn) {
135
135
    displayWarning("Parameter " + parameterName + suffix + " not specified. Default used instead: " + TextTools::toString(defaultValue));
136
136
  }
137
137
  return iParam;
150
150
  string sParam = defaultValue;
151
151
  if (parameterExists(parameterName + suffix, params)) {
152
152
    sParam = params[parameterName + suffix];
153
 
  } else if(suffixIsOptional && parameterExists(parameterName, params)) {
 
153
  } else if (suffixIsOptional && parameterExists(parameterName, params)) {
154
154
    sParam = params[parameterName];
155
 
  } else if(warn) {
 
155
  } else if (warn) {
156
156
    displayWarning("Parameter " + parameterName + " not specified. Default used instead: " + defaultValue);
157
157
  }
158
158
  return sParam;
182
182
        || (sParam == "Y")
183
183
        || (sParam == "1");
184
184
  }
185
 
  else if(suffixIsOptional && parameterExists(parameterName, params)) {
 
185
  else if (suffixIsOptional && parameterExists(parameterName, params)) {
186
186
    string sParam = params[parameterName];
187
187
    bParam = (sParam == "true") 
188
188
        || (sParam == "TRUE")
194
194
        || (sParam == "Y")
195
195
          || (sParam == "1");
196
196
  }
197
 
  else if(warn)
 
197
  else if (warn)
198
198
  {
199
199
    displayWarning("Parameter " + parameterName + " not specified. Default used instead: " + TextTools::toString(defaultValue));
200
200
  }
223
223
 
224
224
/******************************************************************************/
225
225
 
226
 
void ApplicationTools::displayGauge(unsigned int iter, unsigned int total, char symbol, const std::string& mes)
 
226
void ApplicationTools::displayGauge(size_t iter, size_t total, char symbol, const std::string& mes)
227
227
{
228
228
  if (!message) return;
229
229
  if (total == 0) return;//We do not display anything in that case.
230
 
  unsigned int width = static_cast<unsigned int>(terminalWidth * terminalSplit - 2);
231
 
  string gauge = string(static_cast<unsigned int>(width * iter / total), symbol);
 
230
  size_t width = static_cast<size_t>(terminalWidth * terminalSplit - 2);
 
231
  string gauge = string(static_cast<unsigned int>((1. * iter / total) * width), symbol);
232
232
  string info = mes;
233
233
  if (interactive)
234
234
  {
235
235
    string fill = string(width - gauge.length(), ' ');
236
236
    gauge = "[" + gauge + fill + "] " + TextTools::resizeLeft(TextTools::toString(100 * iter / total), 3) + "%";
237
 
    if (mes.size() > 80 - gauge.size())
238
 
      info = TextTools::resizeRight(mes, 80 - gauge.size());
 
237
    if (mes.size() > terminalWidth - gauge.size())
 
238
      info = TextTools::resizeRight(mes, terminalWidth - gauge.size());
239
239
    *message << '\r' + info + gauge;
240
240
    message->flush();
241
241
  }
247
247
      message->flush();
248
248
      return;
249
249
    }
250
 
    unsigned int step = static_cast<unsigned int>(ceil((double)total / width));
 
250
    size_t step = static_cast<size_t>(ceil(1. * total / width));
251
251
    if (iter >= total)
252
252
    {
253
 
      unsigned int fill = static_cast<unsigned int>(terminalWidth * terminalSplit) - (total - 1) / step - 1;
 
253
      size_t fill = static_cast<size_t>(terminalWidth * terminalSplit) - (total - 1) / step - 1;
254
254
      *message << TextTools::resizeLeft("]", fill, symbol);
255
255
      message->flush();
256
256
      return;
257
257
    }
258
 
    unsigned int x = iter % step;
 
258
    size_t x = iter % step;
259
259
    if (x == 0) { *message << symbol; message->flush(); }
260
260
  }
261
261
}
262
262
 
263
263
/******************************************************************************/
264
264
 
265
 
void ApplicationTools::displayUnlimitedGauge(unsigned int iter, const std::string& mes)
 
265
void ApplicationTools::displayUnlimitedGauge(size_t iter, const std::string& mes)
266
266
{
267
267
  if (!message) return;
268
268
  string chars = "-/-\\";