Changeset 6475 for code/branches/pickup3/src/orxonox/pickup
- Timestamp:
- Mar 5, 2010, 6:26:54 PM (15 years ago)
- Location:
- code/branches/pickup3/src/orxonox/pickup
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup3/src/orxonox/pickup/PickupIdentifier.cc
r6474 r6475 34 34 { 35 35 36 /** 37 @brief 38 Constructor. Registers the object and initializes member variables. 39 */ 36 40 PickupIdentifier::PickupIdentifier() 37 41 { 38 42 RegisterRootObject(PickupIdentifier); 39 43 40 44 this->classIdentifier_ = NULL; 41 45 } 42 46 … … 52 56 Pointer to the second PickupIdentifier, b. 53 57 @return 54 Returns an int .58 Returns an integer. 0 if the two compared PickupIdentifiers are the same, <0 if a < b and >0 if a > b. 55 59 */ 56 int PickupIdentifier::compare(const PickupIdentifier &identifier) const60 int PickupIdentifier::compare(const PickupIdentifier* identifier) const 57 61 { 58 if(!identifier.classIdentifier_->isExactlyA(this->classIdentifier_)) 59 return this->classIdentifier_->getName().compare(identifier.classIdentifier_->getName()); 62 //! If the classIdentifiers are not the same (meaning the PickupIdentifiers identify different classes), the obviously the two Pickupables identified by the PickupIdentifiers cannot be the same. An ordering is established through the alphabetical ordering of the respective classnames. 63 if(!identifier->classIdentifier_->isExactlyA(this->classIdentifier_)) 64 return this->classIdentifier_->getName().compare(identifier->classIdentifier_->getName()); 60 65 61 if(!(this->parameters_.size() == identifier.parameters_.size())) 66 //! If the class is the same for both PickupIdentifiers we go on to check the parameters of the class. 67 //! If the two have a different number of parameters then obviusly something is very wrong. 68 if(!(this->parameters_.size() == identifier->parameters_.size())) 62 69 { 63 70 COUT(1) << "Something went wrong in PickupIdentifier!" << std::endl; 64 return this->parameters_.size()-identifier .parameters_.size();71 return this->parameters_.size()-identifier->parameters_.size(); 65 72 } 66 73 74 //! We iterate through all parameters and compar 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. 67 75 for(std::map<std::string, std::string>::const_iterator it = this->parameters_.begin(); it != this->parameters_.end(); it++) 68 76 { 69 if(identifier.parameters_.find(it->first) == identifier.parameters_.end()) 77 //!< If a parameter present in one of the identifiers is not found in the other, once again, something is very wrong. 78 if(identifier->parameters_.find(it->first) == identifier->parameters_.end()) 70 79 { 71 80 COUT(1) << "Something went wrong in PickupIdentifier!" << std::endl; 72 81 return -1; 73 82 } 74 if(identifier .parameters_.find(it->first)->second != it->second)75 return it->second.compare(identifier .parameters_.find(it->first)->second);83 if(identifier->parameters_.find(it->first)->second != it->second) 84 return it->second.compare(identifier->parameters_.find(it->first)->second); 76 85 } 77 86 … … 79 88 } 80 89 90 /** 91 @brief 92 Add the class of the Pickupable to its PickupIdentifier. 93 @param identifier 94 A pointer to the Identifier of the class. 95 */ 81 96 void PickupIdentifier::addClass(Identifier* identifier) 82 97 { … … 84 99 } 85 100 101 /** 102 @brief 103 Add a parameter to the PickupIdentifier. 104 @param name 105 The name of the parameter. 106 @param value 107 The value of the parameter. 108 @return 109 Returns false if the parameter already existed, true if not. 110 */ 86 111 bool PickupIdentifier::addParameter(std::string & name, std::string & value) 87 112 { -
code/branches/pickup3/src/orxonox/pickup/PickupIdentifier.h
r6474 r6475 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "core/OrxonoxClass.h"35 #include "core/Identifier.h"36 34 #include <map> 37 35 #include <string> 36 #include "core/Identifier.h" 37 38 #include "core/OrxonoxClass.h" 38 39 39 40 namespace orxonox 40 41 { 41 42 43 /** 44 @brief 45 The purpose of the PickupIdentifier class is to identify different types of pickups allthough they are of the same class. 46 This allows for more generic classes (or pickups in this case) that can be a number of different pickup types and can be identified as such without the need for a lot of different classes. An example is the HealthPickup class that encompasses a wide variety of different types of health pickups, e.g a HealthPickup that adds 10 health every second for 10 seconds or a HealthPickup that adds 100 health as soon as it is picked up, a.s.o. 47 To that purpose this class provides functionality to compare two PickupIdentifier (and since all Pickupables have an Identifier through that Pickupables can be compared). It als provides functionality to add parameters that distinguish between different types of pickups in the same pickup class. 48 Lastly a struct is provided that can be used in stl containers to establish a strictly lesser ordering between PickupIdentifiers (and thus Pickupables). 49 @author 50 Damian 'Mozork' Frick 51 */ 42 52 class _OrxonoxExport PickupIdentifier : virtual public OrxonoxClass 43 53 { 44 54 45 55 public: 46 PickupIdentifier(void); 47 ~PickupIdentifier(); 56 PickupIdentifier(void); //!< Constructor. 57 ~PickupIdentifier(); //!< Destructor. 48 58 49 virtual int compare(const PickupIdentifier & identifier) const;59 virtual int compare(const PickupIdentifier* identifier) const; //!< Compares two PickupIdentifiers and returns 0 if a == b, <0 if a < b and >0 if a > b for a.compare(b). 50 60 51 void addClass(Identifier* identifier); 52 bool addParameter(std::string & name, std::string & value); 61 void addClass(Identifier* identifier); //!< Add the class of the Pickupable to its PickupIdentifier. 62 bool addParameter(std::string & name, std::string & value); //!< Add a parameter to the PickupIdentifier. 53 63 54 64 private: 55 Identifier* classIdentifier_; 56 std::map<std::string, std::string> parameters_; 57 65 Identifier* classIdentifier_; //!< The Identifier of the class. 66 std::map<std::string, std::string> parameters_; //!< The parameters identifying the type of the pickup beyond the class. 58 67 59 68 }; 60 69 61 //TODO: Needed? 70 /** 71 @brief 72 Struct that overloads the compare operation between two PickupIdentifier pointers. 73 */ 62 74 struct PickupIdentifierCompare 63 75 { 64 bool operator() (const PickupIdentifier& lhs, const PickupIdentifier& rhs) const65 { return lhs.compare(rhs) < 0; }66 };67 68 struct PickupIdentifierPtrCompare69 {70 76 bool operator() (const PickupIdentifier* lhs, const PickupIdentifier* rhs) const 71 { return lhs->compare( *rhs) < 0; }77 { return lhs->compare(rhs) < 0; } 72 78 }; 73 79
Note: See TracChangeset
for help on using the changeset viewer.