Commit 6a0ed1c7 authored by Tom Perkins's avatar Tom Perkins
Browse files

Implement getPropertyAsSingleValue for valid strings

(Strings that can be parsed as a number)

re #17087
parent f7e11bf2
......@@ -335,6 +335,16 @@ double LogManager::getPropertyAsSingleValue(
if (convertSingleValue(log, singleValue) ||
convertTimeSeriesToDouble(log, singleValue, statistic)) {
return singleValue;
} else if (const auto stringLog =
dynamic_cast<const PropertyWithValue<std::string> *>(log)) {
// Try to lexically cast string to a double
try {
return std::stod(stringLog->value());
} catch (const std::invalid_argument &) {
throw std::invalid_argument(
"Run::getPropertyAsSingleValue - Property\"" + name +
"\"cannot be converted to a numeric value.");
}
} else {
throw std::invalid_argument(
"Run::getPropertyAsSingleValue - Property \"" + name +
......
......@@ -261,7 +261,7 @@ public:
runInfo.addProperty<std::string>(name, value);
double result = std::nan("1");
TS_ASSERT_THROWS_NOTHING(result = runInfo.getPropertyAsSingleValue(name));
TS_ASSERT_EQUALS(value, std::to_string(result));
TS_ASSERT_DELTA(1.0, result, 1e-12);
}
void test_GetPropertyAsSingleValue_TimeSeries_DoubleType() {
......
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