00001 #ifndef FORGE_TIME_H
00002 #define FORGE_TIME_H
00003
00007 #ifdef _MSC_VER
00008 #include <sys/timeb.h>
00009 #else
00010 #include <sys/time.h>
00011 #endif
00012 #if defined ( __WIN32__ )
00013 #include <winsock.h>
00014 extern "C" {
00015 struct eris_timeval {
00016 long tv_sec;
00017 long tv_usec;
00018 };
00019 }
00020 #endif
00021
00022 namespace Time {
00023
00024 class Stamp {
00025 private:
00026 #if defined( __WIN32__ )
00027
00028
00029
00030 struct eris_timeval _val;
00031
00032 #elif defined( macintosh )
00033 UnsignedWide _val;
00034 #else
00035
00036 struct timeval _val;
00037 #endif
00038
00039
00040
00041 static void Init() {_did_init = true;}
00042 static bool _did_init;
00043
00044 public:
00045 Stamp() {Init();}
00046
00047
00048
00049
00052 double seconds();
00053
00054 friend bool operator<(const Stamp &a, const Stamp &b);
00055 friend bool operator>(const Stamp &a, const Stamp &b);
00056
00057 friend Stamp operator+(const Stamp &a, long msec);
00058 friend Stamp operator-(const Stamp &a, long msec);
00059
00060 friend long operator-(const Stamp &a, const Stamp &b);
00061
00062 static Stamp now();
00063 };
00064
00065
00066
00067 bool operator<(const Stamp &a, const Stamp &b);
00068 bool operator>(const Stamp &a, const Stamp &b);
00069
00070 Stamp operator+(const Stamp &a, long msec);
00071
00072 inline Stamp operator+(unsigned long msec, const Stamp &a)
00073 {return a + msec;}
00074
00075 Stamp operator-(const Stamp &a, long msec);
00076
00077 long operator-(const Stamp &a, const Stamp &b);
00078
00079 }
00080
00081 #endif