Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Timer.h

Go to the documentation of this file.
00001 /*  Timer.h - high frequency timer wrapper
00002     Copyright (C) 2001-2005 Mark Weaver
00003     Written by Mark Weaver <mark@npsl.co.uk>
00004 
00005     Part of the Open-Win32 library.
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public
00017     License along with this library; if not, write to the
00018     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA  02111-1307, USA.
00020 */
00021 
00026 #ifndef OW32_Timer_h
00027 #define OW32_Timer_h
00028 
00029 #include <OW32/OW32Libs.h>
00030 
00031 namespace OW32
00032 {
00033 
00037 class OW32_LIB_EXPORT CTimer
00038 {
00039 private:
00041     LARGE_INTEGER   m_liStart;
00043     LARGE_INTEGER   m_liStop;
00044 
00048     class OW32_LIB_EXPORT CTimerFrequency
00049     {
00050     private:
00052         LARGE_INTEGER m_liFreq;
00053 
00054     public:
00058         CTimerFrequency()
00059         {
00060             // Avoid divz on failure
00061             if (!QueryPerformanceFrequency(&m_liFreq))
00062                 m_liFreq.QuadPart = 1;
00063         }
00064 
00070         __int64 GetFrequency() { return m_liFreq.QuadPart; }
00071     };
00072 
00074     static CTimerFrequency m_sTimerFreq;
00075 
00076 public:
00082     BOOL Start()
00083     {
00084         return QueryPerformanceCounter(&m_liStart);
00085     }
00086 
00092     BOOL Stop()
00093     {
00094         return QueryPerformanceCounter(&m_liStop);
00095     }
00096 
00102     double Elapsed() const
00103     {
00104         return (double)(m_liStop.QuadPart-m_liStart.QuadPart)/m_sTimerFreq.GetFrequency();
00105     }
00106 };
00107 
00108 } // namespace OW32
00109 
00110 #endif // OW32_Timer_h

Generated on Sun Jun 5 01:29:18 2005 for OW32 by  doxygen 1.3.9.1