00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00029
00031 #ifndef __TIMESTAMP_H__
00032 #define __TIMESTAMP_H__
00033
00034 #include "H3DApi.h"
00035
00036 #ifdef WIN32
00037 #include <sys/timeb.h>
00038 #else
00039 #ifdef HAVE_SYS_TIME_H
00040 #include <sys/time.h>
00041 #else
00042 #error Compiler does not support any of the default getCurrentTime() implementations in TimeStamp.h
00043 #endif
00044 #endif
00045 #include "H3DApi.h"
00046 #include "Exception.h"
00047
00048
00049 namespace H3D {
00050 struct H3DAPI_API TimeStamp {
00051 H3D_API_EXCEPTION( PerformanceCounterNotSupported );
00052
00053 TimeStamp() {
00054 time = getCurrentTime();
00055 }
00056 TimeStamp( double _time ) : time( _time ) {}
00057
00058 static TimeStamp now() {
00059 return TimeStamp( getCurrentTime() );
00060 }
00061
00062
00063 operator double() const { return time; }
00064 bool operator==( const TimeStamp &arg ) const { return time==arg.time; }
00065 bool operator!=( const TimeStamp &arg ) const { return time!=arg.time; }
00066 bool operator> ( const TimeStamp &arg ) const { return time>arg.time; }
00067 bool operator< ( const TimeStamp &arg ) const { return time<arg.time; }
00068 bool operator>=( const TimeStamp &arg ) const { return time>=arg.time; }
00069 bool operator<=( const TimeStamp &arg ) const { return time<=arg.time; }
00070
00071 protected:
00072 double time;
00073
00074 static double getCurrentTime();
00075
00076 #ifdef WIN32
00077 static bool init_done;
00078 static double start_time;
00079 static LARGE_INTEGER start_perf_count;
00080 static LARGE_INTEGER perf_freq;
00081 #endif
00082 };
00083 }
00084
00085
00086 #endif