Changeset 5831 for code/branches/core5/src/libraries/tools/Timer.h
- Timestamp:
- Sep 28, 2009, 10:48:47 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/libraries/tools/Timer.h
r5798 r5831 40 40 ClassName(); 41 41 void functionName(); 42 Timer <ClassName>myTimer;42 Timer myTimer; 43 43 }; 44 44 … … 48 48 ClassName::ClassName() 49 49 { 50 myTimer.setTimer(interval_in_seconds, bLoop, this, createExecutor(createFunctor(&ClassName::functionName)));50 myTimer.setTimer(interval_in_seconds, bLoop, createExecutor(createFunctor(&ClassName::functionName, this))); 51 51 } 52 52 … … 69 69 namespace orxonox 70 70 { 71 class StaticTimer;72 71 void delay(float delay, const std::string& command); 73 72 void killdelays(); 74 void executeDelayedCommand( StaticTimer* timer, const std::string& command);73 void executeDelayedCommand(Timer* timer, const std::string& command); 75 74 76 //! T imerBase is the parent of the Timer class.77 class _ToolsExport Timer Base: public TimeFactorListener75 //! The Timer is a callback-object, calling a given function after a given time-interval. 76 class _ToolsExport Timer : public TimeFactorListener 78 77 { 79 78 public: 80 ~TimerBase(); 79 Timer(); 80 ~Timer(); 81 82 Timer(float interval, bool bLoop, Executor* executor, bool bKillAfterCall = false); 83 84 /** 85 @brief Initializes the Timer with given values. 86 @param interval The timer-interval in seconds 87 @param bLoop If true, the function gets called every 'interval' seconds 88 @param object The object owning the timer and the function 89 @param executor A executor of the function to call 90 */ 91 void setTimer(float interval, bool bLoop, Executor* executor, bool bKillAfterCall = false) 92 { 93 this->deleteExecutor(); 94 95 this->setInterval(interval); 96 this->bLoop_ = bLoop; 97 this->executor_ = executor; 98 this->bActive_ = true; 99 100 this->time_ = this->interval_; 101 this->bKillAfterCall_ = bKillAfterCall; 102 } 81 103 82 104 void run(); … … 116 138 void tick(const Clock& time); 117 139 118 pr otected:119 TimerBase();120 140 private: 141 void init(); 142 121 143 Executor* executor_; //!< The executor of the function that should be called when the time expires 122 144 … … 128 150 long long time_; //!< Internal variable, counting the time till the next function-call 129 151 }; 130 131 //! The Timer is a callback-object, calling a given function after a given time-interval.132 template <class T = BaseObject>133 class Timer : public TimerBase134 {135 public:136 Timer() {}137 138 /**139 @brief Constructor: Initializes the Timer with given values.140 @param interval The timer-interval in seconds141 @param bLoop If true, the function gets called every 'interval' seconds142 @param object The object owning the timer and the function143 @param exeuctor A executor of the function to call144 */145 template <class O>146 Timer(float interval, bool bLoop, T* object, ExecutorMember<O>* exeuctor, bool bKillAfterCall = false)147 {148 this->setTimer(interval, bLoop, object, exeuctor, bKillAfterCall);149 }150 151 /**152 @brief Initializes the Timer with given values.153 @param interval The timer-interval in seconds154 @param bLoop If true, the function gets called every 'interval' seconds155 @param object The object owning the timer and the function156 @param exeuctor A executor of the function to call157 */158 template <class O>159 void setTimer(float interval, bool bLoop, T* object, ExecutorMember<O>* executor, bool bKillAfterCall = false)160 {161 this->deleteExecutor();162 163 this->setInterval(interval);164 this->bLoop_ = bLoop;165 executor->setObject(object);166 this->executor_ = static_cast<Executor*>(executor);167 this->bActive_ = true;168 169 this->time_ = this->interval_;170 this->bKillAfterCall_ = bKillAfterCall;171 }172 };173 174 //! The StaticTimer is a callback-object, calling a static function after a given time-interval.175 class _ToolsExport StaticTimer : public TimerBase176 {177 public:178 StaticTimer() {}179 180 /**181 @brief Constructor: Initializes the Timer with given values.182 @param interval The timer-interval in seconds183 @param bLoop If true, the function gets called every 'interval' seconds184 @param exeuctor A executor of the function to call185 */186 StaticTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false)187 {188 this->setTimer(interval, bLoop, executor, bKillAfterCall);189 }190 191 /**192 @brief Initializes the Timer with given values.193 @param interval The timer-interval in seconds194 @param bLoop If true, the function gets called every 'interval' seconds195 @param object The object owning the timer and the function196 @param executor A executor of the function to call197 */198 void setTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false)199 {200 this->deleteExecutor();201 202 this->setInterval(interval);203 this->bLoop_ = bLoop;204 this->executor_ = executor;205 this->bActive_ = true;206 207 this->time_ = this->interval_;208 this->bKillAfterCall_ = bKillAfterCall;209 }210 };211 212 152 } 213 153
Note: See TracChangeset
for help on using the changeset viewer.