Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 25, 2010, 5:35:37 PM (14 years ago)
Author:
landauf
Message:

new console command interface now supports all functions of the old implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h

    r7214 r7215  
    192192
    193193
    194 #define _ModifyConsoleCommand(...) \
    195     orxonox::_ConsoleCommand::getCommand(__VA_ARGS__, true)->getManipulator()
    196 
    197 
    198194namespace orxonox
    199195{
     
    208204        };
    209205
     206        struct AccessLevel
     207        {
     208            enum Enum
     209            {
     210                All,
     211                Standalone,
     212                Master,
     213                Server,
     214                Client,
     215                Online,
     216                Offline,
     217                None
     218            };
     219        };
     220
    210221        public:
    211222            struct _ConsoleCommandManipulator
     
    219230                            if (this->command_)
    220231                            {
    221                                 if (this->command_->getExecutor() && this->command_->getFunctor() && this->command_->getFunctor()->getFullIdentifier() == typeid(F))
     232                                if (this->command_->getExecutor() && this->command_->getExecutor()->getFunctor() && this->command_->getExecutor()->getFunctor()->getFullIdentifier() == typeid(F))
    222233                                {
    223                                     FunctorPointer<F>* functor = static_cast<FunctorPointer<F>*>(this->command_->getFunctor().get());
     234                                    FunctorPointer<F>* functor = static_cast<FunctorPointer<F>*>(this->command_->getExecutor()->getFunctor().get());
    224235                                    functor->setFunction(function);
    225236                                    return *this;
     
    234245                            if (this->command_)
    235246                            {
    236                                 if (this->command_->getExecutor() && this->command_->getFunctor() && this->command_->getFunctor()->getFullIdentifier() == typeid(F))
     247                                if (this->command_->getExecutor() && this->command_->getExecutor()->getFunctor() && this->command_->getExecutor()->getFunctor()->getFullIdentifier() == typeid(F))
    237248                                {
    238                                     FunctorPointer<F, O>* functor = static_cast<FunctorPointer<F, O>*>(this->command_->getFunctor().get());
     249                                    FunctorPointer<F, O>* functor = static_cast<FunctorPointer<F, O>*>(this->command_->getExecutor()->getFunctor().get());
    239250                                    functor->setFunction(function);
    240251                                    functor->setObject(object);
     
    271282                        { if (this->command_) { this->command_->popObject(); } return *this; }
    272283
    273                     inline void* getObject() const
    274                         { if (this->command_) { return this->command_->getObject(); } else { return 0; } }
    275 
    276284                    inline _ConsoleCommandManipulator& setActive(bool bActive)
    277285                        { if (this->command_) { this->command_->setActive(bActive); } return *this; }
     
    281289                        { return this->setActive(false); }
    282290
    283                     inline bool isActive() const
    284                         { return this->command_ ? this->command_->isActive() : false; }
    285                     inline bool exists() const
    286                         { return (this->command_ != 0); }
     291                    inline _ConsoleCommandManipulator& setHidden(bool bHidden)
     292                        { if (this->command_) { this->command_->setHidden(bHidden); } return *this; }
     293                    inline _ConsoleCommandManipulator& hide()
     294                        { return this->setHidden(true); }
     295                    inline _ConsoleCommandManipulator& show()
     296                        { return this->setHidden(false); }
     297
     298                    inline _ConsoleCommandManipulator& defaultValues(const MultiType& param1)
     299                        { if (this->command_) { this->command_->defaultValues(param1); } return *this; }
     300                    inline _ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2)
     301                        { if (this->command_) { this->command_->defaultValues(param1, param2); } return *this; }
     302                    inline _ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3)
     303                        { if (this->command_) { this->command_->defaultValues(param1, param2, param3); } return *this; }
     304                    inline _ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4)
     305                        { if (this->command_) { this->command_->defaultValues(param1, param2, param3, param4); } return *this; }
     306                    inline _ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)
     307                        { if (this->command_) { this->command_->defaultValues(param1, param2, param3, param4, param5); } return *this; }
     308                    inline _ConsoleCommandManipulator& defaultValue(unsigned int index, const MultiType& param)
     309                        { if (this->command_) { this->command_->defaultValue(index, param); } return *this; }
     310
     311                    inline _ConsoleCommandManipulator& accessLevel(_ConsoleCommand::AccessLevel::Enum level)
     312                        { if (this->command_) { this->command_->accessLevel(level); } return *this; }
     313
     314                    inline _ConsoleCommandManipulator& argumentCompleter(unsigned int param, ArgumentCompleter* completer)
     315                        { if (this->command_) { this->command_->argumentCompleter(param, completer); } return *this; }
     316
     317                    inline _ConsoleCommandManipulator& setAsInputCommand()
     318                        { if (this->command_) { this->command_->setAsInputCommand(); } return *this; }
     319                    inline _ConsoleCommandManipulator& keybindMode(KeybindMode::Value mode)
     320                        { if (this->command_) { this->command_->keybindMode(mode); } return *this; }
     321                    inline _ConsoleCommandManipulator& inputConfiguredParam(int index)
     322                        { if (this->command_) { this->command_->inputConfiguredParam(index); } return *this; }
    287323
    288324                private:
     
    299335            _ConsoleCommand& addGroup(const std::string& group, const std::string&  name);
    300336
    301             inline void setActive(bool bActive)
    302                 { this->bActive_ = bActive; }
    303             inline void activate()
    304                 { this->setActive(true); }
    305             inline void deactivate()
    306                 { this->setActive(false); }
     337            inline _ConsoleCommand setActive(bool bActive)
     338                { this->bActive_ = bActive; return *this; }
     339            inline _ConsoleCommand activate()
     340                { return this->setActive(true); }
     341            inline _ConsoleCommand deactivate()
     342                { return this->setActive(false); }
     343
     344            inline _ConsoleCommand& setHidden(bool bHidden)
     345                { this->bHidden_ = bHidden; return *this; }
     346            inline _ConsoleCommand& hide()
     347                { return this->setHidden(true); }
     348            inline _ConsoleCommand& show()
     349                { return this->setHidden(false); }
     350
    307351            bool isActive() const;
     352            bool hasAccess() const;
     353            bool isHidden() const;
     354
     355            _ConsoleCommand& description(const std::string& description);
     356            const std::string& getDescription() const;
     357
     358            _ConsoleCommand& descriptionParam(unsigned int param, const std::string& description);
     359            const std::string& getDescriptionParam(unsigned int param) const;
     360
     361            _ConsoleCommand& descriptionReturnvalue(const std::string& description);
     362            const std::string& getDescriptionReturnvalue(int param) const;
     363
     364            _ConsoleCommand& defaultValues(const MultiType& param1);
     365            _ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2);
     366            _ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3);
     367            _ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4);
     368            _ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5);
     369            _ConsoleCommand& defaultValue(unsigned int index, const MultiType& param);
     370
     371            inline _ConsoleCommand& accessLevel(AccessLevel::Enum level)
     372                { this->accessLevel_ = level; return *this; }
     373            inline AccessLevel::Enum getAccessLevel() const
     374                { return this->accessLevel_; }
     375
     376            _ConsoleCommand& argumentCompleter(unsigned int param, ArgumentCompleter* completer);
     377            ArgumentCompleter* getArgumentCompleter(unsigned int param) const;
     378
     379            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 = "");
     380            const ArgumentCompletionList& getArgumentCompletionList() const
     381                { return this->argumentList_; }
     382            ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const
     383                { return this->argumentList_.begin(); }
     384            ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const
     385                { return this->argumentList_.end(); }
     386
     387            inline _ConsoleCommand& setAsInputCommand()
     388            {
     389                this->keybindMode(KeybindMode::OnHold);
     390                this->defaultValue(0, Vector2(0.0f, 0.0f));
     391                this->inputConfiguredParam(0);
     392                return *this;
     393            }
     394
     395            inline _ConsoleCommand& keybindMode(KeybindMode::Value mode)
     396                { this->keybindMode_ = mode; return *this; }
     397            inline KeybindMode::Value getKeybindMode() const
     398                { return this->keybindMode_; }
     399
     400            inline _ConsoleCommand& inputConfiguredParam(int index)
     401                { this->inputConfiguredParam_ = index; return *this; }
     402            inline int getInputConfiguredParam_() const
     403                { return this->inputConfiguredParam_; }
    308404
    309405            inline _ConsoleCommandManipulator getManipulator() const
    310406                { return this; }
    311407
    312             static inline const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommands()
    313                 { return _ConsoleCommand::getCommandMap(); }
    314 
    315             static inline const _ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false)
    316                 { return _ConsoleCommand::getCommand("", name, bPrintError); }
    317             static const _ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
    318 
    319408        private:
    320             static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
    321             static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command);
    322             static void unregisterCommand(_ConsoleCommand* command);
    323 
    324409            bool headersMatch(const FunctorPtr& functor);
    325410            bool headersMatch(const ExecutorPtr& executor);
     
    340425
    341426            bool bActive_;
    342 //            const std::type_info& functionHeader_;
     427            bool bHidden_;
     428            AccessLevel::Enum accessLevel_;
    343429            std::string baseName_;
    344430            ExecutorPtr baseExecutor_;
     
    347433            std::stack<Command> commandStack_;
    348434            std::stack<void*> objectStack_;
     435
     436            ArgumentCompleter* argumentCompleter_[5];
     437            ArgumentCompletionList argumentList_;
     438
     439            KeybindMode::Value keybindMode_;
     440            int inputConfiguredParam_;
     441
     442            LanguageEntryLabel description_;
     443            LanguageEntryLabel descriptionReturnvalue_;
     444            LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];
     445
     446        public:
     447            static inline const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommands()
     448                { return _ConsoleCommand::getCommandMap(); }
     449
     450            static inline const _ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false)
     451                { return _ConsoleCommand::getCommand("", name, bPrintError); }
     452            static const _ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
     453
     454        private:
     455            static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
     456            static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command);
     457            static void unregisterCommand(_ConsoleCommand* command);
    349458    };
    350459
    351460    inline _ConsoleCommand* _createConsoleCommand(const std::string& name, const ExecutorPtr& executor, bool bInitialized = true)
    352     {
    353         return new _ConsoleCommand("", name, executor, bInitialized);
    354     }
    355 
     461        { return new _ConsoleCommand("", name, executor, bInitialized); }
    356462    inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized = true)
    357     {
    358         return new _ConsoleCommand(group, name, executor, bInitialized);
    359     }
     463        { return new _ConsoleCommand(group, name, executor, bInitialized); }
     464
     465    inline _ConsoleCommand::_ConsoleCommandManipulator _ModifyConsoleCommand(const std::string& name)
     466        { return _ConsoleCommand::getCommand(name, true); }
     467    inline _ConsoleCommand::_ConsoleCommandManipulator _ModifyConsoleCommand(const std::string& group, const std::string& name)
     468        { return _ConsoleCommand::getCommand(group, name, true); }
    360469}
    361470
Note: See TracChangeset for help on using the changeset viewer.