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/libraries/core/input
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/core/input/Button.cc

    r10768 r10821  
    196196
    197197                    // add command to the buffer if not yet existing
    198                     for (unsigned int iParamCmd = 0; iParamCmd < paramCommandBuffer_->size(); iParamCmd++)
    199                     {
    200                         if ((*paramCommandBuffer_)[iParamCmd]->evaluation_.getConsoleCommand()
     198                    for (auto & elem : *paramCommandBuffer_)
     199                    {
     200                        if (elem->evaluation_.getConsoleCommand()
    201201                            == eval.getConsoleCommand())
    202202                        {
    203203                            // already in list
    204                             cmd->paramCommand_ = (*paramCommandBuffer_)[iParamCmd];
     204                            cmd->paramCommand_ = elem;
    205205                            break;
    206206                        }
  • code/branches/cpp11_v2/src/libraries/core/input/InputBuffer.cc

    r9667 r10821  
    110110    void InputBuffer::insert(const std::string& input, bool update)
    111111    {
    112         for (unsigned int i = 0; i < input.size(); ++i)
    113         {
    114             this->insert(input[i], false);
     112        for (auto & elem : input)
     113        {
     114            this->insert(elem, false);
    115115
    116116            if (update)
    117                 this->updated(input[i], false);
     117                this->updated(elem, false);
    118118        }
    119119
     
    170170    void InputBuffer::updated()
    171171    {
    172         for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
    173         {
    174             if ((*it)->bListenToAllChanges_)
    175                 (*it)->callFunction();
     172        for (auto & elem : this->listeners_)
     173        {
     174            if ((elem)->bListenToAllChanges_)
     175                (elem)->callFunction();
    176176        }
    177177    }
     
    179179    void InputBuffer::updated(const char& update, bool bSingleInput)
    180180    {
    181         for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
    182         {
    183             if ((!(*it)->trueKeyFalseChar_) && ((*it)->bListenToAllChanges_ || ((*it)->char_ == update)) && (!(*it)->bOnlySingleInput_ || bSingleInput))
    184                 (*it)->callFunction();
     181        for (auto & elem : this->listeners_)
     182        {
     183            if ((!(elem)->trueKeyFalseChar_) && ((elem)->bListenToAllChanges_ || ((elem)->char_ == update)) && (!(elem)->bOnlySingleInput_ || bSingleInput))
     184                (elem)->callFunction();
    185185        }
    186186    }
     
    201201            return;
    202202
    203         for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
    204         {
    205             if ((*it)->trueKeyFalseChar_ && ((*it)->key_ == evt.getKeyCode()))
    206                 (*it)->callFunction();
     203        for (auto & elem : this->listeners_)
     204        {
     205            if ((elem)->trueKeyFalseChar_ && ((elem)->key_ == evt.getKeyCode()))
     206                (elem)->callFunction();
    207207        }
    208208
  • code/branches/cpp11_v2/src/libraries/core/input/InputDevice.h

    r10817 r10821  
    158158
    159159            // Call all the states with the held button event
    160             for (unsigned int iB = 0; iB < pressedButtons_.size(); ++iB)
    161                 for (unsigned int iS = 0; iS < inputStates_.size(); ++iS)
    162                     inputStates_[iS]->template buttonEvent<ButtonEvent::THold, typename Traits::ButtonTypeParam>(
    163                         this->getDeviceID(), static_cast<DeviceClass*>(this)->getButtonEventArg(pressedButtons_[iB]));
     160            for (auto & button : pressedButtons_)
     161                for (auto & state : inputStates_)
     162                    state->template buttonEvent<ButtonEvent::THold, typename Traits::ButtonTypeParam>(
     163                        this->getDeviceID(), static_cast<DeviceClass*>(this)->getButtonEventArg(button));
    164164
    165165            // Call states with device update events
    166             for (unsigned int i = 0; i < inputStates_.size(); ++i)
    167                 inputStates_[i]->update(time.getDeltaTime(), this->getDeviceID());
     166            for (auto & elem : inputStates_)
     167                elem->update(time.getDeltaTime(), this->getDeviceID());
    168168
    169169            static_cast<DeviceClass*>(this)->updateImpl(time);
     
    196196
    197197            // Call states
    198             for (unsigned int i = 0; i < inputStates_.size(); ++i)
    199                 inputStates_[i]->template buttonEvent<ButtonEvent::TPress, typename Traits::ButtonTypeParam>(this->getDeviceID(), static_cast<DeviceClass*>(this)->getButtonEventArg(button));
     198            for (auto & elem : inputStates_)
     199                elem->template buttonEvent<ButtonEvent::TPress, typename Traits::ButtonTypeParam>(this->getDeviceID(), static_cast<DeviceClass*>(this)->getButtonEventArg(button));
    200200        }
    201201
     
    218218
    219219            // Call states
    220             for (unsigned int i = 0; i < inputStates_.size(); ++i)
    221                 inputStates_[i]->template buttonEvent<ButtonEvent::TRelease, typename Traits::ButtonTypeParam>(this->getDeviceID(), static_cast<DeviceClass*>(this)->getButtonEventArg(button));
     220            for (auto & elem : inputStates_)
     221                elem->template buttonEvent<ButtonEvent::TRelease, typename Traits::ButtonTypeParam>(this->getDeviceID(), static_cast<DeviceClass*>(this)->getButtonEventArg(button));
    222222        }
    223223
  • code/branches/cpp11_v2/src/libraries/core/input/InputManager.cc

    r10778 r10821  
    373373        // check whether a state has changed its EMPTY situation
    374374        bool bUpdateRequired = false;
    375         for (std::map<int, InputState*>::iterator it = activeStates_.begin(); it != activeStates_.end(); ++it)
    376         {
    377             if (it->second->hasExpired())
    378             {
    379                 it->second->resetExpiration();
     375        for (auto & elem : activeStates_)
     376        {
     377            if (elem.second->hasExpired())
     378            {
     379                elem.second->resetExpiration();
    380380                bUpdateRequired = true;
    381381            }
     
    391391
    392392        // Collect function calls for the update
    393         for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i)
    394             activeStatesTicked_[i]->update(time.getDeltaTime());
     393        for (auto & elem : activeStatesTicked_)
     394            elem->update(time.getDeltaTime());
    395395
    396396        // Execute all cached function calls in order
     
    401401        // If we delay the calls, then OIS and and the InputStates are not anymore
    402402        // in the call stack and can therefore be edited.
    403         for (size_t i = 0; i < this->callBuffer_.size(); ++i)
    404             this->callBuffer_[i]();
     403        for (auto & elem : this->callBuffer_)
     404            elem();
    405405
    406406        this->callBuffer_.clear();
     
    437437        // Using an std::set to avoid duplicates
    438438        std::set<InputState*> tempSet;
    439         for (unsigned int i = 0; i < devices_.size(); ++i)
    440             if (devices_[i] != nullptr)
    441                 for (unsigned int iState = 0; iState < devices_[i]->getStateListRef().size(); ++iState)
    442                     tempSet.insert(devices_[i]->getStateListRef()[iState]);
     439        for (auto & elem : devices_)
     440            if (elem != nullptr)
     441                for (unsigned int iState = 0; iState < elem->getStateListRef().size(); ++iState)
     442                    tempSet.insert(elem->getStateListRef()[iState]);
    443443
    444444        // Copy the content of the std::set back to the actual vector
    445445        activeStatesTicked_.clear();
    446         for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
    447             activeStatesTicked_.push_back(*it);
     446        for (const auto & elem : tempSet)
     447            activeStatesTicked_.push_back(elem);
    448448
    449449        // Check whether we have to change the mouse mode
  • code/branches/cpp11_v2/src/libraries/core/input/JoyStick.cc

    r10778 r10821  
    186186    void JoyStick::clearBuffersImpl()
    187187    {
    188         for (int j = 0; j < 4; ++j)
    189             povStates_[j] = 0;
     188        for (auto & elem : povStates_)
     189            elem = 0;
    190190    }
    191191
  • code/branches/cpp11_v2/src/libraries/core/input/KeyBinder.cc

    r10772 r10821  
    153153    void KeyBinder::buttonThresholdChanged()
    154154    {
    155         for (unsigned int i = 0; i < allHalfAxes_.size(); i++)
    156             if (!allHalfAxes_[i]->bButtonThresholdUser_)
    157                 allHalfAxes_[i]->buttonThreshold_ = this->buttonThreshold_;
     155        for (auto & elem : allHalfAxes_)
     156            if (!elem->bButtonThresholdUser_)
     157                elem->buttonThreshold_ = this->buttonThreshold_;
    158158    }
    159159
     
    383383            it->second->clear();
    384384
    385         for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++)
    386             delete paramCommandBuffer_[i];
     385        for (auto & elem : paramCommandBuffer_)
     386            delete elem;
    387387        paramCommandBuffer_.clear();
    388388    }
     
    394394    {
    395395        // iterate over all buttons
    396         for (std::map<std::string, Button*>::iterator it = this->allButtons_.begin(); it != this->allButtons_.end(); ++it)
    397         {
    398             Button* button = it->second;
     396        for (const auto & elem : this->allButtons_)
     397        {
     398            Button* button = elem.second;
    399399
    400400            // iterate over all modes
     
    465465        this->mousePosition_[1] = 0.0f;
    466466
    467         for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
    468             mouseAxes_[i].reset();
     467        for (auto & elem : mouseAxes_)
     468            elem.reset();
    469469    }
    470470
     
    505505        }
    506506
    507         for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
     507        for (auto & elem : mouseAxes_)
    508508        {
    509509            // Why dividing relative value by dt? The reason lies in the simple fact, that when you
     
    515515            {
    516516                // just ignore if dt == 0.0 because we have multiplied by 0.0 anyway..
    517                 mouseAxes_[i].relVal_ /= dt;
    518             }
    519 
    520             tickHalfAxis(mouseAxes_[i]);
     517                elem.relVal_ /= dt;
     518            }
     519
     520            tickHalfAxis(elem);
    521521        }
    522522    }
  • code/branches/cpp11_v2/src/libraries/core/input/KeyBinder.h

    r10817 r10821  
    226226    {
    227227        // execute all buffered bindings (additional parameter)
    228         for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++)
     228        for (auto & elem : paramCommandBuffer_)
    229229        {
    230             paramCommandBuffer_[i]->rel_ *= dt;
    231             paramCommandBuffer_[i]->execute();
     230            elem->rel_ *= dt;
     231            elem->execute();
    232232        }
    233233
    234234        // always reset the relative movement of the mouse
    235         for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
    236             mouseAxes_[i].relVal_ = 0.0f;
     235        for (auto & elem : mouseAxes_)
     236            elem.relVal_ = 0.0f;
    237237    }
    238238}// tolua_export
  • code/branches/cpp11_v2/src/libraries/core/input/Mouse.cc

    r10768 r10821  
    8282            IntVector2 rel(e.state.X.rel, e.state.Y.rel);
    8383            IntVector2 clippingSize(e.state.width, e.state.height);
    84             for (unsigned int i = 0; i < inputStates_.size(); ++i)
    85                 inputStates_[i]->mouseMoved(abs, rel, clippingSize);
     84            for (auto & elem : inputStates_)
     85                elem->mouseMoved(abs, rel, clippingSize);
    8686        }
    8787
     
    8989        if (e.state.Z.rel != 0)
    9090        {
    91             for (unsigned int i = 0; i < inputStates_.size(); ++i)
    92                 inputStates_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
     91            for (auto & elem : inputStates_)
     92                elem->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    9393        }
    9494
Note: See TracChangeset for help on using the changeset viewer.