Changeset 2003 for code/branches/objecthierarchy/src/core/CommandLine.cc
- Timestamp:
- Oct 24, 2008, 12:43:13 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/core/CommandLine.cc
r1755 r2003 35 35 /** 36 36 @brief 37 Parses a value string for a command line argument. 38 It simply uses convertValue(Output, Input) to do that. 39 Bools are treated specially. That is necessary 40 so that you can have simple command line switches. 41 */ 42 void CommandLineArgument::parse(const std::string& value) 43 { 44 if (value_.getType() == MT_bool) 45 { 46 // simulate command line switch 47 bool temp; 48 if (convertValue(&temp, value)) 49 { 50 this->bHasDefaultValue_ = false; 51 this->value_ = temp; 52 } 53 else if (value == "") 54 { 55 this->bHasDefaultValue_ = false; 56 this->value_ = true; 57 } 58 else 59 { 60 ThrowException(Argument, "Could not read command line argument '" + getName() + "'."); 61 } 62 } 63 else 64 { 65 if (!value_.setValue(value)) 66 { 67 value_.setValue(defaultValue_); 68 ThrowException(Argument, "Could not read command line argument '" + getName() + "'."); 69 } 70 else 71 this->bHasDefaultValue_ = false; 72 } 73 } 74 75 76 /** 77 @brief 37 78 Destructor destroys all CommandLineArguments with it. 38 79 */ 39 80 CommandLine::~CommandLine() 40 81 { 41 for (std::map<std::string, BaseCommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();82 for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin(); 42 83 it != cmdLineArgs_.end(); ++it) 43 84 { … … 73 114 { 74 115 // first shove all the shortcuts in a map 75 for (std::map<std::string, BaseCommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();116 for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin(); 76 117 it != cmdLineArgs_.end(); ++it) 77 118 { … … 178 219 void CommandLine::checkFullArgument(const std::string& name, const std::string& value) 179 220 { 180 std::map<std::string, BaseCommandLineArgument*>::const_iterator it = cmdLineArgs_.find(name);221 std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.find(name); 181 222 if (it == cmdLineArgs_.end()) 182 223 ThrowException(Argument, "Command line argument '" + name + "' does not exist."); … … 195 236 void CommandLine::checkShortcut(const std::string& shortcut, const std::string& value) 196 237 { 197 std::map<std::string, BaseCommandLineArgument*>::const_iterator it = cmdLineArgsShortcut_.find(shortcut);238 std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgsShortcut_.find(shortcut); 198 239 if (it == cmdLineArgsShortcut_.end()) 199 240 ThrowException(Argument, "Command line shortcut '" + shortcut + "' does not exist."); … … 206 247 CommandLine* inst = &_getInstance(); 207 248 std::string infoStr; 208 for (std::map<std::string, BaseCommandLineArgument*>::const_iterator it = inst->cmdLineArgs_.begin();249 for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst->cmdLineArgs_.begin(); 209 250 it != inst->cmdLineArgs_.end(); ++it) 210 251 { … … 214 255 } 215 256 257 /** 258 @brief 259 Retrieves a CommandLineArgument. 260 The method throws an exception if 'name' was not found or the value could not be converted. 261 @note 262 You shold of course not call this method before the command line has been parsed. 263 */ 264 const CommandLineArgument* CommandLine::getArgument(const std::string& name) 265 { 266 std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name); 267 if (it == _getInstance().cmdLineArgs_.end()) 268 { 269 ThrowException(Argument, "Could find command line argument '" + name + "'."); 270 } 271 else 272 { 273 return it->second; 274 } 275 } 216 276 }
Note: See TracChangeset
for help on using the changeset viewer.