Time.h

Go to the documentation of this file.
00001 
00022 #ifndef HYPERTABLE_HIRES_TIME_H
00023 #define HYPERTABLE_HIRES_TIME_H
00024 
00025 #include <iosfwd>
00026 #include <boost/thread/xtime.hpp>
00027 
00028 namespace Hypertable {
00029 
00030   bool xtime_add_millis(boost::xtime &xt, uint32_t millis);
00031   bool xtime_sub_millis(boost::xtime &xt, uint32_t millis);
00032   int64_t xtime_diff_millis(boost::xtime &early, boost::xtime &late);
00033 
00034   using boost::TIME_UTC;
00035 
00038   struct HiResTime : public boost::xtime {
00039     HiResTime(int type = TIME_UTC) { reset(type); }
00040 
00044     bool reset(int type = TIME_UTC) {
00045       return boost::xtime_get(this, type) != 0;
00046     }
00047 
00051     int cmp(const HiResTime &y) const {
00052       return boost::xtime_cmp(*this, y);
00053     }
00054 
00055     bool operator<(const HiResTime &y) const { return cmp(y) < 0; }
00056     bool operator==(const HiResTime &y) const { return cmp(y) == 0; }
00057 
00058     HiResTime &operator+=(uint32_t ms) {
00059       xtime_add_millis(*this, ms);
00060       return *this;
00061     }
00062 
00063     HiResTime &operator-=(uint32_t ms) {
00064       xtime_sub_millis(*this, ms);
00065       return *this;
00066     }
00067   };
00068 
00069   int64_t get_ts64();
00070   std::ostream &hires_ts(std::ostream &);
00071   std::ostream &hires_ts_date(std::ostream &);
00072 
00073 #if defined(__sun__)
00074   time_t timegm(struct tm *t);
00075 #endif
00076 
00077 } // namespace Hypertable
00078 
00079 #endif // HYPERTABLE_HIRES_TIME_H