Changeset 1638 for code/branches/gui/src/util
- Timestamp:
- Jul 20, 2008, 7:49:26 PM (17 years ago)
- Location:
- code/branches/gui
- Files:
-
- 5 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.cc
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 */ … … 35 36 #include "SubString.h" 36 37 37 ArgReader::ArgReader(int argc, char **argv)38 std::string ArgReader::parse(int argc, char **argv) 38 39 { 39 failure_ = false; 40 errorString_ = ""; 41 CmdLineArg arg; 40 std::string errorString; 41 CmdLineArg arg; 42 int i = 1; 43 while (i < argc) 44 { 45 if (argv[i][0] == '-' && argv[i][1] == '-') // name 46 { 47 if (argv[i][2] == '\0') 48 { 49 errorString += "Expected word after \"--\".\n"; 50 } 51 arg.bChecked_ = false; 52 arg.name_ = argv[i] + 2; 53 arg.value_ = " "; 54 arguments_.push_back(arg); 55 } 56 else // value 57 { 58 if (arguments_.size() == 0) 59 { 60 errorString += "Expected \"--\" in command line arguments.\n"; 61 arg.bChecked_ = false; 62 arg.name_ = ""; 63 arg.value_ = " "; 64 arguments_.push_back(arg); 65 } 42 66 43 int i = 1; 44 while (i < argc) 45 { 46 if (argv[i][0] == '-' && argv[i][1] == '-') // name 47 { 48 if (argv[i][2] == '\0') 49 { 50 failure_ = true; 51 errorString_ += "Expected word after \"--\".\n"; 52 } 53 arg.bChecked_ = false; 54 arg.name_ = argv[i] + 2; 55 arg.value_ = ""; 56 arguments_.push_back(arg); 67 if (arguments_.back().value_ != " ") 68 arguments_.back().value_ += " " + std::string(argv[i]); 69 else 70 arguments_.back().value_ = argv[i]; 71 } 72 ++i; 57 73 } 58 else // value 59 { 60 if (arguments_.size() == 0) 61 { 62 failure_ = true; 63 errorString_ += "Expected \"--\" in command line arguments.\n"; 64 arg.bChecked_ = false; 65 arg.name_ = ""; 66 arg.value_ = ""; 67 arguments_.push_back(arg); 68 } 69 70 if (arguments_.back().value_ != "") 71 arguments_.back().value_ += " " + std::string(argv[i]); 72 else 73 arguments_.back().value_ = argv[i]; 74 } 75 ++i; 76 } 74 return errorString; 77 75 } 78 76 79 bool ArgReader::errorHandling()77 const std::string& ArgReader::getArgument(const std::string& option) 80 78 { 81 bool argumentsChecked = true; 82 for (unsigned int i = 1; i < arguments_.size(); ++i) 83 argumentsChecked &= arguments_[i].bChecked_; 84 85 if (!argumentsChecked) 86 errorString_ += "Not all arguments could be matched.\n"; 87 88 return !argumentsChecked || failure_; 79 unsigned int iArg = 0; 80 while (iArg < arguments_.size()) 81 { 82 if (arguments_[iArg].name_ == option) 83 { 84 arguments_[iArg].bChecked_ = true; 85 return arguments_[iArg].value_; 86 } 87 ++iArg; 88 } 89 return blankString; 89 90 } 90 91 91 const std::string& ArgReader::getErrorString()92 bool ArgReader::allChecked() 92 93 { 93 return errorString_; 94 bool argumentsChecked = true; 95 for (unsigned int i = 1; i < arguments_.size(); ++i) 96 argumentsChecked &= arguments_[i].bChecked_; 97 98 return argumentsChecked; 94 99 } -
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__ */ -
code/branches/gui/src/util/OrxonoxPlatform.h
r1505 r1638 103 103 #else 104 104 # define ORXONOX_ARCH_TYPE ORXONOX_ARCHITECTURE_32 105 #endif 106 107 // try to define function information 108 #ifndef __FUNCTIONNAME__ 109 # if ORXONOX_COMPILER == ORXONOX_COMPILER_BORL 110 # define __FUNCTIONNAME__ __FUNC__ 111 # elif ORXONOX_COMPILER == ORXONOX_COMPILER_GNUC 112 # define __FUNCTIONNAME__ __PRETTY_FUNCTION__ 113 # elif ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 114 # define __FUNCTIONNAME__ __FUNCTION__ 115 # else 116 # define __FUNCTIONNAME__ 117 # endif 105 118 #endif 106 119 … … 265 278 // generated code from nvparse etc). I doubt very much that these calls 266 279 // will ever be actually removed from VC anyway, it would break too much code. 267 //# 280 //# pragma warning( disable: 4996) 268 281 269 282 // disable: "conditional expression constant", always occurs on -
code/branches/gui/src/util/Sleep.h
r1505 r1638 29 29 /** 30 30 @file Sleep.h 31 @brief Macros for using sleep() and usleep() under windows31 @brief Functions for using sleep() and usleep() under windows 32 32 */ 33 33
Note: See TracChangeset
for help on using the changeset viewer.