24 #ifndef __UTILS_TIME_TIME_H_ 25 #define __UTILS_TIME_TIME_H_ 43 double res = a.tv_sec - b.tv_sec + (a.tv_usec - b.tv_usec) / 1000000.0;
59 const long int b_sec,
const long int b_usec)
62 double res = a_sec - b_sec + (a_usec - b_usec) / 1000000.0;
74 return (
long)round(sec * 1000000.);
86 return (a.tv_sec - b.tv_sec) * 1000000 + (a.tv_usec - b.tv_usec);
96 Time(
const timeval* tv);
97 Time(
long sec,
long usec,
Clock *clock = 0);
110 long get_sec()
const {
return __time.tv_sec; }
111 long get_msec()
const {
return __time.tv_usec / 1000; }
113 long get_nsec()
const {
return __time.tv_usec * 1000; }
115 { sec = __time.tv_sec; usec = __time.tv_usec; }
116 bool is_zero()
const {
return (__time.tv_sec == 0) && (__time.tv_usec == 0); }
119 void set_time(
long int sec,
long int usec);
127 void add(
double seconds);
163 const char *
str(
bool utc =
false)
const;
164 void str_r(
char *s,
bool utc =
false);
171 mutable char *__timestr;
static const unsigned int TIMESTR_SIZE
Maximum size of string returned by str() and the minimum size of the string passwd to str_r()...
Time & operator=(const Time &t)
Assign operator.
double in_sec() const
Convet time to seconds.
long int time_sec_to_usec(double sec)
Convert seconds to micro seconds.
Time & operator-=(const Time &t)
-= operator.
const timeval * get_timeval() const
Obtain the timeval where the time is stored.
const char * str(bool utc=false) const
Output function.
void get_timestamp(long &sec, long &usec) const
Get time stamp.
Time & stamp_systime()
Set this time to the current system time.
bool operator<=(const Time &t) const
Less than or equal to operator.
Fawkes library namespace.
This is supposed to be the central clock in Fawkes.
Time & operator+=(const long int usec)
+= operator
A class for handling time.
bool operator<(const Time &t) const
Less than operator.
void str_r(char *s, bool utc=false)
Output function.
bool operator==(const Time &t) const
Check equality of times.
void wait()
Wait (sleep) for this time.
void wait_systime()
Wait (sleep) for this system time.
Time operator-(const Time &t) const
Operator that substracts one Time from another.
const Time TIME_MIN
Instance of Time denoting the minimum value possible.
long in_msec() const
Convert the stored time into milli-seconds.
void add(double seconds)
Add seconds.
void set_clock(Clock *clock)
Set clock for this instance.
bool operator>=(const Time &t) const
Greater than or equal to operator.
double time_diff_sec(const timeval &a, const timeval &b)
Calculate time difference of two time structs.
long get_nsec() const
Get nanoseconds.
bool is_zero() const
Check if time is zero.
long int time_diff_usec(const timeval &a, const timeval &b)
Get difference between two time structs in microseconds.
long get_sec() const
Get seconds.
long get_usec() const
Get microseconds.
const Time TIME_MAX
Instance of Time denoting the maximum value possible.
void set_time(const timeval *tv)
Sets the time.
bool operator>(const Time &t) const
Greater than operator.
Time operator+(const double sec) const
Operator that adds times.
long in_usec() const
Convert the stored time into micro-seconds.
Time & stamp()
Set this time to the current time.
long get_msec() const
Get milliseconds.
bool operator!=(const Time &t) const
Check inequality of times.