Constraint_Interpreter.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Constraint_Interpreter.h
00006  *
00007  *  $Id: Constraint_Interpreter.h 77001 2007-02-12 07:54:49Z johnnyw $
00008  *
00009  *  @author Seth Widoff <sbw1@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef TAO_CONSTRAINT_INTERPRETER_H
00015 #define TAO_CONSTRAINT_INTERPRETER_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "orbsvcs/Trader/Constraint_Nodes.h"
00019 #include "orbsvcs/Trader/Constraint_Visitors.h"
00020 #include "orbsvcs/Trader/Interpreter.h"
00021 
00022 #include "orbsvcs/CosTradingS.h"
00023 #include "orbsvcs/CosTradingReposS.h"
00024 
00025 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00026 
00027 class TAO_Constraint_Evaluator;
00028 class TAO_Constraint_Validator;
00029 
00030 /**
00031  * @class TAO_Constraint_Interpreter
00032  *
00033  * @brief TAO_Constraint_Interpreter will, given a constraint string whose
00034  * syntax and semantics comply with the trader specification for the
00035  * constraint language, determine if a CosTrading::Offer meets the
00036  * constraints.
00037  *
00038  * TAO_Constraint_Interpreter will first build an expression tree
00039  * representing the constraint expression using Lex and Yacc. Then,
00040  * using a TAO_Constraint_Validator, it will validate the semantic
00041  * correctness of the tree. When the evaluate method is invoked with
00042  * an Offer, the TAO_Constraint_Interpreter will construct an
00043  * EvaluationVisitor, which will evaluate the tree and decide
00044  * whether the offer meets the constraints.
00045  */
00046 class TAO_Trading_Serv_Export TAO_Constraint_Interpreter : public TAO_Interpreter
00047 {
00048 public:
00049   // = Initialization and termination methods.
00050   TAO_Constraint_Interpreter (const CosTradingRepos::ServiceTypeRepository::TypeStruct& ts,
00051                               const char* constraints);
00052 
00053   /**
00054    * This constructor builds an expression tree representing the
00055    * constraint specified in <constraints>, and throws an Illegal
00056    * Constraint exception if the constraint given has syntax errors or
00057    * semantic errors, such as mismatched types.
00058    */
00059   TAO_Constraint_Interpreter (TAO_Constraint_Validator& validator,
00060                               const char* constraints);
00061 
00062   /// Destructor
00063   ~TAO_Constraint_Interpreter (void);
00064 
00065   CORBA::Boolean evaluate (CosTrading::Offer* offer);
00066 
00067   CORBA::Boolean evaluate (TAO_Constraint_Evaluator& evaluator);
00068 
00069   // Determine whether an offer fits the constraints with which the
00070   // tree was constructed. This method is thread safe (hopefully).
00071 };
00072 
00073 /**
00074  * @class TAO_Preference_Interpreter
00075  *
00076  * @brief The TAO_Preference_Interpreter will, given a valid preference
00077  * string and offers, will order the offers based on the offers'
00078  * compliance with the preferences.
00079  *
00080  * Each time the order_offer method is invoked, the
00081  * TAO_Preference_Interpreter stores the offer reference in the
00082  * order dictated by its evaluation of the preference string. After
00083  * the TAO_Preference_Interpreter client has finished ordering all
00084  * the offers, it will extract the offers in order using the
00085  * remove_offer method.
00086  */
00087 class TAO_Trading_Serv_Export TAO_Preference_Interpreter : public TAO_Interpreter
00088 {
00089 public:
00090   // = Initialization and termination methods.
00091   TAO_Preference_Interpreter (const CosTradingRepos::ServiceTypeRepository::TypeStruct& ts,
00092                               const char* preference);
00093 
00094   /**
00095     * Parse the preference string, determining first if it's
00096     * valid. Throw an IllegalPreference exception if the preference
00097     * doesn't conform to the BNF grammar for preferences.
00098     */
00099   TAO_Preference_Interpreter (TAO_Constraint_Validator& validator,
00100                               const char* preference);
00101 
00102   /// Destructor
00103   ~TAO_Preference_Interpreter(void);
00104 
00105   void order_offer (CosTrading::Offer* offer,
00106                     CosTrading::OfferId offer_id = 0);
00107 
00108   /// Evaluate the offer, and order it internally based on the results
00109   /// of the evaluation.
00110   void order_offer (TAO_Constraint_Evaluator& evaluator,
00111                     CosTrading::Offer* offer,
00112                     CosTrading::OfferId offer_id = 0);
00113 
00114   int remove_offer (CosTrading::Offer*& offer,
00115                     CosTrading::OfferId& offer_id);
00116 
00117   /// Remove the next offer. The offer returned will be the next in the
00118   /// ordering determined by the preference string.
00119   int remove_offer (CosTrading::Offer*& offer);
00120 
00121   /// Return the number of offers remaining in the ordering.
00122   size_t num_offers (void);
00123 
00124   struct Preference_Info
00125   {
00126     /// True if the preference evaluation didn't return an error for this offer.
00127     CORBA::Boolean evaluated_;
00128 
00129     /// The value of the preference evaluation.
00130     TAO_Literal_Constraint value_;
00131 
00132     /// The offer id of this offer.
00133     CosTrading::OfferId offer_id_;
00134 
00135     /// A pointer to the offer.
00136     CosTrading::Offer* offer_;
00137   };
00138 
00139   typedef ACE_Unbounded_Queue<Preference_Info> Ordered_Offers;
00140 
00141 private:
00142 
00143   /// Disallow copying.
00144   TAO_Preference_Interpreter (const TAO_Preference_Interpreter&);
00145   TAO_Preference_Interpreter& operator= (const TAO_Preference_Interpreter&);
00146 
00147   /// The ordered list of offers.
00148   Ordered_Offers offers_;
00149 };
00150 
00151 TAO_END_VERSIONED_NAMESPACE_DECL
00152 
00153 #include /**/ "ace/post.h"
00154 #endif /* TAO_CONSTRAINT_INTERPRETER_H */

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