1 #ifndef MSP_TIME_TIMEDELTA_H_
2 #define MSP_TIME_TIMEDELTA_H_
5 #include <msp/strings/lexicalcast.h>
12 Represents a quantity of time, such as five seconds.
20 /** Constructs a zero TimeDelta. */
21 TimeDelta(): usec(0) { }
23 /** Constructs a TimeDelta from a plain number. The purpose of this is to
24 allow serialization together with the raw() function. For creating
25 TimeDeltas with a specific length, see units.h. */
26 explicit TimeDelta(RawTime u): usec(u) { }
28 /** Returns the raw number stored inside the TimeDelta. This should only be used
29 for serialization and the result should not be interpreted in any way. */
30 RawTime raw() const { return usec; }
32 TimeDelta operator+(const TimeDelta &t) const { return TimeDelta(usec+t.usec); }
33 TimeDelta &operator+=(const TimeDelta &t) { usec += t.usec; return *this; }
34 TimeDelta operator-(const TimeDelta &t) const { return TimeDelta(usec-t.usec); }
35 TimeDelta &operator-=(const TimeDelta &t) { usec -= t.usec; return *this; }
38 TimeDelta operator*(T a) const { return TimeDelta(RawTime(usec*a)); }
40 TimeDelta &operator*=(T a) { usec = RawTime(usec*a); return *this; }
43 TimeDelta operator/(T a) const { return TimeDelta(RawTime(usec/a)); }
45 TimeDelta &operator/=(T a) { usec = RawTime(usec/a); return *this; }
47 double operator/(const TimeDelta &t) const { return double(usec)/t.usec; }
49 bool operator>(const TimeDelta &t) const { return usec>t.usec; }
50 bool operator>=(const TimeDelta &t) const { return usec>=t.usec; }
51 bool operator<(const TimeDelta &t) const { return usec<t.usec; }
52 bool operator<=(const TimeDelta &t) const { return usec<=t.usec; }
53 bool operator==(const TimeDelta &t) const { return usec==t.usec; }
54 bool operator!=(const TimeDelta &t) const { return usec!=t.usec; }
56 operator const void *() const { return usec ? this : 0; }
60 inline TimeDelta operator*(T a, const TimeDelta &t) { return t*a; }
62 void operator<<(LexicalConverter &, const TimeDelta &);