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/command
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/core/command/ArgumentCompletionFunctions.cc

    r10769 r10821  
    7777            bool groupIsVisible(const std::map<std::string, ConsoleCommand*>& group, bool bOnlyShowHidden)
    7878            {
    79                 for (std::map<std::string, ConsoleCommand*>::const_iterator it_command = group.begin(); it_command != group.end(); ++it_command)
    80                     if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden)
     79                for (const auto & elem : group)
     80                    if (elem.second->isActive() && elem.second->hasAccess() && (!elem.second->isHidden())^bOnlyShowHidden)
    8181                        return true;
    8282
     
    100100                // get all the groups that are visible (except the shortcut group "")
    101101                const std::map<std::string, std::map<std::string, ConsoleCommand*>>& commands = ConsoleCommandManager::getInstance().getCommands();
    102                 for (std::map<std::string, std::map<std::string, ConsoleCommand*>>::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group)
    103                     if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "" && (fragmentLC == "" || getLowercase(it_group->first).find(fragmentLC) == 0))
    104                         groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first)));
     102                for (const auto & command : commands)
     103                    if (groupIsVisible(command.second, bOnlyShowHidden) && command.first != "" && (fragmentLC == "" || getLowercase(command.first).find(fragmentLC) == 0))
     104                        groupList.push_back(ArgumentCompletionListElement(command.first, getLowercase(command.first)));
    105105
    106106                // now add all shortcuts (in group "")
     
    113113
    114114                    // add the shortcuts
    115                     for (std::map<std::string, ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)
    116                         if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden && (fragmentLC == "" || getLowercase(it_command->first).find(fragmentLC) == 0))
    117                             groupList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first)));
     115                    for (const auto & elem : it_group->second)
     116                        if (elem.second->isActive() && elem.second->hasAccess() && (!elem.second->isHidden())^bOnlyShowHidden && (fragmentLC == "" || getLowercase(elem.first).find(fragmentLC) == 0))
     117                            groupList.push_back(ArgumentCompletionListElement(elem.first, getLowercase(elem.first)));
    118118                }
    119119
     
    146146                if (it_group != ConsoleCommandManager::getInstance().getCommands().end())
    147147                {
    148                     for (std::map<std::string, ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)
    149                         if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden)
    150                             commandList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first)));
     148                    for (const auto & elem : it_group->second)
     149                        if (elem.second->isActive() && elem.second->hasAccess() && (!elem.second->isHidden())^bOnlyShowHidden)
     150                            commandList.push_back(ArgumentCompletionListElement(elem.first, getLowercase(elem.first)));
    151151                }
    152152
     
    281281
    282282            const std::set<std::string>& names = SettingsConfigFile::getInstance().getSectionNames();
    283             for (std::set<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
    284                 sectionList.push_back(ArgumentCompletionListElement(*it, getLowercase(*it)));
     283            for (const auto & name : names)
     284                sectionList.push_back(ArgumentCompletionListElement(name, getLowercase(name)));
    285285
    286286            return sectionList;
  • code/branches/cpp11_v2/src/libraries/core/command/CommandEvaluation.cc

    r10769 r10821  
    306306                // the user typed 1-2 arguments, check what he tried to type and print a suitable error
    307307                std::string groupLC = getLowercase(this->getToken(0));
    308                 for (std::map<std::string, std::map<std::string, ConsoleCommand*>>::const_iterator it_group = ConsoleCommandManager::getInstance().getCommandsLC().begin(); it_group != ConsoleCommandManager::getInstance().getCommandsLC().end(); ++it_group)
    309                     if (it_group->first == groupLC)
     308                for (const auto & elem : ConsoleCommandManager::getInstance().getCommandsLC())
     309                    if (elem.first == groupLC)
    310310                        return std::string("Error: There is no command in group \"") + this->getToken(0) + "\" starting with \"" + this->getToken(1) + "\".";
    311311
     
    328328
    329329        // iterate through all groups and their commands and calculate the distance to the current command. keep the best.
    330         for (std::map<std::string, std::map<std::string, ConsoleCommand*>>::const_iterator it_group = ConsoleCommandManager::getInstance().getCommandsLC().begin(); it_group != ConsoleCommandManager::getInstance().getCommandsLC().end(); ++it_group)
    331         {
    332             if (it_group->first != "")
    333             {
    334                 for (std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ++it_name)
    335                 {
    336                     std::string command = it_group->first + " " + it_name->first;
     330        for (const auto & elem : ConsoleCommandManager::getInstance().getCommandsLC())
     331        {
     332            if (elem.first != "")
     333            {
     334                for (std::map<std::string, ConsoleCommand*>::const_iterator it_name = elem.second.begin(); it_name != elem.second.end(); ++it_name)
     335                {
     336                    std::string command = elem.first + " " + it_name->first;
    337337                    unsigned int distance = getLevenshteinDistance(command, token0_LC + " " + token1_LC);
    338338                    if (distance < nearestDistance)
     
    349349        if (it_group !=  ConsoleCommandManager::getInstance().getCommandsLC().end())
    350350        {
    351             for (std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ++it_name)
    352             {
    353                 std::string command = it_name->first;
     351            for (const auto & elem : it_group->second)
     352            {
     353                std::string command = elem.first;
    354354                unsigned int distance = getLevenshteinDistance(command, token0_LC);
    355355                if (distance < nearestDistance)
     
    429429    {
    430430        size_t count = 0;
    431         for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
    432             if (it->getComparable() != "")
     431        for (const auto & elem : list)
     432            if (elem.getComparable() != "")
    433433                ++count;
    434434        return count;
     
    495495        {
    496496            // only one (non-empty) value in the list - search it and return it
    497             for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
    498             {
    499                 if (it->getComparable() != "")
     497            for (const auto & elem : list)
     498            {
     499                if (elem.getComparable() != "")
    500500                {
    501501                    // arguments that have a separate string to be displayed need a little more care - just return them without modification. add a space character to the others.
    502                     if (it->hasDisplay())
    503                         return (it->getString());
     502                    if (elem.hasDisplay())
     503                        return (elem.getString());
    504504                    else
    505                         return (it->getString() + ' ');
     505                        return (elem.getString() + ' ');
    506506                }
    507507            }
     
    517517                char tempComparable = '\0';
    518518                char temp = '\0';
    519                 for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
    520                 {
    521                     const std::string& argumentComparable = it->getComparable();
    522                     const std::string& argument = it->getString();
     519                for (const auto & elem : list)
     520                {
     521                    const std::string& argumentComparable = elem.getComparable();
     522                    const std::string& argument = elem.getString();
    523523
    524524                    // ignore empty arguments
     
    560560    {
    561561        std::string output;
    562         for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
    563         {
    564             output += it->getDisplay();
     562        for (const auto & elem : list)
     563        {
     564            output += elem.getDisplay();
    565565
    566566            // add a space character between two elements for all non-empty arguments
    567             if (it->getComparable() != "")
     567            if (elem.getComparable() != "")
    568568                output += ' ';
    569569        }
  • code/branches/cpp11_v2/src/libraries/core/command/ConsoleCommand.cc

    r10768 r10821  
    7575        this->baseFunctor_ = executor->getFunctor();
    7676
    77         for (size_t i = 0; i < MAX_FUNCTOR_ARGUMENTS; ++i)
    78             this->argumentCompleter_[i] = nullptr;
     77        for (auto & elem : this->argumentCompleter_)
     78            elem = nullptr;
    7979
    8080        this->keybindMode_ = KeybindMode::OnPress;
  • code/branches/cpp11_v2/src/libraries/core/command/Shell.cc

    r10624 r10821  
    258258        vectorize(text, '\n', &lines);
    259259
    260         for (size_t i = 0; i < lines.size(); ++i)
    261             this->addLine(lines[i], type);
     260        for (auto & line : lines)
     261            this->addLine(line, type);
    262262    }
    263263
  • code/branches/cpp11_v2/src/libraries/core/command/TclThreadList.h

    r7401 r10821  
    262262        boost::shared_lock<boost::shared_mutex> lock(this->mutex_);
    263263
    264         for (typename std::list<T>::const_iterator it = this->list_.begin(); it != this->list_.end(); ++it)
    265             if (*it == value)
     264        for (const auto & elem : this->list_)
     265            if (elem == value)
    266266                return true;
    267267
  • code/branches/cpp11_v2/src/libraries/core/command/TclThreadManager.cc

    r10775 r10821  
    551551
    552552        std::list<unsigned int> threads;
    553         for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
    554             if (it->first > 0 && it->first <= this->numInterpreterBundles_) // only list autonumbered interpreters (created with create()) - exclude the default interpreter 0 and all manually numbered interpreters)
    555                 threads.push_back(it->first);
     553        for (const auto & elem : this->interpreterBundles_)
     554            if (elem.first > 0 && elem.first <= this->numInterpreterBundles_) // only list autonumbered interpreters (created with create()) - exclude the default interpreter 0 and all manually numbered interpreters)
     555                threads.push_back(elem.first);
    556556        return threads;
    557557    }
Note: See TracChangeset for help on using the changeset viewer.