00001 #ifndef MY_TIMER_H 00002 #define MY_TIMER_H 00003 00004 #ifdef WIN32 00005 #include <windows.h> 00006 #else 00007 #include <sys/time.h> 00008 #endif //WIN32 00009 00010 namespace ParabolicRamp { 00011 00012 #ifdef WIN32 00013 typedef DWORD TimerCounterType; 00014 #else 00015 #ifdef _POSIX_MONOTONIC_CLOCK 00016 typedef timespec TimerCounterType; 00017 #else 00018 typedef timeval TimerCounterType; 00019 #endif //_POSIX_MONOTONIC_CLOCK 00020 #endif //WIN32 00021 00022 class Timer 00023 { 00024 public: 00025 Timer(); 00026 void Reset(); 00027 00028 // Returns elapsed time in milliseconds,seconds respectively 00029 long long ElapsedTicks(); 00030 double ElapsedTime(); 00031 00032 // Doesn't refresh the current time 00033 long long LastElapsedTicks() const; 00034 double LastElapsedTime() const; 00035 00036 private: 00037 TimerCounterType start; 00038 TimerCounterType current; 00039 }; 00040 00041 } //namespace ParabolicRamp 00042 00043 #endif