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.
|
|
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.
|
|
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.
|
|
void | set_interval (int interval, std::function< void(Args...)> const &func, Args... args) const |
| Executes function func for every interval milliseconds.
|
|
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.
|
|
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.
|
|
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().
|
|
bool | is_stopped () const |
| Returns whether the timer has been stopped. If a timer is stopped, it cannot be restarted again.
|
|
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().
|
|
bool | is_paused () const |
| Returns whether the timer has been paused. After a timer is paused, it can be resumed by calling resume()
|
|
void | resume () |
| Resumes the timer. This will be effective only when the timer has been paused and not stopped.
|
|
|
static void | single_shot (int delay, std::function< void(Args...)> const &func, Args... args) |
| Executes function func after delay milliseconds.
|
|
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.
|
|
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.
|
|
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
- Tutorial_312_MultiThread/main.cpp, and Tutorial_406_CollisionDetection/main.cpp.
◆ is_paused()
◆ is_stopped()
template<class... Args>
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]
template<class... Args>
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.
- 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'. |
args | The arguments to be passed to the function func . |
- 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).
The built-in Easy3D viewer.
Definition viewer.h:63
◆ set_interval() [2/3]
template<class... Args>
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.
- 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'. |
args | The arguments to be passed to the function func . |
- 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]
template<class... Args>
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. |
args | The arguments to be passed to the function func . |
- 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
- Tutorial_312_MultiThread/main.cpp.
◆ set_timeout() [1/3]
template<class... Args>
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.
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'. |
args | The arguments to be passed to the function func . |
- 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]
template<class... Args>
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.
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'. |
args | The arguments to be passed to the function func . |
- 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]
template<class... Args>
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. |
args | The arguments to be passed to the function func . |
- 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).
◆ single_shot() [1/3]
template<class... Args>
template<class Class>
void single_shot |
( |
int | delay, |
|
|
Class * | inst, |
|
|
void(Class::* | func )(Args...), |
|
|
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'. |
args | The arguments to be passed to the function func . |
- 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]
template<class... Args>
template<class Class>
void single_shot |
( |
int | delay, |
|
|
Class const * | inst, |
|
|
void(Class::* | func )(Args...) const, |
|
|
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'. |
args | The arguments to be passed to the function func . |
- 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]
template<class... Args>
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. |
args | The arguments to be passed to the function func . |
- 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
- Tutorial_204_Viewer_Qt/main.cpp.
◆ 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:
- G:/3_code/Easy3D/easy3d/util/timer.h