Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 19, 2010, 2:11:28 AM (14 years ago)
Author:
landauf
Message:

continued working on the new console command interface and implementation

File:
1 edited

Legend:

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

    r7179 r7185  
    3232#include "CorePrereqs.h"
    3333
     34#include <stack>
    3435#include <boost/preprocessor/cat.hpp>
    3536#include <boost/preprocessor/facilities/expand.hpp>
     
    179180
    180181#define _DeclareConsoleCommandGeneric(group, name, functionpointer) \
    181     orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createFunctor(functionpointer), orxonox::_ConsoleCommand::State::UninitializedActive))
     182    orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createFunctor(functionpointer), false))
    182183
    183184
     
    193194
    194195        public:
    195             struct State
    196             {
    197                 enum Enum
    198                 {
    199                     UninitializedActive,
    200                     UninitializedInactive,
    201                     Active,
    202                     Inactive
    203                 };
    204             };
    205 
    206             struct ObjectPointer
    207             {
    208                 enum Enum
    209                 {
    210                     Null,
    211                     RawCopy,
    212                     CastViaBaseObject
    213                 };
    214             };
    215 
    216196            struct _ConsoleCommandManipulator
    217197            {
     
    220200
    221201                    template <class F>
    222                     inline _ConsoleCommandManipulator& setFunction(F function, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null)
    223                         { if (this->command_) { this->command_->setFunctor(createFunctor(function), mode); } return *this; }
     202                    inline _ConsoleCommandManipulator& setFunction(F function, bool bForce = false)
     203                        { if (this->command_) { this->command_->setFunctor(createFunctor(function), bForce); } return *this; }
    224204                    template <class F, class O>
    225                     inline _ConsoleCommandManipulator& setFunction(F function, O* object)
    226                         { if (this->command_) { this->command_->setFunctor(createFunctor(function, object)); } return *this; }
    227                     inline _ConsoleCommandManipulator& setFunction(Functor* functor)
    228                         { if (this->command_) { this->command_->setFunctor(functor); } return *this; }
    229                     inline _ConsoleCommandManipulator& setFunction(const _ConsoleCommand* command)
    230                         { if (this->command_) { this->command_->setFunctor(command->functor_); } return *this; }
    231                     inline _ConsoleCommandManipulator& setFunction(const _ConsoleCommandManipulator& manipulator)
    232                         { if (this->command_) { this->command_->setFunctor(manipulator.command_->functor_); } return *this; }
     205                    inline _ConsoleCommandManipulator& setFunction(F function, O* object, bool bForce = false)
     206                        { if (this->command_) { this->command_->setFunctor(createFunctor(function, object), bForce); } return *this; }
     207                    inline _ConsoleCommandManipulator& setFunction(Functor* functor, bool bForce = false)
     208                        { if (this->command_) { this->command_->setFunctor(functor, bForce); } return *this; }
    233209
    234210                    template <class F>
    235                     inline _ConsoleCommandManipulator& pushFunction(F function, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null)
    236                         { if (this->command_) { this->command_->pushFunctor(createFunctor(function), mode); } return *this; }
     211                    inline _ConsoleCommandManipulator& pushFunction(F function, bool bForce = false)
     212                        { if (this->command_) { this->command_->pushFunctor(createFunctor(function), bForce); } return *this; }
    237213                    template <class F, class O>
    238                     inline _ConsoleCommandManipulator& pushFunction(F function, O* object)
    239                         { if (this->command_) { this->command_->pushFunctor(createFunctor(function, object)); } return *this; }
    240                     inline _ConsoleCommandManipulator& pushFunction(Functor* functor)
    241                         { if (this->command_) { this->command_->pushFunctor(functor); } return *this; }
    242                     inline _ConsoleCommandManipulator& pushFunction(const _ConsoleCommand* command)
    243                         { if (this->command_) { this->command_->pushFunctor(command->functor_); } return *this; }
    244                     inline _ConsoleCommandManipulator& pushFunction(const _ConsoleCommandManipulator& manipulator)
    245                         { if (this->command_) { this->command_->pushFunctor(manipulator.command_->functor_); } return *this; }
     214                    inline _ConsoleCommandManipulator& pushFunction(F function, O* object, bool bForce = false)
     215                        { if (this->command_) { this->command_->pushFunctor(createFunctor(function, object), bForce); } return *this; }
     216                    inline _ConsoleCommandManipulator& pushFunction(Functor* functor, bool bForce = false)
     217                        { if (this->command_) { this->command_->pushFunctor(functor, bForce); } return *this; }
    246218
    247219                    inline _ConsoleCommandManipulator& popFunction()
     
    250222                    inline _ConsoleCommandManipulator& setObject(void* object)
    251223                        { if (this->command_) { this->command_->setObject(object); } return *this; }
    252                     inline _ConsoleCommandManipulator& setObject(BaseObject* object)
    253                         { if (this->command_) { this->command_->setObject(object); } return *this; }
     224                    inline _ConsoleCommandManipulator& pushObject(void* object)
     225                        { if (this->command_) { this->command_->pushObject(object); } return *this; }
     226                    inline _ConsoleCommandManipulator& popObject()
     227                        { if (this->command_) { this->command_->popObject(); } return *this; }
     228
     229                    inline void* getObject() const
     230                        { if (this->command_) { return this->command_->getObject(); } else { return 0; } }
    254231
    255232                    inline _ConsoleCommandManipulator& setActive(bool bActive)
     
    261238
    262239        public:
    263             _ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, State::Enum state = State::Active);
     240            _ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized = true);
    264241
    265242            _ConsoleCommand& addShortcut();
     
    268245            _ConsoleCommand& addGroup(const std::string& group, const std::string&  name);
    269246
    270             void setActive(bool bActive);
    271             inline State::Enum getState() const
    272                 { return this->state_; }
     247            inline void setActive(bool bActive)
     248                { this->bActive_ = bActive; }
    273249            inline bool isActive() const
    274                 { return (this->state_ == State::Active); }
     250                { return (this->bActive_ && this->bInitialized_); }
     251
     252            inline _ConsoleCommandManipulator getManipulator() const
     253                { return this; }
    275254
    276255            static inline const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommands()
     
    281260            static const _ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
    282261
    283             inline _ConsoleCommandManipulator getManipulator() const
    284                 { return this; }
    285 
    286262        private:
    287263            static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
    288264            static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command);
    289265
    290             void setInitialized(bool bInitialized);
    291 
    292             void setFunctor(Functor* functor, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null);
    293             void pushFunctor(Functor* functor, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null);
     266            bool setFunctor(Functor* functor, bool bForce = false);
     267            void pushFunctor(Functor* functor, bool bForce = false);
    294268            void popFunctor();
     269            Functor* getFunctor() const;
     270
    295271            bool functionHeaderMatches(Functor* functor) const;
    296272
    297273            void setObject(void* object);
    298             void setObject(BaseObject* object);
    299 
    300             State::Enum state_;
     274            void pushObject(void* object);
     275            void popObject();
     276            void* getObject() const;
     277
     278            bool bActive_;
     279            bool bInitialized_;
    301280            const std::type_info& functionHeader_;
     281            std::stack<Functor*> functorStack_;
     282            std::stack<void*> objectStack_;
    302283    };
    303284
    304     inline _ConsoleCommand* _createConsoleCommand(const std::string& name, Functor* functor, _ConsoleCommand::State::Enum state = _ConsoleCommand::State::Active)
    305     {
    306         return new _ConsoleCommand("", name, functor, state);
    307     }
    308 
    309     inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, Functor* functor, _ConsoleCommand::State::Enum state = _ConsoleCommand::State::Active)
    310     {
    311         return new _ConsoleCommand(group, name, functor, state);
     285    inline _ConsoleCommand* _createConsoleCommand(const std::string& name, Functor* functor, bool bInitialized = true)
     286    {
     287        return new _ConsoleCommand("", name, functor, bInitialized);
     288    }
     289
     290    inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized = true)
     291    {
     292        return new _ConsoleCommand(group, name, functor, bInitialized);
    312293    }
    313294}
Note: See TracChangeset for help on using the changeset viewer.