WSL/SLF GitLab Repository

Commit 3b38f1ae authored by Thomas Egger's avatar Thomas Egger
Browse files

libsmet: a new convert_to_double implementation, based on strtod from the...

libsmet: a new convert_to_double implementation, based on strtod from the cstdlib, cuts conversion time to about a fourth of the stringstream implementation.
parent c164fcd6
......@@ -82,11 +82,14 @@ bool SMETCommon::initStaticData()
double SMETCommon::convert_to_double(const std::string& in_string)
{
istringstream ss(in_string);
double value;
if (!(ss >> value)) throw SMETException("Value \"" + in_string + "\" cannot be converted to double", SMET_AT);
char* end;
double value = strtod(in_string.c_str(),&end);
return value;
if (*end == '\0') {
return value;
} else {
throw SMETException("Value \"" + in_string + "\" cannot be converted to double", SMET_AT);
}
}
int SMETCommon::convert_to_int(const std::string& in_string)
......
......@@ -21,6 +21,7 @@
#include <meteoio/IOUtils.h> //HACK: move FileIndexer in a plugins specific file
#include <cmath>
#include <cstdlib>
#include <string>
#include <sstream>
#include <iostream>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment