Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1427


Ignore:
Timestamp:
May 26, 2008, 3:08:39 AM (16 years ago)
Author:
landauf
Message:

CommandExecutor seems to work very well right now. yet to come: autocompletion lists

Location:
code/branches/console/src
Files:
5 edited

Legend:

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

    r1424 r1427  
    5757        this->functionclass_ = 0;
    5858        this->function_ = 0;
     59        this->possibleArgument_ = "";
     60        this->argument_ = "";
    5961
    6062        this->errorMessage_ = "";
     
    9799        if (!this->bNewCommand_)
    98100        {
    99 std::cout << "ASDF" << std::endl;
     101std::cout << "not new" << std::endl;
    100102            switch (this->state_)
    101103            {
     
    106108                case CS_ShortcutOrIdentifier:
    107109                    if (this->function_)
    108                         return CommandExecutor::complete(this->function_->getName() + " ");
     110                    {
     111                        if (this->function_->getParamCount() == 0)
     112                            return /*CommandExecutor::complete*/(this->command_ = this->function_->getName());
     113                        else
     114                            return /*CommandExecutor::complete*/(this->command_ = this->function_->getName() + " ");
     115                    }
    109116                    else if (this->functionclass_)
    110                         return CommandExecutor::complete(this->functionclass_->getName() + " ");
     117                        return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " ");
    111118                    break;
    112119                case CS_Function:
    113120                    if (this->function_)
    114                         return CommandExecutor::complete(this->functionclass_->getName() + " " + this->function_->getName() + " ");
    115                     break;
     121                    {
     122                        if (this->function_->getParamCount() == 0)
     123                            return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " " + this->function_->getName());
     124                        else
     125                            return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " " + this->function_->getName() + " ");
     126                    }
     127                    break;
     128                case CS_ParamPreparation:
    116129                case CS_Params:
    117                     break;
     130                {
     131                    unsigned int maxIndex = this->commandTokens_.size();
     132                    if (this->command_[this->command_.size() - 1] != ' ')
     133                        maxIndex -= 1;
     134                    std::string whitespace = "";
     135                    if (this->function_->getParamCount() > (maxIndex + 1 - this->getStartindex()))
     136                        whitespace = " ";
     137
     138                    if (this->possibleArgument_ != "")
     139                    {
     140                        maxIndex -= 1;
     141                        this->argument_ = this->possibleArgument_;
     142                    }
     143
     144                    return /*CommandExecutor::complete*/(this->command_ = this->commandTokens_.subSet(0, maxIndex).join() + " " + this->argument_ + whitespace);
     145                    break;
     146                }
    118147                case CS_Finished:
    119148                    break;
     
    144173                return CommandEvaluation::dump(this->listOfPossibleFunctions_);
    145174                break;
     175            case CS_ParamPreparation:
    146176            case CS_Params:
    147177                if (this->listOfPossibleArguments_.size() > 0)
     
    241271    std::string CommandEvaluation::dump(const ConsoleCommand* command)
    242272    {
    243         std::string output = command->getName() + ": ";
     273        std::string output = command->getName();
     274        if (command->getParamCount() > 0)
     275            output += ": ";
     276
    244277        for (unsigned int i = 0; i < command->getParamCount(); i++)
    245278        {
  • code/branches/console/src/core/CommandEvaluation.h

    r1424 r1427  
    4646        CS_ShortcutOrIdentifier,
    4747        CS_Function,
     48        CS_ParamPreparation,
    4849        CS_Params,
    4950        CS_Finished,
     
    9899            Identifier* functionclass_;
    99100            ConsoleCommand* function_;
     101            std::string possibleArgument_;
     102            std::string argument_;
    100103
    101104            std::string errorMessage_;
  • code/branches/console/src/core/CommandExecutor.cc

    r1424 r1427  
    146146    void CommandExecutor::parse(const std::string& command, bool bInitialize)
    147147    {
    148 std::cout << "parse: command: >" << command << "<" << std::endl;
     148std::cout << "parse (" << bInitialize << "): command: >" << command << "<" << std::endl;
    149149        if (bInitialize)
    150150            CommandExecutor::getEvaluation().initialize(command);
     
    185185                    {
    186186                        // It's a shortcut
    187                         CommandExecutor::getEvaluation().state_ = CS_Params;
     187                        CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
    188188                        CommandExecutor::getEvaluation().functionclass_ = 0;
    189189                        // Move on to next case
     
    224224                            CommandExecutor::getEvaluation().bCommandChanged_ = true;
    225225                        }
    226                         CommandExecutor::getEvaluation().state_ = CS_Params;
     226                        CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
    227227                        CommandExecutor::getEvaluation().functionclass_ = 0;
    228228                        CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().function_->getName();
    229229                        if (CommandExecutor::getEvaluation().function_->getParamCount() > 0)
     230                        {
    230231                            CommandExecutor::getEvaluation().command_ += " ";
     232                            CommandExecutor::getEvaluation().bCommandChanged_ = true;
     233                        }
    231234                        // Move on to next case
    232235                    }
     
    263266                        CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0));
    264267                        CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0));
     268                        CommandExecutor::getEvaluation().bCommandChanged_ = true;
    265269                        return;
    266270                    }
     
    280284                        {
    281285                            // It's a function
    282                             CommandExecutor::getEvaluation().state_ = CS_Params;
     286                            CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
    283287                            // Move on to next case
    284288                        }
     
    308312                                CommandExecutor::getEvaluation().bCommandChanged_ = true;
    309313                            }
    310                             CommandExecutor::getEvaluation().state_ = CS_Params;
     314                            CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
    311315                            CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getEvaluation().function_->getName();
    312316                            if (CommandExecutor::getEvaluation().function_->getParamCount() > 0)
     317                            {
    313318                                CommandExecutor::getEvaluation().command_ += " ";
     319                                CommandExecutor::getEvaluation().bCommandChanged_ = true;
     320                            }
    314321                            // Move on to next case
    315322                        }
     
    327334                            CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleFunctions_);
    328335                            CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_);
     336                            CommandExecutor::getEvaluation().bCommandChanged_ = true;
    329337                            return;
    330338                        }
     
    333341                else
    334342                {
    335                     // There is no classname - move on to CS_Shortcut_Params
    336                 }
    337             }
    338 std::cout << "Waiting for arguments" << std::endl;
     343                    // There is no classname - move on to CS_ParamPreparation
     344                }
     345            }
     346std::cout << "1\n";
     347            case CS_ParamPreparation:
     348std::cout << "2\n";
     349            {
     350                if (CommandExecutor::getEvaluation().function_->getParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_))
     351                {
     352                    CommandExecutor::getEvaluation().state_ = CS_Finished;
     353                    return;
     354                }
     355                else
     356                {
     357                    unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 1;
     358                    if (CommandExecutor::getEvaluation().functionclass_)
     359                        argumentNumber -= 1;
     360
     361                    CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber);
     362                    CommandExecutor::getEvaluation().state_ = CS_Params;
     363
     364                    if (CommandExecutor::getEvaluation().bCommandChanged_)
     365                    {
     366                        // Don't do more than one change
     367                        return;
     368                    }
     369                }
     370            }
    339371            case CS_Params:
    340             {
     372std::cout << "3\n";
     373            {
     374                if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 1)
     375                {
     376std::cout << "3_1\n";
     377                    // There is exactly one possible argument
     378                    CommandExecutor::getEvaluation().argument_ = *(*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second;
     379                    CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
     380                    return;
     381                }
     382                else if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 0)
     383                {
     384std::cout << "3_2\n";
     385                    // The user tries something new - we let him do
     386                    CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
     387                    CommandExecutor::getEvaluation().argument_ = CommandExecutor::getLastArgument();
     388                    return;
     389                }
     390                else
     391                {
     392std::cout << "3_3\n";
     393                    // There are several possibilities
     394                    unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 1;
     395                    if (CommandExecutor::getEvaluation().functionclass_)
     396                        argumentNumber -= 1;
     397
     398                    CommandExecutor::getEvaluation().argument_ = CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleArguments_);
     399                    CommandExecutor::getEvaluation().possibleArgument_ = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber);
     400                    CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
     401                    return;
     402                }
    341403            }
    342404            case CS_Finished:
     405std::cout << "4\n";
    343406            {
    344407                // Nothing more to do
     
    373436    {
    374437        if (CommandExecutor::getEvaluation().functionclass_)
    375             return (CommandExecutor::getEvaluation().commandTokens_.size() >= (2 + command->getParamCount()));
    376         else
    377             return (CommandExecutor::getEvaluation().commandTokens_.size() >= (1 + command->getParamCount()));
     438            return (CommandExecutor::argumentsGiven() > (2 + command->getParamCount()));
     439        else
     440            return (CommandExecutor::argumentsGiven() > (1 + command->getParamCount()));
    378441    }
    379442
     
    388451    std::string CommandExecutor::getLastArgument()
    389452    {
    390         return CommandExecutor::getArgument(CommandExecutor::argumentsGiven());
     453        return CommandExecutor::getArgument(CommandExecutor::argumentsGiven() - 1);
    391454    }
    392455
     
    462525    }
    463526
    464     const std::string* CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param)
     527    std::string CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param)
    465528    {
    466529        std::string lowercase = getLowercase(name);
    467530        for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(param); it != command->getArgumentCompletionListEnd(param); ++it)
    468531            if ((*it).first == lowercase)
    469                 return &(*it).second;
     532                return (*it).second;
    470533
    471534        return 0;
  • code/branches/console/src/core/CommandExecutor.h

    r1424 r1427  
    9191            static Identifier* getPossibleIdentifier(const std::string& name);
    9292            static ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0);
    93             static const std::string* getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param);
     93            static std::string getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param);
    9494
    9595            static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);
  • code/branches/console/src/orxonox/objects/SpaceShip.cc

    r1341 r1427  
    5454{
    5555    SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug);
    56     SetConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug);
    57     SetConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug);
    58     SetConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug);
     56    SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug);
     57    SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug);
     58    SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug);
    5959
    6060    CreateFactory(SpaceShip);
Note: See TracChangeset for help on using the changeset viewer.