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/weaponsystem
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/orxonox/weaponsystem/Munition.cc

    r10768 r10821  
    5555    Munition::~Munition()
    5656    {
    57         for (std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)
    58             delete it->second;
     57        for (auto & elem : this->currentMagazines_)
     58            delete elem.second;
    5959    }
    6060
     
    268268        {
    269269            // Return true if any of the current magazines is not full (loading counts as full although it returns 0 munition)
    270             for (std::map<WeaponMode*, Magazine*>::const_iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)
    271                 if (it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_)
     270            for (const auto & elem : this->currentMagazines_)
     271                if (elem.second->munition_ < this->maxMunitionPerMagazine_ && elem.second->bLoaded_)
    272272                    return true;
    273273        }
     
    316316            {
    317317                bool change = false;
    318                 for (std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)
     318                for (auto & elem : this->currentMagazines_)
    319319                {
    320320                    // Add munition if the magazine isn't full (but only to loaded magazines)
    321                     if (amount > 0 && it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_)
     321                    if (amount > 0 && elem.second->munition_ < this->maxMunitionPerMagazine_ && elem.second->bLoaded_)
    322322                    {
    323                         it->second->munition_++;
     323                        elem.second->munition_++;
    324324                        amount--;
    325325                        change = true;
  • code/branches/cpp11_v2/src/orxonox/weaponsystem/Weapon.cc

    r10768 r10821  
    6161                this->weaponPack_->removeWeapon(this);
    6262
    63             for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)
    64                 it->second->destroy();
     63            for (auto & elem : this->weaponmodes_)
     64                elem.second->destroy();
    6565        }
    6666    }
     
    8585    {
    8686        unsigned int i = 0;
    87         for (std::multimap<unsigned int, WeaponMode*>::const_iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)
     87        for (const auto & elem : this->weaponmodes_)
    8888        {
    8989            if (i == index)
    90                 return it->second;
     90                return elem.second;
    9191
    9292            ++i;
     
    136136    void Weapon::reload()
    137137    {
    138         for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)
    139             it->second->reload();
     138        for (auto & elem : this->weaponmodes_)
     139            elem.second->reload();
    140140    }
    141141
     
    148148    void Weapon::notifyWeaponModes()
    149149    {
    150         for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)
    151             it->second->setWeapon(this);
     150        for (auto & elem : this->weaponmodes_)
     151            elem.second->setWeapon(this);
    152152    }
    153153}
  • code/branches/cpp11_v2/src/orxonox/weaponsystem/WeaponPack.cc

    r10768 r10821  
    7676    void WeaponPack::fire(unsigned int weaponmode)
    7777    {
    78         for (std::vector<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
    79             (*it)->fire(weaponmode);
     78        for (auto & elem : this->weapons_)
     79            (elem)->fire(weaponmode);
    8080    }
    8181
     
    8686    void WeaponPack::reload()
    8787    {
    88         for (std::vector<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
    89             (*it)->reload();
     88        for (auto & elem : this->weapons_)
     89            (elem)->reload();
    9090    }
    9191
     
    114114        unsigned int i = 0;
    115115
    116         for (std::vector<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
     116        for (const auto & elem : this->weapons_)
    117117        {
    118118            if (i == index)
    119                 return (*it);
     119                return (elem);
    120120            ++i;
    121121        }
     
    132132    {
    133133        unsigned int i = 0;
    134         for (std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it)
     134        for (const auto & elem : this->links_)
    135135        {
    136136            if (i == index)
    137                 return (*it);
     137                return (elem);
    138138
    139139            ++i;
     
    144144    unsigned int WeaponPack::getDesiredWeaponmode(unsigned int firemode) const
    145145    {
    146         for (std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it)
    147             if ((*it)->getFiremode() == firemode)
    148                 return (*it)->getWeaponmode();
     146        for (const auto & elem : this->links_)
     147            if ((elem)->getFiremode() == firemode)
     148                return (elem)->getWeaponmode();
    149149
    150150        return WeaponSystem::WEAPON_MODE_UNASSIGNED;
  • code/branches/cpp11_v2/src/orxonox/weaponsystem/WeaponSet.cc

    r10768 r10821  
    6363    {
    6464        // Fire all WeaponPacks with their defined weaponmode
    65         for (std::map<WeaponPack*, unsigned int>::iterator it = this->weaponpacks_.begin(); it != this->weaponpacks_.end(); ++it)
    66             if (it->second != WeaponSystem::WEAPON_MODE_UNASSIGNED)
    67                 it->first->fire(it->second);
     65        for (auto & elem : this->weaponpacks_)
     66            if (elem.second != WeaponSystem::WEAPON_MODE_UNASSIGNED)
     67                elem.first->fire(elem.second);
    6868    }
    6969
     
    7171    {
    7272        // Reload all WeaponPacks with their defined weaponmode
    73         for (std::map<WeaponPack*, unsigned int>::iterator it = this->weaponpacks_.begin(); it != this->weaponpacks_.end(); ++it)
    74             it->first->reload();
     73        for (auto & elem : this->weaponpacks_)
     74            elem.first->reload();
    7575    }
    7676
  • code/branches/cpp11_v2/src/orxonox/weaponsystem/WeaponSystem.cc

    r10768 r10821  
    106106    {
    107107        unsigned int i = 0;
    108         for (std::vector<WeaponSlot*>::const_iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
     108        for (const auto & elem : this->weaponSlots_)
    109109        {
    110110            ++i;
    111111            if (i > index)
    112                 return (*it);
     112                return (elem);
    113113        }
    114114        return nullptr;
     
    153153    {
    154154        unsigned int i = 0;
    155         for (std::map<unsigned int, WeaponSet*>::const_iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it)
     155        for (const auto & elem : this->weaponSets_)
    156156        {
    157157            ++i;
    158158            if (i > index)
    159                 return it->second;
     159                return elem.second;
    160160        }
    161161        return nullptr;
     
    168168
    169169        unsigned int freeSlots = 0;
    170         for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
    171         {
    172             if (!(*it)->isOccupied())
     170        for (auto & elem : this->weaponSlots_)
     171        {
     172            if (!(elem)->isOccupied())
    173173                ++freeSlots;
    174174        }
     
    184184        // Attach all weapons to the first free slots (and to the Pawn)
    185185        unsigned int i = 0;
    186         for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
    187         {
    188             if (!(*it)->isOccupied() && i < wPack->getNumWeapons())
     186        for (auto & elem : this->weaponSlots_)
     187        {
     188            if (!(elem)->isOccupied() && i < wPack->getNumWeapons())
    189189            {
    190190                Weapon* weapon = wPack->getWeapon(i);
    191                 (*it)->attachWeapon(weapon);
     191                (elem)->attachWeapon(weapon);
    192192                this->getPawn()->attach(weapon);
    193193                ++i;
     
    196196
    197197        // Assign the desired weaponmode to the firemodes
    198         for (std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it)
    199         {
    200             unsigned int weaponmode = wPack->getDesiredWeaponmode(it->first);
     198        for (auto & elem : this->weaponSets_)
     199        {
     200            unsigned int weaponmode = wPack->getDesiredWeaponmode(elem.first);
    201201            if (weaponmode != WeaponSystem::WEAPON_MODE_UNASSIGNED)
    202                 it->second->setWeaponmodeLink(wPack, weaponmode);
     202                elem.second->setWeaponmodeLink(wPack, weaponmode);
    203203        }
    204204
     
    219219
    220220        // Remove all added links from the WeaponSets
    221         for (std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it)
    222             it->second->removeWeaponmodeLink(wPack);
     221        for (auto & elem : this->weaponSets_)
     222            elem.second->removeWeaponmodeLink(wPack);
    223223
    224224        // Remove the WeaponPack from the WeaponSystem
     
    231231    {
    232232        unsigned int i = 0;
    233         for (std::vector<WeaponPack*>::const_iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it)
     233        for (const auto & elem : this->weaponPacks_)
    234234        {
    235235            ++i;
    236236            if (i > index)
    237                 return (*it);
     237                return (elem);
    238238        }
    239239        return nullptr;
     
    268268        // Check if the WeaponSet belongs to this WeaponSystem
    269269        bool foundWeaponSet = false;
    270         for (std::map<unsigned int, WeaponSet *>::iterator it2 = this->weaponSets_.begin(); it2 != this->weaponSets_.end(); ++it2)
    271         {
    272             if (it2->second == wSet)
     270        for (auto & elem : this->weaponSets_)
     271        {
     272            if (elem.second == wSet)
    273273            {
    274274                foundWeaponSet = true;
     
    296296    void WeaponSystem::reload()
    297297    {
    298         for (std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it)
    299             it->second->reload();
     298        for (auto & elem : this->weaponSets_)
     299            elem.second->reload();
    300300    }
    301301
Note: See TracChangeset for help on using the changeset viewer.