TAO_Constraint_Evaluator Class Reference

TAO_Constraint_Evaluator traverse a constraint expression tree, and determines whether an offer fits the constraints represented by the tree. More...

#include <Constraint_Visitors.h>

Inheritance diagram for TAO_Constraint_Evaluator:

Inheritance graph
[legend]
Collaboration diagram for TAO_Constraint_Evaluator:

Collaboration graph
[legend]
List of all members.

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_Evaluatoroperator= (const TAO_Constraint_Evaluator &)

Detailed Description

TAO_Constraint_Evaluator traverse a constraint expression tree, and determines whether an offer fits the constraints represented by the tree.

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.


Constructor & Destructor Documentation

TAO_Constraint_Evaluator::TAO_Constraint_Evaluator void   ) 
 

Constructor.

Definition at line 54 of file Constraint_Visitors.cpp.

00055 {
00056   // No-Op.
00057 }

TAO_Constraint_Evaluator::TAO_Constraint_Evaluator const TAO_Constraint_Evaluator  )  [private]
 

Disallow copying.


Member Function Documentation

void TAO_Constraint_Evaluator::do_the_op int  operation  )  [private]
 

Method for performing a arithmetic or comparison operation.

Definition at line 277 of file Constraint_Visitors.cpp.

References TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< TAO_Literal_Constraint >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_left_operand(), TAO_Constraint_Evaluator::Operand_Queue::get_right_operand(), TAO_DIV, TAO_EQ, TAO_GE, TAO_GT, TAO_LE, TAO_LT, TAO_MINUS, TAO_MULT, TAO_NE, and TAO_PLUS.

Referenced by visit_bin_op().

00278 {
00279   TAO_Literal_Constraint& l_op = this->queue_.get_left_operand ();
00280   TAO_Literal_Constraint& r_op = this->queue_.get_right_operand ();
00281 
00282   // Perform the listed bindary operation on the first two elements on
00283   // the stack.
00284 
00285   TAO_Literal_Constraint result =
00286     (operation <= TAO_NE)
00287     ?
00288     TAO_Literal_Constraint
00289     ((CORBA::Boolean)
00290      ((operation == TAO_GT) ? l_op > r_op :
00291       (operation == TAO_GE) ? l_op >= r_op :
00292       (operation == TAO_LT) ? l_op < r_op :
00293       (operation == TAO_LE) ? l_op <= r_op :
00294       (operation == TAO_NE) ? l_op != r_op :
00295       (operation == TAO_EQ) ? l_op == r_op : 0))
00296     :
00297     ((operation == TAO_PLUS) ? l_op + r_op :
00298      (operation == TAO_MINUS) ? l_op - r_op :
00299      (operation == TAO_MULT) ? l_op * r_op :
00300      (operation == TAO_DIV) ? l_op / r_op :
00301      TAO_Literal_Constraint ());
00302 
00303   this->queue_.dequeue_operand ();
00304   this->queue_.dequeue_operand ();
00305   this->queue_.enqueue_head (result);
00306 }

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 , 0 if it doesn't. If an error occurs during process, the constraint automatically fails.

Definition at line 60 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), TAO_Constraint_Evaluator::Operand_Queue::get_operand(), ACE_Unbounded_Queue< TAO_Literal_Constraint >::is_empty(), and ACE_Unbounded_Queue< TAO_Literal_Constraint >::reset().

Referenced by TAO_Constraint_Interpreter::evaluate().

00061 {
00062   CORBA::Boolean result = 0;
00063   this->queue_.reset ();
00064 
00065   // Evaluate the offer according to the constraints in root_;
00066   if (root != 0)
00067     {
00068       if ((root->accept (this) == 0) &&
00069           (! this->queue_.is_empty ()))
00070         {
00071           result = (CORBA::Boolean) this->queue_.get_operand();
00072           this->queue_.dequeue_operand ();
00073         }
00074     }
00075 
00076   // If a property couldn't be evaluated we must return 0.
00077   return result;
00078 }

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 82 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), TAO_Constraint_Evaluator::Operand_Queue::get_operand(), and ACE_Unbounded_Queue< TAO_Literal_Constraint >::is_empty().

Referenced by TAO_Preference_Interpreter::order_offer().

