summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Trader/Preference_Interpreter.h
blob: 7ff86a6ba171cc3e870fa64e2661a81d1f04336d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* -*- C++ -*- */

// ========================================================================
// $Id$
// 
// = LIBRARY 
//    orbsvcs
//  
// = FILENAME 
//    Preference_Interpreter.h
// 
// = AUTHOR
//    Seth Widoff <sbw1@cs.wustl.edu>
// 
// ========================================================================

#ifndef TAO_PREFERENCE_INTERPRETER_H
#define TAO_PREFERENCE_INTERPRETER_H

#include <map>
#include "Interpreter.h"
#include "Constraint_Evaluator.h"
#include "Constraint_Validator.h"

class TAO_Preference_Interpreter : public TAO_Interpreter
// = TITLE
//   The TAO_Preference_Interpreter will, given a valid preference
//   string and offers, will order the offers based on the offers'
//   compliance with the preferences.
//
// = DESCRIPTION
//   Each time the order_offer method is invoked, the
//   TAO_Preference_Interpreter stores the offer reference in the
//   order dictated by its evaluation of the preference string. After
//   the TAO_Preference_Interpreter client has finished ordering all
//   the offers, it will extract the offers in order using the
//   remove_offer method.
{
public:

  TAO_Preference_Interpreter(CosTradingRepos::ServiceTypeRepository::TypeStruct* ts,
			     const char* preference,
			     CORBA::Environment& env)
    TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPreference));

  TAO_Preference_Interpreter(TAO_Constraint_Validator& validator,
			     const char* preference,
			     CORBA::Environment& env)
    TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPreference));

  // Parse the preference string, determining first if it's
  // valid. Throw an IllegalPreference exception if the preference
  // doesn't conform to the BNF grammar for preferences. 
  
  ~TAO_Preference_Interpreter(void);
  // Destructor
  
  void order_offer (CosTrading::OfferId offer_id,
		    CosTrading::Offer* offer);

  void order_offer (CosTrading::OfferId offer_id,
		    CosTrading::Offer* offer,
		    TAO_Constraint_Evaluator& evaluator);
  // Evaluate the offer, and order it internally based on the results
  // of the evaluation.

  int remove_offer (CosTrading::OfferId& offer_id,
		    CosTrading::Offer*& offer);
  // Remove the next offer. The offer returned will be the next in the 
  // ordering determined by the preference string. 

  int num_offers(void);
  // Return the number of offers remaining in the ordering.

private:

  typedef multimap
  < TAO_Literal_Constraint,
    pair < CosTrading::OfferId, CosTrading::Offer* >,
    less < TAO_Literal_Constraint > >
  ORDERED_OFFERS;
  // The map of ordered offers to their order value.
    
  ORDERED_OFFERS offers_;
};

#endif /* TAO_PREFERENCE_INTERPRETER_H */