Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7221


Ignore:
Timestamp:
Aug 26, 2010, 2:06:16 AM (14 years ago)
Author:
landauf
Message:

adapted CommandExecutor and CommandEvaluation to make it compile again, but it doesn't run yet. ready for refactoring.

Location:
code/branches/consolecommands3/src/libraries/core/command
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc

    r7203 r7221  
    6767    }
    6868
    69     bool CommandEvaluation::isValid() const
    70     {
    71         return (this->function_);
    72     }
    73 
    7469    bool CommandEvaluation::execute() const
    7570    {
     
    8479            *success = false;
    8580
    86         if (!this->isValid())
     81        if (!this->function_ || !this->function_->isActive())
    8782            return MT_Type::Null;
    8883
     
    9287                *success = true;
    9388            COUT(6) << "CE_execute (evaluation): " << this->function_->getName() << ' ' << this->param_[0] << ' ' << this->param_[1] << ' ' << this->param_[2] << ' ' << this->param_[3] << ' ' << this->param_[4] << std::endl;
    94             return (*this->function_)(this->param_[0], this->param_[1], this->param_[2], this->param_[3], this->param_[4]);
     89            return (*this->function_->getExecutor())(this->param_[0], this->param_[1], this->param_[2], this->param_[3], this->param_[4]);
    9590        }
    9691
     
    10196            unsigned int startindex = this->getStartindex();
    10297            if (this->commandTokens_.size() > startindex)
    103                 return this->function_->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter()), success);
     98                return this->function_->getExecutor()->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter()), success);
    10499            else
    105                 return this->function_->parse(removeSlashes(this->additionalParameter_), success);
     100                return this->function_->getExecutor()->parse(removeSlashes(this->additionalParameter_), success);
    106101        }
    107102
     
    122117                    if (this->function_)
    123118                    {
    124                         if (this->function_->getParamCount() == 0)
     119                        if (this->function_->getExecutor()->getParamCount() == 0)
    125120                            return (this->command_ = this->function_->getName());
    126121                        else
     
    133128                    if (this->function_)
    134129                    {
    135                         if (this->function_->getParamCount() == 0)
     130                        if (this->function_->getExecutor()->getParamCount() == 0)
    136131                            return (this->command_ = this->functionclass_->getName() + ' ' + this->function_->getName());
    137132                        else
     
    153148                    {
    154149                        this->argument_ = this->possibleArgument_;
    155                         if (this->function_->getParamCount() > (maxIndex + 1 - this->getStartindex()))
     150                        if (this->function_->getExecutor()->getParamCount() > (maxIndex + 1 - this->getStartindex()))
    156151                            whitespace = " ";
    157152                    }
     
    213208            this->param_[i] = MT_Type::Null;
    214209
    215         if (!this->isValid())
     210        if (!this->function_)
    216211            return;
    217212
     
    220215        if (this->commandTokens_.size() <= startindex)
    221216        {
    222             if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " "))
     217            if (this->function_->getBaseExecutor()->evaluate(this->getAdditionalParameter(), this->param_, " "))
    223218                this->bEvaluatedParams_ = true;
    224219        }
    225220        else if (this->commandTokens_.size() > startindex)
    226221        {
    227             if (this->function_->evaluate(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter(), this->param_, " "))
     222            if (this->function_->getBaseExecutor()->evaluate(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter(), this->param_, " "))
    228223                this->bEvaluatedParams_ = true;
    229224        }
     
    280275    }
    281276
    282     std::string CommandEvaluation::dump(const ConsoleCommand* command)
     277    std::string CommandEvaluation::dump(const _ConsoleCommand* command)
    283278    {
    284279        std::string output = command->getName();
    285         if (command->getParamCount() > 0)
     280        if (command->getExecutor()->getParamCount() > 0)
    286281            output += ": ";
    287282
    288         for (unsigned int i = 0; i < command->getParamCount(); i++)
     283        for (unsigned int i = 0; i < command->getExecutor()->getParamCount(); i++)
    289284        {
    290285            if (i != 0)
    291286                output += ' ';
    292287
    293             if (command->defaultValueSet(i))
     288            if (command->getExecutor()->defaultValueSet(i))
    294289                output += '[';
    295290            else
    296291                output += '{';
    297292
    298             output += command->getTypenameParam(i);
    299 
    300             if (command->defaultValueSet(i))
    301                 output += '=' + command->getDefaultValue(i).getString() + ']';
     293            output += command->getExecutor()->getTypenameParam(i);
     294
     295            if (command->getExecutor()->defaultValueSet(i))
     296                output += '=' + command->getExecutor()->getDefaultValue(i).getString() + ']';
    302297            else
    303298                output += '}';
  • code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h

    r7203 r7221  
    7272            void evaluateParams();
    7373
    74             bool isValid() const;
     74            bool isValid() const
     75                { return this->function_; }
    7576
    76             inline ConsoleCommand* getConsoleCommand() const
     77            inline _ConsoleCommand* getConsoleCommand() const
    7778                { return this->function_; }
    7879            inline const std::string& getOriginalCommand() const
     
    9394            static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list);
    9495            static std::string dump(const ArgumentCompletionList& list);
    95             static std::string dump(const ConsoleCommand* command);
     96            static std::string dump(const _ConsoleCommand* command);
    9697
    9798
     
    109110
    110111            Identifier* functionclass_;
    111             ConsoleCommand* function_;
     112            _ConsoleCommand* function_;
    112113            std::string possibleArgument_;
    113114            std::string argument_;
  • code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc

    r7216 r7221  
    4949    }
    5050
    51     const CommandEvaluation& CommandExecutor::getLastEvaluation()
    52     {
    53         return CommandExecutor::getInstance().evaluation_;
    54     }
    55 
    5651    bool CommandExecutor::execute(const std::string& command, bool useTcl)
    5752    {
     
    216211                        CommandExecutor::getEvaluation().functionclass_ = 0;
    217212                        CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().function_->getName();
    218                         if (CommandExecutor::getEvaluation().function_->getParamCount() > 0)
     213                        if (CommandExecutor::getEvaluation().function_->getExecutor()->getParamCount() > 0)
    219214                        {
    220215                            CommandExecutor::getEvaluation().command_ += ' ';
     
    303298                            CommandExecutor::getEvaluation().state_ = CommandState::ParamPreparation;
    304299                            CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + ' ' + CommandExecutor::getEvaluation().function_->getName();
    305                             if (CommandExecutor::getEvaluation().function_->getParamCount() > 0)
     300                            if (CommandExecutor::getEvaluation().function_->getExecutor()->getParamCount() > 0)
    306301                            {
    307302                                CommandExecutor::getEvaluation().command_ += ' ';
     
    335330            case CommandState::ParamPreparation:
    336331            {
    337                 if (CommandExecutor::getEvaluation().function_->getParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_))
     332                if (CommandExecutor::getEvaluation().function_->getExecutor()->getParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_))
    338333                {
    339334                    CommandExecutor::getEvaluation().state_ = CommandState::Finished;
     
    418413    }
    419414
    420     bool CommandExecutor::enoughArgumentsGiven(ConsoleCommand* command)
     415    bool CommandExecutor::enoughArgumentsGiven(_ConsoleCommand* command)
    421416    {
    422417        if (CommandExecutor::getEvaluation().functionclass_)
    423             return (CommandExecutor::argumentsGiven() > (2 + command->getParamCount()));
    424         else
    425             return (CommandExecutor::argumentsGiven() > (1 + command->getParamCount()));
     418            return (CommandExecutor::argumentsGiven() > (2 + command->getExecutor()->getParamCount()));
     419        else
     420            return (CommandExecutor::argumentsGiven() > (1 + command->getExecutor()->getParamCount()));
    426421    }
    427422
     
    441436    void CommandExecutor::createListOfPossibleIdentifiers(const std::string& fragment)
    442437    {
     438/*
    443439        CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.clear();
    444440        const std::string& lowercase = getLowercase(fragment);
     
    447443                if (it->first.find(lowercase) == 0 || fragment.empty())
    448444                    CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.push_back(std::pair<const std::string*, const std::string*>(&it->first, &it->second->getName()));
     445*/
    449446    }
    450447
    451448    void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier)
    452449    {
     450/*
    453451        CommandExecutor::getEvaluation().listOfPossibleFunctions_.clear();
    454452        const std::string& lowercase = getLowercase(fragment);
    455453        if (!identifier)
    456454        {
    457             for (std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
     455            for (std::map<std::string, _ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
    458456                if (it->first.find(lowercase) == 0 || fragment.empty())
    459457                    CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&it->first, &it->second->getName()));
     
    461459        else
    462460        {
    463             for (std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
     461            for (std::map<std::string, _ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
    464462                if (it->first.find(lowercase) == 0 || fragment.empty())
    465463                    CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&it->first, &it->second->getName()));
    466464        }
    467     }
    468 
    469     void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param)
    470     {
     465*/
     466    }
     467
     468    void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, _ConsoleCommand* command, unsigned int param)
     469    {
     470/*
    471471        CommandExecutor::createArgumentCompletionList(command, param);
    472472
     
    486486            }
    487487        }
     488*/
    488489    }
    489490
    490491    Identifier* CommandExecutor::getPossibleIdentifier(const std::string& name)
    491492    {
     493/*
    492494        const std::string& lowercase = getLowercase(name);
    493495        std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMap().find(lowercase);
    494496        if ((it != Identifier::getLowercaseStringIdentifierMapEnd()) && it->second->hasConsoleCommands())
    495497            return it->second;
    496 
     498*/
    497499        return 0;
    498500    }
    499501
    500     ConsoleCommand* CommandExecutor::getPossibleCommand(const std::string& name, Identifier* identifier)
    501     {
     502    _ConsoleCommand* CommandExecutor::getPossibleCommand(const std::string& name, Identifier* identifier)
     503    {
     504/*
    502505        const std::string& lowercase = getLowercase(name);
    503506        if (!identifier)
    504507        {
    505             std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(lowercase);
     508            std::map<std::string, _ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(lowercase);
    506509            if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd())
    507510                return it->second;
     
    509512        else
    510513        {
    511             std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(lowercase);
     514            std::map<std::string, _ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(lowercase);
    512515            if (it != identifier->getLowercaseConsoleCommandMapEnd())
    513516                return it->second;
    514517        }
     518*/
    515519        return 0;
    516520    }
    517521
    518     const std::string& CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param)
    519     {
     522    const std::string& CommandExecutor::getPossibleArgument(const std::string& name, _ConsoleCommand* command, unsigned int param)
     523    {
     524/*
    520525        CommandExecutor::createArgumentCompletionList(command, param);
    521526
     
    534539            }
    535540        }
    536 
     541*/
    537542        return BLANKSTRING;
    538543    }
    539544
    540     void CommandExecutor::createArgumentCompletionList(ConsoleCommand* command, unsigned int param)
    541     {
     545    void CommandExecutor::createArgumentCompletionList(_ConsoleCommand* command, unsigned int param)
     546    {
     547/*
    542548        std::string params[5];
    543549
     
    554560
    555561        command->createArgumentCompletionList(param, params[0], params[1], params[2], params[3], params[4]);
     562*/
    556563    }
    557564
     
    643650        }
    644651    }
    645 
    646     void CommandExecutor::destroyExternalCommands()
    647     {
    648         for (std::set<ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandExternals_.begin();
    649             it != CommandExecutor::getInstance().consoleCommandExternals_.end(); ++it)
    650             delete *it;
    651     }
    652652}
  • code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h

    r7216 r7221  
    5555
    5656            static CommandEvaluation evaluate(const std::string& command);
    57             static const CommandEvaluation& getLastEvaluation();
    5857
    5958        private:
     
    7069            static unsigned int argumentsFinished();
    7170            static unsigned int argumentsGiven();
    72             static bool enoughArgumentsGiven(ConsoleCommand* command);
     71            static bool enoughArgumentsGiven(_ConsoleCommand* command);
    7372            static const std::string& getArgument(unsigned int index);
    7473            static const std::string& getLastArgument();
     
    7675            static void createListOfPossibleIdentifiers(const std::string& fragment);
    7776            static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier = 0);
    78             static void createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param);
     77            static void createListOfPossibleArguments(const std::string& fragment, _ConsoleCommand* command, unsigned int param);
    7978
    8079            static Identifier* getPossibleIdentifier(const std::string& name);
    81             static ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0);
    82             static const std::string& getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param);
     80            static _ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0);
     81            static const std::string& getPossibleArgument(const std::string& name, _ConsoleCommand* command, unsigned int param);
    8382
    84             static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param);
     83            static void createArgumentCompletionList(_ConsoleCommand* command, unsigned int param);
    8584            static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);
    8685            static std::string getCommonBegin(const ArgumentCompletionList& list);
  • code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc

    r7218 r7221  
    343343    }
    344344
    345     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)
    346     {
    347         if (param < 5 && this->argumentCompleter_[param])
    348             this->argumentList_ = (*this->argumentCompleter_[param])(param1, param2, param3, param4, param5);
    349         else
    350             this->argumentList_.clear();
    351     }
    352 
    353345    _ConsoleCommand& _ConsoleCommand::description(const std::string& description)
    354346    {
  • code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h

    r7218 r7221  
    268268            ArgumentCompleter* getArgumentCompleter(unsigned int param) const;
    269269
    270             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 = "");
    271             const ArgumentCompletionList& getArgumentCompletionList() const
    272                 { return this->argumentList_; }
    273             ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const
    274                 { return this->argumentList_.begin(); }
    275             ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const
    276                 { return this->argumentList_.end(); }
    277 
    278270            inline _ConsoleCommand& setAsInputCommand()
    279271            {
     
    325317
    326318            ArgumentCompleter* argumentCompleter_[5];
    327             ArgumentCompletionList argumentList_;
    328319
    329320            KeybindMode::Value keybindMode_;
Note: See TracChangeset for help on using the changeset viewer.