fixed a bug in wxStopWatch::Pause() (wouldn't pause if called immediately after Start()) and changed Pause()/Resume() calls to nest
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15051 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -26,6 +26,8 @@ wxBase:
|
|||||||
documentation for details and revise your code accordingly: this change was
|
documentation for details and revise your code accordingly: this change was
|
||||||
unfortunately needed as the old class didn't behave correctly in all cases
|
unfortunately needed as the old class didn't behave correctly in all cases
|
||||||
|
|
||||||
|
- small change to wxStopWatch::Pause() semantics, please see the documentation
|
||||||
|
|
||||||
All (GUI):
|
All (GUI):
|
||||||
|
|
||||||
- the event type constants are not constants any more but are dynamically
|
- the event type constants are not constants any more but are dynamically
|
||||||
|
@@ -1,6 +1,19 @@
|
|||||||
\section{\class{wxStopWatch}}\label{wxstopwatch}
|
\section{\class{wxStopWatch}}\label{wxstopwatch}
|
||||||
|
|
||||||
The wxStopWatch class allow you to measure time intervals.
|
The wxStopWatch class allow you to measure time intervals. For example, you may
|
||||||
|
use it to measure the time elapsed by some function:
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
wxStopWatch sw;
|
||||||
|
CallLongRunningFunction();
|
||||||
|
wxLogMessage("The long running function took %ldms to execute",
|
||||||
|
sw.Time());
|
||||||
|
sw.Pause();
|
||||||
|
... stopwatch is stopped now ...
|
||||||
|
sw.Resume();
|
||||||
|
CallLongRunningFunction();
|
||||||
|
wxLogMessage("And calling it twice took $ldms in all", sw.Time());
|
||||||
|
\end{verbatim}
|
||||||
|
|
||||||
\wxheading{Include files}
|
\wxheading{Include files}
|
||||||
|
|
||||||
@@ -25,17 +38,22 @@ Constructor. This starts the stop watch.
|
|||||||
Pauses the stop watch. Call \helpref{wxStopWatch::Resume}{wxstopwatchresume} to resume
|
Pauses the stop watch. Call \helpref{wxStopWatch::Resume}{wxstopwatchresume} to resume
|
||||||
time measuring again.
|
time measuring again.
|
||||||
|
|
||||||
\membersection{wxStopWatch::Start}
|
If this method is called several times, {\tt Resume()} must be called the same
|
||||||
|
number of times to really resume the stop watch. You may, however, call
|
||||||
\func{void}{Start}{\param{long}{ milliseconds = 0}}
|
\helpref{Start}{wxstopwatchstart} to resume it unconditionally.
|
||||||
|
|
||||||
(Re)starts the stop watch with a given initial value.
|
|
||||||
|
|
||||||
\membersection{wxStopWatch::Resume}\label{wxstopwatchresume}
|
\membersection{wxStopWatch::Resume}\label{wxstopwatchresume}
|
||||||
|
|
||||||
\func{void}{Resume}{\void}
|
\func{void}{Resume}{\void}
|
||||||
|
|
||||||
Resumes the stop watch after having been paused with \helpref{wxStopWatch::Pause}{wxstopwatchpause}.
|
Resumes the stop watch which had been paused with
|
||||||
|
\helpref{wxStopWatch::Pause}{wxstopwatchpause}.
|
||||||
|
|
||||||
|
\membersection{wxStopWatch::Start}\label{wxstopwatchstart}
|
||||||
|
|
||||||
|
\func{void}{Start}{\param{long}{ milliseconds = 0}}
|
||||||
|
|
||||||
|
(Re)starts the stop watch with a given initial value.
|
||||||
|
|
||||||
\membersection{wxStopWatch::Time}
|
\membersection{wxStopWatch::Time}
|
||||||
|
|
||||||
|
@@ -191,12 +191,18 @@ class WXDLLEXPORT wxStopWatch
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// ctor starts the stop watch
|
// ctor starts the stop watch
|
||||||
wxStopWatch() { Start(); }
|
wxStopWatch() { m_pauseCount = 0; Start(); }
|
||||||
void Start(long t = 0);
|
|
||||||
void Pause() { m_pause = GetElapsedTime(); }
|
|
||||||
void Resume() { Start(m_pause); }
|
|
||||||
|
|
||||||
// get elapsed time since the last Start() or Pause() in milliseconds
|
// start the stop watch at the moment t0
|
||||||
|
void Start(long t0 = 0);
|
||||||
|
|
||||||
|
// pause the stop watch
|
||||||
|
void Pause() { if ( !m_pauseCount++) m_pause = GetElapsedTime(); }
|
||||||
|
|
||||||
|
// resume it
|
||||||
|
void Resume() { if ( !--m_pauseCount ) Start(m_pause); }
|
||||||
|
|
||||||
|
// get elapsed time since the last Start() in milliseconds
|
||||||
long Time() const;
|
long Time() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -204,8 +210,14 @@ protected:
|
|||||||
long GetElapsedTime() const;
|
long GetElapsedTime() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxLongLong m_t0; // the time of the last Start()
|
// the time of the last Start()
|
||||||
long m_pause; // the time of the last Pause() or 0
|
wxLongLong m_t0;
|
||||||
|
|
||||||
|
// the time of the last Pause() (only valid if m_pauseCount > 0)
|
||||||
|
long m_pause;
|
||||||
|
|
||||||
|
// if > 0, the stop watch is paused, otherwise it is running
|
||||||
|
int m_pauseCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // wxUSE_STOPWATCH
|
#endif // wxUSE_STOPWATCH
|
||||||
|
@@ -91,7 +91,7 @@
|
|||||||
#undef TEST_ALL
|
#undef TEST_ALL
|
||||||
static const bool TEST_ALL = TRUE;
|
static const bool TEST_ALL = TRUE;
|
||||||
#else
|
#else
|
||||||
#define TEST_FILENAME
|
#define TEST_TIMER
|
||||||
|
|
||||||
static const bool TEST_ALL = FALSE;
|
static const bool TEST_ALL = FALSE;
|
||||||
#endif
|
#endif
|
||||||
@@ -3032,18 +3032,28 @@ static void TestStopWatch()
|
|||||||
puts("*** Testing wxStopWatch ***\n");
|
puts("*** Testing wxStopWatch ***\n");
|
||||||
|
|
||||||
wxStopWatch sw;
|
wxStopWatch sw;
|
||||||
printf("Sleeping 3 seconds...");
|
sw.Pause();
|
||||||
|
printf("Initially paused, after 2 seconds time is...");
|
||||||
|
fflush(stdout);
|
||||||
|
wxSleep(2);
|
||||||
|
printf("\t%ldms\n", sw.Time());
|
||||||
|
|
||||||
|
printf("Resuming stopwatch and sleeping 3 seconds...");
|
||||||
|
fflush(stdout);
|
||||||
|
sw.Resume();
|
||||||
wxSleep(3);
|
wxSleep(3);
|
||||||
printf("\telapsed time: %ldms\n", sw.Time());
|
printf("\telapsed time: %ldms\n", sw.Time());
|
||||||
|
|
||||||
sw.Pause();
|
sw.Pause();
|
||||||
printf("Sleeping 2 more seconds...");
|
printf("Pausing agan and sleeping 2 more seconds...");
|
||||||
|
fflush(stdout);
|
||||||
wxSleep(2);
|
wxSleep(2);
|
||||||
printf("\telapsed time: %ldms\n", sw.Time());
|
printf("\telapsed time: %ldms\n", sw.Time());
|
||||||
|
|
||||||
sw.Resume();
|
sw.Resume();
|
||||||
printf("And 3 more seconds...");
|
printf("Finally resuming and sleeping 2 more seconds...");
|
||||||
wxSleep(3);
|
fflush(stdout);
|
||||||
|
wxSleep(2);
|
||||||
printf("\telapsed time: %ldms\n", sw.Time());
|
printf("\telapsed time: %ldms\n", sw.Time());
|
||||||
|
|
||||||
wxStopWatch sw2;
|
wxStopWatch sw2;
|
||||||
@@ -3061,6 +3071,7 @@ static void TestStopWatch()
|
|||||||
}
|
}
|
||||||
|
|
||||||
putchar('.');
|
putchar('.');
|
||||||
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
puts(", ok.");
|
puts(", ok.");
|
||||||
|
@@ -161,12 +161,12 @@ void wxStopWatch::Start(long t)
|
|||||||
|
|
||||||
long wxStopWatch::GetElapsedTime() const
|
long wxStopWatch::GetElapsedTime() const
|
||||||
{
|
{
|
||||||
return (wxGetLocalTimeMillis() - m_t0).GetLo();
|
return (wxGetLocalTimeMillis() - m_t0).GetLo();
|
||||||
}
|
}
|
||||||
|
|
||||||
long wxStopWatch::Time() const
|
long wxStopWatch::Time() const
|
||||||
{
|
{
|
||||||
return (m_pause ? m_pause : GetElapsedTime());
|
return m_pauseCount ? m_pause : GetElapsedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_LONGLONG
|
#endif // wxUSE_LONGLONG
|
||||||
|
Reference in New Issue
Block a user