[847] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License |
---|
| 9 | * as published by the Free Software Foundation; either version 2 |
---|
| 10 | * of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Fabian 'x3n' Landau |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | * Inspiration: Executor by Benjamin Grauer |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "Executor.h" |
---|
| 30 | #include "Language.h" |
---|
| 31 | |
---|
| 32 | namespace orxonox |
---|
| 33 | { |
---|
[947] | 34 | Executor::Executor(Functor* functor, const std::string& name, AccessLevel::Level level) |
---|
[847] | 35 | { |
---|
| 36 | this->functor_ = functor; |
---|
| 37 | this->name_ = name; |
---|
[947] | 38 | this->accessLevel_ = level; |
---|
| 39 | |
---|
[847] | 40 | this->bAddedDescription_ = false; |
---|
| 41 | this->bAddedDescriptionReturnvalue_ = false; |
---|
[931] | 42 | |
---|
[847] | 43 | this->bAddedDescriptionParam_[0] = false; |
---|
| 44 | this->bAddedDescriptionParam_[1] = false; |
---|
| 45 | this->bAddedDescriptionParam_[2] = false; |
---|
| 46 | this->bAddedDescriptionParam_[3] = false; |
---|
| 47 | this->bAddedDescriptionParam_[4] = false; |
---|
[931] | 48 | |
---|
| 49 | this->bAddedDefaultValue_[0] = false; |
---|
| 50 | this->bAddedDefaultValue_[1] = false; |
---|
| 51 | this->bAddedDefaultValue_[2] = false; |
---|
| 52 | this->bAddedDefaultValue_[3] = false; |
---|
| 53 | this->bAddedDefaultValue_[4] = false; |
---|
[847] | 54 | } |
---|
| 55 | |
---|
| 56 | Executor::~Executor() |
---|
| 57 | { |
---|
[931] | 58 | delete this->functor_; |
---|
[847] | 59 | } |
---|
| 60 | |
---|
[931] | 61 | bool Executor::parse(const std::string& params, const std::string& delimiter) const |
---|
| 62 | { |
---|
[939] | 63 | EXECUTOR_PARSE(normal); |
---|
[931] | 64 | } |
---|
| 65 | |
---|
[957] | 66 | Executor& Executor::setDescription(const std::string& description) |
---|
[847] | 67 | { |
---|
| 68 | if (!this->bAddedDescription_) |
---|
| 69 | { |
---|
| 70 | this->description_ = std::string("ExecutorDescription::" + this->name_ + "::function"); |
---|
| 71 | AddLanguageEntry(this->description_, description); |
---|
| 72 | this->bAddedDescription_ = true; |
---|
| 73 | } |
---|
[957] | 74 | return (*this); |
---|
[847] | 75 | } |
---|
| 76 | |
---|
| 77 | const std::string& Executor::getDescription() const |
---|
| 78 | { |
---|
| 79 | return GetLocalisation(this->description_); |
---|
| 80 | } |
---|
| 81 | |
---|
[957] | 82 | Executor& Executor::setDescriptionParam(int param, const std::string& description) |
---|
[847] | 83 | { |
---|
[931] | 84 | if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS) |
---|
[847] | 85 | { |
---|
| 86 | if (!this->bAddedDescriptionParam_[param]) |
---|
| 87 | { |
---|
| 88 | std::string paramnumber; |
---|
| 89 | if (!Convert::ToString(¶mnumber, param)) |
---|
[957] | 90 | return (*this); |
---|
[847] | 91 | |
---|
| 92 | this->descriptionParam_[param] = std::string("ExecutorDescription::" + this->name_ + "::param" + paramnumber); |
---|
| 93 | AddLanguageEntry(this->descriptionParam_[param], description); |
---|
| 94 | this->bAddedDescriptionParam_[param] = true; |
---|
| 95 | } |
---|
| 96 | } |
---|
[957] | 97 | return (*this); |
---|
[847] | 98 | } |
---|
| 99 | |
---|
| 100 | const std::string& Executor::getDescriptionParam(int param) const |
---|
| 101 | { |
---|
[931] | 102 | if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS) |
---|
[847] | 103 | return GetLocalisation(this->descriptionParam_[param]); |
---|
| 104 | |
---|
| 105 | return this->descriptionParam_[0]; |
---|
| 106 | } |
---|
| 107 | |
---|
[957] | 108 | Executor& Executor::setDescriptionReturnvalue(const std::string& description) |
---|
[847] | 109 | { |
---|
| 110 | if (!this->bAddedDescriptionReturnvalue_) |
---|
| 111 | { |
---|
| 112 | this->descriptionReturnvalue_ = std::string("ExecutorDescription::" + this->name_ + "::returnvalue"); |
---|
| 113 | AddLanguageEntry(this->descriptionReturnvalue_, description); |
---|
| 114 | this->bAddedDescriptionReturnvalue_ = true; |
---|
| 115 | } |
---|
[957] | 116 | return (*this); |
---|
[847] | 117 | } |
---|
| 118 | |
---|
| 119 | const std::string& Executor::getDescriptionReturnvalue(int param) const |
---|
| 120 | { |
---|
| 121 | return GetLocalisation(this->descriptionReturnvalue_); |
---|
| 122 | } |
---|
[931] | 123 | |
---|
[957] | 124 | Executor& Executor::setDefaultValues(const MultiTypeMath& param1) |
---|
[931] | 125 | { |
---|
| 126 | this->defaultValue_[0] = param1; |
---|
| 127 | this->bAddedDefaultValue_[0] = true; |
---|
[957] | 128 | |
---|
| 129 | return (*this); |
---|
[931] | 130 | } |
---|
| 131 | |
---|
[957] | 132 | Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) |
---|
[931] | 133 | { |
---|
| 134 | this->defaultValue_[0] = param1; |
---|
| 135 | this->bAddedDefaultValue_[0] = true; |
---|
| 136 | this->defaultValue_[1] = param2; |
---|
| 137 | this->bAddedDefaultValue_[1] = true; |
---|
[957] | 138 | |
---|
| 139 | return (*this); |
---|
[931] | 140 | } |
---|
| 141 | |
---|
[957] | 142 | Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) |
---|
[931] | 143 | { |
---|
| 144 | this->defaultValue_[0] = param1; |
---|
| 145 | this->bAddedDefaultValue_[0] = true; |
---|
| 146 | this->defaultValue_[1] = param2; |
---|
| 147 | this->bAddedDefaultValue_[1] = true; |
---|
| 148 | this->defaultValue_[2] = param3; |
---|
| 149 | this->bAddedDefaultValue_[2] = true; |
---|
[957] | 150 | |
---|
| 151 | return (*this); |
---|
[931] | 152 | } |
---|
| 153 | |
---|
[957] | 154 | Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) |
---|
[931] | 155 | { |
---|
| 156 | this->defaultValue_[0] = param1; |
---|
| 157 | this->bAddedDefaultValue_[0] = true; |
---|
| 158 | this->defaultValue_[1] = param2; |
---|
| 159 | this->bAddedDefaultValue_[1] = true; |
---|
| 160 | this->defaultValue_[2] = param3; |
---|
| 161 | this->bAddedDefaultValue_[2] = true; |
---|
| 162 | this->defaultValue_[3] = param4; |
---|
| 163 | this->bAddedDefaultValue_[3] = true; |
---|
[957] | 164 | |
---|
| 165 | return (*this); |
---|
[931] | 166 | } |
---|
| 167 | |
---|
[957] | 168 | Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) |
---|
[931] | 169 | { |
---|
| 170 | this->defaultValue_[0] = param1; |
---|
| 171 | this->bAddedDefaultValue_[0] = true; |
---|
| 172 | this->defaultValue_[1] = param2; |
---|
| 173 | this->bAddedDefaultValue_[1] = true; |
---|
| 174 | this->defaultValue_[2] = param3; |
---|
| 175 | this->bAddedDefaultValue_[2] = true; |
---|
| 176 | this->defaultValue_[3] = param4; |
---|
| 177 | this->bAddedDefaultValue_[3] = true; |
---|
| 178 | this->defaultValue_[4] = param5; |
---|
| 179 | this->bAddedDefaultValue_[4] = true; |
---|
[957] | 180 | |
---|
| 181 | return (*this); |
---|
[931] | 182 | } |
---|
| 183 | |
---|
[957] | 184 | Executor& Executor::setDefaultValue(unsigned int index, const MultiTypeMath& param) |
---|
[931] | 185 | { |
---|
| 186 | if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) |
---|
| 187 | { |
---|
| 188 | this->defaultValue_[index] = param; |
---|
| 189 | this->bAddedDefaultValue_[index] = true; |
---|
| 190 | } |
---|
[957] | 191 | return (*this); |
---|
[931] | 192 | } |
---|
[933] | 193 | |
---|
| 194 | bool Executor::allDefaultValuesSet() const |
---|
| 195 | { |
---|
| 196 | for (unsigned int i = 0; i < this->functor_->getParamCount(); i++) |
---|
| 197 | if (!this->bAddedDefaultValue_[i]) |
---|
| 198 | return false; |
---|
| 199 | |
---|
| 200 | return true; |
---|
| 201 | } |
---|
[847] | 202 | } |
---|