Changeset 7198 for code/branches/consolecommands3
- Timestamp:
- Aug 21, 2010, 9:52:13 PM (14 years ago)
- Location:
- code/branches/consolecommands3/src/libraries
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/BaseObject.h
r7163 r7198 196 196 mbool bVisible_; //!< True = the object is visible 197 197 std::string mainStateName_; 198 Functor *mainStateFunctor_;198 FunctorPtr mainStateFunctor_; 199 199 std::set<std::string> networkTemplateNames_; 200 200 -
code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc
r7186 r7198 34 34 namespace orxonox 35 35 { 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) 37 37 { 38 38 this->accessLevel_ = AccessLevel::None; … … 124 124 _ConsoleCommand::_ConsoleCommandManipulator test(_ModifyConsoleCommand("BaseObject", "setName").setFunction(&BaseObject::setActive)); 125 125 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()) 127 127 { 128 128 this->bActive_ = true; … … 155 155 } 156 156 157 bool _ConsoleCommand::setFunctor( Functor*functor, bool bForce)157 bool _ConsoleCommand::setFunctor(const FunctorPtr& functor, bool bForce) 158 158 { 159 159 if (!functor) … … 174 174 } 175 175 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(); 179 179 180 180 if (this->setFunctor(functor, bForce)); … … 184 184 void _ConsoleCommand::popFunctor() 185 185 { 186 Functor * newfunctor = 0;186 FunctorPtr newfunctor; 187 187 if (!this->functorStack_.empty()) 188 188 { … … 193 193 } 194 194 195 Functor*_ConsoleCommand::getFunctor() const196 { 197 if (this->bInitialized_) 195 const FunctorPtr& _ConsoleCommand::getFunctor() const 196 { 197 // if (this->bInitialized_) // FIXME 198 198 return this->functor_; 199 else200 return 0;201 } 202 203 bool _ConsoleCommand::functionHeaderMatches( Functor*functor) const199 // else 200 // return 0; 201 } 202 203 bool _ConsoleCommand::functionHeaderMatches(const FunctorPtr& functor) const 204 204 { 205 205 if (!this->functor_) … … 216 216 this->functor_->setRawObjectPointer(object); 217 217 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; 219 219 } 220 220 … … 227 227 } 228 228 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; 230 230 } 231 231 … … 263 263 { 264 264 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; 266 266 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; 268 268 } 269 269 return 0; -
code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h
r7186 r7198 88 88 { 89 89 public: 90 ConsoleCommand( Functor*functor, const std::string& name = "");90 ConsoleCommand(const FunctorPtr& functor, const std::string& name = ""); 91 91 92 92 ConsoleCommand& description(const std::string& description); … … 159 159 }; 160 160 161 inline ConsoleCommand* createConsoleCommand( Functor*functor, const std::string& name = "")161 inline ConsoleCommand* createConsoleCommand(const FunctorPtr& functor, const std::string& name = "") 162 162 { 163 163 return new ConsoleCommand(functor, name); … … 212 212 inline _ConsoleCommandManipulator& setFunction(F function, O* object, bool bForce = false) 213 213 { 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) 215 215 { if (this->command_) { this->command_->setFunctor(functor, bForce); } return *this; } 216 216 … … 221 221 inline _ConsoleCommandManipulator& pushFunction(F function, O* object, bool bForce = false) 222 222 { 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) 224 224 { if (this->command_) { this->command_->pushFunctor(functor, bForce); } return *this; } 225 225 … … 245 245 246 246 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); 248 248 249 249 _ConsoleCommand& addShortcut(); … … 271 271 static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command); 272 272 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); 275 275 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; 279 279 280 280 void setObject(void* object); … … 286 286 bool bInitialized_; 287 287 const std::type_info& functionHeader_; 288 std::stack<Functor *> functorStack_;288 std::stack<FunctorPtr> functorStack_; 289 289 std::stack<void*> objectStack_; 290 290 }; 291 291 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) 293 293 { 294 294 return new _ConsoleCommand("", name, functor, bInitialized); 295 295 } 296 296 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) 298 298 { 299 299 return new _ConsoleCommand(group, name, functor, bInitialized); -
code/branches/consolecommands3/src/libraries/core/Event.cc
r7163 r7198 34 34 namespace orxonox 35 35 { 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 45 36 /** 46 37 @brief Processes an event (calls the set-function if the necessary conditions are met). -
code/branches/consolecommands3/src/libraries/core/Event.h
r6800 r7198 67 67 { 68 68 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) {} 71 70 72 71 void process(const Event& event, BaseObject* object); 73 72 74 Functor*getFunctor() const73 const FunctorPtr& getFunctor() const 75 74 { return this->statefunction_; } 76 75 … … 78 77 bool bProcessingEvent_; //!< This becomes true while the container processes an event (used to prevent loops) 79 78 int activeEvents_; //!< The number of events which affect this state and are currently active 80 Functor *statefunction_; //!< A functor to set the state79 FunctorPtr statefunction_; //!< A functor to set the state 81 80 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) 82 81 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 42 42 int Executor::instances_s = 0; 43 43 44 Executor::Executor( Functor*functor, const std::string& name)44 Executor::Executor(const FunctorPtr& functor, const std::string& name) 45 45 { 46 46 this->functor_ = functor; … … 51 51 Executor::~Executor() 52 52 { 53 delete this->functor_;54 53 --instances_s; COUT(0) << "executor --: " << instances_s << std::endl; 55 54 } -
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); -
code/branches/consolecommands3/src/libraries/core/Functor.h
r7196 r7198 89 89 class _CoreExport Functor 90 90 { 91 friend class SharedPtr<Functor>;92 93 91 public: 94 92 struct Type … … 215 213 216 214 217 inline Functor* createFunctor(Functor*functor)215 inline const FunctorPtr& createFunctor(const FunctorPtr& functor) 218 216 { 219 217 return functor; … … 424 422 \ 425 423 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))) \ 427 425 { \ 428 426 return new FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams) (functionPointer); \ … … 517 515 \ 518 516 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))) \ 520 518 { \ 521 519 return new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ … … 524 522 \ 525 523 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) \ 527 525 { \ 528 526 return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ … … 530 528 \ 531 529 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) \ 533 531 { \ 534 532 FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* functor = new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ … … 539 537 \ 540 538 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) \ 542 540 { \ 543 541 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 77 77 if (this->base_) 78 78 this->base_->unregisterWeakPtr(this); 79 if (this->callback_)80 delete this->callback_;81 79 82 80 } … … 168 166 } 169 167 170 inline void setCallback( Functor*callback)168 inline void setCallback(const FunctorPtr& callback) 171 169 { 172 170 this->callback_ = callback; 173 171 } 174 172 175 inline Functor* getFunctor() const173 inline const FunctorPtr& getCallback() const 176 174 { 177 175 return this->callback_; … … 189 187 T* pointer_; 190 188 OrxonoxClass* base_; 191 Functor *callback_;189 FunctorPtr callback_; 192 190 }; 193 191 -
code/branches/consolecommands3/src/libraries/core/input/InputState.h
r6746 r7198 150 150 void left(); 151 151 //! 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; } 153 153 //! 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; } 155 155 156 156 private: … … 172 172 //! Handler to be used for all joy sticks (needs to be saved in case another joy stick gets attached) 173 173 InputHandler* joyStickHandlerAll_; 174 Functor *enterFunctor_; //!< Functor to be executed on enter175 Functor *leaveFunctor_; //!< Functor to be executed on leave174 FunctorPtr enterFunctor_; //!< Functor to be executed on enter 175 FunctorPtr leaveFunctor_; //!< Functor to be executed on leave 176 176 }; 177 177 -
code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.cc
r6417 r7198 156 156 { 157 157 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)); 159 159 InputManager::getInstance().enterState("detector"); 160 160 this->command_ = command; -
code/branches/consolecommands3/src/libraries/core/input/KeyBinderManager.h
r6417 r7198 99 99 void unbind(const std::string& binding); //tolua_export 100 100 void tunbind(const std::string& binding); 101 inline void registerKeybindCallback( Functor* function) { this->callbackFunction_.reset(function); } // tolua_export101 inline void registerKeybindCallback(const FunctorPtr& function) { this->callbackFunction_ = function; } // tolua//_//export // <-- FIXME 102 102 103 103 private: … … 114 114 115 115 // keybind command related 116 shared_ptr<Functor> callbackFunction_;//! Function to be called when key was pressed after "keybind" command116 FunctorPtr callbackFunction_; //! Function to be called when key was pressed after "keybind" command 117 117 bool bBinding_; //! Tells whether a key binding process is active 118 118 bool bTemporary_; //! Stores tkeybind/keybind value -
code/branches/consolecommands3/src/libraries/core/input/KeyDetector.h
r6417 r7198 46 46 ~KeyDetector(); 47 47 48 void setCallback(const shared_ptr<Functor>& function) { this->callbackFunction_ = function; }48 void setCallback(const FunctorPtr& function) { this->callbackFunction_ = function; } 49 49 50 50 private: … … 55 55 void assignCommands(); 56 56 57 shared_ptr<Functor>callbackFunction_;57 FunctorPtr callbackFunction_; 58 58 InputState* inputState_; 59 59 static std::string callbackCommand_s; -
code/branches/consolecommands3/src/libraries/network/NetworkFunction.cc
r6417 r7198 68 68 69 69 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): 71 71 NetworkFunctionBase(name) 72 72 { … … 76 76 NetworkFunctionStatic::getFunctorMap()[p] = this; 77 77 NetworkFunctionStatic::getIdMap()[ this->getNetworkID() ] = this; 78 }79 80 NetworkFunctionStatic::~NetworkFunctionStatic()81 {82 delete this->functor_;83 78 } 84 79 -
code/branches/consolecommands3/src/libraries/network/NetworkFunction.h
r6417 r7198 102 102 class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase { 103 103 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); 106 105 107 106 inline void call(){ (*this->functor_)(); } … … 124 123 static std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& getFunctorMap(); 125 124 static std::map<uint32_t, NetworkFunctionStatic*>& getIdMap(); 126 FunctorStatic *functor_;125 FunctorStaticPtr functor_; 127 126 128 127 }; … … 155 154 template <class T> class NetworkMemberFunction: public NetworkMemberFunctionBase { 156 155 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); 159 157 160 158 inline void call(uint32_t objectID) … … 190 188 191 189 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 193 template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(const FunctorMemberPtr<T>& functor, const std::string& name, const NetworkFunctionPointer& p): 196 194 NetworkMemberFunctionBase(name, p), functor_(functor) 197 195 { 198 }199 template <class T> NetworkMemberFunction<T>::~NetworkMemberFunction()200 {201 delete this->functor_;202 196 } 203 197
Note: See TracChangeset
for help on using the changeset viewer.