Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 21, 2015, 7:05:53 PM (9 years ago)
Author:
muemart
Message:

Run clang-modernize -loop-convert

  • Again, not all possible loops were converted
  • It can do pretty cool transformations, but I had to fix a few compile errors, so there might be some runtime errors lurking around too
Location:
code/branches/cpp11_v2/src/orxonox/worldentities
Files:
6 edited

Legend:

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

    r10769 r10821  
    165165    {
    166166        unsigned int i = 0;
    167         for (std::list<StrongPtr<CameraPosition>>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
     167        for (const auto & elem : this->cameraPositions_)
    168168        {
    169169            if (i == index)
    170                 return (*it);
     170                return (elem);
    171171            ++i;
    172172        }
     
    180180
    181181        unsigned int counter = 0;
    182         for (std::list<StrongPtr<CameraPosition>>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
    183         {
    184             if ((*it) == this->currentCameraPosition_)
     182        for (const auto & elem : this->cameraPositions_)
     183        {
     184            if ((elem) == this->currentCameraPosition_)
    185185                break;
    186186            counter++;
     
    477477        if (parent)
    478478        {
    479             for (std::list<StrongPtr<CameraPosition>>::iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
    480                 if ((*it)->getIsAbsolute())
    481                     parent->attach((*it));
     479            for (auto & elem : this->cameraPositions_)
     480                if ((elem)->getIsAbsolute())
     481                    parent->attach((elem));
    482482        }
    483483    }
  • code/branches/cpp11_v2/src/orxonox/worldentities/EffectContainer.cc

    r10765 r10821  
    8989    {
    9090        unsigned int i = 0;
    91         for (std::vector<WorldEntity*>::const_iterator it = this->effects_.begin(); it != this->effects_.end(); ++it)
     91        for (const auto & elem : this->effects_)
    9292            if (i == index)
    93                 return (*it);
     93                return (elem);
    9494        return nullptr;
    9595    }
  • code/branches/cpp11_v2/src/orxonox/worldentities/WorldEntity.cc

    r10774 r10821  
    233233
    234234            // iterate over all children and change their activity as well
    235             for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++)
     235            for (const auto & elem : this->getAttachedObjects())
    236236            {
    237237                if(!this->isActive())
    238238                {
    239                     (*it)->bActiveMem_ = (*it)->isActive();
    240                     (*it)->setActive(this->isActive());
     239                    (elem)->bActiveMem_ = (elem)->isActive();
     240                    (elem)->setActive(this->isActive());
    241241                }
    242242                else
    243243                {
    244                     (*it)->setActive((*it)->bActiveMem_);
     244                    (elem)->setActive((elem)->bActiveMem_);
    245245                }
    246246            }
     
    259259        {
    260260            // iterate over all children and change their visibility as well
    261             for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++)
     261            for (const auto & elem : this->getAttachedObjects())
    262262            {
    263263                if(!this->isVisible())
    264264                {
    265                     (*it)->bVisibleMem_ = (*it)->isVisible();
    266                     (*it)->setVisible(this->isVisible());
     265                    (elem)->bVisibleMem_ = (elem)->isVisible();
     266                    (elem)->setVisible(this->isVisible());
    267267                }
    268268                else
    269269                {
    270                     (*it)->setVisible((*it)->bVisibleMem_);
     270                    (elem)->setVisible((elem)->bVisibleMem_);
    271271                }
    272272            }
     
    518518    {
    519519        unsigned int i = 0;
    520         for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it)
     520        for (const auto & elem : this->children_)
    521521        {
    522522            if (i == index)
    523                 return (*it);
     523                return (elem);
    524524            ++i;
    525525        }
     
    938938        // Recalculate mass
    939939        this->childrenMass_ = 0.0f;
    940         for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it)
    941             this->childrenMass_ += (*it)->getMass();
     940        for (const auto & elem : this->children_)
     941            this->childrenMass_ += (elem)->getMass();
    942942        recalculateMassProps();
    943943        // Notify parent WE
  • code/branches/cpp11_v2/src/orxonox/worldentities/pawns/ModularSpaceShip.cc

    r10768 r10821  
    9999            }
    100100            // iterate through all attached parts
    101             for(unsigned int j = 0; j < this->partList_.size(); j++)
     101            for(auto & elem : this->partList_)
    102102            {
    103103                // if the name of the part matches the name of the object, add the object to that parts entitylist (unless it was already done).
    104                 if((this->partList_[j]->getName() == this->getAttachedObject(i)->getName()) && !this->partList_[j]->hasEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i))))
     104                if((elem->getName() == this->getAttachedObject(i)->getName()) && !elem->hasEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i))))
    105105                {
    106106                    // The Entity is added to the part's entityList_
    107                     this->partList_[j]->addEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i)));
     107                    elem->addEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i)));
    108108                    // An entry in the partMap_ is created, assigning the part to the entity.
    109                     this->addPartEntityAssignment((StaticEntity*)(this->getAttachedObject(i)), this->partList_[j]);
     109                    this->addPartEntityAssignment((StaticEntity*)(this->getAttachedObject(i)), elem);
    110110                }
    111111            }
     
    146146    ShipPart* ModularSpaceShip::getPartOfEntity(StaticEntity* entity) const
    147147    {
    148         for (std::map<StaticEntity*, ShipPart*>::const_iterator it = this->partMap_.begin(); it != this->partMap_.end(); ++it)
    149         {
    150             if (it->first == entity)
    151                 return it->second;
     148        for (const auto & elem : this->partMap_)
     149        {
     150            if (elem.first == entity)
     151                return elem.second;
    152152        }
    153153        return nullptr;
     
    242242    ShipPart* ModularSpaceShip::getShipPartByName(std::string name)
    243243    {
    244         for(std::vector<ShipPart*>::iterator it = this->partList_.begin(); it != this->partList_.end(); ++it)
    245         {
    246             if(orxonox_cast<ShipPart*>(*it)->getName() == name)
    247             {
    248                 return orxonox_cast<ShipPart*>(*it);
     244        for(auto & elem : this->partList_)
     245        {
     246            if(orxonox_cast<ShipPart*>(elem)->getName() == name)
     247            {
     248                return orxonox_cast<ShipPart*>(elem);
    249249            }
    250250        }
     
    261261    bool ModularSpaceShip::hasShipPart(ShipPart* part) const
    262262    {
    263         for(unsigned int i = 0; i < this->partList_.size(); i++)
    264         {
    265             if(this->partList_[i] == part)
     263        for(auto & elem : this->partList_)
     264        {
     265            if(elem == part)
    266266                return true;
    267267        }
  • code/branches/cpp11_v2/src/orxonox/worldentities/pawns/SpaceShip.cc

    r10768 r10821  
    158158
    159159        // Run the engines
    160         for(std::vector<Engine*>::iterator it = this->engineList_.begin(); it != this->engineList_.end(); it++)
    161             (*it)->run(dt);
     160        for(auto & elem : this->engineList_)
     161            (elem)->run(dt);
    162162
    163163        if (this->hasLocalController())
     
    318318    bool SpaceShip::hasEngine(Engine* engine) const
    319319    {
    320         for(unsigned int i = 0; i < this->engineList_.size(); i++)
    321         {
    322             if(this->engineList_[i] == engine)
     320        for(auto & elem : this->engineList_)
     321        {
     322            if(elem == engine)
    323323                return true;
    324324        }
     
    350350    Engine* SpaceShip::getEngineByName(const std::string& name)
    351351    {
    352         for(size_t i = 0; i < this->engineList_.size(); ++i)
    353             if(this->engineList_[i]->getName() == name)
    354                 return this->engineList_[i];
     352        for(auto & elem : this->engineList_)
     353            if(elem->getName() == name)
     354                return elem;
    355355
    356356        orxout(internal_warning) << "Couldn't find Engine with name \"" << name << "\"." << endl;
     
    396396    void SpaceShip::addSpeedFactor(float factor)
    397397    {
    398         for(unsigned int i=0; i<this->engineList_.size(); i++)
    399             this->engineList_[i]->addSpeedMultiply(factor);
     398        for(auto & elem : this->engineList_)
     399            elem->addSpeedMultiply(factor);
    400400    }
    401401
     
    408408    void SpaceShip::addSpeed(float speed)
    409409    {
    410         for(unsigned int i=0; i<this->engineList_.size(); i++)
    411             this->engineList_[i]->addSpeedAdd(speed);
     410        for(auto & elem : this->engineList_)
     411            elem->addSpeedAdd(speed);
    412412    }
    413413
     
    436436    {
    437437        float speed=0;
    438         for(unsigned int i=0; i<this->engineList_.size(); i++)
    439         {
    440             if(this->engineList_[i]->getMaxSpeedFront() > speed)
    441                 speed = this->engineList_[i]->getMaxSpeedFront();
     438        for(auto & elem : this->engineList_)
     439        {
     440            if(elem->getMaxSpeedFront() > speed)
     441                speed = elem->getMaxSpeedFront();
    442442        }
    443443        return speed;
  • code/branches/cpp11_v2/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc

    r10624 r10821  
    8080
    8181        std::set<WorldEntity*> attachments = this->getAttachedObjects();
    82         for (std::set<WorldEntity*>::iterator it = attachments.begin(); it != attachments.end(); ++it)
     82        for (const auto & attachment : attachments)
    8383        {
    84             if ((*it)->isA(Class(TeamColourable)))
     84            if ((attachment)->isA(Class(TeamColourable)))
    8585            {
    86                 TeamColourable* tc = orxonox_cast<TeamColourable*>(*it);
     86                TeamColourable* tc = orxonox_cast<TeamColourable*>(attachment);
    8787                tc->setTeamColour(colour);
    8888            }
Note: See TracChangeset for help on using the changeset viewer.