- Timestamp:
- May 27, 2008, 12:27:13 AM (17 years ago)
- Location:
- code/branches/console/src/core
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/ArgumentCompletionFunctions.cc
r1430 r1434 28 28 29 29 #include <iostream> 30 #include <map> 30 31 31 32 #include "ArgumentCompletionFunctions.h" 33 #include "CoreIncludes.h" 34 #include "Identifier.h" 35 #include "ConfigValueContainer.h" 36 #include "TclThreadManager.h" 37 #include "util/String.h" 32 38 33 39 namespace orxonox … … 39 45 return std::list<std::pair<std::string, std::string> >(); 40 46 } 47 48 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalueclasses)() 49 { 50 std::list<std::pair<std::string, std::string> > classlist; 51 52 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it) 53 if ((*it).second->hasConfigValues()) 54 classlist.push_back(std::pair<std::string, std::string>(getLowercase((*it).first), (*it).second->getName())); 55 56 return classlist; 57 } 58 59 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& classname) 60 { 61 std::list<std::pair<std::string, std::string> > configvalues; 62 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getIdentifierMap().find(classname); 63 64 if (identifier != Identifier::getIdentifierMapEnd() && (*identifier).second->hasConfigValues()) 65 { 66 for (std::map<std::string, ConfigValueContainer*>::const_iterator it = (*identifier).second->getConfigValueMapBegin(); it != (*identifier).second->getConfigValueMapEnd(); ++it) 67 configvalues.push_back(std::pair<std::string, std::string>(getLowercase((*it).first), (*it).second->getName())); 68 } 69 70 return configvalues; 71 } 72 73 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& varname, const std::string& classname) 74 { 75 std::list<std::pair<std::string, std::string> > oldvalue; 76 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); 77 if (identifier != Identifier::getLowercaseIdentifierMapEnd()) 78 { 79 std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); 80 if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) 81 { 82 std::string valuestring = (*variable).second->toString(); 83 oldvalue.push_back(std::pair<std::string, std::string>(valuestring, valuestring)); 84 } 85 } 86 return oldvalue; 87 } 88 89 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)() 90 { 91 return TclThreadManager::getInstance().getThreadList(); 92 } 41 93 } 42 94 } -
code/branches/console/src/core/ArgumentCompletionFunctions.h
r1430 r1434 50 50 std::list<std::pair<std::string, std::string> > acf_##functionname 51 51 52 52 53 namespace orxonox 53 54 { … … 55 56 { 56 57 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(fallback)(); 58 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(configvalueclasses)(); 59 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(configvalues)(const std::string& classname); 60 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(configvalue)(const std::string& varname, const std::string& classname); 61 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(tclthreads)(); 57 62 } 58 63 } -
code/branches/console/src/core/CommandEvaluation.cc
r1430 r1434 30 30 #include "ConsoleCommand.h" 31 31 #include "Debug.h" 32 #include "util/String.h" 32 33 33 34 namespace orxonox … … 81 82 } 82 83 83 if (!this->bCommandChanged_ )84 if (!this->bCommandChanged_ || removeTrailingWhitespaces(this->command_) == removeTrailingWhitespaces(this->originalCommand_)) 84 85 { 85 86 COUT(4) << "CE_execute: " << this->command_ << "\n"; … … 136 137 maxIndex -= 1; 137 138 std::string whitespace = ""; 138 if (this->function_->getParamCount() > (maxIndex + 1 - this->getStartindex()))139 whitespace = " ";140 139 141 140 if (this->possibleArgument_ != "") 142 141 { 143 maxIndex -= 1;144 142 this->argument_ = this->possibleArgument_; 143 if (this->function_->getParamCount() > (maxIndex + 1 - this->getStartindex())) 144 whitespace = " "; 145 145 } 146 146 … … 163 163 { 164 164 case CS_Uninitialized: 165 std::cout << "hint: CS_Uninitialized" << std::endl; 165 166 break; 166 167 case CS_Empty: 168 std::cout << "hint: CS_Empty" << std::endl; 167 169 case CS_ShortcutOrIdentifier: 170 std::cout << "hint: CS_ShortcutOrIdentifier" << std::endl; 168 171 if (this->listOfPossibleFunctions_.size() == 0) 169 172 return CommandEvaluation::dump(this->listOfPossibleIdentifiers_); … … 174 177 break; 175 178 case CS_Function: 179 std::cout << "hint: CS_Function" << std::endl; 176 180 return CommandEvaluation::dump(this->listOfPossibleFunctions_); 177 181 break; 178 182 case CS_ParamPreparation: 183 std::cout << "hint: CS_ParamPreparation" << std::endl; 179 184 case CS_Params: 185 std::cout << "hint: CS_Params" << std::endl; 180 186 if (this->listOfPossibleArguments_.size() > 0) 181 187 return CommandEvaluation::dump(this->listOfPossibleArguments_); … … 183 189 return CommandEvaluation::dump(this->function_); 184 190 case CS_Finished: 191 std::cout << "hint: CS_Finished" << std::endl; 185 192 if (this->function_) 186 193 return CommandEvaluation::dump(this->function_); 187 194 break; 188 195 case CS_Error: 196 std::cout << "hint: CS_Error" << std::endl; 189 197 return this->errorMessage_; 190 198 break; … … 272 280 } 273 281 282 std::string CommandEvaluation::dump(const std::list<std::pair<std::string, std::string> >& list) 283 { 284 std::string output = ""; 285 for (std::list<std::pair<std::string, std::string> >::const_iterator it = list.begin(); it != list.end(); ++it) 286 { 287 if (it != list.begin()) 288 output += " "; 289 290 output += (*it).second; 291 } 292 return output; 293 } 294 274 295 std::string CommandEvaluation::dump(const ConsoleCommand* command) 275 296 { -
code/branches/console/src/core/CommandEvaluation.h
r1427 r1434 82 82 unsigned int getStartindex() const; 83 83 static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list); 84 static std::string dump(const std::list<std::pair<std::string, std::string> >& list); 84 85 static std::string dump(const ConsoleCommand* command); 85 86 … … 95 96 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleIdentifiers_; 96 97 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_; 97 std::list<std::pair< const std::string*, const std::string*> > listOfPossibleArguments_;98 std::list<std::pair<std::string, std::string> > listOfPossibleArguments_; 98 99 99 100 Identifier* functionclass_; -
code/branches/console/src/core/CommandExecutor.cc
r1430 r1434 126 126 void CommandExecutor::parseIfNeeded(const std::string& command) 127 127 { 128 std::cout << "parse if needed: command: >" << command << "<" << std::endl; 129 std::cout << " old original: >" << CommandExecutor::getEvaluation().originalCommand_ << "<" << std::endl; 130 std::cout << " old modified: >" << CommandExecutor::getEvaluation().command_ << "<" << std::endl; 128 131 if (CommandExecutor::getEvaluation().state_ == CS_Uninitialized) 129 132 { 133 std::cout << "parse if needed: parse!" << std::endl; 130 134 CommandExecutor::parse(command); 131 135 } 132 else if ( CommandExecutor::getEvaluation().originalCommand_ != command)136 else if (/*removeTrailingWhitespaces*/(CommandExecutor::getEvaluation().originalCommand_) != /*removeTrailingWhitespaces*/(command)) 133 137 { 134 138 if (CommandExecutor::getEvaluation().command_ == command) 135 139 { 140 std::cout << "parse if needed: parse and set bNewCommand_ to false" << std::endl; 136 141 CommandExecutor::parse(command); 137 142 CommandExecutor::getEvaluation().bNewCommand_ = false; … … 139 144 else 140 145 { 146 std::cout << "parse if needed: parse!" << std::endl; 141 147 CommandExecutor::parse(command); 142 148 } 143 149 } 150 std::cout << "parse if needed: don't parse" << std::endl; 144 151 } 145 152 … … 156 163 { 157 164 case CS_Uninitialized: 165 std::cout << "0: Uninitialized\n"; 158 166 { 159 167 // Impossible … … 161 169 } 162 170 case CS_Empty: 171 std::cout << "0: Empty\n"; 163 172 { 164 173 if (CommandExecutor::argumentsGiven() == 0) … … 175 184 } 176 185 case CS_ShortcutOrIdentifier: 186 std::cout << "0: ShortcutOrIdentifier\n"; 177 187 { 178 188 if (CommandExecutor::argumentsGiven() > 1) … … 191 201 else if (CommandExecutor::getEvaluation().functionclass_) 192 202 { 203 std::cout << "MEP" << std::endl; 193 204 // It's a functionname 194 205 CommandExecutor::getEvaluation().state_ = CS_Function; … … 272 283 } 273 284 case CS_Function: 285 std::cout << "0: Function\n"; 274 286 { 275 287 if (CommandExecutor::getEvaluation().functionclass_) … … 283 295 if (CommandExecutor::getEvaluation().function_) 284 296 { 297 std::cout << "MEP2" << std::endl; 285 298 // It's a function 286 299 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; … … 377 390 std::cout << "3_1\n"; 378 391 // There is exactly one possible argument 379 CommandExecutor::getEvaluation().argument_ = *(*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second; 392 CommandExecutor::getEvaluation().argument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second; 393 CommandExecutor::getEvaluation().possibleArgument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second; 380 394 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 381 395 return; … … 393 407 std::cout << "3_3\n"; 394 408 // There are several possibilities 395 unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 1; 396 if (CommandExecutor::getEvaluation().functionclass_) 397 argumentNumber -= 1; 398 409 unsigned int argumentNumber = CommandExecutor::argumentsGiven(); 410 if (argumentNumber > 0) 411 --argumentNumber; 412 std::cout << "3_3_1\n"; 413 if (CommandExecutor::getEvaluation().functionclass_ && argumentNumber > 0) 414 --argumentNumber; 415 416 std::cout << "3_3_2\n"; 399 417 CommandExecutor::getEvaluation().argument_ = CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleArguments_); 418 std::cout << "3_3_3\n"; 400 419 CommandExecutor::getEvaluation().possibleArgument_ = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber); 420 std::cout << "3_3_4\n"; 401 421 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 422 std::cout << "3_3_5\n"; 402 423 return; 403 424 } … … 495 516 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it) 496 517 if ((*it).first.find(lowercase) == 0 || fragment == "") 497 CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(std::pair< const std::string*, const std::string*>(&(*it).first, &(*it).second));498 499 CommandExecutor::getEvaluation().listOfPossibleArguments_.sort(CommandExecutor::compareStringsInList );518 CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(std::pair<std::string, std::string>((*it).first, (*it).second)); 519 520 CommandExecutor::getEvaluation().listOfPossibleArguments_.sort(CommandExecutor::compareStringsInList2); 500 521 } 501 522 … … 530 551 std::string CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param) 531 552 { 553 std::cout << "4_1\n"; 532 554 CommandExecutor::createArgumentCompletionList(command, param); 533 555 556 std::cout << "4_2\n"; 534 557 std::string lowercase = getLowercase(name); 558 std::cout << "4_3\n"; 535 559 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it) 560 { 561 std::cout << "4_4\n"; 536 562 if ((*it).first == lowercase) 537 563 return (*it).second; 538 539 return 0; 564 } 565 566 std::cout << "4_5\n"; 567 return ""; 540 568 } 541 569 … … 599 627 } 600 628 629 std::string CommandExecutor::getCommonBegin(const std::list<std::pair<std::string, std::string> >& list) 630 { 631 if (list.size() == 0) 632 { 633 return ""; 634 } 635 else if (list.size() == 1) 636 { 637 return ((*list.begin()).first + " "); 638 } 639 else 640 { 641 std::string output = ""; 642 for (unsigned int i = 0; true; i++) 643 { 644 char temp = 0; 645 for (std::list<std::pair<std::string, std::string> >::const_iterator it = list.begin(); it != list.end(); ++it) 646 { 647 if ((*it).first.size() > i) 648 { 649 if (it == list.begin()) 650 { 651 temp = (*it).first[i]; 652 } 653 else 654 { 655 if (temp != (*it).first[i]) 656 return output; 657 } 658 } 659 else 660 { 661 return output; 662 } 663 } 664 output += temp; 665 } 666 return output; 667 } 668 } 669 601 670 bool CommandExecutor::compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second) 602 671 { 603 672 return ((*first.first) < (*second.first)); 604 673 } 674 675 bool CommandExecutor::compareStringsInList2(const std::pair<std::string, std::string>& first, const std::pair<std::string, std::string>& second) 676 { 677 return (first.first < second.first); 678 } 605 679 } -
code/branches/console/src/core/CommandExecutor.h
r1430 r1434 95 95 static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param); 96 96 static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list); 97 static std::string getCommonBegin(const std::list<std::pair<std::string, std::string> >& list); 97 98 static bool compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second); 99 static bool compareStringsInList2(const std::pair<std::string, std::string>& first, const std::pair<std::string, std::string>& second); 98 100 99 101 -
code/branches/console/src/core/ConfigFileManager.cc
r1341 r1434 38 38 namespace orxonox 39 39 { 40 SetConsoleCommandShortcutExtern(config).setArgumentCompleter(0, autocompletion::configvalueclasses()).setArgumentCompleter(1, autocompletion::configvalues()).setArgumentCompleter(2, autocompletion::configvalue()); 41 SetConsoleCommandShortcutExtern(tconfig); 40 42 SetConsoleCommandShortcutExtern(reloadConfig); 41 43 SetConsoleCommandShortcutExtern(cleanConfig); 42 44 SetConsoleCommandShortcutExtern(loadSettings); 43 45 SetConsoleCommandShortcutExtern(loadKeybindings); 46 47 bool config(const std::string& classname, const std::string& varname, const std::string& value) 48 { 49 std::cout << "10a_1\n"; 50 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); 51 if (identifier != Identifier::getLowercaseIdentifierMapEnd()) 52 { 53 std::cout << "10a_2\n"; 54 std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); 55 if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) 56 { 57 std::cout << "10a_3\n"; 58 return (*variable).second->tset(value); 59 } 60 } 61 return false; 62 } 63 64 bool tconfig(const std::string& classname, const std::string& varname, const std::string& value) 65 { 66 std::cout << "10b_1\n"; 67 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); 68 if (identifier != Identifier::getLowercaseIdentifierMapEnd()) 69 { 70 std::cout << "10b_2\n"; 71 std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); 72 if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) 73 { 74 std::cout << "10b_3\n"; 75 return (*variable).second->tset(value); 76 } 77 } 78 return false; 79 } 44 80 45 81 void reloadConfig() -
code/branches/console/src/core/ConfigFileManager.h
r1116 r1434 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/console/src/core/ConsoleCommand.cc
r1430 r1434 41 41 } 42 42 43 ConsoleCommand& ConsoleCommand::setArgumentComplet ionList(unsigned int param, ArgumentCompleter* completer)43 ConsoleCommand& ConsoleCommand::setArgumentCompleter(unsigned int param, ArgumentCompleter* completer) 44 44 { 45 45 if (param < 5) … … 52 52 } 53 53 54 ArgumentCompleter* ConsoleCommand::getArgumentCompleter(unsigned int param) const 55 { 56 if (param < 5) 57 return this->argumentCompleter_[param]; 58 else 59 return 0; 60 } 61 54 62 void ConsoleCommand::createArgumentCompletionList(unsigned int param, const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5) 55 63 { -
code/branches/console/src/core/ConsoleCommand.h
r1430 r1434 100 100 { return this->accessLevel_; } 101 101 102 ConsoleCommand& setArgumentCompletionList(unsigned int param, ArgumentCompleter* completer); 102 ConsoleCommand& setArgumentCompleter(unsigned int param, ArgumentCompleter* completer); 103 ArgumentCompleter* getArgumentCompleter(unsigned int param) const; 104 103 105 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 = ""); 104 106 const std::list<std::pair<std::string, std::string> >& getArgumentCompletionList() const -
code/branches/console/src/core/TclThreadManager.cc
r1424 r1434 48 48 namespace orxonox 49 49 { 50 SetConsoleCommandShortcutGeneric(tclexecute, createConsoleCommand(createFunctor(&TclThreadManager::execute), "tclexecute")) ;51 SetConsoleCommandShortcutGeneric(tclquery, createConsoleCommand(createFunctor(&TclThreadManager::query), "tclquery" )) ;50 SetConsoleCommandShortcutGeneric(tclexecute, createConsoleCommand(createFunctor(&TclThreadManager::execute), "tclexecute")).setArgumentCompleter(0, autocompletion::tclthreads()); 51 SetConsoleCommandShortcutGeneric(tclquery, createConsoleCommand(createFunctor(&TclThreadManager::query), "tclquery" )).setArgumentCompleter(0, autocompletion::tclthreads()); 52 52 SetConsoleCommand(TclThreadManager, create, false); 53 SetConsoleCommand(TclThreadManager, destroy, false) ;54 SetConsoleCommand(TclThreadManager, execute, false) ;55 SetConsoleCommand(TclThreadManager, query, false) ;53 SetConsoleCommand(TclThreadManager, destroy, false).setArgumentCompleter(0, autocompletion::tclthreads()); 54 SetConsoleCommand(TclThreadManager, execute, false).setArgumentCompleter(0, autocompletion::tclthreads()); 55 SetConsoleCommand(TclThreadManager, query, false).setArgumentCompleter(0, autocompletion::tclthreads()); 56 56 SetConsoleCommand(TclThreadManager, status, false); 57 SetConsoleCommand(TclThreadManager, dump, false) ;58 SetConsoleCommand(TclThreadManager, flush, false) ;57 SetConsoleCommand(TclThreadManager, dump, false).setArgumentCompleter(0, autocompletion::tclthreads()); 58 SetConsoleCommand(TclThreadManager, flush, false).setArgumentCompleter(0, autocompletion::tclthreads()); 59 59 60 60 TclThreadManager* instance_tclthreadmanager = &TclThreadManager::getInstance(); … … 632 632 } 633 633 634 std::list<std::pair<std::string, std::string> > TclThreadManager::getThreadList() const 635 { 636 boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_); 637 std::list<std::pair<std::string, std::string> > threads; 638 for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it) 639 { 640 std::string number = getConvertedValue<unsigned int, std::string>((*it).first); 641 threads.push_back(std::pair<std::string, std::string>(number, number)); 642 } 643 return threads; 644 } 645 634 646 void tclThread(TclInterpreterBundle* interpreterBundle, std::string command) 635 647 { -
code/branches/console/src/core/TclThreadManager.h
r1337 r1434 109 109 virtual void tick(float dt); 110 110 111 std::list<std::pair<std::string, std::string> > getThreadList() const; 112 111 113 private: 112 114 TclThreadManager();
Note: See TracChangeset
for help on using the changeset viewer.