Changeset 10542 for code/branches/core7/src/libraries/core/commandline
- Timestamp:
- Jun 7, 2015, 2:16:55 PM (10 years ago)
- Location:
- code/branches/core7/src/libraries/core/commandline
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/commandline/CommandLineParser.cc
r10520 r10542 40 40 namespace orxonox 41 41 { 42 CommandLineParser* CommandLineParser::singletonPtr_s = 0; 43 42 44 /** 43 45 @brief … … 85 87 CommandLineParser::~CommandLineParser() 86 88 { 87 }88 89 /**90 @brief91 Returns a unique instance (Meyers Singleton).92 */93 CommandLineParser& CommandLineParser::_getInstance()94 {95 static CommandLineParser instance;96 return instance;97 89 } 98 90 … … 260 252 std::string CommandLineParser::getUsageInformation() 261 253 { 262 CommandLineParser& inst = _getInstance();254 CommandLineParser& inst = getInstance(); 263 255 std::ostringstream infoStr; 264 256 … … 313 305 const CommandLineArgument* CommandLineParser::getArgument(const std::string& name) 314 306 { 315 std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name);316 if (it == _getInstance().cmdLineArgs_.end())307 std::map<std::string, CommandLineArgument*>::const_iterator it = getInstance().cmdLineArgs_.find(name); 308 if (it == getInstance().cmdLineArgs_.end()) 317 309 { 318 310 ThrowException(Argument, "Could find command line argument '" + name + "'."); … … 331 323 void CommandLineParser::addArgument(CommandLineArgument* argument) 332 324 { 333 OrxAssert(! _getInstance().existsArgument(argument->getName()),325 OrxAssert(!getInstance().existsArgument(argument->getName()), 334 326 "Cannot add a command line argument with name '" + argument->getName() + "' twice."); 335 327 OrxAssert(!argument->getDefaultValue().isType<bool>() || argument->getDefaultValue().get<bool>() != true, … … 337 329 << "Please use SetCommandLineSwitch and adjust your argument: " << argument->getName()); 338 330 339 _getInstance().cmdLineArgs_[argument->getName()] = argument;331 getInstance().cmdLineArgs_[argument->getName()] = argument; 340 332 } 341 333 … … 345 337 void CommandLineParser::removeArgument(CommandLineArgument* argument) 346 338 { 347 _getInstance().cmdLineArgs_.erase(argument->getName());339 getInstance().cmdLineArgs_.erase(argument->getName()); 348 340 } 349 341 } -
code/branches/core7/src/libraries/core/commandline/CommandLineParser.h
r10520 r10542 48 48 #include "util/OrxAssert.h" 49 49 #include "util/MultiType.h" 50 #include "util/Singleton.h" 50 51 51 52 namespace orxonox … … 134 135 CommandLineArgument 135 136 */ 136 class _CoreExport CommandLineParser 137 class _CoreExport CommandLineParser : public Singleton<CommandLineParser> 137 138 { 139 friend class Singleton<CommandLineParser>; 140 138 141 public: 142 //! Constructor initialises bFirstTimeParse_ with true. 143 CommandLineParser() : bFirstTimeParse_(true) { } 144 ~CommandLineParser(); 139 145 140 146 //! Parse redirection to internal member method. 141 147 static void parse(const std::string& cmdLine) 142 { _getInstance()._parse(cmdLine); }148 { getInstance()._parse(cmdLine); } 143 149 144 150 static std::string getUsageInformation(); … … 157 163 static bool existsArgument(const std::string& name) 158 164 { 159 std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name);160 return !(it == _getInstance().cmdLineArgs_.end());165 std::map<std::string, CommandLineArgument*>::const_iterator it = getInstance().cmdLineArgs_.find(name); 166 return !(it == getInstance().cmdLineArgs_.end()); 161 167 } 162 168 … … 164 170 165 171 private: 166 //! Constructor initialises bFirstTimeParse_ with true.167 CommandLineParser() : bFirstTimeParse_(true) { }168 172 //! Undefined copy constructor 169 173 CommandLineParser(const CommandLineParser& instance); 170 ~CommandLineParser();171 172 static CommandLineParser& _getInstance();173 174 174 175 void _parse(const std::string& cmdLine); … … 187 188 //! Search map by shortcut for the arguments. 188 189 std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_; 190 191 static CommandLineParser* singletonPtr_s; 189 192 }; 190 193
Note: See TracChangeset
for help on using the changeset viewer.