1 #include "ErrorHandler/MessageAnalyzer/ma_cond_test_primary.h"
2 #include "ErrorHandler/MessageAnalyzer/ma_cond_test_expr.h"
4 using namespace novadaq::errorhandler;
7 bool compare(compare_op_t op, T v, T rhv)
34 void ma_cond_test_primary::insert_func(std::string
const& name, anys_t
const& args)
36 func.reset(ma_test_function_factory::create_instance(name));
40 if (!func->parse_arguments(args))
41 throw std::runtime_error(
"arguments rejected by test function " + name);
43 catch (std::exception& e)
45 throw std::runtime_error(
"arguments rejected by test function " + name +
"() with an exception:\n" + e.what());
51 void ma_cond_test_primary::insert_compare_op(compare_op_t cop, any_t
const& v)
55 if (v.type() ==
typeid(bool))
57 rhv_b = boost::any_cast<
bool>(v);
58 cond_type = FUNCTION_BOOL;
60 else if (v.type() ==
typeid(int))
62 rhv_d = boost::any_cast<
int>(v);
63 cond_type = FUNCTION_DOUBLE;
65 else if (v.type() ==
typeid(double))
67 rhv_d = boost::any_cast<
double>(v);
68 cond_type = FUNCTION_DOUBLE;
72 rhv_s = boost::any_cast<std::string>(v);
73 cond_type = FUNCTION_STRING;
77 bool ma_cond_test_primary::evaluate(
ma_condition const* cond)
const
79 if (cond_type == EXPR)
81 assert(expr.get() != NULL);
82 return expr->evaluate(cond);
86 any_t v = func->evaluate(*cond);
95 return boost::any_cast<
bool>(v);
98 b = boost::any_cast<
bool>(v);
99 return compare(op, b, rhv_b);
101 case FUNCTION_STRING:
102 s = boost::any_cast<std::string>(v);
103 return compare(op, s, rhv_s);
105 case FUNCTION_DOUBLE:
106 if (v.type() ==
typeid(int))
107 d = boost::any_cast<
int>(v);
108 else if (v.type() ==
typeid(
unsigned int))
109 d = boost::any_cast<
unsigned int>(v);
110 else if (v.type() ==
typeid(long))
111 d = boost::any_cast<
long>(v);
112 else if (v.type() ==
typeid(float))
113 d = boost::any_cast<
float>(v);
115 d = boost::any_cast<
double>(v);
117 return compare(op, d, rhv_d);
120 throw std::runtime_error(
"Unkonwn test primary type");