]> git.saurik.com Git - wxWidgets.git/blame - include/wx/stopwatch.h
A better fix for wxHash{Map,Set} with g++ 4.7.
[wxWidgets.git] / include / wx / stopwatch.h
CommitLineData
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
VZ
6// Created: 26.06.03 (extracted from wx/timer.h)
7// RCS-ID: $Id$
99d80019 8// Copyright: (c) 1998-2003 Julian Smart, Sylvain Bougnoux
a43503cb 9// (c) 2011 Vadim Zeitlin
65571936 10// Licence: wxWindows licence
5fb98c22
VZ
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef _WX_STOPWATCH_H_
14#define _WX_STOPWATCH_H_
d5b12ad9 15
2ecf902b 16#include "wx/defs.h"
d5b12ad9
VS
17#include "wx/longlong.h"
18
a43503cb
VZ
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
5fb98c22
VZ
24// ----------------------------------------------------------------------------
25// wxStopWatch: measure time intervals with up to 1ms resolution
26// ----------------------------------------------------------------------------
27
28#if wxUSE_STOPWATCH
29
bddd7a8d 30class WXDLLIMPEXP_BASE wxStopWatch
5fb98c22
VZ
31{
32public:
33 // ctor starts the stop watch
34 wxStopWatch() { m_pauseCount = 0; Start(); }
35
b0ec0023
VZ
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.
5fb98c22
VZ
39 void Start(long t0 = 0);
40
41 // pause the stop watch
42 void Pause()
43 {
ac55e0a1 44 if ( m_pauseCount++ == 0 )
b0ec0023 45 m_elapsedBeforePause = GetCurrentClockValue() - m_t0;
5fb98c22
VZ
46 }
47
48 // resume it
49 void Resume()
50 {
51 wxASSERT_MSG( m_pauseCount > 0,
9a83f860 52 wxT("Resuming stop watch which is not paused") );
5fb98c22 53
ac55e0a1 54 if ( --m_pauseCount == 0 )
b0ec0023
VZ
55 {
56 DoStart();
57 m_t0 -= m_elapsedBeforePause;
58 }
5fb98c22
VZ
59 }
60
b0ec0023
VZ
61 // Get elapsed time since the last Start() in microseconds.
62 wxLongLong TimeInMicro() const;
5fb98c22 63
b0ec0023
VZ
64 // get elapsed time since the last Start() in milliseconds
65 long Time() const { return (TimeInMicro()/1000).ToLong(); }
5fb98c22
VZ
66
67private:
b0ec0023
VZ
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.
5fb98c22
VZ
81 wxLongLong m_t0;
82
b0ec0023
VZ
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;
5fb98c22
VZ
86
87 // if > 0, the stop watch is paused, otherwise it is running
88 int m_pauseCount;
89};
90
91#endif // wxUSE_STOPWATCH
92
40ff126a 93#if wxUSE_LONGLONG && WXWIN_COMPATIBILITY_2_6
5fb98c22 94
40ff126a
WS
95 // Starts a global timer
96 // -- DEPRECATED: use wxStopWatch instead
97 wxDEPRECATED( void WXDLLIMPEXP_BASE wxStartTimer() );
5fb98c22 98
40ff126a
WS
99 // Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime
100 // -- DEPRECATED: use wxStopWatch instead
101 wxDEPRECATED( long WXDLLIMPEXP_BASE wxGetElapsedTime(bool resetTimer = true) );
5fb98c22 102
40ff126a 103#endif // wxUSE_LONGLONG && WXWIN_COMPATIBILITY_2_6
5fb98c22 104
5fb98c22 105#endif // _WX_STOPWATCH_H_