- Timestamp:
- Mar 29, 2008, 3:04:06 PM (17 years ago)
- Location:
- code/branches/core2/src/orxonox/core
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/CommandExecutor.cc
r951 r952 51 51 } 52 52 53 CommandEvaluation& CommandExecutor::getEvaluation() 54 { 55 return CommandExecutor::getInstance().evaluation_; 56 } 57 53 58 bool CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor) 54 59 { … … 88 93 bool CommandExecutor::execute(const std::string& command) 89 94 { 90 if (CommandExecutor::get Instance().lastProcessedCommand_ != command)95 if (CommandExecutor::getEvaluation().processedCommand_ != command) 91 96 CommandExecutor::parse(command); 92 97 93 CommandExecutor::getInstance().tokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 94 95 switch (CommandExecutor::getInstance().state_) 98 return CommandExecutor::execute(CommandExecutor::getEvaluation()); 99 } 100 101 102 bool CommandExecutor::execute(const CommandEvaluation& evaluation) 103 { 104 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 105 106 switch (evaluation.state_) 96 107 { 97 108 case CS_Empty: … … 104 115 case CS_Shortcut_Finished: 105 116 // call the shortcut 106 if ( CommandExecutor::getInstance().shortcut_ != 0)107 return CommandExecutor::getInstance().shortcut_->parse(CommandExecutor::getInstance().tokens_.subSet(1).join());117 if (evaluation.shortcut_ != 0) 118 return evaluation.shortcut_->parse(tokens.subSet(1).join()); 108 119 break; 109 120 case CS_Function: … … 114 125 case CS_Function_Finished: 115 126 // call the shortcut 116 if ( CommandExecutor::getInstance().function_ != 0)117 return CommandExecutor::getInstance().function_->parse(CommandExecutor::getInstance().tokens_.subSet(2).join());127 if (evaluation.function_ != 0) 128 return evaluation.function_->parse(tokens.subSet(2).join()); 118 129 break; 119 130 case CS_ConfigValueClass: … … 126 137 case CS_ConfigValueFinished: 127 138 // set the config value 128 if ( CommandExecutor::getInstance().configvalue_ != 0)129 return CommandExecutor::getInstance().configvalue_->parseString(CommandExecutor::getInstance().tokens_.subSet(3).join());139 if (evaluation.configvalue_ != 0) 140 return evaluation.configvalue_->parseString(tokens.subSet(3).join()); 130 141 break; 131 142 case CS_KeybindKey: … … 147 158 std::string CommandExecutor::complete(const std::string& command) 148 159 { 149 if (CommandExecutor::get Instance().lastProcessedCommand_ != command)160 if (CommandExecutor::getEvaluation().processedCommand_ != command) 150 161 CommandExecutor::parse(command); 151 162 152 CommandExecutor::getInstance().tokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 163 return CommandExecutor::complete(CommandExecutor::getEvaluation()); 164 } 165 166 std::string CommandExecutor::complete(const CommandEvaluation& evaluation) 167 { 168 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 153 169 154 170 std::list<const std::string*> temp; 155 if ( CommandExecutor::getInstance().state_ == CS_Empty)156 { 157 temp.insert(temp.end(), CommandExecutor::getInstance().listOfPossibleShortcuts_.begin(), CommandExecutor::getInstance().listOfPossibleShortcuts_.end());158 temp.insert(temp.end(), CommandExecutor::getInstance().listOfPossibleFunctionClasses_.begin(), CommandExecutor::getInstance().listOfPossibleFunctionClasses_.end());159 } 160 161 switch ( CommandExecutor::getInstance().state_)171 if (evaluation.state_ == CS_Empty) 172 { 173 temp.insert(temp.end(), evaluation.listOfPossibleShortcuts_.begin(), evaluation.listOfPossibleShortcuts_.end()); 174 temp.insert(temp.end(), evaluation.listOfPossibleFunctionClasses_.begin(), evaluation.listOfPossibleFunctionClasses_.end()); 175 } 176 177 switch (evaluation.state_) 162 178 { 163 179 case CS_Empty: 164 return ( CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(temp));180 return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(temp)); 165 181 break; 166 182 case CS_FunctionClass_Or_Shortcut_Or_Keyword: 167 183 break; 168 184 case CS_Shortcut_Params: 169 if ( command[command.size() - 1] != ' ')170 return ( command+ " ");185 if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' ')) 186 return (evaluation.processedCommand_ + " "); 171 187 break; 172 188 case CS_Shortcut_Finished: 173 189 break; 174 190 case CS_Function: 175 return ( CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleFunctions_));191 return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleFunctions_)); 176 192 break; 177 193 case CS_Function_Params: 178 if ( command[command.size() - 1] != ' ')179 return ( command+ " ");194 if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' ')) 195 return (evaluation.processedCommand_ + " "); 180 196 break; 181 197 case CS_Function_Finished: 182 198 break; 183 199 case CS_ConfigValueClass: 184 return ( CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleConfigValueClasses_));200 return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValueClasses_)); 185 201 break; 186 202 case CS_ConfigValue: 187 return ( CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleConfigValues_));203 return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValues_)); 188 204 break; 189 205 case CS_ConfigValueType: 190 if ( command[command.size() - 1] != ' ')191 return ( command+ " ");206 if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' ')) 207 return (evaluation.processedCommand_ + " "); 192 208 break; 193 209 case CS_ConfigValueFinished: 194 210 break; 195 211 case CS_KeybindKey: 196 return ( CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleKeys_));212 return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleKeys_)); 197 213 break; 198 214 case CS_KeybindCommand: 199 if ( command[command.size() - 1] != ' ')200 return ( command+ " ");215 if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' ')) 216 return (evaluation.processedCommand_ + " "); 201 217 break; 202 218 case CS_KeybindFinished: … … 206 222 } 207 223 208 return CommandExecutor::getInstance().lastProcessedCommand_;224 return evaluation.processedCommand_; 209 225 } 210 226 211 227 std::string CommandExecutor::hint(const std::string& command) 212 228 { 213 if (CommandExecutor::get Instance().lastProcessedCommand_ != command)229 if (CommandExecutor::getEvaluation().processedCommand_ != command) 214 230 CommandExecutor::parse(command); 215 231 216 CommandExecutor::getInstance().tokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 217 218 switch (CommandExecutor::getInstance().state_) 232 return CommandExecutor::hint(CommandExecutor::getEvaluation()); 233 } 234 235 std::string CommandExecutor::hint(const CommandEvaluation& evaluation) 236 { 237 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 238 239 switch (evaluation.state_) 219 240 { 220 241 case CS_Empty: 221 return (CommandExecutor::dump( CommandExecutor::getInstance().listOfPossibleShortcuts_) + "\n" + CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleFunctionClasses_));242 return (CommandExecutor::dump(evaluation.listOfPossibleShortcuts_) + "\n" + CommandExecutor::dump(evaluation.listOfPossibleFunctionClasses_)); 222 243 break; 223 244 case CS_FunctionClass_Or_Shortcut_Or_Keyword: 224 245 break; 225 246 case CS_Shortcut_Params: 226 if ( CommandExecutor::getInstance().shortcut_ != 0)227 return CommandExecutor::dump( CommandExecutor::getInstance().shortcut_);247 if (evaluation.shortcut_ != 0) 248 return CommandExecutor::dump(evaluation.shortcut_); 228 249 break; 229 250 case CS_Shortcut_Finished: 230 if ( CommandExecutor::getInstance().shortcut_ != 0)231 return CommandExecutor::dump( CommandExecutor::getInstance().shortcut_);251 if (evaluation.shortcut_ != 0) 252 return CommandExecutor::dump(evaluation.shortcut_); 232 253 break; 233 254 case CS_Function: 234 return CommandExecutor::dump( CommandExecutor::getInstance().listOfPossibleFunctions_);255 return CommandExecutor::dump(evaluation.listOfPossibleFunctions_); 235 256 break; 236 257 case CS_Function_Params: 237 if ( CommandExecutor::getInstance().function_ != 0)238 return CommandExecutor::dump( CommandExecutor::getInstance().function_);258 if (evaluation.function_ != 0) 259 return CommandExecutor::dump(evaluation.function_); 239 260 break; 240 261 case CS_Function_Finished: 241 if ( CommandExecutor::getInstance().function_ != 0)242 return CommandExecutor::dump( CommandExecutor::getInstance().function_);262 if (evaluation.function_ != 0) 263 return CommandExecutor::dump(evaluation.function_); 243 264 break; 244 265 case CS_ConfigValueClass: 245 return CommandExecutor::dump( CommandExecutor::getInstance().listOfPossibleConfigValueClasses_);266 return CommandExecutor::dump(evaluation.listOfPossibleConfigValueClasses_); 246 267 break; 247 268 case CS_ConfigValue: 248 return CommandExecutor::dump( CommandExecutor::getInstance().listOfPossibleConfigValues_);269 return CommandExecutor::dump(evaluation.listOfPossibleConfigValues_); 249 270 break; 250 271 case CS_ConfigValueType: 251 if ( CommandExecutor::getInstance().configvalue_ != 0)252 return CommandExecutor::dump( CommandExecutor::getInstance().configvalue_);272 if (evaluation.configvalue_ != 0) 273 return CommandExecutor::dump(evaluation.configvalue_); 253 274 break; 254 275 case CS_ConfigValueFinished: 255 if ( CommandExecutor::getInstance().configvalue_ != 0)256 return CommandExecutor::dump( CommandExecutor::getInstance().configvalue_);276 if (evaluation.configvalue_ != 0) 277 return CommandExecutor::dump(evaluation.configvalue_); 257 278 break; 258 279 case CS_KeybindKey: 259 return CommandExecutor::dump( CommandExecutor::getInstance().listOfPossibleKeys_);280 return CommandExecutor::dump(evaluation.listOfPossibleKeys_); 260 281 break; 261 282 case CS_KeybindCommand: 262 if ( CommandExecutor::getInstance().key_ != 0)263 return CommandExecutor::dump( CommandExecutor::getInstance().key_);283 if (evaluation.key_ != 0) 284 return CommandExecutor::dump(evaluation.key_); 264 285 break; 265 286 case CS_KeybindFinished: 266 if ( CommandExecutor::getInstance().key_ != 0)267 return CommandExecutor::dump( CommandExecutor::getInstance().key_);287 if (evaluation.key_ != 0) 288 return CommandExecutor::dump(evaluation.key_); 268 289 break; 269 290 case CS_Error: … … 275 296 } 276 297 298 const CommandEvaluation& CommandExecutor::evaluate(const std::string& command) 299 { 300 CommandExecutor::parse(command, true); 301 return CommandExecutor::getEvaluation(); 302 } 303 277 304 void CommandExecutor::parse(const std::string& command, bool bInitialize) 278 305 { 279 CommandExecutor::get Instance().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');280 CommandExecutor::get Instance().lastProcessedCommand_ = command;306 CommandExecutor::getEvaluation().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 307 CommandExecutor::getEvaluation().processedCommand_ = command; 281 308 282 309 if (bInitialize) 283 310 CommandExecutor::initialize(); 284 311 285 switch (CommandExecutor::get Instance().state_)312 switch (CommandExecutor::getEvaluation().state_) 286 313 { 287 314 case CS_Empty: … … 290 317 // We want a hint for the first token 291 318 // Check if there is already a perfect match 292 CommandExecutor::get Instance().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));293 CommandExecutor::get Instance().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));294 295 if ((CommandExecutor::get Instance().functionclass_ != 0) || (CommandExecutor::getInstance().shortcut_ != 0))319 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0)); 320 CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0)); 321 322 if ((CommandExecutor::getEvaluation().functionclass_ != 0) || (CommandExecutor::getEvaluation().shortcut_ != 0)) 296 323 { 297 324 // Yes, there is a class or a shortcut with the searched name 298 325 // Add a whitespace and continue parsing 299 CommandExecutor::get Instance().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;326 CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword; 300 327 CommandExecutor::parse(command + " ", false); 301 328 return; … … 310 337 { 311 338 // There is at least one argument: Check if it's a shortcut, a classname or a special keyword 312 CommandExecutor::get Instance().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;339 CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword; 313 340 CommandExecutor::parse(command, false); 314 341 return; … … 321 348 { 322 349 // We want to set a config value 323 CommandExecutor::get Instance().state_ = CS_ConfigValueClass;350 CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass; 324 351 CommandExecutor::parse(command, false); 325 352 return; … … 328 355 { 329 356 // We want to set a keybinding 330 CommandExecutor::get Instance().state_ = CS_KeybindKey;357 CommandExecutor::getEvaluation().state_ = CS_KeybindKey; 331 358 CommandExecutor::parse(command, false); 332 359 return; 333 360 } 334 361 335 if (CommandExecutor::get Instance().functionclass_ == 0)336 CommandExecutor::get Instance().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));337 if (CommandExecutor::get Instance().shortcut_ == 0)338 CommandExecutor::get Instance().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));339 340 if ((CommandExecutor::get Instance().functionclass_ == 0) && (CommandExecutor::getInstance().shortcut_ == 0))362 if (CommandExecutor::getEvaluation().functionclass_ == 0) 363 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0)); 364 if (CommandExecutor::getEvaluation().shortcut_ == 0) 365 CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0)); 366 367 if ((CommandExecutor::getEvaluation().functionclass_ == 0) && (CommandExecutor::getEvaluation().shortcut_ == 0)) 341 368 { 342 369 // Argument 1 seems to be wrong 343 370 AddLanguageEntry("CommandExecutor::NoSuchCommandOrClassName", "No such command or classname"); 344 CommandExecutor::get Instance().errorMessage_ = (CommandExecutor::getToken(0) + ": " + GetLocalisation("CommandExecutor::NoSuchCommandOrClassName"));345 CommandExecutor::get Instance().state_ = CS_Error;346 return; 347 } 348 else if (CommandExecutor::get Instance().shortcut_ != 0)371 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(0) + ": " + GetLocalisation("CommandExecutor::NoSuchCommandOrClassName")); 372 CommandExecutor::getEvaluation().state_ = CS_Error; 373 return; 374 } 375 else if (CommandExecutor::getEvaluation().shortcut_ != 0) 349 376 { 350 377 // Argument 1 is a shortcut: Return the needed parameter types 351 CommandExecutor::get Instance().state_ = CS_Shortcut_Params;378 CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params; 352 379 CommandExecutor::parse(command, false); 353 380 return; … … 356 383 { 357 384 // Argument 1 is a classname: Return the possible functions 358 CommandExecutor::get Instance().state_ = CS_Function;385 CommandExecutor::getEvaluation().state_ = CS_Function; 359 386 CommandExecutor::parse(command, false); 360 387 return; … … 363 390 else 364 391 { 365 CommandExecutor::get Instance().state_ = CS_Error;392 CommandExecutor::getEvaluation().state_ = CS_Error; 366 393 return; 367 394 } 368 395 break; 369 396 case CS_Shortcut_Params: 370 if (CommandExecutor::get Instance().shortcut_ != 0)397 if (CommandExecutor::getEvaluation().shortcut_ != 0) 371 398 { 372 399 // Valid command 373 400 // Check if there are enough parameters 374 if (CommandExecutor::enoughParametersGiven(1, CommandExecutor::get Instance().shortcut_))375 { 376 CommandExecutor::get Instance().state_ = CS_Shortcut_Finished;401 if (CommandExecutor::enoughParametersGiven(1, CommandExecutor::getEvaluation().shortcut_)) 402 { 403 CommandExecutor::getEvaluation().state_ = CS_Shortcut_Finished; 377 404 return; 378 405 } … … 381 408 { 382 409 // Something is wrong 383 CommandExecutor::get Instance().state_ = CS_Error;410 CommandExecutor::getEvaluation().state_ = CS_Error; 384 411 return; 385 412 } 386 413 break; 387 414 case CS_Function: 388 if (CommandExecutor::get Instance().functionclass_ != 0)415 if (CommandExecutor::getEvaluation().functionclass_ != 0) 389 416 { 390 417 // We have a valid classname … … 393 420 { 394 421 // There is a second argument: Check if it's a valid functionname 395 CommandExecutor::get Instance().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getInstance().functionclass_);396 if (CommandExecutor::get Instance().function_ == 0)422 CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_); 423 if (CommandExecutor::getEvaluation().function_ == 0) 397 424 { 398 425 // Argument 2 seems to be wrong 399 426 AddLanguageEntry("CommandExecutor::NoSuchFunctionnameIn", "No such functionname in"); 400 CommandExecutor::get Instance().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchFunctionnameIn") + " " + CommandExecutor::getInstance().functionclass_->getName());401 CommandExecutor::get Instance().state_ = CS_Error;427 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchFunctionnameIn") + " " + CommandExecutor::getEvaluation().functionclass_->getName()); 428 CommandExecutor::getEvaluation().state_ = CS_Error; 402 429 return; 403 430 } … … 405 432 { 406 433 // Argument 2 seems to be a valid functionname: Get the parameters 407 CommandExecutor::get Instance().state_ = CS_Function_Params;434 CommandExecutor::getEvaluation().state_ = CS_Function_Params; 408 435 CommandExecutor::parse(command, false); 409 436 return; … … 414 441 // There is no finished second argument 415 442 // Check if there's already a perfect match 416 if (CommandExecutor::get Instance().tokens_.size() >= 2)417 { 418 CommandExecutor::get Instance().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getInstance().functionclass_);419 if (CommandExecutor::get Instance().function_ != 0)443 if (CommandExecutor::getEvaluation().tokens_.size() >= 2) 444 { 445 CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_); 446 if (CommandExecutor::getEvaluation().function_ != 0) 420 447 { 421 448 // There is a perfect match: Add a whitespace and continue parsing 422 CommandExecutor::get Instance().state_ = CS_Function_Params;449 CommandExecutor::getEvaluation().state_ = CS_Function_Params; 423 450 CommandExecutor::parse(command + " ", false); 424 451 return; … … 427 454 428 455 // No perfect match: Create the list of all possible functions and return 429 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getToken(1), CommandExecutor::get Instance().functionclass_);456 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_); 430 457 return; 431 458 } … … 433 460 else 434 461 { 435 CommandExecutor::get Instance().state_ = CS_Error;462 CommandExecutor::getEvaluation().state_ = CS_Error; 436 463 return; 437 464 } 438 465 break; 439 466 case CS_Function_Params: 440 if ((CommandExecutor::get Instance().functionclass_ != 0) && (CommandExecutor::getInstance().function_ != 0))467 if ((CommandExecutor::getEvaluation().functionclass_ != 0) && (CommandExecutor::getEvaluation().function_ != 0)) 441 468 { 442 469 // Valid command 443 470 // Check if there are enough parameters 444 if (CommandExecutor::enoughParametersGiven(2, CommandExecutor::get Instance().function_))445 { 446 CommandExecutor::get Instance().state_ = CS_Function_Finished;471 if (CommandExecutor::enoughParametersGiven(2, CommandExecutor::getEvaluation().function_)) 472 { 473 CommandExecutor::getEvaluation().state_ = CS_Function_Finished; 447 474 return; 448 475 } … … 451 478 { 452 479 // Something is wrong 453 CommandExecutor::get Instance().state_ = CS_Error;480 CommandExecutor::getEvaluation().state_ = CS_Error; 454 481 return; 455 482 } … … 463 490 { 464 491 // There is a second argument: Check if it's a valid classname 465 CommandExecutor::get Instance().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));466 if (CommandExecutor::get Instance().configvalueclass_ == 0)492 CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1)); 493 if (CommandExecutor::getEvaluation().configvalueclass_ == 0) 467 494 { 468 495 // Argument 2 seems to be wrong 469 496 AddLanguageEntry("CommandExecutor::NoSuchClassWithConfigValues", "No such class with config values"); 470 CommandExecutor::get Instance().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchClassWithConfigValues"));471 CommandExecutor::get Instance().state_ = CS_Error;497 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchClassWithConfigValues")); 498 CommandExecutor::getEvaluation().state_ = CS_Error; 472 499 return; 473 500 } … … 475 502 { 476 503 // Argument 2 seems to be a valid classname: Search for possible config values 477 CommandExecutor::get Instance().state_ = CS_ConfigValue;504 CommandExecutor::getEvaluation().state_ = CS_ConfigValue; 478 505 CommandExecutor::parse(command, false); 479 506 return; … … 484 511 // There's no finished second argument 485 512 // Check if there's already a perfect match 486 if (CommandExecutor::get Instance().tokens_.size() >= 2)487 { 488 CommandExecutor::get Instance().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));489 if (CommandExecutor::get Instance().configvalueclass_ != 0)513 if (CommandExecutor::getEvaluation().tokens_.size() >= 2) 514 { 515 CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1)); 516 if (CommandExecutor::getEvaluation().configvalueclass_ != 0) 490 517 { 491 518 // There is a perfect match: Add a whitespace and continue parsing 492 CommandExecutor::get Instance().state_ = CS_ConfigValue;519 CommandExecutor::getEvaluation().state_ = CS_ConfigValue; 493 520 CommandExecutor::parse(command + " ", false); 494 521 return; … … 504 531 { 505 532 // Something is wrong 506 CommandExecutor::get Instance().state_ = CS_Error;533 CommandExecutor::getEvaluation().state_ = CS_Error; 507 534 return; 508 535 } 509 536 break; 510 537 case CS_ConfigValue: 511 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::get Instance().configvalueclass_ != 0))538 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getEvaluation().configvalueclass_ != 0)) 512 539 { 513 540 // Check if there is a third argument … … 515 542 { 516 543 // There is a third argument: Check if it's a valid config value 517 CommandExecutor::get Instance().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getInstance().configvalueclass_);518 if (CommandExecutor::get Instance().configvalue_ == 0)544 CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_); 545 if (CommandExecutor::getEvaluation().configvalue_ == 0) 519 546 { 520 547 // Argument 3 seems to be wrong 521 548 AddLanguageEntry("CommandExecutor::NoSuchConfigValueIn", "No such config value in"); 522 CommandExecutor::get Instance().errorMessage_ = (CommandExecutor::getToken(2) + ": " + GetLocalisation("CommandExecutor::NoSuchConfigValueIn") + " " + CommandExecutor::getInstance().configvalueclass_->getName());523 CommandExecutor::get Instance().state_ = CS_Error;549 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(2) + ": " + GetLocalisation("CommandExecutor::NoSuchConfigValueIn") + " " + CommandExecutor::getEvaluation().configvalueclass_->getName()); 550 CommandExecutor::getEvaluation().state_ = CS_Error; 524 551 return; 525 552 } … … 527 554 { 528 555 // Argument 3 seems to be a valid config value: Get the type 529 CommandExecutor::get Instance().state_ = CS_ConfigValueType;556 CommandExecutor::getEvaluation().state_ = CS_ConfigValueType; 530 557 CommandExecutor::parse(command, false); 531 558 return; … … 536 563 // There is no finished third argument 537 564 // Check if there's already a perfect match 538 if (CommandExecutor::get Instance().tokens_.size() >= 3)539 { 540 CommandExecutor::get Instance().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getInstance().configvalueclass_);541 if (CommandExecutor::get Instance().configvalueclass_ != 0)565 if (CommandExecutor::getEvaluation().tokens_.size() >= 3) 566 { 567 CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_); 568 if (CommandExecutor::getEvaluation().configvalueclass_ != 0) 542 569 { 543 570 // There is a perfect match: Add a whitespace and continue parsing 544 CommandExecutor::get Instance().state_ = CS_ConfigValueType;571 CommandExecutor::getEvaluation().state_ = CS_ConfigValueType; 545 572 CommandExecutor::parse(command + " ", false); 546 573 return; … … 549 576 550 577 // No perfect match: Create the list of all possible config values 551 CommandExecutor::createListOfPossibleConfigValues(CommandExecutor::getToken(2), CommandExecutor::get Instance().configvalueclass_);578 CommandExecutor::createListOfPossibleConfigValues(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_); 552 579 return; 553 580 } … … 556 583 { 557 584 // Something is wrong 558 CommandExecutor::get Instance().state_ = CS_Error;585 CommandExecutor::getEvaluation().state_ = CS_Error; 559 586 return; 560 587 } 561 588 break; 562 589 case CS_ConfigValueType: 563 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::get Instance().configvalueclass_ != 0) && (CommandExecutor::getInstance().configvalue_ != 0))590 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getEvaluation().configvalueclass_ != 0) && (CommandExecutor::getEvaluation().configvalue_ != 0)) 564 591 { 565 592 // Valid command 566 593 // Check if there are enough parameters 567 if (CommandExecutor::get Instance().tokens_.size() >= 4)568 { 569 CommandExecutor::get Instance().state_ = CS_ConfigValueFinished;594 if (CommandExecutor::getEvaluation().tokens_.size() >= 4) 595 { 596 CommandExecutor::getEvaluation().state_ = CS_ConfigValueFinished; 570 597 return; 571 598 } … … 574 601 { 575 602 // Something is wrong 576 CommandExecutor::get Instance().state_ = CS_Error;603 CommandExecutor::getEvaluation().state_ = CS_Error; 577 604 return; 578 605 } … … 586 613 { 587 614 // Something is wrong 588 CommandExecutor::get Instance().state_ = CS_Error;615 CommandExecutor::getEvaluation().state_ = CS_Error; 589 616 return; 590 617 } … … 595 622 // Valid command 596 623 // Check if there are enough parameters 597 if (CommandExecutor::get Instance().tokens_.size() >= 3)598 { 599 CommandExecutor::get Instance().state_ = CS_KeybindFinished;624 if (CommandExecutor::getEvaluation().tokens_.size() >= 3) 625 { 626 CommandExecutor::getEvaluation().state_ = CS_KeybindFinished; 600 627 return; 601 628 } … … 605 632 { 606 633 // Something is wrong 607 CommandExecutor::get Instance().state_ = CS_Error;634 CommandExecutor::getEvaluation().state_ = CS_Error; 608 635 return; 609 636 } … … 629 656 void CommandExecutor::initialize() 630 657 { 631 CommandExecutor::get Instance().listOfPossibleFunctionClasses_.clear();632 CommandExecutor::get Instance().listOfPossibleShortcuts_.clear();633 CommandExecutor::get Instance().listOfPossibleFunctions_.clear();634 CommandExecutor::get Instance().listOfPossibleConfigValueClasses_.clear();635 CommandExecutor::get Instance().listOfPossibleConfigValues_.clear();636 CommandExecutor::get Instance().listOfPossibleKeys_.clear();637 638 CommandExecutor::get Instance().functionclass_ = 0;639 CommandExecutor::get Instance().configvalueclass_ = 0;640 CommandExecutor::get Instance().shortcut_ = 0;641 CommandExecutor::get Instance().function_ = 0;642 CommandExecutor::get Instance().configvalue_ = 0;643 CommandExecutor::get Instance().key_ = 0;644 645 CommandExecutor::get Instance().errorMessage_ = "";646 CommandExecutor::get Instance().state_ = CS_Empty;658 CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.clear(); 659 CommandExecutor::getEvaluation().listOfPossibleShortcuts_.clear(); 660 CommandExecutor::getEvaluation().listOfPossibleFunctions_.clear(); 661 CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.clear(); 662 CommandExecutor::getEvaluation().listOfPossibleConfigValues_.clear(); 663 CommandExecutor::getEvaluation().listOfPossibleKeys_.clear(); 664 665 CommandExecutor::getEvaluation().functionclass_ = 0; 666 CommandExecutor::getEvaluation().configvalueclass_ = 0; 667 CommandExecutor::getEvaluation().shortcut_ = 0; 668 CommandExecutor::getEvaluation().function_ = 0; 669 CommandExecutor::getEvaluation().configvalue_ = 0; 670 CommandExecutor::getEvaluation().key_ = 0; 671 672 CommandExecutor::getEvaluation().errorMessage_ = ""; 673 CommandExecutor::getEvaluation().state_ = CS_Empty; 647 674 } 648 675 … … 651 678 // Because we added a cursor we have +1 arguments 652 679 // There are num arguments given if there are at least num arguments + one cursor 653 return (CommandExecutor::get Instance().tokens_.size() >= (num + 1));680 return (CommandExecutor::getEvaluation().tokens_.size() >= (num + 1)); 654 681 } 655 682 … … 657 684 { 658 685 // Because we added a cursor we have +1 arguments 659 if (CommandExecutor::get Instance().tokens_.size() >= 1)660 return (CommandExecutor::get Instance().tokens_.size() - 1);686 if (CommandExecutor::getEvaluation().tokens_.size() >= 1) 687 return (CommandExecutor::getEvaluation().tokens_.size() - 1); 661 688 else 662 689 return 0; … … 665 692 std::string CommandExecutor::getToken(unsigned int index) 666 693 { 667 if ((index >= 0) && (index < (CommandExecutor::get Instance().tokens_.size() - 1)))668 return CommandExecutor::get Instance().tokens_[index];669 else if (index == (CommandExecutor::get Instance().tokens_.size() - 1))670 return CommandExecutor::get Instance().tokens_[index].substr(0, CommandExecutor::getInstance().tokens_[index].size() - 1);694 if ((index >= 0) && (index < (CommandExecutor::getEvaluation().tokens_.size() - 1))) 695 return CommandExecutor::getEvaluation().tokens_[index]; 696 else if (index == (CommandExecutor::getEvaluation().tokens_.size() - 1)) 697 return CommandExecutor::getEvaluation().tokens_[index].substr(0, CommandExecutor::getEvaluation().tokens_[index].size() - 1); 671 698 else 672 699 return ""; … … 683 710 break; 684 711 } 685 return (CommandExecutor::get Instance().tokens_.size() >= neededParams);712 return (CommandExecutor::getEvaluation().tokens_.size() >= neededParams); 686 713 } 687 714 … … 694 721 if ((*it).first.find(getLowercase(fragment)) == 0) 695 722 { 696 CommandExecutor::get Instance().listOfPossibleFunctionClasses_.push_back(&(*it).first);723 CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.push_back(&(*it).first); 697 724 } 698 725 } 699 726 } 700 727 701 CommandExecutor::get Instance().listOfPossibleFunctionClasses_.sort(CommandExecutor::compareStringsInList);728 CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.sort(CommandExecutor::compareStringsInList); 702 729 } 703 730 … … 708 735 if ((*it).first.find(getLowercase(fragment)) == 0) 709 736 { 710 CommandExecutor::get Instance().listOfPossibleShortcuts_.push_back(&(*it).first);737 CommandExecutor::getEvaluation().listOfPossibleShortcuts_.push_back(&(*it).first); 711 738 } 712 739 } 713 740 714 CommandExecutor::get Instance().listOfPossibleShortcuts_.sort(CommandExecutor::compareStringsInList);741 CommandExecutor::getEvaluation().listOfPossibleShortcuts_.sort(CommandExecutor::compareStringsInList); 715 742 } 716 743 … … 721 748 if ((*it).first.find(getLowercase(fragment)) == 0) 722 749 { 723 CommandExecutor::get Instance().listOfPossibleFunctions_.push_back(&(*it).first);750 CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(&(*it).first); 724 751 } 725 752 } 726 753 727 CommandExecutor::get Instance().listOfPossibleFunctions_.sort(CommandExecutor::compareStringsInList);754 CommandExecutor::getEvaluation().listOfPossibleFunctions_.sort(CommandExecutor::compareStringsInList); 728 755 } 729 756 … … 736 763 if ((*it).first.find(getLowercase(fragment)) == 0) 737 764 { 738 CommandExecutor::get Instance().listOfPossibleConfigValueClasses_.push_back(&(*it).first);765 CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.push_back(&(*it).first); 739 766 } 740 767 } 741 768 } 742 769 743 CommandExecutor::get Instance().listOfPossibleConfigValueClasses_.sort(CommandExecutor::compareStringsInList);770 CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.sort(CommandExecutor::compareStringsInList); 744 771 } 745 772 … … 750 777 if ((*it).first.find(getLowercase(fragment)) == 0) 751 778 { 752 CommandExecutor::get Instance().listOfPossibleConfigValues_.push_back(&(*it).first);779 CommandExecutor::getEvaluation().listOfPossibleConfigValues_.push_back(&(*it).first); 753 780 } 754 781 } 755 782 756 CommandExecutor::get Instance().listOfPossibleConfigValues_.sort(CommandExecutor::compareStringsInList);783 CommandExecutor::getEvaluation().listOfPossibleConfigValues_.sort(CommandExecutor::compareStringsInList); 757 784 } 758 785 … … 761 788 // todo 762 789 763 CommandExecutor::get Instance().listOfPossibleKeys_.sort(CommandExecutor::compareStringsInList);790 CommandExecutor::getEvaluation().listOfPossibleKeys_.sort(CommandExecutor::compareStringsInList); 764 791 } 765 792 -
code/branches/core2/src/orxonox/core/CommandExecutor.h
r951 r952 40 40 namespace orxonox 41 41 { 42 enum CommandState 43 { 44 CS_Empty, 45 CS_FunctionClass_Or_Shortcut_Or_Keyword, 46 CS_Shortcut_Params, 47 CS_Shortcut_Finished, 48 CS_Function, 49 CS_Function_Params, 50 CS_Function_Finished, 51 CS_ConfigValueClass, 52 CS_ConfigValue, 53 CS_ConfigValueType, 54 CS_ConfigValueFinished, 55 CS_KeybindKey, 56 CS_KeybindCommand, 57 CS_KeybindFinished, 58 CS_Error 59 }; 60 61 class _CoreExport CommandEvaluation 62 { 63 public: 64 std::string processedCommand_; 65 SubString tokens_; 66 std::list<const std::string*> listOfPossibleFunctionClasses_; 67 std::list<const std::string*> listOfPossibleShortcuts_; 68 std::list<const std::string*> listOfPossibleFunctions_; 69 std::list<const std::string*> listOfPossibleConfigValueClasses_; 70 std::list<const std::string*> listOfPossibleConfigValues_; 71 std::list<const std::string*> listOfPossibleKeys_; 72 73 Identifier* functionclass_; 74 Identifier* configvalueclass_; 75 ExecutorStatic* shortcut_; 76 ExecutorStatic* function_; 77 ConfigValueContainer* configvalue_; 78 ConfigValueContainer* key_; 79 80 std::string errorMessage_; 81 CommandState state_; 82 }; 83 42 84 class _CoreExport CommandExecutor 43 85 { 44 enum CommandState45 {46 CS_Empty,47 CS_FunctionClass_Or_Shortcut_Or_Keyword,48 CS_Shortcut_Params,49 CS_Shortcut_Finished,50 CS_Function,51 CS_Function_Params,52 CS_Function_Finished,53 CS_ConfigValueClass,54 CS_ConfigValue,55 CS_ConfigValueType,56 CS_ConfigValueFinished,57 CS_KeybindKey,58 CS_KeybindCommand,59 CS_KeybindFinished,60 CS_Error61 };62 63 86 public: 64 87 static bool execute(const std::string& command); 88 static bool execute(const CommandEvaluation& evaluation); 89 65 90 static std::string complete(const std::string& command); 91 static std::string complete(const CommandEvaluation& evaluation); 92 66 93 static std::string hint(const std::string& command); 94 static std::string hint(const CommandEvaluation& evaluation); 95 96 static const CommandEvaluation& evaluate(const std::string& command); 67 97 68 98 static bool addConsoleCommandShortcut(ExecutorStatic* executor); … … 90 120 91 121 static CommandExecutor& getInstance(); 122 static CommandEvaluation& getEvaluation(); 92 123 93 124 static void parse(const std::string& command, bool bInitialize = true); … … 123 154 static ConfigValueContainer* getContainerOfPossibleKey(const std::string& name); 124 155 125 std::string lastProcessedCommand_; 126 SubString tokens_; 127 std::list<const std::string*> listOfPossibleFunctionClasses_; 128 std::list<const std::string*> listOfPossibleShortcuts_; 129 std::list<const std::string*> listOfPossibleFunctions_; 130 std::list<const std::string*> listOfPossibleConfigValueClasses_; 131 std::list<const std::string*> listOfPossibleConfigValues_; 132 std::list<const std::string*> listOfPossibleKeys_; 133 134 Identifier* functionclass_; 135 Identifier* configvalueclass_; 136 ExecutorStatic* shortcut_; 137 ExecutorStatic* function_; 138 ConfigValueContainer* configvalue_; 139 ConfigValueContainer* key_; 140 141 std::string errorMessage_; 142 CommandState state_; 156 CommandEvaluation evaluation_; 143 157 144 158 std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_; -
code/branches/core2/src/orxonox/core/CorePrereqs.h
r947 r952 91 91 class ClassTreeMaskIterator; 92 92 class ClassTreeMaskNode; 93 class CommandEvaluation; 93 94 class CommandExecutor; 94 95 class ConfigValueContainer; … … 106 107 class Identifier; 107 108 class IdentifierDistributor; 109 class InputBuffer; 110 class InputBufferListener; 108 111 template <class T> 109 112 class Iterator; … … 123 126 class OrxonoxClass; 124 127 class OutputHandler; 128 class Shell; 125 129 template <class T> 126 130 class SubclassIdentifier;
Note: See TracChangeset
for help on using the changeset viewer.