00084 {
00085   int return_value = -1;
00086   while (! this->queue_.is_empty ())
00087     this->queue_.dequeue_operand ();
00088 
00089   // Evaluate the offer according to the constraints in root_;
00090   if (root != 0)
00091     {
00092       if ((root->accept (this) == 0) &&
00093           (! this->queue_.is_empty ()))
00094         {
00095           result = this->queue_.get_operand ();
00096           this->queue_.dequeue_operand ();
00097           return_value = 0;
00098         }
00099     }
00100 
00101   return return_value;
00102 }

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 , a literal of the same simple type as . Return 1 in this eventuality.

Definition at line 511 of file Constraint_Visitors.cpp.

References ACE_CATCHANY, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_TRY, ACE_TRY_CHECK, and TAO_Sequence_Extracter_Base::sequence_type().

Referenced by visit_in().

00513 {
00514   // Helper method to cast the void* value returned from the sequence
00515   // any into a sequence type locally compiled from idl. The sequence
00516   // wrapper uses the [] operator to locate the target element in the
00517   // sequence.
00518 
00519   ACE_DECLARE_NEW_CORBA_ENV;
00520   CORBA::Boolean return_value = 0;
00521   CORBA::TypeCode_var type = sequence->type ();
00522   CORBA::TCKind sequence_type = CORBA::tk_void;
00523   ACE_TRY
00524     {
00525       sequence_type =
00526         TAO_Sequence_Extracter_Base::sequence_type (type.in () ACE_ENV_ARG_PARAMETER);
00527       ACE_TRY_CHECK;
00528     }
00529   ACE_CATCHANY
00530     {
00531       return return_value;
00532     }
00533   ACE_ENDTRY;
00534   //  ACE_CHECK_RETURN (return_value);
00535 
00536   if (sequence_type == CORBA::tk_void)
00537     return return_value;
00538 
00539   switch (sequence_type)
00540     {
00541     case CORBA::tk_short:
00542       {
00543         CORBA::Long value = element;
00544         return_value = ::TAO_find (*sequence, static_cast<CORBA::Short> (value));
00545       }
00546     break;
00547     case CORBA::tk_ushort:
00548       {
00549         CORBA::ULong value = element;
00550         return_value = ::TAO_find (*sequence, static_cast<CORBA::UShort> (value));
00551       }
00552       break;
00553     case CORBA::tk_long:
00554       {
00555         CORBA::Long value = element;
00556         return_value = ::TAO_find (*sequence, value);
00557       }
00558       break;
00559     case CORBA::tk_ulong:
00560       {
00561         CORBA::ULong value = element;
00562         return_value = ::TAO_find (*sequence, value);
00563       }
00564       break;
00565     case CORBA::tk_float:
00566       {
00567         CORBA::Double value = element;
00568         return_value = ::TAO_find (*sequence, static_cast<CORBA::Float> (value));
00569       }
00570       break;
00571     case CORBA::tk_double:
00572       {
00573         CORBA::Double value = element;
00574         return_value = ::TAO_find (*sequence, value);
00575       }
00576       break;
00577     case CORBA::tk_boolean:
00578       {
00579         CORBA::Boolean value = element;
00580         return_value = ::TAO_find (*sequence, value);
00581       }
00582       break;
00583     case CORBA::tk_string:
00584       {
00585         const char* value = element;
00586         return_value = ::TAO_find (*sequence, value);
00587       }
00588       break;
00589     default:
00590       break;
00591     }
00592 
00593   return return_value;
00594 }

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 334 of file Constraint_Visitors.cpp.

References TAO_PLUS, and visit_bin_op().

00335 {
00336   return this->visit_bin_op (boolean_add, TAO_PLUS);
00337 }

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 150 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< TAO_Literal_Constraint >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_operand(), TAO_Binary_Constraint::left_operand(), and TAO_Binary_Constraint::right_operand().

