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)
7 // Copyright: (c) 1998-2003 Julian Smart, Sylvain Bougnoux
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_STOPWATCH_H_
12 #define _WX_STOPWATCH_H_
15 #include "wx/longlong.h"
17 // ----------------------------------------------------------------------------
18 // wxStopWatch: measure time intervals with up to 1ms resolution
19 // ----------------------------------------------------------------------------
23 class WXDLLIMPEXP_BASE wxStopWatch
26 // ctor starts the stop watch
27 wxStopWatch() { m_pauseCount
= 0; Start(); }
29 // start the stop watch at the moment t0
30 void Start(long t0
= 0);
32 // pause the stop watch
35 if ( m_pauseCount
++ == 0 )
36 m_pause
= GetElapsedTime();
42 wxASSERT_MSG( m_pauseCount
> 0,
43 wxT("Resuming stop watch which is not paused") );
45 if ( --m_pauseCount
== 0 )
49 // get elapsed time since the last Start() in milliseconds
53 // returns the elapsed time since t0
54 long GetElapsedTime() const;
57 // the time of the last Start()
60 // the time of the last Pause() (only valid if m_pauseCount > 0)
63 // if > 0, the stop watch is paused, otherwise it is running
67 #endif // wxUSE_STOPWATCH
69 #if wxUSE_LONGLONG && WXWIN_COMPATIBILITY_2_6
71 // Starts a global timer
72 // -- DEPRECATED: use wxStopWatch instead
73 wxDEPRECATED( void WXDLLIMPEXP_BASE
wxStartTimer() );
75 // Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime
76 // -- DEPRECATED: use wxStopWatch instead
77 wxDEPRECATED( long WXDLLIMPEXP_BASE
wxGetElapsedTime(bool resetTimer
= true) );
79 #endif // wxUSE_LONGLONG && WXWIN_COMPATIBILITY_2_6
81 // ----------------------------------------------------------------------------
82 // global time functions
83 // ----------------------------------------------------------------------------
85 // Get number of seconds since local time 00:00:00 Jan 1st 1970.
86 extern long WXDLLIMPEXP_BASE
wxGetLocalTime();
88 // Get number of seconds since GMT 00:00:00, Jan 1st 1970.
89 extern long WXDLLIMPEXP_BASE
wxGetUTCTime();
92 typedef wxLongLong wxMilliClock_t
;
93 inline long wxMilliClockToLong(wxLongLong ll
) { return ll
.ToLong(); }
95 typedef double wxMilliClock_t
;
96 inline long wxMilliClockToLong(double d
) { return wx_truncate_cast(long, d
); }
97 #endif // wxUSE_LONGLONG
99 // Get number of milliseconds since local time 00:00:00 Jan 1st 1970
100 extern wxMilliClock_t WXDLLIMPEXP_BASE
wxGetLocalTimeMillis();
102 #define wxGetCurrentTime() wxGetLocalTime()
104 // on some really old systems gettimeofday() doesn't have the second argument,
105 // define wxGetTimeOfDay() to hide this difference
106 #ifdef HAVE_GETTIMEOFDAY
107 #ifdef WX_GETTIMEOFDAY_NO_TZ
108 #define wxGetTimeOfDay(tv) gettimeofday(tv)
110 #define wxGetTimeOfDay(tv) gettimeofday((tv), NULL)
112 #endif // HAVE_GETTIMEOFDAY
114 #endif // _WX_STOPWATCH_H_