5 // Created by James McIlree on 4/14/13.
6 // Copyright (c) 2013 Apple. All rights reserved.
9 #ifndef __CPPUtil__UtilAbsTime__
10 #define __CPPUtil__UtilAbsTime__
19 // Minimum and Maximum possible values
20 static const AbsTime BEGINNING_OF_TIME;
21 static const AbsTime END_OF_TIME;
25 AbsTime() : _time(0ULL) {}
26 explicit AbsTime(uint64_t t) : _time(t) {}
28 bool operator==(const AbsTime& rhs) const { return this->_time == rhs._time; }
29 bool operator!=(const AbsTime &rhs) const { return !(*this == rhs); }
31 bool operator<(const AbsTime& rhs) const { return this->_time < rhs._time; }
32 bool operator<=(const AbsTime& rhs) const { return this->_time <= rhs._time; }
33 bool operator>(const AbsTime& rhs) const { return this->_time > rhs._time; }
34 bool operator>=(const AbsTime& rhs) const { return this->_time >= rhs._time; }
36 // We do not want to be able to mutate AbsTime(s)
37 // without type enforcement, but it is useful to be able
38 // to say "if (time == 0) {}", so we have value based
39 // operators for comparison
40 bool operator==(uint64_t value) const { return this->_time == value; }
41 bool operator!=(uint64_t value) const { return !(*this == value); }
43 bool operator<(uint64_t value) const { return this->_time < value; }
44 bool operator<=(uint64_t value) const { return this->_time <= value; }
45 bool operator>(uint64_t value) const { return this->_time > value; }
46 bool operator>=(uint64_t value) const { return this->_time >= value; }
48 AbsTime operator+(const AbsTime& rhs) const { return AbsTime(_time + rhs._time); }
49 AbsTime operator-(const AbsTime& rhs) const { return AbsTime(_time - rhs._time); }
50 AbsTime operator*(const AbsTime& rhs) const { return AbsTime(_time * rhs._time); }
51 AbsTime operator/(const AbsTime& rhs) const { return AbsTime(_time / rhs._time); }
53 AbsTime& operator+=(const AbsTime& rhs) { _time += rhs._time; return *this; }
55 NanoTime nano_time() const; // NOTE! Uses system mach_timebase_info, potentially expensive conversion costs.
56 NanoTime nano_time(mach_timebase_info_data_t timebase_info) const;
58 uint64_t value() const { return _time; }
59 double double_value() const { return (double)_time; }
62 #endif /* defined(__CPPUtil__UtilAbsTime__) */