[Orxonox-commit 2508] r7215 - code/branches/consolecommands3/src/libraries/core/command

landauf at orxonox.net landauf at orxonox.net
Wed Aug 25 17:35:37 CEST 2010


Author: landauf
Date: 2010-08-25 17:35:37 +0200 (Wed, 25 Aug 2010)
New Revision: 7215

Modified:
   code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc
   code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h
Log:
new console command interface now supports all functions of the old implementation

Modified: code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc	2010-08-25 11:04:55 UTC (rev 7214)
+++ code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc	2010-08-25 15:35:37 UTC (rev 7215)
@@ -127,9 +127,21 @@
     _ConsoleCommand::_ConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized)
     {
         this->bActive_ = true;
+        this->bHidden_ = false;
+        this->accessLevel_ = AccessLevel::All;
+
         this->baseName_ = name;
         this->baseExecutor_ = executor;
 
+        this->argumentCompleter_[0] = 0;
+        this->argumentCompleter_[1] = 0;
+        this->argumentCompleter_[2] = 0;
+        this->argumentCompleter_[3] = 0;
+        this->argumentCompleter_[4] = 0;
+
+        this->keybindMode_ = KeybindMode::OnPress;
+        this->inputConfiguredParam_ = -1;
+
         if (bInitialized)
             this->executor_ = executor;
 
@@ -245,7 +257,7 @@
         Command command;
         command.executor_ = this->getExecutor();
         if (command.executor_)
-            command.functor_ = this->getFunctor();
+            command.functor_ = this->getExecutor()->getFunctor();
 
         if (this->setFunction(executor, bForce))
             this->commandStack_.push(command);
@@ -256,7 +268,7 @@
         Command command;
         command.executor_ = this->getExecutor();
         if (command.executor_)
-            command.functor_ = this->getFunctor();
+            command.functor_ = this->getExecutor()->getFunctor();
 
         if (this->setFunction(functor, bForce))
             this->commandStack_.push(command);
@@ -289,11 +301,6 @@
         return this->executor_;
     }
 
-    const FunctorPtr& _ConsoleCommand::getFunctor() const
-    {
-        return this->executor_->getFunctor();
-    }
-
     bool _ConsoleCommand::setObject(void* object)
     {
         if (this->executor_)
@@ -338,6 +345,134 @@
             return 0;
     }
 
