[Orxonox-commit 2514] r7221 - code/branches/consolecommands3/src/libraries/core/command

landauf at orxonox.net landauf at orxonox.net
Thu Aug 26 02:06:16 CEST 2010


Author: landauf
Date: 2010-08-26 02:06:16 +0200 (Thu, 26 Aug 2010)
New Revision: 7221

Modified:
   code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc
   code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h
   code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc
   code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h
   code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc
   code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h
Log:
adapted CommandExecutor and CommandEvaluation to make it compile again, but it doesn't run yet. ready for refactoring.

Modified: code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc	2010-08-25 22:29:33 UTC (rev 7220)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc	2010-08-26 00:06:16 UTC (rev 7221)
@@ -66,11 +66,6 @@
         this->state_ = CommandState::Empty;
     }
 
-    bool CommandEvaluation::isValid() const
-    {
-        return (this->function_);
-    }
-
     bool CommandEvaluation::execute() const
     {
         bool success;
@@ -83,7 +78,7 @@
         if (success)
             *success = false;
 
-        if (!this->isValid())
+        if (!this->function_ || !this->function_->isActive())
             return MT_Type::Null;
 
         if (this->bEvaluatedParams_ && this->function_)
@@ -91,7 +86,7 @@
             if (success)
                 *success = true;
             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;
-            return (*this->function_)(this->param_[0], this->param_[1], this->param_[2], this->param_[3], this->param_[4]);
+            return (*this->function_->getExecutor())(this->param_[0], this->param_[1], this->param_[2], this->param_[3], this->param_[4]);
         }
 
         if (!this->bCommandChanged_ || nocaseCmp(removeTrailingWhitespaces(this->command_), removeTrailingWhitespaces(this->originalCommand_)) == 0)
@@ -100,9 +95,9 @@
 
             unsigned int startindex = this->getStartindex();
             if (this->commandTokens_.size() > startindex)
-                return this->function_->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter()), success);
+                return this->function_->getExecutor()->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter()), success);
             else
-                return this->function_->parse(removeSlashes(this->additionalParameter_), success);
+                return this->function_->getExecutor()->parse(removeSlashes(this->additionalParameter_), success);
         }
 
         return MT_Type::Null;
@@ -121,7 +116,7 @@
                 case CommandState::ShortcutOrIdentifier:
                     if (this->function_)
                     {
-                        if (this->function_->getParamCount() == 0)
+                        if (this->function_->getExecutor()->getParamCount() == 0)
                             return (this->command_ = this->function_->getName());
                         else
                             return (this->command_ = this->function_->getName() + ' ');
@@ -132,7 +127,7 @@
                 case CommandState::Function:
                     if (this->function_)
                     {
-                        if (this->function_->getParamCount() == 0)
+                        if (this->function_->getExecutor()->getParamCount() == 0)
                             return (this->command_ = this->functionclass_->getName() + ' ' + this->function_->getName());
                         else
                             return (this->command_ = this->functionclass_->getName() + ' ' + this->function_->getName() + ' ');
@@ -152,7 +147,7 @@
                     if (!this->possibleArgument_.empty())
                     {
                         this->argument_ = this->possibleArgument_;
-                        if (this->function_->getParamCount() > (maxIndex + 1 - this->getStartindex()))
+                        if (this->function_->getExecutor()->getParamCount() > (maxIndex + 1 - this->getStartindex()))
                             whitespace = " ";
                     }
 
@@ -212,19 +207,19 @@
         for (unsigned int i = 0; i < MAX_FUNCTOR_ARGUMENTS; i++)
             this->param_[i] = MT_Type::Null;
 
-        if (!this->isValid())
+        if (!this->function_)
             return;
 
         unsigned int startindex = this->getStartindex();
 
         if (this->commandTokens_.size() <= startindex)
         {
-            if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " "))
+            if (this->function_->getBaseExecutor()->evaluate(this->getAdditionalParameter(), this->param_, " "))
                 this->bEvaluatedParams_ = true;
         }
         else if (this->commandTokens_.size() > startindex)
         {
-            if (this->function_->evaluate(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter(), this->param_, " "))
+            if (this->function_->getBaseExecutor()->evaluate(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter(), this->param_, " "))
                 this->bEvaluatedParams_ = true;
         }
     }
