From f417270df130ad039b28d37748a8a7d03f576ee9 Mon Sep 17 00:00:00 2001 From: ponchio Date: Tue, 20 Jul 2004 14:03:47 +0000 Subject: [PATCH] Changed interface. --- apps/nexus/stopwatch.cpp | 47 ++++++++++++++++++++++++++-------------- apps/nexus/stopwatch.h | 8 +++++-- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/apps/nexus/stopwatch.cpp b/apps/nexus/stopwatch.cpp index cf0a4bfc..cfd20c07 100644 --- a/apps/nexus/stopwatch.cpp +++ b/apps/nexus/stopwatch.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.2 2004/07/05 15:49:39 ponchio +Windows (DevCpp, mingw) port. + Revision 1.1 2004/07/01 21:38:30 ponchio First draft created. @@ -31,23 +34,27 @@ First draft created. ****************************************************************************/ #include "stopwatch.h" -StopWatch::StopWatch(): elapsed(0) {} - -#ifdef WIN32 -void StopWatch::Start(void) { - static int first = 1; - if(first) { +StopWatch::StopWatch(): elapsed(0) { QueryPerformanceFrequency(&freq); - first = 0; - } - QueryPerformanceCounter(&tstart); } -void StopWatch::Stop() { +#ifdef WIN32 +double StopWatch::Start(void) { + QueryPerformanceCounter(&tstart); + return elapsed; +} + +double StopWatch::Pause() { QueryPerformanceCounter(&tend); elapsed += Diff(); + return elapsed; } +double StopWatch::Elapsed() { + QueryPerformanceCounter(&tend); + return elapsed + Diff(); +} + double StopWatch::Diff() { return ((double)tend.QuadPart - (double)tstart.QuadPart)/ @@ -56,13 +63,20 @@ double StopWatch::Diff() { #else -void StopWatch::Start() { +double StopWatch::Start() { gettimeofday(&tstart, &tz); + return elapsed; } -void StopWatch::Stop() { +double StopWatch::Pause() { gettimeofday(&tend, &tz); elapsed += Diff(); + return elapsed; +} + +double StopWatch::Elapsed() { + gettimeofday(&tend, &tz); + return elapsed + Diff(); } double StopWatch::Diff() { @@ -72,12 +86,13 @@ double StopWatch::Diff() { } #endif -void StopWatch::Reset() { - elapsed = 0; +void StopWatch::Restart(void) { + elapsed = 0; + Start(); } -double StopWatch::Elapsed() { - return elapsed; +void StopWatch::Reset() { + elapsed = 0; } int StopWatch::Usec() { diff --git a/apps/nexus/stopwatch.h b/apps/nexus/stopwatch.h index d68688b0..2349dd3e 100644 --- a/apps/nexus/stopwatch.h +++ b/apps/nexus/stopwatch.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.2 2004/07/05 15:49:39 ponchio +Windows (DevCpp, mingw) port. + Revision 1.1 2004/07/01 21:38:30 ponchio First draft created. @@ -40,8 +43,9 @@ First draft created. class StopWatch { public: StopWatch(); - void Start(); - void Stop(); + double Start(); + double Pause(); + void Restart(); void Reset(); double Elapsed(); int Usec();