10#if __has_include("defs.h")
14#include "safe_winsock.h"
22timeval
operator+ (
const timeval& t1,
const timeval& t2);
23timeval
operator- (
const timeval& t1,
const timeval& t2);
24timeval&
operator+= (timeval& lhs,
const timeval& rhs);
25timeval&
operator-= (timeval& lhs,
const timeval& rhs);
26timeval
operator* (
const timeval& op1,
int op2);
27timeval
operator* (
int op1,
const timeval& op2);
28timeval
operator/ (
const timeval& op1,
int op2);
31inline bool operator== (
const timeval& t1,
const timeval& t2)
33 if (t1.tv_sec == t2.tv_sec)
34 return (t1.tv_usec == t2.tv_usec);
39#if __cplusplus < 202002L
43inline bool operator< (
const timeval& t1,
const timeval& t2)
45 if (t1.tv_sec != t2.tv_sec)
46 return (t1.tv_sec < t2.tv_sec);
48 return (t1.tv_usec < t2.tv_usec);
52inline bool operator> (
const timeval& t1,
const timeval& t2)
54 if (t1.tv_sec != t2.tv_sec)
55 return (t1.tv_sec > t2.tv_sec);
57 return (t1.tv_usec > t2.tv_usec);
61inline bool operator>= (
const timeval& t1,
const timeval& t2)
67inline bool operator<= (
const timeval& t1,
const timeval& t2)
73inline bool operator!= (
const timeval& t1,
const timeval& t2)
81inline auto operator<=> (
const timeval& t1,
const timeval& t2)
83 if (t1.tv_sec == t2.tv_sec)
84 return (t1.tv_usec <=> t2.tv_usec);
86 return (t1.tv_sec <=> t2.tv_sec);
92long long usec64 (
const timeval& tv);
96double secd (
const timeval& tv);
99timeval fromsystime (
const SYSTEMTIME& st);
100void tosystime (
const timeval& tv, SYSTEMTIME* st);
101void tolocaltime (
const timeval& tv, SYSTEMTIME* st);
116 ans.tv_usec = t1.tv_usec + t2.tv_usec;
117 ans.tv_sec = t1.tv_sec + t2.tv_sec;
128 ans.tv_usec = t1.tv_usec - t2.tv_usec;
129 ans.tv_sec = t1.tv_sec - t2.tv_sec;
138 lhs.tv_usec += rhs.tv_usec;
139 lhs.tv_sec += rhs.tv_sec;
148 lhs.tv_usec -= rhs.tv_usec;
149 lhs.tv_sec -= rhs.tv_sec;
158 return tv.tv_sec + (double)tv.tv_usec / 1000000;
165 return (
long long)tv.tv_sec * 1000000L + (
long long)tv.tv_usec;
173 tv.tv_sec = (int)(us / 1000000L);
174 tv.tv_usec = (int)(us % 1000000L);
184 tv.tv_usec = (long)((d - tv.tv_sec) * 1000000);
192 using namespace std::chrono;
193 auto sec = duration_cast<seconds>(dur);
194 auto us = duration_cast<microseconds> (dur - sec);
195 return timeval{(long)sec.count (), (long)us.count ()};
202 using namespace std::chrono;
203 return seconds (tv.tv_sec) + microseconds (tv.tv_usec);
213 tv.tv_usec = op1.tv_usec * op2;
214 tv.tv_sec = op1.tv_sec * op2;
231 tv.tv_usec = op1.tv_usec / op2;
232 tv.tv_sec = op1.tv_sec / op2;
238inline ::std::ostream&
operator<< (::std::ostream& os,
const timeval& tv)
240 os <<
"{ tv_sec: " << tv.tv_sec <<
", tv_usec: " << tv.tv_usec <<
'}';
bool operator<=(const timeval &t1, const timeval &t2)
"Less or equal than" operator
Definition tvops.h:67
bool operator!=(const timeval &t1, const timeval &t2)
"Not equal" operator
Definition tvops.h:73
timeval operator/(const timeval &op1, int op2)
Division by an integer.
Definition tvops.h:228
timeval operator-(const timeval &t1, const timeval &t2)
Subtraction operator.
Definition tvops.h:124
long long usec64(const timeval &tv)
Conversion to 64-bit microseconds.
Definition tvops.h:163
timeval operator+(const timeval &t1, const timeval &t2)
Addition operator.
Definition tvops.h:113
bool operator>(const timeval &t1, const timeval &t2)
"Greater than" operator
Definition tvops.h:52
void normalize(timeval &tv)
Following an arithmetic operation, brings timeval structure to a canonical form where tv_usec is less...
Definition tvops.cpp:74
std::chrono::microseconds to_chrono(const timeval &tv)
Conversion to a chrono duration in microseconds.
Definition tvops.h:200
timeval operator*(const timeval &op1, int op2)
Multiplication by an integer.
Definition tvops.h:209
inline ::std::ostream & operator<<(::std::ostream &os, const timeval &tv)
Stream extraction operator.
Definition tvops.h:238
timeval fromdouble(double d)
Conversion from floating-point seconds.
Definition tvops.h:180
double secd(const timeval &tv)
Conversion to floating-point seconds.
Definition tvops.h:156
timeval fromusec(long long us)
Conversion from 64-bit microseconds.
Definition tvops.h:170
timeval & operator-=(timeval &lhs, const timeval &rhs)
Subtraction assignment.
Definition tvops.h:146
timeval from_chrono(const T &dur)
Conversion from a chrono duration.
Definition tvops.h:190
bool operator>=(const timeval &t1, const timeval &t2)
"Greater or equal than" operator
Definition tvops.h:61
bool operator==(const timeval &t1, const timeval &t2)
Equality operator.
Definition tvops.h:31
bool operator<(const timeval &t1, const timeval &t2)
"Less than" operator
Definition tvops.h:43
timeval & operator+=(timeval &lhs, const timeval &rhs)
Addition assignment operator.
Definition tvops.h:136