1 //===-- TimeValue.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_TimeValue_h_
11 #define liblldb_TimeValue_h_
18 // BEGIN: MinGW work around
19 #if !defined(_STRUCT_TIMESPEC) && !defined(HAVE_STRUCT_TIMESPEC)
22 // END: MinGW work around
26 // Other libraries and framework includes
28 #include "lldb/lldb-private.h"
30 namespace lldb_private {
35 static const uint64_t MicroSecPerSec = 1000000UL;
36 static const uint64_t NanoSecPerSec = 1000000000UL;
37 static const uint64_t NanoSecPerMicroSec = 1000U;
39 //------------------------------------------------------------------
40 // Constructors and Destructors
41 //------------------------------------------------------------------
43 TimeValue(const TimeValue& rhs);
44 TimeValue(const struct timespec& ts);
45 explicit TimeValue(uint32_t seconds, uint32_t nanos = 0);
48 //------------------------------------------------------------------
50 //------------------------------------------------------------------
52 operator=(const TimeValue& rhs);
58 GetAsNanoSecondsSinceJan1_1970() const;
61 GetAsMicroSecondsSinceJan1_1970() const;
64 GetAsSecondsSinceJan1_1970() const;
67 GetAsTimeSpec () const;
73 OffsetWithSeconds (uint64_t sec);
76 OffsetWithMicroSeconds (uint64_t usec);
79 OffsetWithNanoSeconds (uint64_t nsec);
85 Dump (Stream *s, uint32_t width = 0) const;
87 /// Returns only the seconds component of the TimeValue. The nanoseconds
88 /// portion is ignored. No rounding is performed.
89 /// @brief Retrieve the seconds component
90 uint32_t seconds() const { return m_nano_seconds / NanoSecPerSec; }
92 /// Returns only the nanoseconds component of the TimeValue. The seconds
93 /// portion is ignored.
94 /// @brief Retrieve the nanoseconds component.
95 uint32_t nanoseconds() const { return m_nano_seconds % NanoSecPerSec; }
97 /// Returns only the fractional portion of the TimeValue rounded down to the
98 /// nearest microsecond (divide by one thousand).
99 /// @brief Retrieve the fractional part as microseconds;
100 uint32_t microseconds() const {
101 return (m_nano_seconds % NanoSecPerSec) / NanoSecPerMicroSec;
105 //------------------------------------------------------------------
106 // Classes that inherit from TimeValue can see and modify these
107 //------------------------------------------------------------------
108 uint64_t m_nano_seconds;
111 bool operator == (const TimeValue &lhs, const TimeValue &rhs);
112 bool operator != (const TimeValue &lhs, const TimeValue &rhs);
113 bool operator < (const TimeValue &lhs, const TimeValue &rhs);
114 bool operator <= (const TimeValue &lhs, const TimeValue &rhs);
115 bool operator > (const TimeValue &lhs, const TimeValue &rhs);
116 bool operator >= (const TimeValue &lhs, const TimeValue &rhs);
118 uint64_t operator -(const TimeValue &lhs, const TimeValue &rhs);
120 } // namespace lldb_private
123 #endif // liblldb_TimeValue_h_