Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 22, 2009, 2:07:44 PM (14 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
Location:
code/branches/presentation2/src/libraries/core/input
Files:
8 edited

Legend:

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

    r5929 r6394  
    116116        for (unsigned int iCommand = 0; iCommand < commandStrings.size(); iCommand++)
    117117        {
    118             if (commandStrings[iCommand] != "")
     118            if (!commandStrings[iCommand].empty())
    119119            {
    120120                SubString tokens(commandStrings[iCommand], " ", SubString::WhiteSpaces, false,
     
    123123                KeybindMode::Value mode = KeybindMode::None;
    124124                float paramModifier = 1.0f;
    125                 std::string commandStr = "";
     125                std::string commandStr;
    126126
    127127                for (unsigned int iToken = 0; iToken < tokens.size(); ++iToken)
    128128                {
    129                     std::string token = getLowercase(tokens[iToken]);
     129                    const std::string& token = getLowercase(tokens[iToken]);
    130130
    131131                    if (token == "onpress")
     
    159159                        // we interpret everything from here as a command string
    160160                        while (iToken != tokens.size())
    161                             commandStr += tokens[iToken++] + " ";
    162                     }
    163                 }
    164 
    165                 if (commandStr == "")
     161                            commandStr += tokens[iToken++] + ' ';
     162                    }
     163                }
     164
     165                if (commandStr.empty())
    166166                {
    167167                    parseError("No command string given.", false);
     
    242242    }
    243243
    244     inline void Button::parseError(std::string message, bool serious)
     244    inline void Button::parseError(const std::string& message, bool serious)
    245245    {
    246246        if (serious)
  • code/branches/presentation2/src/libraries/core/input/Button.h

    r5781 r6394  
    7676
    7777    private:
    78         void parseError(std::string message, bool serious);
     78        void parseError(const std::string& message, bool serious);
    7979    };
    8080
  • code/branches/presentation2/src/libraries/core/input/InputBuffer.cc

    r6177 r6394  
    3939        RegisterRootObject(InputBuffer);
    4040
    41         this->buffer_ = "";
    4241        this->cursor_ = 0;
    4342        this->maxLength_ = 1024;
     
    6261        this->maxLength_ = 1024;
    6362        this->allowedChars_ = allowedChars;
    64         this->buffer_ = "";
    6563        this->cursor_ = 0;
    6664
     
    138136    void InputBuffer::clear(bool update)
    139137    {
    140         this->buffer_ = "";
     138        this->buffer_.clear();
    141139        this->cursor_ = 0;
    142140
     
    188186    bool InputBuffer::charIsAllowed(const char& input)
    189187    {
    190         if (this->allowedChars_ == "")
     188        if (this->allowedChars_.empty())
    191189            return true;
    192190        else
  • code/branches/presentation2/src/libraries/core/input/InputManager.cc

    r6388 r6394  
    297297            if (device == NULL)
    298298                continue;
    299             std::string className = device->getClassName();
     299            const std::string& className = device->getClassName();
    300300            try
    301301            {
     
    579579    InputState* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
    580580    {
    581         if (name == "")
     581        if (name.empty())
    582582            return 0;
    583583        if (statesByName_.find(name) == statesByName_.end())
  • code/branches/presentation2/src/libraries/core/input/JoyStick.cc

    r5781 r6394  
    3333#include <boost/foreach.hpp>
    3434
     35#include "util/StringUtils.h"
    3536#include "core/ConfigFileManager.h"
    3637#include "core/ConfigValueIncludes.h"
     
    6162            std::string name = oisDevice_->vendor();
    6263            replaceCharacters(name, ' ', '_');
    63             deviceName_ = name + "_";
    64         }
    65         deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button))  + "_";
    66         deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis))    + "_";
    67         deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider))  + "_";
     64            deviceName_ = name + '_';
     65        }
     66        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Button))  + '_';
     67        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Axis))    + '_';
     68        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Slider))  + '_';
    6869        deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV));
    6970        //deviceName_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3));
     
    7475            {
    7576                // Make the ID unique for this execution time.
    76                 deviceName_ += "_" + multi_cast<std::string>(this->getDeviceName());
     77                deviceName_ += '_' + multi_cast<std::string>(this->getDeviceName());
    7778                break;
    7879            }
  • 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())
  • code/branches/presentation2/src/libraries/core/input/KeyBinder.h

    r6387 r6394  
    6666        void clearBindings();
    6767        bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
    68         std::string getBinding(std::string commandName); //tolua_export
    69         std::string getBinding(std::string commandName, unsigned int index); //tolua_export
    70         unsigned int getNumberOfBindings(std::string commandName); //tolua_export
     68        const std::string& getBinding(const std::string& commandName); //tolua_export
     69        const std::string& getBinding(const std::string& commandName, unsigned int index); //tolua_export
     70        unsigned int getNumberOfBindings(const std::string& commandName); //tolua_export
    7171
    7272        const std::string& getBindingsFilename()
     
    160160
    161161    private:
    162         void addButtonToCommand(std::string command, Button* button);
     162        void addButtonToCommand(const std::string& command, Button* button);
    163163
    164164        //##### ConfigValues #####
  • code/branches/presentation2/src/libraries/core/input/KeyDetector.cc

    r6182 r6394  
    6767        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    6868        {
    69             it->second->bindingString_ = callbackCommand_s + " " + it->second->groupName_ + "." + it->second->name_;
     69            it->second->bindingString_ = callbackCommand_s + ' ' + it->second->groupName_ + "." + it->second->name_;
    7070            it->second->parse();
    7171        }
Note: See TracChangeset for help on using the changeset viewer.