Changeset 967
- Timestamp:
- Mar 31, 2008, 12:25:09 AM (17 years ago)
- Location:
- code/branches/core2/src/orxonox/core
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/CommandExecutor.cc
r965 r967 63 63 this->errorMessage_ = ""; 64 64 this->state_ = CS_Uninitialized; 65 66 this->bEvaluatedParams_ = false; 67 this->evaluatedExecutor_ = 0; 65 68 } 66 69 … … 113 116 return false; 114 117 } 118 } 119 120 void CommandEvaluation::evaluateParams() 121 { 122 this->bEvaluatedParams_ = false; 123 this->evaluatedExecutor_ = 0; 124 125 for (unsigned int i = 0; i < MAX_FUNCTOR_ARGUMENTS; i++) 126 this->param_[i] = MT_null; 127 128 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished) 129 { 130 if (this->shortcut_ != 0) 131 { 132 if (this->shortcut_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " ")) 133 { 134 this->bEvaluatedParams_ = true; 135 this->evaluatedExecutor_ = this->shortcut_; 136 } 137 } 138 } 139 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished) 140 { 141 if (this->function_ != 0) 142 { 143 if (this->function_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " ")) 144 { 145 this->bEvaluatedParams_ = true; 146 this->evaluatedExecutor_ = this->function_; 147 } 148 } 149 } 150 } 151 152 void CommandEvaluation::setEvaluatedParameter(unsigned int index, MultiTypeMath param) 153 { 154 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) 155 this->param_[index] = param; 156 } 157 158 MultiTypeMath CommandEvaluation::getEvaluatedParameter(unsigned int index) const 159 { 160 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) 161 return this->param_[index]; 162 163 return MT_null; 115 164 } 116 165 … … 178 227 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 179 228 229 if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_ != 0) 230 { 231 (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]); 232 } 233 180 234 switch (evaluation.state_) 181 235 { … … 404 458 { 405 459 CommandExecutor::parse(command, true); 460 CommandExecutor::getEvaluation().evaluateParams(); 406 461 return CommandExecutor::getEvaluation(); 407 462 } -
code/branches/core2/src/orxonox/core/CommandExecutor.h
r965 r967 77 77 78 78 inline void setAdditionalParameter(const std::string& param) 79 { this->additionalParameter_ = param; }79 { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; } 80 80 inline std::string getAdditionalParameter() const 81 81 { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; } 82 83 void setEvaluatedParameter(unsigned int index, MultiTypeMath param); 84 MultiTypeMath getEvaluatedParameter(unsigned int index) const; 85 86 void evaluateParams(); 82 87 83 88 private: … … 102 107 std::string errorMessage_; 103 108 CommandState state_; 109 110 bool bEvaluatedParams_; 111 MultiTypeMath param_[5]; 112 ExecutorStatic* evaluatedExecutor_; 104 113 }; 105 114 -
code/branches/core2/src/orxonox/core/Executor.cc
r957 r967 29 29 #include "Executor.h" 30 30 #include "Language.h" 31 #include "util/Math.h" 31 32 32 33 namespace orxonox … … 62 63 { 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, '\\', '"', '(', ')', '\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 } 64 113 } 65 114 -
code/branches/core2/src/orxonox/core/Executor.h
r957 r967 89 89 MultiTypeMath param[paramCount]; \ 90 90 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; \ 91 for (unsigned int i = 0; i < tokens.size() ; i++) \91 for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) \ 92 92 { \ 93 93 param[i] = tokens[i]; \ … … 165 165 bool parse(const std::string& params, const std::string& delimiter = " ") const; 166 166 167 bool evaluate(const std::string& params, MultiTypeMath param[5], const std::string& delimiter = " ") const; 168 167 169 Executor& setDescription(const std::string& description); 168 170 const std::string& getDescription() const; -
code/branches/core2/src/orxonox/core/Functor.h
r955 r967 103 103 std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; } 104 104 std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; } 105 106 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const = 0; 105 107 106 108 protected: … … 278 280 279 281 282 #define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams 283 #define FUNCTOR_EVALUATE_PARAM0 284 #define FUNCTOR_EVALUATE_PARAM1 \ 285 if (index == 0) param = (P1)param 286 #define FUNCTOR_EVALUATE_PARAM2 \ 287 if (index == 0) param = (P1)param; \ 288 else if (index == 1) param = (P2)param 289 #define FUNCTOR_EVALUATE_PARAM3 \ 290 if (index == 0) param = (P1)param; \ 291 else if (index == 1) param = (P2)param; \ 292 else if (index == 2) param = (P3)param 293 #define FUNCTOR_EVALUATE_PARAM4 \ 294 if (index == 0) param = (P1)param; \ 295 else if (index == 1) param = (P2)param; \ 296 else if (index == 2) param = (P3)param; \ 297 else if (index == 3) param = (P4)param 298 #define FUNCTOR_EVALUATE_PARAM5 \ 299 if (index == 0) param = (P1)param; \ 300 else if (index == 1) param = (P2)param; \ 301 else if (index == 2) param = (P3)param; \ 302 else if (index == 3) param = (P4)param; \ 303 else if (index == 4) param = (P5)param 304 305 306 280 307 281 308 … … 301 328 } \ 302 329 \ 330 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 331 { \ 332 FUNCTOR_EVALUATE_PARAM(numparams); \ 333 } \ 334 \ 303 335 private: \ 304 336 FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ … … 340 372 } \ 341 373 \ 374 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 375 { \ 376 FUNCTOR_EVALUATE_PARAM(numparams); \ 377 } \ 378 \ 342 379 private: \ 343 380 FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ … … 365 402 { \ 366 403 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ 404 } \ 405 \ 406 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 407 { \ 408 FUNCTOR_EVALUATE_PARAM(numparams); \ 367 409 } \ 368 410 \
Note: See TracChangeset
for help on using the changeset viewer.