2 #include "ErrorHandler/MessageAnalyzer/ma_boolean_cond.h"
3 #include "ErrorHandler/MessageAnalyzer/ma_boolean_expr.h"
5 using namespace novadaq::errorhandler;
9 compare(compare_op_t op, T v, T rhv)
13 case CO_L:
return (v < rhv);
14 case CO_LE:
return (v <= rhv);
15 case CO_E:
return (v == rhv);
16 case CO_NE:
return (v != rhv);
17 case CO_GE:
return (v >= rhv);
18 case CO_G:
return (v > rhv);
19 default:
return false;
23 typedef std::vector<boost::any> anys_t;
25 void ma_boolean_cond::insert_ext_func( cond_idx_t ci
27 , anys_t
const & func_args
28 , std::string
const &
function )
31 cond_arg.second = arg;
33 ext_func.reset( ma_function_factory::create_instance(
function) );
35 if( !ext_func->parse_arguments( func_args ) )
36 throw std::runtime_error(
"arguments rejected by " +
function );
39 void ma_boolean_cond::reset( )
41 if( cond_type == EXPR )
44 assert( expr.get() != NULL );
48 if( cond_type == COND )
53 if( cond_type >= FUNCTION )
56 assert( ext_func.get() != NULL );
58 return ext_func->reset();
62 throw std::runtime_error(
"ma_boolean_cond::reset(): unknow cond_type");
66 bool ma_boolean_cond::evaluate( ma_domain & value
68 , ma_domain
const & domain )
const
70 if( cond_type == EXPR )
73 assert( expr.get() != NULL );
76 return expr->evaluate(value, alarm, domain);
79 if( cond_type == COND )
81 cond_idx_t cond_idx = cond_arg.first;
84 assert( cond_idx.first != NULL );
87 if( domain_is_null(alarm[cond_idx.second]) )
88 alarm[cond_idx.second] = value[cond_idx.second];
91 return cond_idx.first->get_status(value[cond_idx.second]);
94 if( cond_type >= FUNCTION )
96 cond_idx_t cond_idx = cond_arg.first;
99 assert( cond_idx.first != NULL );
102 assert( ext_func.get() != NULL );
105 if( ext_func->grouped_alarm() )
107 alarm[cond_idx.second] = domain[cond_idx.second];
111 alarm[cond_idx.second] =
112 ma_cond_domain( cond_idx.first->find_source( cond_idx.first->get_msg_source() )
113 , cond_idx.first->find_target( cond_idx.first->get_qt_mf_msgarget() ) );
117 boost::any v = ext_func->evaluate( *(cond_idx.first)
118 , domain[cond_idx.second] );
126 b = boost::any_cast<
bool>(v);
130 b = boost::any_cast<
bool>(v);
131 return compare( op, b, rhv_b );
133 case FUNCTION_STRING:
134 s = boost::any_cast<std::string>(v);
135 return compare( op, s, rhv_s );
137 case FUNCTION_DOUBLE:
138 if( v.type() ==
typeid(int) ) d = boost::any_cast<
int>(v);
139 else d = boost::any_cast<
double>(v);
140 return compare( op, d, rhv_d );
146 throw std::runtime_error(
"ma_boolean_cond::evaluate(): unknow cond_type");