+    _ConsoleCommand& _ConsoleCommand::defaultValues(const MultiType& param1)
+    {
+        if (this->executor_)
+            this->executor_->setDefaultValues(param1);
+        else
+            COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl;
+
+        return *this;
+    }
+
+    _ConsoleCommand& _ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2)
+    {
+        if (this->executor_)
+            this->executor_->setDefaultValues(param1, param2);
+        else
+            COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl;
+
+        return *this;
+    }
+
+    _ConsoleCommand& _ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3)
+    {
+        if (this->executor_)
+            this->executor_->setDefaultValues(param1, param2, param3);
+        else
+            COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl;
+
+        return *this;
+    }
+
+    _ConsoleCommand& _ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4)
+    {
+        if (this->executor_)
+            this->executor_->setDefaultValues(param1, param2, param3, param4);
+        else
+            COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl;
+
+        return *this;
+    }
+
+    _ConsoleCommand& _ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)
+    {
+        if (this->executor_)
+            this->executor_->setDefaultValues(param1, param2, param3, param4, param5);
+        else
+            COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl;
+
+        return *this;
+    }
+
+    _ConsoleCommand& _ConsoleCommand::defaultValue(unsigned int index, const MultiType& param)
+    {
+        if (this->executor_)
+            this->executor_->setDefaultValue(index, param);
+        else
+            COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl;
+
+        return *this;
+    }
+
+    _ConsoleCommand& _ConsoleCommand::argumentCompleter(unsigned int param, ArgumentCompleter* completer)
+    {
+        if (param < 5)
+            this->argumentCompleter_[param] = completer;
+        else
+            COUT(2) << "Warning: Couldn't add autocompletion-function for param " << param << " in console command \"" << this->baseName_ << "\": index out of bound." << std::endl;
+
+        return *this;
+    }
+
+    ArgumentCompleter* _ConsoleCommand::getArgumentCompleter(unsigned int param) const
+    {
+        if (param < 5)
+            return this->argumentCompleter_[param];
+        else
+            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");
+        AddLanguageEntry(this->description_, description);
+        return *this;
+    }
+
+    const std::string& _ConsoleCommand::getDescription() const
+    {
+        return GetLocalisation_noerror(this->description_);
+    }
+
+    _ConsoleCommand& _ConsoleCommand::descriptionParam(unsigned int param, const std::string& description)
+    {
+        if (param < MAX_FUNCTOR_ARGUMENTS)
+        {
+            this->descriptionParam_[param] = std::string("ConsoleCommandDescription::" + this->baseName_ + "::param" + multi_cast<std::string>(param));
+            AddLanguageEntry(this->descriptionParam_[param], description);
+        }
+        return *this;
+    }
+
+    const std::string& _ConsoleCommand::getDescriptionParam(unsigned int param) const
+    {
+        if (param < MAX_FUNCTOR_ARGUMENTS)
+            return GetLocalisation_noerror(this->descriptionParam_[param]);
+
+        return this->descriptionParam_[0];
+    }
+
+    _ConsoleCommand& _ConsoleCommand::descriptionReturnvalue(const std::string& description)
+    {
+        this->descriptionReturnvalue_ = std::string("ConsoleCommandDescription::" + this->baseName_ + "::returnvalue");
+        AddLanguageEntry(this->descriptionReturnvalue_, description);
+        return *this;
+    }
+
+    const std::string& _ConsoleCommand::getDescriptionReturnvalue(int param) const
+    {
+        return GetLocalisation_noerror(this->descriptionReturnvalue_);
+    }
+
     /* static */ const _ConsoleCommand* _ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError)
     {
         std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommandMap().find(group);

Modified: code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h	2010-08-25 11:04:55 UTC (rev 7214)
+++ code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h	2010-08-25 15:35:37 UTC (rev 7215)
@@ -191,10 +191,6 @@
     orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = orxonox::_createConsoleCommand(group, name, orxonox::createExecutor(functor), false)
 
 
-#define _ModifyConsoleCommand(...) \
-    orxonox::_ConsoleCommand::getCommand(__VA_ARGS__, true)->getManipulator()
-
-
 namespace orxonox
 {
     class _CoreExport _ConsoleCommand
@@ -207,6 +203,21 @@
             FunctorPtr functor_;
         };
 
+        struct AccessLevel
+        {
+            enum Enum
+            {
+                All,
+                Standalone,
+                Master,
+                Server,
+                Client,
+                Online,
+                Offline,
+                None
+            };
+        };
+
         public:
             struct _ConsoleCommandManipulator
             {
@@ -218,9 +229,9 @@
                         {
                             if (this->command_)
                             {
-                                if (this->command_->getExecutor() && this->command_->getFunctor() && this->command_->getFunctor()->getFullIdentifier() == typeid(F))
+                                if (this->command_->getExecutor() && this->command_->getExecutor()->getFunctor() && this->command_->getExecutor()->getFunctor()->getFullIdentifier() == typeid(F))
                                 {
-                                    FunctorPointer<F>* functor = static_cast<FunctorPointer<F>*>(this->command_->getFunctor().get());
+                                    FunctorPointer<F>* functor = static_cast<FunctorPointer<F>*>(this->command_->getExecutor()->getFunctor().get());
                                     functor->setFunction(function);
                                     return *this;
                                 }
@@ -233,9 +244,9 @@
                         {
                             if (this->command_)
                             {
-                                if (this->command_->getExecutor() && this->command_->getFunctor() && this->command_->getFunctor()->getFullIdentifier() == typeid(F))
+                                if (this->command_->getExecutor() && this->command_->getExecutor()->getFunctor() && this->command_->getExecutor()->getFunctor()->getFullIdentifier() == typeid(F))
                                 {
-                                    FunctorPointer<F, O>* functor = static_cast<FunctorPointer<F, O>*>(this->command_->getFunctor().get());
+                                    FunctorPointer<F, O>* functor = static_cast<FunctorPointer<F, O>*>(this->command_->getExecutor()->getFunctor().get());
                                     functor->setFunction(function);
                                     functor->setObject(object);
                                     return *this;
@@ -270,9 +281,6 @@
                     inline _ConsoleCommandManipulator& popObject()
                         { if (this->command_) { this->command_->popObject(); } return *this; }
 
-                    inline void* getObject() const
-                        { if (this->command_) { return this->command_->getObject(); } else { return 0; } }
-
                     inline _ConsoleCommandManipulator& setActive(bool bActive)
                         { if (this->command_) { this->command_->setActive(bActive); } return *this; }
                     inline _ConsoleCommandManipulator& activate()
@@ -280,11 +288,39 @@
                     inline _ConsoleCommandManipulator& deactivate()
                         { return this->setActive(false); }
 
-                    inline bool isActive() const
-                        { return this->command_ ? this->command_->isActive() : false; }
-                    inline bool exists() const
-                        { return (this->command_ != 0); }
+                    inline _ConsoleCommandManipulator& setHidden(bool bHidden)
+                        { if (this->command_) { this->command_->setHidden(bHidden); } return *this; }
+                    inline _ConsoleCommandManipulator& hide()
+                        { return this->setHidden(true); }
+                    inline _ConsoleCommandManipulator& show()
+                        { return this->setHidden(false); }
 
+                    inline _ConsoleCommandManipulator& defaultValues(const MultiType& param1)
+                        { if (this->command_) { this->command_->defaultValues(param1); } return *this; }
+                    inline _ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2)
+                        { if (this->command_) { this->command_->defaultValues(param1, param2); } return *this; }
+                    inline _ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3)
+                        { if (this->command_) { this->command_->defaultValues(param1, param2, param3); } return *this; }
+                    inline _ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4)
+                        { if (this->command_) { this->command_->defaultValues(param1, param2, param3, param4); } return *this; }
+                    inline _ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)
+                        { if (this->command_) { this->command_->defaultValues(param1, param2, param3, param4, param5); } return *this; }
+                    inline _ConsoleCommandManipulator& defaultValue(unsigned int index, const MultiType& param)
+                        { if (this->command_) { this->command_->defaultValue(index, param); } return *this; }
+
+                    inline _ConsoleCommandManipulator& accessLevel(_ConsoleCommand::AccessLevel::Enum level)
+                        { if (this->command_) { this->command_->accessLevel(level); } return *this; }
+
+                    inline _ConsoleCommandManipulator& argumentCompleter(unsigned int param, ArgumentCompleter* completer)
+                        { if (this->command_) { this->command_->argumentCompleter(param, completer); } return *this; }
+
+                    inline _ConsoleCommandManipulator& setAsInputCommand()
+                        { if (this->command_) { this->command_->setAsInputCommand(); } return *this; }
+                    inline _ConsoleCommandManipulator& keybindMode(KeybindMode::Value mode)
+                        { if (this->command_) { this->command_->keybindMode(mode); } return *this; }
+                    inline _ConsoleCommandManipulator& inputConfiguredParam(int index)
+                        { if (this->command_) { this->command_->inputConfiguredParam(index); } return *this; }
+
                 private:
                     _ConsoleCommand* command_;
             };
@@ -298,29 +334,78 @@
             _ConsoleCommand& addGroup(const std::string& group);
             _ConsoleCommand& addGroup(const std::string& group, const std::string&  name);
 
-            inline void setActive(bool bActive)
-                { this->bActive_ = bActive; }
-            inline void activate()
-                { this->setActive(true); }
-            inline void deactivate()
-                { this->setActive(false); }
+            inline _ConsoleCommand setActive(bool bActive)
+                { this->bActive_ = bActive; return *this; }
+            inline _ConsoleCommand activate()
+                { return this->setActive(true); }
+            inline _ConsoleCommand deactivate()
+                { return this->setActive(false); }
+
+            inline _ConsoleCommand& setHidden(bool bHidden)
+                { this->bHidden_ = bHidden; return *this; }
+            inline _ConsoleCommand& hide()
+                { return this->setHidden(true); }
+            inline _ConsoleCommand& show()
+                { return this->setHidden(false); }
+
             bool isActive() const;
+            bool hasAccess() const;
+            bool isHidden() const;
 
+            _ConsoleCommand& description(const std::string& description);
+            const std::string& getDescription() const;
+
+            _ConsoleCommand& descriptionParam(unsigned int param, const std::string& description);
+            const std::string& getDescriptionParam(unsigned int param) const;
+
+            _ConsoleCommand& descriptionReturnvalue(const std::string& description);
+            const std::string& getDescriptionReturnvalue(int param) const;
+
+            _ConsoleCommand& defaultValues(const MultiType& param1);
+            _ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2);
+            _ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3);
+            _ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4);
+            _ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5);
+            _ConsoleCommand& defaultValue(unsigned int index, const MultiType& param);
+
+            inline _ConsoleCommand& accessLevel(AccessLevel::Enum level)
+                { this->accessLevel_ = level; return *this; }
+            inline AccessLevel::Enum getAccessLevel() const
+                { return this->accessLevel_; }
+
+            _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);
+                this->defaultValue(0, Vector2(0.0f, 0.0f));
+                this->inputConfiguredParam(0);
+                return *this;
+            }
+
+            inline _ConsoleCommand& keybindMode(KeybindMode::Value mode)
+                { this->keybindMode_ = mode; return *this; }
+            inline KeybindMode::Value getKeybindMode() const
+                { return this->keybindMode_; }
+
+            inline _ConsoleCommand& inputConfiguredParam(int index)
+                { this->inputConfiguredParam_ = index; return *this; }
+            inline int getInputConfiguredParam_() const
+                { return this->inputConfiguredParam_; }
+
             inline _ConsoleCommandManipulator getManipulator() const
                 { return this; }
 
