00001 // unixtimer.h 00002 // 00003 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net> 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 00010 00011 #include <sys/time.h> 00012 #include <unistd.h> 00013 #include "timer.h" 00014 00015 class UnixTimer : public Timer 00016 { 00017 public: 00018 UnixTimer(); 00019 ~UnixTimer(); 00020 double getTime() const; 00021 void reset(); 00022 00023 private: 00024 double start; 00025 }; 00026 00027 00028 UnixTimer::UnixTimer() 00029 { 00030 reset(); 00031 } 00032 00033 UnixTimer::~UnixTimer() 00034 { 00035 } 00036 00037 double UnixTimer::getTime() const 00038 { 00039 struct timeval t; 00040 gettimeofday(&t, NULL); 00041 return (double) t.tv_sec + (double) t.tv_usec / 1000000.0 - start; 00042 } 00043 00044 void UnixTimer::reset() 00045 { 00046 struct timeval t; 00047 gettimeofday(&t, NULL); 00048 start = (double) t.tv_sec + (double) t.tv_usec / 1000000.0; 00049 } 00050 00051 Timer* CreateTimer() 00052 { 00053 return new UnixTimer(); 00054 }
1.4.1