00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifdef HAVE_CONFIG_H
00028 # include <simgear_config.h>
00029 #endif
00030
00031 #ifdef HAVE_WINDOWS_H
00032 # include <windows.h>
00033 #endif
00034
00035 #include <simgear/compiler.h>
00036
00037 #ifdef SG_HAVE_STD_INCLUDES
00038 # include <ctime>
00039 #else
00040 # include <time.h>
00041 #endif
00042
00043 #ifdef HAVE_SYS_TIMEB_H
00044 # include <sys/timeb.h>
00045 #endif
00046 #ifdef HAVE_UNISTD_H
00047 # include <unistd.h>
00048 #endif
00049 #ifdef HAVE_SYS_TIME_H
00050 # include <sys/time.h>
00051 #endif
00052
00053
00054 #ifdef macintosh
00055 # include <time.h>
00056 # include <timer.h>
00057 #endif
00058
00059 #ifdef WIN32
00060 # include <windows.h>
00061 # if defined( __CYGWIN__ ) || defined( __CYGWIN32__ )
00062 # define NEAR
00063 # define FAR
00064 # endif
00065 # include <mmsystem.h>
00066 #endif
00067
00068 #include "timestamp.hxx"
00069
00070
00071 void SGTimeStamp::stamp() {
00072 #if defined( WIN32 ) && !defined(__CYGWIN__)
00073 unsigned int t;
00074 t = timeGetTime();
00075 seconds = t / 1000;
00076 usec = ( t - ( seconds * 1000 ) ) * 1000;
00077 #elif defined( HAVE_GETTIMEOFDAY )
00078 struct timeval current;
00079 struct timezone tz;
00080
00081 gettimeofday(¤t, &tz);
00082 seconds = current.tv_sec;
00083 usec = current.tv_usec;
00084 #elif defined( HAVE_GETLOCALTIME )
00085 SYSTEMTIME current;
00086 GetLocalTime(¤t);
00087 seconds = current.wSecond;
00088 usec = current.wMilliseconds * 1000;
00089 #elif defined( HAVE_FTIME )
00090 struct timeb current;
00091 ftime(¤t);
00092 seconds = current.time;
00093 usec = current.millitm * 1000;
00094
00095 #elif defined( macintosh )
00096 UnsignedWide ms;
00097 Microseconds(&ms);
00098
00099 seconds = ms.lo / 1000000;
00100 usec = ms.lo - ( seconds * 1000000 );
00101 #else
00102 # error Port me
00103 #endif
00104 }
00105
00106
00107 SGTimeStamp operator + (const SGTimeStamp& t, const long& m) {
00108 return SGTimeStamp( t.seconds + ( t.usec + m ) / 1000000,
00109 ( t.usec + m ) % 1000000 );
00110 }
00111
00112
00113 long operator - (const SGTimeStamp& a, const SGTimeStamp& b)
00114 {
00115 return 1000000 * (a.seconds - b.seconds) + (a.usec - b.usec);
00116 }