Easy3D 2.5.3
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. 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 Public Member Functions

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...
 

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
Test_Timer, Tutorial_312_MultiThread, Tutorial_406_CollisionDetection, and visualization_cross_section.

Member Function Documentation

◆ is_paused()

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

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

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

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]

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
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'.
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
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'.
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
intervalThe interval, in milliseconds.
funcThe 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
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'.
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
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'.
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
delayThe time to be delayed, in milliseconds.
funcThe 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
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'.
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
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'.
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
funcThe pointer to the function.
delayThe 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()

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: