Changeset 11071 for code/trunk/src/libraries/core/commandline
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/commandline/CommandLineIncludes.h
r10535 r11071 64 64 ~StaticallyInitializedCommandLineArgument() { delete argument_; } 65 65 66 virtual void load() 66 virtual void load() override 67 67 { CommandLineParser::addArgument(this->argument_); } 68 68 69 virtual void unload() 69 virtual void unload() override 70 70 { CommandLineParser::removeArgument(this->argument_); } 71 71 -
code/trunk/src/libraries/core/commandline/CommandLineParser.cc
r10542 r11071 40 40 namespace orxonox 41 41 { 42 CommandLineParser* CommandLineParser::singletonPtr_s = 0;42 CommandLineParser* CommandLineParser::singletonPtr_s = nullptr; 43 43 44 44 /** … … 110 110 { 111 111 // 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_) 114 113 { 115 OrxAssert(cmdLineArgsShortcut_.find( it->second->getShortcut()) == cmdLineArgsShortcut_.end(),114 OrxAssert(cmdLineArgsShortcut_.find(mapEntry.second->getShortcut()) == cmdLineArgsShortcut_.end(), 116 115 "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; 119 118 } 120 119 bFirstTimeParse_ = false; … … 124 123 std::string shortcut; 125 124 std::string value; 126 for ( unsigned int i = 0; i < arguments.size(); ++i)127 { 128 if (argument s[i].size() != 0)125 for (const std::string& argument : arguments) 126 { 127 if (argument.size() != 0) 129 128 { 130 129 // sure not "" 131 if (argument s[i][0] == '-')130 if (argument[0] == '-') 132 131 { 133 132 // start with "-" 134 if (argument s[i].size() == 1)133 if (argument.size() == 1) 135 134 { 136 135 // argument[i] is "-", probably a minus sign 137 136 value += "- "; 138 137 } 139 else if (argument s[i][1] <= 57 && arguments[i][1] >= 48)138 else if (argument[1] <= 57 && argument[1] >= 48) 140 139 { 141 140 // negative number as a value 142 value += argument s[i]+ ' ';141 value += argument + ' '; 143 142 } 144 143 else … … 161 160 } 162 161 163 if (argument s[i][1] == '-')162 if (argument[1] == '-') 164 163 { 165 164 // full name argument with "--name" 166 name = argument s[i].substr(2);165 name = argument.substr(2); 167 166 } 168 167 else 169 168 { 170 169 // shortcut with "-s" 171 shortcut = argument s[i].substr(1);170 shortcut = argument.substr(1); 172 171 } 173 172 … … 186 185 187 186 // Concatenate strings as long as there's no new argument by "-" or "--" 188 value += argument s[i]+ ' ';187 value += argument + ' '; 189 188 } 190 189 } … … 257 256 // determine maximum name size 258 257 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); 263 261 } 264 262 … … 267 265 infoStr << "Available options:" << endl; 268 266 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() << "] "; 274 271 else 275 272 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>()) 278 275 infoStr << " "; 279 276 else 280 277 infoStr << "ARG "; 281 278 // 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(); 284 281 infoStr << endl; 285 282 } -
code/trunk/src/libraries/core/commandline/CommandLineParser.h
r10542 r11071 107 107 108 108 private: 109 //! Undefined copy constructor 110 CommandLineArgument(const CommandLineArgument& instance); 109 // non-copyable: 110 CommandLineArgument(const CommandLineArgument&) = delete; 111 CommandLineArgument& operator=(const CommandLineArgument&) = delete; 111 112 112 113 //! Parses the value string of a command line argument.
Note: See TracChangeset
for help on using the changeset viewer.