Changeset 1446
- Timestamp:
- May 28, 2008, 5:30:11 AM (16 years ago)
- Location:
- code/branches/network
- Files:
-
- 62 edited
- 20 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/CMakeLists.txt
r1445 r1446 68 68 FIND_PACKAGE(ENet) 69 69 FIND_PACKAGE(Boost REQUIRED thread) 70 FIND_PACKAGE(Boost REQUIRED filesystem) 70 71 FIND_PACKAGE(OpenAL) 71 72 FIND_PACKAGE(ALUT) -
code/branches/network/bin/disco.txt
r1069 r1446 2 2 delay 0.2 Ambient setAmbientLightTest 0,1,0,1 3 3 delay 0.4 Ambient setAmbientLightTest 0,0,1,1 4 delay 0.6 execdisco.txt4 delay 0.6 source disco.txt -
code/branches/network/cmake/FindBoost.cmake
r1293 r1446 102 102 SET(SUFFIX_FOR_PATH 103 103 boost 104 boost-1_35_0 105 boost-1_35 104 106 boost-1_34_1 105 107 boost-1_34_0 … … 113 115 # 114 116 IF(WIN32) 115 SET(Boost_INCLUDE_DIR ../libs/boost_1_33_1) 117 SET(Boost_INCLUDE_DIR 118 # ../libs/boost_1_33_1 119 ../libs/boost_1_34_1 120 # ../libs/boost_1_35_0 121 ) 116 122 ELSE(WIN32) 117 123 FIND_PATH(Boost_INCLUDE_DIR NAMES boost/config.hpp PATH_SUFFIXES ${SUFFIX_FOR_PATH} PATHS … … 188 194 gcc-1_33_1 189 195 gcc-mt-1_33_1 196 mgw34-mt-1_34_1 197 mgw34-mt-1_35 190 198 ) 191 199 -
code/branches/network/src/audio/AudioStream.cc
r1064 r1446 117 117 118 118 for(int i = 0; i < vorbisComment->comments; i++) 119 { 119 120 COUT(3) << " " << vorbisComment->user_comments[i] << std::endl; 121 } 120 122 121 123 COUT(3) << std::endl; -
code/branches/network/src/core/CMakeLists.txt
r1413 r1446 2 2 BaseObject.cc 3 3 ClassTreeMask.cc 4 CommandExecutor.cc5 4 ConfigFileManager.cc 6 5 ConfigValueContainer.cc … … 11 10 Identifier.cc 12 11 IdentifierDistributor.cc 13 InputBuffer.cc14 12 InputManager.cc 15 13 KeyBinder.cc 14 OutputBuffer.cc 15 InputBuffer.cc 16 Shell.cc 17 CommandExecutor.cc 18 CommandEvaluation.cc 19 ConsoleCommand.cc 20 ArgumentCompletionFunctions.cc 21 ConsoleCommandCompilation.cc 16 22 Language.cc 17 23 Loader.cc … … 26 32 Tickable.cc 27 33 XMLPort.cc 34 TclThreadManager.cc 35 IRC.cc 28 36 tolua/tolua_bind.cc 29 37 ) … … 37 45 ) 38 46 39 ADD_LIBRARY(core SHARED ${CORE_SRC_FILES}) 47 IF(WIN32) 48 ADD_LIBRARY(core ${CORE_SRC_FILES}) 49 ELSE(WIN32) 50 ADD_LIBRARY(core SHARED ${CORE_SRC_FILES}) 51 ENDIF(WIN32) 40 52 41 53 TARGET_LINK_LIBRARIES(core … … 47 59 ois 48 60 util 61 ${Boost_thread_LIBRARIES} 62 ${Boost_filesystem_LIBRARIES} 49 63 ) -
code/branches/network/src/core/ClassManager.h
r1062 r1446 49 49 #include "Identifier.h" 50 50 #include "IdentifierDistributor.h" 51 #include "Debug.h" 51 52 52 53 namespace orxonox -
code/branches/network/src/core/CommandEvaluation.h
r1445 r1446 69 69 bool isValid() const; 70 70 71 inline ConsoleCommand* getConsoleCommand() const 72 { return this->function_; } 73 inline const std::string& getOriginalCommand() const 74 { return this->originalCommand_; } 75 inline const std::string& getCommand() const 76 { return this->command_; } 77 71 78 inline void setAdditionalParameter(const std::string& param) 72 79 { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; } -
code/branches/network/src/core/CommandExecutor.cc
r1391 r1446 31 31 #include "util/String.h" 32 32 #include "util/Convert.h" 33 #include "util/SubString.h"34 33 #include "Identifier.h" 35 34 #include "Language.h" 36 35 #include "Debug.h" 37 #include "Executor.h"38 #include "ConfigValueContainer.h"39 36 #include "TclBind.h" 40 41 #define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE "set"42 #define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY "tset"43 #define COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND "bind"44 37 45 38 namespace orxonox 46 39 { 47 ConsoleCommandShortcutGeneric(keyword1, createExecutor((FunctorStatic*)0, "set", AccessLevel::User));48 ConsoleCommandShortcutGeneric(keyword2, createExecutor((FunctorStatic*)0, "tset", AccessLevel::User));49 ConsoleCommandShortcutGeneric(keyword3, createExecutor((FunctorStatic*)0, "bind", AccessLevel::User));50 51 ConsoleCommandShortcutExtern(exec, AccessLevel::None);52 ConsoleCommandShortcutExtern(echo, AccessLevel::None);53 54 ConsoleCommandShortcutExtern(read, AccessLevel::None);55 ConsoleCommandShortcutExtern(append, AccessLevel::None);56 ConsoleCommandShortcutExtern(write, AccessLevel::None);57 58 void exec(const std::string& filename)59 {60 static std::set<std::string> executingFiles;61 62 std::set<std::string>::const_iterator it = executingFiles.find(filename);63 if (it != executingFiles.end())64 {65 COUT(1) << "Error: Recurring exec command in \"" << filename << "\". Stopped execution." << std::endl;66 return;67 }68 69 // Open the file70 std::ifstream file;71 file.open(filename.c_str(), std::fstream::in);72 73 if (!file.is_open())74 {75 COUT(1) << "Error: Couldn't execute file \"" << filename << "\"." << std::endl;76 return;77 }78 79 executingFiles.insert(filename);80 81 // Iterate through the file and put the lines into the CommandExecutor82 char line[1024];83 while (file.good() && !file.eof())84 {85 file.getline(line, 1024);86 CommandExecutor::execute(line);87 }88 89 executingFiles.erase(filename);90 file.close();91 }92 93 std::string echo(const std::string& text)94 {95 return text;96 }97 98 void write(const std::string& filename, const std::string& text)99 {100 std::ofstream file;101 file.open(filename.c_str(), std::fstream::out);102 103 if (!file.is_open())104 {105 COUT(1) << "Error: Couldn't write to file \"" << filename << "\"." << std::endl;106 return;107 }108 109 file << text << std::endl;110 file.close();111 }112 113 void append(const std::string& filename, const std::string& text)114 {115 std::ofstream file;116 file.open(filename.c_str(), std::fstream::app);117 118 if (!file.is_open())119 {120 COUT(1) << "Error: Couldn't append to file \"" << filename << "\"." << std::endl;121 return;122 }123 124 file << text << std::endl;125 file.close();126 }127 128 std::string read(const std::string& filename)129 {130 std::ifstream file;131 file.open(filename.c_str(), std::fstream::in);132 133 if (!file.is_open())134 {135 COUT(1) << "Error: Couldn't read from file \"" << filename << "\"." << std::endl;136 return "";137 }138 139 std::string output = "";140 char line[1024];141 while (file.good() && !file.eof())142 {143 file.getline(line, 1024);144 output += line;145 output += "\n";146 }147 148 file.close();149 150 return output;151 }152 153 154 ///////////////////////155 // CommandEvaluation //156 ///////////////////////157 CommandEvaluation::CommandEvaluation()158 {159 this->processedCommand_ = "";160 this->additionalParameter_ = "";161 162 this->functionclass_ = 0;163 this->configvalueclass_ = 0;164 this->shortcut_ = 0;165 this->function_ = 0;166 this->configvalue_ = 0;167 this->key_ = 0;168 169 this->errorMessage_ = "";170 this->state_ = CS_Uninitialized;171 172 this->bEvaluatedParams_ = false;173 this->evaluatedExecutor_ = 0;174 }175 176 KeybindMode::Enum CommandEvaluation::getKeybindMode()177 {178 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)179 {180 // if (this->shortcut_ != 0)181 // return this->shortcut_->getKeybindMode();182 }183 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)184 {185 // if (this->function_ != 0)186 // return this->function_->getKeybindMode();187 }188 else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)189 {190 // return KeybindMode::onPress;191 }192 else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)193 {194 // return KeybindMode::onPress;195 }196 else197 {198 // return KeybindMode::onPress;199 }200 // FIXME: Had to insert a return statement201 return (KeybindMode::Enum)0;202 }203 204 bool CommandEvaluation::isValid() const205 {206 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)207 {208 return this->shortcut_;209 }210 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)211 {212 return (this->functionclass_ && this->function_);213 }214 else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)215 {216 return (this->configvalueclass_ && this->configvalue_);217 }218 else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)219 {220 return this->key_;221 }222 else223 {224 return false;225 }226 }227 228 void CommandEvaluation::evaluateParams()229 {230 this->bEvaluatedParams_ = false;231 this->evaluatedExecutor_ = 0;232 233 for (unsigned int i = 0; i < MAX_FUNCTOR_ARGUMENTS; i++)234 this->param_[i] = MT_null;235 236 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)237 {238 if (this->shortcut_)239 {240 if (this->tokens_.size() <= 1)241 {242 if (this->shortcut_->evaluate(this->getAdditionalParameter(), this->param_, " "))243 {244 this->bEvaluatedParams_ = true;245 this->evaluatedExecutor_ = this->shortcut_;246 }247 }248 else if (this->tokens_.size() > 1)249 {250 if (this->shortcut_->evaluate(this->tokens_.subSet(1).join() + this->getAdditionalParameter(), this->param_, " "))251 {252 this->bEvaluatedParams_ = true;253 this->evaluatedExecutor_ = this->shortcut_;254 }255 }256 }257 }258 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)259 {260 if (this->function_)261 {262 if (this->tokens_.size() <= 2)263 {264 if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " "))265 {266 this->bEvaluatedParams_ = true;267 this->evaluatedExecutor_ = this->function_;268 }269 }270 else if (this->tokens_.size() > 2)271 {272 if (this->function_->evaluate(this->tokens_.subSet(2).join() + this->getAdditionalParameter(), this->param_, " "))273 {274 this->bEvaluatedParams_ = true;275 this->evaluatedExecutor_ = this->function_;276 }277 }278 }279 }280 }281 282 void CommandEvaluation::setEvaluatedParameter(unsigned int index, MultiTypeMath param)283 {284 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)285 this->param_[index] = param;286 }287 288 MultiTypeMath CommandEvaluation::getEvaluatedParameter(unsigned int index) const289 {290 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)291 return this->param_[index];292 293 return MT_null;294 }295 296 bool CommandEvaluation::hasReturnvalue() const297 {298 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)299 {300 if (this->shortcut_)301 return this->shortcut_->hasReturnvalue();302 }303 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)304 {305 if (this->function_)306 return this->function_->hasReturnvalue();307 }308 309 return MT_null;310 }311 312 MultiTypeMath CommandEvaluation::getReturnvalue() const313 {314 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)315 {316 if (this->shortcut_)317 return this->shortcut_->getReturnvalue();318 }319 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)320 {321 if (this->function_)322 return this->function_->getReturnvalue();323 }324 325 return MT_null;326 }327 328 329 /////////////////////330 // CommandExecutor //331 /////////////////////332 40 CommandExecutor& CommandExecutor::getInstance() 333 41 { … … 346 54 } 347 55 348 Executor& CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor) 349 { 350 CommandExecutor::getInstance().consoleCommandShortcuts_[executor->getName()] = executor; 351 CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(executor->getName())] = executor; 352 return (*executor); 56 ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command) 57 { 58 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(command->getName()); 59 if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end()) 60 { 61 COUT(2) << "Warning: Overwriting console-command shortcut with name " << command->getName() << "." << std::endl; 62 } 63 64 65 CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command; 66 CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(command->getName())] = command; 67 return (*command); 353 68 } 354 69 … … 358 73 @return The executor of the requested console command shortcut 359 74 */ 360 ExecutorStatic* CommandExecutor::getConsoleCommandShortcut(const std::string& name)361 { 362 std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name);75 ConsoleCommand* CommandExecutor::getConsoleCommandShortcut(const std::string& name) 76 { 77 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name); 363 78 if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end()) 364 79 return (*it).second; … … 372 87 @return The executor of the requested console command shortcut 373 88 */ 374 ExecutorStatic* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name)375 { 376 std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name);89 ConsoleCommand* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name) 90 { 91 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name); 377 92 if (it != CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end()) 378 93 return (*it).second; … … 384 99 { 385 100 if (useTcl) 386 {387 101 return TclBind::eval(command); 388 } 389 else 390 { 391 if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)) 392 CommandExecutor::parse(command); 393 394 return CommandExecutor::execute(CommandExecutor::getEvaluation()); 395 } 396 } 397 398 399 bool CommandExecutor::execute(const CommandEvaluation& evaluation) 400 { 401 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 402 403 if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_) 404 { 405 //std::cout << "CE_execute (evaluation): " << evaluation.evaluatedExecutor_->getName() << " " << evaluation.param_[0] << " " << evaluation.param_[1] << " " << evaluation.param_[2] << " " << evaluation.param_[3] << " " << evaluation.param_[4] << std::endl; 406 (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]); 407 return true; 408 } 409 410 //std::cout << "CE_execute: " << evaluation.processedCommand_ << "\n"; 411 switch (evaluation.state_) 412 { 413 case CS_Uninitialized: 414 break; 415 case CS_Empty: 416 break; 417 case CS_FunctionClass_Or_Shortcut_Or_Keyword: 418 break; 419 case CS_Shortcut_Params: 420 // not enough parameters but lets hope there are some additional parameters and go on 421 case CS_Shortcut_Finished: 422 // call the shortcut 423 if (evaluation.shortcut_) 424 { 425 if (tokens.size() >= 2) 426 return evaluation.shortcut_->parse(removeSlashes(tokens.subSet(1).join() + evaluation.getAdditionalParameter())); 427 else 428 return evaluation.shortcut_->parse(removeSlashes(evaluation.additionalParameter_)); 429 } 430 break; 431 case CS_Function: 432 break; 433 case CS_Function_Params: 434 // not enough parameters but lets hope there are some additional parameters and go on 435 case CS_Function_Finished: 436 // call the shortcut 437 if (evaluation.function_) 438 { 439 if (tokens.size() >= 3) 440 return evaluation.function_->parse(removeSlashes(tokens.subSet(2).join() + evaluation.getAdditionalParameter())); 441 else 442 return evaluation.function_->parse(removeSlashes(evaluation.additionalParameter_)); 443 } 444 break; 445 case CS_ConfigValueClass: 446 break; 447 case CS_ConfigValue: 448 break; 449 case CS_ConfigValueType: 450 // not enough parameters but lets hope there are some additional parameters and go on 451 case CS_ConfigValueFinished: 452 // set the config value 453 if (evaluation.configvalue_) 454 { 455 if ((tokens.size() >= 1) && (tokens[0] == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE)) 456 { 457 if (tokens.size() >= 4) 458 return evaluation.configvalue_->set(removeSlashes(tokens.subSet(3).join() + evaluation.getAdditionalParameter())); 459 else 460 return evaluation.configvalue_->set(removeSlashes(evaluation.additionalParameter_)); 461 } 462 else if ((tokens.size() >= 1) && (tokens[0] == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) 463 { 464 if (tokens.size() >= 4) 465 return evaluation.configvalue_->tset(removeSlashes(tokens.subSet(3).join() + evaluation.getAdditionalParameter())); 466 else 467 return evaluation.configvalue_->tset(removeSlashes(evaluation.additionalParameter_)); 468 } 469 } 470 break; 471 case CS_KeybindKey: 472 break; 473 case CS_KeybindCommand: 474 // not enough parameters but lets hope there are some additional parameters and go on 475 case CS_KeybindFinished: 476 // set the keybind 477 // ...todo 478 break; 479 case CS_Error: 480 break; 481 } 482 483 return false; 102 103 CommandExecutor::parseIfNeeded(command); 104 return CommandExecutor::getEvaluation().execute(); 484 105 } 485 106 486 107 std::string CommandExecutor::complete(const std::string& command) 487 108 { 488 if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)) 489 CommandExecutor::parse(command); 490 491 return CommandExecutor::complete(CommandExecutor::getEvaluation()); 492 } 493 494 std::string CommandExecutor::complete(const CommandEvaluation& evaluation) 495 { 496 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 497 498 std::list<std::pair<const std::string*, const std::string*> > temp; 499 if (evaluation.state_ == CS_Empty) 500 { 501 temp.insert(temp.end(), evaluation.listOfPossibleShortcuts_.begin(), evaluation.listOfPossibleShortcuts_.end()); 502 temp.insert(temp.end(), evaluation.listOfPossibleFunctionClasses_.begin(), evaluation.listOfPossibleFunctionClasses_.end()); 503 } 504 505 switch (evaluation.state_) 506 { 507 case CS_Uninitialized: 508 break; 509 case CS_Empty: 510 return (CommandExecutor::getCommonBegin(temp)); 511 break; 512 case CS_FunctionClass_Or_Shortcut_Or_Keyword: 513 break; 514 case CS_Shortcut_Params: 515 if (evaluation.shortcut_) 516 return (evaluation.shortcut_->getName() + " "); 517 break; 518 case CS_Shortcut_Finished: 519 if (evaluation.shortcut_) 520 { 521 if (evaluation.shortcut_->getParamCount() == 0) 522 return (evaluation.shortcut_->getName()); 523 else if (tokens.size() >= 2) 524 return (evaluation.shortcut_->getName() + " " + tokens.subSet(1).join()); 525 } 526 break; 527 case CS_Function: 528 if (evaluation.functionclass_) 529 return (evaluation.functionclass_->getName() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleFunctions_)); 530 break; 531 case CS_Function_Params: 532 if (evaluation.functionclass_ && evaluation.function_) 533 return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName() + " "); 534 break; 535 case CS_Function_Finished: 536 if (evaluation.functionclass_ && evaluation.function_) 537 { 538 if (evaluation.function_->getParamCount() == 0) 539 return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName()); 540 else if (tokens.size() >= 3) 541 return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName() + " " + tokens.subSet(2).join()); 542 } 543 break; 544 case CS_ConfigValueClass: 545 if (tokens.size() >= 1) 546 return (tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValueClasses_)); 547 break; 548 case CS_ConfigValue: 549 if ((tokens.size() >= 1) && evaluation.configvalueclass_) 550 return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValues_)); 551 break; 552 case CS_ConfigValueType: 553 if ((tokens.size() >= 1) && evaluation.configvalueclass_ && evaluation.configvalue_) 554 return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + evaluation.configvalue_->getName() + " "); 555 break; 556 case CS_ConfigValueFinished: 557 if ((tokens.size() >= 1) && evaluation.configvalueclass_ && evaluation.configvalue_ && (tokens.size() >= 4)) 558 return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + evaluation.configvalue_->getName() + " " + tokens.subSet(3).join()); 559 break; 560 case CS_KeybindKey: 561 if (tokens.size() >= 1) 562 return (tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleKeys_)); 563 break; 564 case CS_KeybindCommand: 565 if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' ')) 566 return (evaluation.processedCommand_ + " "); 567 break; 568 case CS_KeybindFinished: 569 break; 570 case CS_Error: 571 break; 572 } 573 574 return evaluation.processedCommand_; 109 CommandExecutor::parseIfNeeded(command); 110 return CommandExecutor::getEvaluation().complete(); 575 111 } 576 112 577 113 std::string CommandExecutor::hint(const std::string& command) 578 114 { 579 if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)) 580 CommandExecutor::parse(command); 581 582 return CommandExecutor::hint(CommandExecutor::getEvaluation()); 583 } 584 585 std::string CommandExecutor::hint(const CommandEvaluation& evaluation) 586 { 587 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 588 589 switch (evaluation.state_) 590 { 591 case CS_Uninitialized: 592 break; 593 case CS_Empty: 594 return (CommandExecutor::dump(evaluation.listOfPossibleShortcuts_) + "\n" + CommandExecutor::dump(evaluation.listOfPossibleFunctionClasses_)); 595 break; 596 case CS_FunctionClass_Or_Shortcut_Or_Keyword: 597 break; 598 case CS_Shortcut_Params: 599 if (evaluation.shortcut_) 600 return CommandExecutor::dump(evaluation.shortcut_); 601 break; 602 case CS_Shortcut_Finished: 603 if (evaluation.shortcut_) 604 return CommandExecutor::dump(evaluation.shortcut_); 605 break; 606 case CS_Function: 607 return CommandExecutor::dump(evaluation.listOfPossibleFunctions_); 608 break; 609 case CS_Function_Params: 610 if (evaluation.function_) 611 return CommandExecutor::dump(evaluation.function_); 612 break; 613 case CS_Function_Finished: 614 if (evaluation.function_) 615 return CommandExecutor::dump(evaluation.function_); 616 break; 617 case CS_ConfigValueClass: 618 return CommandExecutor::dump(evaluation.listOfPossibleConfigValueClasses_); 619 break; 620 case CS_ConfigValue: 621 return CommandExecutor::dump(evaluation.listOfPossibleConfigValues_); 622 break; 623 case CS_ConfigValueType: 624 if (evaluation.configvalue_) 625 return CommandExecutor::dump(evaluation.configvalue_); 626 break; 627 case CS_ConfigValueFinished: 628 if (evaluation.configvalue_) 629 return CommandExecutor::dump(evaluation.configvalue_); 630 break; 631 case CS_KeybindKey: 632 return CommandExecutor::dump(evaluation.listOfPossibleKeys_); 633 break; 634 case CS_KeybindCommand: 635 if (evaluation.key_) 636 return CommandExecutor::dump(evaluation.key_); 637 break; 638 case CS_KeybindFinished: 639 if (evaluation.key_) 640 return CommandExecutor::dump(evaluation.key_); 641 break; 642 case CS_Error: 643 return CommandExecutor::getEvaluation().errorMessage_; 644 break; 645 } 646 647 return ""; 115 CommandExecutor::parseIfNeeded(command); 116 return CommandExecutor::getEvaluation().hint(); 648 117 } 649 118 650 119 CommandEvaluation CommandExecutor::evaluate(const std::string& command) 651 120 { 652 CommandExecutor::parse(command, true); 653 654 if (CommandExecutor::getEvaluation().tokens_.size() > 0) 655 { 656 std::string lastToken; 657 lastToken = CommandExecutor::getEvaluation().tokens_[CommandExecutor::getEvaluation().tokens_.size() - 1]; 658 lastToken = lastToken.substr(0, lastToken.size() - 1); 659 CommandExecutor::getEvaluation().tokens_.pop_back(); 660 CommandExecutor::getEvaluation().tokens_.append(SubString(lastToken, " ", "", true, '\0', false, '\0', false, '\0', '\0', false, '\0')); 661 } 662 121 CommandExecutor::parse(command); 663 122 CommandExecutor::getEvaluation().evaluateParams(); 664 123 return CommandExecutor::getEvaluation(); 665 124 } 666 125 126 void CommandExecutor::parseIfNeeded(const std::string& command) 127 { 128 if (CommandExecutor::getEvaluation().state_ == CS_Uninitialized) 129 { 130 CommandExecutor::parse(command); 131 } 132 else if (CommandExecutor::getEvaluation().originalCommand_ != command) 133 { 134 if (CommandExecutor::getEvaluation().command_ == command) 135 { 136 CommandExecutor::parse(command); 137 CommandExecutor::getEvaluation().bNewCommand_ = false; 138 } 139 else 140 { 141 CommandExecutor::parse(command); 142 } 143 } 144 } 145 667 146 void CommandExecutor::parse(const std::string& command, bool bInitialize) 668 147 { 669 CommandExecutor::getEvaluation().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');670 CommandExecutor::getEvaluation().processedCommand_ = command;671 672 148 if (bInitialize) 673 CommandExecutor::initialize(command); 149 CommandExecutor::getEvaluation().initialize(command); 150 151 CommandExecutor::getEvaluation().commandTokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 152 CommandExecutor::getEvaluation().command_ = command; 674 153 675 154 switch (CommandExecutor::getEvaluation().state_) 676 155 { 677 156 case CS_Uninitialized: 157 { 678 158 // Impossible 679 159 break; 160 } 680 161 case CS_Empty: 162 { 681 163 if (CommandExecutor::argumentsGiven() == 0) 682 164 { 683 // We want a hint for the first token 684 // Check if there is already a perfect match 685 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0)); 686 CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0)); 687 688 if ((CommandExecutor::getEvaluation().functionclass_) || (CommandExecutor::getEvaluation().shortcut_)) 689 { 690 // Yes, there is a class or a shortcut with the searched name 691 // Add a whitespace and continue parsing 692 CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword; 693 CommandExecutor::parse(command + " ", false); 165 CommandExecutor::createListOfPossibleFunctions(""); 166 CommandExecutor::createListOfPossibleIdentifiers(""); 167 break; 168 } 169 else 170 { 171 CommandExecutor::getEvaluation().state_ = CS_ShortcutOrIdentifier; 172 // Move on to next case 173 } 174 } 175 case CS_ShortcutOrIdentifier: 176 { 177 if (CommandExecutor::argumentsGiven() > 1) 178 { 179 // There's a finished first argument - check if it's a shortcut or a classname 180 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0)); 181 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0)); 182 183 if (CommandExecutor::getEvaluation().function_) 184 { 185 // It's a shortcut 186 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 187 CommandExecutor::getEvaluation().functionclass_ = 0; 188 // Move on to next case 189 } 190 else if (CommandExecutor::getEvaluation().functionclass_) 191 { 192 // It's a functionname 193 CommandExecutor::getEvaluation().state_ = CS_Function; 194 CommandExecutor::getEvaluation().function_ = 0; 195 // Move on to next case 196 } 197 else 198 { 199 // The first argument is bad 200 CommandExecutor::getEvaluation().state_ = CS_Error; 201 AddLanguageEntry("commandexecutorunknownfirstargument", "is not a shortcut nor a classname"); 202 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getArgument(0) + " " + GetLocalisation("commandexecutorunknownfirstargument") + "."; 694 203 return; 695 204 } 696 697 // No perfect match: Create the lists of all possible classes and shortcuts and return 698 CommandExecutor::createListOfPossibleFunctionClasses(CommandExecutor::getToken(0)); 699 CommandExecutor::createListOfPossibleShortcuts(CommandExecutor::getToken(0)); 700 701 // Check if there's only one possiblility 702 if ((CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.size() == 1) && (CommandExecutor::getEvaluation().listOfPossibleShortcuts_.size() == 0)) 703 { 704 // There's only one possible class 205 } 206 else 207 { 208 // There's no finished first argument - search possible shortcuts or classnames 209 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(0)); 210 CommandExecutor::createListOfPossibleIdentifiers(CommandExecutor::getArgument(0)); 211 212 unsigned int num_functions = CommandExecutor::getEvaluation().listOfPossibleFunctions_.size(); 213 unsigned int num_identifiers = CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.size(); 214 215 if (num_functions == 1 && num_identifiers == 0) 216 { 217 // It's a shortcut 218 std::string functionname = *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first; 219 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(functionname); 220 if (getLowercase(functionname) != getLowercase(CommandExecutor::getArgument(0))) 221 { 222 // Unfinished shortcut 223 CommandExecutor::getEvaluation().bCommandChanged_ = true; 224 } 225 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 226 CommandExecutor::getEvaluation().functionclass_ = 0; 227 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().function_->getName(); 228 if (CommandExecutor::getEvaluation().function_->getParamCount() > 0) 229 { 230 CommandExecutor::getEvaluation().command_ += " "; 231 CommandExecutor::getEvaluation().bCommandChanged_ = true; 232 } 233 // Move on to next case 234 } 235 else if (num_identifiers == 1 && num_functions == 0) 236 { 237 // It's a classname 238 std::string classname = *(*CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.begin()).first; 239 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(classname); 240 if (getLowercase(classname) != getLowercase(CommandExecutor::getArgument(0))) 241 { 242 // Unfinished classname 243 CommandExecutor::getEvaluation().bCommandChanged_ = true; 244 } 705 245 CommandExecutor::getEvaluation().state_ = CS_Function; 706 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(*(*CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.begin()).first); 707 CommandExecutor::parse(*(*CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.begin()).first + " ", false); 246 CommandExecutor::getEvaluation().function_ = 0; 247 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " "; 248 // Move on to next case 249 } 250 else if (num_identifiers == 0 && num_functions == 0) 251 { 252 // No possibilities 253 CommandExecutor::getEvaluation().state_ = CS_Error; 254 AddLanguageEntry("commandexecutorunknownfirstargumentstart", "There is no command or classname starting with"); 255 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + GetLocalisation("commandexecutorunknownfirstargumentstart") + " " + CommandExecutor::getArgument(0) + "."; 708 256 return; 709 257 } 710 else if ((CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.size() == 0) && (CommandExecutor::getEvaluation().listOfPossibleShortcuts_.size() == 1)) 711 { 712 if ((*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) 713 && (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY) 714 && (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND)) 715 { 716 // There's only one possible shortcut 717 CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params; 718 CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first); 719 } 720 else if ((*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) 721 || (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) 722 { 723 // It's the 'set' or 'tset' keyword 724 CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass; 725 } 726 else if (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND) 727 { 728 // It's the 'bind' keyword 729 CommandExecutor::getEvaluation().state_ = CS_KeybindKey; 730 } 731 732 CommandExecutor::parse(*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first + " ", false); 258 else 259 { 260 // There are several possiblilities 261 std::list<std::pair<const std::string*, const std::string*> > temp; 262 temp.insert(temp.end(), CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin(), CommandExecutor::getEvaluation().listOfPossibleFunctions_.end()); 263 temp.insert(temp.end(), CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.begin(), CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.end()); 264 CommandExecutor::getEvaluation().command_ = CommandExecutor::getCommonBegin(temp); 265 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0)); 266 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0)); 267 CommandExecutor::getEvaluation().bCommandChanged_ = true; 733 268 return; 734 269 } 735 736 // It's ambiguous 270 } 271 } 272 case CS_Function: 273 { 274 if (CommandExecutor::getEvaluation().functionclass_) 275 { 276 // There is a classname - search for the commandname 277 if (CommandExecutor::argumentsGiven() > 2) 278 { 279 // There is a finished second argument - check if it's a commandname 280 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_); 281 282 if (CommandExecutor::getEvaluation().function_) 283 { 284 // It's a function 285 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 286 // Move on to next case 287 } 288 else 289 { 290 // The second argument is bad 291 CommandExecutor::getEvaluation().state_ = CS_Error; 292 AddLanguageEntry("commandexecutorunknownsecondargument", "is not a function of"); 293 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknownsecondargument") + " " + CommandExecutor::getEvaluation().functionclass_->getName() + "."; 294 return; 295 } 296 } 297 else 298 { 299 // There is no finished second argument - search for possibilities 300 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_); 301 unsigned int num_functions = CommandExecutor::getEvaluation().listOfPossibleFunctions_.size(); 302 303 if (num_functions == 1) 304 { 305 // It's a function 306 std::string functionname = *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first; 307 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(functionname, CommandExecutor::getEvaluation().functionclass_); 308 if (getLowercase(functionname) != getLowercase(CommandExecutor::getArgument(1))) 309 { 310 // Unfinished function 311 CommandExecutor::getEvaluation().bCommandChanged_ = true; 312 } 313 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 314 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getEvaluation().function_->getName(); 315 if (CommandExecutor::getEvaluation().function_->getParamCount() > 0) 316 { 317 CommandExecutor::getEvaluation().command_ += " "; 318 CommandExecutor::getEvaluation().bCommandChanged_ = true; 319 } 320 // Move on to next case 321 } 322 else if (num_functions == 0) 323 { 324 // No possibilities 325 CommandExecutor::getEvaluation().state_ = CS_Error; 326 AddLanguageEntry("commandexecutorunknownsecondargumentstart", "has no function starting with"); 327 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getEvaluation().functionclass_->getName() + " " + GetLocalisation("commandexecutorunknownsecondargumentstart") + " " + CommandExecutor::getArgument(1) + "."; 328 return; 329 } 330 else 331 { 332 // There are several possibilities 333 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleFunctions_); 334 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_); 335 CommandExecutor::getEvaluation().bCommandChanged_ = true; 336 return; 337 } 338 } 339 } 340 else 341 { 342 // There is no classname - move on to CS_ParamPreparation 343 } 344 } 345 case CS_ParamPreparation: 346 { 347 if (CommandExecutor::getEvaluation().function_->getParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_)) 348 { 349 CommandExecutor::getEvaluation().state_ = CS_Finished; 737 350 return; 738 351 } 739 352 else 740 353 { 741 // There is at least one argument: Check if it's a shortcut, a classname or a special keyword 742 CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword; 743 CommandExecutor::parse(command, false); 354 unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 2; 355 if (CommandExecutor::getEvaluation().functionclass_) 356 argumentNumber -= 1; 357 358 CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber); 359 CommandExecutor::getEvaluation().state_ = CS_Params; 360 361 if (CommandExecutor::getEvaluation().bCommandChanged_) 362 { 363 // Don't do more than one change 364 return; 365 } 366 } 367 } 368 case CS_Params: 369 { 370 if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 1) 371 { 372 // There is exactly one possible argument 373 CommandExecutor::getEvaluation().argument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).getString(); 374 CommandExecutor::getEvaluation().possibleArgument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).getString(); 375 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 744 376 return; 745 377 } 378 else if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 0) 379 { 380 // The user tries something new - we let him do 381 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 382 CommandExecutor::getEvaluation().argument_ = CommandExecutor::getLastArgument(); 383 return; 384 } 385 else 386 { 387 // There are several possibilities 388 unsigned int argumentNumber = CommandExecutor::argumentsGiven(); 389 if (argumentNumber > 0) 390 --argumentNumber; 391 if (CommandExecutor::getEvaluation().functionclass_ && argumentNumber > 0) 392 --argumentNumber; 393 394 CommandExecutor::getEvaluation().argument_ = CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleArguments_); 395 CommandExecutor::getEvaluation().possibleArgument_ = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber); 396 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 397 return; 398 } 399 } 400 case CS_Finished: 401 { 402 // Nothing more to do 746 403 break; 747 case CS_FunctionClass_Or_Shortcut_Or_Keyword: 748 if (CommandExecutor::argumentsGiven() >= 1) 749 { 750 if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) 751 { 752 // We want to set a config value 753 CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass; 754 CommandExecutor::parse(command, false); 755 return; 756 } 757 else if (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND) 758 { 759 // We want to set a keybinding 760 CommandExecutor::getEvaluation().state_ = CS_KeybindKey; 761 CommandExecutor::parse(command, false); 762 return; 763 } 764 765 if (!CommandExecutor::getEvaluation().functionclass_) 766 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0)); 767 if (!CommandExecutor::getEvaluation().shortcut_) 768 CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0)); 769 770 if ((!CommandExecutor::getEvaluation().functionclass_) && (!CommandExecutor::getEvaluation().shortcut_)) 771 { 772 // Argument 1 seems to be wrong 773 AddLanguageEntry("CommandExecutor::NoSuchCommandOrClassName", "No such command or classname"); 774 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(0) + ": " + GetLocalisation("CommandExecutor::NoSuchCommandOrClassName")); 775 CommandExecutor::getEvaluation().state_ = CS_Error; 776 return; 777 } 778 else if (CommandExecutor::getEvaluation().shortcut_) 779 { 780 // Argument 1 is a shortcut: Return the needed parameter types 781 CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params; 782 CommandExecutor::parse(command, false); 783 return; 784 } 785 else 786 { 787 // Argument 1 is a classname: Return the possible functions 788 CommandExecutor::getEvaluation().state_ = CS_Function; 789 CommandExecutor::parse(command, false); 790 return; 791 } 792 } 793 else 794 { 795 CommandExecutor::getEvaluation().state_ = CS_Error; 796 return; 797 } 404 } 405 case CS_Error: 406 { 407 // Bad, very bad 798 408 break; 799 case CS_Shortcut_Params: 800 if (CommandExecutor::getEvaluation().shortcut_) 801 { 802 // Valid command 803 // Check if there are enough parameters 804 if (CommandExecutor::enoughParametersGiven(1, CommandExecutor::getEvaluation().shortcut_)) 805 { 806 CommandExecutor::getEvaluation().state_ = CS_Shortcut_Finished; 807 return; 808 } 809 } 810 else 811 { 812 // Something is wrong 813 CommandExecutor::getEvaluation().state_ = CS_Error; 814 return; 815 } 816 break; 817 case CS_Function: 818 if (CommandExecutor::getEvaluation().functionclass_) 819 { 820 // We have a valid classname 821 // Check if there is a second argument 822 if (CommandExecutor::argumentsGiven() >= 2) 823 { 824 // There is a second argument: Check if it's a valid functionname 825 CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_); 826 if (!CommandExecutor::getEvaluation().function_) 827 { 828 // Argument 2 seems to be wrong 829 AddLanguageEntry("CommandExecutor::NoSuchFunctionnameIn", "No such functionname in"); 830 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchFunctionnameIn") + " " + CommandExecutor::getEvaluation().functionclass_->getName()); 831 CommandExecutor::getEvaluation().state_ = CS_Error; 832 return; 833 } 834 else 835 { 836 // Argument 2 seems to be a valid functionname: Get the parameters 837 CommandExecutor::getEvaluation().state_ = CS_Function_Params; 838 CommandExecutor::parse(command, false); 839 return; 840 } 841 } 842 else 843 { 844 // There is no finished second argument 845 // Check if there's already a perfect match 846 if (CommandExecutor::getEvaluation().tokens_.size() >= 2) 847 { 848 CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_); 849 if (CommandExecutor::getEvaluation().function_) 850 { 851 // There is a perfect match: Add a whitespace and continue parsing 852 CommandExecutor::getEvaluation().state_ = CS_Function_Params; 853 CommandExecutor::parse(command + " ", false); 854 return; 855 } 856 } 857 858 // No perfect match: Create the list of all possible functions and return 859 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_); 860 861 // Check if there's only one possiblility 862 if (CommandExecutor::getEvaluation().listOfPossibleFunctions_.size() == 1) 863 { 864 // There's only one possible function 865 CommandExecutor::getEvaluation().state_ = CS_Function_Params; 866 CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(*(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first, CommandExecutor::getEvaluation().functionclass_); 867 CommandExecutor::parse(CommandExecutor::getToken(0) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first + " ", false); 868 return; 869 } 870 871 // It's ambiguous 872 return; 873 } 874 } 875 else 876 { 877 CommandExecutor::getEvaluation().state_ = CS_Error; 878 return; 879 } 880 break; 881 case CS_Function_Params: 882 if (CommandExecutor::getEvaluation().functionclass_ && CommandExecutor::getEvaluation().function_) 883 { 884 // Valid command 885 // Check if there are enough parameters 886 if (CommandExecutor::enoughParametersGiven(2, CommandExecutor::getEvaluation().function_)) 887 { 888 CommandExecutor::getEvaluation().state_ = CS_Function_Finished; 889 return; 890 } 891 } 892 else 893 { 894 // Something is wrong 895 CommandExecutor::getEvaluation().state_ = CS_Error; 896 return; 897 } 898 break; 899 case CS_ConfigValueClass: 900 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY))) 901 { 902 // We want to set a config value 903 // Check if there is a second argument 904 if (CommandExecutor::argumentsGiven() >= 2) 905 { 906 // There is a second argument: Check if it's a valid classname 907 CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1)); 908 if (!CommandExecutor::getEvaluation().configvalueclass_) 909 { 910 // Argument 2 seems to be wrong 911 AddLanguageEntry("CommandExecutor::NoSuchClassWithConfigValues", "No such class with config values"); 912 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchClassWithConfigValues")); 913 CommandExecutor::getEvaluation().state_ = CS_Error; 914 return; 915 } 916 else 917 { 918 // Argument 2 seems to be a valid classname: Search for possible config values 919 CommandExecutor::getEvaluation().state_ = CS_ConfigValue; 920 CommandExecutor::parse(command, false); 921 return; 922 } 923 } 924 else 925 { 926 // There's no finished second argument 927 // Check if there's already a perfect match 928 if (CommandExecutor::getEvaluation().tokens_.size() >= 2) 929 { 930 CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1)); 931 if (CommandExecutor::getEvaluation().configvalueclass_) 932 { 933 // There is a perfect match: Add a whitespace and continue parsing 934 CommandExecutor::getEvaluation().state_ = CS_ConfigValue; 935 CommandExecutor::parse(command + " ", false); 936 return; 937 } 938 } 939 940 // No perfect match: Create the list of all possible classnames and return 941 CommandExecutor::createListOfPossibleConfigValueClasses(CommandExecutor::getToken(1)); 942 943 // Check if there's only one possiblility 944 if (CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.size() == 1) 945 { 946 // There's only one possible classname 947 CommandExecutor::getEvaluation().state_ = CS_ConfigValue; 948 CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(*(*CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.begin()).first); 949 CommandExecutor::parse(CommandExecutor::getToken(0) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.begin()).first + " ", false); 950 return; 951 } 952 953 // It's ambiguous 954 return; 955 } 956 } 957 else 958 { 959 // Something is wrong 960 CommandExecutor::getEvaluation().state_ = CS_Error; 961 return; 962 } 963 break; 964 case CS_ConfigValue: 965 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getEvaluation().configvalueclass_)) 966 { 967 // Check if there is a third argument 968 if (CommandExecutor::argumentsGiven() >= 3) 969 { 970 // There is a third argument: Check if it's a valid config value 971 CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_); 972 if (!CommandExecutor::getEvaluation().configvalue_) 973 { 974 // Argument 3 seems to be wrong 975 AddLanguageEntry("CommandExecutor::NoSuchConfigValueIn", "No such config value in"); 976 CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(2) + ": " + GetLocalisation("CommandExecutor::NoSuchConfigValueIn") + " " + CommandExecutor::getEvaluation().configvalueclass_->getName()); 977 CommandExecutor::getEvaluation().state_ = CS_Error; 978 return; 979 } 980 else 981 { 982 // Argument 3 seems to be a valid config value: Get the type 983 CommandExecutor::getEvaluation().state_ = CS_ConfigValueType; 984 CommandExecutor::parse(command, false); 985 return; 986 } 987 } 988 else 989 { 990 // There is no finished third argument 991 // Check if there's already a perfect match 992 if (CommandExecutor::getEvaluation().tokens_.size() >= 3) 993 { 994 CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_); 995 if (CommandExecutor::getEvaluation().configvalue_) 996 { 997 // There is a perfect match: Add a whitespace and continue parsing 998 CommandExecutor::getEvaluation().state_ = CS_ConfigValueType; 999 CommandExecutor::parse(command + " ", false); 1000 return; 1001 } 1002 } 1003 1004 // No perfect match: Create the list of all possible config values 1005 CommandExecutor::createListOfPossibleConfigValues(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_); 1006 1007 // Check if there's only one possiblility 1008 if (CommandExecutor::getEvaluation().listOfPossibleConfigValues_.size() == 1) 1009 { 1010 // There's only one possible config value 1011 CommandExecutor::getEvaluation().state_ = CS_ConfigValueType; 1012 CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(*(*CommandExecutor::getEvaluation().listOfPossibleConfigValues_.begin()).first, CommandExecutor::getEvaluation().configvalueclass_); 1013 CommandExecutor::parse(CommandExecutor::getToken(0) + " " + CommandExecutor::getToken(1) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleConfigValues_.begin()).first + " ", false); 1014 return; 1015 } 1016 1017 // It's ambiguous 1018 return; 1019 } 1020 } 1021 else 1022 { 1023 // Something is wrong 1024 CommandExecutor::getEvaluation().state_ = CS_Error; 1025 return; 1026 } 1027 break; 1028 case CS_ConfigValueType: 1029 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && CommandExecutor::getEvaluation().configvalueclass_ && CommandExecutor::getEvaluation().configvalue_) 1030 { 1031 // Valid command 1032 // Check if there are enough parameters 1033 if ((CommandExecutor::getEvaluation().tokens_.size() >= 4) && (CommandExecutor::getEvaluation().tokens_[3] != COMMAND_EXECUTOR_CURSOR)) 1034 { 1035 CommandExecutor::getEvaluation().state_ = CS_ConfigValueFinished; 1036 return; 1037 } 1038 } 1039 else 1040 { 1041 // Something is wrong 1042 CommandExecutor::getEvaluation().state_ = CS_Error; 1043 return; 1044 } 1045 break; 1046 case CS_KeybindKey: 1047 if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND)) 1048 { 1049 // todo 1050 } 1051 else 1052 { 1053 // Something is wrong 1054 CommandExecutor::getEvaluation().state_ = CS_Error; 1055 return; 1056 } 1057 break; 1058 case CS_KeybindCommand: 1059 if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND) && (false)) // todo 1060 { 1061 // Valid command 1062 // Check if there are enough parameters 1063 if (CommandExecutor::getEvaluation().tokens_.size() >= 3) 1064 { 1065 CommandExecutor::getEvaluation().state_ = CS_KeybindFinished; 1066 return; 1067 } 1068 1069 } 1070 else 1071 { 1072 // Something is wrong 1073 CommandExecutor::getEvaluation().state_ = CS_Error; 1074 return; 1075 } 1076 break; 1077 case CS_Shortcut_Finished: 1078 // Nothing to do 1079 break; 1080 case CS_Function_Finished: 1081 // Nothing to do 1082 break; 1083 case CS_ConfigValueFinished: 1084 // Nothing to do 1085 break; 1086 case CS_KeybindFinished: 1087 // Nothing to do 1088 break; 1089 case CS_Error: 1090 // This is bad 1091 break; 1092 } 1093 } 1094 1095 void CommandExecutor::initialize(const std::string& command) 1096 { 1097 CommandExecutor::getEvaluation().processedCommand_ = command; 1098 CommandExecutor::getEvaluation().additionalParameter_ = ""; 1099 1100 CommandExecutor::getEvaluation().bEvaluatedParams_ = false; 1101 CommandExecutor::getEvaluation().evaluatedExecutor_ = 0; 1102 1103 CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.clear(); 1104 CommandExecutor::getEvaluation().listOfPossibleShortcuts_.clear(); 409 } 410 } 411 } 412 413 unsigned int CommandExecutor::argumentsFinished() 414 { 415 unsigned int argumentsGiven = CommandExecutor::argumentsGiven(); 416 if (argumentsGiven > 0) 417 return argumentsGiven - 1; 418 else 419 return 0; 420 } 421 422 unsigned int CommandExecutor::argumentsGiven() 423 { 424 if (CommandExecutor::getEvaluation().command_.size() > 0 && CommandExecutor::getEvaluation().command_[CommandExecutor::getEvaluation().command_.size() - 1] == ' ') 425 return CommandExecutor::getEvaluation().commandTokens_.size() + 1; 426 else 427 return CommandExecutor::getEvaluation().commandTokens_.size(); 428 } 429 430 bool CommandExecutor::enoughArgumentsGiven(ConsoleCommand* command) 431 { 432 if (CommandExecutor::getEvaluation().functionclass_) 433 return (CommandExecutor::argumentsGiven() > (2 + command->getParamCount())); 434 else 435 return (CommandExecutor::argumentsGiven() > (1 + command->getParamCount())); 436 } 437 438 std::string CommandExecutor::getArgument(unsigned int index) 439 { 440 if (index < (CommandExecutor::getEvaluation().commandTokens_.size())) 441 return CommandExecutor::getEvaluation().commandTokens_[index]; 442 else 443 return ""; 444 } 445 446 std::string CommandExecutor::getLastArgument() 447 { 448 return CommandExecutor::getArgument(CommandExecutor::argumentsGiven() - 1); 449 } 450 451 void CommandExecutor::createListOfPossibleIdentifiers(const std::string& fragment) 452 { 453 CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.clear(); 454 std::string lowercase = getLowercase(fragment); 455 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it) 456 if ((*it).second->hasConsoleCommands()) 457 if ((*it).first.find(lowercase) == 0 || fragment == "") 458 CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 459 } 460 461 void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier) 462 { 1105 463 CommandExecutor::getEvaluation().listOfPossibleFunctions_.clear(); 1106 CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.clear(); 1107 CommandExecutor::getEvaluation().listOfPossibleConfigValues_.clear(); 1108 CommandExecutor::getEvaluation().listOfPossibleKeys_.clear(); 1109 1110 CommandExecutor::getEvaluation().functionclass_ = 0; 1111 CommandExecutor::getEvaluation().configvalueclass_ = 0; 1112 CommandExecutor::getEvaluation().shortcut_ = 0; 1113 CommandExecutor::getEvaluation().function_ = 0; 1114 CommandExecutor::getEvaluation().configvalue_ = 0; 1115 CommandExecutor::getEvaluation().key_ = 0; 1116 1117 CommandExecutor::getEvaluation().errorMessage_ = ""; 1118 CommandExecutor::getEvaluation().state_ = CS_Empty; 1119 } 1120 1121 bool CommandExecutor::argumentsGiven(unsigned int num) 1122 { 1123 // Because we added a cursor we have +1 arguments 1124 // There are num arguments given if there are at least num arguments + one cursor 1125 return (CommandExecutor::getEvaluation().tokens_.size() >= (num + 1)); 1126 } 1127 1128 unsigned int CommandExecutor::argumentsGiven() 1129 { 1130 // Because we added a cursor we have +1 arguments 1131 if (CommandExecutor::getEvaluation().tokens_.size() >= 1) 1132 return (CommandExecutor::getEvaluation().tokens_.size() - 1); 1133 else 1134 return 0; 1135 } 1136 1137 std::string CommandExecutor::getToken(unsigned int index) 1138 { 1139 if ((index >= 0) && (index < (CommandExecutor::getEvaluation().tokens_.size() - 1))) 1140 return CommandExecutor::getEvaluation().tokens_[index]; 1141 else if (index == (CommandExecutor::getEvaluation().tokens_.size() - 1)) 1142 return CommandExecutor::getEvaluation().tokens_[index].substr(0, CommandExecutor::getEvaluation().tokens_[index].size() - 1); 1143 else 1144 return ""; 1145 } 1146 1147 bool CommandExecutor::enoughParametersGiven(unsigned int head, Executor* executor) 1148 { 1149 unsigned int neededParams = head + executor->getParamCount(); 1150 /* 1151 for (unsigned int i = executor->getParamCount() - 1; i >= 0; i--) 1152 { 1153 if (executor->defaultValueSet(i)) 1154 neededParams--; 464 std::string lowercase = getLowercase(fragment); 465 if (!identifier) 466 { 467 for (std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it) 468 if ((*it).first.find(lowercase) == 0 || fragment == "") 469 CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 470 } 471 else 472 { 473 for (std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it) 474 if ((*it).first.find(lowercase) == 0 || fragment == "") 475 CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 476 } 477 } 478 479 void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param) 480 { 481 CommandExecutor::createArgumentCompletionList(command, param); 482 483 CommandExecutor::getEvaluation().listOfPossibleArguments_.clear(); 484 std::string lowercase = getLowercase(fragment); 485 for (ArgumentCompletionList::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it) 486 { 487 if ((*it).lowercaseComparison()) 488 { 489 if ((*it).getComparable().find(lowercase) == 0 || fragment == "") 490 CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(*it); 491 } 1155 492 else 1156 break; 1157 } 1158 */ 1159 return ((CommandExecutor::getEvaluation().tokens_.size() >= neededParams) && (CommandExecutor::getEvaluation().tokens_[neededParams - 1] != COMMAND_EXECUTOR_CURSOR)); 1160 } 1161 1162 void CommandExecutor::createListOfPossibleFunctionClasses(const std::string& fragment) 1163 { 1164 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it) 1165 { 1166 if ((*it).second->hasConsoleCommands()) 1167 { 1168 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "") 1169 { 1170 CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 1171 } 1172 } 1173 } 1174 1175 CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.sort(CommandExecutor::compareStringsInList); 1176 } 1177 1178 void CommandExecutor::createListOfPossibleShortcuts(const std::string& fragment) 1179 { 1180 for (std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it) 1181 { 1182 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "") 1183 { 1184 CommandExecutor::getEvaluation().listOfPossibleShortcuts_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 1185 } 1186 } 1187 1188 CommandExecutor::getEvaluation().listOfPossibleShortcuts_.sort(CommandExecutor::compareStringsInList); 1189 } 1190 1191 void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier) 1192 { 1193 for (std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it) 1194 { 1195 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "") 1196 { 1197 CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 1198 } 1199 } 1200 1201 CommandExecutor::getEvaluation().listOfPossibleFunctions_.sort(CommandExecutor::compareStringsInList); 1202 } 1203 1204 void CommandExecutor::createListOfPossibleConfigValueClasses(const std::string& fragment) 1205 { 1206 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it) 1207 { 1208 if ((*it).second->hasConfigValues()) 1209 { 1210 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "") 1211 { 1212 CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 1213 } 1214 } 1215 } 1216 1217 CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.sort(CommandExecutor::compareStringsInList); 1218 } 1219 1220 void CommandExecutor::createListOfPossibleConfigValues(const std::string& fragment, Identifier* identifier) 1221 { 1222 for (std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMapBegin(); it != identifier->getLowercaseConfigValueMapEnd(); ++it) 1223 { 1224 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "") 1225 { 1226 CommandExecutor::getEvaluation().listOfPossibleConfigValues_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 1227 } 1228 } 1229 1230 CommandExecutor::getEvaluation().listOfPossibleConfigValues_.sort(CommandExecutor::compareStringsInList); 1231 } 1232 1233 void CommandExecutor::createListOfPossibleKeys(const std::string& fragment) 1234 { 1235 // todo 1236 1237 CommandExecutor::getEvaluation().listOfPossibleKeys_.sort(CommandExecutor::compareStringsInList); 1238 } 1239 1240 bool CommandExecutor::compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second) 1241 { 1242 return ((*first.first) < (*second.first)); 1243 } 1244 1245 Identifier* CommandExecutor::getIdentifierOfPossibleFunctionClass(const std::string& name) 1246 { 1247 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name)); 493 { 494 if ((*it).getComparable().find(fragment) == 0 || fragment == "") 495 CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(*it); 496 } 497 } 498 } 499 500 Identifier* CommandExecutor::getPossibleIdentifier(const std::string& name) 501 { 502 std::string lowercase = getLowercase(name); 503 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(lowercase); 1248 504 if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConsoleCommands()) 1249 505 return (*it).second; … … 1252 508 } 1253 509 1254 ExecutorStatic* CommandExecutor::getExecutorOfPossibleShortcut(const std::string& name) 1255 { 1256 std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(getLowercase(name)); 1257 if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd()) 1258 return (*it).second; 1259 510 ConsoleCommand* CommandExecutor::getPossibleCommand(const std::string& name, Identifier* identifier) 511 { 512 std::string lowercase = getLowercase(name); 513 if (!identifier) 514 { 515 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(lowercase); 516 if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd()) 517 return (*it).second; 518 } 519 else 520 { 521 std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(lowercase); 522 if (it != identifier->getLowercaseConsoleCommandMapEnd()) 523 return (*it).second; 524 } 1260 525 return 0; 1261 526 } 1262 527 1263 ExecutorStatic* CommandExecutor::getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier) 1264 { 1265 std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(getLowercase(name)); 1266 if (it != identifier->getLowercaseConsoleCommandMapEnd()) 1267 return (*it).second; 1268 1269 return 0; 1270 } 1271 1272 Identifier* CommandExecutor::getIdentifierOfPossibleConfigValueClass(const std::string& name) 1273 { 1274 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name)); 1275 if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConfigValues()) 1276 return (*it).second; 1277 1278 return 0; 1279 } 1280 1281 ConfigValueContainer* CommandExecutor::getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier) 1282 { 1283 std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMap().find(getLowercase(name)); 1284 if (it != identifier->getLowercaseConfigValueMapEnd()) 1285 { 1286 return (*it).second; 1287 } 1288 1289 return 0; 1290 } 1291 1292 ConfigValueContainer* CommandExecutor::getContainerOfPossibleKey(const std::string& name) 1293 { 1294 // todo 1295 1296 return 0; 1297 } 1298 1299 std::string CommandExecutor::dump(const std::list<std::pair<const std::string*, const std::string*> >& list) 1300 { 1301 std::string output = ""; 1302 for (std::list<std::pair<const std::string*, const std::string*> >::const_iterator it = list.begin(); it != list.end(); ++it) 1303 { 1304 if (it != list.begin()) 1305 output += " "; 1306 1307 output += *(*it).second; 1308 } 1309 return output; 1310 } 1311 1312 std::string CommandExecutor::dump(const ExecutorStatic* executor) 1313 { 1314 std::string output = ""; 1315 for (unsigned int i = 0; i < executor->getParamCount(); i++) 1316 { 1317 if (i != 0) 1318 output += " "; 1319 1320 if (executor->defaultValueSet(i)) 1321 output += "["; 528 std::string CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param) 529 { 530 CommandExecutor::createArgumentCompletionList(command, param); 531 532 std::string lowercase = getLowercase(name); 533 for (ArgumentCompletionList::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it) 534 { 535 if ((*it).lowercaseComparison()) 536 { 537 if ((*it).getComparable() == lowercase) 538 return (*it).getString(); 539 } 1322 540 else 1323 output += "{"; 1324 1325 output += executor->getTypenameParam(i); 1326 1327 if (executor->defaultValueSet(i)) 1328 output += "=" + executor->getDefaultValue(i).toString() + "]"; 1329 else 1330 output += "}"; 1331 } 1332 return output; 1333 } 1334 1335 std::string CommandExecutor::dump(const ConfigValueContainer* container) 1336 { 1337 AddLanguageEntry("CommandExecutor::oldvalue", "old value"); 1338 if (!container->isVector()) 1339 return ("{" + container->getTypename() + "} (" + GetLocalisation("CommandExecutor::oldvalue") + ": " + container->toString() + ")"); 1340 else 1341 return ("(vector<" + container->getTypename() + ">) (size: " + getConvertedValue<unsigned int, std::string>(container->getVectorSize()) + ")"); 541 { 542 if ((*it).getComparable() == name) 543 return (*it).getString(); 544 } 545 } 546 547 return ""; 548 } 549 550 void CommandExecutor::createArgumentCompletionList(ConsoleCommand* command, unsigned int param) 551 { 552 std::string params[5]; 553 554 unsigned int index = 0; 555 unsigned int lowestIndex = 1 + (CommandExecutor::getEvaluation().functionclass_ != 0); 556 557 for (unsigned int i = CommandExecutor::argumentsGiven() - 1; i >= lowestIndex; --i) 558 { 559 params[index] = CommandExecutor::getArgument(i); 560 ++index; 561 if (index >= 5) 562 break; 563 } 564 565 command->createArgumentCompletionList(param, params[0], params[1], params[2], params[3], params[4]); 1342 566 } 1343 567 … … 1382 606 } 1383 607 } 608 609 std::string CommandExecutor::getCommonBegin(const ArgumentCompletionList& list) 610 { 611 if (list.size() == 0) 612 { 613 return ""; 614 } 615 else if (list.size() == 1) 616 { 617 return ((*list.begin()).getComparable() + " "); 618 } 619 else 620 { 621 std::string output = ""; 622 for (unsigned int i = 0; true; i++) 623 { 624 char temp = 0; 625 for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it) 626 { 627 std::string argument = (*it).getComparable(); 628 if (argument.size() > i) 629 { 630 if (it == list.begin()) 631 { 632 temp = argument[i]; 633 } 634 else 635 { 636 if (temp != argument[i]) 637 return output; 638 } 639 } 640 else 641 { 642 return output; 643 } 644 } 645 output += temp; 646 } 647 return output; 648 } 649 } 1384 650 } -
code/branches/network/src/core/CommandExecutor.h
r1349 r1446 32 32 #include "CorePrereqs.h" 33 33 34 #include <string>35 34 #include <map> 36 #include <list>37 35 38 #include "util/SubString.h" 39 #include "util/MultiTypeMath.h" 40 41 #define COMMAND_EXECUTOR_CURSOR "$" 36 #include "CommandEvaluation.h" 42 37 43 38 namespace orxonox 44 39 { 45 enum CommandState46 {47 CS_Uninitialized,48 CS_Empty,49 CS_FunctionClass_Or_Shortcut_Or_Keyword,50 CS_Shortcut_Params,51 CS_Shortcut_Finished,52 CS_Function,53 CS_Function_Params,54 CS_Function_Finished,55 CS_ConfigValueClass,56 CS_ConfigValue,57 CS_ConfigValueType,58 CS_ConfigValueFinished,59 CS_KeybindKey,60 CS_KeybindCommand,61 CS_KeybindFinished,62 CS_Error63 };64 65 void exec(const std::string& filename);66 std::string echo(const std::string& text);67 68 void write(const std::string& filename, const std::string& text);69 void append(const std::string& filename, const std::string& text);70 std::string read(const std::string& filename);71 72 ///////////////////////73 // CommandEvaluation //74 ///////////////////////75 class _CoreExport CommandEvaluation76 {77 friend class CommandExecutor;78 79 public:80 CommandEvaluation();81 82 KeybindMode::Enum getKeybindMode();83 bool isValid() const;84 85 inline void setAdditionalParameter(const std::string& param)86 { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; }87 inline std::string getAdditionalParameter() const88 { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; }89 inline ExecutorStatic* getEvaluatedExecutor() { return evaluatedExecutor_; }90 inline std::string getCommandString() { return this->processedCommand_; }91 92 void setEvaluatedParameter(unsigned int index, MultiTypeMath param);93 MultiTypeMath getEvaluatedParameter(unsigned int index) const;94 95 void evaluateParams();96 97 bool hasReturnvalue() const;98 MultiTypeMath getReturnvalue() const;99 100 private:101 std::string processedCommand_;102 SubString tokens_;103 std::string additionalParameter_;104 105 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctionClasses_;106 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleShortcuts_;107 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_;108 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValueClasses_;109 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValues_;110 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleKeys_;111 112 Identifier* functionclass_;113 Identifier* configvalueclass_;114 ExecutorStatic* shortcut_;115 ExecutorStatic* function_;116 ConfigValueContainer* configvalue_;117 ConfigValueContainer* key_;118 119 std::string errorMessage_;120 CommandState state_;121 122 bool bEvaluatedParams_;123 MultiTypeMath param_[5];124 ExecutorStatic* evaluatedExecutor_;125 };126 127 /////////////////////128 // CommandExecutor //129 /////////////////////130 40 class _CoreExport CommandExecutor 131 41 { 132 42 public: 133 43 static bool execute(const std::string& command, bool useTcl = true); 134 static bool execute(const CommandEvaluation& evaluation);135 136 44 static std::string complete(const std::string& command); 137 static std::string complete(const CommandEvaluation& evaluation);138 139 45 static std::string hint(const std::string& command); 140 static std::string hint(const CommandEvaluation& evaluation);141 46 142 47 static CommandEvaluation evaluate(const std::string& command); 143 144 48 static const CommandEvaluation& getLastEvaluation(); 145 49 146 static Executor& addConsoleCommandShortcut(ExecutorStatic* executor);147 static ExecutorStatic* getConsoleCommandShortcut(const std::string& name);148 static ExecutorStatic* getLowercaseConsoleCommandShortcut(const std::string& name);50 static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command); 51 static ConsoleCommand* getConsoleCommandShortcut(const std::string& name); 52 static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name); 149 53 150 54 /** @brief Returns the map that stores all console commands. @return The const_iterator */ 151 static inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }55 static inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; } 152 56 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */ 153 static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); }57 static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); } 154 58 /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */ 155 static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }59 static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); } 156 60 157 61 /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */ 158 static inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }62 static inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; } 159 63 /** @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 */ 160 static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); }64 static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); } 161 65 /** @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 */ 162 static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }66 static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); } 163 67 164 68 private: … … 170 74 static CommandEvaluation& getEvaluation(); 171 75 76 static void parseIfNeeded(const std::string& command); 172 77 static void parse(const std::string& command, bool bInitialize = true); 173 static void initialize(const std::string& command);174 78 175 static bool argumentsGiven(unsigned int num);79 static unsigned int argumentsFinished(); 176 80 static unsigned int argumentsGiven(); 81 static bool enoughArgumentsGiven(ConsoleCommand* command); 82 static std::string getArgument(unsigned int index); 83 static std::string getLastArgument(); 177 84 178 static std::string getToken(unsigned int index); 85 static void createListOfPossibleIdentifiers(const std::string& fragment); 86 static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier = 0); 87 static void createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param); 179 88 180 static bool enoughParametersGiven(unsigned int head, Executor* executor); 89 static Identifier* getPossibleIdentifier(const std::string& name); 90 static ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0); 91 static std::string getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param); 181 92 182 static void createListOfPossibleShortcuts(const std::string& fragment); 183 static void createListOfPossibleFunctionClasses(const std::string& fragment); 184 static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier); 185 static void createListOfPossibleConfigValueClasses(const std::string& fragment); 186 static void createListOfPossibleConfigValues(const std::string& fragment, Identifier* identifier); 187 static void createListOfPossibleKeys(const std::string& fragment); 188 189 static bool compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second); 190 191 static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list); 192 static std::string dump(const ExecutorStatic* executor); 193 static std::string dump(const ConfigValueContainer* container); 194 93 static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param); 195 94 static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list); 196 197 static Identifier* getIdentifierOfPossibleFunctionClass(const std::string& name); 198 static ExecutorStatic* getExecutorOfPossibleShortcut(const std::string& name); 199 static ExecutorStatic* getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier); 200 static Identifier* getIdentifierOfPossibleConfigValueClass(const std::string& name); 201 static ConfigValueContainer* getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier); 202 static ConfigValueContainer* getContainerOfPossibleKey(const std::string& name); 95 static std::string getCommonBegin(const ArgumentCompletionList& list); 203 96 204 97 CommandEvaluation evaluation_; 205 206 std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_; 207 std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_LC_; 98 std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_; 99 std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_; 208 100 }; 209 101 } -
code/branches/network/src/core/ConfigFileManager.cc
r1413 r1446 38 38 namespace orxonox 39 39 { 40 ConsoleCommandShortcutExtern(reloadConfig, AccessLevel::None); 41 ConsoleCommandShortcutExtern(cleanConfig, AccessLevel::None); 42 ConsoleCommandShortcutExtern(loadSettings, AccessLevel::None); 43 ConsoleCommandShortcutExtern(loadKeybindings, AccessLevel::None); 40 SetConsoleCommandShortcutExtern(config).setArgumentCompleter(0, autocompletion::configvalueclasses()).setArgumentCompleter(1, autocompletion::configvalues()).setArgumentCompleter(2, autocompletion::configvalue()); 41 SetConsoleCommandShortcutExtern(tconfig).setArgumentCompleter(0, autocompletion::configvalueclasses()).setArgumentCompleter(1, autocompletion::configvalues()).setArgumentCompleter(2, autocompletion::configvalue()); 42 SetConsoleCommandShortcutExtern(reloadConfig); 43 SetConsoleCommandShortcutExtern(cleanConfig); 44 SetConsoleCommandShortcutExtern(loadSettings).setArgumentCompleter(0, autocompletion::files()); 45 SetConsoleCommandShortcutExtern(loadKeybindings).setArgumentCompleter(0, autocompletion::files()); 46 47 bool config(const std::string& classname, const std::string& varname, const std::string& value) 48 { 49 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); 50 if (identifier != Identifier::getLowercaseIdentifierMapEnd()) 51 { 52 std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); 53 if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) 54 return (*variable).second->set(value); 55 } 56 return false; 57 } 58 59 bool tconfig(const std::string& classname, const std::string& varname, const std::string& value) 60 { 61 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); 62 if (identifier != Identifier::getLowercaseIdentifierMapEnd()) 63 { 64 std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); 65 if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) 66 return (*variable).second->tset(value); 67 } 68 return false; 69 } 44 70 45 71 void reloadConfig() -
code/branches/network/src/core/ConfigFileManager.h
r1413 r1446 50 50 51 51 52 bool config(const std::string& classname, const std::string& varname, const std::string& value); 53 bool tconfig(const std::string& classname, const std::string& varname, const std::string& value); 52 54 void reloadConfig(); 53 55 void saveConfig(); -
code/branches/network/src/core/ConfigValueContainer.cc
r1444 r1446 87 87 88 88 if (defvalue.size() > 0) 89 this->value_ = defvalue[0]; 90 91 for (unsigned int i = 0; i < defvalue.size(); i++) 92 ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string)); 93 94 for (unsigned int i = 0; i < defvalue.size(); i++) 95 this->defvalueStringVector_.push_back(defvalue[i].toString()); 96 97 this->update(); 89 { 90 this->value_ = defvalue[0]; 91 92 for (unsigned int i = 0; i < defvalue.size(); i++) 93 { 94 ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string)); 95 this->defvalueStringVector_.push_back(defvalue[i].toString()); 96 } 97 98 this->update(); 99 } 100 } 101 102 /** 103 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 104 @param input The new value 105 @return True if the new value was successfully assigned 106 */ 107 bool ConfigValueContainer::set(const MultiTypeMath& input) 108 { 109 if (this->bIsVector_) 110 { 111 return this->callFunctionWithIndex(&ConfigValueContainer::set, input.toString()); 112 } 113 else 114 { 115 if (this->tset(input)) 116 { 117 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input.toString(), this->value_.isA(MT_string)); 118 return true; 119 } 120 } 121 return false; 122 } 123 124 /** 125 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 126 @param index The index in the vector 127 @param input The new value 128 @return True if the new value was successfully assigned 129 */ 130 bool ConfigValueContainer::set(unsigned int index, const MultiTypeMath& input) 131 { 132 if (this->bIsVector_) 133 { 134 if (this->tset(index, input)) 135 { 136 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input.toString(), this->value_.isA(MT_string)); 137 return true; 138 } 139 } 140 else 141 { 142 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 143 } 144 return false; 145 } 146 147 /** 148 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). 149 @param input The new value. If bIsVector_ then write "index value" 150 @return True if the new value was successfully assigned 151 */ 152 bool ConfigValueContainer::tset(const MultiTypeMath& input) 153 { 154 if (this->bIsVector_) 155 { 156 return this->callFunctionWithIndex(&ConfigValueContainer::tset, input.toString()); 157 } 158 else 159 { 160 MultiTypeMath temp = this->value_; 161 if (temp.assimilate(input)) 162 { 163 this->value_ = temp; 164 if (this->identifier_) 165 this->identifier_->updateConfigValues(); 166 167 return true; 168 } 169 } 170 return false; 171 } 172 173 /** 174 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). 175 @param index The index in the vector 176 @param input The new value 177 @return True if the new value was successfully assigned 178 */ 179 bool ConfigValueContainer::tset(unsigned int index, const MultiTypeMath& input) 180 { 181 if (this->bIsVector_) 182 { 183 if (index > MAX_VECTOR_INDEX) 184 { 185 COUT(1) << "Error: Index " << index << " is too large." << std::endl; 186 return false; 187 } 188 189 if (index >= this->valueVector_.size()) 190 { 191 for (unsigned int i = this->valueVector_.size(); i <= index; i++) 192 { 193 this->valueVector_.push_back(MultiTypeMath()); 194 } 195 } 196 197 MultiTypeMath temp = this->value_; 198 if (temp.assimilate(input)) 199 { 200 this->valueVector_[index] = temp; 201 202 if (this->identifier_) 203 this->identifier_->updateConfigValues(); 204 205 return true; 206 } 207 } 208 else 209 { 210 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 211 } 212 return false; 98 213 } 99 214 … … 103 218 @return True if the new entry was successfully added 104 219 */ 105 bool ConfigValueContainer::add(const std::string& input)220 bool ConfigValueContainer::add(const MultiTypeMath& input) 106 221 { 107 222 if (this->bIsVector_) … … 123 238 if (index < this->valueVector_.size()) 124 239 { 240 // Erase the entry from the vector, change (shift) all entries beginning with index in the config file, remove the last entry from the file 125 241 this->valueVector_.erase(this->valueVector_.begin() + index); 126 242 for (unsigned int i = index; i < this->valueVector_.size(); i++) … … 131 247 } 132 248 COUT(1) << "Error: Invalid vector-index." << std::endl; 133 }134 135 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;136 return false;137 }138 139 /**140 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.141 @param input The new value. If bIsVector_ then write "index value"142 @return True if the new value was successfully assigned143 */144 bool ConfigValueContainer::set(const std::string& input)145 {146 if (this->bIsVector_)147 {148 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0');149 int index = -1;150 bool success = false;151 152 if (token.size() > 0)153 success = ConvertValue(&index, token[0]);154 155 if (!success || index < 0 || index > MAX_VECTOR_INDEX)156 {157 if (!success)158 {159 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl;160 }161 else162 {163 COUT(1) << "Error: Invalid vector-index." << std::endl;164 }165 return false;166 }167 168 if (token.size() >= 2)169 return this->set(index, token.subSet(1).join());170 else171 return this->set(index, "");172 }173 174 bool success = this->tset(input);175 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isA(MT_string));176 return success;177 }178 179 /**180 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.181 @param index The index in the vector182 @param input The new value183 @return True if the new value was successfully assigned184 */185 bool ConfigValueContainer::set(unsigned int index, const std::string& input)186 {187 if (this->bIsVector_)188 {189 bool success = this->tset(index, input);190 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isA(MT_string));191 return success;192 }193 194 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;195 return false;196 }197 198 /**199 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).200 @param input The new value201 @return True if the new value was successfully assigned202 */203 bool ConfigValueContainer::tset(const std::string& input)204 {205 bool success = this->parse(input);206 if (this->identifier_)207 this->identifier_->updateConfigValues();208 return success;209 }210 211 /**212 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).213 @param index The index in the vector214 @param input The new value215 @return True if the new value was successfully assigned216 */217 bool ConfigValueContainer::tset(unsigned int index, const std::string& input)218 {219 if (this->bIsVector_)220 {221 bool success = this->parse(index, input);222 if (this->identifier_)223 this->identifier_->updateConfigValues();224 return success;225 249 } 226 250 … … 259 283 for (unsigned int i = 0; i < ConfigFileManager::getSingleton()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++) 260 284 { 261 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string))); 262 this->valueVector_.push_back(this->value_); 263 } 264 } 265 } 266 267 /** 268 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 269 @param input The string to convert 270 @return True if the string was successfully parsed 271 */ 272 bool ConfigValueContainer::parse(const std::string& input) 273 { 274 if (this->bIsVector_) 275 { 276 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0'); 277 int index = -1; 278 bool success = false; 279 280 if (token.size() > 0) 281 success = ConvertValue(&index, token[0]); 282 283 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 284 { 285 if (!success) 285 if (i < this->defvalueStringVector_.size()) 286 286 { 287 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl;287 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string))); 288 288 } 289 289 else 290 290 { 291 COUT(1) << "Error: Invalid vector-index." << std::endl;291 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, MultiTypeMath(), this->value_.isA(MT_string))); 292 292 } 293 return false; 294 } 295 296 if (token.size() >= 2) 297 return this->parse(index, token.subSet(1).join()); 293 294 this->valueVector_.push_back(this->value_); 295 } 296 } 297 } 298 299 /** 300 @brief Calls the given function with parsed index and the parsed argument from the input string. 301 @param function The function to call 302 @param input The input string 303 @return The returnvalue of the functioncall 304 */ 305 bool ConfigValueContainer::callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiTypeMath&), const std::string& input) 306 { 307 SubString token(input, " ", SubString::WhiteSpaces, true, '\\', false, '"', false, '(', ')', false, '\0'); 308 int index = -1; 309 bool success = false; 310 311 if (token.size() > 0) 312 success = ConvertValue(&index, token[0]); 313 314 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 315 { 316 if (!success) 317 { 318 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl; 319 } 298 320 else 299 return this->parse(index, ""); 300 } 301 302 MultiTypeMath temp = this->value_; 303 if (temp.fromString(input)) 304 { 305 this->value_ = temp; 306 return true; 307 } 308 return false; 309 } 310 311 /** 312 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 313 @param index The index in the vector 314 @param input The string to convert 315 @return True if the string was successfully parsed 316 */ 317 bool ConfigValueContainer::parse(unsigned int index, const std::string& input) 318 { 319 if (this->bIsVector_) 320 { 321 if (index >= this->valueVector_.size()) 322 { 323 for (unsigned int i = this->valueVector_.size(); i <= index; i++) 324 { 325 this->valueVector_.push_back(MultiTypeMath()); 326 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string)); 327 } 328 } 329 330 MultiTypeMath temp = this->value_; 331 if (temp.fromString(input)) 332 { 333 this->valueVector_[index] = temp; 334 return true; 321 { 322 COUT(1) << "Error: Invalid vector-index." << std::endl; 335 323 } 336 324 return false; 337 325 } 338 326 339 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 340 return false; 341 } 342 343 /** 344 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 345 @param input The string to convert 346 @param defvalue The default value to assign if the parsing fails 347 @return True if the string was successfully parsed 348 */ 349 bool ConfigValueContainer::parse(const std::string& input, const MultiTypeMath& defvalue) 350 { 351 if (this->parse(input)) 352 return true; 353 354 this->value_ = defvalue; 355 return false; 356 } 357 358 /** 359 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 360 @param index The index in the vector 361 @param input The string to convert 362 @param defvalue The default value to assign if the parsing fails 363 @return True if the string was successfully parsed 364 */ 365 bool ConfigValueContainer::parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue) 366 { 367 if (this->bIsVector_) 368 { 369 if (this->parse(index, input)) 370 return true; 371 372 this->valueVector_[index] = defvalue; 373 return false; 374 } 375 376 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 377 return false; 327 if (token.size() >= 2) 328 return (this->*function)(index, token.subSet(1).join()); 329 else 330 return (this->*function)(index, ""); 378 331 } 379 332 -
code/branches/network/src/core/ConfigValueContainer.h
r1062 r1446 90 90 } 91 91 92 template <typename T> 93 inline void setVectorType(const std::vector<T>& value) 94 { 95 this->value_ = T(); 96 this->update(); 97 } 98 92 99 inline const std::string& getName() const 93 100 { return this->varname_; } … … 100 107 const std::string& getDescription() const; 101 108 102 bool add(const std::string& input); 109 bool set(const MultiTypeMath& input); 110 bool tset(const MultiTypeMath& input); 111 112 bool set(unsigned int index, const MultiTypeMath& input); 113 bool tset(unsigned int index, const MultiTypeMath& input); 114 bool add(const MultiTypeMath& input); 103 115 bool remove(unsigned int index); 104 bool set(const std::string& input); 105 bool tset(const std::string& input); 116 106 117 bool reset(); 107 118 void update(); … … 115 126 116 127 private: 117 bool parse(const std::string& input); 118 bool parse(const std::string& input, const MultiTypeMath& defvalue); 119 120 bool set(unsigned int index, const std::string& input); 121 bool tset(unsigned int index, const std::string& input); 122 bool parse(unsigned int index, const std::string& input); 123 bool parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue); 128 bool callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiTypeMath&), const std::string& input); 124 129 125 130 bool bIsVector_; //!< True if the container contains a std::vector -
code/branches/network/src/core/ConfigValueIncludes.h
r1444 r1446 84 84 temp.push_back(MultiTypeMath(defvalue[i])); \ 85 85 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, temp); \ 86 container##varname->setVectorType(varname); \ 86 87 this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \ 87 88 } \ -
code/branches/network/src/core/ConsoleCommand.cc
r1445 r1446 39 39 this->argumentCompleter_[3] = 0; 40 40 this->argumentCompleter_[4] = 0; 41 42 this->keybindMode_ = KeybindMode::OnPress; 43 this->axisParamIndex_ = -1; 44 this->bAxisRelative_ = false; 41 45 } 42 46 -
code/branches/network/src/core/ConsoleCommand.h
r1062 r1446 34 34 #include "Executor.h" 35 35 #include "ClassManager.h" 36 #include "Identifier.h"37 36 #include "CommandExecutor.h" 37 #include "ArgumentCompletionFunctions.h" 38 38 39 39 40 #define SetConsoleCommand(classname, function, bCreateShortcut) \ 41 SetConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function), bCreateShortcut) 40 42 41 #define ConsoleCommand(classname, function, accesslevel, bCreateShortcut) \ 42 ConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createExecutor(orxonox::createFunctor(&classname::function), #function, accesslevel), bCreateShortcut) 43 44 #define ConsoleCommandGeneric(fakevariable, classname, executor, bCreateShortcut) \ 45 Executor& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand((ExecutorStatic*)executor, bCreateShortcut) 43 #define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \ 44 ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut) 46 45 47 46 48 #define ConsoleCommandShortcut(classname, function, accesslevel) \49 ConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createExecutor(orxonox::createFunctor(&classname::function), #function, accesslevel))47 #define SetConsoleCommandShortcut(classname, function) \ 48 SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function)) 50 49 51 #define ConsoleCommandShortcutExtern(function, accesslevel) \52 ConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createExecutor(orxonox::createFunctor(&function), #function, accesslevel))50 #define SetConsoleCommandShortcutExtern(function) \ 51 SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&function), #function)) 53 52 54 #define ConsoleCommandShortcutGeneric(fakevariable, executor) \55 Executor& fakevariable = CommandExecutor::addConsoleCommandShortcut((ExecutorStatic*)executor)53 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \ 54 ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut(command) 56 55 57 56 57 namespace orxonox 58 { 59 namespace AccessLevel 60 { 61 enum Level 62 { 63 None, 64 User, 65 Admin, 66 Offline, 67 Debug, 68 Disabled 69 }; 70 } 71 72 class _CoreExport ConsoleCommand : public ExecutorStatic 73 { 74 public: 75 ConsoleCommand(FunctorStatic* functor, const std::string& name = ""); 76 77 inline ConsoleCommand& setDescription(const std::string& description) 78 { this->ExecutorStatic::setDescription(description); return (*this); } 79 inline ConsoleCommand& setDescriptionParam(int param, const std::string& description) 80 { this->ExecutorStatic::setDescriptionParam(param, description); return (*this); } 81 inline ConsoleCommand& setDescriptionReturnvalue(const std::string& description) 82 { this->ExecutorStatic::setDescriptionReturnvalue(description); return (*this); } 83 inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1) 84 { this->ExecutorStatic::setDefaultValues(param1); return (*this); } 85 inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) 86 { this->ExecutorStatic::setDefaultValues(param1, param2); return (*this); } 87 inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) 88 { this->ExecutorStatic::setDefaultValues(param1, param2, param3); return (*this); } 89 inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) 90 { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4); return (*this); } 91 inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) 92 { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4, param5); return (*this); } 93 inline ConsoleCommand& setDefaultValue(unsigned int index, const MultiTypeMath& param) 94 { this->ExecutorStatic::setDefaultValue(index, param); return (*this); } 95 96 inline ConsoleCommand& setAccessLevel(AccessLevel::Level level) 97 { this->accessLevel_ = level; return (*this); } 98 inline AccessLevel::Level getAccessLevel() const 99 { return this->accessLevel_; } 100 101 ConsoleCommand& setArgumentCompleter(unsigned int param, ArgumentCompleter* completer); 102 ArgumentCompleter* getArgumentCompleter(unsigned int param) const; 103 104 void createArgumentCompletionList(unsigned int param, const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = ""); 105 const ArgumentCompletionList& getArgumentCompletionList() const 106 { return this->argumentList_; } 107 ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const 108 { return this->argumentList_.begin(); } 109 ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const 110 { return this->argumentList_.end(); } 111 112 inline ConsoleCommand& setKeybindMode(KeybindMode::Enum mode) 113 { this->keybindMode_ = mode; return *this; } 114 inline KeybindMode::Enum getKeybindMode() const 115 { return this->keybindMode_; } 116 117 inline ConsoleCommand& setAxisParamIndex(int index) 118 { this->axisParamIndex_ = index; return *this; } 119 inline int getAxisParamIndex() const 120 { return this->axisParamIndex_; } 121 122 inline ConsoleCommand& setIsAxisRelative(bool val) 123 { this->bAxisRelative_ = val; return *this; } 124 inline int getIsAxisRelative() const 125 { return this->bAxisRelative_; } 126 127 private: 128 AccessLevel::Level accessLevel_; 129 ArgumentCompleter* argumentCompleter_[5]; 130 ArgumentCompletionList argumentList_; 131 132 KeybindMode::Enum keybindMode_; 133 int axisParamIndex_; 134 bool bAxisRelative_; 135 }; 136 137 inline ConsoleCommand* createConsoleCommand(FunctorStatic* functor, const std::string& name = "") 138 { 139 return new ConsoleCommand(functor, name); 140 } 141 } 142 58 143 #endif /* _ConsoleCommand_H__ */ -
code/branches/network/src/core/CorePrereqs.h
r1444 r1446 66 66 namespace orxonox 67 67 { 68 #ifndef _XMLPort_Mode__69 #define _XMLPort_Mode__70 68 namespace XMLPort 71 69 { … … 76 74 }; 77 75 } 78 #endif79 76 80 77 namespace KeybindMode … … 91 88 typedef std::string LanguageEntryLabel; 92 89 90 class ArgumentCompleter; 91 class ArgumentCompletionListElement; 93 92 class BaseFactory; 94 93 class BaseMetaObjectListElement; … … 112 111 class ConfigFileSection; 113 112 class ConfigValueContainer; 113 class ConsoleCommand; 114 114 class CoreSettings; 115 115 class Error; … … 125 125 class Identifier; 126 126 class IdentifierDistributor; 127 class IRC; 127 128 template <class T> 128 129 class Iterator; … … 141 142 class ObjectListElement; 142 143 class OrxonoxClass; 144 class OutputBuffer; 145 class OutputBufferListener; 143 146 class OutputHandler; 144 147 class Shell; 148 class ShellListener; 145 149 template <class T> 146 150 class SubclassIdentifier; 147 151 class TclBind; 152 struct TclInterpreterBundle; 153 class TclThreadManager; 148 154 class Tickable; 149 155 template <class T, class O> -
code/branches/network/src/core/CoreSettings.cc
r1058 r1446 117 117 118 118 /** 119 @brief Static function that holds the singleton. 119 @brief Returns the softDebugLevel for the given device (returns a default-value if the class ist right about to be created). 120 @param device The device 121 @return The softDebugLevel 120 122 */ 121 123 int CoreSettings::getSoftDebugLevel(OutputHandler::OutputDevice device) … … 136 138 return 2; 137 139 } 140 141 /** 142 @brief Sets the softDebugLevel for the given device. Please use this only temporary and restore the value afterwards, as it overrides the configured value. 143 @param device The device 144 @param level The level 145 */ 146 void CoreSettings::setSoftDebugLevel(OutputHandler::OutputDevice device, int level) 147 { 148 if (!CoreSettings::isCreatingCoreSettings()) 149 { 150 if (device == OutputHandler::LD_All) 151 CoreSettings::getInstance().softDebugLevel_ = level; 152 else if (device == OutputHandler::LD_Console) 153 CoreSettings::getInstance().softDebugLevelConsole_ = level; 154 else if (device == OutputHandler::LD_Logfile) 155 CoreSettings::getInstance().softDebugLevelLogfile_ = level; 156 else if (device == OutputHandler::LD_Shell) 157 CoreSettings::getInstance().softDebugLevelShell_ = level; 158 } 159 } 138 160 139 161 /** -
code/branches/network/src/core/CoreSettings.h
r1064 r1446 54 54 55 55 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); 56 static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level); 56 57 static const std::string& getLanguage(); 57 58 static void resetLanguage(); -
code/branches/network/src/core/Debug.h
r1293 r1446 206 206 COUT ## x 207 207 208 #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE 209 #define COUT0 \ 210 if (getSoftDebugLevel() >= ORX_NONE) \ 211 COUT_EXEC(0) 212 #else 213 #define COUT0 if (ORX_NONE)\ 214 COUT_EXEC(0) 215 #endif 216 208 217 #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR 209 218 #define COUT1 \ … … 256 265 #endif /* if ORX_PRINT_DEBUG_OUTPUT */ 257 266 258 #define COUT0 \259 COUT_EXEC(0)260 267 #endif /* ifndef COUT */ 261 268 … … 280 287 CCOUT ## x 281 288 289 #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE 290 #define CCOUT0 \ 291 if (getSoftDebugLevel() >= ORX_NONE) \ 292 CCOUT_EXEC(0) 293 #else 294 #define CCOUT0 if (ORX_NONE)\ 295 CCOUT_EXEC(0) 296 #endif 297 282 298 #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR 283 299 #define CCOUT1 \ … … 330 346 #endif /* if ORX_PRINT_DEBUG_OUTPUT */ 331 347 332 #define CCOUT0 \333 CCOUT_EXEC(0)334 348 #endif /* ifndef CCOUT */ 335 349 -
code/branches/network/src/core/Executor.cc
r1349 r1446 34 34 namespace orxonox 35 35 { 36 Executor::Executor(Functor* functor, const std::string& name , AccessLevel::Level level)36 Executor::Executor(Functor* functor, const std::string& name) 37 37 { 38 38 this->functor_ = functor; 39 39 this->name_ = name; 40 this->accessLevel_ = level;41 this->keybindMode_ = KeybindMode::OnPress;42 this->axisParamIndex_ = -1;43 this->bAxisRelative_ = false;44 40 45 41 this->bAddedDescription_ = false; -
code/branches/network/src/core/Executor.h
r1349 r1446 35 35 #include "util/SubString.h" 36 36 #include "util/String.h" 37 #include "util/Math.h" 37 38 #include "Functor.h" 38 39 #include "Debug.h" … … 100 101 COUT(5) << tokens[i]; \ 101 102 } \ 102 COUT(5) << ") and " << (paramCount - tokens.size()) << " default values ("; \103 COUT(5) << ") and " << max((int)paramCount - (int)tokens.size(), 0) << " default values ("; \ 103 104 for (unsigned int i = tokens.size(); i < paramCount; i++) \ 104 105 { \ … … 134 135 return true 135 136 136 namespace AccessLevel137 {138 enum Level139 {140 None,141 User,142 Admin,143 Offline,144 Debug,145 Disabled146 };147 }148 149 137 namespace orxonox 150 138 { … … 152 140 { 153 141 public: 154 Executor(Functor* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None);142 Executor(Functor* functor, const std::string& name = ""); 155 143 virtual ~Executor(); 156 144 … … 181 169 const std::string& getDescriptionReturnvalue(int param) const; 182 170 171 inline Functor* getFunctor() const 172 { return this->functor_; } 183 173 inline unsigned int getParamCount() const 184 174 { return this->functor_->getParamCount(); } … … 199 189 { return this->name_; } 200 190 201 inline void setAccessLevel(AccessLevel::Level level)202 { this->accessLevel_ = level; }203 inline AccessLevel::Level getAccessLevel() const204 { return this->accessLevel_; }205 206 inline Executor& setKeybindMode(KeybindMode::Enum mode)207 { this->keybindMode_ = mode; return *this; }208 inline KeybindMode::Enum getKeybindMode() const209 { return this->keybindMode_; }210 211 inline Executor& setAxisParamIndex(int index)212 { this->axisParamIndex_ = index; return *this; }213 inline int getAxisParamIndex() const214 { return this->axisParamIndex_; }215 216 inline Executor& setIsAxisRelative(bool val)217 { this->bAxisRelative_ = val; return *this; }218 inline int getIsAxisRelative() const219 { return this->bAxisRelative_; }220 221 191 Executor& setDefaultValues(const MultiTypeMath& param1); 222 192 Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2); … … 249 219 bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS]; 250 220 251 KeybindMode::Enum keybindMode_;252 int axisParamIndex_;253 bool bAxisRelative_;254 255 221 private: 256 222 LanguageEntryLabel description_; … … 261 227 bool bAddedDescriptionReturnvalue_; 262 228 bool bAddedDescriptionParam_[MAX_FUNCTOR_ARGUMENTS]; 263 264 AccessLevel::Level accessLevel_;265 229 }; 266 230 … … 268 232 { 269 233 public: 270 ExecutorStatic(FunctorStatic* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {}234 ExecutorStatic(FunctorStatic* functor, const std::string& name = "") : Executor(functor, name) {} 271 235 virtual ~ExecutorStatic() {} 272 236 }; … … 276 240 { 277 241 public: 278 ExecutorMember(FunctorMember<T>* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {}242 ExecutorMember(FunctorMember<T>* functor, const std::string& name = "") : Executor(functor, name) {} 279 243 virtual ~ExecutorMember() {} 280 244 … … 322 286 }; 323 287 324 inline Executor* createExecutor(Functor* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None)325 { 326 return new Executor(functor, name , level);288 inline Executor* createExecutor(Functor* functor, const std::string& name = "") 289 { 290 return new Executor(functor, name); 327 291 } 328 292 329 293 template <class T> 330 inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None)331 { 332 return new ExecutorMember<T>(functor, name , level);294 inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "") 295 { 296 return new ExecutorMember<T>(functor, name); 333 297 } 334 298 335 inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "" , AccessLevel::Level level = AccessLevel::None)336 { 337 return new ExecutorStatic(functor, name , level);299 inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "") 300 { 301 return new ExecutorStatic(functor, name); 338 302 } 339 303 } -
code/branches/network/src/core/Identifier.cc
r1062 r1446 37 37 38 38 #include "Factory.h" 39 #include " Executor.h"39 #include "ConsoleCommand.h" 40 40 #include "CommandExecutor.h" 41 41 … … 231 231 void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container) 232 232 { 233 std::map<std::string, ConfigValueContainer*>::const_iterator it = this->configValues_.find(varname); 234 if (it != this->configValues_.end()) 235 { 236 COUT(2) << "Warning: Overwriting config-value with name " << varname << " in class " << this->getName() << "." << std::endl; 237 } 238 233 239 this->bHasConfigValues_ = true; 234 240 this->configValues_[varname] = container; … … 270 276 @return The executor of the command 271 277 */ 272 ExecutorStatic& Identifier::addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut) 273 { 278 ConsoleCommand& Identifier::addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut) 279 { 280 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(command->getName()); 281 if (it != this->consoleCommands_.end()) 282 { 283 COUT(2) << "Warning: Overwriting console-command with name " << command->getName() << " in class " << this->getName() << "." << std::endl; 284 } 285 274 286 this->bHasConsoleCommands_ = true; 275 this->consoleCommands_[ executor->getName()] = executor;276 this->consoleCommands_LC_[getLowercase( executor->getName())] = executor;287 this->consoleCommands_[command->getName()] = command; 288 this->consoleCommands_LC_[getLowercase(command->getName())] = command; 277 289 278 290 if (bCreateShortcut) 279 CommandExecutor::addConsoleCommandShortcut( executor);280 281 return (* executor);291 CommandExecutor::addConsoleCommandShortcut(command); 292 293 return (*command); 282 294 } 283 295 … … 287 299 @return The executor of the requested console command 288 300 */ 289 ExecutorStatic* Identifier::getConsoleCommand(const std::string& name) const290 { 291 std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_.find(name);301 ConsoleCommand* Identifier::getConsoleCommand(const std::string& name) const 302 { 303 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name); 292 304 if (it != this->consoleCommands_.end()) 293 305 return (*it).second; … … 301 313 @return The executor of the requested console command 302 314 */ 303 ExecutorStatic* Identifier::getLowercaseConsoleCommand(const std::string& name) const304 { 305 std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_LC_.find(name);315 ConsoleCommand* Identifier::getLowercaseConsoleCommand(const std::string& name) const 316 { 317 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name); 306 318 if (it != this->consoleCommands_LC_.end()) 307 319 return (*it).second; -
code/branches/network/src/core/Identifier.h
r1064 r1446 63 63 #include "Debug.h" 64 64 #include "Iterator.h" 65 #include "MetaObjectList.h" 65 66 #include "util/String.h" 66 67 … … 175 176 176 177 /** @brief Returns the map that stores all console commands. @return The const_iterator */ 177 inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandMap() const { return this->consoleCommands_; }178 inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandMap() const { return this->consoleCommands_; } 178 179 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */ 179 inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); }180 inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); } 180 181 /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */ 181 inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); }182 inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); } 182 183 183 184 /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */ 184 inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; }185 inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; } 185 186 /** @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 */ 186 inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); }187 inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); } 187 188 /** @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 */ 188 inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); }189 inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); } 189 190 190 191 … … 213 214 virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0; 214 215 215 ExecutorStatic& addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut);216 ExecutorStatic* getConsoleCommand(const std::string& name) const;217 ExecutorStatic* getLowercaseConsoleCommand(const std::string& name) const;216 ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut); 217 ConsoleCommand* getConsoleCommand(const std::string& name) const; 218 ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const; 218 219 219 220 protected: … … 270 271 271 272 bool bHasConsoleCommands_; //!< True if this class has at least one assigned console command 272 std::map<std::string, ExecutorStatic*> consoleCommands_; //!< All console commands of this class273 std::map<std::string, ExecutorStatic*> consoleCommands_LC_; //!< All console commands of this class with their names in lowercase273 std::map<std::string, ConsoleCommand*> consoleCommands_; //!< All console commands of this class 274 std::map<std::string, ConsoleCommand*> consoleCommands_LC_; //!< All console commands of this class with their names in lowercase 274 275 }; 275 276 -
code/branches/network/src/core/InputBuffer.cc
r1413 r1446 37 37 namespace orxonox 38 38 { 39 InputBuffer::InputBuffer(const std::string allowedChars) : 40 buffer_(""), 41 allowedChars_(allowedChars), 42 lastKey_(KeyCode::Unassigned), 43 timeSinceKeyPressed_(0.0f), 44 timeSinceKeyRepeated_(0.0f), 45 keysToRepeat_(0) 46 { 47 RegisterObject(InputBuffer); 48 setConfigValues(); 49 } 50 51 void InputBuffer::setConfigValues() 52 { 53 SetConfigValue(keyRepeatDeleay_, 0.4).description("Key repeat deleay of the input buffer"); 54 SetConfigValue(keyRepeatTime_, 0.022).description("Key repeat time of the input buffer"); 55 if (keyRepeatDeleay_ < 0.0) 56 { 57 ResetConfigValue(keyRepeatDeleay_); 58 } 59 if (keyRepeatTime_ < 0.0) 60 { 61 ResetConfigValue(keyRepeatTime_); 62 } 63 } 64 /* 65 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), bool bOnlySingleInput) 66 { 67 struct InputBufferListenerTuple newListener = {listener, function, true, bOnlySingleInput, ' '}; 68 listeners_.insert(listeners_.end(), newListener); 69 } 70 71 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), char char_, bool bOnlySingleInput) 72 { 73 struct InputBufferListenerTuple newListener = {listener, function, false, bOnlySingleInput, char_}; 74 listeners_.insert(listeners_.end(), newListener); 75 } 76 */ 77 void InputBuffer::set(const std::string& input) 78 { 79 buffer_ = ""; 80 append(input); 81 } 82 83 void InputBuffer::append(const std::string& input) 84 { 85 for (unsigned int i = 0; i < input.size(); i++) 86 { 87 if (charIsAllowed(input[i])) 88 buffer_ += input[i]; 89 90 updated(input[i], false); 91 } 92 updated(); 93 } 94 95 void InputBuffer::append(const char& input) 96 { 97 if (charIsAllowed(input)) 98 buffer_ += input; 99 100 updated(input, true); 101 } 102 103 void InputBuffer::clear() 104 { 105 buffer_ = ""; 106 updated(); 107 } 108 109 void InputBuffer::removeLast() 110 { 111 buffer_ = buffer_.substr(0, buffer_.size() - 1); 112 updated(); 113 } 114 115 void InputBuffer::updated() 116 { 117 for (std::list<InputBufferListenerTuple>::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 118 { 119 if ((*it).bListenToAllChanges_) 120 (*(*it).listener_.*(*it).function_)(); 121 } 122 } 123 124 void InputBuffer::updated(const char& update, bool bSingleInput) 125 { 126 for (std::list<InputBufferListenerTuple>::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 127 { 128 if (((*it).bListenToAllChanges_ || ((*it).char_ == update)) && (!(*it).bOnlySingleInput_ || bSingleInput)) 129 (*(*it).listener_.*(*it).function_)(); 130 } 131 } 132 133 bool InputBuffer::charIsAllowed(const char& input) 134 { 135 if (allowedChars_ == "") 136 return true; 137 else 138 return (allowedChars_.find(input) != std::string::npos); 139 } 140 141 142 void InputBuffer::processKey(const KeyEvent &evt) 143 { 144 if (evt.isModifierDown(KeyboardModifier::Ctrl)) 145 { 146 if (evt.key == KeyCode::V) 147 append(fromClipboard()); 148 else if (evt.key == KeyCode::C) 149 toClipboard(buffer_); 150 else if (evt.key == KeyCode::X) 151 { 152 toClipboard(buffer_); 153 clear(); 154 } 155 } 156 else if (evt.isModifierDown(KeyboardModifier::Shift)) 157 { 158 if (evt.key == KeyCode::Insert) 159 { 160 append(fromClipboard()); 161 } 162 else if (evt.key == KeyCode::Delete) 163 { 164 toClipboard(buffer_); 165 clear(); 166 } 167 } 168 //std::string input = keyboard_->getAsString(e.key); 169 /*if (input.size() >= 1) 170 append(input[0]);*/ 171 172 append((char)evt.text); 173 } 174 175 /** 176 * This tick() function is called by the InputManager if the InputBuffer is active. 177 * @param dt Delta time 178 */ 179 void InputBuffer::tickInput(float dt, const HandlerState& state) 180 { 181 timeSinceKeyPressed_ += dt; 182 if (keysToRepeat_ < 10 && timeSinceKeyPressed_ > keyRepeatDeleay_) 183 { 184 // initial time out has gone by, start repeating keys 185 while (timeSinceKeyPressed_ - timeSinceKeyRepeated_ > keyRepeatTime_) 186 { 187 timeSinceKeyRepeated_ += keyRepeatTime_; 188 keysToRepeat_++; 189 } 190 } 191 } 192 193 void InputBuffer::keyPressed(const KeyEvent &evt) 194 { 195 lastKey_ = evt.key; 196 timeSinceKeyPressed_ = 0.0; 197 timeSinceKeyRepeated_ = keyRepeatDeleay_; 198 keysToRepeat_ = 0; 199 200 processKey(evt); 201 } 202 203 void InputBuffer::keyHeld(const KeyEvent& evt) 204 { 205 if (evt.key == lastKey_) 206 { 207 while (keysToRepeat_) 208 { 39 InputBuffer::InputBuffer() 40 { 41 RegisterObject(InputBuffer); 42 43 this->buffer_ = ""; 44 this->cursor_ = 0; 45 this->allowedChars_ = "abcdefghijklmnopqrstuvwxyz \ 46 ABCDEFGHIJKLMNOPQRSTUVWXYZ \ 47 äëïöüÄËÏÖÜáâàéêèíîìóôòúûù \ 48 0123456789 \ 49 \\\"(){}[]<>.:,;_-+*/=!?|$&%^~#"; 50 51 this->lastKey_ = KeyCode::Unassigned; 52 this->timeSinceKeyPressed_ = 0.0f; 53 this->timeSinceKeyRepeated_ = 0.0f; 54 this->keysToRepeat_ = 0; 55 56 setConfigValues(); 57 } 58 59 InputBuffer::InputBuffer(const std::string allowedChars) 60 { 61 RegisterObject(InputBuffer); 62 63 this->allowedChars_ = allowedChars; 64 this->buffer_ = ""; 65 this->cursor_ = 0; 66 67 this->lastKey_ = KeyCode::Unassigned; 68 this->timeSinceKeyPressed_ = 0.0f; 69 this->timeSinceKeyRepeated_ = 0.0f; 70 this->keysToRepeat_ = 0; 71 72 setConfigValues(); 73 } 74 75 void InputBuffer::setConfigValues() 76 { 77 SetConfigValue(keyRepeatDeleay_, 0.4).description("Key repeat deleay of the input buffer"); 78 SetConfigValue(keyRepeatTime_, 0.022).description("Key repeat time of the input buffer"); 79 80 if (keyRepeatDeleay_ < 0.0) 81 { 82 ResetConfigValue(keyRepeatDeleay_); 83 } 84 if (keyRepeatTime_ < 0.0) 85 { 86 ResetConfigValue(keyRepeatTime_); 87 } 88 } 89 90 void InputBuffer::unregisterListener(InputBufferListener* listener) 91 { 92 for (std::list<InputBufferListenerTuple>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) 93 { 94 if ((*it).listener_ == listener) 95 this->listeners_.erase(it++); 96 else 97 ++it; 98 } 99 } 100 101 void InputBuffer::set(const std::string& input, bool update) 102 { 103 this->clear(false); 104 this->insert(input, update); 105 } 106 107 void InputBuffer::insert(const std::string& input, bool update) 108 { 109 for (unsigned int i = 0; i < input.size(); ++i) 110 { 111 this->insert(input[i], false); 112 113 if (update) 114 this->updated(input[i], false); 115 } 116 117 if (update) 118 this->updated(); 119 } 120 121 void InputBuffer::insert(const char& input, bool update) 122 { 123 if (this->charIsAllowed(input)) 124 { 125 this->buffer_.insert(this->cursor_, 1, input); 126 ++this->cursor_; 127 } 128 129 if (update) 130 this->updated(input, true); 131 } 132 133 void InputBuffer::clear(bool update) 134 { 135 this->buffer_ = ""; 136 this->cursor_ = 0; 137 138 if (update) 139 this->updated(); 140 } 141 142 void InputBuffer::removeBehindCursor(bool update) 143 { 144 if (this->cursor_ > 0) 145 { 146 --this->cursor_; 147 this->buffer_.erase(this->cursor_, 1); 148 149 if (update) 150 this->updated(); 151 } 152 } 153 154 void InputBuffer::removeAtCursor(bool update) 155 { 156 if (this->cursor_ < this->buffer_.size()) 157 { 158 this->buffer_.erase(this->cursor_, 1); 159 160 if (update) 161 this->updated(); 162 } 163 } 164 165 void InputBuffer::updated() 166 { 167 for (std::list<InputBufferListenerTuple>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 168 { 169 if ((*it).bListenToAllChanges_) 170 (*(*it).listener_.*(*it).function_)(); 171 } 172 } 173 174 void InputBuffer::updated(const char& update, bool bSingleInput) 175 { 176 for (std::list<InputBufferListenerTuple>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 177 { 178 if ((!(*it).trueKeyFalseChar_) && ((*it).bListenToAllChanges_ || ((*it).char_ == update)) && (!(*it).bOnlySingleInput_ || bSingleInput)) 179 (*(*it).listener_.*(*it).function_)(); 180 } 181 } 182 183 bool InputBuffer::charIsAllowed(const char& input) 184 { 185 if (this->allowedChars_ == "") 186 return true; 187 else 188 return (this->allowedChars_.find(input) != std::string::npos); 189 } 190 191 192 void InputBuffer::processKey(const KeyEvent &evt) 193 { 194 if (evt.isModifierDown(KeyboardModifier::Alt) && evt.key == KeyCode::Tab) 195 return; 196 197 for (std::list<InputBufferListenerTuple>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 198 { 199 if ((*it).trueKeyFalseChar_ && ((*it).key_ == evt.key)) 200 (*(*it).listener_.*(*it).function_)(); 201 } 202 203 if (evt.isModifierDown(KeyboardModifier::Ctrl)) 204 { 205 if (evt.key == KeyCode::V) 206 this->insert(fromClipboard()); 207 else if (evt.key == KeyCode::C) 208 toClipboard(this->buffer_); 209 else if (evt.key == KeyCode::X) 210 { 211 toClipboard(this->buffer_); 212 this->clear(); 213 } 214 } 215 else if (evt.isModifierDown(KeyboardModifier::Shift)) 216 { 217 if (evt.key == KeyCode::Insert) 218 this->insert(fromClipboard()); 219 else if (evt.key == KeyCode::Delete) 220 { 221 toClipboard(this->buffer_); 222 this->clear(); 223 } 224 } 225 226 this->insert((char)evt.text); 227 } 228 229 /** 230 @brief This tick() function is called by the InputManager if the InputBuffer is active. 231 @param dt Delta time 232 */ 233 void InputBuffer::tickInput(float dt, const HandlerState& state) 234 { 235 timeSinceKeyPressed_ += dt; 236 if (keysToRepeat_ < 10 && timeSinceKeyPressed_ > keyRepeatDeleay_) 237 { 238 // initial time out has gone by, start repeating keys 239 while (timeSinceKeyPressed_ - timeSinceKeyRepeated_ > keyRepeatTime_) 240 { 241 timeSinceKeyRepeated_ += keyRepeatTime_; 242 keysToRepeat_++; 243 } 244 } 245 } 246 247 void InputBuffer::keyPressed(const KeyEvent &evt) 248 { 249 lastKey_ = evt.key; 250 timeSinceKeyPressed_ = 0.0; 251 timeSinceKeyRepeated_ = keyRepeatDeleay_; 252 keysToRepeat_ = 0; 253 209 254 processKey(evt); 210 keysToRepeat_--; 211 } 212 } 213 } 214 255 } 256 257 void InputBuffer::keyHeld(const KeyEvent& evt) 258 { 259 if (evt.key == lastKey_) 260 { 261 while (keysToRepeat_) 262 { 263 processKey(evt); 264 keysToRepeat_--; 265 } 266 } 267 } 215 268 } -
code/branches/network/src/core/InputBuffer.h
r1413 r1446 36 36 37 37 #include "InputInterfaces.h" 38 #include " Tickable.h"38 #include "OrxonoxClass.h" 39 39 40 40 namespace orxonox 41 41 { 42 class _CoreExport InputBufferListener43 {};42 class _CoreExport InputBufferListener 43 {}; 44 44 45 class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass 46 { 47 struct InputBufferListenerTuple 45 class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass 48 46 { 49 InputBufferListener* listener_; 50 void (InputBufferListener::*function_)(); 51 bool bListenToAllChanges_; 52 bool bOnlySingleInput_; 53 char char_; 47 struct InputBufferListenerTuple 48 { 49 InputBufferListener* listener_; 50 void (InputBufferListener::*function_)(); 51 bool bListenToAllChanges_; 52 bool bOnlySingleInput_; 53 bool trueKeyFalseChar_; 54 char char_; 55 KeyCode::Enum key_; 56 }; 57 58 public: 59 InputBuffer(); 60 InputBuffer(const std::string allowedChars); 61 62 void setConfigValues(); 63 64 template <class T> 65 void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput) 66 { 67 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned}; 68 this->listeners_.insert(this->listeners_.end(), newListener); 69 } 70 template <class T> 71 void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput) 72 { 73 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned}; 74 this->listeners_.insert(this->listeners_.end(), newListener); 75 } 76 77 template <class T> 78 void registerListener(T* listener, void (T::*function)(), char _char, bool bOnlySingleInput) 79 { 80 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned}; 81 this->listeners_.insert(this->listeners_.end(), newListener); 82 } 83 template <class T> 84 void registerListener(T* listener, void (T::*function)() const, char _char, bool bOnlySingleInput) 85 { 86 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned}; 87 this->listeners_.insert(this->listeners_.end(), newListener); 88 } 89 90 template <class T> 91 void registerListener(T* listener, void (T::*function)(), KeyCode::Enum key) 92 { 93 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, true, true, '\0', key}; 94 this->listeners_.insert(this->listeners_.end(), newListener); 95 } 96 template <class T> 97 void registerListener(T* listener, void (T::*function)() const, KeyCode::Enum key) 98 { 99 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, true, true, '\0', key}; 100 this->listeners_.insert(this->listeners_.end(), newListener); 101 } 102 103 void unregisterListener(InputBufferListener* listener); 104 105 void set(const std::string& input, bool update = true); 106 void insert(const std::string& input, bool update = true); 107 void insert(const char& input, bool update = true); 108 void clear(bool update = true); 109 void removeAtCursor(bool update = true); 110 void removeBehindCursor(bool update = true); 111 112 void updated(); 113 void updated(const char& update, bool bSingleInput); 114 115 inline std::string get() const 116 { return this->buffer_; } 117 inline unsigned int getSize() const 118 { return this->buffer_.size(); } 119 120 inline unsigned int getCursorPosition() const 121 { return this->cursor_; } 122 inline void setCursorPosition(unsigned int cursor) 123 { if (cursor <= this->buffer_.size()) { this->cursor_ = cursor; } } 124 inline void setCursorToEnd() 125 { this->cursor_ = this->buffer_.size(); } 126 inline void setCursorToBegin() 127 { this->cursor_ = 0; } 128 inline void increaseCursor() 129 { if (this->cursor_ < this->buffer_.size()) { ++this->cursor_; } } 130 inline void decreaseCursor() 131 { if (this->cursor_ > 0) { --this->cursor_; } } 132 133 private: 134 bool charIsAllowed(const char& input); 135 136 void keyPressed (const KeyEvent& evt); 137 void keyReleased(const KeyEvent& evt) { } 138 void keyHeld (const KeyEvent& evt); 139 void processKey (const KeyEvent &e); 140 141 void tickInput(float dt, const HandlerState& state); 142 143 std::string buffer_; 144 std::list<InputBufferListenerTuple> listeners_; 145 std::string allowedChars_; 146 unsigned int cursor_; 147 148 KeyCode::Enum lastKey_; 149 float timeSinceKeyPressed_; 150 float timeSinceKeyRepeated_; 151 int keysToRepeat_; 152 153 float keyRepeatDeleay_; 154 float keyRepeatTime_; 54 155 }; 55 56 public:57 InputBuffer(const std::string allowedChars =58 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^");59 60 void setConfigValues();61 62 template <class T>63 void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput)64 {65 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '};66 this->listeners_.insert(this->listeners_.end(), newListener);67 }68 template <class T>69 void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput)70 {71 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '};72 this->listeners_.insert(this->listeners_.end(), newListener);73 }74 75 template <class T>76 void registerListener(T* listener, void (T::*function)(), char char_, bool bOnlySingleInput)77 {78 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_};79 this->listeners_.insert(this->listeners_.end(), newListener);80 }81 template <class T>82 void registerListener(T* listener, void (T::*function)() const, char char_, bool bOnlySingleInput)83 {84 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_};85 this->listeners_.insert(this->listeners_.end(), newListener);86 }87 88 void set(const std::string& input);89 void append(const std::string& input);90 void append(const char& input);91 void removeLast();92 void clear();93 94 void updated();95 void updated(const char& update, bool bSingleInput);96 97 inline std::string get() const98 { return this->buffer_; }99 100 private: // functions101 bool charIsAllowed(const char& input);102 103 void keyPressed (const KeyEvent& evt);104 void keyReleased(const KeyEvent& evt) { }105 void keyHeld (const KeyEvent& evt);106 void processKey (const KeyEvent &e);107 108 void tickInput(float dt, const HandlerState& state);109 110 private: // variables111 std::string buffer_;112 std::list<InputBufferListenerTuple> listeners_;113 std::string allowedChars_;114 115 KeyCode::Enum lastKey_;116 float timeSinceKeyPressed_;117 float timeSinceKeyRepeated_;118 int keysToRepeat_;119 120 // configured values121 float keyRepeatDeleay_;122 float keyRepeatTime_;123 };124 156 } 125 157 -
code/branches/network/src/core/InputManager.cc
r1444 r1446 42 42 #include "CommandExecutor.h" 43 43 #include "ConsoleCommand.h" 44 #include "Shell.h" 44 45 45 46 namespace orxonox 46 47 { 47 ConsoleCommandShortcut(InputManager, keyBind, AccessLevel::User);48 ConsoleCommandShortcut(InputManager, storeKeyStroke, AccessLevel::Offline);49 ConsoleCommandShortcut(InputManager, calibrate, AccessLevel::User);48 SetConsoleCommandShortcut(InputManager, keyBind); 49 SetConsoleCommandShortcut(InputManager, storeKeyStroke); 50 SetConsoleCommandShortcut(InputManager, calibrate); 50 51 51 52 // ############################### … … 150 151 buffer_ = new InputBuffer(); 151 152 addKeyHandler(buffer_, "buffer"); 153 Shell::getInstance().setInputBuffer(buffer_); 152 154 153 155 keyBinder_ = new KeyBinder(); … … 233 235 // register our listener in OIS. 234 236 mouse_->setEventCallback(this); 235 CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;237 CCOUT(ORX_DEBUG) << "Created OIS mouse" << std::endl; 236 238 return true; 237 239 } … … 907 909 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 908 910 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis, fValue); 909 } 911 } 910 912 } 911 913 … … 953 955 if (lastState & OIS::Pov::West) 954 956 buttonReleased(arg, 32 + id * 4 + 3); 955 957 956 958 povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction; 957 959 -
code/branches/network/src/core/Iterator.h
r1063 r1446 50 50 51 51 #include "ObjectList.h" 52 #include "Debug.h"53 52 54 53 namespace orxonox -
code/branches/network/src/core/KeyBinder.cc
r1444 r1446 42 42 #include "CoreIncludes.h" 43 43 #include "CommandExecutor.h" 44 #include "ConsoleCommand.h" 44 45 #include "Executor.h" 45 46 // TODO: only needed by the CalibratorCallback class; move to new file … … 66 67 cmd.nValuesAdded_ = 0; 67 68 cmd.value_ = 0; 68 return CommandExecutor::execute(cmd.evaluation_);69 return cmd.evaluation_.execute(); 69 70 } 70 71 else … … 82 83 bool SimpleCommand::execute(float abs, float rel) 83 84 { 84 return CommandExecutor::execute(evaluation_);85 return evaluation_.execute(); 85 86 } 86 87 … … 183 184 SubString tokens(commandStrings[iCommand], " ", SubString::WhiteSpaces, false, 184 185 '\\', false, '"', false, '(', ')', false, '\0'); 185 186 186 187 unsigned int iToken = 0; 187 188 … … 238 239 239 240 // check for param command 240 int paramIndex = eval.get EvaluatedExecutor()->getAxisParamIndex();241 int paramIndex = eval.getConsoleCommand()->getAxisParamIndex(); 241 242 if (paramIndex >= 0) 242 243 { … … 244 245 ParamCommand* cmd = new ParamCommand(); 245 246 cmd->paramModifier_ = paramModifier; 246 cmd->bRelative_ = eval.get EvaluatedExecutor()->getIsAxisRelative();247 cmd->bRelative_ = eval.getConsoleCommand()->getIsAxisRelative(); 247 248 248 249 // add command to the buffer if not yet existing 249 250 for (unsigned int iParamCmd = 0; iParamCmd < paramCommandBuffer.size(); iParamCmd++) 250 251 { 251 if (getLowercase(paramCommandBuffer[iParamCmd]->evaluation_.get CommandString())252 if (getLowercase(paramCommandBuffer[iParamCmd]->evaluation_.getOriginalCommand()) 252 253 == getLowercase(commandStr)) 253 254 { … … 271 272 if (!addParamCommand(cmd)) 272 273 { 273 mode = eval.get EvaluatedExecutor()->getKeybindMode();274 mode = eval.getConsoleCommand()->getKeybindMode(); 274 275 commands[mode].push_back(cmd); 275 276 } … … 282 283 283 284 if (mode == KeybindMode::None) 284 mode = eval.get EvaluatedExecutor()->getKeybindMode();285 mode = eval.getConsoleCommand()->getKeybindMode(); 285 286 286 287 commands[mode].push_back(cmd); … … 331 332 } 332 333 } 333 334 334 335 bool HalfAxis::addParamCommand(ParamCommand* command) 335 336 { -
code/branches/network/src/core/KeyBinder.h
r1444 r1446 43 43 #include "util/Math.h" 44 44 #include "OrxonoxClass.h" 45 #include "CommandE xecutor.h"45 #include "CommandEvaluation.h" 46 46 #include "InputInterfaces.h" 47 47 -
code/branches/network/src/core/Language.cc
r1062 r1446 37 37 38 38 #include "CoreSettings.h" 39 40 #include "Debug.h" 39 41 40 42 namespace orxonox -
code/branches/network/src/core/Language.h
r1064 r1446 50 50 #include <map> 51 51 #include <string> 52 53 52 54 53 #define AddLanguageEntry(label, fallbackstring) \ -
code/branches/network/src/core/OrxonoxClass.cc
r1293 r1446 33 33 34 34 #include "OrxonoxClass.h" 35 #include "MetaObjectList.h" 36 #include "Identifier.h" 35 37 36 38 namespace orxonox … … 41 43 parents_(0) 42 44 { 45 this->metaList_ = new MetaObjectList(); 46 43 47 this->setConfigValues(); 44 48 } … … 47 51 OrxonoxClass::~OrxonoxClass() 48 52 { 53 delete this->metaList_; 54 49 55 // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class 50 56 if (this->parents_) 51 57 delete this->parents_; 52 58 } 59 60 /** @brief Returns true if the objects class is of the given type or a derivative. */ 61 bool OrxonoxClass::isA(const Identifier* identifier) 62 { return this->getIdentifier()->isA(identifier); } 63 /** @brief Returns true if the objects class is exactly of the given type. */ 64 bool OrxonoxClass::isExactlyA(const Identifier* identifier) 65 { return this->getIdentifier()->isExactlyA(identifier); } 66 /** @brief Returns true if the objects class is a child of the given type. */ 67 bool OrxonoxClass::isChildOf(const Identifier* identifier) 68 { return this->getIdentifier()->isChildOf(identifier); } 69 /** @brief Returns true if the objects class is a direct child of the given type. */ 70 bool OrxonoxClass::isDirectChildOf(const Identifier* identifier) 71 { return this->getIdentifier()->isDirectChildOf(identifier); } 72 /** @brief Returns true if the objects class is a parent of the given type. */ 73 bool OrxonoxClass::isParentOf(const Identifier* identifier) 74 { return this->getIdentifier()->isParentOf(identifier); } 75 /** @brief Returns true if the objects class is a direct parent of the given type. */ 76 bool OrxonoxClass::isDirectParentOf(const Identifier* identifier) 77 { return this->getIdentifier()->isDirectParentOf(identifier); } 78 79 80 /** @brief Returns true if the objects class is of the given type or a derivative. */ 81 bool OrxonoxClass::isA(const SubclassIdentifier<class B>* identifier) 82 { return this->getIdentifier()->isA(identifier->getIdentifier()); } 83 /** @brief Returns true if the objects class is exactly of the given type. */ 84 bool OrxonoxClass::isExactlyA(const SubclassIdentifier<class B>* identifier) 85 { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); } 86 /** @brief Returns true if the objects class is a child of the given type. */ 87 bool OrxonoxClass::isChildOf(const SubclassIdentifier<class B>* identifier) 88 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 89 /** @brief Returns true if the objects class is a direct child of the given type. */ 90 bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<class B>* identifier) 91 { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); } 92 /** @brief Returns true if the objects class is a parent of the given type. */ 93 bool OrxonoxClass::isParentOf(const SubclassIdentifier<class B>* identifier) 94 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 95 /** @brief Returns true if the objects class is a direct parent of the given type. */ 96 bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<class B>* identifier) 97 { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); } 98 99 100 /** @brief Returns true if the objects class is of the given type or a derivative. */ 101 bool OrxonoxClass::isA(const SubclassIdentifier<class B> identifier) 102 { return this->getIdentifier()->isA(identifier.getIdentifier()); } 103 /** @brief Returns true if the objects class is exactly of the given type. */ 104 bool OrxonoxClass::isExactlyA(const SubclassIdentifier<class B> identifier) 105 { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); } 106 /** @brief Returns true if the objects class is a child of the given type. */ 107 bool OrxonoxClass::isChildOf(const SubclassIdentifier<class B> identifier) 108 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 109 /** @brief Returns true if the objects class is a direct child of the given type. */ 110 bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<class B> identifier) 111 { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); } 112 /** @brief Returns true if the objects class is a parent of the given type. */ 113 bool OrxonoxClass::isParentOf(const SubclassIdentifier<class B> identifier) 114 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 115 /** @brief Returns true if the objects class is a direct parent of the given type. */ 116 bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<class B> identifier) 117 { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); } 118 119 120 /** @brief Returns true if the objects class is of the given type or a derivative. */ 121 bool OrxonoxClass::isA(const OrxonoxClass* object) 122 { return this->getIdentifier()->isA(object->getIdentifier()); } 123 /** @brief Returns true if the objects class is exactly of the given type. */ 124 bool OrxonoxClass::isExactlyA(const OrxonoxClass* object) 125 { return this->getIdentifier()->isExactlyA(object->getIdentifier()); } 126 /** @brief Returns true if the objects class is a child of the given type. */ 127 bool OrxonoxClass::isChildOf(const OrxonoxClass* object) 128 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 129 /** @brief Returns true if the objects class is a direct child of the given type. */ 130 bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object) 131 { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); } 132 /** @brief Returns true if the objects class is a parent of the given type. */ 133 bool OrxonoxClass::isParentOf(const OrxonoxClass* object) 134 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 135 /** @brief Returns true if the objects class is a direct child of the given type. */ 136 bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object) 137 { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } 53 138 } -
code/branches/network/src/core/OrxonoxClass.h
r1062 r1446 43 43 #include <string> 44 44 45 #include "MetaObjectList.h"46 #include "Iterator.h"47 48 45 namespace orxonox 49 46 { … … 75 72 76 73 /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */ 77 inline MetaObjectList& getMetaList() { return this->metaList_; }74 inline MetaObjectList& getMetaList() { return (*this->metaList_); } 78 75 79 76 80 /** @brief Returns true if the objects class is of the given type or a derivative. */ 81 inline bool isA(const Identifier* identifier) 82 { return this->getIdentifier()->isA(identifier); } 83 /** @brief Returns true if the objects class is exactly of the given type. */ 84 inline bool isExactlyA(const Identifier* identifier) 85 { return this->getIdentifier()->isExactlyA(identifier); } 86 /** @brief Returns true if the objects class is a child of the given type. */ 87 inline bool isChildOf(const Identifier* identifier) 88 { return this->getIdentifier()->isChildOf(identifier); } 89 /** @brief Returns true if the objects class is a direct child of the given type. */ 90 inline bool isDirectChildOf(const Identifier* identifier) 91 { return this->getIdentifier()->isDirectChildOf(identifier); } 92 /** @brief Returns true if the objects class is a parent of the given type. */ 93 inline bool isParentOf(const Identifier* identifier) 94 { return this->getIdentifier()->isParentOf(identifier); } 95 /** @brief Returns true if the objects class is a direct parent of the given type. */ 96 inline bool isDirectParentOf(const Identifier* identifier) 97 { return this->getIdentifier()->isDirectParentOf(identifier); } 77 bool isA(const Identifier* identifier); 78 bool isExactlyA(const Identifier* identifier); 79 bool isChildOf(const Identifier* identifier); 80 bool isDirectChildOf(const Identifier* identifier); 81 bool isParentOf(const Identifier* identifier); 82 bool isDirectParentOf(const Identifier* identifier); 98 83 84 bool isA(const SubclassIdentifier<class B>* identifier); 85 bool isExactlyA(const SubclassIdentifier<class B>* identifier); 86 bool isChildOf(const SubclassIdentifier<class B>* identifier); 87 bool isDirectChildOf(const SubclassIdentifier<class B>* identifier); 88 bool isParentOf(const SubclassIdentifier<class B>* identifier); 89 bool isDirectParentOf(const SubclassIdentifier<class B>* identifier); 99 90 100 /** @brief Returns true if the objects class is of the given type or a derivative. */ 101 inline bool isA(const SubclassIdentifier<class B>* identifier) 102 { return this->getIdentifier()->isA(identifier->getIdentifier()); } 103 /** @brief Returns true if the objects class is exactly of the given type. */ 104 inline bool isExactlyA(const SubclassIdentifier<class B>* identifier) 105 { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); } 106 /** @brief Returns true if the objects class is a child of the given type. */ 107 inline bool isChildOf(const SubclassIdentifier<class B>* identifier) 108 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 109 /** @brief Returns true if the objects class is a direct child of the given type. */ 110 inline bool isDirectChildOf(const SubclassIdentifier<class B>* identifier) 111 { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); } 112 /** @brief Returns true if the objects class is a parent of the given type. */ 113 inline bool isParentOf(const SubclassIdentifier<class B>* identifier) 114 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 115 /** @brief Returns true if the objects class is a direct parent of the given type. */ 116 inline bool isDirectParentOf(const SubclassIdentifier<class B>* identifier) 117 { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); } 91 bool isA(const SubclassIdentifier<class B> identifier); 92 bool isExactlyA(const SubclassIdentifier<class B> identifier); 93 bool isChildOf(const SubclassIdentifier<class B> identifier); 94 bool isDirectChildOf(const SubclassIdentifier<class B> identifier); 95 bool isParentOf(const SubclassIdentifier<class B> identifier); 96 bool isDirectParentOf(const SubclassIdentifier<class B> identifier); 118 97 119 120 /** @brief Returns true if the objects class is of the given type or a derivative. */ 121 inline bool isA(const SubclassIdentifier<class B> identifier) 122 { return this->getIdentifier()->isA(identifier.getIdentifier()); } 123 /** @brief Returns true if the objects class is exactly of the given type. */ 124 inline bool isExactlyA(const SubclassIdentifier<class B> identifier) 125 { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); } 126 /** @brief Returns true if the objects class is a child of the given type. */ 127 inline bool isChildOf(const SubclassIdentifier<class B> identifier) 128 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 129 /** @brief Returns true if the objects class is a direct child of the given type. */ 130 inline bool isDirectChildOf(const SubclassIdentifier<class B> identifier) 131 { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); } 132 /** @brief Returns true if the objects class is a parent of the given type. */ 133 inline bool isParentOf(const SubclassIdentifier<class B> identifier) 134 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 135 /** @brief Returns true if the objects class is a direct parent of the given type. */ 136 inline bool isDirectParentOf(const SubclassIdentifier<class B> identifier) 137 { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); } 138 139 140 /** @brief Returns true if the objects class is of the given type or a derivative. */ 141 inline bool isA(const OrxonoxClass* object) 142 { return this->getIdentifier()->isA(object->getIdentifier()); } 143 /** @brief Returns true if the objects class is exactly of the given type. */ 144 inline bool isExactlyA(const OrxonoxClass* object) 145 { return this->getIdentifier()->isExactlyA(object->getIdentifier()); } 146 /** @brief Returns true if the objects class is a child of the given type. */ 147 inline bool isChildOf(const OrxonoxClass* object) 148 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 149 /** @brief Returns true if the objects class is a direct child of the given type. */ 150 inline bool isDirectChildOf(const OrxonoxClass* object) 151 { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); } 152 /** @brief Returns true if the objects class is a parent of the given type. */ 153 inline bool isParentOf(const OrxonoxClass* object) 154 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 155 /** @brief Returns true if the objects class is a direct child of the given type. */ 156 inline bool isDirectParentOf(const OrxonoxClass* object) 157 { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } 98 bool isA(const OrxonoxClass* object); 99 bool isExactlyA(const OrxonoxClass* object); 100 bool isChildOf(const OrxonoxClass* object); 101 bool isDirectChildOf(const OrxonoxClass* object); 102 bool isParentOf(const OrxonoxClass* object); 103 bool isDirectParentOf(const OrxonoxClass* object); 158 104 159 105 private: 160 Identifier* identifier_; 106 Identifier* identifier_; //!< The Identifier of the object 161 107 std::set<const Identifier*>* parents_; //!< List of all parents of the object 162 MetaObjectList metaList_;//!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in108 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 163 109 }; 164 110 } -
code/branches/network/src/core/OutputHandler.cc
r1062 r1446 38 38 namespace orxonox 39 39 { 40 ConsoleCommandShortcutGeneric(log, createExecutor(createFunctor(&OutputHandler::log), "log", AccessLevel::None)); 40 SetConsoleCommandShortcutGeneric(log, createConsoleCommand(createFunctor(&OutputHandler::log), "log" )); 41 SetConsoleCommandShortcutGeneric(error, createConsoleCommand(createFunctor(&OutputHandler::error), "error" )); 42 SetConsoleCommandShortcutGeneric(warning, createConsoleCommand(createFunctor(&OutputHandler::warning), "warning")); 43 SetConsoleCommandShortcutGeneric(info, createConsoleCommand(createFunctor(&OutputHandler::info), "info" )); 44 SetConsoleCommandShortcutGeneric(debug, createConsoleCommand(createFunctor(&OutputHandler::debug), "debug" )); 41 45 42 46 /** … … 97 101 } 98 102 103 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 104 Shell::getInstance().getOutputBuffer() << sb; 105 99 106 return *this; 100 107 } … … 115 122 this->logfile_.flush(); 116 123 } 124 125 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 126 Shell::getInstance().getOutputBuffer() << manipulator; 117 127 118 128 return *this; … … 135 145 } 136 146 147 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 148 Shell::getInstance().getOutputBuffer() << manipulator; 149 137 150 return *this; 138 151 } … … 154 167 } 155 168 169 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 170 Shell::getInstance().getOutputBuffer() << manipulator; 171 156 172 return *this; 157 173 } -
code/branches/network/src/core/OutputHandler.h
r1064 r1446 44 44 #include <string> 45 45 46 #include "Shell.h" 47 46 48 namespace orxonox 47 49 { … … 63 65 static inline std::string log(const std::string& text) 64 66 { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); return text; } 67 68 /** @brief Puts an error on the outstream. @param text The text */ 69 static inline std::string error(const std::string& text) 70 { OutputHandler::getOutStream().setOutputLevel(1); OutputHandler::getOutStream().output(text + "\n"); return text; } 71 72 /** @brief Puts a warning on the outstream. @param text The text */ 73 static inline std::string warning(const std::string& text) 74 { OutputHandler::getOutStream().setOutputLevel(2); OutputHandler::getOutStream().output(text + "\n"); return text; } 75 76 /** @brief Puts an info on the outstream. @param text The text */ 77 static inline std::string info(const std::string& text) 78 { OutputHandler::getOutStream().setOutputLevel(3); OutputHandler::getOutStream().output(text + "\n"); return text; } 79 80 /** @brief Puts some debug output on the outstream. @param text The text */ 81 static inline std::string debug(const std::string& text) 82 { OutputHandler::getOutStream().setOutputLevel(4); OutputHandler::getOutStream().output(text + "\n"); return text; } 65 83 66 84 /** @brief Returns a reference to the logfile. @return The logfile */ … … 138 156 } 139 157 158 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 159 Shell::getInstance().getOutputBuffer() << output; 160 140 161 return *this; 141 162 } … … 159 180 } 160 181 182 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= out.getOutputLevel()) 183 Shell::getInstance().getOutputBuffer() << output; 184 161 185 return out; 162 186 } -
code/branches/network/src/core/Script.cc
r1153 r1446 67 67 { 68 68 output_ += str; 69 COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl; 69 // COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl; 70 COUT(5) << str; 70 71 } 71 72 … … 99 100 100 101 if (luaTags) luaSource_ = replaceLuaTags(levelString); 101 COUT( 4) << "ParsedSourceCode: " << luaSource_ << std::endl;102 COUT(5) << "ParsedSourceCode: " << luaSource_ << std::endl; 102 103 } 103 104 … … 127 128 if (error == 0) 128 129 error = lua_pcall(luaState_, 0, 0, 0); 129 if (error != 0) COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl; 130 if (error != 0) 131 { 132 COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl; 133 } 130 134 } 131 135 -
code/branches/network/src/core/Shell.cc
r1445 r1446 33 33 #include "CoreSettings.h" 34 34 #include "ConsoleCommand.h" 35 #include "InputManager.h" 35 36 36 37 #define SHELL_UPDATE_LISTENERS(function) \ … … 56 57 this->clearLines(); 57 58 58 this->inputBuffer_.registerListener(this, &Shell::inputChanged, true); 59 this->inputBuffer_.registerListener(this, &Shell::execute, '\r', false); 60 this->inputBuffer_.registerListener(this, &Shell::hintandcomplete, '\t', true); 61 this->inputBuffer_.registerListener(this, &Shell::backspace, '\b', true); 62 this->inputBuffer_.registerListener(this, &Shell::deletechar, OIS::KC_DELETE); 63 this->inputBuffer_.registerListener(this, &Shell::exit, (char)27, true); 64 this->inputBuffer_.registerListener(this, &Shell::cursor_right, OIS::KC_RIGHT); 65 this->inputBuffer_.registerListener(this, &Shell::cursor_left, OIS::KC_LEFT); 66 this->inputBuffer_.registerListener(this, &Shell::cursor_end, OIS::KC_END); 67 this->inputBuffer_.registerListener(this, &Shell::cursor_home, OIS::KC_HOME); 68 this->inputBuffer_.registerListener(this, &Shell::history_up, OIS::KC_UP); 69 this->inputBuffer_.registerListener(this, &Shell::history_down, OIS::KC_DOWN); 70 this->inputBuffer_.registerListener(this, &Shell::scroll_up, OIS::KC_PGUP); 71 this->inputBuffer_.registerListener(this, &Shell::scroll_down, OIS::KC_PGDOWN); 59 this->inputBuffer_ = 0; 60 this->setInputBuffer(new InputBuffer()); 72 61 73 62 this->outputBuffer_.registerListener(this); … … 108 97 } 109 98 99 void Shell::setInputBuffer(InputBuffer* buffer) 100 { 101 if (this->inputBuffer_) 102 { 103 this->inputBuffer_->unregisterListener(this); 104 delete this->inputBuffer_; 105 } 106 107 this->inputBuffer_ = buffer; 108 this->inputBuffer_->registerListener(this, &Shell::inputChanged, true); 109 this->inputBuffer_->registerListener(this, &Shell::execute, '\r', false); 110 this->inputBuffer_->registerListener(this, &Shell::hintandcomplete, '\t', true); 111 this->inputBuffer_->registerListener(this, &Shell::backspace, '\b', true); 112 this->inputBuffer_->registerListener(this, &Shell::deletechar, OIS::KC_DELETE); 113 this->inputBuffer_->registerListener(this, &Shell::exit, (char)27, true); 114 this->inputBuffer_->registerListener(this, &Shell::cursor_right, OIS::KC_RIGHT); 115 this->inputBuffer_->registerListener(this, &Shell::cursor_left, OIS::KC_LEFT); 116 this->inputBuffer_->registerListener(this, &Shell::cursor_end, OIS::KC_END); 117 this->inputBuffer_->registerListener(this, &Shell::cursor_home, OIS::KC_HOME); 118 this->inputBuffer_->registerListener(this, &Shell::history_up, OIS::KC_UP); 119 this->inputBuffer_->registerListener(this, &Shell::history_down, OIS::KC_DOWN); 120 this->inputBuffer_->registerListener(this, &Shell::scroll_up, OIS::KC_PGUP); 121 this->inputBuffer_->registerListener(this, &Shell::scroll_down, OIS::KC_PGDOWN); 122 } 123 110 124 void Shell::clearShell() 111 125 { … … 141 155 void Shell::setCursorPosition(unsigned int cursor) 142 156 { 143 this->inputBuffer_ .setCursorPosition(cursor);157 this->inputBuffer_->setCursorPosition(cursor); 144 158 SHELL_UPDATE_LISTENERS(cursorChanged); 145 159 } … … 147 161 void Shell::setInput(const std::string& input) 148 162 { 149 this->inputBuffer_ .set(input);163 this->inputBuffer_->set(input); 150 164 this->inputChanged(); 151 165 } … … 251 265 void Shell::execute() 252 266 { 253 this->addToHistory(this->inputBuffer_ .get());254 this->addLine(this->inputBuffer_ .get(), 0);255 256 if (!CommandExecutor::execute(this->inputBuffer_ .get()))257 this->addLine("Error: Can't execute \"" + this->inputBuffer_ .get() + "\".", 1);267 this->addToHistory(this->inputBuffer_->get()); 268 this->addLine(this->inputBuffer_->get(), 0); 269 270 if (!CommandExecutor::execute(this->inputBuffer_->get())) 271 this->addLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1); 258 272 259 273 this->clear(); … … 262 276 void Shell::hintandcomplete() 263 277 { 264 this->inputBuffer_ .set(CommandExecutor::complete(this->inputBuffer_.get()));265 this->addLine(CommandExecutor::hint(this->inputBuffer_ .get()), -1);278 this->inputBuffer_->set(CommandExecutor::complete(this->inputBuffer_->get())); 279 this->addLine(CommandExecutor::hint(this->inputBuffer_->get()), -1); 266 280 267 281 this->inputChanged(); … … 270 284 void Shell::backspace() 271 285 { 272 this->inputBuffer_ .removeBehindCursor();286 this->inputBuffer_->removeBehindCursor(); 273 287 SHELL_UPDATE_LISTENERS(inputChanged); 274 288 SHELL_UPDATE_LISTENERS(cursorChanged); … … 277 291 void Shell::deletechar() 278 292 { 279 this->inputBuffer_ .removeAtCursor();293 this->inputBuffer_->removeAtCursor(); 280 294 SHELL_UPDATE_LISTENERS(inputChanged); 281 295 } … … 283 297 void Shell::clear() 284 298 { 285 this->inputBuffer_ .clear();299 this->inputBuffer_->clear(); 286 300 this->historyPosition_ = 0; 287 301 SHELL_UPDATE_LISTENERS(inputChanged); … … 291 305 void Shell::cursor_right() 292 306 { 293 this->inputBuffer_ .increaseCursor();307 this->inputBuffer_->increaseCursor(); 294 308 SHELL_UPDATE_LISTENERS(cursorChanged); 295 309 } … … 297 311 void Shell::cursor_left() 298 312 { 299 this->inputBuffer_ .decreaseCursor();313 this->inputBuffer_->decreaseCursor(); 300 314 SHELL_UPDATE_LISTENERS(cursorChanged); 301 315 } … … 303 317 void Shell::cursor_end() 304 318 { 305 this->inputBuffer_ .setCursorToEnd();319 this->inputBuffer_->setCursorToEnd(); 306 320 SHELL_UPDATE_LISTENERS(cursorChanged); 307 321 } … … 309 323 void Shell::cursor_home() 310 324 { 311 this->inputBuffer_ .setCursorToBegin();325 this->inputBuffer_->setCursorToBegin(); 312 326 SHELL_UPDATE_LISTENERS(cursorChanged); 313 327 } … … 318 332 { 319 333 this->historyPosition_++; 320 this->inputBuffer_ .set(this->getFromHistory());334 this->inputBuffer_->set(this->getFromHistory()); 321 335 } 322 336 } … … 327 341 { 328 342 this->historyPosition_--; 329 this->inputBuffer_ .set(this->getFromHistory());343 this->inputBuffer_->set(this->getFromHistory()); 330 344 } 331 345 } … … 355 369 void Shell::exit() 356 370 { 357 if (this->inputBuffer_ .getSize() > 0)371 if (this->inputBuffer_->getSize() > 0) 358 372 { 359 373 this->clear(); -
code/branches/network/src/core/Shell.h
r1445 r1446 71 71 void unregisterListener(ShellListener* listener); 72 72 73 void setInputBuffer(InputBuffer* buffer); 73 74 inline InputBuffer& getInputBuffer() 74 { return this->inputBuffer_; }75 { return (*this->inputBuffer_); } 75 76 inline OutputBuffer& getOutputBuffer() 76 77 { return this->outputBuffer_; } … … 78 79 void setCursorPosition(unsigned int cursor); 79 80 inline unsigned int getCursorPosition() const 80 { return this->inputBuffer_ .getCursorPosition(); }81 { return this->inputBuffer_->getCursorPosition(); } 81 82 82 83 void setInput(const std::string& input); … … 85 86 { this->setInput(""); } 86 87 inline std::string getInput() const 87 { return this->inputBuffer_ .get(); }88 { return this->inputBuffer_->get(); } 88 89 89 90 std::list<std::string>::const_iterator getNewestLineIterator() const; … … 127 128 128 129 std::list<ShellListener*> listeners_; 129 InputBuffer inputBuffer_;130 InputBuffer* inputBuffer_; 130 131 OutputBuffer outputBuffer_; 131 132 bool finishedLastLine_; -
code/branches/network/src/core/TclBind.cc
r1214 r1446 33 33 #include "CommandExecutor.h" 34 34 #include "Debug.h" 35 #include "TclThreadManager.h" 35 36 #include "TclBind.h" 37 #include "util/String.h" 36 38 37 39 namespace orxonox 38 40 { 39 ConsoleCommandShortcutGeneric(tcl, createExecutor(createFunctor(&TclBind::tcl), "tcl", AccessLevel::None)); 41 SetConsoleCommandShortcutGeneric(tcl, createConsoleCommand(createFunctor(&TclBind::tcl), "tcl")); 42 SetConsoleCommandShortcutGeneric(bgerror, createConsoleCommand(createFunctor(&TclBind::bgerror), "bgerror")); 40 43 41 44 TclBind::TclBind() … … 70 73 { 71 74 this->interpreter_ = new Tcl::interpreter(this->tclLibPath_); 72 this->interpreter_->def("puts", TclBind::puts, Tcl::variadic()); 73 this->interpreter_->def("orxonox", TclBind::orxonox, Tcl::variadic()); 74 this->interpreter_->def("execute", TclBind::execute, Tcl::variadic()); 75 this->interpreter_->eval("proc unknown {args} { return [orxonox $args] }"); 76 this->interpreter_->eval("rename exit tclexit; proc exit {} { orxonox exit }"); 75 this->interpreter_->def("orxonox::query", TclBind::tcl_query, Tcl::variadic()); 76 this->interpreter_->def("orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic()); 77 this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic()); 78 79 try 80 { 81 this->interpreter_->eval("proc query args { orxonox::query $args }"); 82 this->interpreter_->eval("proc crossquery {id args} { orxonox::crossquery 0 $id $args }"); 83 this->interpreter_->eval("set id 0"); 84 this->interpreter_->eval("rename exit tcl::exit; proc exit {} { execute exit }"); 85 this->interpreter_->eval("redef_puts"); 86 } 87 catch (Tcl::tcl_error const &e) 88 { COUT(1) << "Tcl error while creating Tcl-interpreter: " << e.what() << std::endl; } 89 catch (std::exception const &e) 90 { COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl; } 77 91 } 78 92 } … … 89 103 } 90 104 91 void TclBind::puts(Tcl::object const &args)105 std::string TclBind::tcl_query(Tcl::object const &args) 92 106 { 93 COUT(0) << args.get() << std::endl; 94 } 107 COUT(4) << "Tcl_query: " << args.get() << std::endl; 95 108 96 std::string TclBind::orxonox(Tcl::object const &args) 97 { 98 std::cout << "Tcl_execute: args: " << args.get() << std::endl; 99 std::string command = args.get(); 100 101 if (command.size() >= 2 && command[0] == '{' && command[command.size() - 1] == '}') 102 command = command.substr(1, command.size() - 2); 109 std::string command = stripEnclosingBraces(args.get()); 103 110 104 111 if (!CommandExecutor::execute(command, false)) 112 { 105 113 COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl; 114 } 106 115 107 116 if (CommandExecutor::getLastEvaluation().hasReturnvalue()) … … 111 120 } 112 121 113 void TclBind:: execute(Tcl::object const &args)122 void TclBind::tcl_execute(Tcl::object const &args) 114 123 { 124 COUT(4) << "Tcl_execute: " << args.get() << std::endl; 125 std::string command = stripEnclosingBraces(args.get()); 126 127 if (!CommandExecutor::execute(command, false)) 128 { 129 COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl; 130 } 115 131 } 116 132 … … 121 137 std::string output = TclBind::getInstance().interpreter_->eval(tclcode); 122 138 if (output != "") 139 { 123 140 COUT(0) << "tcl> " << output << std::endl; 141 } 124 142 return output; 125 143 } 126 144 catch (Tcl::tcl_error const &e) 127 { 128 COUT(1) << "tcl> Error: " << e.what() << std::endl; 129 } 145 { COUT(1) << "tcl> Error: " << e.what() << std::endl; } 130 146 catch (std::exception const &e) 131 { 132 COUT(1) << "Error while executing tcl: " << e.what() << std::endl; 133 } 147 { COUT(1) << "Error while executing Tcl: " << e.what() << std::endl; } 134 148 135 149 return ""; 150 } 151 152 void TclBind::bgerror(std::string error) 153 { 154 COUT(1) << "Tcl background error: " << stripEnclosingBraces(error) << std::endl; 136 155 } 137 156 … … 144 163 } 145 164 catch (Tcl::tcl_error const &e) 146 { 147 COUT(1) << "Error: " << e.what() << std::endl; 148 } 165 { COUT(1) << "Tcl error: " << e.what() << std::endl; } 149 166 catch (std::exception const &e) 150 { 151 COUT(1) << "Error while executing tcl: " << e.what() << std::endl; 152 } 167 { COUT(1) << "Error while executing Tcl: " << e.what() << std::endl; } 153 168 154 169 return false; -
code/branches/network/src/core/TclBind.h
r1223 r1446 41 41 static TclBind& getInstance(); 42 42 43 static std::string tcl(const std::string& tclcode); 44 static void bgerror(std::string error); 45 43 46 void setDataPath(const std::string& datapath); 47 std::string getTclLibPath() const { return this->tclLibPath_; } 44 48 void createTclInterpreter(); 45 49 void createNewTclInterpreter(); 50 Tcl::interpreter* getTclInterpreter() const { return this->interpreter_; } 46 51 47 static void puts(Tcl::object const &args); 48 static void execute(Tcl::object const &args); 49 static std::string orxonox(Tcl::object const &args); 50 static std::string tcl(const std::string& tclcode); 52 static std::string tcl_query(Tcl::object const &args); 53 static void tcl_execute(Tcl::object const &args); 54 51 55 static bool eval(const std::string& tclcode); 52 56 -
code/branches/network/src/core/XMLPort.h
r1445 r1446 78 78 namespace orxonox 79 79 { 80 81 #ifndef _XMLPort_Mode__82 #define _XMLPort_Mode__83 namespace XMLPort84 {85 enum Mode86 {87 LoadObject,88 SaveObject89 };90 }91 #endif92 93 80 // ############################### 94 81 // ### XMLPortParamContainer ### -
code/branches/network/src/network/GameStateClient.cc
r1432 r1446 42 42 int id; 43 43 }; 44 44 45 45 GameStateClient::GameStateClient() { 46 46 COUT(5) << "this: " << this << std::endl; … … 96 96 return false; 97 97 } 98 98 99 99 GameStateCompressed *GameStateClient::popPartialGameState(){ 100 100 GameState *gs = getPartialSnapshot(); … … 104 104 return cgs; 105 105 } 106 106 107 107 void GameStateClient::addGameState(GameStateCompressed *gs){ 108 108 if(tempGameState_!=NULL){ … … 128 128 return GAMESTATEID_INITIAL; 129 129 } 130 130 131 131 132 132 /** … … 193 193 } 194 194 if( !no->create() ) 195 { 195 196 COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl; 197 } 196 198 it=orxonox::ObjectList<Synchronisable>::end(); 197 199 } … … 199 201 // we have our object 200 202 if(! it->updateData(sync)) 203 { 201 204 COUT(1) << "We couldn't update objectID: " \ 202 205 << sync.objectID << "; classID: " << sync.classID << std::endl; 206 } 203 207 } 204 208 ++it; … … 272 276 return retval; 273 277 } 274 275 278 279 276 280 GameState *GameStateClient::undiff(GameState *old, GameState *diff) { 277 281 if(!old || !diff) … … 334 338 switch ( retval ) { 335 339 case Z_OK: COUT(5) << "G.St.Cl: compress: successfully compressed" << std::endl; break; 336 case Z_MEM_ERROR: COUT(1) << "G.St.Cl: compress: not enough memory available in gamestate.compress" << std::endl; 340 case Z_MEM_ERROR: COUT(1) << "G.St.Cl: compress: not enough memory available in gamestate.compress" << std::endl; 337 341 return NULL; 338 342 case Z_BUF_ERROR: COUT(2) << "G.St.Cl: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; … … 352 356 return compressedGamestate; 353 357 } 354 355 358 359 356 360 GameState *GameStateClient::decompress(GameStateCompressed *a) { 357 361 //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl; … … 409 413 return t; 410 414 } 411 415 412 416 void GameStateClient::cleanup(){ 413 417 std::map<int, GameState*>::iterator temp, it = gameStateMap.begin(); … … 431 435 } 432 436 COUT(4) << std::endl; 433 434 } 435 437 438 } 439 436 440 bool GameStateClient::saveShipCache(){ 437 441 if(myShip_==NULL) … … 448 452 return false; 449 453 } 450 454 451 455 bool GameStateClient::loadShipCache(){ 452 456 if(myShip_){ … … 459 463 return false; 460 464 } 461 465 462 466 //##### ADDED FOR TESTING PURPOSE ##### 463 467 GameState* GameStateClient::testDecompress( GameStateCompressed* gc ) { 464 468 return decompress( gc ); 465 469 } 466 470 467 471 GameState* GameStateClient::testUndiff( GameState* g_old, GameState* g_diffed ) { 468 472 return undiff( g_old, g_diffed ); 469 473 } 470 474 //##### ADDED FOR TESTING PURPOSE ##### 471 472 475 476 473 477 } 474 478 -
code/branches/network/src/network/PacketDecoder.cc
r1440 r1446 84 84 return false; 85 85 } 86 86 87 87 bool PacketDecoder::testAndRemoveCRC(ENetPacket *packet){ 88 88 uint32_t submittetcrc; … … 102 102 return false; 103 103 } 104 104 105 105 // ATTENTION: TODO watch, that arguments we pass over to the processFunction gets deleted in THE PROCESSXXX function 106 106 … … 118 118 enet_packet_destroy( packet ); 119 119 } 120 120 121 121 bool PacketDecoder::command( ENetPacket* packet, int clientId ){ 122 122 int length = *(int*)((unsigned char *)packet->data+sizeof(int)); … … 175 175 //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream 176 176 if(currentState->compsize==0) 177 { 177 178 COUT(2) << "PacketDecoder: compsize is 0" << std::endl; 179 } 178 180 // currentState->data = (unsigned char*)(malloc( currentState->compsize )); 179 181 if(currentState->compsize==0) … … 181 183 currentState->data = new unsigned char[currentState->compsize]; 182 184 if(currentState->data==NULL) 185 { 183 186 COUT(2) << "PacketDecoder: Gamestatepacket-decoder: memory leak" << std::endl; 187 } 184 188 //copy the GameStateCompressed data 185 189 memcpy( (void*)(currentState->data), (const void*)(packet->data+5*sizeof( int ) + 2*sizeof(bool)), currentState->compsize ); … … 206 210 processClassid(cid); 207 211 } 208 209 212 213 210 214 bool PacketDecoder::decodeWelcome( ENetPacket* packet, int clientID ){ 211 215 welcome *w = new welcome; … … 217 221 return processWelcome(w); 218 222 } 219 223 220 224 bool PacketDecoder::decodeConnectRequest( ENetPacket *packet, int clientID ){ 221 225 connectRequest *con = new connectRequest; … … 256 260 return; 257 261 } 258 262 259 263 bool PacketDecoder::processWelcome( welcome *w ){ 260 264 delete w; 261 265 return true; 262 266 } 263 267 264 268 bool PacketDecoder::processConnectRequest( connectRequest *con, int clientID ){ 265 269 COUT(3) << "packetdecoder: processing connectRequest" << std::endl; … … 280 284 { 281 285 if(clientId!=CLIENTID_CLIENT) 286 { 282 287 COUT(5) << "client: " << clientId << std::endl; 288 } 283 289 COUT(5) << "data id: " << data->id << std::endl; 284 290 COUT(5) << "data: " << data->message << std::endl; -
code/branches/network/src/network/dummyclient3.cc
r1293 r1446 51 51 Client client( str, PORT ); 52 52 if ( client.establishConnection() ) 53 { 53 54 COUT(3) << "connection established" << std::endl; 54 else COUT(0) << "problems establishing connection" << std::endl; 55 } 56 else 57 { 58 COUT(0) << "problems establishing connection" << std::endl; 59 } 55 60 char message[10000]; 56 61 char signs[] = "abcdefghijklmnopqrstuvwxy"; -
code/branches/network/src/orxonox/GraphicsEngine.cc
r1349 r1446 45 45 #include "core/Debug.h" 46 46 #include "core/CommandExecutor.h" 47 47 #include "console/InGameConsole.h" 48 48 49 49 namespace orxonox { … … 345 345 int h = rw->getHeight(); 346 346 InputManager::setWindowExtents(w, h); 347 InGameConsole::getInstance().resize(); 347 348 } 348 349 -
code/branches/network/src/orxonox/Orxonox.cc
r1443 r1446 51 51 //#include "util/Sleep.h" 52 52 #include "util/ArgReader.h" 53 #include "util/ExprParser.h"54 53 55 54 // core … … 57 56 #include "core/ConsoleCommand.h" 58 57 #include "core/Debug.h" 59 #include "core/Factory.h"60 58 #include "core/Loader.h" 61 59 #include "core/Tickable.h" 62 #include "core/InputBuffer.h"63 60 #include "core/InputManager.h" 64 61 #include "core/TclBind.h" … … 72 69 73 70 // objects and tools 74 #include "tools/Timer.h"75 71 #include "hud/HUD.h" 76 #include "console/InGameConsole.h"77 72 78 73 // FIXME: is this really file scope? … … 83 78 namespace orxonox 84 79 { 85 ConsoleCommandShortcut(Orxonox, exit, AccessLevel::None).setKeybindMode(KeybindMode::OnPress); 86 ConsoleCommandShortcut(Orxonox, slomo, AccessLevel::Offline).setDefaultValue(0, 1.0) 87 .setAxisParamIndex(0).setIsAxisRelative(false); 88 ConsoleCommandShortcut(Orxonox, setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0); 89 ConsoleCommandShortcut(Orxonox, activateConsole, AccessLevel::None); 90 class Testconsole : public InputBufferListener 91 { 92 public: 93 Testconsole(InputBuffer* ib) : ib_(ib) {} 94 void listen() const 95 { 96 std::cout << "> " << this->ib_->get() << std::endl; 97 } 98 void execute() const 99 { 100 std::cout << ">> " << this->ib_->get() << std::endl; 101 if (!CommandExecutor::execute(this->ib_->get())) 102 std::cout << "Error" << std::endl; 103 this->ib_->clear(); 104 } 105 void hintandcomplete() const 106 { 107 std::cout << CommandExecutor::hint(this->ib_->get()) << std::endl; 108 this->ib_->set(CommandExecutor::complete(this->ib_->get())); 109 } 110 void clear() const 111 { 112 this->ib_->clear(); 113 } 114 void removeLast() const 115 { 116 this->ib_->removeLast(); 117 } 118 void exit() const 119 { 120 InputManager::setInputState(InputManager::IS_NORMAL); 121 } 122 123 private: 124 InputBuffer* ib_; 125 }; 126 127 class Calculator 128 { 129 public: 130 static float calculate(const std::string& calculation) 131 { 132 ExprParser expr(calculation); 133 if (expr.getSuccess()) 134 { 135 if (expr.getResult() == 42.0) 136 std::cout << "Greetings from the restaurant at the end of the universe." << std::endl; 137 // FIXME: insert modifier to display in full precision 138 std::cout << "Result is: " << expr.getResult() << std::endl; 139 if (expr.getRemains() != "") 140 std::cout << "Warning: Expression could not be parsed to the end! Remains: '" 141 << expr.getRemains() << "'" << std::endl; 142 return expr.getResult(); 143 } 144 else 145 { 146 std::cout << "Cannot calculate expression: Parse error" << std::endl; 147 return 0; 148 } 149 } 150 }; 151 ConsoleCommandShortcut(Calculator, calculate, AccessLevel::None); 80 SetConsoleCommandShortcut(Orxonox, exit).setKeybindMode(KeybindMode::OnPress); 81 SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false); 82 SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0); 152 83 153 84 /** … … 165 96 // turn on frame smoothing by setting a value different from 0 166 97 frameSmoothingTime_(0.0f), 167 orxonoxConsole_(0),168 98 orxonoxHUD_(0), 169 99 bAbort_(false), … … 351 281 COUT(3) << "Orxonox: Loading HUD..." << std::endl; 352 282 orxonoxHUD_ = &HUD::getSingleton(); 353 354 COUT(3) << "Orxonox: Loading Console..." << std::endl;355 InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer"));356 /*357 Testconsole* console = new Testconsole(ib);358 ib->registerListener(console, &Testconsole::listen, true);359 ib->registerListener(console, &Testconsole::execute, '\r', false);360 ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true);361 ib->registerListener(console, &Testconsole::clear, '�', true);362 ib->registerListener(console, &Testconsole::removeLast, '\b', true);363 ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);364 */365 orxonoxConsole_ = new InGameConsole(ib);366 ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true);367 ib->registerListener(orxonoxConsole_, &InGameConsole::execute, '\r', false);368 ib->registerListener(orxonoxConsole_, &InGameConsole::hintandcomplete, '\t', true);369 //ib->registerListener(orxonoxConsole_, &InGameConsole::clear, '§', true);370 ib->registerListener(orxonoxConsole_, &InGameConsole::removeLast, '\b', true);371 ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true);372 373 283 return true; 374 284 } … … 495 405 renderTime = 0.0f; 496 406 } 497 407 498 408 // Call those objects that need the real time 499 409 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) … … 502 412 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 503 413 it->tick((float)evt.timeSinceLastFrame * this->timefactor_); 504 // TODO: currently a hack. Somehow the console doesn't work with OrxonoxClass505 orxonoxConsole_->tick((float)evt.timeSinceLastFrame);506 414 507 415 // don't forget to call _fireFrameStarted in ogre to make sure … … 571 479 return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000); 572 480 } 573 574 /**575 * Static function that shows the console in game mode.576 */577 void Orxonox::activateConsole()578 {579 // currently, the console shows itself when feeded with input.580 InputManager::setInputState(InputManager::IS_CONSOLE);581 }582 481 } -
code/branches/network/src/orxonox/Orxonox.h
r1379 r1446 70 70 static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; } 71 71 static inline void exit() { Orxonox::getSingleton()->abortRequest(); } 72 static inline void activateConsole();73 72 74 73 private: … … 97 96 // TODO: make this a config-value by creating a config class for orxonox 98 97 float frameSmoothingTime_; 99 InGameConsole* orxonoxConsole_;100 98 HUD* orxonoxHUD_; 101 99 bool bAbort_; //!< aborts the render loop if true -
code/branches/network/src/orxonox/console/InGameConsole.cc
r1362 r1446 23 23 * Felix Schulthess 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau 26 26 * 27 27 */ … … 40 40 #include "core/Debug.h" 41 41 #include "core/CoreIncludes.h" 42 #include "core/ConfigValueIncludes.h" 42 43 #include "core/ConsoleCommand.h" 43 44 #include "core/InputManager.h" 45 #include "util/Math.h" 44 46 #include "GraphicsEngine.h" 45 47 46 #define LINES 20 48 #define LINES 30 49 #define CHAR_WIDTH 7.85 // fix this please - determine the char-width dynamically 47 50 48 51 namespace orxonox 49 52 { 53 SetConsoleCommand(InGameConsole, openConsole, true); 54 SetConsoleCommand(InGameConsole, closeConsole, true); 55 50 56 using namespace Ogre; 51 57 52 const float REL_WIDTH = 0.8; 53 const float REL_HEIGHT = 0.4; 54 const float BLINK = 0.25; 55 56 InGameConsole::InGameConsole(InputBuffer* ib) : 57 windowW(0), windowH(0), 58 scroll(0), scrollTimer(0.0f), 59 cursor(0.0f), 60 active(false), 61 ib_(ib), 62 om(0), 63 consoleOverlay(0), 64 consoleOverlayContainer(0), 65 consoleOverlayNoise(0), 66 consoleOverlayBorder(0), 67 consoleOverlayTextAreas(0) 68 { 69 //RegisterObject(InGameConsole); 70 init(); 71 } 72 73 InGameConsole::~InGameConsole(void){ 74 for(int i=0; i<LINES; i++) delete consoleOverlayTextAreas[i]; 75 delete consoleOverlayTextAreas; 76 } 77 78 void InGameConsole::listen(){ 79 if(!active) activate(); 80 print(convert2UTF(this->ib_->get())); 81 } 82 83 void InGameConsole::execute(){ 84 newline(); 85 if (!CommandExecutor::execute(this->ib_->get())){ 86 print("Error"); 87 newline(); 88 } 89 this->ib_->clear(); 90 } 91 92 void InGameConsole::hintandcomplete(){ 93 print(CommandExecutor::hint(this->ib_->get())); 94 newline(); 95 this->ib_->set(CommandExecutor::complete(this->ib_->get())); 96 print(convert2UTF(this->ib_->get())); 97 } 98 99 void InGameConsole::clear(){ 100 this->ib_->clear(); 101 } 102 103 void InGameConsole::removeLast(){ 104 this->ib_->removeLast(); 105 } 106 107 void InGameConsole::exit(){ 108 clear(); 109 deactivate(); 110 InputManager::setInputState(InputManager::IS_NORMAL); 111 } 112 113 /** 114 @brief called once by constructor 115 */ 116 void InGameConsole::init(){ 58 float InGameConsole::REL_WIDTH = 0.8; 59 float InGameConsole::REL_HEIGHT = 0.4; 60 float InGameConsole::BLINK = 0.5; 61 62 /** 63 @brief Constructor: Creates and initializes the InGameConsole. 64 */ 65 InGameConsole::InGameConsole() : 66 om_(0), consoleOverlay_(0), consoleOverlayContainer_(0), 67 consoleOverlayNoise_(0), consoleOverlayBorder_(0), consoleOverlayTextAreas_(0) 68 { 69 RegisterObject(InGameConsole); 70 71 this->active_ = false; 72 this->cursor_ = 0.0; 73 this->cursorSymbol_ = '|'; 74 this->inputWindowStart_ = 0; 75 this->numLinesShifted_ = LINES - 1; 76 77 this->init(); 78 this->setConfigValues(); 79 80 Shell::getInstance().addOutputLevel(true); 81 } 82 83 /** 84 @brief Destructor: Destroys the TextAreas. 85 */ 86 InGameConsole::~InGameConsole(void) 87 { 88 for (int i = 0; i < LINES; i++) 89 if (this->consoleOverlayTextAreas_[i]) 90 delete this->consoleOverlayTextAreas_[i]; 91 92 if (this->consoleOverlayTextAreas_) 93 delete this->consoleOverlayTextAreas_; 94 } 95 96 /** 97 @brief Returns a reference to the only existing instance of InGameConsole. 98 */ 99 InGameConsole& InGameConsole::getInstance() 100 { 101 static InGameConsole instance; 102 return instance; 103 } 104 105 /** 106 @brief Sets the config values, describing the size of the console. 107 */ 108 void InGameConsole::setConfigValues() 109 { 110 SetConfigValue(REL_WIDTH, 0.8); 111 SetConfigValue(REL_HEIGHT, 0.4); 112 SetConfigValue(BLINK, 0.5); 113 } 114 115 /** 116 @brief Called if all output-lines have to be redrawn. 117 */ 118 void InGameConsole::linesChanged() 119 { 120 std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator(); 121 int max = 0; 122 for (int i = 1; i < LINES; ++i) 123 { 124 if (it != Shell::getInstance().getEndIterator()) 125 { 126 ++it; 127 max = i; 128 } 129 else 130 break; 131 } 132 133 for (int i = LINES - 1; i > max; --i) 134 this->print("", i, true); 135 136 for (int i = max; i >= 1; --i) 137 { 138 --it; 139 this->print(*it, i, true); 140 } 141 } 142 143 /** 144 @brief Called if only the last output-line has changed. 145 */ 146 void InGameConsole::onlyLastLineChanged() 147 { 148 if (LINES > 1) 149 this->print(*Shell::getInstance().getNewestLineIterator(), 1); 150 } 151 152 /** 153 @brief Called if a new output-line was added. 154 */ 155 void InGameConsole::lineAdded() 156 { 157 this->numLinesShifted_ = 0; 158 this->shiftLines(); 159 this->onlyLastLineChanged(); 160 } 161 162 /** 163 @brief Called if the text in the input-line has changed. 164 */ 165 void InGameConsole::inputChanged() 166 { 167 if (LINES > 0) 168 this->print(Shell::getInstance().getInput(), 0); 169 170 if (Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0) 171 this->inputWindowStart_ = 0; 172 } 173 174 /** 175 @brief Called if the position of the cursor in the input-line has changed. 176 */ 177 void InGameConsole::cursorChanged() 178 { 179 std::string input = Shell::getInstance().getInput(); 180 input.insert(Shell::getInstance().getCursorPosition(), 1, this->cursorSymbol_); 181 if (LINES > 0) 182 this->print(input, 0); 183 } 184 185 /** 186 @brief Called if the console gets closed. 187 */ 188 void InGameConsole::exit() 189 { 190 this->deactivate(); 191 } 192 193 /** 194 @brief Called once by constructor, initializes the InGameConsole. 195 */ 196 void InGameConsole::init() 197 { 117 198 // for the beginning, don't scroll 118 scroll= 0;119 scrollTimer= 0;120 cursor= 0;199 this->scroll_ = 0; 200 this->scrollTimer_ = 0; 201 this->cursor_ = 0; 121 202 122 203 // create overlay and elements 123 om= &Ogre::OverlayManager::getSingleton();204 this->om_ = &Ogre::OverlayManager::getSingleton(); 124 205 125 206 // create a container 126 consoleOverlayContainer = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", "container"));127 consoleOverlayContainer->setMetricsMode(Ogre::GMM_RELATIVE);128 consoleOverlayContainer->setPosition((1-REL_WIDTH)/2, 0);129 consoleOverlayContainer->setDimensions(REL_WIDTH,REL_HEIGHT);207 this->consoleOverlayContainer_ = static_cast<OverlayContainer*>(this->om_->createOverlayElement("Panel", "InGameConsoleContainer")); 208 this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE); 209 this->consoleOverlayContainer_->setPosition((1 - InGameConsole::REL_WIDTH) / 2, 0); 210 this->consoleOverlayContainer_->setDimensions(InGameConsole::REL_WIDTH, InGameConsole::REL_HEIGHT); 130 211 131 212 // create BorderPanel 132 consoleOverlayBorder = static_cast<BorderPanelOverlayElement*>(om->createOverlayElement("BorderPanel", "borderPanel"));133 consoleOverlayBorder->setMetricsMode(Ogre::GMM_PIXELS);134 consoleOverlayBorder->setMaterialName("ConsoleCenter");213 this->consoleOverlayBorder_ = static_cast<BorderPanelOverlayElement*>(this->om_->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel")); 214 this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS); 215 this->consoleOverlayBorder_->setMaterialName("ConsoleCenter"); 135 216 // set parameters for border 136 consoleOverlayBorder->setBorderSize(16, 16, 0, 16);137 consoleOverlayBorder->setBorderMaterialName("ConsoleBorder");138 consoleOverlayBorder->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);139 consoleOverlayBorder->setRightBorderUV(0.5, 0.49, 1.0, 0.5);140 consoleOverlayBorder->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);141 consoleOverlayBorder->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);142 consoleOverlayBorder->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);217 this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16); 218 this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder"); 219 this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51); 220 this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5); 221 this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0); 222 this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0); 223 this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0); 143 224 144 225 // create the text lines 145 consoleOverlayTextAreas = new TextAreaOverlayElement*[LINES]; 146 for(int i = 0; i<LINES; i++){ 147 consoleOverlayTextAreas[i] = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "textArea"+Ogre::StringConverter::toString(i))); 148 consoleOverlayTextAreas[i]->setMetricsMode(Ogre::GMM_PIXELS); 149 consoleOverlayTextAreas[i]->setFontName("Console"); 150 consoleOverlayTextAreas[i]->setCharHeight(20); 151 consoleOverlayTextAreas[i]->setParameter("colour_top", "0.21 0.69 0.21"); 152 consoleOverlayTextAreas[i]->setLeft(8); 153 consoleOverlayTextAreas[i]->setCaption(""); 226 this->consoleOverlayTextAreas_ = new TextAreaOverlayElement*[LINES]; 227 for (int i = 0; i < LINES; i++) 228 { 229 this->consoleOverlayTextAreas_[i] = static_cast<TextAreaOverlayElement*>(this->om_->createOverlayElement("TextArea", "InGameConsoleTextArea" + Ogre::StringConverter::toString(i))); 230 this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS); 231 this->consoleOverlayTextAreas_[i]->setFontName("Console"); 232 this->consoleOverlayTextAreas_[i]->setCharHeight(18); 233 this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21"); 234 this->consoleOverlayTextAreas_[i]->setLeft(8); 235 this->consoleOverlayTextAreas_[i]->setCaption(""); 154 236 } 155 237 156 238 // create noise 157 consoleOverlayNoise = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "noise")); 158 consoleOverlayNoise->setMetricsMode(Ogre::GMM_PIXELS); 159 consoleOverlayNoise->setPosition(5,0); 160 consoleOverlayNoise->setMaterialName("ConsoleNoise"); 161 162 consoleOverlay = om->create("Console"); 163 consoleOverlay->add2D(consoleOverlayContainer); 164 consoleOverlayContainer->addChild(consoleOverlayBorder); 165 //comment following line to disable noise 166 consoleOverlayContainer->addChild(consoleOverlayNoise); 167 for(int i = 0; i<LINES; i++) consoleOverlayContainer->addChild(consoleOverlayTextAreas[i]); 168 resize(); 239 this->consoleOverlayNoise_ = static_cast<PanelOverlayElement*>(this->om_->createOverlayElement("Panel", "InGameConsoleNoise")); 240 this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS); 241 this->consoleOverlayNoise_->setPosition(5,0); 242 this->consoleOverlayNoise_->setMaterialName("ConsoleNoise"); 243 244 this->consoleOverlay_ = this->om_->create("InGameConsoleConsole"); 245 this->consoleOverlay_->add2D(this->consoleOverlayContainer_); 246 this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_); 247 //comment following line to disable noise 248 this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_); 249 for (int i = 0; i < LINES; i++) 250 this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]); 251 252 this->resize(); 169 253 170 254 // move overlay "above" the top edge of the screen 171 255 // we take -1.2 because the border mkes the panel bigger 172 consoleOverlayContainer->setTop(-1.2*REL_HEIGHT);256 this->consoleOverlayContainer_->setTop(-1.2 * InGameConsole::REL_HEIGHT); 173 257 // show overlay 174 consoleOverlay->show(); 175 176 COUT(3) << "Info: InGameConsole initialized" << std::endl; 177 } 178 179 /** 180 @brief used to control the actual scrolling and cursor 181 */ 182 void InGameConsole::tick(float dt){ 183 scrollTimer += dt; 184 if(scrollTimer >= 0.01){ 185 float top = consoleOverlayContainer->getTop(); 186 scrollTimer = 0; 187 if(scroll!=0){ 258 this->consoleOverlay_->show(); 259 260 COUT(4) << "Info: InGameConsole initialized" << std::endl; 261 } 262 263 /** 264 @brief Resizes the console elements. Call if window size changes. 265 */ 266 void InGameConsole::resize() 267 { 268 this->windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 269 this->windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 270 this->consoleOverlayBorder_->setWidth((int) this->windowW_* InGameConsole::REL_WIDTH); 271 this->consoleOverlayBorder_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT); 272 this->consoleOverlayNoise_->setWidth((int) this->windowW_ * InGameConsole::REL_WIDTH - 10); 273 this->consoleOverlayNoise_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT - 5); 274 275 // now adjust the text lines... 276 this->desiredTextWidth_ = (int) (this->windowW_ * InGameConsole::REL_WIDTH) - 12; 277 278 if (LINES > 0) 279 this->maxCharsPerLine_ = max((unsigned int)10, (unsigned int) ((float)this->desiredTextWidth_ / CHAR_WIDTH)); 280 else 281 this->maxCharsPerLine_ = 10; 282 283 for (int i = 0; i < LINES; i++) 284 { 285 this->consoleOverlayTextAreas_[i]->setWidth(this->desiredTextWidth_); 286 this->consoleOverlayTextAreas_[i]->setTop((int) this->windowH_ * InGameConsole::REL_HEIGHT - 24 - 14*i); 287 } 288 289 this->linesChanged(); 290 } 291 292 /** 293 @brief Used to control the actual scrolling and the cursor. 294 */ 295 void InGameConsole::tick(float dt) 296 { 297 this->scrollTimer_ += dt; 298 if (this->scrollTimer_ >= 0.01) 299 { 300 float top = this->consoleOverlayContainer_->getTop(); 301 this->scrollTimer_ = 0; 302 if (this->scroll_ != 0) 303 { 188 304 // scroll 189 top = top + 0.02 *scroll;190 consoleOverlayContainer->setTop(top);305 top = top + 0.02 * this->scroll_; 306 this->consoleOverlayContainer_->setTop(top); 191 307 } 192 if(top <= -1.2*REL_HEIGHT){ 308 if (top <= -1.2 * InGameConsole::REL_HEIGHT) 309 { 193 310 // window has completely scrolled up 194 scroll = 0; 195 consoleOverlay->hide(); 196 active = false; 311 this->scroll_ = 0; 312 this->consoleOverlay_->hide(); 313 this->active_ = false; 314 Shell::getInstance().unregisterListener(this); 197 315 } 198 if(top >= 0){ 316 if (top >= 0) 317 { 199 318 // window has completely scrolled down 200 scroll= 0;201 consoleOverlayContainer->setTop(0);202 active= true;319 this->scroll_ = 0; 320 this->consoleOverlayContainer_->setTop(0); 321 this->active_ = true; 203 322 } 204 323 } 205 324 206 cursor += dt; 207 if(cursor >= 2*BLINK) cursor = 0; 208 print(convert2UTF(this->ib_->get())); 209 210 // this creates a flickering effect 211 consoleOverlayNoise->setTiling(1, rand()%5+1); 212 } 213 214 /** 215 @brief resizes the console elements. call if window size changes 216 */ 217 void InGameConsole::resize(){ 218 windowW = GraphicsEngine::getSingleton().getWindowWidth(); 219 windowH = GraphicsEngine::getSingleton().getWindowHeight(); 220 consoleOverlayBorder->setWidth((int) windowW*REL_WIDTH); 221 consoleOverlayBorder->setHeight((int) windowH*REL_HEIGHT); 222 consoleOverlayNoise->setWidth((int) windowW*REL_WIDTH - 10); 223 consoleOverlayNoise->setHeight((int) windowH*REL_HEIGHT - 5); 224 // now adjust the text lines... 225 for(int i = 0; i<LINES; i++){ 226 consoleOverlayTextAreas[i]->setWidth(windowW*REL_WIDTH); 227 consoleOverlayTextAreas[i]->setTop((int)windowH*REL_HEIGHT - 24 - 16*i); 228 } 229 } 230 231 /** 232 @brief shows console 233 */ 234 void InGameConsole::activate(){ 235 consoleOverlay->show(); 325 this->cursor_ += dt; 326 if (this->cursor_ >= 2 * InGameConsole::BLINK) 327 this->cursor_ = 0; 328 329 if (this->cursor_ >= InGameConsole::BLINK && this->cursorSymbol_ == '|') 330 { 331 this->cursorSymbol_ = ' '; 332 this->cursorChanged(); 333 } 334 else if (this->cursor_ < InGameConsole::BLINK && this->cursorSymbol_ == ' ') 335 { 336 this->cursorSymbol_ = '|'; 337 this->cursorChanged(); 338 } 339 340 // this creates a flickering effect 341 this->consoleOverlayNoise_->setTiling(1, rand() % 5 + 1); 342 } 343 344 /** 345 @brief Shows the InGameConsole. 346 */ 347 void InGameConsole::activate() 348 { 349 InputManager::setInputState(InputManager::IS_CONSOLE); 350 Shell::getInstance().registerListener(this); 351 this->linesChanged(); 352 353 this->consoleOverlay_->show(); 236 354 // just in case window size has changed... 237 resize();355 this->resize(); 238 356 // scroll down 239 scroll= 1;357 this->scroll_ = 1; 240 358 // the rest is done by tick 241 359 } 242 360 243 361 /** 244 @brief hides console 245 */ 246 void InGameConsole::deactivate(){ 362 @brief Hides the InGameConsole. 363 */ 364 void InGameConsole::deactivate() 365 { 247 366 // scroll up 248 scroll= -1;367 this->scroll_ = -1; 249 368 // the rest is done by tick 250 } 251 252 /** 253 @brief prints string to bottom line 254 @param s string to be printed 255 */ 256 void InGameConsole::print(Ogre::UTFString s){ 257 if(cursor>BLINK) consoleOverlayTextAreas[0]->setCaption(">" + s); 258 else consoleOverlayTextAreas[0]->setCaption(">" + s + "_"); 259 } 260 261 /** 262 @brief shifts all lines up and clears the bottom line 263 */ 264 void InGameConsole::newline(){ 265 Ogre::UTFString line; 266 for(int i = LINES-1; i>=1; i--){ 267 line = consoleOverlayTextAreas[i-1]->getCaption(); 268 // don't copy the cursor... 269 int l = line.length(); 270 if(!line.empty() && line.substr(l-1) == "_") line.erase(l-1); 271 consoleOverlayTextAreas[i]->setCaption(line); 272 } 273 consoleOverlayTextAreas[0]->setCaption(">"); 274 } 275 276 Ogre::UTFString InGameConsole::convert2UTF(std::string s){ 369 InputManager::setInputState(InputManager::IS_NORMAL); 370 } 371 372 /** 373 @brief Activates the console. 374 */ 375 void InGameConsole::openConsole() 376 { 377 InGameConsole::getInstance().activate(); 378 } 379 380 /** 381 @brief Deactivates the console. 382 */ 383 void InGameConsole::closeConsole() 384 { 385 InGameConsole::getInstance().deactivate(); 386 } 387 388 /** 389 @brief Shifts all output lines one line up 390 */ 391 void InGameConsole::shiftLines() 392 { 393 for (unsigned int i = LINES - 1; i > 1; --i) 394 { 395 this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption()); 396 this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop()); 397 this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom()); 398 } 399 } 400 401 void InGameConsole::colourLine(int colourcode, int index) 402 { 403 if (colourcode == -1) 404 { 405 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.90, 0.90, 0.90, 1.00)); 406 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00)); 407 } 408 else if (colourcode == 1) 409 { 410 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.25, 0.25, 1.00)); 411 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00)); 412 } 413 else if (colourcode == 2) 414 { 415 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.50, 0.20, 1.00)); 416 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00)); 417 } 418 else if (colourcode == 3) 419 { 420 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.50, 0.50, 0.95, 1.00)); 421 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00)); 422 } 423 else if (colourcode == 4) 424 { 425 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.65, 0.48, 0.44, 1.00)); 426 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00)); 427 } 428 else if (colourcode == 5) 429 { 430 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.40, 0.20, 0.40, 1.00)); 431 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00)); 432 } 433 else 434 { 435 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.21, 0.69, 0.21, 1.00)); 436 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00)); 437 } 438 } 439 440 /** 441 @brief Prints string to bottom line. 442 @param s String to be printed 443 */ 444 void InGameConsole::print(const std::string& text, int index, bool alwaysShift) 445 { 446 char level = 0; 447 if (text.size() > 0) 448 level = text[0]; 449 450 std::string output = text; 451 452 if (level >= -1 && level <= 5) 453 output.erase(0, 1); 454 455 if (LINES > index) 456 { 457 this->colourLine(level, index); 458 459 if (index > 0) 460 { 461 unsigned int linesUsed = 1; 462 while (output.size() > this->maxCharsPerLine_) 463 { 464 ++linesUsed; 465 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output.substr(0, this->maxCharsPerLine_))); 466 output.erase(0, this->maxCharsPerLine_); 467 output.insert(0, 1, ' '); 468 if (linesUsed > numLinesShifted_ || alwaysShift) 469 this->shiftLines(); 470 this->colourLine(level, index); 471 } 472 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output)); 473 this->numLinesShifted_ = linesUsed; 474 } 475 else 476 { 477 if (output.size() > this->maxCharsPerLine_) 478 { 479 if (Shell::getInstance().getInputBuffer().getCursorPosition() < this->inputWindowStart_) 480 this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition(); 481 else if (Shell::getInstance().getInputBuffer().getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1)) 482 this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition() - this->maxCharsPerLine_ + 1; 483 484 output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_); 485 } 486 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output)); 487 } 488 } 489 } 490 491 /** 492 @brief Converts a string into an Ogre::UTFString. 493 @param s The string to convert 494 @return The converted string 495 */ 496 Ogre::UTFString InGameConsole::convert2UTF(std::string s) 497 { 277 498 Ogre::UTFString utf; 278 int i;279 499 Ogre::UTFString::code_point cp; 280 for (i=0; i<(int)s.size(); ++i){ 500 for (unsigned int i = 0; i < s.size(); ++i) 501 { 281 502 cp = s[i]; 282 503 cp &= 0xFF; -
code/branches/network/src/orxonox/console/InGameConsole.h
r1214 r1446 37 37 38 38 #include "core/Tickable.h" 39 #include "core/ InputBuffer.h"39 #include "core/Shell.h" 40 40 41 41 42 42 namespace orxonox 43 43 { 44 class _OrxonoxExport InGameConsole : public InputBufferListener44 class _OrxonoxExport InGameConsole : public Tickable, public ShellListener 45 45 { 46 46 public: 47 InGameConsole(InputBuffer* ib); 48 ~InGameConsole(); 49 void listen(); 50 void execute(); 51 void hintandcomplete(); 52 void clear(); 53 void removeLast(); 54 void exit(); 55 void init(); 47 static InGameConsole& getInstance(); 48 49 void setConfigValues(); 56 50 void tick(float dt); 51 57 52 void activate(); 58 53 void deactivate(); 54 void resize(); 55 56 static void openConsole(); 57 static void closeConsole(); 59 58 60 59 private: 61 void resize(); 62 void print(Ogre::UTFString s); 63 void newline(); 64 Ogre::UTFString convert2UTF(std::string s); 60 InGameConsole(); 61 InGameConsole(const InGameConsole& other); 62 ~InGameConsole(); 65 63 66 int windowW; 67 int windowH; 68 int scroll; 69 float scrollTimer; 70 float cursor; 71 bool active; 72 InputBuffer* ib_; 73 Ogre::OverlayManager* om; 74 Ogre::Overlay* consoleOverlay; 75 Ogre::OverlayContainer* consoleOverlayContainer; 76 Ogre::PanelOverlayElement* consoleOverlayNoise; 77 Ogre::BorderPanelOverlayElement* consoleOverlayBorder; 78 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas; 64 virtual void linesChanged(); 65 virtual void onlyLastLineChanged(); 66 virtual void lineAdded(); 67 virtual void inputChanged(); 68 virtual void cursorChanged(); 69 virtual void exit(); 70 71 void init(); 72 void shiftLines(); 73 void colourLine(int colourcode, int index); 74 void print(const std::string& text, int index, bool alwaysShift = false); 75 static Ogre::UTFString convert2UTF(std::string s); 76 77 static float REL_WIDTH; 78 static float REL_HEIGHT; 79 static float BLINK; 80 81 int windowW_; 82 int windowH_; 83 int desiredTextWidth_; 84 unsigned int maxCharsPerLine_; 85 unsigned int numLinesShifted_; 86 int scroll_; 87 float scrollTimer_; 88 float cursor_; 89 unsigned int inputWindowStart_; 90 char cursorSymbol_; 91 bool active_; 92 Ogre::OverlayManager* om_; 93 Ogre::Overlay* consoleOverlay_; 94 Ogre::OverlayContainer* consoleOverlayContainer_; 95 Ogre::PanelOverlayElement* consoleOverlayNoise_; 96 Ogre::BorderPanelOverlayElement* consoleOverlayBorder_; 97 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_; 79 98 }; 80 99 } -
code/branches/network/src/orxonox/hud/HUD.cc
r1422 r1446 47 47 namespace orxonox 48 48 { 49 ConsoleCommandShortcut(HUD, cycleNavigationFocus,AccessLevel::User);49 SetConsoleCommandShortcut(HUD, cycleNavigationFocus).setAccessLevel(AccessLevel::User); 50 50 51 51 using namespace Ogre; -
code/branches/network/src/orxonox/objects/Ambient.cc
r1418 r1446 47 47 namespace orxonox 48 48 { 49 ConsoleCommand(Ambient, setAmbientLightTest, AccessLevel::Offline, false).setDefaultValues(ColourValue(1, 1, 1, 1));49 SetConsoleCommand(Ambient, setAmbientLightTest, false).setDefaultValues(ColourValue(1, 1, 1, 1)).setAccessLevel(AccessLevel::Offline); 50 50 51 51 CreateFactory(Ambient); -
code/branches/network/src/orxonox/objects/SpaceShip.cc
r1443 r1446 51 51 namespace orxonox 52 52 { 53 ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false);54 ConsoleCommand(SpaceShip, whereAmI, AccessLevel::User, true);55 ConsoleCommand(SpaceShip, moveLongitudinal, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);56 ConsoleCommand(SpaceShip, moveLateral, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);57 ConsoleCommand(SpaceShip, moveYaw, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);58 ConsoleCommand(SpaceShip, movePitch, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);59 ConsoleCommand(SpaceShip, moveRoll, AccessLevel::User, true).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);60 ConsoleCommand(SpaceShip, fire, AccessLevel::User, true).setKeybindMode(KeybindMode::OnHold);61 ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false);62 ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false);63 ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false);53 SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug); 54 SetConsoleCommand(SpaceShip, whereAmI, true).setAccessLevel(AccessLevel::User); 55 SetConsoleCommand(SpaceShip, moveLongitudinal, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 56 SetConsoleCommand(SpaceShip, moveLateral, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 57 SetConsoleCommand(SpaceShip, moveYaw, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 58 SetConsoleCommand(SpaceShip, movePitch, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 59 SetConsoleCommand(SpaceShip, moveRoll, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 60 SetConsoleCommand(SpaceShip, fire, true).setAccessLevel(AccessLevel::User).setKeybindMode(KeybindMode::OnHold); 61 SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug); 62 SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug); 63 SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug); 64 64 65 65 CreateFactory(SpaceShip); -
code/branches/network/src/orxonox/tools/Timer.cc
r1293 r1446 27 27 */ 28 28 29 #include <set> 30 29 31 #include "OrxonoxStableHeaders.h" 30 32 #include "Timer.h" … … 37 39 namespace orxonox 38 40 { 39 ConsoleCommandShortcutExtern(delay, AccessLevel::None); 41 SetConsoleCommandShortcutExtern(delay); 42 SetConsoleCommandShortcutExtern(killdelays); 43 44 static std::set<StaticTimer*> delaytimerset; 40 45 41 46 /** … … 47 52 { 48 53 StaticTimer *delaytimer = new StaticTimer(); 54 delaytimerset.insert(delaytimer); 55 49 56 ExecutorStatic* delayexecutor = createExecutor(createFunctor(&executeDelayedCommand)); 50 57 delayexecutor->setDefaultValues(delaytimer, command); … … 61 68 CommandExecutor::execute(command); 62 69 delete timer; 70 delaytimerset.erase(timer); 71 } 72 73 /** 74 @brief Kills all delayed commands. 75 */ 76 void killdelays() 77 { 78 for (std::set<StaticTimer*>::iterator it = delaytimerset.begin(); it != delaytimerset.end(); ++it) 79 delete (*it); 80 81 delaytimerset.clear(); 63 82 } 64 83 -
code/branches/network/src/orxonox/tools/Timer.h
r1056 r1446 69 69 class StaticTimer; 70 70 void delay(float delay, const std::string& command); 71 void killdelays(); 71 72 void executeDelayedCommand(StaticTimer* timer, const std::string& command); 72 73 -
code/branches/network/src/util/Convert.h
r1064 r1446 384 384 else if (input.getType() == MT_vector3) 385 385 return ConvertValue(output, input.getVector3()); 386 else if (input.getType() == MT_vector4) 387 return ConvertValue(output, input.getVector4()); 386 388 else if (input.getType() == MT_quaternion) 387 389 return ConvertValue(output, input.getQuaternion()); -
code/branches/network/src/util/Math.h
r1349 r1446 121 121 122 122 template <typename T> 123 inline int mod(T x, int max) 124 { 125 if (x >= 0) 126 return (x % max); 127 else 128 return ((x % max) + max); 129 } 130 131 template <typename T> 123 132 T interpolate(float time, const T& start, const T& end) 124 133 { -
code/branches/network/src/util/MultiType.h
r1056 r1446 54 54 MT_vector2, 55 55 MT_vector3, 56 MT_vector4, 56 57 MT_colourvalue, 57 58 MT_quaternion, -
code/branches/network/src/util/MultiTypeMath.cc
r1056 r1446 37 37 else if (type == MT_vector3) 38 38 this->vector3_ = orxonox::Vector3(0, 0, 0); 39 else if (type == MT_vector4) 40 this->vector4_ = orxonox::Vector4(0, 0, 0, 0); 39 41 else if (type == MT_colourvalue) 40 42 this->colourvalue_ = orxonox::ColourValue(0, 0, 0, 0); … … 55 57 else if (this->type_ == MT_vector3) 56 58 return (this->vector3_ == mtm.vector3_); 59 else if (this->type_ == MT_vector4) 60 return (this->vector4_ == mtm.vector4_); 57 61 else if (this->type_ == MT_colourvalue) 58 62 return (this->colourvalue_ == mtm.colourvalue_); … … 68 72 } 69 73 74 bool MultiTypeMath::operator==(const MultiTypeString& mts) const 75 { 76 return MultiTypeString::operator==(mts); 77 } 78 79 bool MultiTypeMath::operator==(const MultiTypePrimitive& mtp) const 80 { 81 return MultiTypePrimitive::operator==(mtp); 82 } 83 70 84 bool MultiTypeMath::operator!=(const MultiTypeMath& mtm) const 71 85 { … … 76 90 else if (this->type_ == MT_vector3) 77 91 return (this->vector3_ != mtm.vector3_); 92 else if (this->type_ == MT_vector4) 93 return (this->vector4_ != mtm.vector4_); 78 94 else if (this->type_ == MT_colourvalue) 79 95 return (this->colourvalue_ != mtm.colourvalue_); … … 87 103 88 104 return true; 105 } 106 107 bool MultiTypeMath::operator!=(const MultiTypeString& mts) const 108 { 109 return MultiTypeString::operator!=(mts); 110 } 111 112 bool MultiTypeMath::operator!=(const MultiTypePrimitive& mtp) const 113 { 114 return MultiTypePrimitive::operator!=(mtp); 89 115 } 90 116 … … 123 149 MultiTypeMath::operator orxonox::Vector3() const 124 150 { return (this->type_ == MT_vector3) ? this->vector3_ : getConvertedValue<MultiTypeMath, orxonox::Vector3>(*this); } 151 MultiTypeMath::operator orxonox::Vector4() const 152 { return (this->type_ == MT_vector4) ? this->vector4_ : getConvertedValue<MultiTypeMath, orxonox::Vector4>(*this); } 125 153 MultiTypeMath::operator orxonox::Quaternion() const 126 154 { return (this->type_ == MT_quaternion) ? this->quaternion_ : getConvertedValue<MultiTypeMath, orxonox::Quaternion>(*this); } … … 137 165 this->vector2_ = mtm.vector2_; 138 166 this->vector3_ = mtm.vector3_; 167 this->vector4_ = mtm.vector4_; 139 168 this->quaternion_ = mtm.quaternion_; 140 169 this->colourvalue_ = mtm.colourvalue_; … … 143 172 } 144 173 174 void MultiTypeMath::setValue(const MultiTypeString& mts) 175 { 176 MultiTypeString::setValue(mts); 177 } 178 179 void MultiTypeMath::setValue(const MultiTypePrimitive& mtp) 180 { 181 MultiTypePrimitive::setValue(mtp); 182 } 183 145 184 std::string MultiTypeMath::getTypename() const 146 185 { … … 149 188 else if (this->type_ == MT_vector3) 150 189 return "Vector3"; 190 else if (this->type_ == MT_vector4) 191 return "Vector4"; 151 192 else if (this->type_ == MT_colourvalue) 152 193 return "ColourValue"; … … 169 210 else if (this->type_ == MT_vector3) 170 211 ConvertValue(&output, this->vector3_); 212 else if (this->type_ == MT_vector4) 213 ConvertValue(&output, this->vector4_); 171 214 else if (this->type_ == MT_colourvalue) 172 215 ConvertValue(&output, this->colourvalue_); … … 189 232 else if (this->type_ == MT_vector3) 190 233 return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0)); 234 else if (this->type_ == MT_vector4) 235 return ConvertValue(&this->vector4_, value, orxonox::Vector4(0, 0, 0, 0)); 191 236 else if (this->type_ == MT_colourvalue) 192 237 return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0)); … … 201 246 } 202 247 248 bool MultiTypeMath::assimilate(const MultiTypeMath& mtm, const MultiTypeMath& defvalue) 249 { 250 if (this->type_ == MT_void) 251 return ConvertValue(&this->value_.void_, mtm, defvalue.value_.void_); 252 else if (this->type_ == MT_int) 253 return ConvertValue(&this->value_.int_, mtm, defvalue.value_.int_); 254 else if (this->type_ == MT_uint) 255 return ConvertValue(&this->value_.uint_, mtm, defvalue.value_.uint_); 256 else if (this->type_ == MT_char) 257 return ConvertValue(&this->value_.char_, mtm, defvalue.value_.char_); 258 else if (this->type_ == MT_uchar) 259 return ConvertValue(&this->value_.uchar_, mtm, defvalue.value_.uchar_); 260 else if (this->type_ == MT_short) 261 return ConvertValue(&this->value_.short_, mtm, defvalue.value_.short_); 262 else if (this->type_ == MT_ushort) 263 return ConvertValue(&this->value_.ushort_, mtm, defvalue.value_.ushort_); 264 else if (this->type_ == MT_long) 265 return ConvertValue(&this->value_.long_, mtm, defvalue.value_.long_); 266 else if (this->type_ == MT_ulong) 267 return ConvertValue(&this->value_.ulong_, mtm, defvalue.value_.ulong_); 268 else if (this->type_ == MT_float) 269 return ConvertValue(&this->value_.float_, mtm, defvalue.value_.float_); 270 else if (this->type_ == MT_double) 271 return ConvertValue(&this->value_.double_, mtm, defvalue.value_.double_); 272 else if (this->type_ == MT_longdouble) 273 return ConvertValue(&this->value_.longdouble_, mtm, defvalue.value_.longdouble_); 274 else if (this->type_ == MT_bool) 275 return ConvertValue(&this->value_.bool_, mtm, defvalue.value_.bool_); 276 else if (this->type_ == MT_constchar) 277 return ConvertValue(&this->string_, mtm, defvalue.string_); 278 else if (this->type_ == MT_string) 279 return ConvertValue(&this->string_, mtm, defvalue.string_); 280 else if (this->type_ == MT_vector2) 281 return ConvertValue(&this->vector2_, mtm, defvalue.vector2_); 282 else if (this->type_ == MT_vector3) 283 return ConvertValue(&this->vector3_, mtm, defvalue.vector3_); 284 else if (this->type_ == MT_vector4) 285 return ConvertValue(&this->vector4_, mtm, defvalue.vector4_); 286 else if (this->type_ == MT_colourvalue) 287 return ConvertValue(&this->colourvalue_, mtm, defvalue.colourvalue_); 288 else if (this->type_ == MT_quaternion) 289 return ConvertValue(&this->quaternion_, mtm, defvalue.quaternion_); 290 else if (this->type_ == MT_radian) 291 return ConvertValue(&this->radian_, mtm, defvalue.radian_); 292 else if (this->type_ == MT_degree) 293 return ConvertValue(&this->degree_, mtm, defvalue.degree_); 294 else 295 return false; 296 } 297 203 298 std::ostream& operator<<(std::ostream& out, MultiTypeMath& mtm) 204 299 { -
code/branches/network/src/util/MultiTypeMath.h
r1064 r1446 63 63 inline MultiTypeMath(const orxonox::Vector2& value) { this->setValue(value); } 64 64 inline MultiTypeMath(const orxonox::Vector3& value) { this->setValue(value); } 65 inline MultiTypeMath(const orxonox::Vector4& value) { this->setValue(value); } 65 66 inline MultiTypeMath(const orxonox::ColourValue& value) { this->setValue(value); } 66 67 inline MultiTypeMath(const orxonox::Quaternion& value) { this->setValue(value); } … … 68 69 inline MultiTypeMath(const orxonox::Degree& value) { this->setValue(value); } 69 70 inline MultiTypeMath(const MultiTypeMath& mtm) { this->setValue(mtm); } 71 inline MultiTypeMath(const MultiTypeString& mts) { this->setValue(mts); } 72 inline MultiTypeMath(const MultiTypePrimitive& mtp) { this->setValue(mtp); } 70 73 virtual inline ~MultiTypeMath() {} 71 74 … … 73 76 inline MultiTypeMath& operator=(const orxonox::Vector2& value) { this->setValue(value); return *this; } 74 77 inline MultiTypeMath& operator=(const orxonox::Vector3& value) { this->setValue(value); return *this; } 78 inline MultiTypeMath& operator=(const orxonox::Vector4& value) { this->setValue(value); return *this; } 75 79 inline MultiTypeMath& operator=(const orxonox::ColourValue& value) { this->setValue(value); return *this; } 76 80 inline MultiTypeMath& operator=(const orxonox::Quaternion& value) { this->setValue(value); return *this; } … … 78 82 inline MultiTypeMath& operator=(const orxonox::Degree& value) { this->setValue(value); return *this; } 79 83 inline MultiTypeMath& operator=(const MultiTypeMath& mtm) { this->setValue(mtm); return *this; } 84 inline MultiTypeMath& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } 85 inline MultiTypeMath& operator=(const MultiTypePrimitive mtp) { this->setValue(mtp); return *this; } 80 86 81 87 using MultiTypeString::operator==; 82 88 inline bool operator==(const orxonox::Vector2& value) const { return (this->vector2_ == value); } 83 89 inline bool operator==(const orxonox::Vector3& value) const { return (this->vector3_ == value); } 90 inline bool operator==(const orxonox::Vector4& value) const { return (this->vector4_ == value); } 84 91 inline bool operator==(const orxonox::ColourValue& value) const { return (this->colourvalue_ == value); } 85 92 inline bool operator==(const orxonox::Quaternion& value) const { return (this->quaternion_ == value); } … … 87 94 inline bool operator==(const orxonox::Degree& value) const { return (this->degree_ == value); } 88 95 bool operator==(const MultiTypeMath& mtm) const; 96 bool operator==(const MultiTypeString& mts) const; 97 bool operator==(const MultiTypePrimitive& mtp) const; 89 98 90 99 using MultiTypeString::operator!=; 91 100 inline bool operator!=(const orxonox::Vector2& value) const { return (this->vector2_ != value); } 92 101 inline bool operator!=(const orxonox::Vector3& value) const { return (this->vector3_ != value); } 102 inline bool operator!=(const orxonox::Vector4& value) const { return (this->vector4_ != value); } 93 103 inline bool operator!=(const orxonox::ColourValue& value) const { return (this->colourvalue_ != value); } 94 104 inline bool operator!=(const orxonox::Quaternion& value) const { return (this->quaternion_ != value); } … … 96 106 inline bool operator!=(const orxonox::Degree& value) const { return (this->degree_ != value); } 97 107 bool operator!=(const MultiTypeMath& mtm) const; 108 bool operator!=(const MultiTypeString& mts) const; 109 bool operator!=(const MultiTypePrimitive& mtp) const; 98 110 99 111 virtual operator void*() const; … … 114 126 virtual operator orxonox::Vector2() const; 115 127 virtual operator orxonox::Vector3() const; 128 virtual operator orxonox::Vector4() const; 116 129 virtual operator orxonox::ColourValue() const; 117 130 virtual operator orxonox::Quaternion() const; … … 122 135 inline void setValue(const orxonox::Vector2& value) { this->type_ = MT_vector2; this->vector2_ = value; } 123 136 inline void setValue(const orxonox::Vector3& value) { this->type_ = MT_vector3; this->vector3_ = value; } 137 inline void setValue(const orxonox::Vector4& value) { this->type_ = MT_vector4; this->vector4_ = value; } 124 138 inline void setValue(const orxonox::ColourValue& value) { this->type_ = MT_colourvalue; this->colourvalue_ = value; } 125 139 inline void setValue(const orxonox::Quaternion& value) { this->type_ = MT_quaternion; this->quaternion_ = value; } … … 127 141 inline void setValue(const orxonox::Degree& value) { this->type_ = MT_degree; this->degree_ = value; } 128 142 void setValue(const MultiTypeMath& mtm); 143 void setValue(const MultiTypeString& mts); 144 void setValue(const MultiTypePrimitive& mtp); 129 145 130 146 inline orxonox::Vector2 getVector2() const { return this->vector2_; } 131 147 inline orxonox::Vector3 getVector3() const { return this->vector3_; } 148 inline orxonox::Vector4 getVector4() const { return this->vector4_; } 132 149 inline orxonox::ColourValue getColourValue() const { return this->colourvalue_; } 133 150 inline orxonox::Quaternion getQuaternion() const { return this->quaternion_; } … … 137 154 inline orxonox::Vector2& getVector2() { return this->vector2_; } 138 155 inline orxonox::Vector3& getVector3() { return this->vector3_; } 156 inline orxonox::Vector4& getVector4() { return this->vector4_; } 139 157 inline orxonox::ColourValue& getColourValue() { return this->colourvalue_; } 140 158 inline orxonox::Quaternion& getQuaternion() { return this->quaternion_; } … … 145 163 inline void getValue(orxonox::Vector2* variable) const { (*variable) = orxonox::Vector2 (this->vector2_); } 146 164 inline void getValue(orxonox::Vector3* variable) const { (*variable) = orxonox::Vector3 (this->vector3_); } 165 inline void getValue(orxonox::Vector4* variable) const { (*variable) = orxonox::Vector4 (this->vector4_); } 147 166 inline void getValue(orxonox::ColourValue* variable) const { (*variable) = orxonox::ColourValue (this->colourvalue_); } 148 167 inline void getValue(orxonox::Quaternion* variable) const { (*variable) = orxonox::Quaternion (this->quaternion_); } … … 155 174 virtual bool fromString(const std::string value); 156 175 176 virtual bool assimilate(const MultiTypeMath& mtm, const MultiTypeMath& defvalue = MultiTypeMath()); 177 157 178 protected: 158 179 orxonox::Vector2 vector2_; 159 180 orxonox::Vector3 vector3_; 181 orxonox::Vector4 vector4_; 160 182 orxonox::ColourValue colourvalue_; 161 183 orxonox::Quaternion quaternion_; -
code/branches/network/src/util/MultiTypePrimitive.cc
r1056 r1446 266 266 } 267 267 268 bool MultiTypePrimitive::assimilate(const MultiTypePrimitive& mtp, const MultiTypePrimitive& defvalue) 269 { 270 if (this->type_ == MT_void) 271 return ConvertValue(&this->value_.void_, mtp, defvalue.value_.void_); 272 else if (this->type_ == MT_int) 273 return ConvertValue(&this->value_.int_, mtp, defvalue.value_.int_); 274 else if (this->type_ == MT_uint) 275 return ConvertValue(&this->value_.uint_, mtp, defvalue.value_.uint_); 276 else if (this->type_ == MT_char) 277 return ConvertValue(&this->value_.char_, mtp, defvalue.value_.char_); 278 else if (this->type_ == MT_uchar) 279 return ConvertValue(&this->value_.uchar_, mtp, defvalue.value_.uchar_); 280 else if (this->type_ == MT_short) 281 return ConvertValue(&this->value_.short_, mtp, defvalue.value_.short_); 282 else if (this->type_ == MT_ushort) 283 return ConvertValue(&this->value_.ushort_, mtp, defvalue.value_.ushort_); 284 else if (this->type_ == MT_long) 285 return ConvertValue(&this->value_.long_, mtp, defvalue.value_.long_); 286 else if (this->type_ == MT_ulong) 287 return ConvertValue(&this->value_.ulong_, mtp, defvalue.value_.ulong_); 288 else if (this->type_ == MT_float) 289 return ConvertValue(&this->value_.float_, mtp, defvalue.value_.float_); 290 else if (this->type_ == MT_double) 291 return ConvertValue(&this->value_.double_, mtp, defvalue.value_.double_); 292 else if (this->type_ == MT_longdouble) 293 return ConvertValue(&this->value_.longdouble_, mtp, defvalue.value_.longdouble_); 294 else if (this->type_ == MT_bool) 295 return ConvertValue(&this->value_.bool_, mtp, defvalue.value_.bool_); 296 else 297 return false; 298 299 } 300 268 301 std::ostream& operator<<(std::ostream& out, const MultiTypePrimitive& mtp) 269 302 { -
code/branches/network/src/util/MultiTypePrimitive.h
r1062 r1446 138 138 void setValue(const MultiTypePrimitive& mtp); 139 139 140 inline void* getVoid() const { return this->value_.void_; 140 inline void* getVoid() const { return this->value_.void_; } 141 141 inline int getInt() const { return this->value_.int_; } 142 142 inline unsigned int getUnsignedInt() const { return this->value_.uint_; } … … 187 187 virtual bool fromString(const std::string value); 188 188 189 virtual bool assimilate(const MultiTypePrimitive& mtp, const MultiTypePrimitive& defvalue = MultiTypePrimitive()); 190 189 191 protected: 190 192 MultiTypeValue value_; -
code/branches/network/src/util/MultiTypeString.cc
r1064 r1446 33 33 MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type) 34 34 { 35 // Nothing to do for string and xml-element35 // Nothing to do for string 36 36 } 37 37 … … 49 49 } 50 50 51 bool MultiTypeString::operator==(const MultiTypePrimitive& mtp) const 52 { 53 return MultiTypePrimitive::operator==(mtp); 54 } 55 51 56 bool MultiTypeString::operator!=(const MultiTypeString& mts) const 52 57 { … … 60 65 61 66 return true; 67 } 68 69 bool MultiTypeString::operator!=(const MultiTypePrimitive& mtp) const 70 { 71 return MultiTypePrimitive::operator!=(mtp); 62 72 } 63 73 … … 99 109 } 100 110 111 void MultiTypeString::setValue(const MultiTypePrimitive& mtp) 112 { 113 MultiTypePrimitive::setValue(mtp); 114 } 115 101 116 std::string MultiTypeString::getTypename() const 102 117 { … … 136 151 } 137 152 153 bool MultiTypeString::assimilate(const MultiTypeString& mts, const MultiTypeString& defvalue) 154 { 155 if (this->type_ == MT_void) 156 return ConvertValue(&this->value_.void_, mts, defvalue.value_.void_); 157 else if (this->type_ == MT_int) 158 return ConvertValue(&this->value_.int_, mts, defvalue.value_.int_); 159 else if (this->type_ == MT_uint) 160 return ConvertValue(&this->value_.uint_, mts, defvalue.value_.uint_); 161 else if (this->type_ == MT_char) 162 return ConvertValue(&this->value_.char_, mts, defvalue.value_.char_); 163 else if (this->type_ == MT_uchar) 164 return ConvertValue(&this->value_.uchar_, mts, defvalue.value_.uchar_); 165 else if (this->type_ == MT_short) 166 return ConvertValue(&this->value_.short_, mts, defvalue.value_.short_); 167 else if (this->type_ == MT_ushort) 168 return ConvertValue(&this->value_.ushort_, mts, defvalue.value_.ushort_); 169 else if (this->type_ == MT_long) 170 return ConvertValue(&this->value_.long_, mts, defvalue.value_.long_); 171 else if (this->type_ == MT_ulong) 172 return ConvertValue(&this->value_.ulong_, mts, defvalue.value_.ulong_); 173 else if (this->type_ == MT_float) 174 return ConvertValue(&this->value_.float_, mts, defvalue.value_.float_); 175 else if (this->type_ == MT_double) 176 return ConvertValue(&this->value_.double_, mts, defvalue.value_.double_); 177 else if (this->type_ == MT_longdouble) 178 return ConvertValue(&this->value_.longdouble_, mts, defvalue.value_.longdouble_); 179 else if (this->type_ == MT_bool) 180 return ConvertValue(&this->value_.bool_, mts, defvalue.value_.bool_); 181 else if (this->type_ == MT_constchar) 182 return ConvertValue(&this->string_, mts, defvalue.string_); 183 else if (this->type_ == MT_string) 184 return ConvertValue(&this->string_, mts, defvalue.string_); 185 else 186 return false; 187 } 188 138 189 std::ostream& operator<<(std::ostream& out, MultiTypeString& mts) 139 190 { -
code/branches/network/src/util/MultiTypeString.h
r1064 r1446 61 61 inline MultiTypeString(long double value) : MultiTypePrimitive(value) {} 62 62 inline MultiTypeString(bool value) : MultiTypePrimitive(value) {} 63 inline MultiTypeString(const char* value) { this->setValue(value); } 64 inline MultiTypeString(const std::string& value) { this->setValue(value); } 65 inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts); } 63 inline MultiTypeString(const char* value) { this->setValue(value); } 64 inline MultiTypeString(const std::string& value) { this->setValue(value); } 65 inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts); } 66 inline MultiTypeString(const MultiTypePrimitive& mtp) { this->setValue(mtp); } 66 67 virtual inline ~MultiTypeString() {} 67 68 68 69 using MultiTypePrimitive::operator=; 69 inline MultiTypeString& operator=(const char* value) { this->setValue(value); return *this; } 70 inline MultiTypeString& operator=(const std::string& value) { this->setValue(value); return *this; } 71 inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } 70 inline MultiTypeString& operator=(const char* value) { this->setValue(value); return *this; } 71 inline MultiTypeString& operator=(const std::string& value) { this->setValue(value); return *this; } 72 inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } 73 inline MultiTypeString& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp); return *this; } 72 74 73 75 using MultiTypePrimitive::operator==; 74 inline bool operator==(const char* value) const { return (this->string_ == std::string(value)); } 75 inline bool operator==(const std::string& value) const { return (this->string_ == value); } 76 bool operator==(const MultiTypeString& mts) const; 76 inline bool operator==(const char* value) const { return (this->string_ == std::string(value)); } 77 inline bool operator==(const std::string& value) const { return (this->string_ == value); } 78 bool operator==(const MultiTypeString& mts) const; 79 bool operator==(const MultiTypePrimitive& mtp) const; 77 80 78 81 using MultiTypePrimitive::operator!=; 79 inline bool operator!=(const char* value) const { return (this->string_ != std::string(value)); } 80 inline bool operator!=(const std::string& value) const { return (this->string_ != value); } 81 bool operator!=(const MultiTypeString& mts) const; 82 inline bool operator!=(const char* value) const { return (this->string_ != std::string(value)); } 83 inline bool operator!=(const std::string& value) const { return (this->string_ != value); } 84 bool operator!=(const MultiTypeString& mts) const; 85 bool operator!=(const MultiTypePrimitive& mtp) const; 82 86 83 virtual operator void*() 84 virtual operator int() 85 virtual operator unsigned int() 86 virtual operator char() 87 virtual operator unsigned char() 88 virtual operator short() 89 virtual operator unsigned short() 90 virtual operator long() 91 virtual operator unsigned long() 92 virtual operator float () 93 virtual operator double () 94 virtual operator long double() 95 virtual operator bool() 96 virtual operator std::string() 97 virtual operator const char*() 87 virtual operator void*() const; 88 virtual operator int() const; 89 virtual operator unsigned int() const; 90 virtual operator char() const; 91 virtual operator unsigned char() const; 92 virtual operator short() const; 93 virtual operator unsigned short() const; 94 virtual operator long() const; 95 virtual operator unsigned long() const; 96 virtual operator float () const; 97 virtual operator double () const; 98 virtual operator long double() const; 99 virtual operator bool() const; 100 virtual operator std::string() const; 101 virtual operator const char*() const; 98 102 99 103 using MultiTypePrimitive::setValue; 100 inline void setValue(const char* value) { this->type_ = MT_string; this->string_ = std::string(value); } 101 inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value; } 102 void setValue(const MultiTypeString& mts); 104 inline void setValue(const char* value) { this->type_ = MT_string; this->string_ = std::string(value); } 105 inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value; } 106 void setValue(const MultiTypeString& mts); 107 void setValue(const MultiTypePrimitive& mtp); 103 108 104 inline std::string getString() 105 inline const char* getConstChar() 109 inline std::string getString() const { return this->string_; } 110 inline const char* getConstChar() const { return this->string_.c_str(); } 106 111 107 inline std::string& getString() 108 inline const char* getConstChar() 112 inline std::string& getString() { return this->string_; } 113 inline const char* getConstChar() { return this->string_.c_str(); } 109 114 110 115 using MultiTypePrimitive::getValue; 111 inline void getValue(std::string* 112 inline void getValue(const char** 116 inline void getValue(std::string* variable) const { (*variable) = this->string_; } 117 inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); } 113 118 114 119 virtual std::string getTypename() const; … … 116 121 virtual std::string toString() const; 117 122 virtual bool fromString(const std::string value); 123 124 virtual bool assimilate(const MultiTypeString& mts, const MultiTypeString& defvalue = MultiTypeString()); 118 125 119 126 protected: -
code/branches/network/src/util/String.cc
r1219 r1446 185 185 else 186 186 return str; 187 } 188 189 /** 190 @brief Removes enclosing {braces}. 191 @param str The string to strip 192 @return The striped string 193 */ 194 std::string stripEnclosingBraces(const std::string& str) 195 { 196 std::string output = str; 197 198 while (output.size() >= 2 && output[0] == '{' && output[output.size() - 1] == '}') 199 output = output.substr(1, output.size() - 2); 200 201 return output; 187 202 } 188 203 -
code/branches/network/src/util/String.h
r1062 r1446 47 47 48 48 _UtilExport std::string stripEnclosingQuotes(const std::string& str); 49 _UtilExport std::string stripEnclosingBraces(const std::string& str); 49 50 50 51 _UtilExport bool isEmpty(const std::string& str);
Note: See TracChangeset
for help on using the changeset viewer.