ColTypeNumeric: Migrated part of Task::modify to ::modify

This commit is contained in:
Paul Beckingham 2016-01-31 20:08:51 -05:00
parent b7a72c5252
commit 7525d4a921

View file

@ -26,6 +26,16 @@
#include <cmake.h> #include <cmake.h>
#include <ColTypeNumeric.h> #include <ColTypeNumeric.h>
#include <Context.h>
#include <Eval.h>
#include <Variant.h>
#include <Filter.h>
#include <Dates.h>
#include <text.h>
#include <i18n.h>
extern Context context;
extern Task& contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ColumnTypeNumeric::ColumnTypeNumeric () ColumnTypeNumeric::ColumnTypeNumeric ()
@ -51,7 +61,31 @@ void ColumnTypeNumeric::render (
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ColumnTypeNumeric::modify (Task& task, const std::string& value) void ColumnTypeNumeric::modify (Task& task, const std::string& value)
{ {
task.set (_name, value); // Try to evaluate 'value'. It might work.
Variant evaluatedValue;
try
{
Eval e;
e.addSource (domSource);
e.addSource (namedDates);
contextTask = task;
e.evaluateInfixExpression (value, evaluatedValue);
}
catch (...)
{
evaluatedValue = Variant (value);
}
std::string label = " MODIFICATION ";
context.debug (label + _name + " <-- '" + evaluatedValue.get_string () + "' <-- '" + value + "'");
// If the result is not readily convertible to a numeric value,
// then this is an error.
if (evaluatedValue.type () == Variant::type_string)
throw format (STRING_UDA_NUMERIC, evaluatedValue.get_string ());
task.set (_name, evaluatedValue);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////