Changeset 1638 for code/branches/gui/src/util/ArgReader.cc
- 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.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 }
Note: See TracChangeset
for help on using the changeset viewer.