24 #ifndef _UTILS_TIME_TIME_H_
25 #define _UTILS_TIME_TIME_H_
44 double res = a.tv_sec - b.tv_sec + (a.tv_usec - b.tv_usec) / 1000000.0;
59 const long int a_usec,
61 const long int b_usec)
64 double res = a_sec - b_sec + (a_usec - b_usec) / 1000000.0;
75 return (
long)round(sec * 1000000.);
87 return (a.tv_sec - b.tv_sec) * 1000000 + (a.tv_usec - b.tv_usec);
98 Time(
const timeval *tv);
99 Time(
long sec,
long usec,
Clock *clock = 0);
124 return time_.tv_usec / 1000;
129 return time_.tv_usec;
134 return time_.tv_usec * 1000;
140 usec = time_.tv_usec;
145 return (time_.tv_sec == 0) && (time_.tv_usec == 0);
149 void set_time(
long int sec,
long int usec);
157 void add(
double seconds);
193 const char *
str(
bool utc =
false)
const;
194 void str_r(
char *s,
bool utc =
false);
201 mutable char *timestr_;
This is supposed to be the central clock in Fawkes.
A class for handling time.
void set_clock(Clock *clock)
Set clock for this instance.
void get_timestamp(long &sec, long &usec) const
Get time stamp.
long get_usec() const
Get microseconds.
Time & operator=(const Time &t)
Assign operator.
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 & stamp()
Set this time to the current time.
void str_r(char *s, bool utc=false)
Output function.
bool operator>(const Time &t) const
Greater than operator.
long get_msec() const
Get milliseconds.
void add(double seconds)
Add seconds.
void wait_systime()
Wait (sleep) for this system time.
bool is_zero() const
Check if time is zero.
void wait()
Wait (sleep) for this time.
Time & operator-=(const Time &t)
-= operator.
double in_sec() const
Convet time to seconds.
const timeval * get_timeval() const
Obtain the timeval where the time is stored.
bool operator<=(const Time &t) const
Less than or equal to operator.
bool operator<(const Time &t) const
Less than operator.
bool operator!=(const Time &t) const
Check inequality of times.
long get_nsec() const
Get nanoseconds.
Time & operator+=(const long int usec)
+= operator
bool operator==(const Time &t) const
Check equality of times.
bool operator>=(const Time &t) const
Greater than or equal to operator.
long in_usec() const
Convert the stored time into micro-seconds.
Time operator-(const Time &t) const
Operator that substracts one Time from another.
Time & stamp_systime()
Set this time to the current system time.
const char * str(bool utc=false) const
Output function.
void set_time(const timeval *tv)
Sets the time.
long get_sec() const
Get seconds.
Time operator+(const double sec) const
Operator that adds times.
long in_msec() const
Convert the stored time into milli-seconds.
Fawkes library namespace.
const Time TIME_MAX
Instance of Time denoting the maximum value possible.
long int time_diff_usec(const timeval &a, const timeval &b)
Get difference between two time structs in microseconds.
long int time_sec_to_usec(double sec)
Convert seconds to micro seconds.
double time_diff_sec(const timeval &a, const timeval &b)
Calculate time difference of two time structs.
const Time TIME_MIN
Instance of Time denoting the minimum value possible.