#include <Trader_Utils.h>
Inheritance diagram for TAO_Property_Evaluator:
Public Member Functions | |
TAO_Property_Evaluator (const CosTrading::PropertySeq &properties, CORBA::Boolean supports_dp=1) | |
TAO_Property_Evaluator (CosTrading::Offer &offer, CORBA::Boolean supports_dp=1) | |
virtual | ~TAO_Property_Evaluator (void) |
Clean up dynamic properties. | |
int | is_dynamic_property (int index) |
CORBA::Any * | property_value (int index) |
CORBA::TypeCode_ptr | property_type (int index) |
Protected Types | |
typedef CosTradingDynamic::DynamicProp | DP_Struct |
typedef CosTradingDynamic::DynamicPropEval | DP_Eval |
Protected Attributes | |
const CosTrading::PropertySeq & | props_ |
int | supports_dp_ |
CORBA::Any ** | dp_cache_ |
Private Member Functions | |
TAO_Property_Evaluator (const TAO_Property_Evaluator &) | |
TAO_Property_Evaluator & | operator= (const TAO_Property_Evaluator &) |
Definition at line 42 of file Trader_Utils.h.
typedef CosTradingDynamic::DynamicPropEval TAO_Property_Evaluator::DP_Eval [protected] |
Definition at line 89 of file Trader_Utils.h.
typedef CosTradingDynamic::DynamicProp TAO_Property_Evaluator::DP_Struct [protected] |
Definition at line 88 of file Trader_Utils.h.
TAO_Property_Evaluator::TAO_Property_Evaluator | ( | const CosTrading::PropertySeq & | properties, | |
CORBA::Boolean | supports_dp = 1 | |||
) |
Definition at line 193 of file Trader_Utils.cpp.
References props_.
00195 : props_ (props), 00196 supports_dp_ (supports_dp), 00197 dp_cache_ (new CORBA::Any*[props.length ()]) 00198 { 00199 if (this->dp_cache_ != 0) 00200 { 00201 for (CORBA::ULong i = 0; i < this->props_.length (); i++) 00202 this->dp_cache_[i] = 0; 00203 } 00204 }
TAO_Property_Evaluator::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>.
Definition at line 208 of file Trader_Utils.cpp.
References props_.
00210 : props_ (offer.properties), 00211 supports_dp_ (supports_dp), 00212 dp_cache_ (new CORBA::Any*[offer.properties.length ()]) 00213 { 00214 if (this->dp_cache_ != 0) 00215 for (CORBA::ULong i = 0; i < this->props_.length (); i++) 00216 this->dp_cache_[i] = 0; 00217 }
TAO_Property_Evaluator::~TAO_Property_Evaluator | ( | void | ) | [virtual] |
Clean up dynamic properties.
Definition at line 219 of file Trader_Utils.cpp.
References dp_cache_, and props_.
00220 { 00221 // Clean up the results of any dynamic properties. 00222 for (CORBA::ULong i = 0; i < this->props_.length (); i++) 00223 if (this->dp_cache_[i] != 0) 00224 delete this->dp_cache_[i]; 00225 00226 delete [] this->dp_cache_; 00227 }
TAO_Property_Evaluator::TAO_Property_Evaluator | ( | const TAO_Property_Evaluator & | ) | [private] |
int TAO_Property_Evaluator::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.
Definition at line 230 of file Trader_Utils.cpp.
References props_.
Referenced by TAO_Offer_Modifier::merge_properties(), TAO_Offer_Filter::ok_to_consider(), and property_value().
00231 { 00232 int return_value = 0; 00233 int num_properties = this->props_.length(); 00234 00235 // Ensure index is in bounds. 00236 if (index >= 0 && index < num_properties) 00237 { 00238 // Obtain the value of the property at index <index>. 00239 const CORBA::Any& value = this->props_[index].value; 00240 CORBA::TypeCode_var type = value.type (); 00241 00242 // @@ Seth, this will not work on platforms using environment variable. 00243 CORBA::Boolean equal = type->equal (CosTradingDynamic::_tc_DynamicProp); 00244 00245 if (equal) 00246 return_value = 1; 00247 } 00248 00249 return return_value; 00250 }
TAO_Property_Evaluator& TAO_Property_Evaluator::operator= | ( | const TAO_Property_Evaluator & | ) | [private] |
CORBA::TypeCode_ptr TAO_Property_Evaluator::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).
Definition at line 310 of file Trader_Utils.cpp.
References props_.
Referenced by TAO_Offer_Modifier::merge_properties().
00311 { 00312 CORBA::TypeCode_ptr prop_type = CORBA::TypeCode::_nil(); 00313 00314 // Determine if property is both defined and dynamic. 00315 if (this->is_dynamic_property (index)) 00316 { 00317 // Extract type information from the DP_Struct. 00318 const CORBA::Any& value = this->props_[index].value; 00319 CosTradingDynamic::DynamicProp* dp_struct = 0; 00320 value >>= dp_struct; 00321 00322 // Grab a pointer to the returned_type description 00323 prop_type = CORBA::TypeCode::_duplicate (dp_struct->returned_type.in ()); 00324 } 00325 else 00326 // TypeCode is self-evident at this point. 00327 prop_type = this->props_[index].value.type (); 00328 00329 return prop_type; 00330 }
CORBA::Any * TAO_Property_Evaluator::property_value | ( | int | index | ) |
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.
Definition at line 253 of file Trader_Utils.cpp.
References dp_cache_, CosTradingDynamic::DynamicProp::eval_if, CosTradingDynamic::DynamicProp::extra_info, is_dynamic_property(), CORBA::is_nil(), props_, and CosTradingDynamic::DynamicProp::returned_type.
Referenced by TAO_Trader_Constraint_Evaluator::visit_property().
00254 { 00255 CORBA::Any* prop_val = 0; 00256 CORBA::Boolean in_cache = 00257 this->dp_cache_ != 0 && this->dp_cache_[index] != 0; 00258 00259 int dynamic = this->is_dynamic_property (index); 00260 00261 if (!dynamic) 00262 prop_val = (CORBA::Any *) &(this->props_[index].value); 00263 else if (this->supports_dp_ && in_cache) 00264 prop_val = this->dp_cache_[index]; 00265 else if (this->supports_dp_) 00266 { 00267 // Property is defined at this point. 00268 CosTradingDynamic::DynamicProp* dp_struct; 00269 const CORBA::String_var name = this->props_[index].name.in (); 00270 const CORBA::Any& value = this->props_[index].value; 00271 00272 // Extract the DP_Struct. 00273 value >>= dp_struct; 00274 00275 CosTradingDynamic::DynamicPropEval_var dp_eval = 00276 CosTradingDynamic::DynamicPropEval::_duplicate (dp_struct->eval_if.in ()); 00277 00278 if (CORBA::is_nil (dp_eval.in ())) 00279 { 00280 throw CosTradingDynamic::DPEvalFailure ( 00281 name, 00282 CORBA::TypeCode::_nil (), 00283 CORBA::Any ()); 00284 } 00285 else 00286 { 00287 CORBA::TypeCode* type = dp_struct->returned_type.in (); 00288 CORBA::Any& info = dp_struct->extra_info; 00289 00290 try 00291 { 00292 // Retrieve the value of the dynamic property. 00293 prop_val = dp_eval->evalDP(name, type, info); 00294 00295 if (this->dp_cache_ != 0) 00296 this->dp_cache_[index] = prop_val; 00297 } 00298 catch (const CORBA::SystemException&) 00299 { 00300 throw 00301 (CosTradingDynamic::DPEvalFailure (name, type, info)); 00302 } 00303 } 00304 } 00305 00306 return prop_val; 00307 }
CORBA::Any** TAO_Property_Evaluator::dp_cache_ [protected] |
In order for the client to treat the results of property_value uniformly, we need to collect the dynamically allocated anys retrieved from dynamic properties and free them upon deletion. If we didn't do this, then the property_value method would leak or cause seg faults, since the client wouldn't be able to tell whether or not the return value should be freed.
Definition at line 105 of file Trader_Utils.h.
Referenced by property_value(), and ~TAO_Property_Evaluator().
const CosTrading::PropertySeq& TAO_Property_Evaluator::props_ [protected] |
The offer from which the TAO_Property_Evaluator extracts property information.
Definition at line 93 of file Trader_Utils.h.
Referenced by TAO_Property_Evaluator_By_Name::get_property(), is_dynamic_property(), property_type(), property_value(), TAO_Property_Evaluator(), TAO_Property_Evaluator_By_Name::TAO_Property_Evaluator_By_Name(), and ~TAO_Property_Evaluator().
int TAO_Property_Evaluator::supports_dp_ [protected] |
Definition at line 95 of file Trader_Utils.h.