Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.