[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 | |
---|
| 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 | }; |
---|
| 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 | |
---|
| 86 | int a = conversionTests::ImplicitConversion<FooBar, const char*>::exists; |
---|
[1766] | 87 | int val1; |
---|
| 88 | long long val2 = conversion_cast<long long>(val1); |
---|
| 89 | //val2 = val1; |
---|
| 90 | //convertValue(&val2, val1); |
---|
| 91 | //explicitConversion(&FooBar(), val1); |
---|
| 92 | |
---|
| 93 | //using namespace1::fooBar1; |
---|
| 94 | //fooBar1(); |
---|
| 95 | //int val1; |
---|
| 96 | //char val2; |
---|
| 97 | //explicitConversion(&val1, val2); |
---|
| 98 | |
---|
| 99 | std::istringstream asdf; |
---|
| 100 | //asdf >> val2; |
---|
| 101 | |
---|
[1535] | 102 | int i = 1; |
---|
| 103 | while (i < argc) |
---|
[945] | 104 | { |
---|
[1535] | 105 | if (argv[i][0] == '-' && argv[i][1] == '-') // name |
---|
| 106 | { |
---|
| 107 | if (argv[i][2] == '\0') |
---|
| 108 | { |
---|
| 109 | failure_ = true; |
---|
| 110 | errorString_ += "Expected word after \"--\".\n"; |
---|
| 111 | } |
---|
| 112 | arg.bChecked_ = false; |
---|
| 113 | arg.name_ = argv[i] + 2; |
---|
| 114 | arg.value_ = ""; |
---|
| 115 | arguments_.push_back(arg); |
---|
[945] | 116 | } |
---|
[1535] | 117 | else // value |
---|
| 118 | { |
---|
| 119 | if (arguments_.size() == 0) |
---|
| 120 | { |
---|
| 121 | failure_ = true; |
---|
| 122 | errorString_ += "Expected \"--\" in command line arguments.\n"; |
---|
| 123 | arg.bChecked_ = false; |
---|
| 124 | arg.name_ = ""; |
---|
| 125 | arg.value_ = ""; |
---|
| 126 | arguments_.push_back(arg); |
---|
| 127 | } |
---|
[945] | 128 | |
---|
[1535] | 129 | if (arguments_.back().value_ != "") |
---|
| 130 | arguments_.back().value_ += " " + std::string(argv[i]); |
---|
| 131 | else |
---|
| 132 | arguments_.back().value_ = argv[i]; |
---|
[945] | 133 | } |
---|
[1535] | 134 | ++i; |
---|
[945] | 135 | } |
---|
| 136 | } |
---|
| 137 | |
---|
[1535] | 138 | bool ArgReader::errorHandling() |
---|
[945] | 139 | { |
---|
[1535] | 140 | bool argumentsChecked = true; |
---|
| 141 | for (unsigned int i = 1; i < arguments_.size(); ++i) |
---|
| 142 | argumentsChecked &= arguments_[i].bChecked_; |
---|
[945] | 143 | |
---|
[1535] | 144 | if (!argumentsChecked) |
---|
| 145 | errorString_ += "Not all arguments could be matched.\n"; |
---|
| 146 | |
---|
| 147 | return !argumentsChecked || failure_; |
---|
[945] | 148 | } |
---|
| 149 | |
---|
[1535] | 150 | const std::string& ArgReader::getErrorString() |
---|
[945] | 151 | { |
---|
[1535] | 152 | return errorString_; |
---|
[945] | 153 | } |
---|