diff --git a/src/OpenMesh/Tools/Utils/Timer.cc b/src/OpenMesh/Tools/Utils/Timer.cc index ee97db0d95e24dfed1c58904e89081c5236ab99f..a544793043dea89e56f5b793f38180848089ce13 100644 --- a/src/OpenMesh/Tools/Utils/Timer.cc +++ b/src/OpenMesh/Tools/Utils/Timer.cc @@ -63,13 +63,87 @@ namespace Utils { using namespace std; // -------------------------------------------------------------- TimerImpl ---- - +// just a base class for the implementation +class TimerImpl +{ +protected: +public: + TimerImpl() { ; } + virtual ~TimerImpl() { ; } + + virtual void reset(void) = 0; + virtual void start(void) = 0; + virtual void stop(void) = 0; + virtual void cont(void) = 0; + virtual double seconds(void) const = 0; +}; // compiler and os dependent implementation +// ------------------------------------------------------------- windows 32 ---- +#if defined(WIN32) && (defined(_MSC_VER) || defined(__INTEL_COMPILER)) + +#ifndef DOXY_IGNORE_THIS +#include +#endif + +class TimerImplWin32 : public TimerImpl +{ +protected: + LARGE_INTEGER freq_; + LARGE_INTEGER count_; + LARGE_INTEGER start_; + +public: + TimerImplWin32(void); + ~TimerImplWin32(void) { ; } + + virtual void reset(void); + virtual void start(void); + virtual void stop(void); + virtual void cont(void); + virtual double seconds(void) const; +}; + +TimerImplWin32::TimerImplWin32(void) +{ + if (QueryPerformanceFrequency(&freq_)==FALSE) + throw std::runtime_error("Performance counter of of stock!"); + reset(); +} + +void TimerImplWin32::reset(void) +{ + memset(&count_,0,sizeof(count_)); + memset(&start_,0,sizeof(count_)); +} + +void TimerImplWin32::start(void) +{ + reset(); + QueryPerformanceCounter(&start_); +} + +void TimerImplWin32::stop(void) +{ + LARGE_INTEGER stop_; + + QueryPerformanceCounter(&stop_); + count_.QuadPart += stop_.QuadPart - start_.QuadPart; +} + +void TimerImplWin32::cont(void) +{ + QueryPerformanceCounter(&start_); +} + +double TimerImplWin32::seconds(void) const +{ + return (double)count_.QuadPart/(double)freq_.QuadPart; +} // ------------------------------------------------------------- posix time ---- -#if defined(__GNUC__) && defined(__POSIX__) +#elif defined(__GNUC__) && defined(__POSIX__) #ifndef DOXY_IGNORE_THIS # include @@ -155,7 +229,7 @@ static const unsigned long clockticks = CLOCKS_PER_SEC; class TimerImplStd : public TimerImpl { public: - TimerImplStd() : freq_(clockticks),count_(0),start_(0) { reset(); } + TimerImplStd() : freq_(clockticks) { reset(); } ~TimerImplStd() { ; } virtual void reset(void) { count_ = 0; } @@ -180,9 +254,12 @@ void TimerImplStd::stop(void) // ----------------------------------------------------------------- Timer ---- +#if ! (defined(WIN32) && (defined(_MSC_VER) || defined(__INTEL_COMPILER))) Timer::Timer(void) { -#if defined(__GNUC__) && defined(__POSIX__) +#if defined(WIN32) && defined(_MSC_VER) + impl_ = new TimerImplWin32; +#elif defined(__GNUC__) && defined(__POSIX__) // CLOCK_REALTIME // CLOCK_MONOTONIC - ? // CLOCK_REALTIME_HR - RTlinux @@ -199,6 +276,7 @@ Timer::Timer(void) #endif state_ = Stopped; } +#endif Timer::~Timer(void) { diff --git a/src/OpenMesh/Tools/Utils/Timer.hh b/src/OpenMesh/Tools/Utils/Timer.hh index 731cf1cf84147459516548c8eb2ed3e83e6ce791..8d29d8f611e475b505470c94bc7e734d7b9f389d 100644 --- a/src/OpenMesh/Tools/Utils/Timer.hh +++ b/src/OpenMesh/Tools/Utils/Timer.hh @@ -70,20 +70,7 @@ namespace Utils { // -------------------------------------------------------------- forwards ---- -// just a base class for the implementation -class TimerImpl -{ -protected: -public: - TimerImpl() { ; } - virtual ~TimerImpl() { ; } - - virtual void reset(void) = 0; - virtual void start(void) = 0; - virtual void stop(void) = 0; - virtual void cont(void) = 0; - virtual double seconds(void) const = 0; -}; +class TimerImpl; // ----------------------------------------------------------------- class ---- diff --git a/src/OpenMesh/Tools/Utils/TimerWin32.cc b/src/OpenMesh/Tools/Utils/TimerWin32.cc deleted file mode 100644 index ee3859edb18f10fd58251dd040c3e1f555c7afc3..0000000000000000000000000000000000000000 --- a/src/OpenMesh/Tools/Utils/TimerWin32.cc +++ /dev/null @@ -1,143 +0,0 @@ -/*===========================================================================*\ - * * - * OpenMesh * - * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen * - * www.openmesh.org * - * * - *---------------------------------------------------------------------------* - * This file is part of OpenMesh. * - * * - * OpenMesh is free software: you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License as * - * published by the Free Software Foundation, either version 3 of * - * the License, or (at your option) any later version with the * - * following exceptions: * - * * - * If other files instantiate templates or use macros * - * or inline functions from this file, or you compile this file and * - * link it with other files to produce an executable, this file does * - * not by itself cause the resulting executable to be covered by the * - * GNU Lesser General Public License. This exception does not however * - * invalidate any other reasons why the executable file might be * - * covered by the GNU Lesser General Public License. * - * * - * OpenMesh is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU LesserGeneral Public * - * License along with OpenMesh. If not, * - * see . * - * * -\*===========================================================================*/ - -/*===========================================================================*\ - * * - * $Revision: 485 $ * - * $Date: 2012-01-12 10:15:18 +0100 (Do, 12 Jan 2012) $ * - * * -\*===========================================================================*/ - -#ifndef DOXY_IGNORE_THIS -// ---------------------------------------------------------------------------- -#include -#if defined(OM_CC_MIPS) -# include -# include -#else -# include -# include -#endif -#include "Timer.hh" -// ---------------------------------------------------------------------------- - -// ------------------------------------------------------------- namespace ---- - -namespace OpenMesh { -namespace Utils { - - -// ---------------------------------------------------------------------------- - -using namespace std; - -// ------------------------------------------------------------- windows 32 ---- -#if defined(WIN32) && (defined(_MSC_VER) || defined(__INTEL_COMPILER)) - -#ifndef DOXY_IGNORE_THIS -#include -#endif - -class TimerImplWin32 : public TimerImpl -{ -protected: - LARGE_INTEGER freq_; - LARGE_INTEGER count_; - LARGE_INTEGER start_; - -public: - TimerImplWin32(void); - ~TimerImplWin32(void) { ; } - - virtual void reset(void); - virtual void start(void); - virtual void stop(void); - virtual void cont(void); - virtual double seconds(void) const; -}; - -TimerImplWin32::TimerImplWin32(void) -{ - if (QueryPerformanceFrequency(&freq_)==FALSE) - throw std::runtime_error("Performance counter of of stock!"); - reset(); -} - -void TimerImplWin32::reset(void) -{ - memset(&count_,0,sizeof(count_)); - memset(&start_,0,sizeof(count_)); -} - -void TimerImplWin32::start(void) -{ - reset(); - QueryPerformanceCounter(&start_); -} - -void TimerImplWin32::stop(void) -{ - LARGE_INTEGER stop_; - - QueryPerformanceCounter(&stop_); - count_.QuadPart += stop_.QuadPart - start_.QuadPart; -} - -void TimerImplWin32::cont(void) -{ - QueryPerformanceCounter(&start_); -} - -double TimerImplWin32::seconds(void) const -{ - return (double)count_.QuadPart/(double)freq_.QuadPart; -} - -Timer::Timer(void) -{ - impl_ = new TimerImplWin32; - state_ = Stopped; -} - -#endif - -// ============================================================================ -} // END_NS_UTILS -} // END_NS_OPENMESH -// ---------------------------------------------------------------------------- -#endif // DOXY_IGNORE_THIS -// ============================================================================ -// end of file Timer.cc -// ============================================================================ -