ACQ2XX_API
Timer.h
Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file Timer.h                                                              */
00003 /* ------------------------------------------------------------------------- */
00004 /*   Copyright (C) 2009 Peter Milne, D-TACQ Solutions Ltd
00005  *                      <Peter dot Milne at D hyphen TACQ dot com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of Version 2 of the GNU General Public License
00009     as published by the Free Software Foundation;
00010 
00011     This program 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
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
00019 /* ------------------------------------------------------------------------- */
00020 
00021 /** @file Timer.h Timer class .
00022 */
00023 
00024 #ifndef TIMER_H_
00025 #define TIMER_H_
00026 #include <sys/time.h>
00027 
00028 class Timer {
00029         struct timeval tv1;
00030 public:
00031         Timer() {
00032                 gettimeofday(&tv1, NULL);
00033         }
00034         double timeFromStart() {
00035                 struct timeval tv2;
00036 
00037                 gettimeofday(&tv2, NULL);
00038                 if (tv2.tv_sec > tv1.tv_sec && tv2.tv_usec < tv1.tv_usec){
00039                         tv2.tv_usec += 1000000;
00040                         tv2.tv_sec -= 1;
00041                 }
00042                 return tv2.tv_sec - tv1.tv_sec +
00043                                 1e-6 * (tv2.tv_usec - tv1.tv_usec);
00044         }
00045 };
00046 
00047 
00048 #endif /* TIMER_H_ */