00151 {
00152   int return_value = -1;
00153   CORBA::Boolean result = (CORBA::Boolean) 0;
00154   TAO_Constraint* left = boolean_and->left_operand (),
00155     *right = boolean_and->right_operand ();
00156 
00157   // Short circuiting AND.
00158 
00159   if (left->accept (this) == 0)
00160     {
00161       result = (CORBA::Boolean) this->queue_.get_operand ();
00162       this->queue_.dequeue_operand ();
00163 
00164       if (result)
00165         {
00166           if (right->accept(this) == 0)
00167             {
00168               result = (CORBA::Boolean) this->queue_.get_operand();
00169               this->queue_.dequeue_operand ();
00170 
00171               return_value = 0;
00172             }
00173         }
00174       else
00175         return_value = 0;
00176     }
00177 
00178   if (return_value != -1)
00179     this->queue_.enqueue_head (TAO_Literal_Constraint (result));
00180 
00181   return return_value;
00182 }

int TAO_Constraint_Evaluator::visit_bin_op TAO_Binary_Constraint op,
int  operation
[private]
 

Method for evaluating a binary operation.

Definition at line 309 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), do_the_op(), TAO_Binary_Constraint::left_operand(), 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().

00311 {
00312   int return_value = -1;
00313   TAO_Constraint* left = op->left_operand ();
00314   TAO_Constraint* right = op->right_operand ();
00315 
00316   // Perform an operation on the results of evaluating the left and
00317   // right branches of this subtree.
00318   if (left->accept (this) == 0)
00319     {
00320       if (right->accept (this) == 0)
00321         {
00322           this->do_the_op (operation);
00323           return_value = 0;
00324         }
00325       else
00326         this->queue_.dequeue_operand ();
00327     }
00328 
00329   return return_value;
00330 }

int TAO_Constraint_Evaluator::visit_constraint TAO_Unary_Constraint constraint  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 105 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), and TAO_Unary_Constraint::operand().

00106 {
00107   TAO_Constraint* operand = constraint->operand ();
00108   return operand->accept (this);
00109 }

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 355 of file Constraint_Visitors.cpp.

References TAO_DIV, and visit_bin_op().

00356 {
00357   return this->visit_bin_op (boolean_div, TAO_DIV);
00358 }

int TAO_Constraint_Evaluator::visit_equal TAO_Binary_Constraint boolean_eq  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 458 of file Constraint_Visitors.cpp.

References TAO_EQ, and visit_bin_op().

00459 {
00460   return this->visit_bin_op (boolean_eq, TAO_EQ);
00461 }

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 map.

Implements TAO_Constraint_Visitor.

Definition at line 242 of file Constraint_Visitors.cpp.

References ACE_Unbounded_Queue< TAO_Literal_Constraint >::enqueue_head(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), TAO_Property_Constraint::name(), TAO_Unary_Constraint::operand(), and props_.

00243 {
00244   TAO_Property_Constraint* operand =
00245     (TAO_Property_Constraint*) unary_exist->operand ();
00246   CORBA::String_var property_name ((const char*) operand->name ());
00247 
00248   // Determine if a property is defined on this offer.
00249 
00250   CORBA::Boolean result =
00251     (CORBA::Boolean) (this->props_.find (property_name) == 0);
00252 
00253   this->queue_.enqueue_head (TAO_Literal_Constraint (result));
00254   return 0;
00255 }

int TAO_Constraint_Evaluator::visit_first TAO_Noop_Constraint noop_first  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 141 of file Constraint_Visitors.cpp.

References ACE_Unbounded_Queue< TAO_Literal_Constraint >::enqueue_head().

00142 {
00143   TAO_Literal_Constraint first ((CORBA::Long) 0);
00144   this->queue_.enqueue_head (first);
00145   return 0;
00146 }

int TAO_Constraint_Evaluator::visit_greater_than TAO_Binary_Constraint boolean_gt  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 444 of file Constraint_Visitors.cpp.

References TAO_GT, and visit_bin_op().

00445 {
00446   return this->visit_bin_op (boolean_gt, TAO_GT);
00447 }

int TAO_Constraint_Evaluator::visit_greater_than_equal TAO_Binary_Constraint boolean_gte  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 451 of file Constraint_Visitors.cpp.

References TAO_GE, and visit_bin_op().

00452 {
00453   return this->visit_bin_op (boolean_gte, TAO_GE);
00454 }

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 395 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< TAO_Literal_Constraint >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_left_operand(), TAO_Constraint_Evaluator::Operand_Queue::get_right_operand(), TAO_Binary_Constraint::left_operand(), TAO_Binary_Constraint::right_operand(), sequence_does_contain(), and visit_property().