@@ -279,26 +274,26 @@
         return output;
     }
 
-    std::string CommandEvaluation::dump(const ConsoleCommand* command)
+    std::string CommandEvaluation::dump(const _ConsoleCommand* command)
     {
         std::string output = command->getName();
-        if (command->getParamCount() > 0)
+        if (command->getExecutor()->getParamCount() > 0)
             output += ": ";
 
-        for (unsigned int i = 0; i < command->getParamCount(); i++)
+        for (unsigned int i = 0; i < command->getExecutor()->getParamCount(); i++)
         {
             if (i != 0)
                 output += ' ';
 
-            if (command->defaultValueSet(i))
+            if (command->getExecutor()->defaultValueSet(i))
                 output += '[';
             else
                 output += '{';
 
-            output += command->getTypenameParam(i);
+            output += command->getExecutor()->getTypenameParam(i);
 
-            if (command->defaultValueSet(i))
-                output += '=' + command->getDefaultValue(i).getString() + ']';
+            if (command->getExecutor()->defaultValueSet(i))
+                output += '=' + command->getExecutor()->getDefaultValue(i).getString() + ']';
             else
                 output += '}';
         }

Modified: code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h	2010-08-25 22:29:33 UTC (rev 7220)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h	2010-08-26 00:06:16 UTC (rev 7221)
@@ -71,9 +71,10 @@
             std::string hint() const;
             void evaluateParams();
 
-            bool isValid() const;
+            bool isValid() const
+                { return this->function_; }
 
-            inline ConsoleCommand* getConsoleCommand() const
+            inline _ConsoleCommand* getConsoleCommand() const
                 { return this->function_; }
             inline const std::string& getOriginalCommand() const
                 { return this->originalCommand_; }
@@ -92,7 +93,7 @@
             unsigned int getStartindex() const;
             static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list);
             static std::string dump(const ArgumentCompletionList& list);
-            static std::string dump(const ConsoleCommand* command);
+            static std::string dump(const _ConsoleCommand* command);
 
 
             bool bNewCommand_;
@@ -108,7 +109,7 @@
             ArgumentCompletionList listOfPossibleArguments_;
 
             Identifier* functionclass_;
-            ConsoleCommand* function_;
+            _ConsoleCommand* function_;
             std::string possibleArgument_;
             std::string argument_;
 

Modified: code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc	2010-08-25 22:29:33 UTC (rev 7220)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc	2010-08-26 00:06:16 UTC (rev 7221)
@@ -48,11 +48,6 @@
         return CommandExecutor::getInstance().evaluation_;
     }
 
-    const CommandEvaluation& CommandExecutor::getLastEvaluation()
-    {
-        return CommandExecutor::getInstance().evaluation_;
-    }
-
     bool CommandExecutor::execute(const std::string& command, bool useTcl)
     {
         if (useTcl)
@@ -215,7 +210,7 @@
                         CommandExecutor::getEvaluation().state_ = CommandState::ParamPreparation;
                         CommandExecutor::getEvaluation().functionclass_ = 0;
                         CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().function_->getName();
-                        if (CommandExecutor::getEvaluation().function_->getParamCount() > 0)
+                        if (CommandExecutor::getEvaluation().function_->getExecutor()->getParamCount() > 0)
                         {
                             CommandExecutor::getEvaluation().command_ += ' ';
                             CommandExecutor::getEvaluation().bCommandChanged_ = true;
@@ -302,7 +297,7 @@
                             }
                             CommandExecutor::getEvaluation().state_ = CommandState::ParamPreparation;
                             CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + ' ' + CommandExecutor::getEvaluation().function_->getName();
-                            if (CommandExecutor::getEvaluation().function_->getParamCount() > 0)
+                            if (CommandExecutor::getEvaluation().function_->getExecutor()->getParamCount() > 0)
                             {
                                 CommandExecutor::getEvaluation().command_ += ' ';
                                 CommandExecutor::getEvaluation().bCommandChanged_ = true;
@@ -334,7 +329,7 @@
             }
             case CommandState::ParamPreparation:
             {
-                if (CommandExecutor::getEvaluation().function_->getParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_))
+                if (CommandExecutor::getEvaluation().function_->getExecutor()->getParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_))
                 {
                     CommandExecutor::getEvaluation().state_ = CommandState::Finished;
                     return;
@@ -417,12 +412,12 @@
             return CommandExecutor::getEvaluation().commandTokens_.size();
     }
 
