Changeset 1430 for code/branches/console/src/core
- Timestamp:
- May 26, 2008, 8:30:33 PM (16 years ago)
- Location:
- code/branches/console/src/core
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/ArgumentCompletionFunctions.cc
r1416 r1430 35 35 namespace autocompletion 36 36 { 37 std::list<std::pair<std::string, std::string> > fallback()37 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)() 38 38 { 39 static std::list<std::pair<std::string, std::string> > list(1, std::pair<std::string, std::string>("muh", "MUH")); 40 return list; 39 return std::list<std::pair<std::string, std::string> >(); 41 40 } 42 41 } -
code/branches/console/src/core/ArgumentCompletionFunctions.h
r1416 r1430 33 33 #include <string> 34 34 35 #include "ArgumentCompleter.h" 36 #include "CorePrereqs.h" 37 38 39 #define ARGUMENT_COMPLETION_FUNCTION_DECLARATION(functionname) \ 40 ArgumentCompleter* functionname(); \ 41 _CoreExport std::list<std::pair<std::string, std::string> > acf_##functionname 42 43 #define ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(functionname) \ 44 ArgumentCompleter* functionname() \ 45 { \ 46 static ArgumentCompleter completer = ArgumentCompleter(&acf_##functionname); \ 47 return &completer; \ 48 } \ 49 \ 50 std::list<std::pair<std::string, std::string> > acf_##functionname 51 35 52 namespace orxonox 36 53 { 37 54 namespace autocompletion 38 55 { 39 std::list<std::pair<std::string, std::string> > fallback();56 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(fallback)(); 40 57 } 41 58 } -
code/branches/console/src/core/CommandEvaluation.cc
r1427 r1430 110 110 { 111 111 if (this->function_->getParamCount() == 0) 112 return /*CommandExecutor::complete*/(this->command_ = this->function_->getName());112 return (this->command_ = this->function_->getName()); 113 113 else 114 return /*CommandExecutor::complete*/(this->command_ = this->function_->getName() + " ");114 return (this->command_ = this->function_->getName() + " "); 115 115 } 116 116 else if (this->functionclass_) 117 return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " ");117 return (this->command_ = this->functionclass_->getName() + " "); 118 118 break; 119 119 case CS_Function: … … 121 121 { 122 122 if (this->function_->getParamCount() == 0) 123 return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " " + this->function_->getName());123 return (this->command_ = this->functionclass_->getName() + " " + this->function_->getName()); 124 124 else 125 return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " " + this->function_->getName() + " ");125 return (this->command_ = this->functionclass_->getName() + " " + this->function_->getName() + " "); 126 126 } 127 127 break; … … 129 129 case CS_Params: 130 130 { 131 if (this->argument_ == "" && this->possibleArgument_ == "") 132 break; 133 131 134 unsigned int maxIndex = this->commandTokens_.size(); 132 135 if (this->command_[this->command_.size() - 1] != ' ') … … 142 145 } 143 146 144 return /*CommandExecutor::complete*/(this->command_ = this->commandTokens_.subSet(0, maxIndex).join() + " " + this->argument_ + whitespace);147 return (this->command_ = this->commandTokens_.subSet(0, maxIndex).join() + " " + this->argument_ + whitespace); 145 148 break; 146 149 } -
code/branches/console/src/core/CommandExecutor.cc
r1427 r1430 355 355 else 356 356 { 357 unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 1;357 unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 2; 358 358 if (CommandExecutor::getEvaluation().functionclass_) 359 359 argumentNumber -= 1; 360 360 361 std::cout << "arglist: " << CommandExecutor::getLastArgument() << ", " << CommandExecutor::getEvaluation().function_->getName() << ", " << argumentNumber << std::endl; 361 362 CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber); 362 363 CommandExecutor::getEvaluation().state_ = CS_Params; … … 488 489 void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param) 489 490 { 491 CommandExecutor::createArgumentCompletionList(command, param); 492 490 493 CommandExecutor::getEvaluation().listOfPossibleArguments_.clear(); 491 494 std::string lowercase = getLowercase(fragment); 492 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin( param); it != command->getArgumentCompletionListEnd(param); ++it)495 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it) 493 496 if ((*it).first.find(lowercase) == 0 || fragment == "") 494 497 CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second)); … … 527 530 std::string CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param) 528 531 { 532 CommandExecutor::createArgumentCompletionList(command, param); 533 529 534 std::string lowercase = getLowercase(name); 530 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin( param); it != command->getArgumentCompletionListEnd(param); ++it)535 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it) 531 536 if ((*it).first == lowercase) 532 537 return (*it).second; … … 535 540 } 536 541 542 void CommandExecutor::createArgumentCompletionList(ConsoleCommand* command, unsigned int param) 543 { 544 std::string params[5]; 545 546 unsigned int index = 0; 547 unsigned int lowestIndex = 1 + (CommandExecutor::getEvaluation().functionclass_ != 0); 548 549 for (unsigned int i = CommandExecutor::argumentsGiven() - 2; i >= lowestIndex; --i) 550 { 551 params[index] = CommandExecutor::getArgument(i); 552 ++index; 553 if (index >= 5) 554 break; 555 } 556 557 command->createArgumentCompletionList(param, params[0], params[1], params[2], params[3], params[4]); 558 } 559 537 560 std::string CommandExecutor::getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list) 538 561 { -
code/branches/console/src/core/CommandExecutor.h
r1427 r1430 93 93 static std::string getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param); 94 94 95 static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param); 95 96 static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list); 96 97 static bool compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second); -
code/branches/console/src/core/ConsoleCommand.cc
r1416 r1430 34 34 { 35 35 this->accessLevel_ = AccessLevel::None; 36 this->a utocompletionFunction_[0] = &autocompletion::fallback;37 this->a utocompletionFunction_[1] = &autocompletion::fallback;38 this->a utocompletionFunction_[2] = &autocompletion::fallback;39 this->a utocompletionFunction_[3] = &autocompletion::fallback;40 this->a utocompletionFunction_[4] = &autocompletion::fallback;36 this->argumentCompleter_[0] = 0; 37 this->argumentCompleter_[1] = 0; 38 this->argumentCompleter_[2] = 0; 39 this->argumentCompleter_[3] = 0; 40 this->argumentCompleter_[4] = 0; 41 41 } 42 42 43 ConsoleCommand& ConsoleCommand::setArgumentCompletionList(unsigned int param, std::list<std::pair<std::string, std::string> > (*function) (void))43 ConsoleCommand& ConsoleCommand::setArgumentCompletionList(unsigned int param, ArgumentCompleter* completer) 44 44 { 45 45 if (param < 5) 46 this->a utocompletionFunction_[param] = function;46 this->argumentCompleter_[param] = completer; 47 47 else 48 48 { … … 52 52 } 53 53 54 const std::list<std::pair<std::string, std::string> >& ConsoleCommand::getArgumentCompletionList(unsigned int param)54 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 55 { 56 if (param < 5 )57 this->argumentList_ = (*this->a utocompletionFunction_[param])();56 if (param < 5 && this->argumentCompleter_[param]) 57 this->argumentList_ = (*this->argumentCompleter_[param])(param1, param2, param3, param4, param5); 58 58 else 59 this->argumentList_ = autocompletion::fallback(); 60 61 return this->argumentList_; 62 } 63 64 std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListBegin(unsigned int param) 65 { 66 if (param < 5) 67 this->argumentList_ = (*this->autocompletionFunction_[param])(); 68 else 69 this->argumentList_ = autocompletion::fallback(); 70 71 return this->argumentList_.begin(); 72 } 73 74 std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListEnd(unsigned int param) 75 { 76 if (param < 5) 77 this->argumentList_ = (*this->autocompletionFunction_[param])(); 78 else 79 this->argumentList_ = autocompletion::fallback(); 80 81 return this->argumentList_.end(); 59 this->argumentList_.clear(); 82 60 } 83 61 } -
code/branches/console/src/core/ConsoleCommand.h
r1416 r1430 43 43 44 44 #define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \ 45 ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand( (ConsoleCommand*)command, bCreateShortcut)45 ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut) 46 46 47 47 … … 53 53 54 54 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \ 55 ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut( (ConsoleCommand*)command)55 ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut(command) 56 56 57 57 … … 100 100 { return this->accessLevel_; } 101 101 102 ConsoleCommand& setArgumentCompletionList(unsigned int param, std::list<std::pair<std::string, std::string> > (*function) (void)); 103 104 const std::list<std::pair<std::string, std::string> >& getArgumentCompletionList(unsigned int param); 105 std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListBegin(unsigned int param); 106 std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListEnd(unsigned int param); 102 ConsoleCommand& setArgumentCompletionList(unsigned int param, ArgumentCompleter* completer); 103 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 const std::list<std::pair<std::string, std::string> >& getArgumentCompletionList() const 105 { return this->argumentList_; } 106 std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListBegin() const 107 { return this->argumentList_.begin(); } 108 std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListEnd() const 109 { return this->argumentList_.end(); } 107 110 108 111 private: 109 112 AccessLevel::Level accessLevel_; 110 std::list<std::pair<std::string, std::string> > (*autocompletionFunction_[5]) (void);113 ArgumentCompleter* argumentCompleter_[5]; 111 114 std::list<std::pair<std::string, std::string> > argumentList_; 112 115 }; -
code/branches/console/src/core/CorePrereqs.h
r1341 r1430 77 77 typedef std::string LanguageEntryLabel; 78 78 79 class ArgumentCompleter; 79 80 class BaseFactory; 80 81 class BaseMetaObjectListElement;
Note: See TracChangeset
for help on using the changeset viewer.