/* */ #ifndef _D_TIME_H_ #define _D_TIME_H_ #include "common.h" #include class Time { private: struct timeval tv; struct timeval getCurrentTime() const; public: // The time value is initialized so that it represents the time at which // this object was created. Time(); Time(const Time& time); Time(int32_t sec); Time& operator=(const Time& time) { if(this != &time) { tv = time.tv; } return *this; } ~Time(); // Makes this object's time value up to date. void reset(); bool elapsed(int32_t sec) const; bool elapsedInMillis(int32_t millis) const; int32_t difference() const; int64_t differenceInMillis() const; int64_t differenceInMillis(const struct timeval& now) const; // Returns true if this object's time value is zero. bool isZero() const { return tv.tv_sec == 0 && tv.tv_usec == 0; } int64_t getTimeInMicros() const { return (int64_t)tv.tv_sec*1000*1000+tv.tv_usec; } int64_t getTimeInMillis() const { return (int64_t)tv.tv_sec*1000+tv.tv_usec/1000; } // Returns this object's time value in seconds. int32_t getTime() const { return tv.tv_sec; } void setTimeInSec(int32_t sec); bool isNewer(const Time& time) const; }; #endif // _D_TIME_H_