Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 26, 2008, 8:30:33 PM (16 years ago)
Author:
landauf
Message:

I start to like it

Location:
code/branches/console/src/core
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/ArgumentCompletionFunctions.cc

    r1416 r1430  
    3535    namespace autocompletion
    3636    {
    37         std::list<std::pair<std::string, std::string> > fallback()
     37        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)()
    3838        {
    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> >();
    4140        }
    4241    }
  • code/branches/console/src/core/ArgumentCompletionFunctions.h

    r1416 r1430  
    3333#include <string>
    3434
     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
    3552namespace orxonox
    3653{
    3754    namespace autocompletion
    3855    {
    39         std::list<std::pair<std::string, std::string> > fallback();
     56        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(fallback)();
    4057    }
    4158}
  • code/branches/console/src/core/CommandEvaluation.cc

    r1427 r1430  
    110110                    {
    111111                        if (this->function_->getParamCount() == 0)
    112                             return /*CommandExecutor::complete*/(this->command_ = this->function_->getName());
     112                            return (this->command_ = this->function_->getName());
    113113                        else
    114                             return /*CommandExecutor::complete*/(this->command_ = this->function_->getName() + " ");
     114                            return (this->command_ = this->function_->getName() + " ");
    115115                    }
    116116                    else if (this->functionclass_)
    117                         return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " ");
     117                        return (this->command_ = this->functionclass_->getName() + " ");
    118118                    break;
    119119                case CS_Function:
     
    121121                    {
    122122                        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());
    124124                        else
    125                             return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " " + this->function_->getName() + " ");
     125                            return (this->command_ = this->functionclass_->getName() + " " + this->function_->getName() + " ");
    126126                    }
    127127                    break;
     
    129129                case CS_Params:
    130130                {
     131                    if (this->argument_ == "" && this->possibleArgument_ == "")
     132                        break;
     133
    131134                    unsigned int maxIndex = this->commandTokens_.size();
    132135                    if (this->command_[this->command_.size() - 1] != ' ')
     
    142145                    }
    143146
    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);
    145148                    break;
    146149                }
  • code/branches/console/src/core/CommandExecutor.cc

    r1427 r1430  
    355355                else
    356356                {
    357                     unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 1;
     357                    unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 2;
    358358                    if (CommandExecutor::getEvaluation().functionclass_)
    359359                        argumentNumber -= 1;
    360360
     361std::cout << "arglist: " << CommandExecutor::getLastArgument() << ", " << CommandExecutor::getEvaluation().function_->getName() << ", " << argumentNumber << std::endl;
    361362                    CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber);
    362363                    CommandExecutor::getEvaluation().state_ = CS_Params;
     
    488489    void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param)
    489490    {
     491        CommandExecutor::createArgumentCompletionList(command, param);
     492
    490493        CommandExecutor::getEvaluation().listOfPossibleArguments_.clear();
    491494        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)
    493496            if ((*it).first.find(lowercase) == 0 || fragment == "")
    494497                CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second));
     
    527530    std::string CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param)
    528531    {
     532        CommandExecutor::createArgumentCompletionList(command, param);
     533
    529534        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)
    531536            if ((*it).first == lowercase)
    532537                return (*it).second;
     
    535540    }
    536541
     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
    537560    std::string CommandExecutor::getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list)
    538561    {
  • code/branches/console/src/core/CommandExecutor.h

    r1427 r1430  
    9393            static std::string getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param);
    9494
     95            static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param);
    9596            static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);
    9697            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  
    3434    {
    3535        this->accessLevel_ = AccessLevel::None;
    36         this->autocompletionFunction_[0] = &autocompletion::fallback;
    37         this->autocompletionFunction_[1] = &autocompletion::fallback;
    38         this->autocompletionFunction_[2] = &autocompletion::fallback;
    39         this->autocompletionFunction_[3] = &autocompletion::fallback;
    40         this->autocompletionFunction_[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;
    4141    }
    4242
    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)
    4444    {
    4545        if (param < 5)
    46             this->autocompletionFunction_[param] = function;
     46            this->argumentCompleter_[param] = completer;
    4747        else
    4848        {
     
    5252    }
    5353
    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)
    5555    {
    56         if (param < 5)
    57             this->argumentList_ = (*this->autocompletionFunction_[param])();
     56        if (param < 5 && this->argumentCompleter_[param])
     57            this->argumentList_ = (*this->argumentCompleter_[param])(param1, param2, param3, param4, param5);
    5858        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();
    8260    }
    8361}
  • code/branches/console/src/core/ConsoleCommand.h

    r1416 r1430  
    4343
    4444#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)
    4646
    4747
     
    5353
    5454#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
    55     ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut((ConsoleCommand*)command)
     55    ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut(command)
    5656
    5757
     
    100100                { return this->accessLevel_; }
    101101
    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(); }
    107110
    108111        private:
    109112            AccessLevel::Level accessLevel_;
    110             std::list<std::pair<std::string, std::string> > (*autocompletionFunction_[5]) (void);
     113            ArgumentCompleter* argumentCompleter_[5];
    111114            std::list<std::pair<std::string, std::string> > argumentList_;
    112115    };
  • code/branches/console/src/core/CorePrereqs.h

    r1341 r1430  
    7777  typedef std::string LanguageEntryLabel;
    7878
     79  class ArgumentCompleter;
    7980  class BaseFactory;
    8081  class BaseMetaObjectListElement;
Note: See TracChangeset for help on using the changeset viewer.