Constraint_Nodes.h

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

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