diff options
author | sbw1 <sbw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-06-02 15:53:54 +0000 |
---|---|---|
committer | sbw1 <sbw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-06-02 15:53:54 +0000 |
commit | ce2ab38671ddcddc5d1d4260673a814d9204c2db (patch) | |
tree | 5f7e5a0ad8ef6a910744928a96361d898d7b7835 | |
parent | 99c1fc6fec7ce38438c0a15b60dddec6b6955599 (diff) | |
download | ATCD-ce2ab38671ddcddc5d1d4260673a814d9204c2db.tar.gz |
*** empty log message ***
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.cpp | 164 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.h | 29 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Trader/Policies.cpp | 5 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Trader/Policies.h | 10 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.cpp | 51 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.h | 13 |
6 files changed, 155 insertions, 117 deletions
diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.cpp b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.cpp index 7987873fe92..9dff63bcda1 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.cpp @@ -14,26 +14,57 @@ // // ======================================================================== +#include "Constraint_Evaluator.h" -#define get_left_operand() (this->queue_.rbegin()[1]) -#define get_right_operand() this->queue_.back() -#define get_operand() this->queue_.back() +TAO_Constraint_Evaluator::Operand_Queue::Operand_Queue (void) +{ +} -#include "Constraint_Evaluator.h" +TAO_Literal_Constraint& +TAO_Constraint_Evaluator::Operand_Queue::get_left_operand (void) +{ + TAO_Literal_Constraint* left_operand = 0; + this->get (left_operand, 1); + return *left_operand; +} + +TAO_Literal_Constraint& +TAO_Constraint_Evaluator::Operand_Queue::get_right_operand (void) +{ + TAO_Literal_Constraint* right_operand = 0; + this->get (right_operand); + return *right_operand; +} + +TAO_Literal_Constraint& +TAO_Constraint_Evaluator::Operand_Queue::get_operand (void) +{ + TAO_Literal_Constraint* operand = 0; + this->get (operand); + return *operand; +} + +void +TAO_Constraint_Evaluator::Operand_Queue::dequeue_operand (void) +{ + TAO_Literal_Constraint operand; + this->dequeue_head (operand); +} TAO_Constraint_Evaluator:: TAO_Constraint_Evaluator(CosTrading::Offer* offer, CORBA::Boolean supports_dp) : prop_eval_ (*offer, supports_dp) { - this->props_.clear(); + this->props_.close(); + this->props_.open (); int length = offer->properties.length(); // Create a map of property names to their values. for (int i = 0; i < length; i++) { - string name = (const char*)offer->properties[i].name; - this->props_[name] = i; + TAO_String_Hash_Key name = (const char*) offer->properties[i].name; + this->props_.bind (name, i); } } @@ -42,17 +73,16 @@ CORBA::Boolean TAO_Constraint_Evaluator::evaluate_constraint(TAO_Constraint* root) { CORBA::Boolean result = 0; - while (! this->queue_.empty()) - this->queue_.pop_back(); + this->queue_.reset (); // Evaluate the offer according to the constraints in root_; if (root != 0) { if ((root->accept(this) == 0) && - (! this->queue_.empty ())) + (! this->queue_.is_empty ())) { - result = (CORBA::Boolean) get_operand(); - this->queue_.pop_back (); + result = (CORBA::Boolean) this->queue_.get_operand(); + this->queue_.dequeue_operand (); } } @@ -66,17 +96,17 @@ evaluate_preference(TAO_Constraint* root, TAO_Literal_Constraint& result) { int return_value = -1; - while (! this->queue_.empty()) - this->queue_.pop_back(); + while (! this->queue_.is_empty()) + this->queue_.dequeue_operand (); // Evaluate the offer according to the constraints in root_; if (root != 0) { if ((root->accept(this) == 0) && - (! this->queue_.empty ())) + (! this->queue_.is_empty ())) { - result = get_operand(); - this->queue_.pop_back(); + result = this->queue_.get_operand(); + this->queue_.dequeue_operand (); return_value = 0; } } @@ -116,7 +146,7 @@ int TAO_Constraint_Evaluator::visit_random(TAO_Noop_Constraint* noop_random) { TAO_Literal_Constraint random((CORBA::Long) (ACE_OS::rand ())); - this->queue_.push_back(random); + this->queue_.enqueue_head (random); return 0; } @@ -124,7 +154,7 @@ int TAO_Constraint_Evaluator::visit_first(TAO_Noop_Constraint* noop_first) { TAO_Literal_Constraint first((CORBA::Long) 0); - this->queue_.push_back (first); + this->queue_.enqueue_head (first); return 0; } @@ -141,15 +171,15 @@ visit_and(TAO_Binary_Constraint* boolean_and) if (left->accept(this) == 0) { - result = (CORBA::Boolean) get_operand(); - this->queue_.pop_back (); + result = (CORBA::Boolean) this->queue_.get_operand(); + this->queue_.dequeue_operand (); if (result) { if (right->accept(this) == 0) { - result = (CORBA::Boolean) get_operand(); - this->queue_.pop_back (); + result = (CORBA::Boolean) this->queue_.get_operand(); + this->queue_.dequeue_operand (); return_value = 0; } @@ -159,7 +189,7 @@ visit_and(TAO_Binary_Constraint* boolean_and) } if (return_value != -1) - this->queue_.push_back (TAO_Literal_Constraint (result)); + this->queue_.enqueue_head (TAO_Literal_Constraint (result)); return return_value; } @@ -177,15 +207,15 @@ visit_or(TAO_Binary_Constraint* boolean_or) if (left->accept(this) == 0) { - result = (CORBA::Boolean) get_operand(); - this->queue_.pop_back (); + result = (CORBA::Boolean) this->queue_.get_operand(); + this->queue_.dequeue_operand (); if (result == (CORBA::Boolean) 0) { if (right->accept (this) == 0) { - result = (CORBA::Boolean) get_operand(); - this->queue_.pop_back(); + result = (CORBA::Boolean) this->queue_.get_operand(); + this->queue_.dequeue_operand (); return_value = 0; } } @@ -194,7 +224,7 @@ visit_or(TAO_Binary_Constraint* boolean_or) } if (return_value != -1) - this->queue_.push_back (TAO_Literal_Constraint (result)); + this->queue_.enqueue_head (TAO_Literal_Constraint (result)); return return_value; } @@ -210,9 +240,9 @@ visit_not(TAO_Unary_Constraint* unary_not) if (operand->accept(this) == 0) { - CORBA::Boolean result = ! (CORBA::Boolean)get_operand(); - this->queue_.pop_back (); - this->queue_.push_back (TAO_Literal_Constraint (result)); + CORBA::Boolean result = ! (CORBA::Boolean)this->queue_.get_operand(); + this->queue_.dequeue_operand (); + this->queue_.enqueue_head (TAO_Literal_Constraint (result)); return_value = 0; } @@ -226,15 +256,14 @@ visit_exist(TAO_Unary_Constraint* unary_exist) { TAO_Property_Constraint* operand = (TAO_Property_Constraint*) unary_exist->operand (); - string property_name ((const char*) operand->name ()); + TAO_String_Hash_Key property_name ((const char*) operand->name ()); // Determine if a property is defined on this offer. - CORBA::Boolean result = (CORBA::Boolean) - (this->props_.find (property_name) != this->props_.end()); - - this->queue_.push_back (TAO_Literal_Constraint (result)); + CORBA::Boolean result = + (CORBA::Boolean) (this->props_.find (property_name) == 0); + this->queue_.enqueue_head (TAO_Literal_Constraint (result)); return 0; } @@ -247,9 +276,9 @@ visit_unary_minus(TAO_Unary_Constraint* unary_minus) if (operand->accept(this) == 0) { - TAO_Literal_Constraint& result = - get_operand(); - this->queue_.pop_back (); - this->queue_.push_back (result); + TAO_Literal_Constraint& result = - this->queue_.get_operand(); + this->queue_.dequeue_operand (); + this->queue_.enqueue_head (result); return_value = 0; } @@ -260,8 +289,8 @@ visit_unary_minus(TAO_Unary_Constraint* unary_minus) void TAO_Constraint_Evaluator::do_the_op (int operation) { - TAO_Literal_Constraint& l_op = get_left_operand(); - TAO_Literal_Constraint& r_op = get_right_operand(); + TAO_Literal_Constraint& l_op = this->queue_.get_left_operand (); + TAO_Literal_Constraint& r_op = this->queue_.get_right_operand (); // Perform the listed bindary operation on the first two elements on // the stack. @@ -284,9 +313,9 @@ TAO_Constraint_Evaluator::do_the_op (int operation) (operation == TAO_DIV) ? l_op / r_op : TAO_Literal_Constraint ()); - this->queue_.pop_back (); - this->queue_.pop_back (); - this->queue_.push_back (result); + this->queue_.dequeue_operand (); + this->queue_.dequeue_operand (); + this->queue_.enqueue_head (result); } int @@ -307,7 +336,7 @@ TAO_Constraint_Evaluator::visit_bin_op (TAO_Binary_Constraint* op, return_value = 0; } else - this->queue_.pop_back (); + this->queue_.dequeue_operand (); } return return_value; @@ -349,26 +378,26 @@ visit_twiddle(TAO_Binary_Constraint* binary_twiddle) TAO_Constraint* left = binary_twiddle->left_operand(), *right = binary_twiddle->right_operand(); - // Determine if the left operand is a substring of the right. + // Determine if the left operand is a subTAO_String_Hash_Key of the right. if (left->accept (this) == 0) { if (right->accept(this) == 0) { - TAO_Literal_Constraint& left_operand = get_left_operand(); - TAO_Literal_Constraint& right_operand = get_right_operand(); + TAO_Literal_Constraint& left_operand = this->queue_.get_left_operand(); + TAO_Literal_Constraint& right_operand = this->queue_.get_right_operand(); CORBA::Boolean result = (CORBA::Boolean) (ACE_OS::strstr ((const char*)left_operand, (const char*)right_operand) != 0); - this->queue_.pop_back(); - this->queue_.pop_back(); - this->queue_.push_back (TAO_Literal_Constraint (result)); + this->queue_.dequeue_operand(); + this->queue_.dequeue_operand(); + this->queue_.enqueue_head (TAO_Literal_Constraint (result)); return_value = 0; } else - this->queue_.pop_back (); + this->queue_.dequeue_operand (); } return return_value; @@ -388,21 +417,21 @@ visit_in(TAO_Binary_Constraint* binary_in) { if (this->visit_property ((TAO_Property_Constraint*) right) == 0) { - TAO_Literal_Constraint& left_value = get_left_operand(); - const CORBA::Any* any = (const CORBA::Any*) get_right_operand(); + TAO_Literal_Constraint& left_value = this->queue_.get_left_operand(); + const CORBA::Any* any = (const CORBA::Any*) this->queue_.get_right_operand(); if (any != 0) { CORBA::Boolean result = this->sequence_does_contain ((CORBA::Any*) any, left_value); - this->queue_.pop_back (); - this->queue_.pop_back (); - this->queue_.push_back (TAO_Literal_Constraint (result)); + this->queue_.dequeue_operand (); + this->queue_.dequeue_operand (); + this->queue_.enqueue_head (TAO_Literal_Constraint (result)); return_value = 0; } else - this->queue_.pop_back (); + this->queue_.dequeue_operand (); } } @@ -455,7 +484,7 @@ int TAO_Constraint_Evaluator:: visit_literal(TAO_Literal_Constraint* literal) { - this->queue_.push_back (*literal); + this->queue_.enqueue_head (*literal); return 0; } @@ -463,23 +492,22 @@ int TAO_Constraint_Evaluator:: visit_property(TAO_Property_Constraint* literal) { - int return_value = -1; + int return_value = -1, prop_index = 0; // Handle case where property is not, in fact, mapped to a value - string prop_name((const char*) literal->name ()); - Property_Map_Iter prop_iter = this->props_.find (prop_name); + TAO_String_Hash_Key prop_name((const char*) literal->name ()); - if (prop_iter != this->props_.end()) + if (this->props_.find (prop_name, prop_index) == 0) { CORBA::Environment env; // Retrieve the value of the property from the Property_Evaluator - int prop_index = (*prop_iter).second; - + CORBA::Any* value = this->prop_eval_.property_value (prop_index, env); - + TAO_CHECK_ENV_RETURN (env, -1); + if (value != 0) { - this->queue_.push_back (TAO_Literal_Constraint (value)); + this->queue_.enqueue_head (TAO_Literal_Constraint (value)); return_value = 0; } } diff --git a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.h b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.h index ef8954e68d9..ce98c2741c2 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.h +++ b/TAO/orbsvcs/orbsvcs/Trader/Constraint_Evaluator.h @@ -123,14 +123,33 @@ public: // Copy the value of the property into the result container. private: - - typedef map<string, int, less<string> > Property_Map; - typedef Property_Map::iterator Property_Map_Iter; - typedef deque<TAO_Literal_Constraint> Operand_Queue; + class Operand_Queue : + public ACE_Unbounded_Queue <TAO_Literal_Constraint> + { + public: + + Operand_Queue (void); + + TAO_Literal_Constraint& get_left_operand (void); + + TAO_Literal_Constraint& get_right_operand (void); + + TAO_Literal_Constraint& get_operand (void); + + void dequeue_operand (void); + }; + + typedef ACE_Hash_Map_Manager + < + TAO_String_Hash_Key, + int, + ACE_Null_Mutex + > + Property_Map; + void do_the_op (int operation); int visit_bin_op (TAO_Binary_Constraint* op, int operation); - CORBA::Boolean sequence_does_contain(CORBA::Any* sequence, TAO_Literal_Constraint& element); diff --git a/TAO/orbsvcs/orbsvcs/Trader/Policies.cpp b/TAO/orbsvcs/orbsvcs/Trader/Policies.cpp index 3ba21db68d8..4a666ed667b 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Policies.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Policies.cpp @@ -22,10 +22,9 @@ TAO_Policies::TAO_Policies (TAO_Trader_Base& trader, CORBA::Environment& _env) TAO_THROW_SPEC ((CosTrading::Lookup::IllegalPolicyName, CosTrading::DuplicatePolicyName)) - : trader_ (trader), - policies_ (REQUEST_ID + 1) + : trader_ (trader) { - for (int i = 0; i <= REQUEST_ID; i++) + for (int i = 0; i < TAO_NUM_POLICIES; i++) this->policies_[i] = 0; for (int j = 0; j < policies.length (); j++) diff --git a/TAO/orbsvcs/orbsvcs/Trader/Policies.h b/TAO/orbsvcs/orbsvcs/Trader/Policies.h index e0f964ee83c..3f2b87e860c 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Policies.h +++ b/TAO/orbsvcs/orbsvcs/Trader/Policies.h @@ -17,8 +17,6 @@ #ifndef TAO_POLICIES_H #define TAO_POLICIES_H -// STL fun stuff. -#include "stl.h" #include "Trader.h" class TAO_Policies @@ -38,6 +36,8 @@ class TAO_Policies { public: +#define TAO_NUM_POLICIES 11 + enum POLICY_TYPE { EXACT_TYPE_MATCH, @@ -249,8 +249,6 @@ public: private: - typedef vector <CosTrading::Policy*> POL_VECTOR; - CORBA::ULong ulong_prop (POLICY_TYPE pol, CORBA::Environment& _env) TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); @@ -260,8 +258,8 @@ private: CORBA::Environment& _env) TAO_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch)); // Reconcile a Boolean property with its debault. - - POL_VECTOR policies_; + + CosTrading::Policy* policies_[TAO_NUM_POLICIES]; // The policies indexable from the enumerated type. TAO_Trader_Base& trader_; diff --git a/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.cpp b/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.cpp index 51dec4c60c2..2565aeaec2b 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.cpp +++ b/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.cpp @@ -131,7 +131,6 @@ TAO_Property_Evaluator_By_Name (const CosTrading::PropertySeq& properties, CosTrading::IllegalPropertyName)) : TAO_Property_Evaluator (properties, supports_dp) { - string prop_name; int length = this->props_.length(); for (int i = 0; i < length; i++) @@ -141,8 +140,8 @@ TAO_Property_Evaluator_By_Name (const CosTrading::PropertySeq& properties, if (! TAO_Trader_Base::is_valid_identifier_name (prop.name)) TAO_THROW (CosTrading::IllegalPropertyName (prop.name)); - prop_name = prop.name; - if (! (this->table_.insert (make_pair (prop_name, i))).second) + TAO_String_Hash_Key prop_name = prop.name; + if (this->table_.bind (prop_name, i)) TAO_THROW (CosTrading::DuplicatePropertyName (prop.name)); } } @@ -156,8 +155,8 @@ TAO_Property_Evaluator_By_Name(CosTrading::Offer& offer, for (int i = 0; i < length; i++) { - string prop_name = (const char*) this->props_[i].name; - this->table_[prop_name] = i; + TAO_String_Hash_Key prop_name = (const char*) this->props_[i].name; + this->table_.bind (prop_name, i); } } @@ -165,17 +164,13 @@ int TAO_Property_Evaluator_By_Name:: is_dynamic_property(const char* property_name) { - int predicate = 0; - string prop_name (property_name); - Lookup_Table_Iter lookup_iter = this->table_.find (prop_name); + int predicate = 0, index = 0; + TAO_String_Hash_Key prop_name (property_name); // If the property name is in the map, delegate evaluation to our // superclass. Otherwise, throw an exception. - if (lookup_iter != this->table_.end()) - { - int index = (*lookup_iter).second; - predicate = this->TAO_Property_Evaluator::is_dynamic_property(index); - } + if (this->table_.find (prop_name, index) == 0) + predicate = this->TAO_Property_Evaluator::is_dynamic_property(index); return predicate; } @@ -185,17 +180,14 @@ TAO_Property_Evaluator_By_Name::property_value (const char* property_name, CORBA::Environment& _env) TAO_THROW_SPEC ((CosTradingDynamic::DPEvalFailure)) { + int index = 0; CORBA::Any* prop_value = 0; - string prop_name(property_name); - Lookup_Table_Iter lookup_iter = this->table_.find(prop_name); + TAO_String_Hash_Key prop_name (property_name); // If the property name is in the map, delegate evaluation to our // superclass. Otherwise, throw an exception. - if (lookup_iter != this->table_.end()) - { - int index = (*lookup_iter).second; - prop_value = this->TAO_Property_Evaluator::property_value (index, _env); - } + if (this->table_.find (prop_name, index) == 0) + prop_value = this->TAO_Property_Evaluator::property_value (index, _env); return prop_value; } @@ -203,17 +195,14 @@ TAO_Property_Evaluator_By_Name::property_value (const char* property_name, CORBA::TypeCode* TAO_Property_Evaluator_By_Name::property_type (const char* property_name) { - string prop_name(property_name); + int index = 0; + TAO_String_Hash_Key prop_name (property_name); CORBA::TypeCode* prop_type = CORBA::TypeCode::_nil(); - Lookup_Table_Iter lookup_iter = this->table_.find(prop_name); // If the property name is in the map, delegate evaluation to our // superclass. Otherwise, throw an exception. - if (lookup_iter != this->table_.end()) - { - int index = (*lookup_iter).second; - prop_type = this->TAO_Property_Evaluator::property_type (index); - } + if (this->table_.find (prop_name, index) == 0) + prop_type = this->TAO_Property_Evaluator::property_type (index); return prop_type; } @@ -221,12 +210,12 @@ TAO_Property_Evaluator_By_Name::property_type (const char* property_name) const CosTrading::Property* TAO_Property_Evaluator_By_Name::get_property (const char* property_name) { + int index = 0; CosTrading::Property* property = 0; - string prop_name (property_name); - Lookup_Table_Iter lookup_iter = this->table_.find(prop_name); + TAO_String_Hash_Key prop_name (property_name); - if (lookup_iter != this->table_.end()) - property = (CosTrading::Property *) &this->props_[(*lookup_iter).second]; + if (this->table_.find (prop_name, index) == 0) + property = (CosTrading::Property *) &this->props_[index]; return property; } diff --git a/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.h b/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.h index c0fa258956b..87bada5a054 100644 --- a/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.h +++ b/TAO/orbsvcs/orbsvcs/Trader/Property_Evaluator.h @@ -17,7 +17,7 @@ #ifndef TAO_PROPERTY_EVALUATOR_H #define TAO_PROPERTY_EVALUATOR_H -#include "stl.h" +#include "Trader.h" #include "orbsvcs/CosTradingC.h" class TAO_Property_Evaluator @@ -127,9 +127,14 @@ public: 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; + + typedef ACE_Hash_Map_Manager + < + TAO_String_Hash_Key, + int, + ACE_Null_Mutex + > + Lookup_Table; // A mapping, upon which lookups will take O(lg n), of property // names to sequence indices. |