TimeInfo.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef BASE_TIMEINFO_H
00025 #define BASE_TIMEINFO_H
00026
00027
00028
00029
00030 #include <stdio.h>
00031 #include <sys/timeb.h>
00032 #include <time.h>
00033
00034 #ifdef __GNUC__
00035 # include <stdint.h>
00036 #endif
00037
00038 namespace Base
00039 {
00041 class BaseExport TimeInfo
00042 {
00043
00044 public:
00046 TimeInfo();
00048 virtual ~TimeInfo();
00049
00051 void setCurrent(void);
00052 void setTime_t (uint64_t seconds);
00053
00054 uint64_t getSeconds(void) const;
00055 unsigned short getMiliseconds(void) const;
00056
00057 void operator = (const TimeInfo &time);
00058 bool operator == (const TimeInfo &time) const;
00059 bool operator != (const TimeInfo &time) const;
00060
00061 bool operator < (const TimeInfo &time) const;
00062 bool operator <= (const TimeInfo &time) const;
00063 bool operator >= (const TimeInfo &time) const;
00064 bool operator > (const TimeInfo &time) const;
00065
00066 static const char* currentDateTimeString();
00067 static std::string diffTime(const TimeInfo &timeStart,const TimeInfo &timeEnd );
00068 static float diffTimeF(const TimeInfo &timeStart,const TimeInfo &timeEnd );
00069 bool isNull() const;
00070 static TimeInfo null();
00071
00072 protected:
00073 #if defined (_MSC_VER)
00074 struct _timeb timebuffer;
00075 #elif defined(__GNUC__)
00076 struct timeb timebuffer;
00077 #endif
00078 };
00079
00080
00081 inline uint64_t TimeInfo::getSeconds(void) const
00082 {
00083 return timebuffer.time;
00084 }
00085
00086 inline unsigned short TimeInfo::getMiliseconds(void) const
00087 {
00088 return timebuffer.millitm;
00089 }
00090
00091 inline bool
00092 TimeInfo::operator != (const TimeInfo &time) const
00093 {
00094 return (timebuffer.time != time.timebuffer.time || timebuffer.millitm != time.timebuffer.millitm);
00095 }
00096
00097 inline void
00098 TimeInfo::operator = (const TimeInfo &time)
00099 {
00100 timebuffer = time.timebuffer;
00101 }
00102
00103 inline bool
00104 TimeInfo::operator == (const TimeInfo &time) const
00105 {
00106 return (timebuffer.time == time.timebuffer.time && timebuffer.millitm == time.timebuffer.millitm);
00107 }
00108
00109 inline bool
00110 TimeInfo::operator < (const TimeInfo &time) const
00111 {
00112 if (timebuffer.time == time.timebuffer.time)
00113 return timebuffer.millitm < time.timebuffer.millitm;
00114 else
00115 return timebuffer.time < time.timebuffer.time;
00116 }
00117
00118 inline bool
00119 TimeInfo::operator <= (const TimeInfo &time) const
00120 {
00121 if (timebuffer.time == time.timebuffer.time)
00122 return timebuffer.millitm <= time.timebuffer.millitm;
00123 else
00124 return timebuffer.time <= time.timebuffer.time;
00125 }
00126
00127 inline bool
00128 TimeInfo::operator >= (const TimeInfo &time) const
00129 {
00130 if (timebuffer.time == time.timebuffer.time)
00131 return timebuffer.millitm >= time.timebuffer.millitm;
00132 else
00133 return timebuffer.time >= time.timebuffer.time;
00134 }
00135
00136 inline bool
00137 TimeInfo::operator > (const TimeInfo &time) const
00138 {
00139 if (timebuffer.time == time.timebuffer.time)
00140 return timebuffer.millitm > time.timebuffer.millitm;
00141 else
00142 return timebuffer.time > time.timebuffer.time;
00143 }
00144
00145 }
00146
00147
00148 #endif // BASE_TIMEINFO_H
00149