Constraint_Nodes.cpp

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

Generated on Tue Feb 2 17:49:26 2010 for TAO_CosTrader by  doxygen 1.4.7