Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 5, 2010, 6:26:54 PM (14 years ago)
Author:
dafrick
Message:

Additional documentation, code niceifying and potential bug fixing. Also: Renamed DroppedItem to DroppedPickup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup3/src/orxonox/pickup/PickupIdentifier.cc

    r6474 r6475  
    3434{
    3535   
     36    /**
     37    @brief
     38        Constructor. Registers the object and initializes member variables.
     39    */
    3640    PickupIdentifier::PickupIdentifier()
    3741    {
    3842        RegisterRootObject(PickupIdentifier);
    3943       
    40        
     44        this->classIdentifier_ = NULL;
    4145    }
    4246   
     
    5256        Pointer to the second PickupIdentifier, b.
    5357    @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.
    5559    */
    56     int PickupIdentifier::compare(const PickupIdentifier& identifier) const
     60    int PickupIdentifier::compare(const PickupIdentifier* identifier) const
    5761    {
    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());
    6065       
    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()))
    6269        {
    6370            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();
    6572        }
    6673       
     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.
    6775        for(std::map<std::string, std::string>::const_iterator it = this->parameters_.begin(); it != this->parameters_.end(); it++)
    6876        {
    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())
    7079            {
    7180                COUT(1) << "Something went wrong in PickupIdentifier!" << std::endl;
    7281                return -1;
    7382            }
    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);
    7685        }
    7786           
     
    7988    }
    8089   
     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    */
    8196    void PickupIdentifier::addClass(Identifier* identifier)
    8297    {
     
    8499    }
    85100   
     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    */
    86111    bool PickupIdentifier::addParameter(std::string & name, std::string & value)
    87112    {
Note: See TracChangeset for help on using the changeset viewer.