Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7233


Ignore:
Timestamp:
Aug 28, 2010, 12:02:03 AM (14 years ago)
Author:
landauf
Message:
  • console commands "setMMSoundPath" and "printObjects" are now hidden.
  • added "unhide" command to show hidden commands
  • extended auto-completion capability by allowing multi-word ArgumentCompleter and more
  • added new auto-completion function that allows other commands as argument for a command (for example "delay [time] [command]")
Location:
code/branches/consolecommands3/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/consolecommands3/src/libraries/core/command/ArgumentCompleter.h

    r7203 r7233  
    3838    {
    3939        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) {}
    4646
    4747            ArgumentCompletionList operator()(const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "")
     
    6666            }
    6767
     68            inline bool useMultipleWords() const
     69                { return this->bUseMultipleWords_; }
     70
    6871        private:
     72            bool bUseMultipleWords_;
    6973            unsigned char paramCount_;
    7074            ArgumentCompletionList (*function_0_) (void);
  • code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc

    r7232 r7233  
    3838#include "core/ConfigFileManager.h"
    3939#include "core/ConfigValueContainer.h"
     40#include "CommandExecutor.h"
     41#include "ConsoleCommand.h"
    4042#include "TclThreadManager.h"
    41 #include "ConsoleCommand.h"
    4243
    4344// Boost 1.36 has some issues with deprecated functions that have been omitted
     
    5758        }
    5859
    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            }
    66113        }
    67114
    68115        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)()
    69116        {
    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);
    88118        }
    89119
    90120        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(subcommands)(const std::string& fragment, const std::string& group)
    91121        {
    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            }
    109150        }
    110151
  • code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.h

    r7228 r7233  
    3939
    4040#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) \
    4146    ArgumentCompleter* functionname() \
    4247    { \
    43         static ArgumentCompleter completer = ArgumentCompleter(&acf_##functionname); \
     48        static ArgumentCompleter completer = ArgumentCompleter(&acf_##functionname, bUseMultipleWords); \
    4449        return &completer; \
    4550    } \
     
    5560        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(groupsandcommands)();
    5661        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);
    5765        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(files)(const std::string& fragment);
    5866        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(settingssections)();
  • code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc

    r7231 r7233  
    177177            this->retrievePossibleArguments();
    178178
    179         if (this->possibleArguments_.empty())
     179        if (CommandEvaluation::getSize(this->possibleArguments_) == 0)
    180180        {
    181181            return this->string_;
     
    184184        {
    185185            std::string output = this->string_.substr(0, this->string_.find_last_of(' ') + 1);
    186 
    187186            output += CommandEvaluation::getCommonBegin(this->possibleArguments_);
    188187            return output;
     
    234233            MultiType param[MAX_FUNCTOR_ARGUMENTS];
    235234
     235            size_t max = this->hintArgumentsOffset_ + this->hintCommand_->getExecutor()->getParamCount();
     236
    236237            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            }
    242257        }
    243258    }
     
    250265        {
    251266            const std::string& entry = it->getComparable();
     267
     268            if (entry == "")
     269            {
     270                ++it;
     271                continue;
     272            }
    252273
    253274            if (entry.size() < fragmentLC.size())
     
    275296    }
    276297
     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
    277307    /* static */ std::string CommandEvaluation::dump(const ArgumentCompletionList& list)
    278308    {
     
    280310        for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
    281311        {
    282             if (it != list.begin())
     312            output += it->getDisplay();
     313
     314            if (it->getComparable() != "")
    283315                output += ' ';
    284 
    285             output += it->getDisplay();
    286316        }
    287317        return output;
     
    316346    /* static */ std::string CommandEvaluation::getCommonBegin(const ArgumentCompletionList& list)
    317347    {
    318         if (list.size() == 0)
     348        if (CommandEvaluation::getSize(list) == 0)
    319349        {
    320350            return "";
    321351        }
    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 "";
    328366        }
    329367        else
     
    338376                    const std::string& argumentComparable = it->getComparable();
    339377                    const std::string& argument = it->getString();
     378
     379                    if (argumentComparable == "")
     380                        continue;
     381
    340382                    if (argument.size() > i)
    341383                    {
    342                         if (it == list.begin())
     384                        if (tempComparable == 0)
    343385                        {
    344386                            tempComparable = argumentComparable[i];
  • code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h

    r7230 r7233  
    6565            MultiType getEvaluatedParameter(unsigned int index) const;
    6666
     67            const ArgumentCompletionList& getPossibleArguments() const
     68                { return this->possibleArguments_; }
     69
    6770        private:
    6871            void initialize(const std::string& command);
     
    7578
    7679            static void strip(ArgumentCompletionList& list, const std::string& fragment);
     80            static size_t getSize(const ArgumentCompletionList& list);
    7781
    7882            static std::string dump(const ArgumentCompletionList& list);
  • code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc

    r7231 r7233  
    4242        .argumentCompleter(0, autocompletion::groupsandcommands())
    4343        .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, "");
    4450
    4551    /* static */ CommandExecutor& CommandExecutor::getInstance()
     
    149155        }
    150156    }
     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    }
    151162}
  • code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h

    r7229 r7233  
    5959            static const int Denied = 4;
    6060
     61            static MultiType unhide(const std::string& group, const std::string& name, const std::string& arguments);
    6162            static void _autocomplete(const std::string& group, const std::string& name) {}
    6263
  • code/branches/consolecommands3/src/libraries/tools/Timer.cc

    r7219 r7233  
    3939namespace orxonox
    4040{
    41     _SetConsoleCommand("delay", &delay);
     41    _SetConsoleCommand("delay", &delay).argumentCompleter(1, autocompletion::command());
    4242    _SetConsoleCommand("killdelays", &killdelays);
    4343
  • code/branches/consolecommands3/src/orxonox/gamestates/GSMainMenu.cc

    r7219 r7233  
    6060    _SetConsoleCommand(__CC_startDedicated_name,       &GSMainMenu::startDedicated ).deactivate();
    6161    _SetConsoleCommand(__CC_startMainMenu_name,        &GSMainMenu::startMainMenu  ).deactivate();
    62     _SetConsoleCommand(__CC_setMainMenuSoundPath_name, &GSMainMenu::setMainMenuSoundPath);
     62    _SetConsoleCommand(__CC_setMainMenuSoundPath_name, &GSMainMenu::setMainMenuSoundPath).hide();
    6363
    6464    GSMainMenu::GSMainMenu(const GameStateInfo& info)
  • code/branches/consolecommands3/src/orxonox/gamestates/GSRoot.cc

    r7219 r7233  
    4545    static const std::string __CC_pause_name = "pause";
    4646
    47     _SetConsoleCommand("printObjects", &GSRoot::printObjects);
     47    _SetConsoleCommand("printObjects", &GSRoot::printObjects).hide();
    4848    _SetConsoleCommand(__CC_setTimeFactor_name, &GSRoot::setTimeFactor).accessLevel(AccessLevel::Master).defaultValues(1.0);
    4949    _SetConsoleCommand(__CC_pause_name,         &GSRoot::pause        ).accessLevel(AccessLevel::Master);
Note: See TracChangeset for help on using the changeset viewer.