Changeset 8729 for code/trunk/src/libraries/core/CommandLineParser.h
- Timestamp:
- Jul 4, 2011, 2:47:44 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
code/trunk/src/libraries/core/CommandLineParser.h
r7401 r8729 51 51 #define SetCommandLineArgument(name, defaultValue) \ 52 52 orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \ 53 = orxonox::CommandLineParser::addArgument(#name, defaultValue, false) 54 #define SetCommandLineOnlyArgument(name, defaultValue) \ 55 orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \ 56 = orxonox::CommandLineParser::addArgument(#name, defaultValue, true) 53 = orxonox::CommandLineParser::addArgument(#name, defaultValue) 57 54 #define SetCommandLineSwitch(name) \ 58 55 orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \ 59 = orxonox::CommandLineParser::addArgument(#name, false, false) 60 #define SetCommandLineOnlySwitch(name) \ 61 orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \ 62 = orxonox::CommandLineParser::addArgument(#name, false, true) 63 56 = orxonox::CommandLineParser::addArgument(#name, false) 64 57 65 58 namespace orxonox … … 106 99 107 100 //! Returns the actual value of the argument. Can be equal to default value. 108 MultiTypegetValue() const { return value_; }101 const MultiType& getValue() const { return value_; } 109 102 //! Returns the given default value as type T. 110 MultiTypegetDefaultValue() const { return defaultValue_; }103 const MultiType& getDefaultValue() const { return defaultValue_; } 111 104 112 105 private: 113 106 //! Constructor initialises both value_ and defaultValue_ with defaultValue. 114 CommandLineArgument(const std::string& name, const MultiType& defaultValue , bool bCommandLineOnly)107 CommandLineArgument(const std::string& name, const MultiType& defaultValue) 115 108 : bHasDefaultValue_(true) 116 109 , name_(name) 117 110 , value_(defaultValue) 118 111 , defaultValue_(defaultValue) 119 , bCommandLineOnly_(bCommandLineOnly)120 112 { } 121 113 … … 125 117 126 118 //! Parses the value string of a command line argument. 127 void parse(const std::string& value , bool bParsingFile);119 void parse(const std::string& value); 128 120 129 121 //! Tells whether the value has been changed by the command line. … … 137 129 MultiType value_; //!< The actual value 138 130 MultiType defaultValue_; //!< Default value. Should not be changed. 139 bool bCommandLineOnly_; //!< Whether you cannot specify the value in a text file140 131 }; 141 132 … … 155 146 156 147 //! Parse redirection to internal member method. 157 static void parse CommandLine(const std::string& cmdLine) { _getInstance()._parseCommandLine(cmdLine); }158 static void parseFile() { _getInstance()._parseFile(); }148 static void parse(const std::string& cmdLine) 149 { _getInstance()._parse(cmdLine); } 159 150 160 151 static std::string getUsageInformation(); … … 165 156 static void getValue(const std::string& name, T* value) 166 157 { *value = (T)(getArgument(name)->getValue()); } 167 static MultiTypegetValue(const std::string& name)158 static const MultiType& getValue(const std::string& name) 168 159 { return getArgument(name)->getValue(); } 169 160 template <class T> 170 static CommandLineArgument& addArgument(const std::string& name, T defaultValue , bool bCommandLineOnly);161 static CommandLineArgument& addArgument(const std::string& name, T defaultValue); 171 162 172 163 static bool existsArgument(const std::string& name) … … 189 180 static CommandLineParser& _getInstance(); 190 181 191 void _parseCommandLine(const std::string& cmdLine); 192 void _parseFile(); 193 void _parse(const std::vector<std::string>& arguments, bool bParsingFile); 194 void checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile); 195 void checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile); 182 void _parse(const std::string& cmdLine); 183 void checkFullArgument(const std::string& name, const std::string& value); 184 void checkShortcut(const std::string& shortcut, const std::string& value); 196 185 197 186 /** … … 222 211 @param defaultValue 223 212 Default value that is used when argument was not given. 224 @param bCommandLineOnly225 Parsing a file or the command line itself226 213 */ 227 214 template <class T> 228 CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue , bool bCommandLineOnly)215 CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue) 229 216 { 230 217 OrxAssert(!_getInstance().existsArgument(name), … … 234 221 << "Please use SetCommandLineSwitch and adjust your argument: " << name); 235 222 236 return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue , bCommandLineOnly));223 return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue)); 237 224 } 238 225 }
Note: See TracChangeset
for help on using the changeset viewer.