-    bool CommandExecutor::enoughArgumentsGiven(ConsoleCommand* command)
+    bool CommandExecutor::enoughArgumentsGiven(_ConsoleCommand* command)
     {
         if (CommandExecutor::getEvaluation().functionclass_)
-            return (CommandExecutor::argumentsGiven() > (2 + command->getParamCount()));
+            return (CommandExecutor::argumentsGiven() > (2 + command->getExecutor()->getParamCount()));
         else
-            return (CommandExecutor::argumentsGiven() > (1 + command->getParamCount()));
+            return (CommandExecutor::argumentsGiven() > (1 + command->getExecutor()->getParamCount()));
     }
 
     const std::string& CommandExecutor::getArgument(unsigned int index)
@@ -440,34 +435,39 @@
 
     void CommandExecutor::createListOfPossibleIdentifiers(const std::string& fragment)
     {
+/*
         CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.clear();
         const std::string& lowercase = getLowercase(fragment);
         for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMapBegin(); it != Identifier::getLowercaseStringIdentifierMapEnd(); ++it)
             if (it->second->hasConsoleCommands())
                 if (it->first.find(lowercase) == 0 || fragment.empty())
                     CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.push_back(std::pair<const std::string*, const std::string*>(&it->first, &it->second->getName()));
+*/
     }
 
     void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier)
     {
+/*
         CommandExecutor::getEvaluation().listOfPossibleFunctions_.clear();
         const std::string& lowercase = getLowercase(fragment);
         if (!identifier)
         {
-            for (std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
+            for (std::map<std::string, _ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
                 if (it->first.find(lowercase) == 0 || fragment.empty())
                     CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&it->first, &it->second->getName()));
         }
         else
         {
-            for (std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
+            for (std::map<std::string, _ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
                 if (it->first.find(lowercase) == 0 || fragment.empty())
                     CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&it->first, &it->second->getName()));
         }
+*/
     }
 
-    void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param)
+    void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, _ConsoleCommand* command, unsigned int param)
     {
+/*
         CommandExecutor::createArgumentCompletionList(command, param);
 
         CommandExecutor::getEvaluation().listOfPossibleArguments_.clear();
@@ -485,38 +485,43 @@
                     CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(*it);
             }
         }
+*/
     }
 
     Identifier* CommandExecutor::getPossibleIdentifier(const std::string& name)
     {
+/*
         const std::string& lowercase = getLowercase(name);
         std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMap().find(lowercase);
         if ((it != Identifier::getLowercaseStringIdentifierMapEnd()) && it->second->hasConsoleCommands())
             return it->second;
-
+*/
         return 0;
     }
 
-    ConsoleCommand* CommandExecutor::getPossibleCommand(const std::string& name, Identifier* identifier)
+    _ConsoleCommand* CommandExecutor::getPossibleCommand(const std::string& name, Identifier* identifier)
     {
+/*
         const std::string& lowercase = getLowercase(name);
         if (!identifier)
         {
-            std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(lowercase);
+            std::map<std::string, _ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(lowercase);
             if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd())
                 return it->second;
         }
         else
         {
-            std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(lowercase);
+            std::map<std::string, _ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(lowercase);
             if (it != identifier->getLowercaseConsoleCommandMapEnd())
                 return it->second;
         }
+*/
         return 0;
     }
 
-    const std::string& CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param)
+    const std::string& CommandExecutor::getPossibleArgument(const std::string& name, _ConsoleCommand* command, unsigned int param)
     {
+/*
         CommandExecutor::createArgumentCompletionList(command, param);
 
         const std::string& lowercase = getLowercase(name);
@@ -533,12 +538,13 @@
                     return it->getString();
             }
         }
-
+*/
         return BLANKSTRING;
     }
 