-            static inline const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommands()
-                { return _ConsoleCommand::getCommandMap(); }
-
-            static inline const _ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false)
-                { return _ConsoleCommand::getCommand("", name, bPrintError); }
-            static const _ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
-
         private:
-            static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
-            static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command);
-            static void unregisterCommand(_ConsoleCommand* command);
-
             bool headersMatch(const FunctorPtr& functor);
             bool headersMatch(const ExecutorPtr& executor);
 
@@ -339,24 +424,48 @@
             void* getObject() const;
 
             bool bActive_;
-//            const std::type_info& functionHeader_;
+            bool bHidden_;
+            AccessLevel::Enum accessLevel_;
             std::string baseName_;
             ExecutorPtr baseExecutor_;
 
             ExecutorPtr executor_;
             std::stack<Command> commandStack_;
             std::stack<void*> objectStack_;
+
+            ArgumentCompleter* argumentCompleter_[5];
+            ArgumentCompletionList argumentList_;
+
+            KeybindMode::Value keybindMode_;
+            int inputConfiguredParam_;
+
+            LanguageEntryLabel description_;
+            LanguageEntryLabel descriptionReturnvalue_;
+            LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];
+
+        public:
+            static inline const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommands()
+                { return _ConsoleCommand::getCommandMap(); }
+
+            static inline const _ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false)
+                { return _ConsoleCommand::getCommand("", name, bPrintError); }
+            static const _ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
+
+        private:
+            static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
+            static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command);
+            static void unregisterCommand(_ConsoleCommand* command);
     };
 
     inline _ConsoleCommand* _createConsoleCommand(const std::string& name, const ExecutorPtr& executor, bool bInitialized = true)
-    {
-        return new _ConsoleCommand("", name, executor, bInitialized);
-    }
+        { return new _ConsoleCommand("", name, executor, bInitialized); }
+    inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized = true)
+        { return new _ConsoleCommand(group, name, executor, bInitialized); }
 
-    inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized = true)
-    {
-        return new _ConsoleCommand(group, name, executor, bInitialized);
-    }
+    inline _ConsoleCommand::_ConsoleCommandManipulator _ModifyConsoleCommand(const std::string& name)
+        { return _ConsoleCommand::getCommand(name, true); }
+    inline _ConsoleCommand::_ConsoleCommandManipulator _ModifyConsoleCommand(const std::string& group, const std::string& name)
+        { return _ConsoleCommand::getCommand(group, name, true); }
 }
 
 #endif /* _ConsoleCommand_H__ */




More information about the Orxonox-commit mailing list