Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7198


Ignore:
Timestamp:
Aug 21, 2010, 9:52:13 PM (14 years ago)
Author:
landauf
Message:

createFunctor() now returns a SharedPtr instead of a pointer. Adapted code that uses createFunctor() accordingly.

Location:
code/branches/consolecommands3/src/libraries
Files:
15 edited

Legend:

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

    r7163 r7198  
    196196            mbool                   bVisible_;                 //!< True = the object is visible
    197197            std::string             mainStateName_;
    198             Functor              mainStateFunctor_;
     198            FunctorPtr              mainStateFunctor_;
    199199            std::set<std::string>   networkTemplateNames_;
    200200
  • code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc

    r7186 r7198  
    3434namespace orxonox
    3535{
    36     ConsoleCommand::ConsoleCommand(Functor* functor, const std::string& name) : Executor(functor, name)
     36    ConsoleCommand::ConsoleCommand(const FunctorPtr& functor, const std::string& name) : Executor(functor, name)
    3737    {
    3838        this->accessLevel_ = AccessLevel::None;
     
    124124    _ConsoleCommand::_ConsoleCommandManipulator test(_ModifyConsoleCommand("BaseObject", "setName").setFunction(&BaseObject::setActive));
    125125
    126     _ConsoleCommand::_ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized) : Executor(functor, name), functionHeader_(functor->getHeaderIdentifier())
     126    _ConsoleCommand::_ConsoleCommand(const std::string& group, const std::string& name, const FunctorPtr& functor, bool bInitialized) : Executor(functor, name), functionHeader_(functor->getHeaderIdentifier())
    127127    {
    128128        this->bActive_ = true;
     
    155155    }
    156156
    157     bool _ConsoleCommand::setFunctor(Functor* functor, bool bForce)
     157    bool _ConsoleCommand::setFunctor(const FunctorPtr& functor, bool bForce)
    158158    {
    159159        if (!functor)
     
    174174    }
    175175
    176     void _ConsoleCommand::pushFunctor(Functor* functor, bool bForce)
    177     {
    178         Functor* oldfunctor = this->getFunctor();
     176    void _ConsoleCommand::pushFunctor(const FunctorPtr& functor, bool bForce)
     177    {
     178        const FunctorPtr& oldfunctor = this->getFunctor();
    179179
    180180        if (this->setFunctor(functor, bForce));
     
    184184    void _ConsoleCommand::popFunctor()
    185185    {
    186         Functor* newfunctor = 0;
     186        FunctorPtr newfunctor;
    187187        if (!this->functorStack_.empty())
    188188        {
     
    193193    }
    194194
    195     Functor* _ConsoleCommand::getFunctor() const
    196     {
    197         if (this->bInitialized_)
     195    const FunctorPtr& _ConsoleCommand::getFunctor() const
     196    {
     197//        if (this->bInitialized_) // FIXME
    198198            return this->functor_;
    199         else
    200             return 0;
    201     }
    202 
    203     bool _ConsoleCommand::functionHeaderMatches(Functor* functor) const
     199//        else
     200//            return 0;
     201    }
     202
     203    bool _ConsoleCommand::functionHeaderMatches(const FunctorPtr& functor) const
    204204    {
    205205        if (!this->functor_)
     
    216216            this->functor_->setRawObjectPointer(object);
    217217        else if (object)
    218             COUT(0) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
     218            COUT(1) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
    219219    }
    220220
     
    227227        }
    228228        else
    229             COUT(0) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
     229            COUT(1) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
    230230    }
    231231
     
    263263        {
    264264            if (group == "")
    265                 COUT(0) << "Error: Couldn't find console command with shortcut \"" << name << "\"" << std::endl;
     265                COUT(1) << "Error: Couldn't find console command with shortcut \"" << name << "\"" << std::endl;
    266266            else
    267                 COUT(0) << "Error: Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << std::endl;
     267                COUT(1) << "Error: Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << std::endl;
    268268        }
    269269        return 0;
  • code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h

    r7186 r7198  
    8888    {
    8989        public:
    90             ConsoleCommand(Functor* functor, const std::string& name = "");
     90            ConsoleCommand(const FunctorPtr& functor, const std::string& name = "");
    9191
    9292            ConsoleCommand& description(const std::string& description);
     
    159159    };
    160160
    161     inline ConsoleCommand* createConsoleCommand(Functor* functor, const std::string& name = "")
     161    inline ConsoleCommand* createConsoleCommand(const FunctorPtr& functor, const std::string& name = "")
    162162    {
    163163        return new ConsoleCommand(functor, name);
     
    212212                    inline _ConsoleCommandManipulator& setFunction(F function, O* object, bool bForce = false)
    213213                        { if (this->command_) { this->command_->setFunctor(createFunctor(function, object), bForce); } return *this; }
    214                     inline _ConsoleCommandManipulator& setFunction(Functor* functor, bool bForce = false)
     214                    inline _ConsoleCommandManipulator& setFunction(const FunctorPtr& functor, bool bForce = false)
    215215                        { if (this->command_) { this->command_->setFunctor(functor, bForce); } return *this; }
    216216
     
    221221                    inline _ConsoleCommandManipulator& pushFunction(F function, O* object, bool bForce = false)
    222222                        { if (this->command_) { this->command_->pushFunctor(createFunctor(function, object), bForce); } return *this; }
    223                     inline _ConsoleCommandManipulator& pushFunction(Functor* functor, bool bForce = false)
     223                    inline _ConsoleCommandManipulator& pushFunction(const FunctorPtr& functor, bool bForce = false)
    224224                        { if (this->command_) { this->command_->pushFunctor(functor, bForce); } return *this; }
    225225
     
    245245
    246246        public:
    247             _ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized = true);
     247            _ConsoleCommand(const std::string& group, const std::string& name, const FunctorPtr& functor, bool bInitialized = true);
    248248
    249249            _ConsoleCommand& addShortcut();
     
    271271            static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command);
    272272
    273             bool setFunctor(Functor* functor, bool bForce = false);
    274             void pushFunctor(Functor* functor, bool bForce = false);
     273            bool setFunctor(const FunctorPtr& functor, bool bForce = false);
     274            void pushFunctor(const FunctorPtr& functor, bool bForce = false);
    275275            void popFunctor();
    276             Functor* getFunctor() const;
    277 
    278             bool functionHeaderMatches(Functor* functor) const;
     276            const FunctorPtr& getFunctor() const;
     277
     278            bool functionHeaderMatches(const FunctorPtr& functor) const;
    279279
    280280            void setObject(void* object);
     
    286286            bool bInitialized_;
    287287            const std::type_info& functionHeader_;
    288             std::stack<Functor*> functorStack_;
     288            std::stack<FunctorPtr> functorStack_;
    289289            std::stack<void*> objectStack_;
    290290    };
    291291
    292     inline _ConsoleCommand* _createConsoleCommand(const std::string& name, Functor* functor, bool bInitialized = true)
     292    inline _ConsoleCommand* _createConsoleCommand(const std::string& name, const FunctorPtr& functor, bool bInitialized = true)
    293293    {
    294294        return new _ConsoleCommand("", name, functor, bInitialized);
    295295    }
    296296
    297     inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized = true)
     297    inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, const FunctorPtr& functor, bool bInitialized = true)
    298298    {
    299299        return new _ConsoleCommand(group, name, functor, bInitialized);
  • code/branches/consolecommands3/src/libraries/core/Event.cc

    r7163 r7198  
    3434namespace orxonox
    3535{
    36     /**
    37         @brief Destructor: Deletes the functor of the event state.
    38     */
    39     EventState::~EventState()
    40     {
    41         if (this->statefunction_)
    42             delete this->statefunction_;
    43     }
    44 
    4536    /**
    4637        @brief Processes an event (calls the set-function if the necessary conditions are met).
  • code/branches/consolecommands3/src/libraries/core/Event.h

    r6800 r7198  
    6767    {
    6868        public:
    69             EventState(Functor* statefunction, Identifier* subclass, bool bSink = false) : bProcessingEvent_(false), activeEvents_(0), statefunction_(statefunction), subclass_(subclass), bSink_(bSink) {}
    70             virtual ~EventState();
     69            EventState(const FunctorPtr& statefunction, Identifier* subclass, bool bSink = false) : bProcessingEvent_(false), activeEvents_(0), statefunction_(statefunction), subclass_(subclass), bSink_(bSink) {}
    7170
    7271            void process(const Event& event, BaseObject* object);
    7372
    74             Functor* getFunctor() const
     73            const FunctorPtr& getFunctor() const
    7574                { return this->statefunction_; }
    7675
     
    7877            bool        bProcessingEvent_;  //!< This becomes true while the container processes an event (used to prevent loops)
    7978            int         activeEvents_;      //!< The number of events which affect this state and are currently active
    80             Functor  statefunction_;     //!< A functor to set the state
     79            FunctorPtr  statefunction_;     //!< A functor to set the state
    8180            Identifier* subclass_;          //!< Originators must be an instance of this class (usually BaseObject, but some statefunctions allow a second argument with an originator of a specific class)
    8281            bool        bSink_;             //!< Determines whether the EventState acts as an EventSink forwarding any Event (even if the state didn't change) or in the normal manner, only processing Events that change the state.
  • code/branches/consolecommands3/src/libraries/core/Executor.cc

    r7196 r7198  
    4242    int Executor::instances_s = 0;
    4343
    44     Executor::Executor(Functor* functor, const std::string& name)
     44    Executor::Executor(const FunctorPtr& functor, const std::string& name)
    4545    {
    4646        this->functor_ = functor;
     
    5151    Executor::~Executor()
    5252    {
    53         delete this->functor_;
    5453        --instances_s; COUT(0) << "executor --: " << instances_s << std::endl;
    5554    }
  • code/branches/consolecommands3/src/libraries/core/Executor.h

    r7196 r7198  
    4242    class _CoreExport Executor
    4343    {
    44         friend class SharedPtr<Executor>;
    45 
    4644        public:
    47             Executor(Functor* functor, const std::string& name = "");
     45            Executor(const FunctorPtr& functor, const std::string& name = "");
    4846            virtual ~Executor();
    4947
     
    6563            bool evaluate(const std::string& params, MultiType param[5], const std::string& delimiter = " ") const;
    6664
    67             inline Functor* getFunctor() const
     65            inline const FunctorPtr& getFunctor() const
    6866                { return this->functor_; }
    6967            inline unsigned int getParamCount() const
     
    108106
    109107        protected:
    110             Functor* functor_;
     108            FunctorPtr functor_;
    111109            std::string name_;
    112110            MultiType defaultValue_[MAX_FUNCTOR_ARGUMENTS];
     
    119117    {
    120118        public:
    121             ExecutorStatic(FunctorStatic* functor, const std::string& name = "") : Executor(functor, name) {}
     119            ExecutorStatic(const FunctorStaticPtr& functor, const std::string& name = "") : Executor(functor, name) {}
    122120            virtual ~ExecutorStatic() {}
    123121    };
     
    127125    {
    128126        public:
    129             ExecutorMember(FunctorMember<T>* functor, const std::string& name = "") : Executor(functor, name) {}
     127            ExecutorMember(const FunctorMemberPtr<T>& functor, const std::string& name = "") : Executor(functor, name), functorMember_(functor) {}
    130128            virtual ~ExecutorMember() {}
    131129
     
    133131
    134132            inline MultiType operator()(T* object) const
    135                 { return (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     133                { return (*this->functorMember_)(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
    136134            inline MultiType operator()(T* object, const MultiType& param1) const
    137                 { return (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     135                { return (*this->functorMember_)(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
    138136            inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2) const
    139                 { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     137                { return (*this->functorMember_)(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
    140138            inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3) const
    141                 { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
     139                { return (*this->functorMember_)(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
    142140            inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const
    143                 { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); }
     141                { return (*this->functorMember_)(object, param1, param2, param3, param4, this->defaultValue_[4]); }
    144142            inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const
    145                 { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); }
     143                { return (*this->functorMember_)(object, param1, param2, param3, param4, param5); }
    146144
    147145
    148146            inline MultiType operator()(const T* object) const
    149                 { return (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     147                { return (*this->functorMember_)(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
    150148            inline MultiType operator()(const T* object, const MultiType& param1) const
    151                 { return (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     149                { return (*this->functorMember_)(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
    152150            inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2) const
    153                 { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     151                { return (*this->functorMember_)(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
    154152            inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3) const
    155                 { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
     153                { return (*this->functorMember_)(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
    156154            inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const
    157                 { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); }
     155                { return (*this->functorMember_)(object, param1, param2, param3, param4, this->defaultValue_[4]); }
    158156            inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const
    159                 { return (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); }
     157                { return (*this->functorMember_)(object, param1, param2, param3, param4, param5); }
    160158
    161159            inline void setObject(T* object) const
    162                 { ((FunctorMember<T>*)this->functor_)->setObject(object); }
     160                { this->functorMember_->setObject(object); }
    163161            inline void setObject(const T* object) const
    164                 { ((FunctorMember<T>*)this->functor_)->setObject(object); }
     162                { this->functorMember_->setObject(object); }
    165163
    166164            using Executor::parse;
     
    168166            MultiType parse(T* object, const std::string& params, bool* success = 0, const std::string& delimiter = " ") const
    169167            {
    170                 FunctorMember<T>* functorMember = static_cast<FunctorMember<T>*>(this->functor_);
    171 
    172                 const typename FunctorMember<T>::Objects& objects = functorMember->getObjects();
    173 
    174                 functorMember->setObject(object);
     168                const typename FunctorMember<T>::Objects& objects = this->functorMember_->getObjects();
     169
     170                this->functorMember_->setObject(object);
    175171                const MultiType& result = Executor::parse(params, success, delimiter);
    176                 functorMember->setObjects(objects);
     172                this->functorMember_->setObjects(objects);
    177173
    178174                return result;
     
    181177            MultiType parse(const T* object, const std::string& params, bool* success = 0, const std::string& delimiter = " ") const
    182178            {
    183                 FunctorMember<T>* functorMember = static_cast<FunctorMember<T>*>(this->functor_);
    184 
    185                 const typename FunctorMember<T>::Objects& objects = functorMember->getObjects();
    186 
    187                 functorMember->setObject(object);
     179                const typename FunctorMember<T>::Objects& objects = this->functorMember_->getObjects();
     180
     181                this->functorMember_->setObject(object);
    188182                const MultiType& result = Executor::parse(params, success, delimiter);
    189                 functorMember->setObjects(objects);
     183                this->functorMember_->setObjects(objects);
    190184
    191185                return result;
    192186            }
     187
     188        protected:
     189            FunctorMemberPtr<T> functorMember_;
    193190    };
    194191
    195     inline Executor* createExecutor(Functor* functor, const std::string& name = "")
     192    inline Executor* createExecutor(const FunctorPtr& functor, const std::string& name = "")
    196193    {
    197194        return new Executor(functor, name);
     
    199196
    200197    template <class T>
    201     inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "")
     198    inline ExecutorMember<T>* createExecutor(const FunctorMemberPtr<T>& functor, const std::string& name = "")
    202199    {
    203200        return new ExecutorMember<T>(functor, name);
    204201    }
    205202
    206     inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "")
     203    inline ExecutorStatic* createExecutor(const FunctorStaticPtr& functor, const std::string& name = "")
    207204    {
    208205        return new ExecutorStatic(functor, name);
  • code/branches/consolecommands3/src/libraries/core/Functor.h

    r7196 r7198  
    8989    class _CoreExport Functor
    9090    {
    91         friend class SharedPtr<Functor>;
    92 
    9391        public:
    9492            struct Type
     
    215213
    216214
    217     inline Functor* createFunctor(Functor* functor)
     215    inline const FunctorPtr& createFunctor(const FunctorPtr& functor)
    218216    {
    219217        return functor;
     
    424422    \
    425423    FUNCTOR_TEMPLATE(0, returnvalue, numparams, 0) \
    426     inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
     424    inline SharedChildPtr<FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams), FunctorStaticPtr> createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
    427425    { \
    428426        return new FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams) (functionPointer); \
     
    517515    \
    518516    FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
    519     inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
     517    inline SharedChildPtr<FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams), FunctorMemberPtr<T> > createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
    520518    { \
    521519        return new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
     
    524522    \
    525523    FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
    526     inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
     524    inline SharedChildPtr<FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams), FunctorMemberPtr<T> > createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
    527525    { \
    528526        return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
     
    530528    \
    531529    FUNCTOR_TEMPLATE(1, returnvalue, numparams, 1) \
    532     inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)), O* object) \
     530    inline SharedChildPtr<FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams), FunctorMemberPtr<T> > createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)), O* object) \
    533531    { \
    534532        FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* functor = new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
     
    539537    \
    540538    FUNCTOR_TEMPLATE(1, returnvalue, numparams, 1) \
    541     inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const, O* object) \
     539    inline SharedChildPtr<FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams), FunctorMemberPtr<T> > createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const, O* object) \
    542540    { \
    543541        FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* functor = new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
  • code/branches/consolecommands3/src/libraries/core/WeakPtr.h

    r6417 r7198  
    7777                if (this->base_)
    7878                    this->base_->unregisterWeakPtr(this);
    79                 if (this->callback_)
    80                     delete this->callback_;
    8179
    8280            }
     
    168166            }
    169167
    170             inline void setCallback(Functor* callback)
     168            inline void setCallback(const FunctorPtr& callback)
    171169            {
    172170                this->callback_ = callback;
    173171            }
    174172
    175             inline Functor* getFunctor() const
     173            inline const FunctorPtr& getCallback() const
    176174            {
    177175                return this->callback_;
     
    189187            T* pointer_;
    190188            OrxonoxClass* base_;
    191             Functor* callback_;
     189            FunctorPtr callback_;
    192190    };
    193191
  • code/branches/consolecommands3/src/libraries/core/input/InputState.h

    r6746 r7198  
    150150        void left();
    151151        //! Sets a functor to be called upon activation of the state
    152         void setEnterFunctor(Functor* functor) { this->enterFunctor_ = functor; }
     152        void setEnterFunctor(const FunctorPtr& functor) { this->enterFunctor_ = functor; }
    153153        //! Sets a functor to be called upon deactivation of the state
    154         void setLeaveFunctor(Functor* functor) { this->leaveFunctor_ = functor; }
     154        void setLeaveFunctor(const FunctorPtr& functor) { this->leaveFunctor_ = functor; }
    155155
    156156    private:
     
    172172        //! Handler to be used for all joy sticks (needs to be saved in case another joy stick gets attached)
    173173        InputHandler*               joyStickHandlerAll_;
    174         Functor                  enterFunctor_;          //!< Functor to be executed on enter
    175         Functor                  leaveFunctor_;          //!< Functor to be executed on leave
     174        FunctorPtr                  enterFunctor_;          //!< Functor to be executed on enter
     175        FunctorPtr                  leaveFunctor_;          //!< Functor to be executed on leave
    176176    };
    177177
  • code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.cc

    r6417 r7198  
    156156        {
    157157            COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
    158             KeyDetector::getInstance().setCallback(shared_ptr<Functor>(createFunctor(&KeyBinderManager::keybindKeyPressed, this)));
     158            KeyDetector::getInstance().setCallback(createFunctor(&KeyBinderManager::keybindKeyPressed, this));
    159159            InputManager::getInstance().enterState("detector");
    160160            this->command_ = command;
  • code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.h

    r6417 r7198  
    9999        void unbind(const std::string& binding); //tolua_export
    100100        void tunbind(const std::string& binding);
    101         inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export
     101        inline void registerKeybindCallback(const FunctorPtr& function) { this->callbackFunction_ = function; } // tolua//_//export // <-- FIXME
    102102
    103103    private:
     
    114114
    115115        // keybind command related
    116         shared_ptr<Functor> callbackFunction_;       //! Function to be called when key was pressed after "keybind" command
     116        FunctorPtr callbackFunction_;                //! Function to be called when key was pressed after "keybind" command
    117117        bool bBinding_;                              //! Tells whether a key binding process is active
    118118        bool bTemporary_;                            //! Stores tkeybind/keybind value
  • code/branches/consolecommands3/src/libraries/core/input/KeyDetector.h

    r6417 r7198  
    4646        ~KeyDetector();
    4747
    48         void setCallback(const shared_ptr<Functor>& function) { this->callbackFunction_ = function; }
     48        void setCallback(const FunctorPtr& function) { this->callbackFunction_ = function; }
    4949
    5050    private:
     
    5555        void assignCommands();
    5656
    57         shared_ptr<Functor> callbackFunction_;
     57        FunctorPtr callbackFunction_;
    5858        InputState* inputState_;
    5959        static std::string callbackCommand_s;
  • code/branches/consolecommands3/src/libraries/network/NetworkFunction.cc

    r6417 r7198  
    6868
    6969
    70   NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p):
     70  NetworkFunctionStatic::NetworkFunctionStatic(const FunctorStaticPtr& functor, const std::string& name, const NetworkFunctionPointer& p):
    7171    NetworkFunctionBase(name)
    7272  {
     
    7676    NetworkFunctionStatic::getFunctorMap()[p] = this;
    7777    NetworkFunctionStatic::getIdMap()[ this->getNetworkID() ] = this;
    78   }
    79 
    80   NetworkFunctionStatic::~NetworkFunctionStatic()
    81   {
    82     delete this->functor_;
    8378  }
    8479
  • code/branches/consolecommands3/src/libraries/network/NetworkFunction.h

    r6417 r7198  
    102102class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase {
    103103  public:
    104     NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p);
    105     ~NetworkFunctionStatic();
     104    NetworkFunctionStatic(const FunctorStaticPtr& functor, const std::string& name, const NetworkFunctionPointer& p);
    106105
    107106    inline void call(){ (*this->functor_)(); }
     
    124123    static std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& getFunctorMap();
    125124    static std::map<uint32_t, NetworkFunctionStatic*>& getIdMap();
    126     FunctorStatic* functor_;
     125    FunctorStaticPtr functor_;
    127126
    128127};
     
    155154template <class T> class NetworkMemberFunction: public NetworkMemberFunctionBase {
    156155  public:
    157     NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p);
    158     ~NetworkMemberFunction();
     156    NetworkMemberFunction(const FunctorMemberPtr<T>& functor, const std::string& name, const NetworkFunctionPointer& p);
    159157
    160158    inline void call(uint32_t objectID)
     
    190188
    191189  private:
    192     FunctorMember<T>* functor_;
    193 };
    194 
    195 template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p):
     190    FunctorMemberPtr<T> functor_;
     191};
     192
     193template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(const FunctorMemberPtr<T>& functor, const std::string& name, const NetworkFunctionPointer& p):
    196194    NetworkMemberFunctionBase(name, p), functor_(functor)
    197195{
    198 }
    199 template <class T> NetworkMemberFunction<T>::~NetworkMemberFunction()
    200 {
    201   delete this->functor_;
    202196}
    203197
Note: See TracChangeset for help on using the changeset viewer.