-    void CommandExecutor::createArgumentCompletionList(ConsoleCommand* command, unsigned int param)
+    void CommandExecutor::createArgumentCompletionList(_ConsoleCommand* command, unsigned int param)
     {
+/*
         std::string params[5];
 
         unsigned int index = 0;
@@ -553,6 +559,7 @@
         }
 
         command->createArgumentCompletionList(param, params[0], params[1], params[2], params[3], params[4]);
+*/
     }
 
     std::string CommandExecutor::getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list)
@@ -642,11 +649,4 @@
             return output;
         }
     }
-
-    void CommandExecutor::destroyExternalCommands()
-    {
-        for (std::set<ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandExternals_.begin();
-            it != CommandExecutor::getInstance().consoleCommandExternals_.end(); ++it)
-            delete *it;
-    }
 }

Modified: code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h	2010-08-25 22:29:33 UTC (rev 7220)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h	2010-08-26 00:06:16 UTC (rev 7221)
@@ -54,7 +54,6 @@
             static std::string hint(const std::string& command);
 
             static CommandEvaluation evaluate(const std::string& command);
-            static const CommandEvaluation& getLastEvaluation();
 
         private:
             CommandExecutor() {}
@@ -69,19 +68,19 @@
 
             static unsigned int argumentsFinished();
             static unsigned int argumentsGiven();
-            static bool enoughArgumentsGiven(ConsoleCommand* command);
+            static bool enoughArgumentsGiven(_ConsoleCommand* command);
             static const std::string& getArgument(unsigned int index);
             static const std::string& getLastArgument();
 
             static void createListOfPossibleIdentifiers(const std::string& fragment);
             static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier = 0);
-            static void createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param);
+            static void createListOfPossibleArguments(const std::string& fragment, _ConsoleCommand* command, unsigned int param);
 
             static Identifier* getPossibleIdentifier(const std::string& name);
-            static ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0);
-            static const std::string& getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param);
+            static _ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0);
+            static const std::string& getPossibleArgument(const std::string& name, _ConsoleCommand* command, unsigned int param);
 
-            static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param);
+            static void createArgumentCompletionList(_ConsoleCommand* command, unsigned int param);
             static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);
             static std::string getCommonBegin(const ArgumentCompletionList& list);
 

Modified: code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc	2010-08-25 22:29:33 UTC (rev 7220)
+++ code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc	2010-08-26 00:06:16 UTC (rev 7221)
@@ -342,14 +342,6 @@
             return 0;
     }
 
-    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)
-    {
-        if (param < 5 && this->argumentCompleter_[param])
-            this->argumentList_ = (*this->argumentCompleter_[param])(param1, param2, param3, param4, param5);
-        else
-            this->argumentList_.clear();
-    }
-
     _ConsoleCommand& _ConsoleCommand::description(const std::string& description)
     {
         this->description_ = std::string("ConsoleCommandDescription::" + this->baseName_ + "::function");

Modified: code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h	2010-08-25 22:29:33 UTC (rev 7220)
+++ code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h	2010-08-26 00:06:16 UTC (rev 7221)
@@ -267,14 +267,6 @@
             _ConsoleCommand& argumentCompleter(unsigned int param, ArgumentCompleter* completer);
             ArgumentCompleter* getArgumentCompleter(unsigned int param) const;
 
-            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 = "");
-            const ArgumentCompletionList& getArgumentCompletionList() const
-                { return this->argumentList_; }
-            ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const
-                { return this->argumentList_.begin(); }
-            ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const
-                { return this->argumentList_.end(); }
-
             inline _ConsoleCommand& setAsInputCommand()
             {
                 this->keybindMode(KeybindMode::OnHold);
@@ -324,7 +316,6 @@
             std::stack<void*> objectStack_;
 
             ArgumentCompleter* argumentCompleter_[5];
-            ArgumentCompletionList argumentList_;
 
             KeybindMode::Value keybindMode_;
             int inputConfiguredParam_;




More information about the Orxonox-commit mailing list