Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 22, 2009, 2:07:44 PM (16 years ago)
Author:
rgrieder
Message:

std::string tweaks:

  • Declared BLANKSTRING in UtilPrereqs.h as well (removed obsolete StringUtils.h includes to avoid dependencies)
  • Using BLANKSTRING if const std::string& return type is possible
  • Replaced a few (const) std::string arguments with const std::string&
  • if (str == "") —> if (str.empty())
  • std::string msg = name + "adsf"; —> const std::string& msg = name + "asdf";
  • std::string asdf = object→getFooBar(); —> const std::string& asdf = object→getFooBar();
  • std::string asdf = "asdf"; —> std::string asdf("asdf");
  • ostream << "."; and name + "." —> ostream << '.'; and name + '.'
  • str = ""; —> str.clear()
  • std::string asdf = ""; —> std::string asdf;
  • asdf_ = ""; (in c'tor) —> delete line
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/libraries/core/input/KeyBinder.cc

    r6388 r6394  
    6161        for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
    6262        {
    63             std::string keyname = KeyCode::ByString[i];
     63            const std::string& keyname = KeyCode::ByString[i];
    6464            if (!keyname.empty())
    6565                keys_[i].name_ = std::string("Key") + keyname;
    6666            else
    67                 keys_[i].name_ = "";
     67                keys_[i].name_.clear();
    6868            keys_[i].paramCommandBuffer_ = &paramCommandBuffer_;
    6969            keys_[i].groupName_ = "Keys";
     
    188188        this->joyStickButtons_.resize(joySticks_.size());
    189189
    190         // reinitialise all joy stick binings (doesn't overwrite the old ones)
     190        // reinitialise all joy stick bindings (doesn't overwrite the old ones)
    191191        for (unsigned int iDev = 0; iDev < joySticks_.size(); iDev++)
    192192        {
    193             std::string deviceName = joySticks_[iDev]->getDeviceName();
     193            const std::string& deviceName = joySticks_[iDev]->getDeviceName();
    194194            // joy stick buttons
    195195            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
     
    221221        for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
    222222            if (!keys_[i].name_.empty())
    223                 allButtons_[keys_[i].groupName_ + "." + keys_[i].name_] = keys_ + i;
     223                allButtons_[keys_[i].groupName_ + '.' + keys_[i].name_] = keys_ + i;
    224224        for (unsigned int i = 0; i < numberOfMouseButtons_; i++)
    225             allButtons_[mouseButtons_[i].groupName_ + "." + mouseButtons_[i].name_] = mouseButtons_ + i;
     225            allButtons_[mouseButtons_[i].groupName_ + '.' + mouseButtons_[i].name_] = mouseButtons_ + i;
    226226        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
    227227        {
    228             allButtons_[mouseAxes_[i].groupName_ + "." + mouseAxes_[i].name_] = mouseAxes_ + i;
     228            allButtons_[mouseAxes_[i].groupName_ + '.' + mouseAxes_[i].name_] = mouseAxes_ + i;
    229229            allHalfAxes_.push_back(mouseAxes_ + i);
    230230        }
     
    232232        {
    233233            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
    234                 allButtons_[(*joyStickButtons_[iDev])[i].groupName_ + "." + (*joyStickButtons_[iDev])[i].name_] = &((*joyStickButtons_[iDev])[i]);
     234                allButtons_[(*joyStickButtons_[iDev])[i].groupName_ + '.' + (*joyStickButtons_[iDev])[i].name_] = &((*joyStickButtons_[iDev])[i]);
    235235            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    236236            {
    237                 allButtons_[(*joyStickAxes_[iDev])[i].groupName_ + "." + (*joyStickAxes_[iDev])[i].name_] = &((*joyStickAxes_[iDev])[i]);
     237                allButtons_[(*joyStickAxes_[iDev])[i].groupName_ + '.' + (*joyStickAxes_[iDev])[i].name_] = &((*joyStickAxes_[iDev])[i]);
    238238                allHalfAxes_.push_back(&((*joyStickAxes_[iDev])[i]));
    239239            }
     
    284284    }
    285285
    286      void KeyBinder::addButtonToCommand(std::string command, Button* button)
     286     void KeyBinder::addButtonToCommand(const std::string& command, Button* button)
    287287     {
    288288        std::ostringstream stream;
    289         stream << button->groupName_  << "." << button->name_;
     289        stream << button->groupName_  << '.' << button->name_;
    290290
    291291        std::vector<std::string>& oldKeynames = this->allCommands_[button->bindingString_];
     
    296296        }
    297297
    298         if(command != "")
     298        if (!command.empty())
    299299        {
    300300            std::vector<std::string>& keynames = this->allCommands_[command];
     
    310310        Return the first key name for a specific command
    311311    */
    312     std::string KeyBinder::getBinding(std::string commandName)
     312    const std::string& KeyBinder::getBinding(const std::string& commandName)
    313313    {
    314314        if( this->allCommands_.find(commandName) != this->allCommands_.end())
     
    318318        }
    319319
    320         return "";
     320        return BLANKSTRING;
    321321    }
    322322
     
    329329        The index at which the key name is returned for.
    330330    */
    331     std::string KeyBinder::getBinding(std::string commandName, unsigned int index)
     331    const std::string& KeyBinder::getBinding(const std::string& commandName, unsigned int index)
    332332    {
    333333        if( this->allCommands_.find(commandName) != this->allCommands_.end())
     
    339339            }
    340340
    341             return "";
    342         }
    343 
    344         return "";
     341            return BLANKSTRING;
     342        }
     343
     344        return BLANKSTRING;
    345345    }
    346346
     
    351351        The command.
    352352    */
    353     unsigned int KeyBinder::getNumberOfBindings(std::string commandName)
     353    unsigned int KeyBinder::getNumberOfBindings(const std::string& commandName)
    354354    {
    355355        if( this->allCommands_.find(commandName) != this->allCommands_.end())
Note: See TracChangeset for help on using the changeset viewer.