00396 {
00397   int return_value = -1;
00398   TAO_Constraint* left = binary_in->left_operand (),
00399     *right = binary_in->right_operand ();
00400 
00401   // Determine if the left operand is contained in the right.
00402 
00403   if (left->accept (this) == 0)
00404     {
00405       if (this->visit_property ((TAO_Property_Constraint*) right) == 0)
00406         {
00407           TAO_Literal_Constraint& left_value = this->queue_.get_left_operand();
00408           const CORBA::Any* any = (const CORBA::Any*) this->queue_.get_right_operand();
00409 
00410           if (any != 0)
00411             {
00412               CORBA::Boolean result =
00413                 this->sequence_does_contain ((CORBA::Any*) any, left_value);
00414 
00415               this->queue_.dequeue_operand ();
00416               this->queue_.dequeue_operand ();
00417               this->queue_.enqueue_head (TAO_Literal_Constraint (result));
00418               return_value = 0;
00419             }
00420           else
00421             this->queue_.dequeue_operand ();
00422         }
00423     }
00424 
00425   return return_value;
00426 }

int TAO_Constraint_Evaluator::visit_less_than TAO_Binary_Constraint boolean_lt  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 430 of file Constraint_Visitors.cpp.

References TAO_LT, and visit_bin_op().

00431 {
00432   return this->visit_bin_op (boolean_lt, TAO_LT);
00433 }

int TAO_Constraint_Evaluator::visit_less_than_equal TAO_Binary_Constraint boolean_lte  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 437 of file Constraint_Visitors.cpp.

References TAO_LE, and visit_bin_op().

00438 {
00439   return this->visit_bin_op (boolean_lte, TAO_LE);
00440 }

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 472 of file Constraint_Visitors.cpp.

References ACE_Unbounded_Queue< TAO_Literal_Constraint >::enqueue_head().

00473 {
00474   this->queue_.enqueue_head (*literal);
00475   return 0;
00476 }

int TAO_Constraint_Evaluator::visit_max TAO_Unary_Constraint unary_max  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 126 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), and TAO_Unary_Constraint::operand().

00127 {
00128   TAO_Constraint* operand = unary_max->operand ();
00129   return operand->accept (this);
00130 }

int TAO_Constraint_Evaluator::visit_min TAO_Unary_Constraint unary_min  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 119 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), and TAO_Unary_Constraint::operand().

00120 {
00121   TAO_Constraint* operand = unary_min->operand ();
00122   return operand->accept (this);
00123 }

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 348 of file Constraint_Visitors.cpp.

References TAO_MULT, and visit_bin_op().

00349 {
00350   return this->visit_bin_op (boolean_mult, TAO_MULT);
00351 }

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 221 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< TAO_Literal_Constraint >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_operand(), and TAO_Unary_Constraint::operand().

00222 {
00223   int return_value = -1;
00224   TAO_Constraint* operand = unary_not->operand ();
00225 
00226   // Logical NOT.
00227 
00228   if (operand->accept (this) == 0)
00229     {
00230       CORBA::Boolean result = ! (CORBA::Boolean)this->queue_.get_operand ();
00231       this->queue_.dequeue_operand ();
00232       this->queue_.enqueue_head (TAO_Literal_Constraint (result));
00233 
00234       return_value = 0;
00235     }
00236 
00237   return return_value;
00238 }

int TAO_Constraint_Evaluator::visit_not_equal TAO_Binary_Constraint boolean_neq  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 465 of file Constraint_Visitors.cpp.

References TAO_NE, and visit_bin_op().

00466 {
00467   return this->visit_bin_op (boolean_neq, TAO_NE);
00468 }

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 186 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< TAO_Literal_Constraint >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_operand(), TAO_Binary_Constraint::left_operand(), and TAO_Binary_Constraint::right_operand().

