summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.h
blob: f24ec8c274d241906c207705dc676afbaf97a0c0 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* -*- C++ -*- */

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

#ifndef TAO_PROPERTY_EVALUATOR_H
#define TAO_PROPERTY_EVALUATOR_H

#include <map>
#include <set>
#include <string>

#include "orbsvcs/CosTradingC.h"

class TAO_Property_Evaluator
//
// = TITLE
//   This class abstracts away the details of obtaining property
//   values and property types. Since the procedure for obtaining the
//   value or type of a dynamic property is disparate from the method
//   for a static property, TAO_Property_Evaluator provides methods
//   that will unify the two approaches under a single
//   interface. Since dynamic properties aren't necessarily supported
//   by a trader, this class accounts for that contingency. The use of 
//   indexed lookups allows them to occur in constant time on the
//   CORBA sequences, but requires that the client know the layout of
//   properties ahead of time. 
{
public:
  
  TAO_Property_Evaluator(CosTrading::PropertySeq& properties,
			 CORBA::Boolean supports_dp = 1);
  
  TAO_Property_Evaluator(CosTrading::Offer& offer,
			 CORBA::Boolean supports_dp = 1);
  // Construct an instance of TAO_Property_Evaluator that operates on
  // an <offer> where the support for dynamic properties is dictated
  // by <supports_dynamic_properties>.
  
  int is_dynamic_property(int index);
  // Returns 1 if the property at index <index> is dynamic. Returns a
  // 0 when the index is out of bounds.
  
  CORBA::Any* property_value(int index, CORBA::Environment& _env)
    TAO_THROW_SPEC ((CosTradingDynamic::DPEvalFailure));
  // Returns value of the property whose index is <index>. If the
  // property at that index is dynamic and the trader supports dynamic 
  // properties, then the property_value method will obtain the value
  // of the dynamic property using the evalDP method on the
  // CosTradingDynamic::DynamicPropEval interface, passing on a
  // CosTradingDynamic::DPEvalFailure exception on failure. If the
  // property index is undefined, the method returns a null pointer.
  
  CORBA::TypeCode* property_type(int index);
  // Returns the type of the property whose index is <index>. If the
  // property is dynamic and the trader supports dynamic properties,
  // then the method returns the <returned_type> field of the
  // CosTradingDynamic::DynamicProp struct associated with the
  // property name. If the index is out of bounds, the method returns 
  // a null pointer (that is, 0).
  
protected:

  typedef CosTradingDynamic::DynamicProp DP_Struct;
  typedef CosTradingDynamic::DynamicPropEval DP_Eval;
  
  CosTrading::PropertySeq& props_;
  // The offer from which the TAO_Property_Evaluator extracts property 
  // information.

  int supports_dp_;
};

class TAO_Property_Evaluator_By_Name : public TAO_Property_Evaluator
//
// = TITLE
//    This class extends the TAO_Property_Evaluator to allow lookups
//    based on the property name of interest. Since the property
//    information is contained within an integer indexed array,
//    lookups may occur in O(n) time, where n is the length of the
//    array. To make lookups by name more efficient,
//    TAO_Property_Evaluator_By_Name creates a mapping of property
//    names to integer indicies, upon which lookups are guaranteed to
//    be O(lg n).
{
public:

  TAO_Property_Evaluator_By_Name (CosTrading::PropertySeq& properties,
				  CORBA::Environment& _env,
				  CORBA::Boolean supports_dp = 1)
    TAO_THROW_SPEC ((CosTrading::DuplicatePropertyName,
		     CosTrading::IllegalPropertyName));
  
  TAO_Property_Evaluator_By_Name(CosTrading::Offer& offer,
				 CORBA::Boolean supports_dp = 1);
  // Construct an instance of TAO_Property_Evaluator that operates on
  // an <offer> where the support for dynamic properties is dictated
  // by <supports_dynamic_properties>.

  int is_dynamic_property(const char* property_name);
  // Returns 1 if the property whose name is <property_name> is
  // defined and dynamic. If the property is undefined, this method
  // will throw a Property_Undefined exception with impunity.
  
  CORBA::Any* property_value(const char* property_name,
			     CORBA::Environment& _env)
    TAO_THROW_SPEC ((CosTradingDynamic::DPEvalFailure));
  // This method is identical to its counterpart in
  // TAO_Property_Evaluator, except property_value first discovers the 
  // index through a string matching lookup.
  
  CORBA::TypeCode* property_type(const char* property_name);
  // This method is identical to its counterpart in
  // TAO_Property_Evaluator, exception property_type first discovers
  // the index through a string matching lookup.

  const CosTrading::Property* get_property (const char* property_name);
  
private:
  
  typedef map<string, int, less<string> > Lookup_Table;
  typedef Lookup_Table::iterator Lookup_Table_Iter;
  // A mapping, upon which lookups will take O(lg n), of property
  // names to sequence indices.
  
  Lookup_Table table_;
  // The instance of the above mapping for the offer provided in the
  // constructor. 
};

#endif /* TAO_PROPERTY_EVALUATOR_H */