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