#include <Constraint_Interpreter.h>
Inheritance diagram for TAO_Preference_Interpreter:
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.
Definition at line 87 of file Constraint_Interpreter.h.
Definition at line 139 of file Constraint_Interpreter.h.
TAO_Preference_Interpreter::TAO_Preference_Interpreter | ( | const CosTradingRepos::ServiceTypeRepository::TypeStruct & | ts, | |
const char * | preference | |||
) |
Definition at line 78 of file Constraint_Interpreter.cpp.
References ACE_NEW_THROW_EX, TAO_Interpreter::is_empty_string(), TAO_FIRST, and TAO_Constraint_Validator::validate().
00082 : TAO_Interpreter () 00083 { 00084 TAO_Trader_Constraint_Validator type_checker (ts); 00085 00086 if (TAO_Interpreter::is_empty_string (preference)) 00087 { 00088 ACE_NEW_THROW_EX (this->root_, 00089 TAO_Noop_Constraint (TAO_FIRST), 00090 CORBA::NO_MEMORY ()); 00091 } 00092 else 00093 { 00094 if (this->build_tree (preference) != 0) 00095 throw CosTrading::Lookup::IllegalPreference (preference); 00096 00097 if (type_checker.validate (this->root_) == -1) 00098 throw CosTrading::Lookup::IllegalPreference (preference); 00099 } 00100 }
TAO_Preference_Interpreter::TAO_Preference_Interpreter | ( | TAO_Constraint_Validator & | validator, | |
const char * | preference | |||
) |
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.
Definition at line 103 of file Constraint_Interpreter.cpp.
References ACE_NEW_THROW_EX, TAO_Interpreter::is_empty_string(), TAO_FIRST, and TAO_Constraint_Validator::validate().
00105 : TAO_Interpreter () 00106 { 00107 if (TAO_Interpreter::is_empty_string (preference)) 00108 { 00109 ACE_NEW_THROW_EX (this->root_, 00110 TAO_Noop_Constraint (TAO_FIRST), 00111 CORBA::NO_MEMORY ()); 00112 } 00113 else 00114 { 00115 if (this->build_tree (preference) != 0) 00116 throw CosTrading::Lookup::IllegalPreference (preference); 00117 00118 if (validator.validate (this->root_) == -1) 00119 throw CosTrading::Lookup::IllegalPreference (preference); 00120 } 00121 }
TAO_Preference_Interpreter::~TAO_Preference_Interpreter | ( | void | ) |
TAO_Preference_Interpreter::TAO_Preference_Interpreter | ( | const TAO_Preference_Interpreter & | ) | [private] |
Disallow copying.
size_t TAO_Preference_Interpreter::num_offers | ( | void | ) |
Return the number of offers remaining in the ordering.
Definition at line 235 of file Constraint_Interpreter.cpp.
References offers_, and ACE_Unbounded_Queue< T >::size().
Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::fill_receptacles().
TAO_Preference_Interpreter& TAO_Preference_Interpreter::operator= | ( | const TAO_Preference_Interpreter & | ) | [private] |
void TAO_Preference_Interpreter::order_offer | ( | TAO_Constraint_Evaluator & | evaluator, | |
CosTrading::Offer * | offer, | |||
CosTrading::OfferId | offer_id = 0 | |||
) |
Evaluate the offer, and order it internally based on the results of the evaluation.
Definition at line 138 of file Constraint_Interpreter.cpp.
References ACE_Unbounded_Queue< T >::enqueue_head(), ACE_Unbounded_Queue< T >::enqueue_tail(), TAO_Constraint_Evaluator::evaluate_preference(), TAO_Preference_Interpreter::Preference_Info::evaluated_, TAO_Preference_Interpreter::Preference_Info::offer_, TAO_Preference_Interpreter::Preference_Info::offer_id_, offers_, ACE_Unbounded_Queue< T >::set(), TAO_FIRST, TAO_MAX, TAO_MIN, TAO_WITH, and TAO_Preference_Interpreter::Preference_Info::value_.
00141 { 00142 if (this->root_ != 0) 00143 { 00144 Preference_Info pref_info; 00145 00146 pref_info.offer_ = offer; 00147 pref_info.offer_id_ = offer_id; 00148 pref_info.evaluated_ = 1; 00149 00150 if (evaluator.evaluate_preference (this->root_, pref_info.value_) == 0) 00151 { 00152 // If the evaluation succeeds, insert the node into the 00153 // correct place in the queue. 00154 TAO_Expression_Type expr_type = this->root_->expr_type (); 00155 00156 if (expr_type == TAO_FIRST 00157 || (expr_type == TAO_WITH 00158 && ! static_cast<CORBA::Boolean> (pref_info.value_))) 00159 this->offers_.enqueue_tail (pref_info); 00160 else 00161 this->offers_.enqueue_head (pref_info); 00162 00163 if (expr_type == TAO_MIN || expr_type == TAO_MAX) 00164 { 00165 Ordered_Offers::ITERATOR offer_iter (this->offers_); 00166 00167 // Push the new item down the list until the min/max 00168 // criterion is satisfied. Observe the evaluation failed 00169 // / evaluation suceeded partion in the list. 00170 offer_iter.advance (); 00171 00172 for (int i = 1; 00173 offer_iter.done () == 0; 00174 offer_iter.advance (), i++) 00175 { 00176 Preference_Info* current_offer = 0; 00177 offer_iter.next (current_offer); 00178 00179 // Maintain the sorted order in the first partition. 00180 if (current_offer->evaluated_ == 1 00181 && ((expr_type == TAO_MIN 00182 && pref_info.value_ > current_offer->value_) 00183 || (expr_type == TAO_MAX 00184 && pref_info.value_ < current_offer->value_))) 00185 { 00186 // Swap the out of order pair 00187 this->offers_.set (*current_offer, 00188 i - 1); 00189 this->offers_.set (pref_info, i); 00190 } 00191 else 00192 break; 00193 } 00194 } 00195 } 00196 else 00197 { 00198 // If the evaluation fails, just tack the sucker onto the 00199 // end of the queue. 00200 pref_info.evaluated_ = 0; 00201 this->offers_.enqueue_tail (pref_info); 00202 } 00203 } 00204 }
void TAO_Preference_Interpreter::order_offer | ( | CosTrading::Offer * | offer, | |
CosTrading::OfferId | offer_id = 0 | |||
) |
Definition at line 129 of file Constraint_Interpreter.cpp.
Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::lookup_one_type(), and TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::order_merged_sequence().
00131 { 00132 TAO_Trader_Constraint_Evaluator evaluator (offer); 00133 this->order_offer (evaluator, offer, offer_id); 00134 }
int TAO_Preference_Interpreter::remove_offer | ( | CosTrading::Offer *& | offer | ) |
Remove the next offer. The offer returned will be the next in the ordering determined by the preference string.
Definition at line 227 of file Constraint_Interpreter.cpp.
References remove_offer().
00228 { 00229 CosTrading::OfferId offer_id = 0; 00230 return this->remove_offer (offer, offer_id); 00231 }
int TAO_Preference_Interpreter::remove_offer | ( | CosTrading::Offer *& | offer, | |
CosTrading::OfferId & | offer_id | |||
) |
Definition at line 208 of file Constraint_Interpreter.cpp.
References ACE_Unbounded_Queue< T >::dequeue_head(), TAO_Preference_Interpreter::Preference_Info::offer_, TAO_Preference_Interpreter::Preference_Info::offer_id_, and offers_.
Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::fill_receptacles(), TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::order_merged_sequence(), and remove_offer().
00210 { 00211 int return_value = -1; 00212 Preference_Info pref_info; 00213 00214 return_value = this->offers_.dequeue_head (pref_info); 00215 00216 if (return_value == 0) 00217 { 00218 offer = pref_info.offer_; 00219 offer_id = pref_info.offer_id_; 00220 } 00221 00222 return return_value; 00223 }
The ordered list of offers.
Definition at line 148 of file Constraint_Interpreter.h.
Referenced by num_offers(), order_offer(), and remove_offer().