Constraint_Nodes.cpp

Go to the documentation of this file.
00001 // Constraint_Nodes.cpp,v 1.32 2006/04/19 10:18:11 jwillemsen Exp
00002 
00003 #include "orbsvcs/Trader/Constraint_Nodes.h"
00004 #include "orbsvcs/Trader/Constraint_Visitors.h"
00005 
00006 #include "tao/AnyTypeCode/Any.h"
00007 #include "ace/OS_NS_string.h"
00008 
00009 ACE_RCSID (Trader,
00010            Constraint_Nodes,
00011            "Constraint_Nodes.cpp,v 1.32 2006/04/19 10:18:11 jwillemsen Exp")
00012 
00013 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00014 
00015 int
00016 TAO_Noop_Constraint::accept (TAO_Constraint_Visitor* visitor)
00017 {
00018   int return_value = -1;
00019   switch (this->type_)
00020     {
00021     case TAO_FIRST:
00022       return_value = visitor->visit_first (this);
00023       break;
00024     case TAO_RANDOM:
00025       return_value = visitor->visit_random (this);
00026     }
00027 
00028   return return_value;
00029 }
00030 
00031 TAO_Binary_Constraint::
00032 TAO_Binary_Constraint (TAO_Expression_Type op_type,
00033                        TAO_Constraint* left,
00034                        TAO_Constraint* right)
00035   : op_ (op_type),
00036     left_ (left),
00037     right_ (right)
00038 {
00039 }
00040 
00041 TAO_Binary_Constraint::~TAO_Binary_Constraint (void)
00042 {
00043   delete left_;
00044   delete right_;
00045 }
00046 
00047 // Dispatch table for the accept method
00048 static int (*dispatch_table[]) (TAO_Constraint_Visitor*,
00049                                  TAO_Binary_Constraint*)=
00050 {
00051   TAO_Binary_Constraint::visit_greater_than,
00052   TAO_Binary_Constraint::visit_greater_than_equal,
00053   TAO_Binary_Constraint::visit_less_than,
00054   TAO_Binary_Constraint::visit_less_than_equal,
00055   TAO_Binary_Constraint::visit_equal,
00056   TAO_Binary_Constraint::visit_not_equal,
00057   0,
00058   TAO_Binary_Constraint::visit_and,
00059   TAO_Binary_Constraint::visit_or,
00060   0,
00061   TAO_Binary_Constraint::visit_in,
00062   TAO_Binary_Constraint::visit_twiddle,
00063   0,
00064   TAO_Binary_Constraint::visit_add,
00065   TAO_Binary_Constraint::visit_sub,
00066   TAO_Binary_Constraint::visit_mult,
00067   TAO_Binary_Constraint::visit_div
00068 };
00069 
00070 // Simulate the fun of actual double dispatching.
00071 
00072 int
00073 TAO_Binary_Constraint::accept (TAO_Constraint_Visitor* visitor)
00074 {
00075   int offset = this->op_ - TAO_GT,
00076     return_value = -1;
00077 
00078   if (dispatch_table[offset] != 0)
00079     return_value = dispatch_table[offset] (visitor, this);
00080 
00081   return return_value;
00082 }
00083 
00084 int
00085 TAO_Binary_Constraint::
00086 visit_or (TAO_Constraint_Visitor* visitor,
00087                   TAO_Binary_Constraint* expr)
00088 {
00089   return visitor->visit_or (expr);
00090 }
00091 
00092 int
00093 TAO_Binary_Constraint::
00094 visit_and (TAO_Constraint_Visitor* visitor,
00095            TAO_Binary_Constraint* expr)
00096 {
00097   return visitor->visit_and (expr);
00098 }
00099 
00100 int
00101 TAO_Binary_Constraint::
00102 visit_less_than (TAO_Constraint_Visitor* visitor,
00103                 TAO_Binary_Constraint* expr)
00104 {
00105   return visitor->visit_less_than (expr);
00106 }
00107 
00108 int
00109 TAO_Binary_Constraint::
00110 visit_less_than_equal (TAO_Constraint_Visitor* visitor,
00111                       TAO_Binary_Constraint* expr)
00112 {
00113   return visitor->visit_less_than_equal (expr);
00114 }
00115 
00116 int
00117 TAO_Binary_Constraint::
00118 visit_greater_than (TAO_Constraint_Visitor* visitor,
00119                    TAO_Binary_Constraint* expr)
00120 {
00121   return visitor->visit_greater_than (expr);
00122 }
00123 
00124 int
00125 TAO_Binary_Constraint::
00126 visit_greater_than_equal (TAO_Constraint_Visitor* visitor,
00127                          TAO_Binary_Constraint* expr)
00128 {
00129   return visitor->visit_greater_than_equal (expr);
00130 }
00131 
00132 int
00133 TAO_Binary_Constraint::
00134 visit_equal (TAO_Constraint_Visitor* visitor,
00135             TAO_Binary_Constraint* expr)
00136 {
00137   return visitor->visit_equal (expr);
00138 }
00139 
00140 int
00141 TAO_Binary_Constraint::
00142 visit_not_equal (TAO_Constraint_Visitor* visitor,
00143                 TAO_Binary_Constraint* expr)
00144 {
00145   return visitor->visit_not_equal (expr);
00146 }
00147 
00148 int
00149 TAO_Binary_Constraint::
00150 visit_add (TAO_Constraint_Visitor* visitor,
00151           TAO_Binary_Constraint* expr)
00152 {
00153   return visitor->visit_add (expr);
00154 }
00155 
00156 int
00157 TAO_Binary_Constraint::
00158 visit_sub (TAO_Constraint_Visitor* visitor,
00159           TAO_Binary_Constraint* expr)
00160 {
00161   return visitor->visit_sub (expr);
00162 }
00163 
00164 int
00165 TAO_Binary_Constraint::
00166 visit_mult (TAO_Constraint_Visitor* visitor,
00167            TAO_Binary_Constraint* expr)
00168 {
00169   return visitor->visit_mult (expr);
00170 }
00171 
00172 int
00173 TAO_Binary_Constraint::
00174 visit_div (TAO_Constraint_Visitor* visitor,
00175           TAO_Binary_Constraint* expr)
00176 {
00177   return visitor->visit_div (expr);
00178 }
00179 
00180 int
00181 TAO_Binary_Constraint::
00182 visit_twiddle (TAO_Constraint_Visitor* visitor,
00183               TAO_Binary_Constraint* expr)
00184 {
00185   return visitor->visit_twiddle (expr);
00186 }
00187 
00188 int
00189 TAO_Binary_Constraint::
00190 visit_in (TAO_Constraint_Visitor* visitor,
00191          TAO_Binary_Constraint* expr)
00192 {
00193   return visitor->visit_in (expr);
00194 }
00195 
00196 
00197 TAO_Constraint*
00198 TAO_Binary_Constraint::left_operand (void) const
00199 {
00200   return this->left_;
00201 }
00202 
00203 TAO_Constraint*
00204 TAO_Binary_Constraint::right_operand (void) const
00205 {
00206   return this->right_;
00207 }
00208 
00209 TAO_Unary_Constraint::
00210 TAO_Unary_Constraint (TAO_Expression_Type op_type,
00211                      TAO_Constraint* operand)
00212   : op_ (op_type),
00213     operand_ (operand)
00214 {
00215 }
00216 
00217 TAO_Unary_Constraint::~TAO_Unary_Constraint (void)
00218 {
00219   delete operand_;
00220 }
00221 
00222 
00223 int
00224 TAO_Unary_Constraint::accept (TAO_Constraint_Visitor* visitor)
00225 {
00226   // Since there are only three unary operators, there's no need for a
00227   // dispatch table.
00228   int return_value = -1;
00229   switch (this->op_)
00230     {
00231     case TAO_CONSTRAINT:
00232       return_value = visitor->visit_constraint (this);
00233       break;
00234     case TAO_WITH:
00235       return_value = visitor->visit_with (this);
00236       break;
00237     case TAO_MIN:
00238       return_value = visitor->visit_min (this);
00239       break;
00240     case TAO_MAX:
00241       return_value = visitor->visit_max (this);
00242       break;
00243     case TAO_NOT:
00244       return_value = visitor->visit_not (this);
00245       break;
00246     case TAO_UMINUS:
00247       return_value = visitor->visit_unary_minus (this);
00248       break;
00249     case TAO_EXIST:
00250       return_value = visitor->visit_exist (this);
00251       break;
00252     }
00253 
00254   return return_value;
00255 }
00256 
00257 TAO_Constraint*
00258 TAO_Unary_Constraint::operand (void)
00259 {
00260   return this->operand_;
00261 }
00262 
00263 TAO_Property_Constraint::
00264 TAO_Property_Constraint (const char* name)
00265   : name_ (CORBA::string_dup (name))
00266 {
00267 }
00268 
00269 TAO_Property_Constraint::~TAO_Property_Constraint (void)
00270 {
00271   CORBA::string_free (this->name_);
00272 }
00273 
00274 int
00275 TAO_Property_Constraint::accept (TAO_Constraint_Visitor* visitor)
00276 {
00277   return visitor->visit_property (this);
00278 }
00279 
00280 const char*
00281 TAO_Property_Constraint::name (void) const
00282 {
00283   return name_;
00284 }
00285 
00286 TAO_Literal_Constraint::
00287 TAO_Literal_Constraint (const TAO_Literal_Constraint& lit)
00288   : TAO_Constraint (lit)
00289 {
00290   this->copy (lit);
00291 }
00292 
00293 
00294 TAO_Literal_Constraint::
00295 TAO_Literal_Constraint (CORBA::Any* any)
00296 {
00297   ACE_DECLARE_NEW_CORBA_ENV;
00298   CORBA::Any& any_ref = *any;
00299   CORBA::TypeCode_var type = any_ref.type ();
00300   // @@ No where to throw exception back.
00301   CORBA::TCKind corba_type = CORBA::tk_null;
00302   ACE_TRY
00303     {
00304       corba_type = type->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
00305       ACE_TRY_CHECK;
00306     }
00307   ACE_CATCHANY
00308     {
00309       // @@ Seth: Don't know what else to do.  Make sure we can tell
00310       // when this constructor fails.
00311       return;
00312     }
00313   ACE_ENDTRY;
00314 
00315   this->type_ = TAO_Literal_Constraint::comparable_type (type.in ());
00316   switch (this->type_)
00317     {
00318     case TAO_SIGNED:
00319       this->op_.integer_ = 0;
00320       if (corba_type == CORBA::tk_short)
00321         {
00322           CORBA::Short sh;
00323           any_ref >>= sh;
00324           this->op_.integer_ = (CORBA::Long) sh;
00325         }
00326       else
00327         any_ref >>= this->op_.integer_;
00328       break;
00329     case TAO_UNSIGNED:
00330       this->op_.uinteger_ = 0;
00331       if (corba_type == CORBA::tk_ushort)
00332         {
00333           CORBA::UShort sh;
00334           any_ref >>= sh;
00335           this->op_.uinteger_ = (CORBA::ULong) sh;
00336         }
00337       else
00338         any_ref >>= this->op_.uinteger_;
00339       break;
00340     case TAO_DOUBLE:
00341       if (corba_type == CORBA::tk_float)
00342         {
00343           CORBA::Float fl;
00344           (*any) >>= fl;
00345           this->op_.double_ = (CORBA::Double) fl;
00346         }
00347       else
00348         (*any) >>= this->op_.double_;
00349       break;
00350     case TAO_BOOLEAN:
00351       {
00352         CORBA::Any::to_boolean tmp (this->op_.bool_);
00353         (*any) >>= tmp;
00354       }
00355     break;
00356     case TAO_STRING:
00357       {
00358         const char* s;
00359         any_ref >>= s;
00360         this->op_.str_ = CORBA::string_dup (s);
00361       }
00362     break;
00363     case TAO_SEQUENCE:
00364       this->op_.any_ = any;
00365     }
00366 }
00367 
00368 TAO_Literal_Constraint::TAO_Literal_Constraint (CORBA::ULong uinteger)
00369   : type_ (TAO_UNSIGNED)
00370 {
00371   this->op_.uinteger_ = uinteger;
00372 }
00373 
00374 TAO_Literal_Constraint::TAO_Literal_Constraint (CORBA::Long integer)
00375   : type_ (TAO_SIGNED)
00376 {
00377   this->op_.integer_ = integer;
00378 }
00379 
00380 TAO_Literal_Constraint::TAO_Literal_Constraint (CORBA::Boolean boolean)
00381   : type_ (TAO_BOOLEAN)
00382 {
00383   this->op_.bool_ = boolean;
00384 }
00385 
00386 TAO_Literal_Constraint::TAO_Literal_Constraint (CORBA::Double doub)
00387   : type_ (TAO_DOUBLE)
00388 {
00389   this->op_.double_ = doub;
00390 }
00391 
00392 TAO_Literal_Constraint::TAO_Literal_Constraint (const char* str)
00393   : type_ (TAO_STRING)
00394 {
00395   this->op_.str_ = CORBA::string_dup (str);
00396 }
00397 
00398 TAO_Literal_Constraint::~TAO_Literal_Constraint (void)
00399 {
00400   if (this->type_ == TAO_STRING)
00401     CORBA::string_free (this->op_.str_);
00402 }
00403 
00404 int
00405 TAO_Literal_Constraint::accept (TAO_Constraint_Visitor* visitor)
00406 {
00407   return visitor->visit_literal (this);
00408 }
00409 
00410 void
00411 TAO_Literal_Constraint::operator= (const TAO_Literal_Constraint& co)
00412 {
00413   this->copy (co);
00414 }
00415 
00416 TAO_Literal_Constraint::operator CORBA::Boolean (void) const
00417 {
00418   return (this->type_ == TAO_BOOLEAN) ? this->op_.bool_ : 0;
00419 }
00420 
00421 TAO_Literal_Constraint::operator CORBA::ULong (void) const
00422 {
00423   CORBA::ULong return_value = (CORBA::ULong)0;
00424 
00425   if (this->type_ == TAO_UNSIGNED)
00426     return_value = this->op_.uinteger_;
00427   else if (this->type_ == TAO_SIGNED)
00428     return_value =
00429       (this->op_.integer_ > 0) ? (CORBA::ULong) this->op_.integer_ : 0;
00430   else if (this->type_ == TAO_DOUBLE)
00431     return_value =
00432       (this->op_.double_ > 0) ?
00433       ((this->op_.double_ > ACE_UINT32_MAX) ?
00434        ACE_UINT32_MAX :
00435        (CORBA::ULong) this->op_.double_)
00436       : 0;
00437 
00438   return return_value;
00439 }
00440 
00441 TAO_Literal_Constraint::operator CORBA::Long (void) const
00442 {
00443   CORBA::Long return_value = (CORBA::Long)0;
00444 
00445   if (this->type_ == TAO_SIGNED)
00446     return_value = this->op_.integer_;
00447   else if (this->type_ == TAO_UNSIGNED)
00448     return_value =
00449       (this->op_.uinteger_ > (CORBA::ULong) ACE_INT32_MAX) ?
00450       ACE_INT32_MAX : (CORBA::Long) this->op_.uinteger_;
00451   else if (this->type_ == TAO_DOUBLE)
00452     return_value  =
00453       (this->op_.double_ > 0) ?
00454       ((this->op_.double_ > ACE_INT32_MAX) ?
00455        ACE_INT32_MAX :
00456        (CORBA::Long) this->op_.double_) :
00457     ((this->op_.double_ < ACE_INT32_MIN) ?
00458      ACE_INT32_MIN :
00459      (CORBA::Long) this->op_.double_);
00460 
00461   return return_value;
00462 }
00463 
00464 TAO_Literal_Constraint::operator CORBA::Double (void) const
00465 {
00466   CORBA::Double return_value = (CORBA::Double)0.0;
00467 
00468   if (this->type_ == TAO_DOUBLE)
00469     return_value = this->op_.double_;
00470   else if (this->type_ == TAO_SIGNED)
00471     return_value = (CORBA::Double) this->op_.integer_;
00472   else if (this->type_ == TAO_UNSIGNED)
00473     return_value = (CORBA::Double) this->op_.uinteger_;
00474 
00475   return return_value;
00476 }
00477 
00478 TAO_Literal_Constraint::operator const char* (void) const
00479 {
00480   return (this->type_ == TAO_STRING) ? this->op_.str_ : 0;
00481 }
00482 
00483 TAO_Literal_Constraint::operator const CORBA::Any* (void) const
00484 {
00485   return (this->type_ == TAO_SEQUENCE) ? this->op_.any_ : 0;
00486 }
00487 
00488 TAO_Expression_Type
00489 TAO_Literal_Constraint::comparable_type (CORBA::TypeCode_ptr type)
00490 {
00491   // Convert a CORBA::TCKind into a TAO_Literal_Type
00492   ACE_DECLARE_NEW_CORBA_ENV;
00493   TAO_Expression_Type return_value = TAO_UNKNOWN;
00494   CORBA::TCKind kind = CORBA::tk_null;
00495   ACE_TRY
00496     {
00497       kind = type->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
00498       ACE_TRY_CHECK;
00499     }
00500   ACE_CATCHANY
00501     {
00502       return return_value;
00503     }
00504   ACE_ENDTRY;
00505   // Since this is a "top level try block, no need to check again.
00506 
00507   switch (kind)
00508     {
00509     case CORBA::tk_ushort:
00510     case CORBA::tk_ulong:
00511       return_value = TAO_UNSIGNED;
00512       break;
00513     case CORBA::tk_long:
00514     case CORBA::tk_short:
00515       return_value = TAO_SIGNED;
00516       break;
00517     case CORBA::tk_boolean:
00518       return_value = TAO_BOOLEAN;
00519       break;
00520     case CORBA::tk_float:
00521     case CORBA::tk_double:
00522       return_value = TAO_DOUBLE;
00523       break;
00524     case CORBA::tk_string:
00525       return_value = TAO_STRING;
00526       break;
00527     case CORBA::tk_sequence:
00528       return_value = TAO_SEQUENCE;
00529       break;
00530     case CORBA::tk_alias:
00531       {
00532         CORBA::TCKind kind = CORBA::tk_void;
00533         ACE_TRY_EX (label2)
00534           {
00535             CORBA::TypeCode_var typecode = type->content_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00536             ACE_TRY_CHECK_EX (label2);
00537             kind = typecode->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
00538             ACE_TRY_CHECK_EX (label2);;
00539           }
00540         ACE_CATCHANY
00541           {
00542             return return_value;
00543           }
00544         ACE_ENDTRY;
00545         // Since this is a "top level try block, no need to check again.
00546 
00547         if (kind == CORBA::tk_sequence)
00548           return_value = TAO_SEQUENCE;
00549       }
00550     break;
00551     default:
00552       return_value = TAO_UNKNOWN;
00553     }
00554 
00555   return return_value;
00556 }
00557 
00558 bool
00559 operator== (const TAO_Literal_Constraint& left,
00560             const TAO_Literal_Constraint& right)
00561 {
00562   bool return_value = false;
00563   TAO_Expression_Type widest_type =
00564     TAO_Literal_Constraint::widest_type (left, right);
00565 
00566   switch (widest_type)
00567     {
00568     case TAO_STRING:
00569       return_value = (ACE_OS::strcmp ((const char*) left, (const char*) right) == 0);
00570       break;
00571     case TAO_DOUBLE:
00572       return_value = (CORBA::Double) left == (CORBA::Double) right;
00573       break;
00574     case TAO_SIGNED:
00575       return_value = (CORBA::Long) left == (CORBA::Long) right;
00576       break;
00577     case TAO_UNSIGNED:
00578       return_value = (CORBA::ULong) left == (CORBA::ULong) right;
00579       break;
00580     case TAO_BOOLEAN:
00581       return_value = (CORBA::Boolean) left == (CORBA::Boolean) right;
00582       break;
00583     }
00584 
00585   return return_value;
00586 }
00587 
00588 
00589 bool
00590 operator!= (const TAO_Literal_Constraint& left,
00591             const TAO_Literal_Constraint& right)
00592 {
00593   bool return_value = false;
00594   TAO_Expression_Type widest_type =
00595     TAO_Literal_Constraint::widest_type (left, right);
00596 
00597   switch (widest_type)
00598     {
00599     case TAO_STRING:
00600       return_value = (ACE_OS::strcmp ((const char*) left, (const char*) right) != 0);
00601       break;
00602     case TAO_DOUBLE:
00603       return_value = (CORBA::Double) left != (CORBA::Double) right;
00604       break;
00605     case TAO_SIGNED:
00606       return_value = (CORBA::Long) left != (CORBA::Long) right;
00607       break;
00608     case TAO_UNSIGNED:
00609       return_value = (CORBA::ULong) left != (CORBA::ULong) right;
00610       break;
00611     case TAO_BOOLEAN:
00612       return_value = (CORBA::Boolean) left != (CORBA::Boolean) right;
00613       break;
00614     }
00615 
00616   return return_value;
00617 }
00618 
00619 bool
00620 operator< (const TAO_Literal_Constraint& left,
00621            const TAO_Literal_Constraint& right)
00622 {
00623   bool return_value = false;
00624   TAO_Expression_Type widest_type =
00625     TAO_Literal_Constraint::widest_type (left, right);
00626 
00627   switch (widest_type)
00628     {
00629     case TAO_STRING:
00630       return_value = (ACE_OS::strcmp ((const char*) left, (const char*) right) < 0);
00631       break;
00632     case TAO_DOUBLE:
00633       return_value = (CORBA::Double) left < (CORBA::Double) right;
00634       break;
00635     case TAO_SIGNED:
00636       return_value = (CORBA::Long) left < (CORBA::Long) right;
00637       break;
00638     case TAO_UNSIGNED:
00639       return_value = (CORBA::ULong) left < (CORBA::ULong) right;
00640       break;
00641     case TAO_BOOLEAN:
00642       return_value = (CORBA::Boolean) left < (CORBA::Boolean) right;
00643       break;
00644     }
00645 
00646   return return_value;
00647 }
00648 
00649 bool
00650 operator<= (const TAO_Literal_Constraint& left,
00651             const TAO_Literal_Constraint& right)
00652 {
00653   bool return_value = false;
00654   TAO_Expression_Type widest_type =
00655     TAO_Literal_Constraint::widest_type (left, right);
00656 
00657   switch (widest_type)
00658     {
00659     case TAO_STRING:
00660       return_value = (ACE_OS::strcmp ((const char*) left, (const char*) right) <= 0);
00661       break;
00662     case TAO_DOUBLE:
00663       return_value = (CORBA::Double) left <= (CORBA::Double) right;
00664       break;
00665     case TAO_SIGNED:
00666       return_value = (CORBA::Long) left <= (CORBA::Long) right;
00667       break;
00668     case TAO_UNSIGNED:
00669       return_value = (CORBA::ULong) left <= (CORBA::ULong) right;
00670       break;
00671     }
00672 
00673   return return_value;
00674 }
00675 
00676 bool
00677 operator> (const TAO_Literal_Constraint& left,
00678            const TAO_Literal_Constraint& right)
00679 {
00680   bool return_value = false;
00681   TAO_Expression_Type widest_type =
00682     TAO_Literal_Constraint::widest_type (left, right);
00683 
00684   switch (widest_type)
00685     {
00686     case TAO_STRING:
00687       return_value = (ACE_OS::strcmp ((const char*) left, (const char*) right) > 0);
00688       break;
00689     case TAO_DOUBLE:
00690       return_value = (CORBA::Double) left > (CORBA::Double) right;
00691       break;
00692     case TAO_SIGNED:
00693       return_value = (CORBA::Long) left > (CORBA::Long) right;
00694       break;
00695     case TAO_UNSIGNED:
00696       return_value = (CORBA::ULong) left > (CORBA::ULong) right;
00697       break;
00698     }
00699 
00700   return return_value;
00701 }
00702 
00703 bool
00704 operator>= (const TAO_Literal_Constraint& left,
00705             const TAO_Literal_Constraint& right)
00706 {
00707   bool return_value = false;
00708   TAO_Expression_Type widest_type =
00709     TAO_Literal_Constraint::widest_type (left, right);
00710 
00711   switch (widest_type)
00712     {
00713     case TAO_STRING:
00714       return_value = (ACE_OS::strcmp ((const char*) left, (const char*) right) >= 0);
00715       break;
00716     case TAO_DOUBLE:
00717       return_value = (CORBA::Double) left >= (CORBA::Double) right;
00718       break;
00719     case TAO_SIGNED:
00720       return_value = (CORBA::Long) left >= (CORBA::Long) right;
00721       break;
00722     case TAO_UNSIGNED:
00723       return_value = (CORBA::ULong) left >= (CORBA::ULong) right;
00724       break;
00725     }
00726 
00727   return return_value;
00728 }
00729 
00730 
00731 bool
00732 operator== (CORBA::Double left, const TAO_Literal_Constraint& right)
00733 {
00734   return (left == (CORBA::Double) right);
00735 }
00736 
00737 bool
00738 operator== (const TAO::String_Manager& left,
00739             const TAO_Literal_Constraint& right)
00740 {
00741   bool result = false;
00742 
00743   if ((const char*) right != 0)
00744     result = ACE_OS::strcmp ((const char*) left,
00745                              (const char*) right) == 0;
00746   return result;
00747 }
00748 
00749 
00750 TAO_Literal_Constraint
00751 operator+ (const TAO_Literal_Constraint& left,
00752            const TAO_Literal_Constraint& right)
00753 {
00754   TAO_Expression_Type widest_type =
00755     TAO_Literal_Constraint::widest_type (left, right);
00756 
00757   switch (widest_type)
00758     {
00759     case TAO_DOUBLE:
00760       {
00761         CORBA::Double result = (CORBA::Double) left + (CORBA::Double) right;
00762         return TAO_Literal_Constraint ((CORBA::Double) result);
00763       }
00764     case TAO_SIGNED:
00765       {
00766         CORBA::Long result = (CORBA::Long) left + (CORBA::Long) right;
00767         return TAO_Literal_Constraint ((CORBA::Long) result);
00768       }
00769     case TAO_UNSIGNED:
00770       {
00771         CORBA::ULong result = (CORBA::ULong) left + (CORBA::ULong) right;
00772         return TAO_Literal_Constraint ((CORBA::ULong) result);
00773       }
00774     default:
00775       return TAO_Literal_Constraint ((CORBA::Long)0);
00776     }
00777 }
00778 
00779 TAO_Literal_Constraint
00780 operator- (const TAO_Literal_Constraint& left,
00781            const TAO_Literal_Constraint& right)
00782 {
00783   TAO_Expression_Type widest_type =
00784     TAO_Literal_Constraint::widest_type (left, right);
00785 
00786   switch (widest_type)
00787     {
00788     case TAO_DOUBLE:
00789       {
00790         CORBA::Double result = (CORBA::Double) left - (CORBA::Double) right;
00791         return TAO_Literal_Constraint ((CORBA::Double) result);
00792       }
00793     case TAO_SIGNED:
00794       {
00795         CORBA::Long result = (CORBA::Long) left - (CORBA::Long) right;
00796         return TAO_Literal_Constraint ((CORBA::Long) result);
00797       }
00798     case TAO_UNSIGNED:
00799       {
00800         CORBA::ULong result = (CORBA::ULong) left - (CORBA::ULong) right;
00801         return TAO_Literal_Constraint ((CORBA::ULong) result);
00802       }
00803     default:
00804       return TAO_Literal_Constraint ((CORBA::Long)0);
00805     }
00806 }
00807 
00808 TAO_Literal_Constraint
00809 operator* (const TAO_Literal_Constraint& left,
00810            const TAO_Literal_Constraint& right)
00811 {
00812   TAO_Expression_Type widest_type =
00813     TAO_Literal_Constraint::widest_type (left, right);
00814 
00815   switch (widest_type)
00816     {
00817     case TAO_DOUBLE:
00818       {
00819         CORBA::Double result = (CORBA::Double) left * (CORBA::Double) right;
00820         return TAO_Literal_Constraint ((CORBA::Double) result);
00821       }
00822     case TAO_SIGNED:
00823       {
00824         CORBA::Long result = (CORBA::Long) left * (CORBA::Long) right;
00825         return TAO_Literal_Constraint ((CORBA::Long) result);
00826       }
00827     case TAO_UNSIGNED:
00828       {
00829         CORBA::ULong result = (CORBA::ULong) left * (CORBA::ULong) right;
00830         return TAO_Literal_Constraint ((CORBA::ULong) result);
00831       }
00832     default:
00833       return TAO_Literal_Constraint ((CORBA::Long)0);
00834     }
00835 }
00836 
00837 TAO_Literal_Constraint
00838 operator/ (const TAO_Literal_Constraint& left,
00839            const TAO_Literal_Constraint& right)
00840 {
00841   TAO_Expression_Type widest_type =
00842     TAO_Literal_Constraint::widest_type (left, right);
00843 
00844   switch (widest_type)
00845     {
00846     case TAO_DOUBLE:
00847       {
00848         CORBA::Double result = (CORBA::Double) left / (CORBA::Double) right;
00849         return TAO_Literal_Constraint ((CORBA::Double) result);
00850       }
00851     case TAO_SIGNED:
00852       {
00853         CORBA::Long result = (CORBA::Long) left / (CORBA::Long) right;
00854         return TAO_Literal_Constraint ((CORBA::Long) result);
00855       }
00856     case TAO_UNSIGNED:
00857       {
00858         CORBA::ULong result = (CORBA::ULong) left / (CORBA::ULong) right;
00859         return TAO_Literal_Constraint ((CORBA::ULong) result);
00860       }
00861     default:
00862       return TAO_Literal_Constraint ((CORBA::Long)0);
00863     }
00864 }
00865 
00866 TAO_Literal_Constraint
00867 operator- (const TAO_Literal_Constraint& operand)
00868 {
00869   switch (operand.expr_type ())
00870     {
00871     case TAO_DOUBLE:
00872       {
00873         CORBA::Double result = - (CORBA::Double) operand;
00874         return TAO_Literal_Constraint ((CORBA::Double) result);
00875       }
00876     case TAO_SIGNED:
00877       {
00878         CORBA::Long result = - (CORBA::Long) operand;
00879         return TAO_Literal_Constraint ((CORBA::Long) result);
00880       }
00881     case TAO_UNSIGNED:
00882       {
00883         CORBA::Long result = - (CORBA::Long) ((CORBA::ULong) operand);
00884         return TAO_Literal_Constraint ((CORBA::ULong) result);
00885       }
00886     default:
00887       return TAO_Literal_Constraint ((CORBA::Long)0);
00888     }
00889 }
00890 
00891 TAO_Expression_Type
00892 TAO_Literal_Constraint::widest_type (const TAO_Literal_Constraint& left,
00893                                      const TAO_Literal_Constraint& right)
00894 {
00895   TAO_Expression_Type left_type = left.expr_type (),
00896     right_type = right.expr_type (),
00897     return_value = right_type;
00898 
00899   if (right_type != left_type)
00900     {
00901       if (right_type > left_type)
00902         return_value = right_type;
00903       else
00904         return_value = left_type;
00905     }
00906 
00907   return return_value;
00908 }
00909 
00910 void
00911 TAO_Literal_Constraint::copy (const TAO_Literal_Constraint& lit)
00912 {
00913   this->type_ = lit.type_;
00914   if (this->type_ == TAO_STRING)
00915     this->op_.str_ = CORBA::string_dup (lit.op_.str_);
00916   else if (this->type_ == TAO_DOUBLE)
00917     this->op_.double_ = lit.op_.double_;
00918   else if (this->type_ == TAO_UNSIGNED)
00919     this->op_.uinteger_ = lit.op_.uinteger_;
00920   else if (this->type_ == TAO_SIGNED)
00921     this->op_.integer_ = lit.op_.integer_;
00922   else if (this->type_ == TAO_BOOLEAN)
00923     this->op_.bool_ = lit.op_.bool_;
00924   else if (this->type_ == TAO_SEQUENCE)
00925     this->op_.any_ = lit.op_.any_;
00926   else
00927     type_ = TAO_UNKNOWN;
00928 }
00929 
00930 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:59:57 2006 for TAO_CosTrader by doxygen 1.3.6