Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (8 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/commandline/CommandLineParser.cc

    r10542 r11071  
    4040namespace orxonox
    4141{
    42     CommandLineParser* CommandLineParser::singletonPtr_s = 0;
     42    CommandLineParser* CommandLineParser::singletonPtr_s = nullptr;
    4343
    4444    /**
     
    110110            {
    111111                // first shove all the shortcuts in a map
    112                 for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();
    113                     it != cmdLineArgs_.end(); ++it)
     112                for (const auto& mapEntry : cmdLineArgs_)
    114113                {
    115                     OrxAssert(cmdLineArgsShortcut_.find(it->second->getShortcut()) == cmdLineArgsShortcut_.end(),
     114                    OrxAssert(cmdLineArgsShortcut_.find(mapEntry.second->getShortcut()) == cmdLineArgsShortcut_.end(),
    116115                        "Cannot have two command line shortcut with the same name.");
    117                     if (!it->second->getShortcut().empty())
    118                         cmdLineArgsShortcut_[it->second->getShortcut()] = it->second;
     116                    if (!mapEntry.second->getShortcut().empty())
     117                        cmdLineArgsShortcut_[mapEntry.second->getShortcut()] = mapEntry.second;
    119118                }
    120119                bFirstTimeParse_ = false;
     
    124123            std::string shortcut;
    125124            std::string value;
    126             for (unsigned int i = 0; i < arguments.size(); ++i)
    127             {
    128                 if (arguments[i].size() != 0)
     125            for (const std::string& argument : arguments)
     126            {
     127                if (argument.size() != 0)
    129128                {
    130129                    // sure not ""
    131                     if (arguments[i][0] == '-')
     130                    if (argument[0] == '-')
    132131                    {
    133132                        // start with "-"
    134                         if (arguments[i].size() == 1)
     133                        if (argument.size() == 1)
    135134                        {
    136135                            // argument[i] is "-", probably a minus sign
    137136                            value += "- ";
    138137                        }
    139                         else if (arguments[i][1] <= 57 && arguments[i][1] >= 48)
     138                        else if (argument[1] <= 57 && argument[1] >= 48)
    140139                        {
    141140                            // negative number as a value
    142                             value += arguments[i] + ' ';
     141                            value += argument + ' ';
    143142                        }
    144143                        else
     
    161160                            }
    162161
    163                             if (arguments[i][1] == '-')
     162                            if (argument[1] == '-')
    164163                            {
    165164                                // full name argument with "--name"
    166                                 name = arguments[i].substr(2);
     165                                name = argument.substr(2);
    167166                            }
    168167                            else
    169168                            {
    170169                                // shortcut with "-s"
    171                                 shortcut = arguments[i].substr(1);
     170                                shortcut = argument.substr(1);
    172171                            }
    173172
     
    186185
    187186                        // Concatenate strings as long as there's no new argument by "-" or "--"
    188                         value += arguments[i] + ' ';
     187                        value += argument + ' ';
    189188                    }
    190189                }
     
    257256        // determine maximum name size
    258257        size_t maxNameSize = 0;
    259         for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
    260             it != inst.cmdLineArgs_.end(); ++it)
    261         {
    262             maxNameSize = std::max(it->second->getName().size(), maxNameSize);
     258        for (const auto& mapEntry : inst.cmdLineArgs_)
     259        {
     260            maxNameSize = std::max(mapEntry.second->getName().size(), maxNameSize);
    263261        }
    264262
     
    267265        infoStr << "Available options:" << endl;
    268266
    269         for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
    270             it != inst.cmdLineArgs_.end(); ++it)
    271         {
    272             if (!it->second->getShortcut().empty())
    273                 infoStr << " [-" << it->second->getShortcut() << "] ";
     267        for (const auto& mapEntry : inst.cmdLineArgs_)
     268        {
     269            if (!mapEntry.second->getShortcut().empty())
     270                infoStr << " [-" << mapEntry.second->getShortcut() << "] ";
    274271            else
    275272                infoStr << "      ";
    276             infoStr << "--" << it->second->getName() << ' ';
    277             if (it->second->getValue().isType<bool>())
     273            infoStr << "--" << mapEntry.second->getName() << ' ';
     274            if (mapEntry.second->getValue().isType<bool>())
    278275                infoStr << "    ";
    279276            else
    280277                infoStr << "ARG ";
    281278            // fill with the necessary amount of blanks
    282             infoStr << std::string(maxNameSize - it->second->getName().size(), ' ');
    283             infoStr << ": " << it->second->getInformation();
     279            infoStr << std::string(maxNameSize - mapEntry.second->getName().size(), ' ');
     280            infoStr << ": " << mapEntry.second->getInformation();
    284281            infoStr << endl;
    285282        }
Note: See TracChangeset for help on using the changeset viewer.