]>
Commit | Line | Data |
---|---|---|
5fb98c22 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/stopwatch.h | |
3 | // Purpose: wxStopWatch and global time-related functions | |
4 | // Author: Julian Smart (wxTimer), Sylvain Bougnoux (wxStopWatch) | |
5 | // Created: 26.06.03 (extracted from wx/timer.h) | |
6 | // RCS-ID: $Id$ | |
99d80019 | 7 | // Copyright: (c) 1998-2003 Julian Smart, Sylvain Bougnoux |
65571936 | 8 | // Licence: wxWindows licence |
5fb98c22 VZ |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef _WX_STOPWATCH_H_ | |
12 | #define _WX_STOPWATCH_H_ | |
d5b12ad9 | 13 | |
2ecf902b | 14 | #include "wx/defs.h" |
d5b12ad9 VS |
15 | #include "wx/longlong.h" |
16 | ||
5fb98c22 VZ |
17 | // ---------------------------------------------------------------------------- |
18 | // wxStopWatch: measure time intervals with up to 1ms resolution | |
19 | // ---------------------------------------------------------------------------- | |
20 | ||
21 | #if wxUSE_STOPWATCH | |
22 | ||
bddd7a8d | 23 | class WXDLLIMPEXP_BASE wxStopWatch |
5fb98c22 VZ |
24 | { |
25 | public: | |
26 | // ctor starts the stop watch | |
27 | wxStopWatch() { m_pauseCount = 0; Start(); } | |
28 | ||
29 | // start the stop watch at the moment t0 | |
30 | void Start(long t0 = 0); | |
31 | ||
32 | // pause the stop watch | |
33 | void Pause() | |
34 | { | |
35 | if ( !m_pauseCount++ ) | |
36 | m_pause = GetElapsedTime(); | |
37 | } | |
38 | ||
39 | // resume it | |
40 | void Resume() | |
41 | { | |
42 | wxASSERT_MSG( m_pauseCount > 0, | |
43 | _T("Resuming stop watch which is not paused") ); | |
44 | ||
45 | if ( !--m_pauseCount ) | |
46 | Start(m_pause); | |
47 | } | |
48 | ||
49 | // get elapsed time since the last Start() in milliseconds | |
50 | long Time() const; | |
51 | ||
52 | protected: | |
53 | // returns the elapsed time since t0 | |
54 | long GetElapsedTime() const; | |
55 | ||
56 | private: | |
57 | // the time of the last Start() | |
58 | wxLongLong m_t0; | |
59 | ||
60 | // the time of the last Pause() (only valid if m_pauseCount > 0) | |
61 | long m_pause; | |
62 | ||
63 | // if > 0, the stop watch is paused, otherwise it is running | |
64 | int m_pauseCount; | |
65 | }; | |
66 | ||
67 | #endif // wxUSE_STOPWATCH | |
68 | ||
69 | #if wxUSE_LONGLONG | |
70 | ||
71 | // Starts a global timer | |
72 | // -- DEPRECATED: use wxStopWatch instead | |
bddd7a8d | 73 | void WXDLLIMPEXP_BASE wxStartTimer(); |
5fb98c22 VZ |
74 | |
75 | // Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime | |
76 | // -- DEPRECATED: use wxStopWatch instead | |
d775fa82 | 77 | long WXDLLIMPEXP_BASE wxGetElapsedTime(bool resetTimer = true); |
5fb98c22 VZ |
78 | |
79 | #endif // wxUSE_LONGLONG | |
80 | ||
81 | // ---------------------------------------------------------------------------- | |
82 | // global time functions | |
83 | // ---------------------------------------------------------------------------- | |
84 | ||
85 | // Get number of seconds since local time 00:00:00 Jan 1st 1970. | |
bddd7a8d | 86 | extern long WXDLLIMPEXP_BASE wxGetLocalTime(); |
5fb98c22 VZ |
87 | |
88 | // Get number of seconds since GMT 00:00:00, Jan 1st 1970. | |
bddd7a8d | 89 | extern long WXDLLIMPEXP_BASE wxGetUTCTime(); |
5fb98c22 VZ |
90 | |
91 | #if wxUSE_LONGLONG | |
608f8a11 VZ |
92 | typedef wxLongLong wxMilliClock_t; |
93 | #else | |
94 | typedef double wxMilliClock_t; | |
5fb98c22 VZ |
95 | #endif // wxUSE_LONGLONG |
96 | ||
608f8a11 VZ |
97 | // Get number of milliseconds since local time 00:00:00 Jan 1st 1970 |
98 | extern wxMilliClock_t WXDLLIMPEXP_BASE wxGetLocalTimeMillis(); | |
99 | ||
5fb98c22 VZ |
100 | #define wxGetCurrentTime() wxGetLocalTime() |
101 | ||
102 | #endif // _WX_STOPWATCH_H_ | |
103 |