Changeset 1052 for code/trunk/src/orxonox/core/Executor.cc
- Timestamp:
- Apr 14, 2008, 3:42:49 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/core/Executor.cc
r871 r1052 29 29 #include "Executor.h" 30 30 #include "Language.h" 31 #include "util/ String.h"31 #include "util/Math.h" 32 32 33 33 namespace orxonox 34 34 { 35 Executor::Executor(Functor* functor, const std::string& name )35 Executor::Executor(Functor* functor, const std::string& name, AccessLevel::Level level) 36 36 { 37 37 this->functor_ = functor; 38 38 this->name_ = name; 39 this->accessLevel_ = level; 40 39 41 this->bAddedDescription_ = false; 40 42 this->bAddedDescriptionReturnvalue_ = false; 43 41 44 this->bAddedDescriptionParam_[0] = false; 42 45 this->bAddedDescriptionParam_[1] = false; … … 44 47 this->bAddedDescriptionParam_[3] = false; 45 48 this->bAddedDescriptionParam_[4] = false; 49 50 this->bAddedDefaultValue_[0] = false; 51 this->bAddedDefaultValue_[1] = false; 52 this->bAddedDefaultValue_[2] = false; 53 this->bAddedDefaultValue_[3] = false; 54 this->bAddedDefaultValue_[4] = false; 46 55 } 47 56 48 57 Executor::~Executor() 49 58 { 50 } 51 52 void Executor::setName(const std::string name) 53 { 54 this->name_ = name; 55 } 56 57 const std::string& Executor::getName() const 58 { 59 return this->name_; 60 } 61 62 void Executor::description(const std::string& description) 59 delete this->functor_; 60 } 61 62 bool Executor::parse(const std::string& params, const std::string& delimiter) const 63 { 64 EXECUTOR_PARSE(normal); 65 } 66 67 bool Executor::evaluate(const std::string& params, MultiTypeMath param[5], const std::string& delimiter) const 68 { 69 unsigned int paramCount = this->functor_->getParamCount(); 70 71 if (paramCount == 1) 72 { 73 // only one param: check if there are params given, otherwise try to use default values 74 std::string temp = getStripped(params); 75 if ((temp != "") && (temp.size() != 0)) 76 { 77 param[0] = params; 78 this->functor_->evaluateParam(0, param[0]); 79 return true; 80 } 81 else if (this->bAddedDefaultValue_[0]) 82 { 83 param[0] = this->defaultValue_[0]; 84 this->functor_->evaluateParam(0, param[0]); 85 return true; 86 } 87 return false; 88 } 89 else 90 { 91 // more than one param 92 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); 93 94 // if there are not enough params given, check if there are default values 95 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) 96 if (!this->bAddedDefaultValue_[i]) 97 return false; 98 99 // assign all given arguments to the multitypes 100 for (unsigned int i = 0; i < min(tokens.size(), (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++) 101 param[i] = tokens[i]; 102 103 // fill the remaining multitypes with default values 104 for (unsigned int i = tokens.size(); i < min(paramCount, (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++) 105 param[i] = this->defaultValue_[i]; 106 107 // evaluate the param types through the functor 108 for (unsigned int i = 0; i < min(paramCount, (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++) 109 this->functor_->evaluateParam(i, param[i]); 110 111 return true; 112 } 113 } 114 115 Executor& Executor::setDescription(const std::string& description) 63 116 { 64 117 if (!this->bAddedDescription_) … … 68 121 this->bAddedDescription_ = true; 69 122 } 123 return (*this); 70 124 } 71 125 … … 75 129 } 76 130 77 void Executor::descriptionParam(int param, const std::string& description)78 { 79 if (param > 0 && param <= 5)131 Executor& Executor::setDescriptionParam(int param, const std::string& description) 132 { 133 if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS) 80 134 { 81 135 if (!this->bAddedDescriptionParam_[param]) … … 83 137 std::string paramnumber; 84 138 if (!Convert::ToString(¶mnumber, param)) 85 return ;139 return (*this); 86 140 87 141 this->descriptionParam_[param] = std::string("ExecutorDescription::" + this->name_ + "::param" + paramnumber); … … 90 144 } 91 145 } 146 return (*this); 92 147 } 93 148 94 149 const std::string& Executor::getDescriptionParam(int param) const 95 150 { 96 if (param > 0 && param <= 5) 97 { 151 if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS) 98 152 return GetLocalisation(this->descriptionParam_[param]); 99 }100 153 101 154 return this->descriptionParam_[0]; 102 155 } 103 156 104 void Executor::descriptionReturnvalue(const std::string& description)157 Executor& Executor::setDescriptionReturnvalue(const std::string& description) 105 158 { 106 159 if (!this->bAddedDescriptionReturnvalue_) … … 110 163 this->bAddedDescriptionReturnvalue_ = true; 111 164 } 165 return (*this); 112 166 } 113 167 … … 116 170 return GetLocalisation(this->descriptionReturnvalue_); 117 171 } 172 173 Executor& Executor::setDefaultValues(const MultiTypeMath& param1) 174 { 175 this->defaultValue_[0] = param1; 176 this->bAddedDefaultValue_[0] = true; 177 178 return (*this); 179 } 180 181 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) 182 { 183 this->defaultValue_[0] = param1; 184 this->bAddedDefaultValue_[0] = true; 185 this->defaultValue_[1] = param2; 186 this->bAddedDefaultValue_[1] = true; 187 188 return (*this); 189 } 190 191 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) 192 { 193 this->defaultValue_[0] = param1; 194 this->bAddedDefaultValue_[0] = true; 195 this->defaultValue_[1] = param2; 196 this->bAddedDefaultValue_[1] = true; 197 this->defaultValue_[2] = param3; 198 this->bAddedDefaultValue_[2] = true; 199 200 return (*this); 201 } 202 203 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) 204 { 205 this->defaultValue_[0] = param1; 206 this->bAddedDefaultValue_[0] = true; 207 this->defaultValue_[1] = param2; 208 this->bAddedDefaultValue_[1] = true; 209 this->defaultValue_[2] = param3; 210 this->bAddedDefaultValue_[2] = true; 211 this->defaultValue_[3] = param4; 212 this->bAddedDefaultValue_[3] = true; 213 214 return (*this); 215 } 216 217 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) 218 { 219 this->defaultValue_[0] = param1; 220 this->bAddedDefaultValue_[0] = true; 221 this->defaultValue_[1] = param2; 222 this->bAddedDefaultValue_[1] = true; 223 this->defaultValue_[2] = param3; 224 this->bAddedDefaultValue_[2] = true; 225 this->defaultValue_[3] = param4; 226 this->bAddedDefaultValue_[3] = true; 227 this->defaultValue_[4] = param5; 228 this->bAddedDefaultValue_[4] = true; 229 230 return (*this); 231 } 232 233 Executor& Executor::setDefaultValue(unsigned int index, const MultiTypeMath& param) 234 { 235 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) 236 { 237 this->defaultValue_[index] = param; 238 this->bAddedDefaultValue_[index] = true; 239 } 240 return (*this); 241 } 242 243 bool Executor::allDefaultValuesSet() const 244 { 245 for (unsigned int i = 0; i < this->functor_->getParamCount(); i++) 246 if (!this->bAddedDefaultValue_[i]) 247 return false; 248 249 return true; 250 } 118 251 }
Note: See TracChangeset
for help on using the changeset viewer.