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