#include <Constraint_Interpreter.h>
Inheritance diagram for TAO_Preference_Interpreter:
Public Types | |
typedef ACE_Unbounded_Queue< Preference_Info > | Ordered_Offers |
Public Member Functions | |
TAO_Preference_Interpreter (const CosTradingRepos::ServiceTypeRepository::TypeStruct &ts, const char *preference) throw (CosTrading::Lookup::IllegalPreference, CORBA::NO_MEMORY) | |
TAO_Preference_Interpreter (TAO_Constraint_Validator &validator, const char *preference) throw (CosTrading::Lookup::IllegalPreference, CORBA::NO_MEMORY) | |
~TAO_Preference_Interpreter (void) | |
Destructor. | |
void | order_offer (CosTrading::Offer *offer, CosTrading::OfferId offer_id=0) |
void | order_offer (TAO_Constraint_Evaluator &evaluator, CosTrading::Offer *offer, CosTrading::OfferId offer_id=0) |
int | remove_offer (CosTrading::Offer *&offer, CosTrading::OfferId &offer_id) |
int | remove_offer (CosTrading::Offer *&offer) |
size_t | num_offers (void) |
Return the number of offers remaining in the ordering. | |
Private Member Functions | |
TAO_Preference_Interpreter (const TAO_Preference_Interpreter &) | |
Disallow copying. | |
TAO_Preference_Interpreter & | operator= (const TAO_Preference_Interpreter &) |
Private Attributes | |
Ordered_Offers | offers_ |
The ordered list of offers. |
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 93 of file Constraint_Interpreter.h.
|
Definition at line 151 of file Constraint_Interpreter.h. |
|
Definition at line 85 of file Constraint_Interpreter.cpp. References ACE_CHECK, ACE_NEW_THROW_EX, ACE_THROW, TAO_Interpreter::is_empty_string(), TAO_FIRST, and TAO_Constraint_Validator::validate().
00092 : TAO_Interpreter () 00093 { 00094 TAO_Trader_Constraint_Validator type_checker (ts); 00095 00096 if (TAO_Interpreter::is_empty_string (preference)) 00097 { 00098 ACE_NEW_THROW_EX (this->root_, 00099 TAO_Noop_Constraint (TAO_FIRST), 00100 CORBA::NO_MEMORY ()); 00101 ACE_CHECK; 00102 } 00103 else 00104 { 00105 if (this->build_tree (preference) != 0) 00106 ACE_THROW (CosTrading::Lookup::IllegalPreference (preference)); 00107 00108 if (type_checker.validate (this->root_) == -1) 00109 ACE_THROW (CosTrading::Lookup::IllegalPreference (preference)); 00110 } 00111 } |
|
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 114 of file Constraint_Interpreter.cpp. References ACE_CHECK, ACE_NEW_THROW_EX, ACE_THROW, TAO_Interpreter::is_empty_string(), and TAO_FIRST.
00119 : TAO_Interpreter () 00120 { 00121 if (TAO_Interpreter::is_empty_string (preference)) 00122 { 00123 ACE_NEW_THROW_EX (this->root_, 00124 TAO_Noop_Constraint (TAO_FIRST), 00125 CORBA::NO_MEMORY ()); 00126 ACE_CHECK; 00127 } 00128 else 00129 { 00130 if (this->build_tree (preference) != 0) 00131 ACE_THROW (CosTrading::Lookup::IllegalPreference (preference)); 00132 00133 if (validator.validate (this->root_) == -1) 00134 ACE_THROW (CosTrading::Lookup::IllegalPreference (preference)); 00135 } 00136 } |
|
Destructor.
Definition at line 138 of file Constraint_Interpreter.cpp.
00139 { 00140 } |
|
Disallow copying.
|
|
Return the number of offers remaining in the ordering.
Definition at line 250 of file Constraint_Interpreter.cpp. References offers_, and ACE_Unbounded_Queue< T >::size().
|
|
|
|
Evaluate the offer, and order it internally based on the results of the evaluation. Definition at line 153 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_Constraint::expr_type(), TAO_Preference_Interpreter::Preference_Info::offer_, TAO_Preference_Interpreter::Preference_Info::offer_id_, CosTrading::OfferId, offers_, ACE_Unbounded_Queue< T >::set(), TAO_Expression_Type, TAO_FIRST, TAO_MAX, TAO_MIN, TAO_WITH, and TAO_Preference_Interpreter::Preference_Info::value_.
00156 { 00157 if (this->root_ != 0) 00158 { 00159 Preference_Info pref_info; 00160 00161 pref_info.offer_ = offer; 00162 pref_info.offer_id_ = offer_id; 00163 pref_info.evaluated_ = 1; 00164 00165 if (evaluator.evaluate_preference (this->root_, pref_info.value_) == 0) 00166 { 00167 // If the evaluation succeeds, insert the node into the 00168 // correct place in the queue. 00169 TAO_Expression_Type expr_type = this->root_->expr_type (); 00170 00171 if (expr_type == TAO_FIRST 00172 || (expr_type == TAO_WITH 00173 && ! static_cast<CORBA::Boolean> (pref_info.value_))) 00174 this->offers_.enqueue_tail (pref_info); 00175 else 00176 this->offers_.enqueue_head (pref_info); 00177 00178 if (expr_type == TAO_MIN || expr_type == TAO_MAX) 00179 { 00180 Ordered_Offers::ITERATOR offer_iter (this->offers_); 00181 00182 // Push the new item down the list until the min/max 00183 // criterion is satisfied. Observe the evaluation failed 00184 // / evaluation suceeded partion in the list. 00185 offer_iter.advance (); 00186 00187 for (int i = 1; 00188 offer_iter.done () == 0; 00189 offer_iter.advance (), i++) 00190 { 00191 Preference_Info* current_offer; 00192 offer_iter.next (current_offer); 00193 00194 // Maintain the sorted order in the first partition. 00195 if (current_offer->evaluated_ == 1 00196 && ((expr_type == TAO_MIN 00197 && pref_info.value_ > current_offer->value_) 00198 || (expr_type == TAO_MAX 00199 && pref_info.value_ < current_offer->value_))) 00200 { 00201 // Swap the out of order pair 00202 this->offers_.set (*current_offer, 00203 i - 1); 00204 this->offers_.set (pref_info, i); 00205 } 00206 else 00207 break; 00208 } 00209 } 00210 } 00211 else 00212 { 00213 // If the evaluation fails, just tack the sucker onto the 00214 // end of the queue. 00215 pref_info.evaluated_ = 0; 00216 this->offers_.enqueue_tail (pref_info); 00217 } 00218 } 00219 } |
|
Definition at line 144 of file Constraint_Interpreter.cpp. References CosTrading::OfferId. 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().
00146 { 00147 TAO_Trader_Constraint_Evaluator evaluator (offer); 00148 this->order_offer (evaluator, offer, offer_id); 00149 } |
|
Remove the next offer. The offer returned will be the next in the ordering determined by the preference string. Definition at line 242 of file Constraint_Interpreter.cpp. References CosTrading::OfferId, and remove_offer().
00243 { 00244 CosTrading::OfferId offer_id = 0; 00245 return this->remove_offer (offer, offer_id); 00246 } |
|
Definition at line 223 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_, CosTrading::OfferId, and offers_. Referenced by TAO_Lookup< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::order_merged_sequence(), and remove_offer().
00225 { 00226 int return_value = -1; 00227 Preference_Info pref_info; 00228 00229 return_value = this->offers_.dequeue_head (pref_info); 00230 00231 if (return_value == 0) 00232 { 00233 offer = pref_info.offer_; 00234 offer_id = pref_info.offer_id_; 00235 } 00236 00237 return return_value; 00238 } |
|
The ordered list of offers.
Definition at line 160 of file Constraint_Interpreter.h. Referenced by num_offers(), order_offer(), and remove_offer(). |