[945] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1505] | 3 | * > www.orxonox.net < |
---|
[945] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[1535] | 23 | * Reto Grieder |
---|
[945] | 24 | * Co-authors: |
---|
[1535] | 25 | * Benjamin Knecht <beni_at_orxonox.net> |
---|
[945] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file ArgReader.cc |
---|
| 31 | @brief Argument Reader |
---|
| 32 | */ |
---|
| 33 | |
---|
[1062] | 34 | #include "ArgReader.h" |
---|
[1535] | 35 | #include "SubString.h" |
---|
[1766] | 36 | #include <ostream> |
---|
| 37 | #include <iostream> |
---|
[1062] | 38 | |
---|
[1766] | 39 | class FooBar |
---|
| 40 | { |
---|
| 41 | //friend class ArgReader; |
---|
| 42 | public: |
---|
| 43 | operator long long() const |
---|
| 44 | { |
---|
| 45 | return 0; |
---|
| 46 | } |
---|
| 47 | float float_; |
---|
| 48 | static FooBar& createFooBar(); |
---|
| 49 | private: |
---|
| 50 | //FooBar(); |
---|
| 51 | //FooBar(const FooBar& instance); |
---|
| 52 | //~FooBar(); |
---|
| 53 | }; |
---|
| 54 | |
---|
| 55 | inline std::ostream& operator<<(std::ostream& outstream, const FooBar& fb) |
---|
| 56 | { |
---|
| 57 | return outstream << fb.float_; |
---|
| 58 | } |
---|
| 59 | inline std::istream& operator>>(std::istream& instream, const FooBar& fb); |
---|
| 60 | //inline bool explicitConversion(const char** output, const FooBar input) |
---|
| 61 | //{ |
---|
| 62 | // return true; |
---|
| 63 | //} |
---|
| 64 | |
---|
| 65 | #include "Convert.h" |
---|
| 66 | |
---|
[1778] | 67 | //template<> |
---|
| 68 | //struct ConverterExplicit<const char*, FooBar> |
---|
| 69 | //{ |
---|
| 70 | // static bool convert(const char** output, const FooBar input) |
---|
| 71 | // { |
---|
| 72 | // return true; |
---|
| 73 | // } |
---|
| 74 | //}; |
---|
[1766] | 75 | |
---|
| 76 | #include "MultiType.h" |
---|
| 77 | |
---|
[1535] | 78 | ArgReader::ArgReader(int argc, char **argv) |
---|
[945] | 79 | { |
---|
[1535] | 80 | failure_ = false; |
---|
| 81 | errorString_ = ""; |
---|
| 82 | CmdLineArg arg; |
---|
[945] | 83 | |
---|
[1768] | 84 | //std::cout << errorString_; |
---|
| 85 | |
---|
[1777] | 86 | //const int a = conversionTests::ExplicitConversion<FooBar, const char*>::exists; |
---|
| 87 | //BOOST_STATIC_ASSERT(a == 0); |
---|
| 88 | //int val1; |
---|
| 89 | //long long val2 = 4LL;//conversion_cast<long long>(val1); |
---|
[1766] | 90 | //val2 = val1; |
---|
| 91 | //convertValue(&val2, val1); |
---|
[1778] | 92 | //convertValue(&FooBar(), val1); |
---|
[1766] | 93 | |
---|
| 94 | //using namespace1::fooBar1; |
---|
| 95 | //fooBar1(); |
---|
| 96 | //int val1; |
---|
| 97 | //char val2; |
---|
[1778] | 98 | //convertValue(&val1, val2); |
---|
[1766] | 99 | |
---|
[1777] | 100 | //std::istringstream asdf; |
---|
[1766] | 101 | //asdf >> val2; |
---|
| 102 | |
---|
[1535] | 103 | int i = 1; |
---|
| 104 | while (i < argc) |
---|
[945] | 105 | { |
---|
[1535] | 106 | if (argv[i][0] == '-' && argv[i][1] == '-') // name |
---|
| 107 | { |
---|
| 108 | if (argv[i][2] == '\0') |
---|
| 109 | { |
---|
| 110 | failure_ = true; |
---|
| 111 | errorString_ += "Expected word after \"--\".\n"; |
---|
| 112 | } |
---|
| 113 | arg.bChecked_ = false; |
---|
| 114 | arg.name_ = argv[i] + 2; |
---|
| 115 | arg.value_ = ""; |
---|
| 116 | arguments_.push_back(arg); |
---|
[945] | 117 | } |
---|
[1535] | 118 | else // value |
---|
| 119 | { |
---|
| 120 | if (arguments_.size() == 0) |
---|
| 121 | { |
---|
| 122 | failure_ = true; |
---|
| 123 | errorString_ += "Expected \"--\" in command line arguments.\n"; |
---|
| 124 | arg.bChecked_ = false; |
---|
| 125 | arg.name_ = ""; |
---|
| 126 | arg.value_ = ""; |
---|
| 127 | arguments_.push_back(arg); |
---|
| 128 | } |
---|
[945] | 129 | |
---|
[1535] | 130 | if (arguments_.back().value_ != "") |
---|
| 131 | arguments_.back().value_ += " " + std::string(argv[i]); |
---|
| 132 | else |
---|
| 133 | arguments_.back().value_ = argv[i]; |
---|
[945] | 134 | } |
---|
[1535] | 135 | ++i; |
---|
[945] | 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
[1535] | 139 | bool ArgReader::errorHandling() |
---|
[945] | 140 | { |
---|
[1535] | 141 | bool argumentsChecked = true; |
---|
| 142 | for (unsigned int i = 1; i < arguments_.size(); ++i) |
---|
| 143 | argumentsChecked &= arguments_[i].bChecked_; |
---|
[945] | 144 | |
---|
[1535] | 145 | if (!argumentsChecked) |
---|
| 146 | errorString_ += "Not all arguments could be matched.\n"; |
---|
| 147 | |
---|
| 148 | return !argumentsChecked || failure_; |
---|
[945] | 149 | } |
---|
| 150 | |
---|
[1535] | 151 | const std::string& ArgReader::getErrorString() |
---|
[945] | 152 | { |
---|
[1535] | 153 | return errorString_; |
---|
[945] | 154 | } |
---|