Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Timestamp.h

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;    /* seconds */
00017                 long tv_usec;   /* microseconds */
00018         };
00019 }
00020 #endif
00021 
00022 namespace Time {
00023 
00024 class Stamp {
00025  private:
00026 #if defined( __WIN32__ )
00027         
00028         // We roll our own timeval... may only need to be done for mingw32.
00029         // FIXME since we're no longer doing a typedef, do we really need to do this?
00030         struct eris_timeval _val;
00031 
00032 #elif defined( macintosh )
00033         UnsignedWide _val;      // micro-seconds
00034 #else
00035         // POSIX, BeOS, ....
00036         struct timeval _val;
00037 #endif  
00038 
00039         // Hook for future expansion to other platforms,
00040         // in case the timer needs initializing
00041         static void Init() {_did_init = true;}
00042         static bool _did_init;
00043 
00044  public:
00045         Stamp() {Init();}
00046         // Don't need to call Init() in copy constructor, it must
00047         // have been called when the value we're copying from was
00048         // constructed
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 //inline Stamp getCurrentStamp() {return Stamp().getCurrent();}
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 } // of namespace Time
00080 
00081 #endif

Generated on Thu May 22 08:01:04 2003 for Eris by doxygen1.3-rc3