Changeset 7375 for code/branches/doc/src/libraries/tools/Timer.h
- Timestamp:
- Sep 8, 2010, 1:39:02 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/doc/src/libraries/tools/Timer.h
r7307 r7375 27 27 */ 28 28 29 /*! 29 /** 30 @defgroup Timer Timer 31 @ingroup Tools 32 */ 33 34 /** 30 35 @file 31 @brief Definition and Implementation of the Timer class. 36 @ingroup Timer 37 @brief Declaration of the Timer class, used to call functions after a given time-interval. 32 38 33 The Timer is a callback-object, calling a given function after a given time-interval. 39 @anchor TimerExample 40 41 Timer is a helper class that executes a function after a given amount of time. 34 42 35 43 Usage: <br> 36 44 header.h: 37 45 @code 38 class ClassName 39 { 40 public: 41 ClassName(); 42 void functionName(); 43 Timer myTimer; 44 }; 46 class MyClass 47 { 48 public: 49 MyClass(); 50 void functionName(); 51 52 private: 53 Timer myTimer; 54 }; 45 55 @endcode 46 56 47 57 source.cc: 48 58 @code 49 59 #include "core/command/Executor.h" 50 60 51 ClassName::ClassName()52 53 myTimer.setTimer(interval_in_seconds, bLoop, createExecutor(createFunctor(&ClassName::functionName, this)));54 61 MyClass::MyClass() 62 { 63 myTimer.setTimer(3, false, createExecutor(createFunctor(&ClassName::myFunction, this))); 64 } 55 65 56 void ClassName::functionName() 57 { 58 whateveryouwant(); 59 something(else); 60 } 66 void MyClass::myFunction() 67 { 68 COUT(0) << "Hello World" << std::endl; 69 } 61 70 @endcode 71 72 The code in this example prints "Hello World" to the console, 3 seconds after creating 73 an instance of MyClass. 62 74 */ 63 75 … … 77 89 void executeDelayedCommand(Timer* timer, const std::string& command); 78 90 79 //! The Timer is a callback-object, calling a given function after a given time-interval. 91 /** 92 @brief Timer is a helper class that executes a function after a given amount of time. 93 94 @see See @ref TimerExample "Timer.h" for an example. 95 */ 80 96 class _ToolsExport Timer : public TimeFactorListener 81 97 { … … 86 102 87 103 /** 88 @brief Initializes the Timer with given values.89 @param interval The timer-interval in seconds90 @param bLoop If true, the function gets called every 'interval'seconds91 @param executor A executor of the function to call92 @param bKillAfterCall If true, the timer will be deleted after the function was executed104 @brief Initializes and starts the timer, which will call an executor after some time. 105 @param interval The timer-interval in seconds 106 @param bLoop If true, the executor gets called every @a interval seconds 107 @param executor The executor that will be called 108 @param bKillAfterCall If true, the timer will be deleted after the executor was called 93 109 */ 94 110 void setTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false) … … 105 121 void run(); 106 122 107 / ** @brief Starts the Timer: Function-call after 'interval' seconds. */123 /// Re-starts the Timer: The executor will be called after @a interval seconds. 108 124 inline void startTimer() 109 125 { this->bActive_ = true; this->time_ = this->interval_; } 110 / ** @brief Stops the Timer. */126 /// Stops the Timer. 111 127 inline void stopTimer() 112 128 { this->bActive_ = false; this->time_ = this->interval_; } 113 / ** @brief Pauses the Timer - it will continue with the actual state if you unpause it. */129 /// Pauses the Timer - it will continue with the actual state if you call unpauseTimer(). 114 130 inline void pauseTimer() 115 131 { this->bActive_ = false; } 116 / ** @brief Unpauses the Timer - continues with the given state. */132 /// Unpauses the Timer - continues with the given state. 117 133 inline void unpauseTimer() 118 134 { this->bActive_ = true; } 119 / ** @brief Returns true if the Timer is active (= not stoped, not paused). @return True = Time is active */135 /// Returns true if the Timer is active (neither stoped nor paused). 120 136 inline bool isActive() const 121 137 { return this->bActive_; } 122 / ** @brief Returns the remaining time until the Timer calls the function. @return The remaining time */138 /// Returns the remaining time until the Timer calls the executor. 123 139 inline float getRemainingTime() const 124 140 { return static_cast<float>(this->time_ / 1000000.0f); } 125 / ** @brief Gives the Timer some extra time. @param time The amount of extra time in seconds */141 /// Increases the remaining time of the Timer by the given amount of time (in seconds). 126 142 inline void addTime(float time) 127 143 { if (time > 0.0f) this->time_ += static_cast<long long>(time * 1000000.0f); } 128 / ** @brief Decreases the remaining time of the Timer. @param time The amount of time to remove */144 /// Decreases the remaining time of the Timer by the given amount of time (in seconds) 129 145 inline void removeTime(float time) 130 146 { if (time > 0.0f) this->time_ -= static_cast<long long>(time * 1000000.0f); } 131 / ** @brief Sets the interval of the Timer. @param interval The interval */147 /// Changes the calling interval. 132 148 inline void setInterval(float interval) 133 149 { this->interval_ = static_cast<long long>(interval * 1000000.0f); } 134 / ** @brief Sets bLoop to a given value. @param bLoop True = loop */150 /// Defines if the timer call the executor every @a interval seconds or only once. 135 151 inline void setLoop(bool bLoop) 136 152 { this->bLoop_ = bLoop; } … … 141 157 void init(); 142 158 143 ExecutorPtr executor_; //!< The executor of the function that shouldbe called when the time expires159 ExecutorPtr executor_; //!< The executor of the function that will be called when the time expires 144 160 145 161 long long interval_; //!< The time-interval in micro seconds 146 bool bLoop_; //!< If true, the function gets called every 'interval'seconds147 bool bActive_; //!< If true, the Timer ticks and calls the functionif the time's up148 bool bKillAfterCall_; //!< If true the timer gets deleted after it called the function162 bool bLoop_; //!< If true, the executor gets called every @a interval seconds 163 bool bActive_; //!< If true, the Timer ticks and calls the executor if the time's up 164 bool bKillAfterCall_; //!< If true the timer gets deleted after it expired and called the executor 149 165 150 long long time_; //!< Internal variable, counting the time till the next function-call166 long long time_; //!< Internal variable, counting the time untill the next executor-call 151 167 }; 152 168 }
Note: See TracChangeset
for help on using the changeset viewer.