Easy3D 2.6.1
Loading...
Searching...
No Matches
Timer< Args > Class Template Reference

A light-weight implementation of the timer mechanism. More...

#include <easy3d/util/timer.h>

Public Member Functions

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 Public Member Functions

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.
 

Detailed Description

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.

Member Function Documentation

◆ is_paused()

template<class... Args>
bool is_paused ( ) const
inline

Returns whether the timer has been paused. After a timer is paused, it can be resumed by calling resume()

See also
pause(), resume(), is_stopped().

◆ 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()

template<class... Args>
void pause ( )
inline

Pauses the timer. After a timer is paused, it can be resumed by calling resume(). You can permanently stop the timer by stop().

See also
is_paused(), resume(), stop().

◆ resume()

template<class... Args>
void resume ( )
inline

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
intervalThe interval, in milliseconds.
instThe pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class.
funcThe pointer to the member function of inst, e.g., '&Class::foo'.
argsThe 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
intervalThe interval, in milliseconds.
instThe pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class.
funcThe pointer to the member function of inst, e.g., '&Class::foo'.
argsThe 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
intervalThe interval, in milliseconds.
funcThe pointer to the function.
argsThe 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
delayThe time to be delayed, in milliseconds.
instThe pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class.
funcThe pointer to the member function of inst, e.g., '&Class::foo'.
argsThe 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
delayThe time to be delayed, in milliseconds.
instThe pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class.
funcThe pointer to the member function of inst, e.g., '&Class::foo'.
argsThe 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
delayThe time to be delayed, in milliseconds.
funcThe pointer to the function.
argsThe 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
delayThe time to be delayed, in milliseconds.
instThe pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class.
funcThe pointer to the member function of inst, e.g., '&Class::foo'.
argsThe 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
delayThe time to be delayed, in milliseconds.
instThe pointer to Class instance, e.g., '&a' for 'Class a' or 'this' within Class.
funcThe pointer to the member function of inst, e.g., '&Class::foo'.
argsThe 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
funcThe pointer to the function.
delayThe time to be delayed, in milliseconds.
argsThe 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()

template<class... Args>
void stop ( )
inline

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: