Constraint_Interpreter.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Constraint_Interpreter.h
00006  *
00007  *  Constraint_Interpreter.h,v 1.34 2006/03/14 06:14:35 jtc Exp
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                               ACE_ENV_ARG_DECL)
00053     ACE_THROW_SPEC ((CosTrading::IllegalConstraint,
00054                      CORBA::NO_MEMORY));
00055 
00056   /**
00057    * This constructor builds an expression tree representing the
00058    * constraint specified in <constraints>, and throws an Illegal
00059    * Constraint exception if the constraint given has syntax errors or
00060    * semantic errors, such as mismatched types.
00061    */
00062   TAO_Constraint_Interpreter (TAO_Constraint_Validator& validator,
00063                               const char* constraints
00064                               ACE_ENV_ARG_DECL)
00065     ACE_THROW_SPEC ((CosTrading::IllegalConstraint,
00066                      CORBA::NO_MEMORY));
00067 
00068   /// Destructor
00069   ~TAO_Constraint_Interpreter (void);
00070 
00071   CORBA::Boolean evaluate (CosTrading::Offer* offer);
00072 
00073   CORBA::Boolean evaluate (TAO_Constraint_Evaluator& evaluator);
00074 
00075   // Determine whether an offer fits the constraints with which the
00076   // tree was constructed. This method is thread safe (hopefully).
00077 };
00078 
00079 /**
00080  * @class TAO_Preference_Interpreter
00081  *
00082  * @brief The TAO_Preference_Interpreter will, given a valid preference
00083  * string and offers, will order the offers based on the offers'
00084  * compliance with the preferences.
00085  *
00086  * Each time the order_offer method is invoked, the
00087  * TAO_Preference_Interpreter stores the offer reference in the
00088  * order dictated by its evaluation of the preference string. After
00089  * the TAO_Preference_Interpreter client has finished ordering all
00090  * the offers, it will extract the offers in order using the
00091  * remove_offer method.
00092  */
00093 class TAO_Trading_Serv_Export TAO_Preference_Interpreter : public TAO_Interpreter
00094 {
00095 public:
00096   // = Initialization and termination methods.
00097   TAO_Preference_Interpreter (const CosTradingRepos::ServiceTypeRepository::TypeStruct& ts,
00098                               const char* preference
00099                               ACE_ENV_ARG_DECL)
00100     ACE_THROW_SPEC ((CosTrading::Lookup::IllegalPreference,
00101                      CORBA::NO_MEMORY));
00102 
00103   /**
00104         * Parse the preference string, determining first if it's
00105         * valid. Throw an IllegalPreference exception if the preference
00106         * doesn't conform to the BNF grammar for preferences.
00107         */
00108   TAO_Preference_Interpreter (TAO_Constraint_Validator& validator,
00109                               const char* preference
00110                               ACE_ENV_ARG_DECL)
00111     ACE_THROW_SPEC ((CosTrading::Lookup::IllegalPreference,
00112                      CORBA::NO_MEMORY));
00113 
00114   /// Destructor
00115   ~TAO_Preference_Interpreter(void);
00116 
00117   void order_offer (CosTrading::Offer* offer,
00118                     CosTrading::OfferId offer_id = 0);
00119 
00120   /// Evaluate the offer, and order it internally based on the results
00121   /// of the evaluation.
00122   void order_offer (TAO_Constraint_Evaluator& evaluator,
00123                     CosTrading::Offer* offer,
00124                     CosTrading::OfferId offer_id = 0);
00125 
00126   int remove_offer (CosTrading::Offer*& offer,
00127                     CosTrading::OfferId& offer_id);
00128 
00129   /// Remove the next offer. The offer returned will be the next in the
00130   /// ordering determined by the preference string.
00131   int remove_offer (CosTrading::Offer*& offer);
00132 
00133   /// Return the number of offers remaining in the ordering.
00134   size_t num_offers (void);
00135 
00136   struct Preference_Info
00137   {
00138     /// True if the preference evaluation didn't return an error for this offer.
00139     CORBA::Boolean evaluated_;
00140 
00141     /// The value of the preference evaluation.
00142     TAO_Literal_Constraint value_;
00143 
00144     /// The offer id of this offer.
00145     CosTrading::OfferId offer_id_;
00146 
00147     /// A pointer to the offer.
00148     CosTrading::Offer* offer_;
00149   };
00150 
00151   typedef ACE_Unbounded_Queue<Preference_Info> Ordered_Offers;
00152 
00153 private:
00154 
00155   /// Disallow copying.
00156   TAO_Preference_Interpreter (const TAO_Preference_Interpreter&);
00157   TAO_Preference_Interpreter& operator= (const TAO_Preference_Interpreter&);
00158 
00159   /// The ordered list of offers.
00160   Ordered_Offers offers_;
00161 };
00162 
00163 TAO_END_VERSIONED_NAMESPACE_DECL
00164 
00165 #include /**/ "ace/post.h"
00166 #endif /* TAO_CONSTRAINT_INTERPRETER_H */

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