Timer_win.cpp
Go to the documentation of this file.
00001 /*
00002  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
00003  *
00004  * Copyright 2007-2012 VTT Technical Research Centre of Finland
00005  *
00006  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
00007  *          <http://www.vtt.fi/multimedia/alvar.html>
00008  *
00009  * ALVAR is free software; you can redistribute it and/or modify it under the
00010  * terms of the GNU Lesser General Public License as published by the Free
00011  * Software Foundation; either version 2.1 of the License, or (at your option)
00012  * any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful, but WITHOUT
00015  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00017  * for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with ALVAR; if not, see
00021  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
00022  */
00023 
00024 #include "Timer_private.h"
00025 
00026 #include <windows.h>
00027 
00028 namespace alvar {
00029 
00030 class TimerPrivateData
00031 {
00032 public:
00033     TimerPrivateData()
00034         : mPerformanceQuerySupported(false)
00035         , mPerformanceFrequency()
00036         , mPerformanceStart()
00037         , mStart()
00038     {
00039     }
00040 
00041     bool mPerformanceQuerySupported;
00042     LARGE_INTEGER mPerformanceFrequency;
00043     LARGE_INTEGER mPerformanceStart;
00044     DWORD mStart;
00045 };
00046 
00047 TimerPrivate::TimerPrivate()
00048     : d(new TimerPrivateData())
00049 {
00050         QueryPerformanceFrequency(&d->mPerformanceFrequency);
00051         if (d->mPerformanceFrequency.QuadPart) {
00052         d->mPerformanceQuerySupported = true;
00053     }
00054 }
00055 
00056 TimerPrivate::~TimerPrivate()
00057 {
00058     delete d;
00059 }
00060 
00061 void TimerPrivate::start()
00062 {
00063     if (d->mPerformanceQuerySupported) {
00064         QueryPerformanceCounter(&d->mPerformanceStart);
00065     }
00066     else {
00067         d->mStart = GetTickCount();
00068     }
00069 }
00070 
00071 double TimerPrivate::stop()
00072 {
00073     if (d->mPerformanceQuerySupported) {
00074         LARGE_INTEGER stop;
00075         LARGE_INTEGER difference;
00076         QueryPerformanceCounter(&stop);
00077         difference.QuadPart = stop.QuadPart - d->mPerformanceStart.QuadPart;
00078         return double(difference.QuadPart) / d->mPerformanceFrequency.QuadPart;
00079     }
00080     else {
00081         return (GetTickCount() - d->mStart) / 1000.0;
00082     }
00083 }
00084 
00085 } // namespace alvar


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Thu Feb 16 2017 03:23:02