A light-weight implementation of the timer mechanism.
More...
#include <easy3d/util/timer.h>
|
void | set_timeout (int delay, std::function< void(Args...)> const &func, Args... args) const |
| Executes function func after delay milliseconds. More...
|
|
template<class Class > |
void | set_timeout (int delay, Class *inst, void(Class::*func)(Args...), Args... args) const |
| Executes a member function func of Class inst after delay milliseconds. More...
|
|
template<class Class > |
void | set_timeout (int delay, Class const *inst, void(Class::*func)(Args...) const, Args... args) const |
| Executes a const member function func of Class inst after delay milliseconds. More...
|
|
void | set_interval (int interval, std::function< void(Args...)> const &func, Args... args) const |
| Executes function func for every interval milliseconds. More...
|
|
template<class Class > |
void | set_interval (int interval, Class *inst, void(Class::*func)(Args...), Args... args) const |
| Executes a member function func of Class inst for every interval milliseconds. More...
|
|
template<class Class > |
void | set_interval (int interval, Class const *inst, void(Class::*func)(Args...) const, Args... args) const |
| Executes a const member function func of Class inst for every interval milliseconds. More...
|
|
void | stop () |
| Stops the timer. After a timer is stopped, it cannot be restarted again. If you want to temporarily pause a timer, call pause(). More...
|
|
bool | is_stopped () const |
| Returns whether the timer has been stopped. If a timer is stopped, it cannot be restarted again. More...
|
|
void | pause () |
| Pauses the timer. After a timer is paused, it can be resumed by calling resume(). You can permanently stop the timer by stop(). More...
|
|
bool | is_paused () const |
| Returns whether the timer has been paused. After a timer is paused, it can be resumed by calling resume() More...
|
|
void | resume () |
| Resumes the timer. This will be effective only when the timer has been paused and not stopped. More...
|
|
|
static void | single_shot (int delay, std::function< void(Args...)> const &func, Args... args) |
| Executes function func after delay milliseconds. More...
|
|
template<class Class > |
static void | single_shot (int delay, Class *inst, void(Class::*func)(Args...), Args... args) |
| Executes a member function func of Class inst after delay milliseconds. More...
|
|
template<class Class > |
static void | single_shot (int delay, Class const *inst, void(Class::*func)(Args...) const, Args... args) |
| Executes a const member function func of Class inst after delay milliseconds. More...
|
|
template<class... Args>
class easy3d::Timer< Args >
A light-weight implementation of the timer mechanism.
Timer functionalities are usually implemented in large libraries (e.g., the QTimer of Qt). This Timer class provides a single-header implementation. With Timer, tasks (i.e., calling to functions) can be easily scheduled at either constant intervals or after a specified period. Timer supports any types of functions with any number of arguments.
- Examples
- Test_Timer, Tutorial_312_MultiThread, Tutorial_406_CollisionDetection, and visualization_cross_section.
◆ is_paused()
◆ is_stopped()
bool is_stopped |
( |
| ) |
const |
|
inline |
Returns whether the timer has been stopped. If a timer is stopped, it cannot be restarted again.
- See also
- stop(), is_paused().
◆ pause()
◆ resume()
Resumes the timer. This will be effective only when the timer has been paused and not stopped.
- See also
- pause(), is_paused(), stop().
◆ set_interval() [1/3]
void set_interval |
( |
int |
interval, |
|
|
Class * |
inst, |
|
|
void(Class::*)(Args...) |
func, |
|
|
Args... |
args |
|
) |
| const |
Executes a member function func
of Class
inst
for every interval
milliseconds.
- Parameters
-
interval | The interval, in milliseconds. |
inst | The pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class. |
func | The pointer to the member function of inst , e.g., '&Class::foo'. |
- Note
- When a member function has overloads, explicitly cast the function to the right function type using e.g.,
static_cast<void (Viewer::*)(const std::string&, int)>(&Viewer::print).
◆ set_interval() [2/3]
void set_interval |
( |
int |
interval, |
|
|
Class const * |
inst, |
|
|
void(Class::*)(Args...) const |
func, |
|
|
Args... |
args |
|
) |
| const |
Executes a const member function func
of Class
inst
for every interval
milliseconds.
- Parameters
-
interval | The interval, in milliseconds. |
inst | The pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class. |
func | The pointer to the member function of inst , e.g., '&Class::foo'. |
- Note
- When a member function has overloads, explicitly cast the function to the right function type using e.g.,
static_cast<void (Viewer::*)(const std::string&, int)>(&Viewer::print).
◆ set_interval() [3/3]
void set_interval |
( |
int |
interval, |
|
|
std::function< void(Args...)> const & |
func, |
|
|
Args... |
args |
|
) |
| const |
Executes function func
for every interval
milliseconds.
- Parameters
-
interval | The interval, in milliseconds. |
func | The pointer to the function. |
- Note
- When a function has overloads, explicitly cast the function to the right function type using e.g.,
static_cast<void (*)(const std::string&, int)>(&print).
- Examples
- Test_Timer, and Tutorial_312_MultiThread.
◆ set_timeout() [1/3]
void set_timeout |
( |
int |
delay, |
|
|
Class * |
inst, |
|
|
void(Class::*)(Args...) |
func, |
|
|
Args... |
args |
|
) |
| const |
Executes a member function func
of Class
inst
after delay
milliseconds.
This is the same as single_shot() except that it is not static.
- Parameters
-
delay | The time to be delayed, in milliseconds. |
inst | The pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class. |
func | The pointer to the member function of inst , e.g., '&Class::foo'. |
- Note
- When a member function has overloads, explicitly cast the function to the right function type using e.g.,
static_cast<void (Viewer::*)(const std::string&, int)>(&Viewer::print).
◆ set_timeout() [2/3]
void set_timeout |
( |
int |
delay, |
|
|
Class const * |
inst, |
|
|
void(Class::*)(Args...) const |
func, |
|
|
Args... |
args |
|
) |
| const |
Executes a const member function func
of Class
inst
after delay
milliseconds.
This is the same as single_shot() except that it is not static.
- Parameters
-
delay | The time to be delayed, in milliseconds. |
inst | The pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class. |
func | The pointer to the member function of inst , e.g., '&Class::foo'.
|
- Note
- When a member function has overloads, explicitly cast the function to the right function type using e.g.,
static_cast<void (Viewer::*)(const std::string&, int)>(&Viewer::print).
◆ set_timeout() [3/3]
void set_timeout |
( |
int |
delay, |
|
|
std::function< void(Args...)> const & |
func, |
|
|
Args... |
args |
|
) |
| const |
Executes function func
after delay
milliseconds.
This is the same as single_shot() except that it is not static.
- Parameters
-
delay | The time to be delayed, in milliseconds. |
func | The pointer to the function.
|
- Note
- When a function has overloads, explicitly cast the function to the right function type using e.g.,
static_cast<void (*)(const std::string&, int)>(&print).
- Examples
- Test_Timer.
◆ single_shot() [1/3]
void single_shot |
( |
int |
delay, |
|
|
Class * |
inst, |
|
|
void(Class::*)(Args...) |
func, |
|
|
Args... |
args |
|
) |
| |
|
static |
Executes a member function func
of Class
inst
after delay
milliseconds.
- Parameters
-
delay | The time to be delayed, in milliseconds. |
inst | The pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class. |
func | The pointer to the member function of inst , e.g., '&Class::foo'. |
- Note
- When a member function has overloads, explicitly cast the function to the right function type using e.g.,
static_cast<void (Viewer::*)(const std::string&, int)>(&Viewer::print).
◆ single_shot() [2/3]
void single_shot |
( |
int |
delay, |
|
|
Class const * |
inst, |
|
|
void(Class::*)(Args...) const |
func, |
|
|
Args... |
args |
|
) |
| |
|
static |
Executes a const member function func
of Class
inst
after delay
milliseconds.
- Parameters
-
delay | The time to be delayed, in milliseconds. |
inst | The pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class. |
func | The pointer to the member function of inst , e.g., '&Class::foo'. |
- Note
- When a member function has overloads, explicitly cast the function to the right function type using e.g.,
static_cast<void (Viewer::*)(const std::string&, int)>(&Viewer::print).
◆ single_shot() [3/3]
void single_shot |
( |
int |
delay, |
|
|
std::function< void(Args...)> const & |
func, |
|
|
Args... |
args |
|
) |
| |
|
static |
Executes function func
after delay
milliseconds.
- Parameters
-
func | The pointer to the function. |
delay | The time to be delayed, in milliseconds. |
- Note
- When a function has overloads, explicitly cast the function to the right function type using e.g.,
static_cast<void (*)(const std::string&, int)>(&print).
- Examples
- Test_Timer, and Tutorial_204_Viewer_Qt.
◆ stop()
Stops the timer. After a timer is stopped, it cannot be restarted again. If you want to temporarily pause a timer, call pause().
- See also
- is_stopped(), pause().
The documentation for this class was generated from the following file:
- /Users/lnan/Documents/Projects/Easy3D/easy3d/util/timer.h