Changeset 1638 for code/branches/gui/src/util/ArgReader.h
- Timestamp:
- Jul 20, 2008, 7:49:26 PM (16 years ago)
- Location:
- code/branches/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui
-
Property
svn:mergeinfo
set to
/code/branches/input merged eligible
-
Property
svn:mergeinfo
set to
-
code/branches/gui/src/util/ArgReader.h
r1535 r1638 22 22 * Author: 23 23 * Reto Grieder 24 * Benjamin Knecht <beni_at_orxonox.net> 24 25 * Co-authors: 25 * Benjamin Knecht <beni_at_orxonox.net>26 * ... 26 27 * 27 28 */ … … 42 43 #include "Convert.h" 43 44 44 struct _UtilExport CmdLineArg45 {46 std::string name_;47 std::string value_;48 bool bChecked_;49 };50 45 51 46 class _UtilExport ArgReader 52 47 { 53 public: 54 ArgReader(int argc, char **argv); 55 template <class T> 56 void checkArgument(std::string option, T* value, bool must = false); 57 bool errorHandling(); 58 const std::string& getErrorString(); 48 public: 49 ArgReader() { } 50 std::string parse(int argc, char **argv); 51 const std::string& getArgument(const std::string& option); 52 bool allChecked(); 59 53 60 private: 54 private: 55 struct CmdLineArg 56 { 57 std::string name_; 58 std::string value_; 59 bool bChecked_; 60 }; 61 61 62 std::vector<CmdLineArg> arguments_; 62 bool failure_;63 std::string errorString_;64 63 }; 65 64 66 template <class T>67 void ArgReader::checkArgument(std::string option, T* value, bool must)68 {69 unsigned int iArg = 0;70 while (iArg < arguments_.size())71 {72 if (arguments_[iArg].name_ == option)73 break;74 ++iArg;75 }76 if (iArg == arguments_.size())77 {78 if (must)79 {80 failure_ = true;81 errorString_ += "Cannot find mandatory argument \"" + option + "\"\n";82 return;83 }84 else85 return;86 }87 88 arguments_[iArg].bChecked_ = true;89 90 if (!convertValue(value, arguments_[iArg].value_))91 {92 failure_ = true;93 errorString_ += "Cannot convert argument value for option \"" + option + "\"\n";94 }95 }96 97 template <>98 void ArgReader::checkArgument(std::string option, bool* value, bool must)99 {100 // for type bool, only check whether the option was set or not101 unsigned int iArg = 0;102 while (iArg < arguments_.size())103 {104 if (arguments_[iArg].name_ == option)105 {106 arguments_[iArg].bChecked_ = true;107 *value = true;108 break;109 }110 ++iArg;111 }112 if (iArg == arguments_.size())113 *value = false;114 }115 116 65 #endif /* _ArgReader_H__ */
Note: See TracChangeset
for help on using the changeset viewer.