[Orxonox-commit 4643] r9314 - in code/branches/presentation2012merge/src: modules/pickup orxonox/pickup

landauf at orxonox.net landauf at orxonox.net
Sun Jul 8 18:31:46 CEST 2012


Author: landauf
Date: 2012-07-08 18:31:46 +0200 (Sun, 08 Jul 2012)
New Revision: 9314

Modified:
   code/branches/presentation2012merge/src/modules/pickup/PickupCollectionIdentifier.cc
   code/branches/presentation2012merge/src/orxonox/pickup/PickupIdentifier.cc
Log:
probably a bugfix: PickupIdentifier compared only the first parameter in the map.
also some performance enhancements

Modified: code/branches/presentation2012merge/src/modules/pickup/PickupCollectionIdentifier.cc
===================================================================
--- code/branches/presentation2012merge/src/modules/pickup/PickupCollectionIdentifier.cc	2012-07-08 15:33:03 UTC (rev 9313)
+++ code/branches/presentation2012merge/src/modules/pickup/PickupCollectionIdentifier.cc	2012-07-08 16:31:46 UTC (rev 9314)
@@ -91,10 +91,9 @@
             const PickupIdentifier* id1 = (*it1)->getPickupIdentifier();
             const PickupIdentifier* id2 = (*it2)->getPickupIdentifier();
 
-            if(id1->compare(id2) < 0)
-                return -1;
-            if(id2->compare(id1) < 0)
-                return 1;
+            int result = id1->compare(id2);
+            if(result != 0)
+                return result;
         }
 
         // This means they are equal.

Modified: code/branches/presentation2012merge/src/orxonox/pickup/PickupIdentifier.cc
===================================================================
--- code/branches/presentation2012merge/src/orxonox/pickup/PickupIdentifier.cc	2012-07-08 15:33:03 UTC (rev 9313)
+++ code/branches/presentation2012merge/src/orxonox/pickup/PickupIdentifier.cc	2012-07-08 16:31:46 UTC (rev 9314)
@@ -75,28 +75,32 @@
         assert(this->pickup_);
 
         // If the classIdentifiers are not the same (meaning the PickupIdentifiers identify different classes), then obviously the two Pickupables identified by the PickupIdentifiers cannot be the same. An ordering is established through the alphabetical ordering of the respective classnames.
-        if(!identifier->pickup_->getIdentifier()->isExactlyA(this->pickup_->getIdentifier()))
+        if(identifier->pickup_->getIdentifier() != this->pickup_->getIdentifier())
             return this->pickup_->getIdentifier()->getName().compare(identifier->pickup_->getIdentifier()->getName());
 
         // If the class is the same for both PickupIdentifiers we go on to check the parameters of the class.
         // If the two have a different number of parameters then obviously something is very wrong.
-        if(!(this->parameters_.size() == identifier->parameters_.size()))
+        if(this->parameters_.size() != identifier->parameters_.size())
         {
             orxout(internal_error, context::pickups) << "Two PickupIdentifiers of the same Class have a different number of parameters. " << this->parameters_.size() << " vs. " << identifier->parameters_.size() << ". This indicates a bug in " << this->pickup_->getIdentifier()->getName() << "." << endl;
             return this->parameters_.size()-identifier->parameters_.size();
         }
 
-        // We iterate through all parameters and compare their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings.
-        for(std::map<std::string, std::string>::const_iterator it = this->parameters_.begin(); it != this->parameters_.end(); it++)
+        // We iterate through all parameters and compare their values (which are strings). The ordering is once again established by the alphabetical comparison of the two value strings.
+        std::map<std::string, std::string>::const_iterator it1 = this->parameters_.begin();
+        std::map<std::string, std::string>::const_iterator it2 = identifier->parameters_.begin();
+        for( ; it1 != this->parameters_.end(); ++it1, ++it2)
         {
             // If a parameter present in one of the identifiers is not found in the other, once again, something is very wrong.
-            if(identifier->parameters_.find(it->first) == identifier->parameters_.end())
+            if(it1->first != it2->first)
             {
                 orxout(internal_error, context::pickups) << this->pickup_->getIdentifier()->getName() <<  " Something went wrong in PickupIdentifier!" << endl;
-                return -1;
+                return it1->first.compare(it2->first);
             }
-            if(identifier->parameters_.find(it->first)->second != it->second)
-                return it->second.compare(identifier->parameters_.find(it->first)->second);
+
+            int result = it1->second.compare(it2->second);
+            if(result != 0)
+                return result;
         }
 
         return 0;




More information about the Orxonox-commit mailing list