Constraint_Nodes.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Constraint_Nodes.h
00006  *
00007  *  Constraint_Nodes.h,v 1.30 2006/04/19 10:18:11 jwillemsen Exp
00008  *
00009  *  @author Seth Widoff <sbw1@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef TAO_CONSTRAINT_NODES_H
00015 #define TAO_CONSTRAINT_NODES_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "orbsvcs/Trader/Constraint_Tokens.h"
00019 
00020 #include "tao/Basic_Types.h"
00021 #include "tao/String_Manager_T.h"
00022 
00023 #include "orbsvcs/Trader/trading_serv_export.h"
00024 
00025 #if defined(_MSC_VER)
00026 #pragma warning(push)
00027 #pragma warning (disable:4250)
00028 #endif /* _MSC_VER */
00029 
00030 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00031 
00032 class TAO_Constraint_Visitor;
00033 typedef unsigned short TAO_Expression_Type;
00034 
00035 namespace CORBA
00036 {
00037   class Any;
00038   typedef Any *Any_ptr;
00039 
00040   class TypeCode;
00041   typedef TypeCode *TypeCode_ptr;
00042 }
00043 
00044 /**
00045  * @class TAO_Constraint
00046  *
00047  * @brief TAO_Constraint is the base class of all nodes on the
00048  * constraint expression tree.
00049  *
00050  * An TAO_Constraint knows what type of operation or entity
00051  * it represents, and which method on TAO_Constraint_Visitor
00052  * correlates to its type. When the accept method is invoked, a
00053  * subclass dispatches the method on an TAO_Constraint_Visitor
00054  * correlating to its type.
00055  */
00056 class TAO_Trading_Serv_Export TAO_Constraint
00057 {
00058 public:
00059 
00060   /**
00061    * Implementing the pattern of double dispatching, each subclass of
00062    * TAO_Constraint will call back on an InterpreterVisitor the
00063    * method to handle a node of its ExpressionType.
00064    */
00065   virtual int accept (TAO_Constraint_Visitor* visitor) = 0;
00066 
00067   /// Return the expression type represented by this node.
00068   virtual TAO_Expression_Type expr_type (void) const = 0;
00069 
00070   virtual ~TAO_Constraint (void) {}
00071 };
00072 
00073 /**
00074  * @class TAO_Noop_Constraint
00075  *
00076  * @brief A node that represents an operation with no operands.
00077  */
00078 class TAO_Trading_Serv_Export TAO_Noop_Constraint : public TAO_Constraint
00079 {
00080 public:
00081 
00082   TAO_Noop_Constraint (TAO_Expression_Type type)
00083     : type_ (type) {}
00084 
00085   virtual int accept (TAO_Constraint_Visitor* visitor);
00086 
00087   virtual TAO_Expression_Type expr_type (void) const
00088     { return this->type_; }
00089 
00090 private:
00091 
00092   TAO_Expression_Type type_;
00093 };
00094 
00095 /**
00096  * @class TAO_Binary_Constraint
00097  *
00098  * @brief TAO_Binary_Constraint represents an operation with left
00099  * and right operands.
00100  */
00101 class TAO_Trading_Serv_Export TAO_Binary_Constraint : public TAO_Constraint
00102 {
00103 public:
00104 
00105   TAO_Binary_Constraint (TAO_Expression_Type op_type,
00106                          TAO_Constraint* left,
00107                          TAO_Constraint* right);
00108 
00109   virtual int accept (TAO_Constraint_Visitor* visitor);
00110 
00111   virtual ~TAO_Binary_Constraint (void);
00112 
00113   virtual TAO_Expression_Type expr_type (void) const
00114     { return this->op_; }
00115 
00116   /// Return the left operand of the binary expression
00117   TAO_Constraint* left_operand (void) const;
00118 
00119   /// Return the right operand of the binary expression
00120   TAO_Constraint* right_operand (void) const;
00121 
00122   // Allow double dispatching without creating an inundation of
00123   // classes by using a dispatch table of static method pointers to
00124   // invoke the correct visitor method as efficiently as a virtual
00125   // method invocation.
00126   static int visit_or (TAO_Constraint_Visitor*, TAO_Binary_Constraint*);
00127   static int visit_and (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00128   static int visit_less_than (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00129   static int visit_less_than_equal (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00130   static int visit_greater_than (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00131   static int visit_greater_than_equal (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00132   static int visit_equal (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00133   static int visit_not_equal (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00134   static int visit_add (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00135   static int visit_sub (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00136   static int visit_mult (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00137   static int visit_div (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00138   static int visit_twiddle (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00139   static int visit_in (TAO_Constraint_Visitor* , TAO_Binary_Constraint*);
00140 
00141 private:
00142 
00143   TAO_Binary_Constraint (const TAO_Binary_Constraint&);
00144   TAO_Binary_Constraint& operator= (const TAO_Binary_Constraint&);
00145 
00146   /// The operator type
00147   TAO_Expression_Type op_;
00148 
00149   /// The operands of the expression
00150   TAO_Constraint* left_;
00151   TAO_Constraint* right_;
00152 };
00153 
00154 /**
00155  * @class TAO_Unary_Constraint
00156  *
00157  * @brief TAO_Unary_Constraint represents an operation with only
00158  * one operand.
00159  */
00160 class TAO_Trading_Serv_Export TAO_Unary_Constraint : public TAO_Constraint
00161 {
00162 public:
00163 
00164   TAO_Unary_Constraint (TAO_Expression_Type op_type,
00165                                  TAO_Constraint* operand);
00166 
00167   virtual ~TAO_Unary_Constraint (void);
00168 
00169   virtual int accept (TAO_Constraint_Visitor* visitor);
00170 
00171   virtual TAO_Expression_Type expr_type (void) const
00172     { return this->op_; }
00173 
00174   TAO_Constraint* operand (void);
00175 
00176 private:
00177 
00178   TAO_Unary_Constraint (const TAO_Unary_Constraint&);
00179   TAO_Unary_Constraint& operator= (const TAO_Unary_Constraint&);
00180 
00181   /// The operator type
00182   TAO_Expression_Type op_;
00183 
00184   /// The operand of the expression
00185   TAO_Constraint* operand_;
00186 };
00187 
00188 /**
00189  * @class TAO_Property_Constraint
00190  *
00191  * @brief TAO_Property_Constraint represents a property whose
00192  * value is determined by the offer being evaluated.
00193  */
00194 class TAO_Trading_Serv_Export TAO_Property_Constraint : public TAO_Constraint
00195 {
00196 public:
00197 
00198   TAO_Property_Constraint (const char* name);
00199 
00200   virtual ~TAO_Property_Constraint (void);
00201 
00202   virtual int accept (TAO_Constraint_Visitor* visitor);
00203 
00204   virtual TAO_Expression_Type expr_type (void) const
00205     { return TAO_IDENT; }
00206 
00207   /// Returns the name of the property.
00208   const char* name (void) const;
00209 
00210 private:
00211 
00212   TAO_Property_Constraint (const TAO_Property_Constraint&);
00213   TAO_Property_Constraint& operator= (const TAO_Property_Constraint&);
00214 
00215   /// The name of the property.
00216   char* name_;
00217 };
00218 
00219 /**
00220  * @class TAO_Literal_Constraint
00221  *
00222  * @brief TAO_Literal_Constraint represents a literal occuring in
00223  * the constraint expression tree.
00224  */
00225 class TAO_Trading_Serv_Export TAO_Literal_Constraint : public TAO_Constraint
00226 {
00227  public:
00228 
00229   TAO_Literal_Constraint (void)
00230     : type_ (TAO_UNKNOWN) {}
00231 
00232   // = Constructors for each of the various types of literals.
00233 
00234   TAO_Literal_Constraint (CORBA::Any* any);
00235   TAO_Literal_Constraint (CORBA::ULong uinteger);
00236   TAO_Literal_Constraint (CORBA::Long integer);
00237   TAO_Literal_Constraint (CORBA::Boolean boolean);
00238   TAO_Literal_Constraint (CORBA::Double doub);
00239   TAO_Literal_Constraint (const char* str);
00240 
00241   /// Copy constructor
00242   TAO_Literal_Constraint (const TAO_Literal_Constraint& lit);
00243 
00244   /// Destructor.
00245   ~TAO_Literal_Constraint(void);
00246 
00247   /// Visitor accept methods.
00248   virtual int accept (TAO_Constraint_Visitor* visitor);
00249 
00250   virtual TAO_Expression_Type expr_type (void) const
00251     { return type_; }
00252 
00253   /// Assignment operator.
00254   void operator= (const TAO_Literal_Constraint& co);
00255 
00256   // Conversion routines.
00257   operator CORBA::Boolean (void) const;
00258   operator CORBA::ULong (void) const;
00259   operator CORBA::Long (void) const;
00260   operator CORBA::Double (void) const;
00261   operator const char* (void) const;
00262   operator const CORBA::Any* (void) const;
00263 
00264   // Return the type represented by this MysteryOperand.
00265 
00266   // = Comparison operators.
00267 
00268   friend bool
00269     operator< (const TAO_Literal_Constraint& left,
00270                const TAO_Literal_Constraint& right);
00271 
00272   friend bool
00273     operator<= (const TAO_Literal_Constraint& left,
00274                 const TAO_Literal_Constraint& right);
00275 
00276   friend bool
00277     operator> (const TAO_Literal_Constraint& left,
00278                const TAO_Literal_Constraint& right);
00279 
00280   friend bool
00281     operator>= (const TAO_Literal_Constraint& left,
00282                 const TAO_Literal_Constraint& right);
00283 
00284   friend bool
00285     operator== (const TAO_Literal_Constraint& left,
00286                 const TAO_Literal_Constraint& right);
00287 
00288   friend bool
00289     operator!= (const TAO_Literal_Constraint& left,
00290                 const TAO_Literal_Constraint& right);
00291 
00292   friend bool
00293     operator== (double left,
00294                 const TAO_Literal_Constraint& right);
00295 
00296   friend bool
00297     operator== (const TAO::String_Manager& left,
00298                 const TAO_Literal_Constraint& right);
00299 
00300   // = Arithmetic operators.
00301 
00302   friend TAO_Literal_Constraint
00303     operator+ (const TAO_Literal_Constraint& left,
00304                const TAO_Literal_Constraint& right);
00305 
00306   friend TAO_Literal_Constraint
00307     operator- (const TAO_Literal_Constraint& left,
00308                const TAO_Literal_Constraint& right);
00309 
00310   friend TAO_Literal_Constraint
00311     operator* (const TAO_Literal_Constraint& left,
00312                const TAO_Literal_Constraint& right);
00313 
00314   friend TAO_Literal_Constraint
00315     operator/ (const TAO_Literal_Constraint& left,
00316                const TAO_Literal_Constraint& right);
00317 
00318   friend TAO_Literal_Constraint
00319     operator- (const TAO_Literal_Constraint& operand);
00320 
00321   /// Ensure both operands are of the same simple numeric type.
00322   static TAO_Expression_Type
00323     widest_type (const TAO_Literal_Constraint& left,
00324                  const TAO_Literal_Constraint& right);
00325 
00326   /// Determine the comparable Expression Type from the CORBA type
00327   static TAO_Expression_Type
00328     comparable_type (CORBA::TypeCode_ptr type);
00329 
00330  private:
00331 
00332   /// Private copy method.
00333   void copy (const TAO_Literal_Constraint& co);
00334 
00335   union
00336   {
00337     char* str_;
00338     CORBA::Any_ptr any_;
00339     CORBA::ULong uinteger_;
00340     CORBA::Long integer_;
00341     CORBA::Boolean bool_;
00342     CORBA::Double double_;
00343   } op_;
00344   // Union of the possible literal types.
00345 
00346   /// The actual types of the TAO_Literal_Constraint.
00347   TAO_Expression_Type type_;
00348 
00349 };
00350 
00351 TAO_END_VERSIONED_NAMESPACE_DECL
00352 
00353 #if defined(_MSC_VER)
00354 #pragma warning(pop)
00355 #endif /* _MSC_VER */
00356 
00357 #include /**/ "ace/post.h"
00358 #endif /* TAO_CONSTRAINT_NODES_H */

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