1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-06-28 12:22:56 +03:00
gmenu2x/src/clock.h
Maarten ter Huurne 9e1f717d9b Made Clock destruction safe
SDL does not guard against the final callback still executing when the
call to remove the timer returns. So we have to make sure the object
we access on the callback is not prematurely destructed. This commit
uses shared_ptr and weak_ptr to ensure that.

Note that we sort-of have a singleton again, only now it is private
and safely destructed.
2013-08-09 03:13:02 +02:00

33 lines
565 B
C++

#ifndef __CLOCK_H__
#define __CLOCK_H__
#include <memory>
#include <string>
/**
* A keeper of wall clock time with minute accuracy.
* Sends a user event on every minute boundary, to force a repaint of the
* clock display.
*/
class Clock {
public:
/**
* Used by implementation; please ignore.
*/
class Timer;
Clock();
/**
* Gets a string representation of the current time.
* Uses 24-hour format if is24 is true, otherwise AM/PM.
*/
std::string getTime(bool is24 = true);
private:
std::shared_ptr<Timer> timer;
};
#endif /* __CLOCK_H__ */