Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7218


Ignore:
Timestamp:
Aug 25, 2010, 11:46:32 PM (14 years ago)
Author:
landauf
Message:

some improvements/fixes in ConsoleCommand

Location:
code/branches/consolecommands3/src/libraries/core/command
Files:
2 edited

Legend:

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

    r7216 r7218  
    9393    bool _ConsoleCommand::isActive() const
    9494    {
    95         return (this->bActive_ && this->executor_ && this->executor_->getFunctor());
     95        return (this->bActive_ && this->executor_ && this->executor_->getFunctor() && (this->executor_->getFunctor()->getType() == Functor::Type::Static || this->executor_->getFunctor()->getRawObjectPointer()));
    9696    }
    9797
     
    154154            if (this->executor_)
    155155                this->executor_->setFunctor(functor);
    156             else
     156            else if (functor)
    157157                this->executor_ = createExecutor(functor);
    158158
     
    208208        if (command.executor_)
    209209            this->executor_->setFunctor(command.functor_);
     210    }
     211
     212    void _ConsoleCommand::resetFunction()
     213    {
     214        if (this->executor_)
     215            this->executor_->setFunctor(0);
    210216    }
    211217
     
    453459    /* static */ void _ConsoleCommand::destroyAll()
    454460    {
    455         while (!_ConsoleCommand::getCommandMap().empty() && !_ConsoleCommand::getCommandMap().begin().empty())
    456             _ConsoleCommand::getCommandMap().begin().erase(_ConsoleCommand::getCommandMap().begin().begin());
     461        while (!_ConsoleCommand::getCommandMap().empty() && !_ConsoleCommand::getCommandMap().begin()->second.empty())
     462            delete _ConsoleCommand::getCommandMap().begin()->second.begin()->second;
    457463    }
    458464}
  • code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h

    r7216 r7218  
    5151
    5252#define _SetConsoleCommandGeneric(group, name, functor) \
    53     orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createExecutor(functor)))
     53    static orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createExecutor(functor)))
    5454
    5555
     
    6464
    6565#define _DeclareConsoleCommandGeneric(group, name, functor) \
    66     orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = orxonox::_createConsoleCommand(group, name, orxonox::createExecutor(functor), false)
     66    static orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createExecutor(functor), false))
    6767
    6868
    6969namespace orxonox
    7070{
     71    namespace prototype
     72    {
     73        inline void void__void(void) {}
     74        inline void void__string(const std::string&) {}
     75    }
     76
     77    namespace AccessLevel
     78    {
     79        enum Enum
     80        {
     81            All,
     82            Standalone,
     83            Master,
     84            Server,
     85            Client,
     86            Online,
     87            Offline,
     88            None
     89        };
     90    }
     91
    7192    class _CoreExport _ConsoleCommand
    7293    {
     
    7798            ExecutorPtr executor_;
    7899            FunctorPtr functor_;
    79         };
    80 
    81         struct AccessLevel
    82         {
    83             enum Enum
    84             {
    85                 All,
    86                 Standalone,
    87                 Master,
    88                 Server,
    89                 Client,
    90                 Online,
    91                 Offline,
    92                 None
    93             };
    94100        };
    95101
     
    150156                        { if (this->command_) { this->command_->popFunction(); } return *this; }
    151157
     158                    inline _ConsoleCommandManipulator& resetFunction()
     159                        { if (this->command_) { this->command_->resetFunction(); } return *this; }
     160
    152161                    inline _ConsoleCommandManipulator& setObject(void* object)
    153162                        { if (this->command_) { this->command_->setObject(object); } return *this; }
     
    184193                        { if (this->command_) { this->command_->defaultValue(index, param); } return *this; }
    185194
    186                     inline _ConsoleCommandManipulator& accessLevel(_ConsoleCommand::AccessLevel::Enum level)
     195                    inline _ConsoleCommandManipulator& accessLevel(AccessLevel::Enum level)
    187196                        { if (this->command_) { this->command_->accessLevel(level); } return *this; }
    188197
     
    210219            _ConsoleCommand& addGroup(const std::string& group, const std::string&  name);
    211220
    212             inline _ConsoleCommand setActive(bool bActive)
     221            inline const std::string& getName() const
     222                { return this->baseName_; }
     223
     224            const ExecutorPtr& getExecutor() const;
     225            inline const ExecutorPtr& getBaseExecutor() const
     226                { return this->baseExecutor_; }
     227
     228            inline _ConsoleCommand& setActive(bool bActive)
    213229                { this->bActive_ = bActive; return *this; }
    214             inline _ConsoleCommand activate()
     230            inline _ConsoleCommand& activate()
    215231                { return this->setActive(true); }
    216             inline _ConsoleCommand deactivate()
     232            inline _ConsoleCommand& deactivate()
    217233                { return this->setActive(false); }
    218234
     
    291307            void pushFunction();
    292308            void popFunction();
    293             const ExecutorPtr& getExecutor() const;
    294             const FunctorPtr& getFunctor() const;
     309            void resetFunction();
    295310
    296311            bool setObject(void* object);
Note: See TracChangeset for help on using the changeset viewer.