#include <Constraint_Visitors.h>
Inheritance diagram for TAO_Constraint_Evaluator:
Public Member Functions | |
TAO_Constraint_Evaluator (void) | |
Constructor. | |
CORBA::Boolean | evaluate_constraint (TAO_Constraint *root) |
int | evaluate_preference (TAO_Constraint *root, TAO_Literal_Constraint &result) |
virtual int | visit_constraint (TAO_Unary_Constraint *constraint) |
virtual int | visit_with (TAO_Unary_Constraint *unary_with) |
virtual int | visit_min (TAO_Unary_Constraint *unary_min) |
virtual int | visit_max (TAO_Unary_Constraint *unary_max) |
virtual int | visit_first (TAO_Noop_Constraint *noop_first) |
virtual int | visit_random (TAO_Noop_Constraint *noop_random) |
virtual int | visit_and (TAO_Binary_Constraint *boolean_and) |
virtual int | visit_or (TAO_Binary_Constraint *boolean_or) |
virtual int | visit_not (TAO_Unary_Constraint *unary_not) |
Logically negates the value of the operand. | |
virtual int | visit_exist (TAO_Unary_Constraint *unary_exist) |
virtual int | visit_unary_minus (TAO_Unary_Constraint *unary_minus) |
Mathematically negates the return value the operand. | |
virtual int | visit_add (TAO_Binary_Constraint *boolean_add) |
Add the results of evaluating the left and right operands. | |
virtual int | visit_sub (TAO_Binary_Constraint *boolean_sub) |
Subtract the results of evaluating the left and right operands. | |
virtual int | visit_mult (TAO_Binary_Constraint *boolean_mult) |
Multiply the results of evaluating the left and right operands. | |
virtual int | visit_div (TAO_Binary_Constraint *boolean_div) |
Divide the results of evaluating the left and right operands. | |
virtual int | visit_twiddle (TAO_Binary_Constraint *binary_twiddle) |
Determines if the right operand is a substring of the left. | |
virtual int | visit_in (TAO_Binary_Constraint *binary_in) |
virtual int | visit_less_than (TAO_Binary_Constraint *boolean_lt) |
virtual int | visit_less_than_equal (TAO_Binary_Constraint *boolean_lte) |
virtual int | visit_greater_than (TAO_Binary_Constraint *boolean_gt) |
virtual int | visit_greater_than_equal (TAO_Binary_Constraint *boolean_gte) |
virtual int | visit_equal (TAO_Binary_Constraint *boolean_eq) |
virtual int | visit_not_equal (TAO_Binary_Constraint *boolean_neq) |
virtual int | visit_literal (TAO_Literal_Constraint *literal) |
Copy the value of the literal into the result container. | |
virtual int | visit_property (TAO_Property_Constraint *literal) |
Copy the value of the property into the result container. | |
Protected Attributes | |
TAO_Lookup_Table | props_ |
The map of property names to their values for a property. | |
Operand_Queue | queue_ |
The result of a non_boolean operation. | |
Private Member Functions | |
void | do_the_op (int operation) |
Method for performing a arithmetic or comparison operation. | |
int | visit_bin_op (TAO_Binary_Constraint *op, int operation) |
Method for evaluating a binary operation. | |
CORBA::Boolean | sequence_does_contain (CORBA::Any *sequence, TAO_Literal_Constraint &element) |
TAO_Constraint_Evaluator (const TAO_Constraint_Evaluator &) | |
Disallow copying. | |
TAO_Constraint_Evaluator & | operator= (const TAO_Constraint_Evaluator &) |
Classes | |
class | Operand_Queue |
Using the Visitor pattern, the TAO_Constraint_Evaluator has each node of the expression tree call back to it with the method designated for its type. In that method, the visitor will evaluate its operands and perform the operation designated by that node's type, and return the result. Note: the TAO_Constraint_Evaluator assumes the tree is semantically correct, that is, the validate method on TAO_Constraint_Validator return true. The only possible evaluation time errors are a divide by a property whose value is zero and undefined properties.
Definition at line 226 of file Constraint_Visitors.h.
TAO_Constraint_Evaluator::TAO_Constraint_Evaluator | ( | void | ) |
TAO_Constraint_Evaluator::TAO_Constraint_Evaluator | ( | const TAO_Constraint_Evaluator & | ) | [private] |
Disallow copying.
void TAO_Constraint_Evaluator::do_the_op | ( | int | operation | ) | [private] |
Method for performing a arithmetic or comparison operation.
Definition at line 278 of file Constraint_Visitors.cpp.
References TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< T >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_left_operand(), TAO_Constraint_Evaluator::Operand_Queue::get_right_operand(), queue_, TAO_DIV, TAO_EQ, TAO_GE, TAO_GT, TAO_LE, TAO_LT, TAO_MINUS, TAO_MULT, TAO_NE, and TAO_PLUS.
00279 { 00280 TAO_Literal_Constraint& l_op = this->queue_.get_left_operand (); 00281 TAO_Literal_Constraint& r_op = this->queue_.get_right_operand (); 00282 00283 // Perform the listed bindary operation on the first two elements on 00284 // the stack. 00285 00286 TAO_Literal_Constraint result = 00287 (operation <= TAO_NE) 00288 ? 00289 TAO_Literal_Constraint 00290 ((CORBA::Boolean) 00291 ((operation == TAO_GT) ? l_op > r_op : 00292 (operation == TAO_GE) ? l_op >= r_op : 00293 (operation == TAO_LT) ? l_op < r_op : 00294 (operation == TAO_LE) ? l_op <= r_op : 00295 (operation == TAO_NE) ? l_op != r_op : 00296 (operation == TAO_EQ) ? l_op == r_op : 0)) 00297 : 00298 ((operation == TAO_PLUS) ? l_op + r_op : 00299 (operation == TAO_MINUS) ? l_op - r_op : 00300 (operation == TAO_MULT) ? l_op * r_op : 00301 (operation == TAO_DIV) ? l_op / r_op : 00302 TAO_Literal_Constraint ()); 00303 00304 this->queue_.dequeue_operand (); 00305 this->queue_.dequeue_operand (); 00306 this->queue_.enqueue_head (result); 00307 }
CORBA::Boolean TAO_Constraint_Evaluator::evaluate_constraint | ( | TAO_Constraint * | root | ) |
Evaluate returns 1 if the offer satisfies the constraints represented by the the expression tree rooted at <root>, 0 if it doesn't. If an error occurs during process, the constraint automatically fails.
Definition at line 61 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), queue_, and ACE_Unbounded_Queue< T >::reset().
Referenced by TAO_Constraint_Interpreter::evaluate().
00062 { 00063 CORBA::Boolean result = 0; 00064 this->queue_.reset (); 00065 00066 // Evaluate the offer according to the constraints in root_; 00067 if (root != 0) 00068 { 00069 if ((root->accept (this) == 0) && 00070 (! this->queue_.is_empty ())) 00071 { 00072 result = (CORBA::Boolean) this->queue_.get_operand(); 00073 this->queue_.dequeue_operand (); 00074 } 00075 } 00076 00077 // If a property couldn't be evaluated we must return 0. 00078 return result; 00079 }
int TAO_Constraint_Evaluator::evaluate_preference | ( | TAO_Constraint * | root, | |
TAO_Literal_Constraint & | result | |||
) |
The result of the preference evaluation is stored in result. The method returns 0 upon success, -1 upon failure.
Definition at line 83 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), TAO_Constraint_Evaluator::Operand_Queue::get_operand(), and queue_.
Referenced by TAO_Preference_Interpreter::order_offer().
00085 { 00086 int return_value = -1; 00087 while (! this->queue_.is_empty ()) 00088 this->queue_.dequeue_operand (); 00089 00090 // Evaluate the offer according to the constraints in root_; 00091 if (root != 0) 00092 { 00093 if ((root->accept (this) == 0) && 00094 (! this->queue_.is_empty ())) 00095 { 00096 result = this->queue_.get_operand (); 00097 this->queue_.dequeue_operand (); 00098 return_value = 0; 00099 } 00100 } 00101 00102 return return_value; 00103 }
TAO_Constraint_Evaluator& TAO_Constraint_Evaluator::operator= | ( | const TAO_Constraint_Evaluator & | ) | [private] |
CORBA::Boolean TAO_Constraint_Evaluator::sequence_does_contain | ( | CORBA::Any * | sequence, | |
TAO_Literal_Constraint & | element | |||
) | [private] |
Determine if sequence contains <element>, a literal of the same simple type as <sequence_type>. Return 1 in this eventuality.
Definition at line 512 of file Constraint_Visitors.cpp.
References TAO_Pseudo_Var_T< T >::in(), TAO_Sequence_Extracter_Base::sequence_type(), TAO_find(), CORBA::tk_boolean, CORBA::tk_double, CORBA::tk_float, CORBA::tk_long, CORBA::tk_longlong, CORBA::tk_short, CORBA::tk_string, CORBA::tk_ulong, CORBA::tk_ulonglong, CORBA::tk_ushort, and CORBA::tk_void.
Referenced by visit_in().
00514 { 00515 // Helper method to cast the void* value returned from the sequence 00516 // any into a sequence type locally compiled from idl. The sequence 00517 // wrapper uses the [] operator to locate the target element in the 00518 // sequence. 00519 00520 CORBA::Boolean return_value = 0; 00521 CORBA::TypeCode_var type = sequence->type (); 00522 CORBA::TCKind sequence_type = CORBA::tk_void; 00523 try 00524 { 00525 sequence_type = 00526 TAO_Sequence_Extracter_Base::sequence_type (type.in ()); 00527 } 00528 catch (const CORBA::Exception&) 00529 { 00530 return return_value; 00531 } 00532 00533 if (sequence_type == CORBA::tk_void) 00534 return return_value; 00535 00536 switch (sequence_type) 00537 { 00538 case CORBA::tk_short: 00539 { 00540 CORBA::LongLong value = element; 00541 return_value = ::TAO_find (*sequence, static_cast<CORBA::Short> (value)); 00542 } 00543 break; 00544 case CORBA::tk_ushort: 00545 { 00546 CORBA::ULongLong value = element; 00547 return_value = ::TAO_find (*sequence, static_cast<CORBA::UShort> (value)); 00548 } 00549 break; 00550 case CORBA::tk_long: 00551 { 00552 CORBA::LongLong value = element; 00553 return_value = ::TAO_find (*sequence, static_cast<CORBA::Long> (value)); 00554 } 00555 break; 00556 case CORBA::tk_ulong: 00557 { 00558 CORBA::ULongLong value = element; 00559 return_value = ::TAO_find (*sequence, static_cast<CORBA::ULong> (value)); 00560 } 00561 break; 00562 case CORBA::tk_longlong: 00563 { 00564 CORBA::LongLong value = element; 00565 return_value = ::TAO_find (*sequence, value); 00566 } 00567 break; 00568 case CORBA::tk_ulonglong: 00569 { 00570 CORBA::ULongLong value = element; 00571 return_value = ::TAO_find (*sequence, value); 00572 } 00573 break; 00574 case CORBA::tk_float: 00575 { 00576 CORBA::Double value = element; 00577 return_value = ::TAO_find (*sequence, static_cast<CORBA::Float> (value)); 00578 } 00579 break; 00580 case CORBA::tk_double: 00581 { 00582 CORBA::Double value = element; 00583 return_value = ::TAO_find (*sequence, value); 00584 } 00585 break; 00586 case CORBA::tk_boolean: 00587 { 00588 CORBA::Boolean value = element; 00589 return_value = ::TAO_find (*sequence, value); 00590 } 00591 break; 00592 case CORBA::tk_string: 00593 { 00594 const char* value = element; 00595 return_value = ::TAO_find (*sequence, value); 00596 } 00597 break; 00598 default: 00599 break; 00600 } 00601 00602 return return_value; 00603 }
int TAO_Constraint_Evaluator::visit_add | ( | TAO_Binary_Constraint * | boolean_add | ) | [virtual] |
Add the results of evaluating the left and right operands.
Implements TAO_Constraint_Visitor.
Definition at line 335 of file Constraint_Visitors.cpp.
References TAO_PLUS, and visit_bin_op().
00336 { 00337 return this->visit_bin_op (boolean_add, TAO_PLUS); 00338 }
int TAO_Constraint_Evaluator::visit_and | ( | TAO_Binary_Constraint * | boolean_and | ) | [virtual] |
Takes the logical and of the results of both operands. Note that in the case where the left operand returns zero, the result is immediately known.
Implements TAO_Constraint_Visitor.
Definition at line 151 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< T >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_operand(), TAO_Binary_Constraint::left_operand(), queue_, and TAO_Binary_Constraint::right_operand().
00152 { 00153 int return_value = -1; 00154 CORBA::Boolean result = (CORBA::Boolean) 0; 00155 TAO_Constraint* left = boolean_and->left_operand (), 00156 *right = boolean_and->right_operand (); 00157 00158 // Short circuiting AND. 00159 00160 if (left->accept (this) == 0) 00161 { 00162 result = (CORBA::Boolean) this->queue_.get_operand (); 00163 this->queue_.dequeue_operand (); 00164 00165 if (result) 00166 { 00167 if (right->accept(this) == 0) 00168 { 00169 result = (CORBA::Boolean) this->queue_.get_operand(); 00170 this->queue_.dequeue_operand (); 00171 00172 return_value = 0; 00173 } 00174 } 00175 else 00176 return_value = 0; 00177 } 00178 00179 if (return_value != -1) 00180 this->queue_.enqueue_head (TAO_Literal_Constraint (result)); 00181 00182 return return_value; 00183 }
int TAO_Constraint_Evaluator::visit_bin_op | ( | TAO_Binary_Constraint * | op, | |
int | operation | |||
) | [private] |
Method for evaluating a binary operation.
Definition at line 310 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), TAO_Binary_Constraint::left_operand(), queue_, and TAO_Binary_Constraint::right_operand().
Referenced by visit_add(), visit_div(), visit_equal(), visit_greater_than(), visit_greater_than_equal(), visit_less_than(), visit_less_than_equal(), visit_mult(), visit_not_equal(), and visit_sub().
00312 { 00313 int return_value = -1; 00314 TAO_Constraint* left = op->left_operand (); 00315 TAO_Constraint* right = op->right_operand (); 00316 00317 // Perform an operation on the results of evaluating the left and 00318 // right branches of this subtree. 00319 if (left->accept (this) == 0) 00320 { 00321 if (right->accept (this) == 0) 00322 { 00323 this->do_the_op (operation); 00324 return_value = 0; 00325 } 00326 else 00327 this->queue_.dequeue_operand (); 00328 } 00329 00330 return return_value; 00331 }
int TAO_Constraint_Evaluator::visit_constraint | ( | TAO_Unary_Constraint * | constraint | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 106 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), and TAO_Unary_Constraint::operand().
00107 { 00108 TAO_Constraint* operand = constraint->operand (); 00109 return operand->accept (this); 00110 }
int TAO_Constraint_Evaluator::visit_div | ( | TAO_Binary_Constraint * | boolean_div | ) | [virtual] |
Divide the results of evaluating the left and right operands.
Implements TAO_Constraint_Visitor.
Definition at line 356 of file Constraint_Visitors.cpp.
References TAO_DIV, and visit_bin_op().
00357 { 00358 return this->visit_bin_op (boolean_div, TAO_DIV); 00359 }
int TAO_Constraint_Evaluator::visit_equal | ( | TAO_Binary_Constraint * | boolean_eq | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 459 of file Constraint_Visitors.cpp.
References TAO_EQ, and visit_bin_op().
00460 { 00461 return this->visit_bin_op (boolean_eq, TAO_EQ); 00462 }
int TAO_Constraint_Evaluator::visit_exist | ( | TAO_Unary_Constraint * | unary_exist | ) | [virtual] |
The property exists if its name is bound to a value in the <props_> map.
Implements TAO_Constraint_Visitor.
Definition at line 243 of file Constraint_Visitors.cpp.
References ACE_Unbounded_Queue< T >::enqueue_head(), TAO_Property_Constraint::name(), TAO_Unary_Constraint::operand(), and queue_.
00244 { 00245 TAO_Property_Constraint* operand = 00246 (TAO_Property_Constraint*) unary_exist->operand (); 00247 CORBA::String_var property_name ((const char*) operand->name ()); 00248 00249 // Determine if a property is defined on this offer. 00250 00251 CORBA::Boolean result = 00252 (CORBA::Boolean) (this->props_.find (property_name) == 0); 00253 00254 this->queue_.enqueue_head (TAO_Literal_Constraint (result)); 00255 return 0; 00256 }
int TAO_Constraint_Evaluator::visit_first | ( | TAO_Noop_Constraint * | noop_first | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 142 of file Constraint_Visitors.cpp.
References ACE_Unbounded_Queue< T >::enqueue_head(), and queue_.
00143 { 00144 TAO_Literal_Constraint first (static_cast<CORBA::LongLong> (0)); 00145 this->queue_.enqueue_head (first); 00146 return 0; 00147 }
int TAO_Constraint_Evaluator::visit_greater_than | ( | TAO_Binary_Constraint * | boolean_gt | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 445 of file Constraint_Visitors.cpp.
References TAO_GT, and visit_bin_op().
00446 { 00447 return this->visit_bin_op (boolean_gt, TAO_GT); 00448 }
int TAO_Constraint_Evaluator::visit_greater_than_equal | ( | TAO_Binary_Constraint * | boolean_gte | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 452 of file Constraint_Visitors.cpp.
References TAO_GE, and visit_bin_op().
00453 { 00454 return this->visit_bin_op (boolean_gte, TAO_GE); 00455 }
int TAO_Constraint_Evaluator::visit_in | ( | TAO_Binary_Constraint * | binary_in | ) | [virtual] |
Determines if the sequence represented by the right operand contains the left operand.
Implements TAO_Constraint_Visitor.
Definition at line 396 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< T >::enqueue_head(), TAO_Binary_Constraint::left_operand(), queue_, TAO_Binary_Constraint::right_operand(), and sequence_does_contain().
00397 { 00398 int return_value = -1; 00399 TAO_Constraint* left = binary_in->left_operand (), 00400 *right = binary_in->right_operand (); 00401 00402 // Determine if the left operand is contained in the right. 00403 00404 if (left->accept (this) == 0) 00405 { 00406 if (this->visit_property ((TAO_Property_Constraint*) right) == 0) 00407 { 00408 TAO_Literal_Constraint& left_value = this->queue_.get_left_operand(); 00409 const CORBA::Any* any = (const CORBA::Any*) this->queue_.get_right_operand(); 00410 00411 if (any != 0) 00412 { 00413 CORBA::Boolean result = 00414 this->sequence_does_contain ((CORBA::Any*) any, left_value); 00415 00416 this->queue_.dequeue_operand (); 00417 this->queue_.dequeue_operand (); 00418 this->queue_.enqueue_head (TAO_Literal_Constraint (result)); 00419 return_value = 0; 00420 } 00421 else 00422 this->queue_.dequeue_operand (); 00423 } 00424 } 00425 00426 return return_value; 00427 }
int TAO_Constraint_Evaluator::visit_less_than | ( | TAO_Binary_Constraint * | boolean_lt | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 431 of file Constraint_Visitors.cpp.
References TAO_LT, and visit_bin_op().
00432 { 00433 return this->visit_bin_op (boolean_lt, TAO_LT); 00434 }
int TAO_Constraint_Evaluator::visit_less_than_equal | ( | TAO_Binary_Constraint * | boolean_lte | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 438 of file Constraint_Visitors.cpp.
References TAO_LE, and visit_bin_op().
00439 { 00440 return this->visit_bin_op (boolean_lte, TAO_LE); 00441 }
int TAO_Constraint_Evaluator::visit_literal | ( | TAO_Literal_Constraint * | literal | ) | [virtual] |
Copy the value of the literal into the result container.
Implements TAO_Constraint_Visitor.
Definition at line 473 of file Constraint_Visitors.cpp.
References ACE_Unbounded_Queue< T >::enqueue_head(), and queue_.
00474 { 00475 this->queue_.enqueue_head (*literal); 00476 return 0; 00477 }
int TAO_Constraint_Evaluator::visit_max | ( | TAO_Unary_Constraint * | unary_max | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 127 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), and TAO_Unary_Constraint::operand().
00128 { 00129 TAO_Constraint* operand = unary_max->operand (); 00130 return operand->accept (this); 00131 }
int TAO_Constraint_Evaluator::visit_min | ( | TAO_Unary_Constraint * | unary_min | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 120 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), and TAO_Unary_Constraint::operand().
00121 { 00122 TAO_Constraint* operand = unary_min->operand (); 00123 return operand->accept (this); 00124 }
int TAO_Constraint_Evaluator::visit_mult | ( | TAO_Binary_Constraint * | boolean_mult | ) | [virtual] |
Multiply the results of evaluating the left and right operands.
Implements TAO_Constraint_Visitor.
Definition at line 349 of file Constraint_Visitors.cpp.
References TAO_MULT, and visit_bin_op().
00350 { 00351 return this->visit_bin_op (boolean_mult, TAO_MULT); 00352 }
int TAO_Constraint_Evaluator::visit_not | ( | TAO_Unary_Constraint * | unary_not | ) | [virtual] |
Logically negates the value of the operand.
Implements TAO_Constraint_Visitor.
Definition at line 222 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< T >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_operand(), TAO_Unary_Constraint::operand(), and queue_.
00223 { 00224 int return_value = -1; 00225 TAO_Constraint* operand = unary_not->operand (); 00226 00227 // Logical NOT. 00228 00229 if (operand->accept (this) == 0) 00230 { 00231 CORBA::Boolean result = ! (CORBA::Boolean)this->queue_.get_operand (); 00232 this->queue_.dequeue_operand (); 00233 this->queue_.enqueue_head (TAO_Literal_Constraint (result)); 00234 00235 return_value = 0; 00236 } 00237 00238 return return_value; 00239 }
int TAO_Constraint_Evaluator::visit_not_equal | ( | TAO_Binary_Constraint * | boolean_neq | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 466 of file Constraint_Visitors.cpp.
References TAO_NE, and visit_bin_op().
00467 { 00468 return this->visit_bin_op (boolean_neq, TAO_NE); 00469 }
int TAO_Constraint_Evaluator::visit_or | ( | TAO_Binary_Constraint * | boolean_or | ) | [virtual] |
Takes the logical or of the results of both operands. Note that in the case where the left operand returns one, the result is immediately known.
Implements TAO_Constraint_Visitor.
Definition at line 187 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< T >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_operand(), TAO_Binary_Constraint::left_operand(), queue_, and TAO_Binary_Constraint::right_operand().
00188 { 00189 int return_value = -1; 00190 CORBA::Boolean result = (CORBA::Boolean) 0; 00191 TAO_Constraint* left = boolean_or->left_operand (), 00192 *right = boolean_or->right_operand (); 00193 00194 // Short-circuiting OR. 00195 00196 if (left->accept (this) == 0) 00197 { 00198 result = (CORBA::Boolean) this->queue_.get_operand (); 00199 this->queue_.dequeue_operand (); 00200 00201 if (result == (CORBA::Boolean) 0) 00202 { 00203 if (right->accept (this) == 0) 00204 { 00205 result = (CORBA::Boolean) this->queue_.get_operand (); 00206 this->queue_.dequeue_operand (); 00207 return_value = 0; 00208 } 00209 } 00210 else 00211 return_value = 0; 00212 } 00213 00214 if (return_value != -1) 00215 this->queue_.enqueue_head (TAO_Literal_Constraint (result)); 00216 00217 return return_value; 00218 }
int TAO_Constraint_Evaluator::visit_property | ( | TAO_Property_Constraint * | literal | ) | [virtual] |
Copy the value of the property into the result container.
Implements TAO_Constraint_Visitor.
Reimplemented in TAO_Trader_Constraint_Evaluator.
Definition at line 481 of file Constraint_Visitors.cpp.
00482 { 00483 ACE_UNUSED_ARG (literal); 00484 return -1; 00485 // A derived class decides how to do this. 00486 }
int TAO_Constraint_Evaluator::visit_random | ( | TAO_Noop_Constraint * | noop_random | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 134 of file Constraint_Visitors.cpp.
References ACE_Unbounded_Queue< T >::enqueue_head(), queue_, and ACE_OS::rand().
00135 { 00136 TAO_Literal_Constraint random (static_cast<CORBA::LongLong> (ACE_OS::rand ())); 00137 this->queue_.enqueue_head (random); 00138 return 0; 00139 }
int TAO_Constraint_Evaluator::visit_sub | ( | TAO_Binary_Constraint * | boolean_sub | ) | [virtual] |
Subtract the results of evaluating the left and right operands.
Implements TAO_Constraint_Visitor.
Definition at line 342 of file Constraint_Visitors.cpp.
References TAO_MINUS, and visit_bin_op().
00343 { 00344 return this->visit_bin_op (boolean_sub, TAO_MINUS); 00345 }
int TAO_Constraint_Evaluator::visit_twiddle | ( | TAO_Binary_Constraint * | binary_twiddle | ) | [virtual] |
Determines if the right operand is a substring of the left.
Implements TAO_Constraint_Visitor.
Definition at line 363 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< T >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_right_operand(), TAO_Binary_Constraint::left_operand(), queue_, TAO_Binary_Constraint::right_operand(), and ACE_OS::strstr().
00364 { 00365 int return_value = -1; 00366 TAO_Constraint* left = binary_twiddle->left_operand (), 00367 *right = binary_twiddle->right_operand (); 00368 00369 // Determine if the left operand is a substring of the right. 00370 00371 if (left->accept (this) == 0) 00372 { 00373 if (right->accept (this) == 0) 00374 { 00375 TAO_Literal_Constraint& left_operand = this->queue_.get_left_operand (); 00376 TAO_Literal_Constraint& right_operand = this->queue_.get_right_operand (); 00377 00378 CORBA::Boolean result = (CORBA::Boolean) 00379 (ACE_OS::strstr ((const char*)right_operand, 00380 (const char*)left_operand) != 0); 00381 00382 this->queue_.dequeue_operand (); 00383 this->queue_.dequeue_operand (); 00384 this->queue_.enqueue_head (TAO_Literal_Constraint (result)); 00385 return_value = 0; 00386 } 00387 else 00388 this->queue_.dequeue_operand (); 00389 } 00390 00391 return return_value; 00392 }
int TAO_Constraint_Evaluator::visit_unary_minus | ( | TAO_Unary_Constraint * | unary_minus | ) | [virtual] |
Mathematically negates the return value the operand.
Implements TAO_Constraint_Visitor.
Definition at line 260 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< T >::enqueue_head(), TAO_Unary_Constraint::operand(), and queue_.
00261 { 00262 int return_value = -1; 00263 TAO_Constraint* operand = unary_minus->operand (); 00264 00265 if (operand->accept (this) == 0) 00266 { 00267 TAO_Literal_Constraint result = - this->queue_.get_operand (); 00268 this->queue_.dequeue_operand (); 00269 this->queue_.enqueue_head (result); 00270 00271 return_value = 0; 00272 } 00273 00274 return return_value; 00275 }
int TAO_Constraint_Evaluator::visit_with | ( | TAO_Unary_Constraint * | unary_with | ) | [virtual] |
Implements TAO_Constraint_Visitor.
Definition at line 113 of file Constraint_Visitors.cpp.
References TAO_Constraint::accept(), and TAO_Unary_Constraint::operand().
00114 { 00115 TAO_Constraint* operand = unary_with->operand (); 00116 return operand->accept (this); 00117 }
TAO_Lookup_Table TAO_Constraint_Evaluator::props_ [protected] |
The map of property names to their values for a property.
Definition at line 356 of file Constraint_Visitors.h.
Referenced by TAO_Trader_Constraint_Evaluator::TAO_Trader_Constraint_Evaluator().
Operand_Queue TAO_Constraint_Evaluator::queue_ [protected] |
The result of a non_boolean operation.
Definition at line 359 of file Constraint_Visitors.h.
Referenced by do_the_op(), evaluate_constraint(), evaluate_preference(), visit_and(), visit_bin_op(), visit_exist(), visit_first(), visit_in(), visit_literal(), visit_not(), visit_or(), TAO_Trader_Constraint_Evaluator::visit_property(), visit_random(), visit_twiddle(), and visit_unary_minus().