Changeset 951 for code/branches/core2
- Timestamp:
- Mar 29, 2008, 3:37:44 AM (17 years ago)
- Location:
- code/branches/core2/src/orxonox/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/CommandExecutor.cc
r949 r951 53 53 bool CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor) 54 54 { 55 CommandExecutor::getInstance().consoleCommandShortcuts_ s[executor->getName()] = executor;56 CommandExecutor::getInstance().consoleCommandShortcuts_LC_ s[getLowercase(executor->getName())] = executor;55 CommandExecutor::getInstance().consoleCommandShortcuts_[executor->getName()] = executor; 56 CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(executor->getName())] = executor; 57 57 return true; 58 58 } … … 65 65 ExecutorStatic* CommandExecutor::getConsoleCommandShortcut(const std::string& name) 66 66 { 67 std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_ s.find(name);68 if (it != CommandExecutor::getInstance().consoleCommandShortcuts_ s.end())67 std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name); 68 if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end()) 69 69 return (*it).second; 70 70 else … … 79 79 ExecutorStatic* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name) 80 80 { 81 std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_ s.find(name);82 if (it != CommandExecutor::getInstance().consoleCommandShortcuts_LC_ s.end())81 std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name); 82 if (it != CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end()) 83 83 return (*it).second; 84 84 else … … 88 88 bool CommandExecutor::execute(const std::string& command) 89 89 { 90 if (CommandExecutor::getInstance().lastProcessedCommand_ s!= command)90 if (CommandExecutor::getInstance().lastProcessedCommand_ != command) 91 91 CommandExecutor::parse(command); 92 92 93 CommandExecutor::getInstance().tokens_ s.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');94 95 switch (CommandExecutor::getInstance().state_ s)93 CommandExecutor::getInstance().tokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 94 95 switch (CommandExecutor::getInstance().state_) 96 96 { 97 97 case CS_Empty: … … 104 104 case CS_Shortcut_Finished: 105 105 // call the shortcut 106 if (CommandExecutor::getInstance().shortcut_ s!= 0)107 return CommandExecutor::getInstance().shortcut_ s->parse(CommandExecutor::getInstance().tokens_s.subSet(1).join());106 if (CommandExecutor::getInstance().shortcut_ != 0) 107 return CommandExecutor::getInstance().shortcut_->parse(CommandExecutor::getInstance().tokens_.subSet(1).join()); 108 108 break; 109 109 case CS_Function: … … 114 114 case CS_Function_Finished: 115 115 // call the shortcut 116 if (CommandExecutor::getInstance().function_ s!= 0)117 return CommandExecutor::getInstance().function_ s->parse(CommandExecutor::getInstance().tokens_s.subSet(2).join());116 if (CommandExecutor::getInstance().function_ != 0) 117 return CommandExecutor::getInstance().function_->parse(CommandExecutor::getInstance().tokens_.subSet(2).join()); 118 118 break; 119 119 case CS_ConfigValueClass: … … 126 126 case CS_ConfigValueFinished: 127 127 // set the config value 128 if (CommandExecutor::getInstance().configvalue_ s!= 0)129 return CommandExecutor::getInstance().configvalue_ s->parseString(CommandExecutor::getInstance().tokens_s.subSet(3).join());128 if (CommandExecutor::getInstance().configvalue_ != 0) 129 return CommandExecutor::getInstance().configvalue_->parseString(CommandExecutor::getInstance().tokens_.subSet(3).join()); 130 130 break; 131 131 case CS_KeybindKey: … … 147 147 std::string CommandExecutor::complete(const std::string& command) 148 148 { 149 if (CommandExecutor::getInstance().lastProcessedCommand_ s!= command)149 if (CommandExecutor::getInstance().lastProcessedCommand_ != command) 150 150 CommandExecutor::parse(command); 151 151 152 CommandExecutor::getInstance().tokens_ s.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');152 CommandExecutor::getInstance().tokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 153 153 154 154 std::list<const std::string*> temp; 155 if (CommandExecutor::getInstance().state_ s== CS_Empty)156 { 157 temp.insert(temp.end(), CommandExecutor::getInstance().listOfPossibleShortcuts_ s.begin(), CommandExecutor::getInstance().listOfPossibleShortcuts_s.end());158 temp.insert(temp.end(), CommandExecutor::getInstance().listOfPossibleFunctionClasses_ s.begin(), CommandExecutor::getInstance().listOfPossibleFunctionClasses_s.end());159 } 160 161 switch (CommandExecutor::getInstance().state_ s)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_) 162 162 { 163 163 case CS_Empty: 164 return (CommandExecutor::getInstance().tokens_ s.subSet(0, CommandExecutor::getInstance().tokens_s.size() - 1).join() + " " + CommandExecutor::getCommonBegin(temp));164 return (CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(temp)); 165 165 break; 166 166 case CS_FunctionClass_Or_Shortcut_Or_Keyword: … … 173 173 break; 174 174 case CS_Function: 175 return (CommandExecutor::getInstance().tokens_ s.subSet(0, CommandExecutor::getInstance().tokens_s.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleFunctions_s));175 return (CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleFunctions_)); 176 176 break; 177 177 case CS_Function_Params: … … 182 182 break; 183 183 case CS_ConfigValueClass: 184 return (CommandExecutor::getInstance().tokens_ s.subSet(0, CommandExecutor::getInstance().tokens_s.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleConfigValueClasses_s));184 return (CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleConfigValueClasses_)); 185 185 break; 186 186 case CS_ConfigValue: 187 return (CommandExecutor::getInstance().tokens_ s.subSet(0, CommandExecutor::getInstance().tokens_s.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleConfigValues_s));187 return (CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleConfigValues_)); 188 188 break; 189 189 case CS_ConfigValueType: … … 194 194 break; 195 195 case CS_KeybindKey: 196 return (CommandExecutor::getInstance().tokens_ s.subSet(0, CommandExecutor::getInstance().tokens_s.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleKeys_s));196 return (CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleKeys_)); 197 197 break; 198 198 case CS_KeybindCommand: … … 206 206 } 207 207 208 return CommandExecutor::getInstance().lastProcessedCommand_ s;208 return CommandExecutor::getInstance().lastProcessedCommand_; 209 209 } 210 210 211 211 std::string CommandExecutor::hint(const std::string& command) 212 212 { 213 if (CommandExecutor::getInstance().lastProcessedCommand_ s!= command)213 if (CommandExecutor::getInstance().lastProcessedCommand_ != command) 214 214 CommandExecutor::parse(command); 215 215 216 CommandExecutor::getInstance().tokens_ s.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');217 218 switch (CommandExecutor::getInstance().state_ s)216 CommandExecutor::getInstance().tokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 217 218 switch (CommandExecutor::getInstance().state_) 219 219 { 220 220 case CS_Empty: 221 return (CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleShortcuts_ s) + "\n" + CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleFunctionClasses_s));221 return (CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleShortcuts_) + "\n" + CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleFunctionClasses_)); 222 222 break; 223 223 case CS_FunctionClass_Or_Shortcut_Or_Keyword: 224 224 break; 225 225 case CS_Shortcut_Params: 226 if (CommandExecutor::getInstance().shortcut_ s!= 0)227 return CommandExecutor::dump(CommandExecutor::getInstance().shortcut_ s);226 if (CommandExecutor::getInstance().shortcut_ != 0) 227 return CommandExecutor::dump(CommandExecutor::getInstance().shortcut_); 228 228 break; 229 229 case CS_Shortcut_Finished: 230 if (CommandExecutor::getInstance().shortcut_ s!= 0)231 return CommandExecutor::dump(CommandExecutor::getInstance().shortcut_ s);230 if (CommandExecutor::getInstance().shortcut_ != 0) 231 return CommandExecutor::dump(CommandExecutor::getInstance().shortcut_); 232 232 break; 233 233 case CS_Function: 234 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleFunctions_ s);234 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleFunctions_); 235 235 break; 236 236 case CS_Function_Params: 237 if (CommandExecutor::getInstance().function_ s!= 0)238 return CommandExecutor::dump(CommandExecutor::getInstance().function_ s);237 if (CommandExecutor::getInstance().function_ != 0) 238 return CommandExecutor::dump(CommandExecutor::getInstance().function_); 239 239 break; 240 240 case CS_Function_Finished: 241 if (CommandExecutor::getInstance().function_ s!= 0)242 return CommandExecutor::dump(CommandExecutor::getInstance().function_ s);241 if (CommandExecutor::getInstance().function_ != 0) 242 return CommandExecutor::dump(CommandExecutor::getInstance().function_); 243 243 break; 244 244 case CS_ConfigValueClass: 245 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleConfigValueClasses_ s);245 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleConfigValueClasses_); 246 246 break; 247 247 case CS_ConfigValue: 248 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleConfigValues_ s);248 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleConfigValues_); 249 249 break; 250 250 case CS_ConfigValueType: 251 if (CommandExecutor::getInstance().configvalue_ s!= 0)252 return CommandExecutor::dump(CommandExecutor::getInstance().configvalue_ s);251 if (CommandExecutor::getInstance().configvalue_ != 0) 252 return CommandExecutor::dump(CommandExecutor::getInstance().configvalue_); 253 253 break; 254 254 case CS_ConfigValueFinished: 255 if (CommandExecutor::getInstance().configvalue_ s!= 0)256 return CommandExecutor::dump(CommandExecutor::getInstance().configvalue_ s);255 if (CommandExecutor::getInstance().configvalue_ != 0) 256 return CommandExecutor::dump(CommandExecutor::getInstance().configvalue_); 257 257 break; 258 258 case CS_KeybindKey: 259 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleKeys_ s);259 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleKeys_); 260 260 break; 261 261 case CS_KeybindCommand: 262 if (CommandExecutor::getInstance().key_ s!= 0)263 return CommandExecutor::dump(CommandExecutor::getInstance().key_ s);262 if (CommandExecutor::getInstance().key_ != 0) 263 return CommandExecutor::dump(CommandExecutor::getInstance().key_); 264 264 break; 265 265 case CS_KeybindFinished: 266 if (CommandExecutor::getInstance().key_ s!= 0)267 return CommandExecutor::dump(CommandExecutor::getInstance().key_ s);266 if (CommandExecutor::getInstance().key_ != 0) 267 return CommandExecutor::dump(CommandExecutor::getInstance().key_); 268 268 break; 269 269 case CS_Error: … … 277 277 void CommandExecutor::parse(const std::string& command, bool bInitialize) 278 278 { 279 CommandExecutor::getInstance().tokens_ s.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');280 CommandExecutor::getInstance().lastProcessedCommand_ s= command;279 CommandExecutor::getInstance().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 280 CommandExecutor::getInstance().lastProcessedCommand_ = command; 281 281 282 282 if (bInitialize) 283 283 CommandExecutor::initialize(); 284 284 285 switch (CommandExecutor::getInstance().state_ s)285 switch (CommandExecutor::getInstance().state_) 286 286 { 287 287 case CS_Empty: … … 290 290 // We want a hint for the first token 291 291 // Check if there is already a perfect match 292 CommandExecutor::getInstance().functionclass_ s= CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));293 CommandExecutor::getInstance().shortcut_ s= CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));294 295 if ((CommandExecutor::getInstance().functionclass_ s != 0) || (CommandExecutor::getInstance().shortcut_s!= 0))292 CommandExecutor::getInstance().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0)); 293 CommandExecutor::getInstance().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0)); 294 295 if ((CommandExecutor::getInstance().functionclass_ != 0) || (CommandExecutor::getInstance().shortcut_ != 0)) 296 296 { 297 297 // Yes, there is a class or a shortcut with the searched name 298 298 // Add a whitespace and continue parsing 299 CommandExecutor::getInstance().state_ s= CS_FunctionClass_Or_Shortcut_Or_Keyword;299 CommandExecutor::getInstance().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword; 300 300 CommandExecutor::parse(command + " ", false); 301 301 return; … … 310 310 { 311 311 // There is at least one argument: Check if it's a shortcut, a classname or a special keyword 312 CommandExecutor::getInstance().state_ s= CS_FunctionClass_Or_Shortcut_Or_Keyword;312 CommandExecutor::getInstance().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword; 313 313 CommandExecutor::parse(command, false); 314 314 return; … … 321 321 { 322 322 // We want to set a config value 323 CommandExecutor::getInstance().state_ s= CS_ConfigValueClass;323 CommandExecutor::getInstance().state_ = CS_ConfigValueClass; 324 324 CommandExecutor::parse(command, false); 325 325 return; … … 328 328 { 329 329 // We want to set a keybinding 330 CommandExecutor::getInstance().state_ s= CS_KeybindKey;330 CommandExecutor::getInstance().state_ = CS_KeybindKey; 331 331 CommandExecutor::parse(command, false); 332 332 return; 333 333 } 334 334 335 if (CommandExecutor::getInstance().functionclass_ s== 0)336 CommandExecutor::getInstance().functionclass_ s= CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));337 if (CommandExecutor::getInstance().shortcut_ s== 0)338 CommandExecutor::getInstance().shortcut_ s= CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));339 340 if ((CommandExecutor::getInstance().functionclass_ s == 0) && (CommandExecutor::getInstance().shortcut_s== 0))335 if (CommandExecutor::getInstance().functionclass_ == 0) 336 CommandExecutor::getInstance().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0)); 337 if (CommandExecutor::getInstance().shortcut_ == 0) 338 CommandExecutor::getInstance().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0)); 339 340 if ((CommandExecutor::getInstance().functionclass_ == 0) && (CommandExecutor::getInstance().shortcut_ == 0)) 341 341 { 342 342 // Argument 1 seems to be wrong 343 343 AddLanguageEntry("CommandExecutor::NoSuchCommandOrClassName", "No such command or classname"); 344 CommandExecutor::getInstance().errorMessage_ s= (CommandExecutor::getToken(0) + ": " + GetLocalisation("CommandExecutor::NoSuchCommandOrClassName"));345 CommandExecutor::getInstance().state_ s= CS_Error;346 return; 347 } 348 else if (CommandExecutor::getInstance().shortcut_ s!= 0)344 CommandExecutor::getInstance().errorMessage_ = (CommandExecutor::getToken(0) + ": " + GetLocalisation("CommandExecutor::NoSuchCommandOrClassName")); 345 CommandExecutor::getInstance().state_ = CS_Error; 346 return; 347 } 348 else if (CommandExecutor::getInstance().shortcut_ != 0) 349 349 { 350 350 // Argument 1 is a shortcut: Return the needed parameter types 351 CommandExecutor::getInstance().state_ s= CS_Shortcut_Params;351 CommandExecutor::getInstance().state_ = CS_Shortcut_Params; 352 352 CommandExecutor::parse(command, false); 353 353 return; … … 356 356 { 357 357 // Argument 1 is a classname: Return the possible functions 358 CommandExecutor::getInstance().state_ s= CS_Function;358 CommandExecutor::getInstance().state_ = CS_Function; 359 359 CommandExecutor::parse(command, false); 360 360 return; … … 363 363 else 364 364 { 365 CommandExecutor::getInstance().state_ s= CS_Error;365 CommandExecutor::getInstance().state_ = CS_Error; 366 366 return; 367 367 } 368 368 break; 369 369 case CS_Shortcut_Params: 370 if (CommandExecutor::getInstance().shortcut_ s!= 0)370 if (CommandExecutor::getInstance().shortcut_ != 0) 371 371 { 372 372 // Valid command 373 373 // Check if there are enough parameters 374 if (CommandExecutor::enoughParametersGiven(1, CommandExecutor::getInstance().shortcut_ s))375 { 376 CommandExecutor::getInstance().state_ s= CS_Shortcut_Finished;374 if (CommandExecutor::enoughParametersGiven(1, CommandExecutor::getInstance().shortcut_)) 375 { 376 CommandExecutor::getInstance().state_ = CS_Shortcut_Finished; 377 377 return; 378 378 } … … 381 381 { 382 382 // Something is wrong 383 CommandExecutor::getInstance().state_ s= CS_Error;383 CommandExecutor::getInstance().state_ = CS_Error; 384 384 return; 385 385 } 386 386 break; 387 387 case CS_Function: 388 if (CommandExecutor::getInstance().functionclass_ s!= 0)388 if (CommandExecutor::getInstance().functionclass_ != 0) 389 389 { 390 390 // We have a valid classname … … 393 393 { 394 394 // There is a second argument: Check if it's a valid functionname 395 CommandExecutor::getInstance().function_ s = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getInstance().functionclass_s);396 if (CommandExecutor::getInstance().function_ s== 0)395 CommandExecutor::getInstance().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getInstance().functionclass_); 396 if (CommandExecutor::getInstance().function_ == 0) 397 397 { 398 398 // Argument 2 seems to be wrong 399 399 AddLanguageEntry("CommandExecutor::NoSuchFunctionnameIn", "No such functionname in"); 400 CommandExecutor::getInstance().errorMessage_ s = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchFunctionnameIn") + " " + CommandExecutor::getInstance().functionclass_s->getName());401 CommandExecutor::getInstance().state_ s= CS_Error;400 CommandExecutor::getInstance().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchFunctionnameIn") + " " + CommandExecutor::getInstance().functionclass_->getName()); 401 CommandExecutor::getInstance().state_ = CS_Error; 402 402 return; 403 403 } … … 405 405 { 406 406 // Argument 2 seems to be a valid functionname: Get the parameters 407 CommandExecutor::getInstance().state_ s= CS_Function_Params;407 CommandExecutor::getInstance().state_ = CS_Function_Params; 408 408 CommandExecutor::parse(command, false); 409 409 return; … … 414 414 // There is no finished second argument 415 415 // Check if there's already a perfect match 416 if (CommandExecutor::getInstance().tokens_ s.size() >= 2)417 { 418 CommandExecutor::getInstance().function_ s = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getInstance().functionclass_s);419 if (CommandExecutor::getInstance().function_ s!= 0)416 if (CommandExecutor::getInstance().tokens_.size() >= 2) 417 { 418 CommandExecutor::getInstance().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getInstance().functionclass_); 419 if (CommandExecutor::getInstance().function_ != 0) 420 420 { 421 421 // There is a perfect match: Add a whitespace and continue parsing 422 CommandExecutor::getInstance().state_ s= CS_Function_Params;422 CommandExecutor::getInstance().state_ = CS_Function_Params; 423 423 CommandExecutor::parse(command + " ", false); 424 424 return; … … 427 427 428 428 // No perfect match: Create the list of all possible functions and return 429 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getToken(1), CommandExecutor::getInstance().functionclass_ s);429 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getToken(1), CommandExecutor::getInstance().functionclass_); 430 430 return; 431 431 } … … 433 433 else 434 434 { 435 CommandExecutor::getInstance().state_ s= CS_Error;435 CommandExecutor::getInstance().state_ = CS_Error; 436 436 return; 437 437 } 438 438 break; 439 439 case CS_Function_Params: 440 if ((CommandExecutor::getInstance().functionclass_ s != 0) && (CommandExecutor::getInstance().function_s!= 0))440 if ((CommandExecutor::getInstance().functionclass_ != 0) && (CommandExecutor::getInstance().function_ != 0)) 441 441 { 442 442 // Valid command 443 443 // Check if there are enough parameters 444 if (CommandExecutor::enoughParametersGiven(2, CommandExecutor::getInstance().function_ s))445 { 446 CommandExecutor::getInstance().state_ s= CS_Function_Finished;444 if (CommandExecutor::enoughParametersGiven(2, CommandExecutor::getInstance().function_)) 445 { 446 CommandExecutor::getInstance().state_ = CS_Function_Finished; 447 447 return; 448 448 } … … 451 451 { 452 452 // Something is wrong 453 CommandExecutor::getInstance().state_ s= CS_Error;453 CommandExecutor::getInstance().state_ = CS_Error; 454 454 return; 455 455 } … … 463 463 { 464 464 // There is a second argument: Check if it's a valid classname 465 CommandExecutor::getInstance().configvalueclass_ s= CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));466 if (CommandExecutor::getInstance().configvalueclass_ s== 0)465 CommandExecutor::getInstance().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1)); 466 if (CommandExecutor::getInstance().configvalueclass_ == 0) 467 467 { 468 468 // Argument 2 seems to be wrong 469 469 AddLanguageEntry("CommandExecutor::NoSuchClassWithConfigValues", "No such class with config values"); 470 CommandExecutor::getInstance().errorMessage_ s= (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchClassWithConfigValues"));471 CommandExecutor::getInstance().state_ s= CS_Error;470 CommandExecutor::getInstance().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchClassWithConfigValues")); 471 CommandExecutor::getInstance().state_ = CS_Error; 472 472 return; 473 473 } … … 475 475 { 476 476 // Argument 2 seems to be a valid classname: Search for possible config values 477 CommandExecutor::getInstance().state_ s= CS_ConfigValue;477 CommandExecutor::getInstance().state_ = CS_ConfigValue; 478 478 CommandExecutor::parse(command, false); 479 479 return; … … 484 484 // There's no finished second argument 485 485 // Check if there's already a perfect match 486 if (CommandExecutor::getInstance().tokens_ s.size() >= 2)487 { 488 CommandExecutor::getInstance().configvalueclass_ s= CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));489 if (CommandExecutor::getInstance().configvalueclass_ s!= 0)486 if (CommandExecutor::getInstance().tokens_.size() >= 2) 487 { 488 CommandExecutor::getInstance().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1)); 489 if (CommandExecutor::getInstance().configvalueclass_ != 0) 490 490 { 491 491 // There is a perfect match: Add a whitespace and continue parsing 492 CommandExecutor::getInstance().state_ s= CS_ConfigValue;492 CommandExecutor::getInstance().state_ = CS_ConfigValue; 493 493 CommandExecutor::parse(command + " ", false); 494 494 return; … … 504 504 { 505 505 // Something is wrong 506 CommandExecutor::getInstance().state_ s= CS_Error;506 CommandExecutor::getInstance().state_ = CS_Error; 507 507 return; 508 508 } 509 509 break; 510 510 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::getInstance().configvalueclass_ s!= 0))511 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getInstance().configvalueclass_ != 0)) 512 512 { 513 513 // Check if there is a third argument … … 515 515 { 516 516 // There is a third argument: Check if it's a valid config value 517 CommandExecutor::getInstance().configvalue_ s = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getInstance().configvalueclass_s);518 if (CommandExecutor::getInstance().configvalue_ s== 0)517 CommandExecutor::getInstance().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getInstance().configvalueclass_); 518 if (CommandExecutor::getInstance().configvalue_ == 0) 519 519 { 520 520 // Argument 3 seems to be wrong 521 521 AddLanguageEntry("CommandExecutor::NoSuchConfigValueIn", "No such config value in"); 522 CommandExecutor::getInstance().errorMessage_ s = (CommandExecutor::getToken(2) + ": " + GetLocalisation("CommandExecutor::NoSuchConfigValueIn") + " " + CommandExecutor::getInstance().configvalueclass_s->getName());523 CommandExecutor::getInstance().state_ s= CS_Error;522 CommandExecutor::getInstance().errorMessage_ = (CommandExecutor::getToken(2) + ": " + GetLocalisation("CommandExecutor::NoSuchConfigValueIn") + " " + CommandExecutor::getInstance().configvalueclass_->getName()); 523 CommandExecutor::getInstance().state_ = CS_Error; 524 524 return; 525 525 } … … 527 527 { 528 528 // Argument 3 seems to be a valid config value: Get the type 529 CommandExecutor::getInstance().state_ s= CS_ConfigValueType;529 CommandExecutor::getInstance().state_ = CS_ConfigValueType; 530 530 CommandExecutor::parse(command, false); 531 531 return; … … 536 536 // There is no finished third argument 537 537 // Check if there's already a perfect match 538 if (CommandExecutor::getInstance().tokens_ s.size() >= 3)539 { 540 CommandExecutor::getInstance().configvalue_ s = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getInstance().configvalueclass_s);541 if (CommandExecutor::getInstance().configvalueclass_ s!= 0)538 if (CommandExecutor::getInstance().tokens_.size() >= 3) 539 { 540 CommandExecutor::getInstance().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getInstance().configvalueclass_); 541 if (CommandExecutor::getInstance().configvalueclass_ != 0) 542 542 { 543 543 // There is a perfect match: Add a whitespace and continue parsing 544 CommandExecutor::getInstance().state_ s= CS_ConfigValueType;544 CommandExecutor::getInstance().state_ = CS_ConfigValueType; 545 545 CommandExecutor::parse(command + " ", false); 546 546 return; … … 549 549 550 550 // No perfect match: Create the list of all possible config values 551 CommandExecutor::createListOfPossibleConfigValues(CommandExecutor::getToken(2), CommandExecutor::getInstance().configvalueclass_ s);551 CommandExecutor::createListOfPossibleConfigValues(CommandExecutor::getToken(2), CommandExecutor::getInstance().configvalueclass_); 552 552 return; 553 553 } … … 556 556 { 557 557 // Something is wrong 558 CommandExecutor::getInstance().state_ s= CS_Error;558 CommandExecutor::getInstance().state_ = CS_Error; 559 559 return; 560 560 } 561 561 break; 562 562 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::getInstance().configvalueclass_ s != 0) && (CommandExecutor::getInstance().configvalue_s!= 0))563 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getInstance().configvalueclass_ != 0) && (CommandExecutor::getInstance().configvalue_ != 0)) 564 564 { 565 565 // Valid command 566 566 // Check if there are enough parameters 567 if (CommandExecutor::getInstance().tokens_ s.size() >= 4)568 { 569 CommandExecutor::getInstance().state_ s= CS_ConfigValueFinished;567 if (CommandExecutor::getInstance().tokens_.size() >= 4) 568 { 569 CommandExecutor::getInstance().state_ = CS_ConfigValueFinished; 570 570 return; 571 571 } … … 574 574 { 575 575 // Something is wrong 576 CommandExecutor::getInstance().state_ s= CS_Error;576 CommandExecutor::getInstance().state_ = CS_Error; 577 577 return; 578 578 } … … 586 586 { 587 587 // Something is wrong 588 CommandExecutor::getInstance().state_ s= CS_Error;588 CommandExecutor::getInstance().state_ = CS_Error; 589 589 return; 590 590 } … … 595 595 // Valid command 596 596 // Check if there are enough parameters 597 if (CommandExecutor::getInstance().tokens_ s.size() >= 3)598 { 599 CommandExecutor::getInstance().state_ s= CS_KeybindFinished;597 if (CommandExecutor::getInstance().tokens_.size() >= 3) 598 { 599 CommandExecutor::getInstance().state_ = CS_KeybindFinished; 600 600 return; 601 601 } … … 605 605 { 606 606 // Something is wrong 607 CommandExecutor::getInstance().state_ s= CS_Error;607 CommandExecutor::getInstance().state_ = CS_Error; 608 608 return; 609 609 } … … 629 629 void CommandExecutor::initialize() 630 630 { 631 CommandExecutor::getInstance().listOfPossibleFunctionClasses_ s.clear();632 CommandExecutor::getInstance().listOfPossibleShortcuts_ s.clear();633 CommandExecutor::getInstance().listOfPossibleFunctions_ s.clear();634 CommandExecutor::getInstance().listOfPossibleConfigValueClasses_ s.clear();635 CommandExecutor::getInstance().listOfPossibleConfigValues_ s.clear();636 CommandExecutor::getInstance().listOfPossibleKeys_ s.clear();637 638 CommandExecutor::getInstance().functionclass_ s= 0;639 CommandExecutor::getInstance().configvalueclass_ s= 0;640 CommandExecutor::getInstance().shortcut_ s= 0;641 CommandExecutor::getInstance().function_ s= 0;642 CommandExecutor::getInstance().configvalue_ s= 0;643 CommandExecutor::getInstance().key_ s= 0;644 645 CommandExecutor::getInstance().errorMessage_ s= "";646 CommandExecutor::getInstance().state_ s= CS_Empty;631 CommandExecutor::getInstance().listOfPossibleFunctionClasses_.clear(); 632 CommandExecutor::getInstance().listOfPossibleShortcuts_.clear(); 633 CommandExecutor::getInstance().listOfPossibleFunctions_.clear(); 634 CommandExecutor::getInstance().listOfPossibleConfigValueClasses_.clear(); 635 CommandExecutor::getInstance().listOfPossibleConfigValues_.clear(); 636 CommandExecutor::getInstance().listOfPossibleKeys_.clear(); 637 638 CommandExecutor::getInstance().functionclass_ = 0; 639 CommandExecutor::getInstance().configvalueclass_ = 0; 640 CommandExecutor::getInstance().shortcut_ = 0; 641 CommandExecutor::getInstance().function_ = 0; 642 CommandExecutor::getInstance().configvalue_ = 0; 643 CommandExecutor::getInstance().key_ = 0; 644 645 CommandExecutor::getInstance().errorMessage_ = ""; 646 CommandExecutor::getInstance().state_ = CS_Empty; 647 647 } 648 648 … … 651 651 // Because we added a cursor we have +1 arguments 652 652 // There are num arguments given if there are at least num arguments + one cursor 653 return (CommandExecutor::getInstance().tokens_ s.size() >= (num + 1));653 return (CommandExecutor::getInstance().tokens_.size() >= (num + 1)); 654 654 } 655 655 … … 657 657 { 658 658 // Because we added a cursor we have +1 arguments 659 if (CommandExecutor::getInstance().tokens_ s.size() >= 1)660 return (CommandExecutor::getInstance().tokens_ s.size() - 1);659 if (CommandExecutor::getInstance().tokens_.size() >= 1) 660 return (CommandExecutor::getInstance().tokens_.size() - 1); 661 661 else 662 662 return 0; … … 665 665 std::string CommandExecutor::getToken(unsigned int index) 666 666 { 667 if ((index >= 0) && (index < (CommandExecutor::getInstance().tokens_ s.size() - 1)))668 return CommandExecutor::getInstance().tokens_ s[index];669 else if (index == (CommandExecutor::getInstance().tokens_ s.size() - 1))670 return CommandExecutor::getInstance().tokens_ s[index].substr(0, CommandExecutor::getInstance().tokens_s[index].size() - 1);667 if ((index >= 0) && (index < (CommandExecutor::getInstance().tokens_.size() - 1))) 668 return CommandExecutor::getInstance().tokens_[index]; 669 else if (index == (CommandExecutor::getInstance().tokens_.size() - 1)) 670 return CommandExecutor::getInstance().tokens_[index].substr(0, CommandExecutor::getInstance().tokens_[index].size() - 1); 671 671 else 672 672 return ""; … … 683 683 break; 684 684 } 685 return (CommandExecutor::getInstance().tokens_ s.size() >= neededParams);685 return (CommandExecutor::getInstance().tokens_.size() >= neededParams); 686 686 } 687 687 … … 694 694 if ((*it).first.find(getLowercase(fragment)) == 0) 695 695 { 696 CommandExecutor::getInstance().listOfPossibleFunctionClasses_ s.push_back(&(*it).first);696 CommandExecutor::getInstance().listOfPossibleFunctionClasses_.push_back(&(*it).first); 697 697 } 698 698 } 699 699 } 700 700 701 CommandExecutor::getInstance().listOfPossibleFunctionClasses_ s.sort(CommandExecutor::compareStringsInList);701 CommandExecutor::getInstance().listOfPossibleFunctionClasses_.sort(CommandExecutor::compareStringsInList); 702 702 } 703 703 … … 708 708 if ((*it).first.find(getLowercase(fragment)) == 0) 709 709 { 710 CommandExecutor::getInstance().listOfPossibleShortcuts_ s.push_back(&(*it).first);710 CommandExecutor::getInstance().listOfPossibleShortcuts_.push_back(&(*it).first); 711 711 } 712 712 } 713 713 714 CommandExecutor::getInstance().listOfPossibleShortcuts_ s.sort(CommandExecutor::compareStringsInList);714 CommandExecutor::getInstance().listOfPossibleShortcuts_.sort(CommandExecutor::compareStringsInList); 715 715 } 716 716 … … 721 721 if ((*it).first.find(getLowercase(fragment)) == 0) 722 722 { 723 CommandExecutor::getInstance().listOfPossibleFunctions_ s.push_back(&(*it).first);723 CommandExecutor::getInstance().listOfPossibleFunctions_.push_back(&(*it).first); 724 724 } 725 725 } 726 726 727 CommandExecutor::getInstance().listOfPossibleFunctions_ s.sort(CommandExecutor::compareStringsInList);727 CommandExecutor::getInstance().listOfPossibleFunctions_.sort(CommandExecutor::compareStringsInList); 728 728 } 729 729 … … 736 736 if ((*it).first.find(getLowercase(fragment)) == 0) 737 737 { 738 CommandExecutor::getInstance().listOfPossibleConfigValueClasses_ s.push_back(&(*it).first);738 CommandExecutor::getInstance().listOfPossibleConfigValueClasses_.push_back(&(*it).first); 739 739 } 740 740 } 741 741 } 742 742 743 CommandExecutor::getInstance().listOfPossibleConfigValueClasses_ s.sort(CommandExecutor::compareStringsInList);743 CommandExecutor::getInstance().listOfPossibleConfigValueClasses_.sort(CommandExecutor::compareStringsInList); 744 744 } 745 745 … … 750 750 if ((*it).first.find(getLowercase(fragment)) == 0) 751 751 { 752 CommandExecutor::getInstance().listOfPossibleConfigValues_ s.push_back(&(*it).first);752 CommandExecutor::getInstance().listOfPossibleConfigValues_.push_back(&(*it).first); 753 753 } 754 754 } 755 755 756 CommandExecutor::getInstance().listOfPossibleConfigValues_ s.sort(CommandExecutor::compareStringsInList);756 CommandExecutor::getInstance().listOfPossibleConfigValues_.sort(CommandExecutor::compareStringsInList); 757 757 } 758 758 … … 761 761 // todo 762 762 763 CommandExecutor::getInstance().listOfPossibleKeys_ s.sort(CommandExecutor::compareStringsInList);763 CommandExecutor::getInstance().listOfPossibleKeys_.sort(CommandExecutor::compareStringsInList); 764 764 } 765 765 -
code/branches/core2/src/orxonox/core/CommandExecutor.h
r950 r951 71 71 72 72 /** @brief Returns the map that stores all console commands. @return The const_iterator */ 73 static inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_ s; }73 static inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; } 74 74 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */ 75 static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_ s.begin(); }75 static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); } 76 76 /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */ 77 static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_ s.end(); }77 static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); } 78 78 79 79 /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */ 80 static inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_ s; }80 static inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; } 81 81 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 82 static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_ s.begin(); }82 static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); } 83 83 /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 84 static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_ s.end(); }84 static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); } 85 85 86 86 private: … … 123 123 static ConfigValueContainer* getContainerOfPossibleKey(const std::string& name); 124 124 125 std::string lastProcessedCommand_ s;126 SubString tokens_ s;127 std::list<const std::string*> listOfPossibleFunctionClasses_ s;128 std::list<const std::string*> listOfPossibleShortcuts_ s;129 std::list<const std::string*> listOfPossibleFunctions_ s;130 std::list<const std::string*> listOfPossibleConfigValueClasses_ s;131 std::list<const std::string*> listOfPossibleConfigValues_ s;132 std::list<const std::string*> listOfPossibleKeys_ s;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 133 134 Identifier* functionclass_ s;135 Identifier* configvalueclass_ s;136 ExecutorStatic* shortcut_ s;137 ExecutorStatic* function_ s;138 ConfigValueContainer* configvalue_ s;139 ConfigValueContainer* key_ s;134 Identifier* functionclass_; 135 Identifier* configvalueclass_; 136 ExecutorStatic* shortcut_; 137 ExecutorStatic* function_; 138 ConfigValueContainer* configvalue_; 139 ConfigValueContainer* key_; 140 140 141 std::string errorMessage_ s;142 CommandState state_ s;141 std::string errorMessage_; 142 CommandState state_; 143 143 144 std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_ s;145 std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_LC_ s;144 std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_; 145 std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_LC_; 146 146 }; 147 147 }
Note: See TracChangeset
for help on using the changeset viewer.