Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 952


Ignore:
Timestamp:
Mar 29, 2008, 3:04:06 PM (16 years ago)
Author:
landauf
Message:

added CommandEvaluation to store the results of a command evaluation in CommandExecutor

Location:
code/branches/core2/src/orxonox/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/CommandExecutor.cc

    r951 r952  
    5151    }
    5252
     53    CommandEvaluation& CommandExecutor::getEvaluation()
     54    {
     55        return CommandExecutor::getInstance().evaluation_;
     56    }
     57
    5358    bool CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor)
    5459    {
     
    8893    bool CommandExecutor::execute(const std::string& command)
    8994    {
    90         if (CommandExecutor::getInstance().lastProcessedCommand_ != command)
     95        if (CommandExecutor::getEvaluation().processedCommand_ != command)
    9196            CommandExecutor::parse(command);
    9297
    93         CommandExecutor::getInstance().tokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
    94 
    95         switch (CommandExecutor::getInstance().state_)
     98        return CommandExecutor::execute(CommandExecutor::getEvaluation());
     99    }
     100
     101
     102    bool CommandExecutor::execute(const CommandEvaluation& evaluation)
     103    {
     104        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     105
     106        switch (evaluation.state_)
    96107        {
    97108            case CS_Empty:
     
    104115            case CS_Shortcut_Finished:
    105116                // call the shortcut
    106                 if (CommandExecutor::getInstance().shortcut_ != 0)
    107                     return CommandExecutor::getInstance().shortcut_->parse(CommandExecutor::getInstance().tokens_.subSet(1).join());
     117                if (evaluation.shortcut_ != 0)
     118                    return evaluation.shortcut_->parse(tokens.subSet(1).join());
    108119                break;
    109120            case CS_Function:
     
    114125            case CS_Function_Finished:
    115126                // call the shortcut
    116                 if (CommandExecutor::getInstance().function_ != 0)
    117                     return CommandExecutor::getInstance().function_->parse(CommandExecutor::getInstance().tokens_.subSet(2).join());
     127                if (evaluation.function_ != 0)
     128                    return evaluation.function_->parse(tokens.subSet(2).join());
    118129                break;
    119130            case CS_ConfigValueClass:
     
    126137            case CS_ConfigValueFinished:
    127138                // set the config value
    128                 if (CommandExecutor::getInstance().configvalue_ != 0)
    129                     return CommandExecutor::getInstance().configvalue_->parseString(CommandExecutor::getInstance().tokens_.subSet(3).join());
     139                if (evaluation.configvalue_ != 0)
     140                    return evaluation.configvalue_->parseString(tokens.subSet(3).join());
    130141                break;
    131142            case CS_KeybindKey:
     
    147158    std::string CommandExecutor::complete(const std::string& command)
    148159    {
    149         if (CommandExecutor::getInstance().lastProcessedCommand_ != command)
     160        if (CommandExecutor::getEvaluation().processedCommand_ != command)
    150161            CommandExecutor::parse(command);
    151162
    152         CommandExecutor::getInstance().tokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     163        return CommandExecutor::complete(CommandExecutor::getEvaluation());
     164    }
     165
     166    std::string CommandExecutor::complete(const CommandEvaluation& evaluation)
     167    {
     168        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
    153169
    154170        std::list<const std::string*> temp;
    155         if (CommandExecutor::getInstance().state_ == CS_Empty)
    156         {
    157             temp.insert(temp.end(), CommandExecutor::getInstance().listOfPossibleShortcuts_.begin(), CommandExecutor::getInstance().listOfPossibleShortcuts_.end());
    158             temp.insert(temp.end(), CommandExecutor::getInstance().listOfPossibleFunctionClasses_.begin(), CommandExecutor::getInstance().listOfPossibleFunctionClasses_.end());
    159         }
    160 
    161         switch (CommandExecutor::getInstance().state_)
     171        if (evaluation.state_ == CS_Empty)
     172        {
     173            temp.insert(temp.end(), evaluation.listOfPossibleShortcuts_.begin(), evaluation.listOfPossibleShortcuts_.end());
     174            temp.insert(temp.end(), evaluation.listOfPossibleFunctionClasses_.begin(), evaluation.listOfPossibleFunctionClasses_.end());
     175        }
     176
     177        switch (evaluation.state_)
    162178        {
    163179            case CS_Empty:
    164                 return (CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(temp));
     180                return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(temp));
    165181                break;
    166182            case CS_FunctionClass_Or_Shortcut_Or_Keyword:
    167183                break;
    168184            case CS_Shortcut_Params:
    169                 if (command[command.size() - 1] != ' ')
    170                     return (command + " ");
     185                if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' '))
     186                    return (evaluation.processedCommand_ + " ");
    171187                break;
    172188            case CS_Shortcut_Finished:
    173189                break;
    174190            case CS_Function:
    175                 return (CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleFunctions_));
     191                return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleFunctions_));
    176192                break;
    177193            case CS_Function_Params:
    178                 if (command[command.size() - 1] != ' ')
    179                     return (command + " ");
     194                if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' '))
     195                    return (evaluation.processedCommand_ + " ");
    180196                break;
    181197            case CS_Function_Finished:
    182198                break;
    183199            case CS_ConfigValueClass:
    184                 return (CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleConfigValueClasses_));
     200                return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValueClasses_));
    185201                break;
    186202            case CS_ConfigValue:
    187                 return (CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleConfigValues_));
     203                return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValues_));
    188204                break;
    189205            case CS_ConfigValueType:
    190                 if (command[command.size() - 1] != ' ')
    191                     return (command + " ");
     206                if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' '))
     207                    return (evaluation.processedCommand_ + " ");
    192208                break;
    193209            case CS_ConfigValueFinished:
    194210                break;
    195211            case CS_KeybindKey:
    196                 return (CommandExecutor::getInstance().tokens_.subSet(0, CommandExecutor::getInstance().tokens_.size() - 1).join() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getInstance().listOfPossibleKeys_));
     212                return (tokens.subSet(0, tokens.size() - 1).join() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleKeys_));
    197213                break;
    198214            case CS_KeybindCommand:
    199                 if (command[command.size() - 1] != ' ')
    200                     return (command + " ");
     215                if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' '))
     216                    return (evaluation.processedCommand_ + " ");
    201217                break;
    202218            case CS_KeybindFinished:
     
    206222        }
    207223
    208         return CommandExecutor::getInstance().lastProcessedCommand_;
     224        return evaluation.processedCommand_;
    209225    }
    210226
    211227    std::string CommandExecutor::hint(const std::string& command)
    212228    {
    213         if (CommandExecutor::getInstance().lastProcessedCommand_ != command)
     229        if (CommandExecutor::getEvaluation().processedCommand_ != command)
    214230            CommandExecutor::parse(command);
    215231
    216         CommandExecutor::getInstance().tokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
    217 
    218         switch (CommandExecutor::getInstance().state_)
     232        return CommandExecutor::hint(CommandExecutor::getEvaluation());
     233    }
     234
     235    std::string CommandExecutor::hint(const CommandEvaluation& evaluation)
     236    {
     237        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     238
     239        switch (evaluation.state_)
    219240        {
    220241            case CS_Empty:
    221                 return (CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleShortcuts_) + "\n" + CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleFunctionClasses_));
     242                return (CommandExecutor::dump(evaluation.listOfPossibleShortcuts_) + "\n" + CommandExecutor::dump(evaluation.listOfPossibleFunctionClasses_));
    222243                break;
    223244            case CS_FunctionClass_Or_Shortcut_Or_Keyword:
    224245                break;
    225246            case CS_Shortcut_Params:
    226                 if (CommandExecutor::getInstance().shortcut_ != 0)
    227                     return CommandExecutor::dump(CommandExecutor::getInstance().shortcut_);
     247                if (evaluation.shortcut_ != 0)
     248                    return CommandExecutor::dump(evaluation.shortcut_);
    228249                break;
    229250            case CS_Shortcut_Finished:
    230                 if (CommandExecutor::getInstance().shortcut_ != 0)
    231                     return CommandExecutor::dump(CommandExecutor::getInstance().shortcut_);
     251                if (evaluation.shortcut_ != 0)
     252                    return CommandExecutor::dump(evaluation.shortcut_);
    232253                break;
    233254            case CS_Function:
    234                 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleFunctions_);
     255                return CommandExecutor::dump(evaluation.listOfPossibleFunctions_);
    235256                break;
    236257            case CS_Function_Params:
    237                 if (CommandExecutor::getInstance().function_ != 0)
    238                     return CommandExecutor::dump(CommandExecutor::getInstance().function_);
     258                if (evaluation.function_ != 0)
     259                    return CommandExecutor::dump(evaluation.function_);
    239260                break;
    240261            case CS_Function_Finished:
    241                 if (CommandExecutor::getInstance().function_ != 0)
    242                     return CommandExecutor::dump(CommandExecutor::getInstance().function_);
     262                if (evaluation.function_ != 0)
     263                    return CommandExecutor::dump(evaluation.function_);
    243264                break;
    244265            case CS_ConfigValueClass:
    245                 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleConfigValueClasses_);
     266                return CommandExecutor::dump(evaluation.listOfPossibleConfigValueClasses_);
    246267                break;
    247268            case CS_ConfigValue:
    248                 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleConfigValues_);
     269                return CommandExecutor::dump(evaluation.listOfPossibleConfigValues_);
    249270                break;
    250271            case CS_ConfigValueType:
    251                 if (CommandExecutor::getInstance().configvalue_ != 0)
    252                     return CommandExecutor::dump(CommandExecutor::getInstance().configvalue_);
     272                if (evaluation.configvalue_ != 0)
     273                    return CommandExecutor::dump(evaluation.configvalue_);
    253274                break;
    254275            case CS_ConfigValueFinished:
    255                 if (CommandExecutor::getInstance().configvalue_ != 0)
    256                     return CommandExecutor::dump(CommandExecutor::getInstance().configvalue_);
     276                if (evaluation.configvalue_ != 0)
     277                    return CommandExecutor::dump(evaluation.configvalue_);
    257278                break;
    258279            case CS_KeybindKey:
    259                 return CommandExecutor::dump(CommandExecutor::getInstance().listOfPossibleKeys_);
     280                return CommandExecutor::dump(evaluation.listOfPossibleKeys_);
    260281                break;
    261282            case CS_KeybindCommand:
    262                 if (CommandExecutor::getInstance().key_ != 0)
    263                     return CommandExecutor::dump(CommandExecutor::getInstance().key_);
     283                if (evaluation.key_ != 0)
     284                    return CommandExecutor::dump(evaluation.key_);
    264285                break;
    265286            case CS_KeybindFinished:
    266                 if (CommandExecutor::getInstance().key_ != 0)
    267                     return CommandExecutor::dump(CommandExecutor::getInstance().key_);
     287                if (evaluation.key_ != 0)
     288                    return CommandExecutor::dump(evaluation.key_);
    268289                break;
    269290            case CS_Error:
     
    275296    }
    276297
     298    const CommandEvaluation& CommandExecutor::evaluate(const std::string& command)
     299    {
     300        CommandExecutor::parse(command, true);
     301        return CommandExecutor::getEvaluation();
     302    }
     303
    277304    void CommandExecutor::parse(const std::string& command, bool bInitialize)
    278305    {
    279         CommandExecutor::getInstance().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
    280         CommandExecutor::getInstance().lastProcessedCommand_ = command;
     306        CommandExecutor::getEvaluation().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     307        CommandExecutor::getEvaluation().processedCommand_ = command;
    281308
    282309        if (bInitialize)
    283310            CommandExecutor::initialize();
    284311
    285         switch (CommandExecutor::getInstance().state_)
     312        switch (CommandExecutor::getEvaluation().state_)
    286313        {
    287314            case CS_Empty:
     
    290317                    // We want a hint for the first token
    291318                    // Check if there is already a perfect match
    292                     CommandExecutor::getInstance().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));
    293                     CommandExecutor::getInstance().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));
    294 
    295                     if ((CommandExecutor::getInstance().functionclass_ != 0) || (CommandExecutor::getInstance().shortcut_ != 0))
     319                    CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));
     320                    CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));
     321
     322                    if ((CommandExecutor::getEvaluation().functionclass_ != 0) || (CommandExecutor::getEvaluation().shortcut_ != 0))
    296323                    {
    297324                        // Yes, there is a class or a shortcut with the searched name
    298325                        // Add a whitespace and continue parsing
    299                         CommandExecutor::getInstance().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;
     326                        CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;
    300327                        CommandExecutor::parse(command + " ", false);
    301328                        return;
     
    310337                {
    311338                    // There is at least one argument: Check if it's a shortcut, a classname or a special keyword
    312                     CommandExecutor::getInstance().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;
     339                    CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;
    313340                    CommandExecutor::parse(command, false);
    314341                    return;
     
    321348                    {
    322349                        // We want to set a config value
    323                         CommandExecutor::getInstance().state_ = CS_ConfigValueClass;
     350                        CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass;
    324351                        CommandExecutor::parse(command, false);
    325352                        return;
     
    328355                    {
    329356                        // We want to set a keybinding
    330                         CommandExecutor::getInstance().state_ = CS_KeybindKey;
     357                        CommandExecutor::getEvaluation().state_ = CS_KeybindKey;
    331358                        CommandExecutor::parse(command, false);
    332359                        return;
    333360                    }
    334361
    335                     if (CommandExecutor::getInstance().functionclass_ == 0)
    336                         CommandExecutor::getInstance().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));
    337                     if (CommandExecutor::getInstance().shortcut_ == 0)
    338                         CommandExecutor::getInstance().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));
    339 
    340                     if ((CommandExecutor::getInstance().functionclass_ == 0) && (CommandExecutor::getInstance().shortcut_ == 0))
     362                    if (CommandExecutor::getEvaluation().functionclass_ == 0)
     363                        CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));
     364                    if (CommandExecutor::getEvaluation().shortcut_ == 0)
     365                        CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));
     366
     367                    if ((CommandExecutor::getEvaluation().functionclass_ == 0) && (CommandExecutor::getEvaluation().shortcut_ == 0))
    341368                    {
    342369                        // Argument 1 seems to be wrong
    343370                        AddLanguageEntry("CommandExecutor::NoSuchCommandOrClassName", "No such command or classname");
    344                         CommandExecutor::getInstance().errorMessage_ = (CommandExecutor::getToken(0) + ": " + GetLocalisation("CommandExecutor::NoSuchCommandOrClassName"));
    345                         CommandExecutor::getInstance().state_ = CS_Error;
    346                         return;
    347                     }
    348                     else if (CommandExecutor::getInstance().shortcut_ != 0)
     371                        CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(0) + ": " + GetLocalisation("CommandExecutor::NoSuchCommandOrClassName"));
     372                        CommandExecutor::getEvaluation().state_ = CS_Error;
     373                        return;
     374                    }
     375                    else if (CommandExecutor::getEvaluation().shortcut_ != 0)
    349376                    {
    350377                        // Argument 1 is a shortcut: Return the needed parameter types
    351                         CommandExecutor::getInstance().state_ = CS_Shortcut_Params;
     378                        CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params;
    352379                        CommandExecutor::parse(command, false);
    353380                        return;
     
    356383                    {
    357384                        // Argument 1 is a classname: Return the possible functions
    358                         CommandExecutor::getInstance().state_ = CS_Function;
     385                        CommandExecutor::getEvaluation().state_ = CS_Function;
    359386                        CommandExecutor::parse(command, false);
    360387                        return;
     
    363390                else
    364391                {
    365                     CommandExecutor::getInstance().state_ = CS_Error;
     392                    CommandExecutor::getEvaluation().state_ = CS_Error;
    366393                    return;
    367394                }
    368395                break;
    369396            case CS_Shortcut_Params:
    370                 if (CommandExecutor::getInstance().shortcut_ != 0)
     397                if (CommandExecutor::getEvaluation().shortcut_ != 0)
    371398                {
    372399                    // Valid command
    373400                    // Check if there are enough parameters
    374                     if (CommandExecutor::enoughParametersGiven(1, CommandExecutor::getInstance().shortcut_))
    375                     {
    376                         CommandExecutor::getInstance().state_ = CS_Shortcut_Finished;
     401                    if (CommandExecutor::enoughParametersGiven(1, CommandExecutor::getEvaluation().shortcut_))
     402                    {
     403                        CommandExecutor::getEvaluation().state_ = CS_Shortcut_Finished;
    377404                        return;
    378405                    }
     
    381408                {
    382409                    // Something is wrong
    383                     CommandExecutor::getInstance().state_ = CS_Error;
     410                    CommandExecutor::getEvaluation().state_ = CS_Error;
    384411                    return;
    385412                }
    386413                break;
    387414            case CS_Function:
    388                 if (CommandExecutor::getInstance().functionclass_ != 0)
     415                if (CommandExecutor::getEvaluation().functionclass_ != 0)
    389416                {
    390417                    // We have a valid classname
     
    393420                    {
    394421                        // There is a second argument: Check if it's a valid functionname
    395                         CommandExecutor::getInstance().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getInstance().functionclass_);
    396                         if (CommandExecutor::getInstance().function_ == 0)
     422                        CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
     423                        if (CommandExecutor::getEvaluation().function_ == 0)
    397424                        {
    398425                            // Argument 2 seems to be wrong
    399426                            AddLanguageEntry("CommandExecutor::NoSuchFunctionnameIn", "No such functionname in");
    400                             CommandExecutor::getInstance().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchFunctionnameIn") + " " + CommandExecutor::getInstance().functionclass_->getName());
    401                             CommandExecutor::getInstance().state_ = CS_Error;
     427                            CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchFunctionnameIn") + " " + CommandExecutor::getEvaluation().functionclass_->getName());
     428                            CommandExecutor::getEvaluation().state_ = CS_Error;
    402429                            return;
    403430                        }
     
    405432                        {
    406433                            // Argument 2 seems to be a valid functionname: Get the parameters
    407                             CommandExecutor::getInstance().state_ = CS_Function_Params;
     434                            CommandExecutor::getEvaluation().state_ = CS_Function_Params;
    408435                            CommandExecutor::parse(command, false);
    409436                            return;
     
    414441                        // There is no finished second argument
    415442                        // Check if there's already a perfect match
    416                         if (CommandExecutor::getInstance().tokens_.size() >= 2)
    417                         {
    418                             CommandExecutor::getInstance().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getInstance().functionclass_);
    419                             if (CommandExecutor::getInstance().function_ != 0)
     443                        if (CommandExecutor::getEvaluation().tokens_.size() >= 2)
     444                        {
     445                            CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
     446                            if (CommandExecutor::getEvaluation().function_ != 0)
    420447                            {
    421448                                // There is a perfect match: Add a whitespace and continue parsing
    422                                 CommandExecutor::getInstance().state_ = CS_Function_Params;
     449                                CommandExecutor::getEvaluation().state_ = CS_Function_Params;
    423450                                CommandExecutor::parse(command + " ", false);
    424451                                return;
     
    427454
    428455                        // No perfect match: Create the list of all possible functions and return
    429                         CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getToken(1), CommandExecutor::getInstance().functionclass_);
     456                        CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
    430457                        return;
    431458                    }
     
    433460                else
    434461                {
    435                     CommandExecutor::getInstance().state_ = CS_Error;
     462                    CommandExecutor::getEvaluation().state_ = CS_Error;
    436463                    return;
    437464                }
    438465                break;
    439466            case CS_Function_Params:
    440                 if ((CommandExecutor::getInstance().functionclass_ != 0) && (CommandExecutor::getInstance().function_ != 0))
     467                if ((CommandExecutor::getEvaluation().functionclass_ != 0) && (CommandExecutor::getEvaluation().function_ != 0))
    441468                {
    442469                    // Valid command
    443470                    // Check if there are enough parameters
    444                     if (CommandExecutor::enoughParametersGiven(2, CommandExecutor::getInstance().function_))
    445                     {
    446                         CommandExecutor::getInstance().state_ = CS_Function_Finished;
     471                    if (CommandExecutor::enoughParametersGiven(2, CommandExecutor::getEvaluation().function_))
     472                    {
     473                        CommandExecutor::getEvaluation().state_ = CS_Function_Finished;
    447474                        return;
    448475                    }
     
    451478                {
    452479                    // Something is wrong
    453                     CommandExecutor::getInstance().state_ = CS_Error;
     480                    CommandExecutor::getEvaluation().state_ = CS_Error;
    454481                    return;
    455482                }
     
    463490                    {
    464491                        // There is a second argument: Check if it's a valid classname
    465                         CommandExecutor::getInstance().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));
    466                         if (CommandExecutor::getInstance().configvalueclass_ == 0)
     492                        CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));
     493                        if (CommandExecutor::getEvaluation().configvalueclass_ == 0)
    467494                        {
    468495                            // Argument 2 seems to be wrong
    469496                            AddLanguageEntry("CommandExecutor::NoSuchClassWithConfigValues", "No such class with config values");
    470                             CommandExecutor::getInstance().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchClassWithConfigValues"));
    471                             CommandExecutor::getInstance().state_ = CS_Error;
     497                            CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchClassWithConfigValues"));
     498                            CommandExecutor::getEvaluation().state_ = CS_Error;
    472499                            return;
    473500                        }
     
    475502                        {
    476503                            // Argument 2 seems to be a valid classname: Search for possible config values
    477                             CommandExecutor::getInstance().state_ = CS_ConfigValue;
     504                            CommandExecutor::getEvaluation().state_ = CS_ConfigValue;
    478505                            CommandExecutor::parse(command, false);
    479506                            return;
     
    484511                        // There's no finished second argument
    485512                        // Check if there's already a perfect match
    486                         if (CommandExecutor::getInstance().tokens_.size() >= 2)
    487                         {
    488                             CommandExecutor::getInstance().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));
    489                             if (CommandExecutor::getInstance().configvalueclass_ != 0)
     513                        if (CommandExecutor::getEvaluation().tokens_.size() >= 2)
     514                        {
     515                            CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));
     516                            if (CommandExecutor::getEvaluation().configvalueclass_ != 0)
    490517                            {
    491518                                // There is a perfect match: Add a whitespace and continue parsing
    492                                 CommandExecutor::getInstance().state_ = CS_ConfigValue;
     519                                CommandExecutor::getEvaluation().state_ = CS_ConfigValue;
    493520                                CommandExecutor::parse(command + " ", false);
    494521                                return;
     
    504531                {
    505532                    // Something is wrong
    506                     CommandExecutor::getInstance().state_ = CS_Error;
     533                    CommandExecutor::getEvaluation().state_ = CS_Error;
    507534                    return;
    508535                }
    509536                break;
    510537            case CS_ConfigValue:
    511                 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getInstance().configvalueclass_ != 0))
     538                if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getEvaluation().configvalueclass_ != 0))
    512539                {
    513540                    // Check if there is a third argument
     
    515542                    {
    516543                        // There is a third argument: Check if it's a valid config value
    517                         CommandExecutor::getInstance().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getInstance().configvalueclass_);
    518                         if (CommandExecutor::getInstance().configvalue_ == 0)
     544                        CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
     545                        if (CommandExecutor::getEvaluation().configvalue_ == 0)
    519546                        {
    520547                            // Argument 3 seems to be wrong
    521548                            AddLanguageEntry("CommandExecutor::NoSuchConfigValueIn", "No such config value in");
    522                             CommandExecutor::getInstance().errorMessage_ = (CommandExecutor::getToken(2) + ": " + GetLocalisation("CommandExecutor::NoSuchConfigValueIn") + " " + CommandExecutor::getInstance().configvalueclass_->getName());
    523                             CommandExecutor::getInstance().state_ = CS_Error;
     549                            CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(2) + ": " + GetLocalisation("CommandExecutor::NoSuchConfigValueIn") + " " + CommandExecutor::getEvaluation().configvalueclass_->getName());
     550                            CommandExecutor::getEvaluation().state_ = CS_Error;
    524551                            return;
    525552                        }
     
    527554                        {
    528555                            // Argument 3 seems to be a valid config value: Get the type
    529                             CommandExecutor::getInstance().state_ = CS_ConfigValueType;
     556                            CommandExecutor::getEvaluation().state_ = CS_ConfigValueType;
    530557                            CommandExecutor::parse(command, false);
    531558                            return;
     
    536563                        // There is no finished third argument
    537564                        // Check if there's already a perfect match
    538                         if (CommandExecutor::getInstance().tokens_.size() >= 3)
    539                         {
    540                             CommandExecutor::getInstance().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getInstance().configvalueclass_);
    541                             if (CommandExecutor::getInstance().configvalueclass_ != 0)
     565                        if (CommandExecutor::getEvaluation().tokens_.size() >= 3)
     566                        {
     567                            CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
     568                            if (CommandExecutor::getEvaluation().configvalueclass_ != 0)
    542569                            {
    543570                                // There is a perfect match: Add a whitespace and continue parsing
    544                                 CommandExecutor::getInstance().state_ = CS_ConfigValueType;
     571                                CommandExecutor::getEvaluation().state_ = CS_ConfigValueType;
    545572                                CommandExecutor::parse(command + " ", false);
    546573                                return;
     
    549576
    550577                        // No perfect match: Create the list of all possible config values
    551                         CommandExecutor::createListOfPossibleConfigValues(CommandExecutor::getToken(2), CommandExecutor::getInstance().configvalueclass_);
     578                        CommandExecutor::createListOfPossibleConfigValues(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
    552579                        return;
    553580                    }
     
    556583                {
    557584                    // Something is wrong
    558                     CommandExecutor::getInstance().state_ = CS_Error;
     585                    CommandExecutor::getEvaluation().state_ = CS_Error;
    559586                    return;
    560587                }
    561588                break;
    562589            case CS_ConfigValueType:
    563                 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getInstance().configvalueclass_ != 0) && (CommandExecutor::getInstance().configvalue_ != 0))
     590                if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getEvaluation().configvalueclass_ != 0) && (CommandExecutor::getEvaluation().configvalue_ != 0))
    564591                {
    565592                    // Valid command
    566593                    // Check if there are enough parameters
    567                     if (CommandExecutor::getInstance().tokens_.size() >= 4)
    568                     {
    569                         CommandExecutor::getInstance().state_ = CS_ConfigValueFinished;
     594                    if (CommandExecutor::getEvaluation().tokens_.size() >= 4)
     595                    {
     596                        CommandExecutor::getEvaluation().state_ = CS_ConfigValueFinished;
    570597                        return;
    571598                    }
     
    574601                {
    575602                    // Something is wrong
    576                     CommandExecutor::getInstance().state_ = CS_Error;
     603                    CommandExecutor::getEvaluation().state_ = CS_Error;
    577604                    return;
    578605                }
     
    586613                {
    587614                    // Something is wrong
    588                     CommandExecutor::getInstance().state_ = CS_Error;
     615                    CommandExecutor::getEvaluation().state_ = CS_Error;
    589616                    return;
    590617                }
     
    595622                    // Valid command
    596623                    // Check if there are enough parameters
    597                     if (CommandExecutor::getInstance().tokens_.size() >= 3)
    598                     {
    599                         CommandExecutor::getInstance().state_ = CS_KeybindFinished;
     624                    if (CommandExecutor::getEvaluation().tokens_.size() >= 3)
     625                    {
     626                        CommandExecutor::getEvaluation().state_ = CS_KeybindFinished;
    600627                        return;
    601628                    }
     
    605632                {
    606633                    // Something is wrong
    607                     CommandExecutor::getInstance().state_ = CS_Error;
     634                    CommandExecutor::getEvaluation().state_ = CS_Error;
    608635                    return;
    609636                }
     
    629656    void CommandExecutor::initialize()
    630657    {
    631         CommandExecutor::getInstance().listOfPossibleFunctionClasses_.clear();
    632         CommandExecutor::getInstance().listOfPossibleShortcuts_.clear();
    633         CommandExecutor::getInstance().listOfPossibleFunctions_.clear();
    634         CommandExecutor::getInstance().listOfPossibleConfigValueClasses_.clear();
    635         CommandExecutor::getInstance().listOfPossibleConfigValues_.clear();
    636         CommandExecutor::getInstance().listOfPossibleKeys_.clear();
    637 
    638         CommandExecutor::getInstance().functionclass_ = 0;
    639         CommandExecutor::getInstance().configvalueclass_ = 0;
    640         CommandExecutor::getInstance().shortcut_ = 0;
    641         CommandExecutor::getInstance().function_ = 0;
    642         CommandExecutor::getInstance().configvalue_ = 0;
    643         CommandExecutor::getInstance().key_ = 0;
    644 
    645         CommandExecutor::getInstance().errorMessage_ = "";
    646         CommandExecutor::getInstance().state_ = CS_Empty;
     658        CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.clear();
     659        CommandExecutor::getEvaluation().listOfPossibleShortcuts_.clear();
     660        CommandExecutor::getEvaluation().listOfPossibleFunctions_.clear();
     661        CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.clear();
     662        CommandExecutor::getEvaluation().listOfPossibleConfigValues_.clear();
     663        CommandExecutor::getEvaluation().listOfPossibleKeys_.clear();
     664
     665        CommandExecutor::getEvaluation().functionclass_ = 0;
     666        CommandExecutor::getEvaluation().configvalueclass_ = 0;
     667        CommandExecutor::getEvaluation().shortcut_ = 0;
     668        CommandExecutor::getEvaluation().function_ = 0;
     669        CommandExecutor::getEvaluation().configvalue_ = 0;
     670        CommandExecutor::getEvaluation().key_ = 0;
     671
     672        CommandExecutor::getEvaluation().errorMessage_ = "";
     673        CommandExecutor::getEvaluation().state_ = CS_Empty;
    647674    }
    648675
     
    651678        // Because we added a cursor we have +1 arguments
    652679        // There are num arguments given if there are at least num arguments + one cursor
    653         return (CommandExecutor::getInstance().tokens_.size() >= (num + 1));
     680        return (CommandExecutor::getEvaluation().tokens_.size() >= (num + 1));
    654681    }
    655682
     
    657684    {
    658685        // Because we added a cursor we have +1 arguments
    659         if (CommandExecutor::getInstance().tokens_.size() >= 1)
    660             return (CommandExecutor::getInstance().tokens_.size() - 1);
     686        if (CommandExecutor::getEvaluation().tokens_.size() >= 1)
     687            return (CommandExecutor::getEvaluation().tokens_.size() - 1);
    661688        else
    662689            return 0;
     
    665692    std::string CommandExecutor::getToken(unsigned int index)
    666693    {
    667         if ((index >= 0) && (index < (CommandExecutor::getInstance().tokens_.size() - 1)))
    668             return CommandExecutor::getInstance().tokens_[index];
    669         else if (index == (CommandExecutor::getInstance().tokens_.size() - 1))
    670             return CommandExecutor::getInstance().tokens_[index].substr(0, CommandExecutor::getInstance().tokens_[index].size() - 1);
     694        if ((index >= 0) && (index < (CommandExecutor::getEvaluation().tokens_.size() - 1)))
     695            return CommandExecutor::getEvaluation().tokens_[index];
     696        else if (index == (CommandExecutor::getEvaluation().tokens_.size() - 1))
     697            return CommandExecutor::getEvaluation().tokens_[index].substr(0, CommandExecutor::getEvaluation().tokens_[index].size() - 1);
    671698        else
    672699            return "";
     
    683710                break;
    684711        }
    685         return (CommandExecutor::getInstance().tokens_.size() >= neededParams);
     712        return (CommandExecutor::getEvaluation().tokens_.size() >= neededParams);
    686713    }
    687714
     
    694721                if ((*it).first.find(getLowercase(fragment)) == 0)
    695722                {
    696                     CommandExecutor::getInstance().listOfPossibleFunctionClasses_.push_back(&(*it).first);
     723                    CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.push_back(&(*it).first);
    697724                }
    698725            }
    699726        }
    700727
    701         CommandExecutor::getInstance().listOfPossibleFunctionClasses_.sort(CommandExecutor::compareStringsInList);
     728        CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.sort(CommandExecutor::compareStringsInList);
    702729    }
    703730
     
    708735            if ((*it).first.find(getLowercase(fragment)) == 0)
    709736            {
    710                 CommandExecutor::getInstance().listOfPossibleShortcuts_.push_back(&(*it).first);
     737                CommandExecutor::getEvaluation().listOfPossibleShortcuts_.push_back(&(*it).first);
    711738            }
    712739        }
    713740
    714         CommandExecutor::getInstance().listOfPossibleShortcuts_.sort(CommandExecutor::compareStringsInList);
     741        CommandExecutor::getEvaluation().listOfPossibleShortcuts_.sort(CommandExecutor::compareStringsInList);
    715742    }
    716743
     
    721748            if ((*it).first.find(getLowercase(fragment)) == 0)
    722749            {
    723                 CommandExecutor::getInstance().listOfPossibleFunctions_.push_back(&(*it).first);
     750                CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(&(*it).first);
    724751            }
    725752        }
    726753
    727         CommandExecutor::getInstance().listOfPossibleFunctions_.sort(CommandExecutor::compareStringsInList);
     754        CommandExecutor::getEvaluation().listOfPossibleFunctions_.sort(CommandExecutor::compareStringsInList);
    728755    }
    729756
     
    736763                if ((*it).first.find(getLowercase(fragment)) == 0)
    737764                {
    738                     CommandExecutor::getInstance().listOfPossibleConfigValueClasses_.push_back(&(*it).first);
     765                    CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.push_back(&(*it).first);
    739766                }
    740767            }
    741768        }
    742769
    743         CommandExecutor::getInstance().listOfPossibleConfigValueClasses_.sort(CommandExecutor::compareStringsInList);
     770        CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.sort(CommandExecutor::compareStringsInList);
    744771    }
    745772
     
    750777            if ((*it).first.find(getLowercase(fragment)) == 0)
    751778            {
    752                 CommandExecutor::getInstance().listOfPossibleConfigValues_.push_back(&(*it).first);
     779                CommandExecutor::getEvaluation().listOfPossibleConfigValues_.push_back(&(*it).first);
    753780            }
    754781        }
    755782
    756         CommandExecutor::getInstance().listOfPossibleConfigValues_.sort(CommandExecutor::compareStringsInList);
     783        CommandExecutor::getEvaluation().listOfPossibleConfigValues_.sort(CommandExecutor::compareStringsInList);
    757784    }
    758785
     
    761788        // todo
    762789
    763         CommandExecutor::getInstance().listOfPossibleKeys_.sort(CommandExecutor::compareStringsInList);
     790        CommandExecutor::getEvaluation().listOfPossibleKeys_.sort(CommandExecutor::compareStringsInList);
    764791    }
    765792
  • code/branches/core2/src/orxonox/core/CommandExecutor.h

    r951 r952  
    4040namespace orxonox
    4141{
     42    enum CommandState
     43    {
     44        CS_Empty,
     45        CS_FunctionClass_Or_Shortcut_Or_Keyword,
     46        CS_Shortcut_Params,
     47        CS_Shortcut_Finished,
     48        CS_Function,
     49        CS_Function_Params,
     50        CS_Function_Finished,
     51        CS_ConfigValueClass,
     52        CS_ConfigValue,
     53        CS_ConfigValueType,
     54        CS_ConfigValueFinished,
     55        CS_KeybindKey,
     56        CS_KeybindCommand,
     57        CS_KeybindFinished,
     58        CS_Error
     59    };
     60
     61    class _CoreExport CommandEvaluation
     62    {
     63        public:
     64            std::string processedCommand_;
     65            SubString tokens_;
     66            std::list<const std::string*> listOfPossibleFunctionClasses_;
     67            std::list<const std::string*> listOfPossibleShortcuts_;
     68            std::list<const std::string*> listOfPossibleFunctions_;
     69            std::list<const std::string*> listOfPossibleConfigValueClasses_;
     70            std::list<const std::string*> listOfPossibleConfigValues_;
     71            std::list<const std::string*> listOfPossibleKeys_;
     72
     73            Identifier* functionclass_;
     74            Identifier* configvalueclass_;
     75            ExecutorStatic* shortcut_;
     76            ExecutorStatic* function_;
     77            ConfigValueContainer* configvalue_;
     78            ConfigValueContainer* key_;
     79
     80            std::string errorMessage_;
     81            CommandState state_;
     82    };
     83
    4284    class _CoreExport CommandExecutor
    4385    {
    44         enum CommandState
    45         {
    46             CS_Empty,
    47             CS_FunctionClass_Or_Shortcut_Or_Keyword,
    48             CS_Shortcut_Params,
    49             CS_Shortcut_Finished,
    50             CS_Function,
    51             CS_Function_Params,
    52             CS_Function_Finished,
    53             CS_ConfigValueClass,
    54             CS_ConfigValue,
    55             CS_ConfigValueType,
    56             CS_ConfigValueFinished,
    57             CS_KeybindKey,
    58             CS_KeybindCommand,
    59             CS_KeybindFinished,
    60             CS_Error
    61         };
    62 
    6386        public:
    6487            static bool execute(const std::string& command);
     88            static bool execute(const CommandEvaluation& evaluation);
     89
    6590            static std::string complete(const std::string& command);
     91            static std::string complete(const CommandEvaluation& evaluation);
     92
    6693            static std::string hint(const std::string& command);
     94            static std::string hint(const CommandEvaluation& evaluation);
     95
     96            static const CommandEvaluation& evaluate(const std::string& command);
    6797
    6898            static bool addConsoleCommandShortcut(ExecutorStatic* executor);
     
    90120
    91121            static CommandExecutor& getInstance();
     122            static CommandEvaluation& getEvaluation();
    92123
    93124            static void parse(const std::string& command, bool bInitialize = true);
     
    123154            static ConfigValueContainer* getContainerOfPossibleKey(const std::string& name);
    124155
    125             std::string lastProcessedCommand_;
    126             SubString tokens_;
    127             std::list<const std::string*> listOfPossibleFunctionClasses_;
    128             std::list<const std::string*> listOfPossibleShortcuts_;
    129             std::list<const std::string*> listOfPossibleFunctions_;
    130             std::list<const std::string*> listOfPossibleConfigValueClasses_;
    131             std::list<const std::string*> listOfPossibleConfigValues_;
    132             std::list<const std::string*> listOfPossibleKeys_;
    133 
    134             Identifier* functionclass_;
    135             Identifier* configvalueclass_;
    136             ExecutorStatic* shortcut_;
    137             ExecutorStatic* function_;
    138             ConfigValueContainer* configvalue_;
    139             ConfigValueContainer* key_;
    140 
    141             std::string errorMessage_;
    142             CommandState state_;
     156            CommandEvaluation evaluation_;
    143157
    144158            std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_;
  • code/branches/core2/src/orxonox/core/CorePrereqs.h

    r947 r952  
    9191  class ClassTreeMaskIterator;
    9292  class ClassTreeMaskNode;
     93  class CommandEvaluation;
    9394  class CommandExecutor;
    9495  class ConfigValueContainer;
     
    106107  class Identifier;
    107108  class IdentifierDistributor;
     109  class InputBuffer;
     110  class InputBufferListener;
    108111  template <class T>
    109112  class Iterator;
     
    123126  class OrxonoxClass;
    124127  class OutputHandler;
     128  class Shell;
    125129  template <class T>
    126130  class SubclassIdentifier;
Note: See TracChangeset for help on using the changeset viewer.