]>
Commit | Line | Data |
---|---|---|
5fb98c22 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/stopwatch.h | |
3 | // Purpose: wxStopWatch and global time-related functions | |
a43503cb VZ |
4 | // Author: Julian Smart (wxTimer), Sylvain Bougnoux (wxStopWatch), |
5 | // Vadim Zeitlin (time functions, current wxStopWatch) | |
5fb98c22 | 6 | // Created: 26.06.03 (extracted from wx/timer.h) |
99d80019 | 7 | // Copyright: (c) 1998-2003 Julian Smart, Sylvain Bougnoux |
a43503cb | 8 | // (c) 2011 Vadim Zeitlin |
65571936 | 9 | // Licence: wxWindows licence |
5fb98c22 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_STOPWATCH_H_ | |
13 | #define _WX_STOPWATCH_H_ | |
d5b12ad9 | 14 | |
2ecf902b | 15 | #include "wx/defs.h" |
d5b12ad9 VS |
16 | #include "wx/longlong.h" |
17 | ||
a43503cb VZ |
18 | // Time-related functions are also available via this header for compatibility |
19 | // but you should include wx/time.h directly if you need only them and not | |
20 | // wxStopWatch itself. | |
21 | #include "wx/time.h" | |
22 | ||
5fb98c22 VZ |
23 | // ---------------------------------------------------------------------------- |
24 | // wxStopWatch: measure time intervals with up to 1ms resolution | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
27 | #if wxUSE_STOPWATCH | |
28 | ||
bddd7a8d | 29 | class WXDLLIMPEXP_BASE wxStopWatch |
5fb98c22 VZ |
30 | { |
31 | public: | |
32 | // ctor starts the stop watch | |
33 | wxStopWatch() { m_pauseCount = 0; Start(); } | |
34 | ||
b0ec0023 VZ |
35 | // Start the stop watch at the moment t0 expressed in milliseconds (i.e. |
36 | // calling Time() immediately afterwards returns t0). This can be used to | |
37 | // restart an existing stopwatch. | |
5fb98c22 VZ |
38 | void Start(long t0 = 0); |
39 | ||
40 | // pause the stop watch | |
41 | void Pause() | |
42 | { | |
ac55e0a1 | 43 | if ( m_pauseCount++ == 0 ) |
b0ec0023 | 44 | m_elapsedBeforePause = GetCurrentClockValue() - m_t0; |
5fb98c22 VZ |
45 | } |
46 | ||
47 | // resume it | |
48 | void Resume() | |
49 | { | |
50 | wxASSERT_MSG( m_pauseCount > 0, | |
9a83f860 | 51 | wxT("Resuming stop watch which is not paused") ); |
5fb98c22 | 52 | |
ac55e0a1 | 53 | if ( --m_pauseCount == 0 ) |
b0ec0023 VZ |
54 | { |
55 | DoStart(); | |
56 | m_t0 -= m_elapsedBeforePause; | |
57 | } | |
5fb98c22 VZ |
58 | } |
59 | ||
b0ec0023 VZ |
60 | // Get elapsed time since the last Start() in microseconds. |
61 | wxLongLong TimeInMicro() const; | |
5fb98c22 | 62 | |
b0ec0023 VZ |
63 | // get elapsed time since the last Start() in milliseconds |
64 | long Time() const { return (TimeInMicro()/1000).ToLong(); } | |
5fb98c22 VZ |
65 | |
66 | private: | |
b0ec0023 VZ |
67 | // Really starts the stop watch. The initial time is set to current clock |
68 | // value. | |
69 | void DoStart(); | |
70 | ||
71 | // Returns the current clock value in its native units. | |
72 | wxLongLong GetCurrentClockValue() const; | |
73 | ||
74 | // Return the frequency of the clock used in its ticks per second. | |
75 | wxLongLong GetClockFreq() const; | |
76 | ||
77 | ||
78 | // The clock value when the stop watch was last started. Its units vary | |
79 | // depending on the platform. | |
5fb98c22 VZ |
80 | wxLongLong m_t0; |
81 | ||
b0ec0023 VZ |
82 | // The elapsed time as of last Pause() call (only valid if m_pauseCount > |
83 | // 0) in the same units as m_t0. | |
84 | wxLongLong m_elapsedBeforePause; | |
5fb98c22 VZ |
85 | |
86 | // if > 0, the stop watch is paused, otherwise it is running | |
87 | int m_pauseCount; | |
88 | }; | |
89 | ||
90 | #endif // wxUSE_STOPWATCH | |
91 | ||
40ff126a | 92 | #if wxUSE_LONGLONG && WXWIN_COMPATIBILITY_2_6 |
5fb98c22 | 93 | |
40ff126a WS |
94 | // Starts a global timer |
95 | // -- DEPRECATED: use wxStopWatch instead | |
96 | wxDEPRECATED( void WXDLLIMPEXP_BASE wxStartTimer() ); | |
5fb98c22 | 97 | |
40ff126a WS |
98 | // Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime |
99 | // -- DEPRECATED: use wxStopWatch instead | |
100 | wxDEPRECATED( long WXDLLIMPEXP_BASE wxGetElapsedTime(bool resetTimer = true) ); | |
5fb98c22 | 101 | |
40ff126a | 102 | #endif // wxUSE_LONGLONG && WXWIN_COMPATIBILITY_2_6 |
5fb98c22 | 103 | |
5fb98c22 | 104 | #endif // _WX_STOPWATCH_H_ |