Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

DTime.h

Go to the documentation of this file.
00001 //=============================================================================
00005 //=============================================================================
00006 #ifndef _DTIME_H_
00007 #define _DTIME_H_
00008 
00009 #ifdef WIN32
00010 #include <time.h>
00011 #include <sys/timeb.h>
00012 #include <winsock2.h>
00013 
00014 #ifdef DUTIL_EXPORTS
00015 #define PEXPR_API __declspec(dllexport)
00016 #else
00017 #define PEXPR_API __declspec(dllimport)
00018 #endif /* DUTIL_EXPORTS */
00019 
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023 
00024 inline PEXPR_API int gettimeofday( timeval* t, int )
00025 {
00026         _timeb wintime;
00027         _ftime( &wintime );
00028         t->tv_sec = wintime.time;
00029         t->tv_usec = wintime.millitm * 1000;
00030         return 0;
00031 };
00032 
00033 #ifdef __cplusplus
00034 }
00035 #endif
00036 
00037 #else
00038 #define PEXPR_API
00039 #endif /* WIN32 */
00040 
00041 
00042 class PEXPR_API DTime
00043 {
00044     public:
00045         DTime( int usec = 0 );
00046         DTime( int sec, int usec );
00047         DTime( int min, int sec, int usec );
00048         DTime( int hr, int min, int sec, int usec );
00049         static DTime current();
00050 
00051         void  start();
00052         DTime reset();
00053         DTime elapsed()const;
00054        
00055         float hour()const   { return minute()/60.; }
00056         float minute()const { return sec()/60.;    }
00057         float sec()const    { return msec()/1000.; }
00058         float msec()const   { return m_usec/1000.; }
00059         int   usec()const   { return m_usec; }
00060 
00061         DTime  operator- (const DTime& b ) { return DTime( m_usec - b.m_usec ); }
00062         DTime& operator-=(const DTime& b ) { m_usec -= b.m_usec; return *this;  }
00063         DTime  operator+ (const DTime& b ) { return DTime( m_usec + b.m_usec ); }
00064         DTime& operator+=(const DTime& b ) { m_usec += b.m_usec; return *this;  }
00065         bool operator> (const DTime& b ) { return m_usec >  b.m_usec; }
00066         bool operator>=(const DTime& b ) { return m_usec >= b.m_usec; }
00067         bool operator< (const DTime& b ) { return m_usec <  b.m_usec; }
00068         bool operator<=(const DTime& b ) { return m_usec <= b.m_usec; }
00069         bool operator==(const DTime& b ) { return m_usec == b.m_usec; }
00070         bool operator!=(const DTime& b ) { return m_usec != b.m_usec; }
00071 
00072     private:
00073                 int   m_usec; // micro-sec from Jan 1, 1970
00074         int   m_start;
00075 };
00076 
00077 #endif

Generated on Tue Jun 15 12:49:28 2004 for pexpr by doxygen 1.3.4