Coverage Report

Created: 2026-11-12 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wxwidgets/include/wx/stopwatch.h
Line
Count
Source
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
// Copyright:   (c) 1998-2003 Julian Smart, Sylvain Bougnoux
8
//              (c) 2011 Vadim Zeitlin
9
// Licence:     wxWindows licence
10
/////////////////////////////////////////////////////////////////////////////
11
12
#ifndef _WX_STOPWATCH_H_
13
#define _WX_STOPWATCH_H_
14
15
#include "wx/defs.h"
16
#include "wx/longlong.h"
17
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
23
// ----------------------------------------------------------------------------
24
// wxStopWatch: measure time intervals with up to 1ms resolution
25
// ----------------------------------------------------------------------------
26
27
#if wxUSE_STOPWATCH
28
29
class WXDLLIMPEXP_BASE wxStopWatch
30
{
31
public:
32
    // ctor starts the stop watch
33
0
    wxStopWatch() { m_pauseCount = 0; Start(); }
34
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.
38
    void Start(long t0 = 0);
39
40
    // pause the stop watch
41
    void Pause()
42
0
    {
43
0
        if ( m_pauseCount++ == 0 )
44
0
            m_elapsedBeforePause = GetCurrentClockValue() - m_t0;
45
0
    }
46
47
    // resume it
48
    void Resume()
49
0
    {
50
0
        wxASSERT_MSG( m_pauseCount > 0,
51
0
                      wxT("Resuming stop watch which is not paused") );
52
0
53
0
        if ( --m_pauseCount == 0 )
54
0
        {
55
0
            DoStart();
56
0
            m_t0 -= m_elapsedBeforePause;
57
0
        }
58
0
    }
59
60
    // Get elapsed time since the last Start() in microseconds.
61
    wxLongLong TimeInMicro() const;
62
63
    // get elapsed time since the last Start() in milliseconds
64
0
    long Time() const { return (TimeInMicro()/1000).ToLong(); }
65
66
private:
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.
80
    wxLongLong m_t0;
81
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;
85
86
    // if > 0, the stop watch is paused, otherwise it is running
87
    int m_pauseCount;
88
};
89
90
#endif // wxUSE_STOPWATCH
91
92
#endif // _WX_STOPWATCH_H_