- Timestamp:
- Mar 27, 2008, 6:49:38 PM (17 years ago)
- Location:
- code/branches/core2/src/orxonox/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/Executor.cc
r933 r939 59 59 bool Executor::parse(const std::string& params, const std::string& delimiter) const 60 60 { 61 unsigned int paramCount = this->functor_->getParamCount(); 62 63 if (paramCount == 0) 64 { 65 COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; 66 (*this->functor_)(); 67 } 68 else if (paramCount == 1) 69 { 70 std::string temp = getStripped(params); 71 if ((temp != "") && (temp.size() != 0)) 72 { 73 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; 74 (*this->functor_)(MultiTypeMath(params)); 75 } 76 else if (this->bAddedDefaultValue_[0]) 77 { 78 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; 79 (*this->functor_)(this->defaultValue_[0]); 80 } 81 else 82 { 83 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; 84 return false; 85 } 86 } 87 else 88 { 89 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 90 91 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) 92 { 93 if (!this->bAddedDefaultValue_[i]) 94 { 95 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; 96 return false; 97 } 98 } 99 100 MultiTypeMath param[paramCount]; 101 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; 102 for (unsigned int i = 0; i < tokens.size(); i++) 103 { 104 param[i] = tokens[i]; 105 if (i != 0) 106 { 107 COUT(5) << ", "; 108 } 109 COUT(5) << tokens[i]; 110 } 111 COUT(5) << ") and " << (paramCount - tokens.size()) << " default values ("; 112 for (unsigned int i = tokens.size(); i < paramCount; i++) 113 { 114 param[i] = this->defaultValue_[i]; 115 if (i != 0) 116 { 117 COUT(5) << ", "; 118 } 119 COUT(5) << this->defaultValue_[i]; 120 } 121 COUT(5) << ")." << std::endl; 122 123 switch(paramCount) 124 { 125 case 2: 126 (*this->functor_)(param[0], param[1]); 127 break; 128 case 3: 129 (*this->functor_)(param[0], param[1], param[2]); 130 break; 131 case 4: 132 (*this->functor_)(param[0], param[1], param[2], param[3]); 133 break; 134 case 5: 135 (*this->functor_)(param[0], param[1], param[2], param[3], param[4]); 136 break; 137 } 138 } 139 140 return true; 61 EXECUTOR_PARSE(normal); 141 62 } 142 63 -
code/branches/core2/src/orxonox/core/Executor.h
r933 r939 35 35 #include "util/SubString.h" 36 36 #include "util/String.h" 37 38 39 #define EXECUTOR_PARSE_FUNCTORCALL(mode) EXECUTOR_PARSE_FUNCTORCALL##mode 40 #define EXECUTOR_PARSE_FUNCTORCALLnormal (*this->functor_) 41 #define EXECUTOR_PARSE_FUNCTORCALLobject (*((FunctorMember<T>*)this->functor_)) 42 43 #define EXECUTOR_PARSE_OBJECT(mode, comma) EXECUTOR_PARSE_OBJECT##mode##comma 44 #define EXECUTOR_PARSE_OBJECTnormal0 45 #define EXECUTOR_PARSE_OBJECTnormal1 46 #define EXECUTOR_PARSE_OBJECTobject0 object 47 #define EXECUTOR_PARSE_OBJECTobject1 object, 48 49 #define EXECUTOR_PARSE(mode) \ 50 unsigned int paramCount = this->functor_->getParamCount(); \ 51 \ 52 if (paramCount == 0) \ 53 { \ 54 COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; \ 55 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 0)); \ 56 } \ 57 else if (paramCount == 1) \ 58 { \ 59 std::string temp = getStripped(params); \ 60 if ((temp != "") && (temp.size() != 0)) \ 61 { \ 62 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; \ 63 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) MultiTypeMath(params)); \ 64 } \ 65 else if (this->bAddedDefaultValue_[0]) \ 66 { \ 67 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; \ 68 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) this->defaultValue_[0]); \ 69 } \ 70 else \ 71 { \ 72 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; \ 73 return false; \ 74 } \ 75 } \ 76 else \ 77 { \ 78 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); \ 79 \ 80 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) \ 81 { \ 82 if (!this->bAddedDefaultValue_[i]) \ 83 { \ 84 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; \ 85 return false; \ 86 } \ 87 } \ 88 \ 89 MultiTypeMath param[paramCount]; \ 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++) \ 92 { \ 93 param[i] = tokens[i]; \ 94 if (i != 0) \ 95 { \ 96 COUT(5) << ", "; \ 97 } \ 98 COUT(5) << tokens[i]; \ 99 } \ 100 COUT(5) << ") and " << (paramCount - tokens.size()) << " default values ("; \ 101 for (unsigned int i = tokens.size(); i < paramCount; i++) \ 102 { \ 103 param[i] = this->defaultValue_[i]; \ 104 if (i != 0) \ 105 { \ 106 COUT(5) << ", "; \ 107 } \ 108 COUT(5) << this->defaultValue_[i]; \ 109 } \ 110 COUT(5) << ")." << std::endl; \ 111 \ 112 switch(paramCount) \ 113 { \ 114 case 2: \ 115 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1]); \ 116 break; \ 117 case 3: \ 118 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2]); \ 119 break; \ 120 case 4: \ 121 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3]); \ 122 break; \ 123 case 5: \ 124 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3], param[4]); \ 125 break; \ 126 } \ 127 } \ 128 \ 129 return true 130 37 131 38 132 namespace orxonox … … 157 251 bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const 158 252 { 159 unsigned int paramCount = this->functor_->getParamCount(); 160 161 if (paramCount == 0) 162 { 163 COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; 164 (*((FunctorMember<T>*)this->functor_))(object); 165 } 166 else if (paramCount == 1) 167 { 168 std::string temp = getStripped(params); 169 if ((temp != "") && (temp.size() != 0)) 170 { 171 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; 172 (*((FunctorMember<T>*)this->functor_))(object, MultiTypeMath(params)); 173 } 174 else if (this->bAddedDefaultValue_[0]) 175 { 176 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; 177 (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0]); 178 } 179 else 180 { 181 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; 182 return false; 183 } 184 } 185 else 186 { 187 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 188 189 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) 190 { 191 if (!this->bAddedDefaultValue_[i]) 192 { 193 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; 194 return false; 195 } 196 } 197 198 MultiTypeMath param[paramCount]; 199 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; 200 for (unsigned int i = 0; i < tokens.size(); i++) 201 { 202 param[i] = tokens[i]; 203 if (i != 0) 204 { 205 COUT(5) << ", "; 206 } 207 COUT(5) << tokens[i]; 208 } 209 COUT(5) << ") and " << (paramCount - tokens.size()) << " default values ("; 210 for (unsigned int i = tokens.size(); i < paramCount; i++) 211 { 212 param[i] = this->defaultValue_[i]; 213 if (i != 0) 214 { 215 COUT(5) << ", "; 216 } 217 COUT(5) << this->defaultValue_[i]; 218 } 219 COUT(5) << ")." << std::endl; 220 221 switch(paramCount) 222 { 223 case 2: 224 (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1]); 225 break; 226 case 3: 227 (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2]); 228 break; 229 case 4: 230 (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2], param[3]); 231 break; 232 case 5: 233 (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2], param[3], param[4]); 234 break; 235 } 236 } 237 238 return true; 253 EXECUTOR_PARSE(object); 239 254 } 240 255 241 256 bool parse(const T* object, const std::string& params, const std::string& delimiter = " ") const 242 257 { 243 unsigned int paramCount = this->functor_->getParamCount(); 244 245 if (paramCount == 0) 246 { 247 COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; 248 (*((FunctorMember<T>*)this->functor_))(object); 249 } 250 else if (paramCount == 1) 251 { 252 std::string temp = getStripped(params); 253 if ((temp != "") && (temp.size() != 0)) 254 { 255 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; 256 (*((FunctorMember<T>*)this->functor_))(object, MultiTypeMath(params)); 257 } 258 else if (this->bAddedDefaultValue_[0]) 259 { 260 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; 261 (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0]); 262 } 263 else 264 { 265 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; 266 return false; 267 } 268 } 269 else 270 { 271 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 272 273 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) 274 { 275 if (!this->bAddedDefaultValue_[i]) 276 { 277 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; 278 return false; 279 } 280 } 281 282 MultiTypeMath param[paramCount]; 283 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; 284 for (unsigned int i = 0; i < tokens.size(); i++) 285 { 286 param[i] = tokens[i]; 287 if (i != 0) 288 { 289 COUT(5) << ", "; 290 } 291 COUT(5) << tokens[i]; 292 } 293 COUT(5) << ") and " << (paramCount - tokens.size()) << " default values ("; 294 for (unsigned int i = tokens.size(); i < paramCount; i++) 295 { 296 param[i] = this->defaultValue_[i]; 297 if (i != 0) 298 { 299 COUT(5) << ", "; 300 } 301 COUT(5) << this->defaultValue_[i]; 302 } 303 COUT(5) << ")." << std::endl; 304 305 switch(paramCount) 306 { 307 case 2: 308 (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1]); 309 break; 310 case 3: 311 (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2]); 312 break; 313 case 4: 314 (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2], param[3]); 315 break; 316 case 5: 317 (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2], param[3], param[4]); 318 break; 319 } 320 } 321 322 return true; 258 EXECUTOR_PARSE(object); 323 259 } 324 260 };
Note: See TracChangeset
for help on using the changeset viewer.