Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 25, 2010, 1:04:55 PM (14 years ago)
Author:
landauf
Message:

progress on the new console command interface.
enhanced possibilities to compare Functors and to manipulate Executors

File:
1 edited

Legend:

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

    r7203 r7214  
    176176
    177177#define _SetConsoleCommandGeneric(group, name, functor) \
    178     orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, functor))
     178    orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createExecutor(functor)))
    179179
    180180
     
    182182    BOOST_PP_CAT(_DeclareConsoleCommand, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__)
    183183#define _DeclareConsoleCommand2(name, functionpointer) \
    184     _DeclareConsoleCommandGeneric("", name, functionpointer)
     184    _DeclareConsoleCommandGeneric("", name, orxonox::createFunctor(functionpointer))
    185185#define _DeclareConsoleCommand3(group, name, functionpointer) \
    186     _DeclareConsoleCommandGeneric(group, name, functionpointer)
    187 
    188 #define _DeclareConsoleCommandGeneric(group, name, functionpointer) \
    189     orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createFunctor(functionpointer), false))
     186    _DeclareConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer))
     187#define _DeclareConsoleCommand4(group, name, functionpointer, object) \
     188    _DeclareConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer, object))
     189
     190#define _DeclareConsoleCommandGeneric(group, name, functor) \
     191    orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = orxonox::_createConsoleCommand(group, name, orxonox::createExecutor(functor), false)
    190192
    191193
     
    196198namespace orxonox
    197199{
    198     class _CoreExport _ConsoleCommand : protected Executor
     200    class _CoreExport _ConsoleCommand
    199201    {
    200202        friend struct _ConsoleCommandManipulator;
     203
     204        struct Command
     205        {
     206            ExecutorPtr executor_;
     207            FunctorPtr functor_;
     208        };
    201209
    202210        public:
     
    208216                    template <class F>
    209217                    inline _ConsoleCommandManipulator& setFunction(F function, bool bForce = false)
    210                         { if (this->command_) { this->command_->setFunctor(createFunctor(function), bForce); } return *this; }
     218                        {
     219                            if (this->command_)
     220                            {
     221                                if (this->command_->getExecutor() && this->command_->getFunctor() && this->command_->getFunctor()->getFullIdentifier() == typeid(F))
     222                                {
     223                                    FunctorPointer<F>* functor = static_cast<FunctorPointer<F>*>(this->command_->getFunctor().get());
     224                                    functor->setFunction(function);
     225                                    return *this;
     226                                }
     227                                this->command_->setFunction(createFunctor(function), bForce);
     228                            }
     229                            return *this;
     230                        }
    211231                    template <class F, class O>
    212232                    inline _ConsoleCommandManipulator& setFunction(F function, O* object, bool bForce = false)
    213                         { if (this->command_) { this->command_->setFunctor(createFunctor(function, object), bForce); } return *this; }
     233                        {
     234                            if (this->command_)
     235                            {
     236                                if (this->command_->getExecutor() && this->command_->getFunctor() && this->command_->getFunctor()->getFullIdentifier() == typeid(F))
     237                                {
     238                                    FunctorPointer<F, O>* functor = static_cast<FunctorPointer<F, O>*>(this->command_->getFunctor().get());
     239                                    functor->setFunction(function);
     240                                    functor->setObject(object);
     241                                    return *this;
     242                                }
     243                                this->command_->setFunction(createFunctor(function, object), bForce);
     244                            }
     245                            return *this;
     246                        }
    214247                    inline _ConsoleCommandManipulator& setFunction(const FunctorPtr& functor, bool bForce = false)
    215                         { if (this->command_) { this->command_->setFunctor(functor, bForce); } return *this; }
     248                        { if (this->command_) { this->command_->setFunction(functor, bForce); } return *this; }
     249                    inline _ConsoleCommandManipulator& setFunction(const ExecutorPtr& executor, bool bForce = false)
     250                        { if (this->command_) { this->command_->setFunction(executor, bForce); } return *this; }
    216251
    217252                    template <class F>
    218253                    inline _ConsoleCommandManipulator& pushFunction(F function, bool bForce = false)
    219                         { if (this->command_) { this->command_->pushFunctor(createFunctor(function), bForce); } return *this; }
     254                        { if (this->command_) { this->command_->pushFunction(createFunctor(function), bForce); } return *this; }
    220255                    template <class F, class O>
    221256                    inline _ConsoleCommandManipulator& pushFunction(F function, O* object, bool bForce = false)
    222                         { if (this->command_) { this->command_->pushFunctor(createFunctor(function, object), bForce); } return *this; }
     257                        { if (this->command_) { this->command_->pushFunction(createFunctor(function, object), bForce); } return *this; }
    223258                    inline _ConsoleCommandManipulator& pushFunction(const FunctorPtr& functor, bool bForce = false)
    224                         { if (this->command_) { this->command_->pushFunctor(functor, bForce); } return *this; }
     259                        { if (this->command_) { this->command_->pushFunction(functor, bForce); } return *this; }
     260                    inline _ConsoleCommandManipulator& pushFunction(const ExecutorPtr& executor, bool bForce = false)
     261                        { if (this->command_) { this->command_->pushFunction(executor, bForce); } return *this; }
    225262
    226263                    inline _ConsoleCommandManipulator& popFunction()
    227                         { if (this->command_) { this->command_->popFunctor(); } return *this; }
     264                        { if (this->command_) { this->command_->popFunction(); } return *this; }
    228265
    229266                    inline _ConsoleCommandManipulator& setObject(void* object)
     
    239276                    inline _ConsoleCommandManipulator& setActive(bool bActive)
    240277                        { if (this->command_) { this->command_->setActive(bActive); } return *this; }
     278                    inline _ConsoleCommandManipulator& activate()
     279                        { return this->setActive(true); }
     280                    inline _ConsoleCommandManipulator& deactivate()
     281                        { return this->setActive(false); }
     282
     283                    inline bool isActive() const
     284                        { return this->command_ ? this->command_->isActive() : false; }
     285                    inline bool exists() const
     286                        { return (this->command_ != 0); }
    241287
    242288                private:
     
    245291
    246292        public:
    247             _ConsoleCommand(const std::string& group, const std::string& name, const FunctorPtr& functor, bool bInitialized = true);
     293            _ConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized = true);
     294            ~_ConsoleCommand();
    248295
    249296            _ConsoleCommand& addShortcut();
     
    254301            inline void setActive(bool bActive)
    255302                { this->bActive_ = bActive; }
    256             inline bool isActive() const
    257                 { return (this->bActive_ && this->bInitialized_); }
     303            inline void activate()
     304                { this->setActive(true); }
     305            inline void deactivate()
     306                { this->setActive(false); }
     307            bool isActive() const;
    258308
    259309            inline _ConsoleCommandManipulator getManipulator() const
     
    270320            static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
    271321            static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command);
    272 
    273             bool setFunctor(const FunctorPtr& functor, bool bForce = false);
    274             void pushFunctor(const FunctorPtr& functor, bool bForce = false);
    275             void popFunctor();
     322            static void unregisterCommand(_ConsoleCommand* command);
     323
     324            bool headersMatch(const FunctorPtr& functor);
     325            bool headersMatch(const ExecutorPtr& executor);
     326
     327            bool setFunction(const ExecutorPtr& executor, bool bForce = false);
     328            bool setFunction(const FunctorPtr& functor, bool bForce = false);
     329            void pushFunction(const ExecutorPtr& executor, bool bForce = false);
     330            void pushFunction(const FunctorPtr& functor, bool bForce = false);
     331            void pushFunction();
     332            void popFunction();
     333            const ExecutorPtr& getExecutor() const;
    276334            const FunctorPtr& getFunctor() const;
    277335
    278             bool functionHeaderMatches(const FunctorPtr& functor) const;
    279 
    280             void setObject(void* object);
     336            bool setObject(void* object);
    281337            void pushObject(void* object);
    282338            void popObject();
     
    284340
    285341            bool bActive_;
    286             bool bInitialized_;
    287             const std::type_info& functionHeader_;
    288             std::stack<FunctorPtr> functorStack_;
     342//            const std::type_info& functionHeader_;
     343            std::string baseName_;
     344            ExecutorPtr baseExecutor_;
     345
     346            ExecutorPtr executor_;
     347            std::stack<Command> commandStack_;
    289348            std::stack<void*> objectStack_;
    290349    };
    291350
    292     inline _ConsoleCommand* _createConsoleCommand(const std::string& name, const FunctorPtr& functor, bool bInitialized = true)
    293     {
    294         return new _ConsoleCommand("", name, functor, bInitialized);
     351    inline _ConsoleCommand* _createConsoleCommand(const std::string& name, const ExecutorPtr& executor, bool bInitialized = true)
     352    {
     353        return new _ConsoleCommand("", name, executor, bInitialized);
    295354    }
    296355
    297     inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, const FunctorPtr& functor, bool bInitialized = true)
    298     {
    299         return new _ConsoleCommand(group, name, functor, bInitialized);
     356    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);
    300359    }
    301360}
Note: See TracChangeset for help on using the changeset viewer.