- Timestamp:
- Apr 12, 2018, 2:07:03 PM (7 years ago)
- Location:
- code/branches/ScriptableController_FS18
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController_FS18
- Property svn:mergeinfo changed
/code/branches/ScriptableController_HS17 (added) merged: 11462,11518-11519,11549,11552,11562,11583,11606,11638,11662,11673-11674,11684,11852,11854
- Property svn:mergeinfo changed
-
code/branches/ScriptableController_FS18/src/libraries/tools/Timer.cc
r11071 r11855 158 158 } 159 159 160 Timer::Timer(float interval, bool bLoop, std::function<void ()> func, bool bKillAfterCall) 161 { 162 this->init(); 163 RegisterObject(Timer); 164 165 this->setTimer(interval, bLoop, func, bKillAfterCall); 166 } 167 160 168 /** 161 169 @brief Initializes the Timer … … 193 201 this->executor_ = executor; 194 202 this->bActive_ = true; 203 this->isStdFunction_ = false; 195 204 196 205 this->time_ = this->interval_; 197 206 this->bKillAfterCall_ = bKillAfterCall; 198 207 199 executor->getFunctor()->setSafeMode(true); 208 if(executor != nullptr) 209 executor->getFunctor()->setSafeMode(true); 210 } 211 212 void Timer::setTimer(float interval, bool bLoop, std::function<void ()> func, bool bKillAfterCall) 213 { 214 // Without the cast, the call would be ambiguous, because nullptr is castable to 215 // both, ExecutorPtr and std::function. 216 this->setTimer(interval, bLoop, static_cast<ExecutorPtr>(nullptr), bKillAfterCall); 217 this->function_ = func; 218 this->isStdFunction_ = true; 200 219 } 201 220 … … 207 226 bool temp = this->bKillAfterCall_; // to avoid errors with bKillAfterCall_=false and an exutors which destroy the timer 208 227 209 (*this->executor_)(); 228 if(this->isStdFunction_) 229 this->function_(); 230 else 231 (*this->executor_)(); 210 232 211 233 if (temp) -
code/branches/ScriptableController_FS18/src/libraries/tools/Timer.h
r11071 r11855 108 108 109 109 Timer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false); 110 Timer(float interval, bool bLoop, std::function<void (void)> func, bool bKillAfterCall = false); 110 111 111 112 void setTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false); 113 void setTimer(float interval, bool bLoop, std::function<void (void)> func, bool bKillAfterCall = false); 112 114 113 115 void run(); … … 153 155 154 156 ExecutorPtr executor_; //!< The executor of the function that will be called when the time expires 157 std::function<void (void)> function_; 155 158 159 bool isStdFunction_; 156 160 long long interval_; //!< The time-interval in micro seconds 157 161 bool bLoop_; //!< If true, the executor gets called every @a interval seconds
Note: See TracChangeset
for help on using the changeset viewer.