Changeset 7233 for code/branches/consolecommands3/src/libraries
- Timestamp:
- Aug 28, 2010, 12:02:03 AM (14 years ago)
- Location:
- code/branches/consolecommands3/src/libraries
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/command/ArgumentCompleter.h
r7203 r7233 38 38 { 39 39 public: 40 ArgumentCompleter(ArgumentCompletionList (*function) (void) ) :paramCount_(0), function_0_(function) {}41 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1) ) :paramCount_(1), function_1_(function) {}42 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2) ) :paramCount_(2), function_2_(function) {}43 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3) ) :paramCount_(3), function_3_(function) {}44 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4) ) :paramCount_(4), function_4_(function) {}45 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5) ) :paramCount_(5), function_5_(function) {}40 ArgumentCompleter(ArgumentCompletionList (*function) (void), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(0), function_0_(function) {} 41 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(1), function_1_(function) {} 42 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(2), function_2_(function) {} 43 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(3), function_3_(function) {} 44 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(4), function_4_(function) {} 45 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(5), function_5_(function) {} 46 46 47 47 ArgumentCompletionList operator()(const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "") … … 66 66 } 67 67 68 inline bool useMultipleWords() const 69 { return this->bUseMultipleWords_; } 70 68 71 private: 72 bool bUseMultipleWords_; 69 73 unsigned char paramCount_; 70 74 ArgumentCompletionList (*function_0_) (void); -
code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc
r7232 r7233 38 38 #include "core/ConfigFileManager.h" 39 39 #include "core/ConfigValueContainer.h" 40 #include "CommandExecutor.h" 41 #include "ConsoleCommand.h" 40 42 #include "TclThreadManager.h" 41 #include "ConsoleCommand.h"42 43 43 44 // Boost 1.36 has some issues with deprecated functions that have been omitted … … 57 58 } 58 59 59 bool groupIsVisible(const std::map<std::string, _ConsoleCommand*>& group) 60 { 61 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = group.begin(); it_command != group.end(); ++it_command) 62 if (it_command->second->isActive() && it_command->second->hasAccess() && !it_command->second->isHidden()) 63 return true; 64 65 return false; 60 namespace detail 61 { 62 bool groupIsVisible(const std::map<std::string, _ConsoleCommand*>& group, bool bOnlyShowHidden) 63 { 64 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = group.begin(); it_command != group.end(); ++it_command) 65 if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden) 66 return true; 67 68 return false; 69 } 70 71 ArgumentCompletionList _groupsandcommands(bool bOnlyShowHidden) 72 { 73 ArgumentCompletionList groupList; 74 75 const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& commands = _ConsoleCommand::getCommands(); 76 for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group) 77 if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "") 78 groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first))); 79 80 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.find(""); 81 if (it_group != commands.end()) 82 { 83 groupList.push_back(ArgumentCompletionListElement("", "", "\n")); 84 85 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) 86 if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden) 87 groupList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first))); 88 } 89 90 return groupList; 91 } 92 93 ArgumentCompletionList _subcommands(const std::string& fragment, const std::string& group, bool bOnlyShowHidden) 94 { 95 ArgumentCompletionList commandList; 96 97 std::string groupLC = getLowercase(group); 98 99 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommands().begin(); 100 for ( ; it_group != _ConsoleCommand::getCommands().end(); ++it_group) 101 if (getLowercase(it_group->first) == groupLC) 102 break; 103 104 if (it_group != _ConsoleCommand::getCommands().end()) 105 { 106 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) 107 if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden) 108 commandList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first))); 109 } 110 111 return commandList; 112 } 66 113 } 67 114 68 115 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)() 69 116 { 70 ArgumentCompletionList groupList; 71 72 const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& commands = _ConsoleCommand::getCommands(); 73 for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group) 74 if (groupIsVisible(it_group->second)) 75 groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first))); 76 77 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.find(""); 78 if (it_group != commands.end()) 79 { 80 groupList.push_back(ArgumentCompletionListElement("\n")); 81 82 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) 83 if (it_command->second->isActive() && it_command->second->hasAccess() && !it_command->second->isHidden()) 84 groupList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first))); 85 } 86 87 return groupList; 117 return detail::_groupsandcommands(false); 88 118 } 89 119 90 120 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(subcommands)(const std::string& fragment, const std::string& group) 91 121 { 92 ArgumentCompletionList commandList; 93 94 std::string groupLC = getLowercase(group); 95 96 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommands().begin(); 97 for ( ; it_group != _ConsoleCommand::getCommands().end(); ++it_group) 98 if (getLowercase(it_group->first) == groupLC) 99 break; 100 101 if (it_group != _ConsoleCommand::getCommands().end()) 102 { 103 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) 104 if (it_command->second->isActive() && it_command->second->hasAccess() && !it_command->second->isHidden()) 105 commandList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first))); 106 } 107 108 return commandList; 122 return detail::_subcommands(fragment, group, false); 123 } 124 125 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(hiddengroupsandcommands)() 126 { 127 return detail::_groupsandcommands(true); 128 } 129 130 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(hiddensubcommands)(const std::string& fragment, const std::string& group) 131 { 132 return detail::_subcommands(fragment, group, true); 133 } 134 135 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI(command)(const std::string& fragment) 136 { 137 CommandEvaluation evaluation = CommandExecutor::evaluate(fragment); 138 const std::string& hint = evaluation.hint(); 139 140 if (evaluation.getPossibleArguments().size() > 0) 141 { 142 return evaluation.getPossibleArguments(); 143 } 144 else 145 { 146 ArgumentCompletionList list; 147 list.push_back(ArgumentCompletionListElement("", "", hint)); 148 return list; 149 } 109 150 } 110 151 -
code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.h
r7228 r7233 39 39 40 40 #define ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(functionname) \ 41 _ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_INTERNAL(functionname, false) 42 #define ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI(functionname) \ 43 _ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_INTERNAL(functionname, true) 44 45 #define _ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_INTERNAL(functionname, bUseMultipleWords) \ 41 46 ArgumentCompleter* functionname() \ 42 47 { \ 43 static ArgumentCompleter completer = ArgumentCompleter(&acf_##functionname ); \48 static ArgumentCompleter completer = ArgumentCompleter(&acf_##functionname, bUseMultipleWords); \ 44 49 return &completer; \ 45 50 } \ … … 55 60 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(groupsandcommands)(); 56 61 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(subcommands)(const std::string& fragment, const std::string& group); 62 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(hiddengroupsandcommands)(); 63 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(hiddensubcommands)(const std::string& fragment, const std::string& group); 64 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(command)(const std::string& fragment); 57 65 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(files)(const std::string& fragment); 58 66 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(settingssections)(); -
code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc
r7231 r7233 177 177 this->retrievePossibleArguments(); 178 178 179 if ( this->possibleArguments_.empty())179 if (CommandEvaluation::getSize(this->possibleArguments_) == 0) 180 180 { 181 181 return this->string_; … … 184 184 { 185 185 std::string output = this->string_.substr(0, this->string_.find_last_of(' ') + 1); 186 187 186 output += CommandEvaluation::getCommonBegin(this->possibleArguments_); 188 187 return output; … … 234 233 MultiType param[MAX_FUNCTOR_ARGUMENTS]; 235 234 235 size_t max = this->hintArgumentsOffset_ + this->hintCommand_->getExecutor()->getParamCount(); 236 236 237 for (size_t i = 0; i < argumentID; ++i) 237 param[i] = this->getToken(this->getNumberOfArguments() - i - 1); 238 239 this->possibleArguments_ = (*ac)(param[0], param[1], param[2], param[3], param[4]); 240 241 CommandEvaluation::strip(this->possibleArguments_, param[0]); 238 param[i] = this->getToken(std::min(this->getNumberOfArguments(), max) - i - 1); 239 240 if (this->getNumberOfArguments() > max) 241 { 242 if (ac->useMultipleWords()) 243 { 244 std::string surplusArguments = this->tokens_.subSet(max - 1).join(); 245 if (this->string_[this->string_.size() - 1] == ' ') 246 surplusArguments += ' '; 247 248 this->possibleArguments_ = (*ac)(surplusArguments, param[1], param[2], param[3], param[4]); 249 CommandEvaluation::strip(this->possibleArguments_, this->getToken(this->getNumberOfArguments() - 1)); 250 } 251 } 252 else 253 { 254 this->possibleArguments_ = (*ac)(param[0], param[1], param[2], param[3], param[4]); 255 CommandEvaluation::strip(this->possibleArguments_, param[0]); 256 } 242 257 } 243 258 } … … 250 265 { 251 266 const std::string& entry = it->getComparable(); 267 268 if (entry == "") 269 { 270 ++it; 271 continue; 272 } 252 273 253 274 if (entry.size() < fragmentLC.size()) … … 275 296 } 276 297 298 /* static */ size_t CommandEvaluation::getSize(const ArgumentCompletionList& list) 299 { 300 size_t count = 0; 301 for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it) 302 if (it->getComparable() != "") 303 ++count; 304 return count; 305 } 306 277 307 /* static */ std::string CommandEvaluation::dump(const ArgumentCompletionList& list) 278 308 { … … 280 310 for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it) 281 311 { 282 if (it != list.begin()) 312 output += it->getDisplay(); 313 314 if (it->getComparable() != "") 283 315 output += ' '; 284 285 output += it->getDisplay();286 316 } 287 317 return output; … … 316 346 /* static */ std::string CommandEvaluation::getCommonBegin(const ArgumentCompletionList& list) 317 347 { 318 if ( list.size() == 0)348 if (CommandEvaluation::getSize(list) == 0) 319 349 { 320 350 return ""; 321 351 } 322 else if (list.size() == 1) 323 { 324 if (list.begin()->hasDisplay()) 325 return (list.begin()->getString()); 326 else 327 return (list.begin()->getString() + ' '); 352 else if (CommandEvaluation::getSize(list) == 1) 353 { 354 for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it) 355 { 356 if (it->getComparable() != "") 357 { 358 if (it->hasDisplay()) 359 return (it->getString()); 360 else 361 return (it->getString() + ' '); 362 } 363 } 364 365 return ""; 328 366 } 329 367 else … … 338 376 const std::string& argumentComparable = it->getComparable(); 339 377 const std::string& argument = it->getString(); 378 379 if (argumentComparable == "") 380 continue; 381 340 382 if (argument.size() > i) 341 383 { 342 if ( it == list.begin())384 if (tempComparable == 0) 343 385 { 344 386 tempComparable = argumentComparable[i]; -
code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h
r7230 r7233 65 65 MultiType getEvaluatedParameter(unsigned int index) const; 66 66 67 const ArgumentCompletionList& getPossibleArguments() const 68 { return this->possibleArguments_; } 69 67 70 private: 68 71 void initialize(const std::string& command); … … 75 78 76 79 static void strip(ArgumentCompletionList& list, const std::string& fragment); 80 static size_t getSize(const ArgumentCompletionList& list); 77 81 78 82 static std::string dump(const ArgumentCompletionList& list); -
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc
r7231 r7233 42 42 .argumentCompleter(0, autocompletion::groupsandcommands()) 43 43 .argumentCompleter(1, autocompletion::subcommands()); 44 45 _SetConsoleCommand("unhide", &CommandExecutor::unhide) 46 .argumentCompleter(0, autocompletion::hiddengroupsandcommands()) 47 .argumentCompleter(1, autocompletion::hiddensubcommands()) 48 .defaultValue(1, "") 49 .defaultValue(2, ""); 44 50 45 51 /* static */ CommandExecutor& CommandExecutor::getInstance() … … 149 155 } 150 156 } 157 158 /* static */ MultiType CommandExecutor::unhide(const std::string& group, const std::string& name, const std::string& arguments) 159 { 160 return CommandExecutor::queryMT(group + " " + name + " " + arguments); 161 } 151 162 } -
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h
r7229 r7233 59 59 static const int Denied = 4; 60 60 61 static MultiType unhide(const std::string& group, const std::string& name, const std::string& arguments); 61 62 static void _autocomplete(const std::string& group, const std::string& name) {} 62 63 -
code/branches/consolecommands3/src/libraries/tools/Timer.cc
r7219 r7233 39 39 namespace orxonox 40 40 { 41 _SetConsoleCommand("delay", &delay) ;41 _SetConsoleCommand("delay", &delay).argumentCompleter(1, autocompletion::command()); 42 42 _SetConsoleCommand("killdelays", &killdelays); 43 43
Note: See TracChangeset
for help on using the changeset viewer.