2 #include "ErrorHandler/MessageAnalyzer/ma_boolean_cond.h"
3 #include "ErrorHandler/MessageAnalyzer/ma_boolean_expr.h"
5 using namespace novadaq::errorhandler;
8 bool compare(compare_op_t op, T v, T rhv)
29 typedef std::vector<boost::any> anys_t;
31 void ma_boolean_cond::insert_ext_func(cond_idx_t ci, arg_t arg, anys_t
const& func_args, std::string
const&
function)
34 cond_arg.second = arg;
36 ext_func.reset(ma_function_factory::create_instance(
function));
38 if (!ext_func->parse_arguments(func_args))
39 throw std::runtime_error(
"arguments rejected by " +
function);
42 void ma_boolean_cond::reset()
44 if (cond_type == EXPR)
47 assert(expr.get() != NULL);
51 if (cond_type == COND)
56 if (cond_type >= FUNCTION)
59 assert(ext_func.get() != NULL);
61 return ext_func->reset();
64 throw std::runtime_error(
"ma_boolean_cond::reset(): unknow cond_type");
67 bool ma_boolean_cond::evaluate(ma_domain& value, ma_domain& alarm, ma_domain
const& domain)
const
69 if (cond_type == EXPR)
72 assert(expr.get() != NULL);
75 return expr->evaluate(value, alarm, domain);
78 if (cond_type == COND)
80 cond_idx_t cond_idx = cond_arg.first;
83 assert(cond_idx.first != NULL);
86 if (domain_is_null(alarm[cond_idx.second]))
87 alarm[cond_idx.second] = value[cond_idx.second];
90 return cond_idx.first->get_status(value[cond_idx.second]);
93 if (cond_type >= FUNCTION)
95 cond_idx_t cond_idx = cond_arg.first;
98 assert(cond_idx.first != NULL);
101 assert(ext_func.get() != NULL);
104 if (ext_func->grouped_alarm())
106 alarm[cond_idx.second] = domain[cond_idx.second];
110 alarm[cond_idx.second] =
111 ma_cond_domain(cond_idx.first->find_source(cond_idx.first->get_msg_source()), cond_idx.first->find_target(cond_idx.first->get_qt_mf_msgarget()));
115 boost::any v = ext_func->evaluate(*(cond_idx.first), domain[cond_idx.second]);
123 b = boost::any_cast<
bool>(v);
127 b = boost::any_cast<
bool>(v);
128 return compare(op, b, rhv_b);
130 case FUNCTION_STRING:
131 s = boost::any_cast<std::string>(v);
132 return compare(op, s, rhv_s);
134 case FUNCTION_DOUBLE:
135 if (v.type() ==
typeid(int))
136 d = boost::any_cast<
int>(v);
138 d = boost::any_cast<
double>(v);
139 return compare(op, d, rhv_d);
146 throw std::runtime_error(
"ma_boolean_cond::evaluate(): unknow cond_type");