00187 {
00188   int return_value = -1;
00189   CORBA::Boolean result = (CORBA::Boolean) 0;
00190   TAO_Constraint* left = boolean_or->left_operand (),
00191     *right = boolean_or->right_operand ();
00192 
00193   // Short-circuiting OR.
00194 
00195   if (left->accept (this) == 0)
00196     {
00197       result = (CORBA::Boolean) this->queue_.get_operand ();
00198       this->queue_.dequeue_operand ();
00199 
00200       if (result == (CORBA::Boolean) 0)
00201         {
00202           if (right->accept (this) == 0)
00203             {
00204               result = (CORBA::Boolean) this->queue_.get_operand ();
00205               this->queue_.dequeue_operand ();
00206               return_value = 0;
00207             }
00208         }
00209       else
00210         return_value = 0;
00211     }
00212 
00213   if (return_value != -1)
00214     this->queue_.enqueue_head (TAO_Literal_Constraint (result));
00215 
00216   return return_value;
00217 }

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 480 of file Constraint_Visitors.cpp.

Referenced by visit_in().

00481 {
00482   ACE_UNUSED_ARG (literal);
00483   return -1;
00484   // A derived class decides how to do this.
00485 }

int TAO_Constraint_Evaluator::visit_random TAO_Noop_Constraint noop_random  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 133 of file Constraint_Visitors.cpp.

References ACE_Unbounded_Queue< TAO_Literal_Constraint >::enqueue_head().

00134 {
00135   TAO_Literal_Constraint random ((CORBA::Long) (ACE_OS::rand ()));
00136   this->queue_.enqueue_head (random);
00137   return 0;
00138 }

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 341 of file Constraint_Visitors.cpp.

References TAO_MINUS, and visit_bin_op().

00342 {
00343   return this->visit_bin_op (boolean_sub, TAO_MINUS);
00344 }

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 362 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< TAO_Literal_Constraint >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_left_operand(), TAO_Constraint_Evaluator::Operand_Queue::get_right_operand(), TAO_Binary_Constraint::left_operand(), TAO_Binary_Constraint::right_operand(), and ACE_OS::strstr().

00363 {
00364   int return_value = -1;
00365   TAO_Constraint* left = binary_twiddle->left_operand (),
00366     *right = binary_twiddle->right_operand ();
00367 
00368   // Determine if the left operand is a substring of the right.
00369 
00370   if (left->accept (this) == 0)
00371     {
00372       if (right->accept (this) == 0)
00373         {
00374           TAO_Literal_Constraint& left_operand = this->queue_.get_left_operand ();
00375           TAO_Literal_Constraint& right_operand = this->queue_.get_right_operand ();
00376 
00377           CORBA::Boolean result = (CORBA::Boolean)
00378             (ACE_OS::strstr ((const char*)right_operand,
00379                              (const char*)left_operand) != 0);
00380 
00381           this->queue_.dequeue_operand ();
00382           this->queue_.dequeue_operand ();
00383           this->queue_.enqueue_head (TAO_Literal_Constraint (result));
00384           return_value = 0;
00385         }
00386       else
00387         this->queue_.dequeue_operand ();
00388     }
00389 
00390   return return_value;
00391 }

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 259 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand(), ACE_Unbounded_Queue< TAO_Literal_Constraint >::enqueue_head(), TAO_Constraint_Evaluator::Operand_Queue::get_operand(), and TAO_Unary_Constraint::operand().

00260 {
00261   int return_value = -1;
00262   TAO_Constraint* operand = unary_minus->operand ();
00263 
00264   if (operand->accept (this) == 0)
00265     {
00266       TAO_Literal_Constraint result = - this->queue_.get_operand ();
00267       this->queue_.dequeue_operand ();
00268       this->queue_.enqueue_head (result);
00269 
00270       return_value = 0;
00271     }
00272 
00273   return return_value;
00274 }

int TAO_Constraint_Evaluator::visit_with TAO_Unary_Constraint unary_with  )  [virtual]
 

Implements TAO_Constraint_Visitor.

Definition at line 112 of file Constraint_Visitors.cpp.

References TAO_Constraint::accept(), and TAO_Unary_Constraint::operand().

00113 {
00114   TAO_Constraint* operand = unary_with->operand ();
00115   return operand->accept (this);
00116 }


Member Data Documentation

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 visit_exist().

Operand_Queue TAO_Constraint_Evaluator::queue_ [protected]
 

The result of a non_boolean operation.

Definition at line 359 of file Constraint_Visitors.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 14:00:47 2006 for TAO_CosTrader by doxygen 1.3.6