Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 5, 2015, 10:47:51 PM (9 years ago)
Author:
landauf
Message:

use range-based for-loop where it makes sense (e.g. ObjectList)

Location:
code/branches/cpp11_v2/src/orxonox/worldentities/pawns
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/orxonox/worldentities/pawns/ModularSpaceShip.cc

    r10916 r10919  
    174174    void ModularSpaceShip::killShipPartStatic(std::string name)
    175175    {
    176         for (std::map<StaticEntity*, ShipPart*>::const_iterator it = ModularSpaceShip::partMap_s->begin(); it != ModularSpaceShip::partMap_s->end(); ++it)
    177         {
    178             if (it->second->getName() == name)
    179             {
    180                 it->second->death();
     176        for (const auto& mapEntry : *ModularSpaceShip::partMap_s)
     177        {
     178            if (mapEntry.second->getName() == name)
     179            {
     180                mapEntry.second->death();
    181181                return;
    182182            }
     
    193193    void ModularSpaceShip::killShipPart(std::string name)
    194194    {
    195         for (std::map<StaticEntity*, ShipPart*>::const_iterator it = ModularSpaceShip::partMap_.begin(); it != ModularSpaceShip::partMap_.end(); ++it)
    196         {
    197             if (it->second->getName() == name)
    198             {
    199                 it->second->death();
     195        for (const auto& mapEntry : ModularSpaceShip::partMap_)
     196        {
     197            if (mapEntry.second->getName() == name)
     198            {
     199                mapEntry.second->death();
    200200                return;
    201201            }
  • code/branches/cpp11_v2/src/orxonox/worldentities/pawns/Pawn.cc

    r10768 r10919  
    574574    bool Pawn::hasSlaves()
    575575    {
    576         for (ObjectList<FormationController>::iterator it =
    577              ObjectList<FormationController>::begin();
    578              it != ObjectList<FormationController>::end(); ++it )
     576        for (FormationController* controller : ObjectList<FormationController>())
    579577        {
    580578            // checks if the pawn's controller has a slave
    581             if (this->hasHumanController() && it->getMaster() == this->getPlayer()->getController())
     579            if (this->hasHumanController() && controller->getMaster() == this->getPlayer()->getController())
    582580                return true;
    583581        }
     
    587585    // A function that returns a slave of the pawn's controller
    588586    Controller* Pawn::getSlave(){
    589         for (ObjectList<FormationController>::iterator it =
    590                 ObjectList<FormationController>::begin();
    591                 it != ObjectList<FormationController>::end(); ++it )
    592         {
    593             if (this->hasHumanController() && it->getMaster() == this->getPlayer()->getController())
    594                 return it->getController();
     587        for (FormationController* controller : ObjectList<FormationController>())
     588        {
     589            if (this->hasHumanController() && controller->getMaster() == this->getPlayer()->getController())
     590                return controller->getController();
    595591        }
    596592        return nullptr;
  • code/branches/cpp11_v2/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc

    r10916 r10919  
    9292
    9393        // Call this so bots stop shooting at the base after they converted it
    94         for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it != ObjectList<ArtificialController>::end(); ++it)
    95             it->abandonTarget(this);
     94        for (ArtificialController* controller : ObjectList<ArtificialController>())
     95            controller->abandonTarget(this);
    9696    }
    9797}
Note: See TracChangeset for help on using the changeset viewer.