1 #include "ErrorHandler/MessageAnalyzer/ma_cond_test_primary.h"
2 #include "ErrorHandler/MessageAnalyzer/ma_cond_test_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;
30 void ma_cond_test_primary::insert_func( std::string
const & name
31 , anys_t
const & args )
33 func.reset( ma_test_function_factory::create_instance(name) );
37 if( !func->parse_arguments( args ) )
38 throw std::runtime_error(
"arguments rejected by test function " + name);
40 catch (std::exception & e)
42 throw std::runtime_error(
"arguments rejected by test function " + name
43 +
"() with an exception:\n" + e.what() );
50 void ma_cond_test_primary::insert_compare_op( compare_op_t cop
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;
78 bool ma_cond_test_primary::evaluate(
ma_condition const * cond )
const
81 if( cond_type == EXPR )
83 assert( expr.get() != NULL );
84 return expr->evaluate( cond );
88 any_t v = func->evaluate( *cond );
97 return boost::any_cast<
bool>( v );
100 b = boost::any_cast<
bool>( v );
101 return compare( op, b, rhv_b );
103 case FUNCTION_STRING:
104 s = boost::any_cast<std::string>( v );
105 return compare( op, s, rhv_s );
107 case FUNCTION_DOUBLE:
108 if ( v.type()==
typeid(int) ) d = boost::any_cast<
int >( v );
109 else if( v.type()==
typeid(
unsigned int) )
110 d = boost::any_cast<
unsigned int>( v );
111 else if( v.type()==
typeid(long) ) d = boost::any_cast<
long >( v );
112 else if( v.type()==
typeid(float) ) d = boost::any_cast<
float >( v );
113 else d = boost::any_cast<
double >( v );
115 return compare( op, d, rhv_d );
118 throw std::runtime_error(
"Unkonwn test primary type");