- Timestamp:
- Aug 21, 2010, 9:52:13 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/Executor.h
r7196 r7198 42 42 class _CoreExport Executor 43 43 { 44 friend class SharedPtr<Executor>;45 46 44 public: 47 Executor( Functor*functor, const std::string& name = "");45 Executor(const FunctorPtr& functor, const std::string& name = ""); 48 46 virtual ~Executor(); 49 47 … … 65 63 bool evaluate(const std::string& params, MultiType param[5], const std::string& delimiter = " ") const; 66 64 67 inline Functor*getFunctor() const65 inline const FunctorPtr& getFunctor() const 68 66 { return this->functor_; } 69 67 inline unsigned int getParamCount() const … … 108 106 109 107 protected: 110 Functor *functor_;108 FunctorPtr functor_; 111 109 std::string name_; 112 110 MultiType defaultValue_[MAX_FUNCTOR_ARGUMENTS]; … … 119 117 { 120 118 public: 121 ExecutorStatic( FunctorStatic*functor, const std::string& name = "") : Executor(functor, name) {}119 ExecutorStatic(const FunctorStaticPtr& functor, const std::string& name = "") : Executor(functor, name) {} 122 120 virtual ~ExecutorStatic() {} 123 121 }; … … 127 125 { 128 126 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) {} 130 128 virtual ~ExecutorMember() {} 131 129 … … 133 131 134 132 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]); } 136 134 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]); } 138 136 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]); } 140 138 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]); } 142 140 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]); } 144 142 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); } 146 144 147 145 148 146 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]); } 150 148 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]); } 152 150 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]); } 154 152 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]); } 156 154 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]); } 158 156 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); } 160 158 161 159 inline void setObject(T* object) const 162 { ((FunctorMember<T>*)this->functor_)->setObject(object); }160 { this->functorMember_->setObject(object); } 163 161 inline void setObject(const T* object) const 164 { ((FunctorMember<T>*)this->functor_)->setObject(object); }162 { this->functorMember_->setObject(object); } 165 163 166 164 using Executor::parse; … … 168 166 MultiType parse(T* object, const std::string& params, bool* success = 0, const std::string& delimiter = " ") const 169 167 { 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); 175 171 const MultiType& result = Executor::parse(params, success, delimiter); 176 functorMember->setObjects(objects);172 this->functorMember_->setObjects(objects); 177 173 178 174 return result; … … 181 177 MultiType parse(const T* object, const std::string& params, bool* success = 0, const std::string& delimiter = " ") const 182 178 { 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); 188 182 const MultiType& result = Executor::parse(params, success, delimiter); 189 functorMember->setObjects(objects);183 this->functorMember_->setObjects(objects); 190 184 191 185 return result; 192 186 } 187 188 protected: 189 FunctorMemberPtr<T> functorMember_; 193 190 }; 194 191 195 inline Executor* createExecutor( Functor*functor, const std::string& name = "")192 inline Executor* createExecutor(const FunctorPtr& functor, const std::string& name = "") 196 193 { 197 194 return new Executor(functor, name); … … 199 196 200 197 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 = "") 202 199 { 203 200 return new ExecutorMember<T>(functor, name); 204 201 } 205 202 206 inline ExecutorStatic* createExecutor( FunctorStatic*functor, const std::string& name = "")203 inline ExecutorStatic* createExecutor(const FunctorStaticPtr& functor, const std::string& name = "") 207 204 { 208 205 return new ExecutorStatic(functor, name);
Note: See TracChangeset
for help on using the changeset viewer.