void TAO_Constraint_Evaluator::do_the_op (int operation) { TAO_Literal_Constraint& l_op = this->queue_.get_left_operand (); TAO_Literal_Constraint& r_op = this->queue_.get_right_operand (); // Perform the listed bindary operation on the first two elements on // the stack. TAO_Literal_Constraint result = (operation <= TAO_NE) ? TAO_Literal_Constraint ((CORBA::Boolean) ((operation == TAO_GT) ? l_op > r_op : (operation == TAO_GE) ? l_op >= r_op : (operation == TAO_LT) ? l_op < r_op : (operation == TAO_LE) ? l_op <= r_op : (operation == TAO_NE) ? l_op != r_op : (operation == TAO_EQ) ? l_op == r_op : 0)) : ((operation == TAO_PLUS) ? l_op + r_op : (operation == TAO_MINUS) ? l_op - r_op : (operation == TAO_MULT) ? l_op * r_op : (operation == TAO_DIV) ? l_op / r_op : TAO_Literal_Constraint ()); this->queue_.dequeue_operand (); this->queue_.dequeue_operand (); this->queue_.enqueue_head (result); }
int TAO_Trader_Constraint_Evaluator:: visit_property (TAO_Property_Constraint* literal) { int return_value = -1, prop_index = 0; // Handle case where property is not, in fact, mapped to a value CORBA::String_var prop_name ((const char*) literal->name ()); if (this->props_.find (prop_name, prop_index) == 0) { CORBA::Any *value = 0; // Retrieve the value of the property from the Property_Evaluator try { value = this->prop_eval_.property_value (prop_index); } catch (const CORBA::Exception&) { return -1; } if (value != 0) { this->queue_.enqueue_head (TAO_Literal_Constraint (value)); return_value = 0; } } return return_value; }
int TAO_Constraint_Evaluator:: visit_in(TAO_Binary_Constraint* binary_in) { int return_value = -1; TAO_Constraint* left = binary_in->left_operand (), *right = binary_in->right_operand (); // Determine if the left operand is contained in the right. if (left->accept (this) == 0) { if (this->visit_property ((TAO_Property_Constraint*) right) == 0) { TAO_Literal_Constraint& left_value = this->queue_.get_left_operand(); const CORBA::Any* any = (const CORBA::Any*) this->queue_.get_right_operand(); if (any != 0) { CORBA::Boolean result = this->sequence_does_contain ((CORBA::Any*) any, left_value); this->queue_.dequeue_operand (); this->queue_.dequeue_operand (); this->queue_.enqueue_head (TAO_Literal_Constraint (result)); return_value = 0; } else this->queue_.dequeue_operand (); } } return return_value; }
int TAO_Constraint_Evaluator:: visit_twiddle (TAO_Binary_Constraint* binary_twiddle) { int return_value = -1; TAO_Constraint* left = binary_twiddle->left_operand (), *right = binary_twiddle->right_operand (); // Determine if the left operand is a substring of the right. if (left->accept (this) == 0) { if (right->accept (this) == 0) { TAO_Literal_Constraint& left_operand = this->queue_.get_left_operand (); TAO_Literal_Constraint& right_operand = this->queue_.get_right_operand (); CORBA::Boolean result = (CORBA::Boolean) (ACE_OS::strstr ((const char*)right_operand, (const char*)left_operand) != 0); this->queue_.dequeue_operand (); this->queue_.dequeue_operand (); this->queue_.enqueue_head (TAO_Literal_Constraint (result)); return_value = 0; } else this->queue_.dequeue_operand (); } return return_value; }
int TAO_Constraint_Evaluator:: visit_or (TAO_Binary_Constraint* boolean_or) { int return_value = -1; CORBA::Boolean result = (CORBA::Boolean) 0; TAO_Constraint* left = boolean_or->left_operand (), *right = boolean_or->right_operand (); // Short-circuiting OR. if (left->accept (this) == 0) { result = (CORBA::Boolean) this->queue_.get_operand (); this->queue_.dequeue_operand (); if (result == (CORBA::Boolean) 0) { if (right->accept (this) == 0) { result = (CORBA::Boolean) this->queue_.get_operand (); this->queue_.dequeue_operand (); return_value = 0; } } else return_value = 0; } if (return_value != -1) this->queue_.enqueue_head (TAO_Literal_Constraint (result)); return return_value; }
TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_Constraint_Interpreter::TAO_Constraint_Interpreter ( const CosTradingRepos::ServiceTypeRepository::TypeStruct& ts, const char* constraints ) : TAO_Interpreter () { // @@ Throwing Exception from constructor is very nasty situation to // deal with. TAO_Trader_Constraint_Validator type_checker (ts); if (TAO_Interpreter::is_empty_string (constraints)) { ACE_NEW_THROW_EX (this->root_, TAO_Literal_Constraint ((CORBA::Boolean) 1), CORBA::NO_MEMORY ()); } else { if (this->build_tree (constraints) != 0) throw CosTrading::IllegalConstraint (constraints); if (type_checker.validate (this->root_) == -1) throw CosTrading::IllegalConstraint (constraints); } }
int TAO_Constraint_Evaluator:: visit_exist (TAO_Unary_Constraint* unary_exist) { TAO_Property_Constraint* operand = (TAO_Property_Constraint*) unary_exist->operand (); CORBA::String_var property_name ((const char*) operand->name ()); // Determine if a property is defined on this offer. CORBA::Boolean result = (CORBA::Boolean) (this->props_.find (property_name) == 0); this->queue_.enqueue_head (TAO_Literal_Constraint (result)); return 0; }
TAO_Constraint_Interpreter:: TAO_Constraint_Interpreter (TAO_Constraint_Validator& validator, const char* constraints) { if (TAO_Interpreter::is_empty_string (constraints)) { ACE_NEW_THROW_EX (this->root_, TAO_Literal_Constraint ((CORBA::Boolean) 1), CORBA::NO_MEMORY ()); } else { if (this->build_tree (constraints) != 0) throw CosTrading::IllegalConstraint (constraints); if (validator.validate (this->root_) == -1) throw CosTrading::IllegalConstraint (constraints); } }
int TAO_Constraint_Evaluator:: visit_not (TAO_Unary_Constraint* unary_not) { int return_value = -1; TAO_Constraint* operand = unary_not->operand (); // Logical NOT. if (operand->accept (this) == 0) { CORBA::Boolean result = ! (CORBA::Boolean)this->queue_.get_operand (); this->queue_.dequeue_operand (); this->queue_.enqueue_head (TAO_Literal_Constraint (result)); return_value = 0; } return return_value; }