]> git.saurik.com Git - wxWidgets.git/blob - include/wx/stopwatch.h
Store a pointer to the wxWindow in the wxWindowDC class
[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 // Created: 26.06.03 (extracted from wx/timer.h)
6 // RCS-ID: $Id$
7 // Copyright: (c) 1998-2003 wxWindows team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_STOPWATCH_H_
12 #define _WX_STOPWATCH_H_
13 //
14 // ----------------------------------------------------------------------------
15 // wxStopWatch: measure time intervals with up to 1ms resolution
16 // ----------------------------------------------------------------------------
17
18 #if wxUSE_STOPWATCH
19
20 class WXDLLIMPEXP_BASE wxStopWatch
21 {
22 public:
23 // ctor starts the stop watch
24 wxStopWatch() { m_pauseCount = 0; Start(); }
25
26 // start the stop watch at the moment t0
27 void Start(long t0 = 0);
28
29 // pause the stop watch
30 void Pause()
31 {
32 if ( !m_pauseCount++ )
33 m_pause = GetElapsedTime();
34 }
35
36 // resume it
37 void Resume()
38 {
39 wxASSERT_MSG( m_pauseCount > 0,
40 _T("Resuming stop watch which is not paused") );
41
42 if ( !--m_pauseCount )
43 Start(m_pause);
44 }
45
46 // get elapsed time since the last Start() in milliseconds
47 long Time() const;
48
49 protected:
50 // returns the elapsed time since t0
51 long GetElapsedTime() const;
52
53 private:
54 // the time of the last Start()
55 wxLongLong m_t0;
56
57 // the time of the last Pause() (only valid if m_pauseCount > 0)
58 long m_pause;
59
60 // if > 0, the stop watch is paused, otherwise it is running
61 int m_pauseCount;
62 };
63
64 #endif // wxUSE_STOPWATCH
65
66 #if wxUSE_LONGLONG
67
68 // Starts a global timer
69 // -- DEPRECATED: use wxStopWatch instead
70 void WXDLLIMPEXP_BASE wxStartTimer();
71
72 // Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime
73 // -- DEPRECATED: use wxStopWatch instead
74 long WXDLLIMPEXP_BASE wxGetElapsedTime(bool resetTimer = TRUE);
75
76 #endif // wxUSE_LONGLONG
77
78 // ----------------------------------------------------------------------------
79 // global time functions
80 // ----------------------------------------------------------------------------
81
82 // Get number of seconds since local time 00:00:00 Jan 1st 1970.
83 extern long WXDLLIMPEXP_BASE wxGetLocalTime();
84
85 // Get number of seconds since GMT 00:00:00, Jan 1st 1970.
86 extern long WXDLLIMPEXP_BASE wxGetUTCTime();
87
88 #if wxUSE_LONGLONG
89 // Get number of milliseconds since local time 00:00:00 Jan 1st 1970
90 extern wxLongLong WXDLLIMPEXP_BASE wxGetLocalTimeMillis();
91 #endif // wxUSE_LONGLONG
92
93 #define wxGetCurrentTime() wxGetLocalTime()
94
95 #endif // _WX_STOPWATCH_H_
96