Skip to content
Snippets Groups Projects
Commit 22dbb6e1 authored by Russell Taylor's avatar Russell Taylor
Browse files

Re #8669. Create an integer-typed log if appropriate.

If the value passed in can be converted to an integer then create a
PropertyWithValue<int> or TimeSeriesProperty<int> for the 'Number' &
'Number Series' options respectively.
parent ca524753
No related branches found
No related tags found
No related merge requests found
...@@ -66,33 +66,54 @@ void AddSampleLog::exec() ...@@ -66,33 +66,54 @@ void AddSampleLog::exec()
// Remove any existing log // Remove any existing log
if (theRun.hasProperty(propName)) if (theRun.hasProperty(propName))
{
theRun.removeLogData(propName); theRun.removeLogData(propName);
}
if (propType == "String") if (propType == "String")
{ {
theRun.addLogData(new PropertyWithValue<std::string>(propName, propValue)); theRun.addLogData(new PropertyWithValue<std::string>(propName, propValue));
return;
}
bool valueIsInt(false);
int intVal;
double dblVal;
if ( Strings::convert(propValue, intVal) )
{
valueIsInt = true;
} }
else if (propType == "Number") else if ( !Strings::convert(propValue, dblVal) )
{ {
double val; throw std::invalid_argument("Error interpreting string '" + propValue + "' as a number.");
if (!Strings::convert(propValue, val)) }
throw std::invalid_argument("Error interpreting string '" + propValue + "' as a number.");
theRun.addLogData(new PropertyWithValue<double>(propName, val)); if (propType == "Number")
{
if (valueIsInt) theRun.addLogData(new PropertyWithValue<int>(propName, intVal));
else theRun.addLogData(new PropertyWithValue<double>(propName, dblVal));
} }
else if (propType == "Number Series") else if (propType == "Number Series")
{ {
double val;
if (!Strings::convert(propValue, val))
throw std::invalid_argument("Error interpreting string '" + propValue + "' as a number.");
Kernel::DateAndTime startTime; Kernel::DateAndTime startTime;
try { try {
startTime = theRun.startTime(); startTime = theRun.startTime();
} catch (std::runtime_error&) { } catch (std::runtime_error&) {
// Swallow the error - startTime will just be 0 // Swallow the error - startTime will just be 0
} }
TimeSeriesProperty<double> * tsp = new TimeSeriesProperty<double>(propName);
tsp->addValue(startTime, val); if (valueIsInt)
theRun.addLogData(tsp); {
auto tsp = new TimeSeriesProperty<int>(propName);
tsp->addValue(startTime, intVal);
theRun.addLogData(tsp);
}
else
{
auto tsp = new TimeSeriesProperty<double>(propName);
tsp->addValue(startTime, dblVal);
theRun.addLogData(tsp);
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment