cpp-sdl2
C++ header-only SDL2 wrapper
sdl::Timer Class Reference

Represent an SDL timer. More...

#include <timer.hpp>

Public Types

using Callback = SDL_TimerCallback
 Just so that the type of a callback function can be. More...
 

Public Member Functions

 Timer ()=delete
 A timer object that is not tied to a timer id in SDL doesn't make senes. More...
 
bool remove ()
 Remove the timer, return true if timer was removed. More...
 
SDL_TimerID timer_id () const
 Get the id of this timer. More...
 
 operator SDL_TimerID () const
 

Static Public Member Functions

static Timer create (uint32_t interval, Callback function, void *user_context)
 Factory function. More...
 
static Timer create (std::chrono::milliseconds interval, Callback function, void *user_context)
 Factory function using std::chrono. More...
 
static void delay (std::chrono::milliseconds millisec)
 Wait for millisec milliseconds. More...
 
static void delay (uint32_t millisec)
 Wait for millisec milliseconds. More...
 
static uint32_t ticks_u32 ()
 Returns the number of milliseconds elapsed as a unint32_t (standard SDL API) More...
 
static std::chrono::milliseconds ticks ()
 Retruns the number of milliseconds. More...
 
static uint64_t perf_counter ()
 Return the performance counter value. More...
 
static uint64_t perf_frequency ()
 Return the performace frequency value. More...
 

Private Member Functions

 Timer (SDL_TimerID timer)
 construct More...
 

Private Attributes

SDL_TimerID timer_ = 0
 

Detailed Description

Represent an SDL timer.

Definition at line 12 of file timer.hpp.

Member Typedef Documentation

◆ Callback

using sdl::Timer::Callback = SDL_TimerCallback

Just so that the type of a callback function can be.

Definition at line 24 of file timer.hpp.

Constructor & Destructor Documentation

◆ Timer() [1/2]

sdl::Timer::Timer ( SDL_TimerID  timer)
inlineprivate

construct

Definition at line 17 of file timer.hpp.

References Timer().

◆ Timer() [2/2]

sdl::Timer::Timer ( )
delete

A timer object that is not tied to a timer id in SDL doesn't make senes.

Referenced by Timer().

Member Function Documentation

◆ create() [1/2]

static Timer sdl::Timer::create ( uint32_t  interval,
Callback  function,
void *  user_context 
)
inlinestatic

Factory function.

Definition at line 36 of file timer.hpp.

Referenced by create().

◆ create() [2/2]

static Timer sdl::Timer::create ( std::chrono::milliseconds  interval,
Callback  function,
void *  user_context 
)
inlinestatic

Factory function using std::chrono.

Definition at line 49 of file timer.hpp.

References create().

◆ delay() [1/2]

static void sdl::Timer::delay ( std::chrono::milliseconds  millisec)
inlinestatic

Wait for millisec milliseconds.

Definition at line 55 of file timer.hpp.

◆ delay() [2/2]

static void sdl::Timer::delay ( uint32_t  millisec)
inlinestatic

Wait for millisec milliseconds.

Definition at line 62 of file timer.hpp.

◆ operator SDL_TimerID()

sdl::Timer::operator SDL_TimerID ( ) const
inline

Definition at line 79 of file timer.hpp.

References timer_id().

◆ perf_counter()

static uint64_t sdl::Timer::perf_counter ( )
inlinestatic

Return the performance counter value.

Definition at line 71 of file timer.hpp.

◆ perf_frequency()

static uint64_t sdl::Timer::perf_frequency ( )
inlinestatic

Return the performace frequency value.

Definition at line 74 of file timer.hpp.

◆ remove()

bool sdl::Timer::remove ( )
inline

Remove the timer, return true if timer was removed.

Definition at line 27 of file timer.hpp.

◆ ticks()

static std::chrono::milliseconds sdl::Timer::ticks ( )
inlinestatic

Retruns the number of milliseconds.

Definition at line 68 of file timer.hpp.

Referenced by ticks_u32().

◆ ticks_u32()

static uint32_t sdl::Timer::ticks_u32 ( )
inlinestatic

Returns the number of milliseconds elapsed as a unint32_t (standard SDL API)

Definition at line 65 of file timer.hpp.

References ticks().

◆ timer_id()

SDL_TimerID sdl::Timer::timer_id ( ) const
inline

Get the id of this timer.

Definition at line 77 of file timer.hpp.

References timer_.

Referenced by operator SDL_TimerID().

Member Data Documentation

◆ timer_

SDL_TimerID sdl::Timer::timer_ = 0
private

Definition at line 14 of file timer.hpp.

Referenced by timer_id().


The documentation for this class was generated from the following file: