29 #ifndef INCLUDE_OLA_CLOCK_H_
30 #define INCLUDE_OLA_CLOCK_H_
43 static const int USEC_IN_SECONDS = 1000000;
44 static const int ONE_THOUSAND = 1000;
56 explicit BaseTimeVal(
const struct timeval ×tamp) { m_tv = timestamp; }
57 explicit BaseTimeVal(int64_t interval_useconds) { Set(interval_useconds); }
82 void AsTimeval(
struct timeval *tv)
const;
85 time_t Seconds()
const {
return m_tv.tv_sec; }
87 int32_t MicroSeconds()
const {
return static_cast<int32_t
>(m_tv.tv_usec); }
90 int64_t InMilliSeconds()
const;
93 int64_t AsInt()
const;
95 std::string ToString()
const;
103 void TimerAdd(
const struct timeval &tv1,
const struct timeval &tv2,
104 struct timeval *result)
const;
109 void TimerSub(
const struct timeval &tv1,
const struct timeval &tv2,
110 struct timeval *result)
const;
112 void Set(int64_t interval_useconds);
122 TimeInterval(int32_t sec, int32_t usec) : m_interval(sec, usec) {}
123 explicit TimeInterval(int64_t usec) : m_interval(usec) {}
143 bool IsZero()
const {
return !m_interval.IsSet(); }
145 void AsTimeval(
struct timeval *tv)
const { m_interval.AsTimeval(tv); }
147 time_t Seconds()
const {
return m_interval.Seconds(); }
148 int32_t MicroSeconds()
const {
return m_interval.MicroSeconds(); }
150 int64_t InMilliSeconds()
const {
return m_interval.InMilliSeconds(); }
151 int64_t AsInt()
const {
return m_interval.AsInt(); }
153 std::string ToString()
const {
return m_interval.ToString(); }
155 friend std::ostream& operator<< (std::ostream &out,
157 return out << interval.m_interval.ToString();
175 explicit TimeStamp(
const struct timeval ×tamp) : m_tv(timestamp) {}
181 TimeStamp& operator=(
const struct timeval &tv);
184 bool operator==(
const TimeStamp &other)
const {
return m_tv == other.m_tv; }
185 bool operator!=(
const TimeStamp &other)
const {
return m_tv != other.m_tv; }
186 bool operator>(
const TimeStamp &other)
const {
return m_tv > other.m_tv; }
187 bool operator>=(
const TimeStamp &other)
const {
return m_tv >= other.m_tv; }
188 bool operator<(
const TimeStamp &other)
const {
return m_tv < other.m_tv; }
189 bool operator<=(
const TimeStamp &other)
const {
return m_tv <= other.m_tv; }
199 bool IsSet()
const {
return m_tv.IsSet(); }
201 time_t Seconds()
const {
return m_tv.Seconds(); }
202 int32_t MicroSeconds()
const {
return m_tv.MicroSeconds(); }
204 std::string ToString()
const {
return m_tv.ToString(); }
206 friend std::ostream& operator<<(std::ostream &out,
208 return out << timestamp.m_tv.ToString();
225 virtual void CurrentTime(
TimeStamp *timestamp)
const;
228 DISALLOW_COPY_AND_ASSIGN(
Clock);
241 void AdvanceTime(int32_t sec, int32_t usec);
243 void CurrentTime(
TimeStamp *timestamp)
const;
249 #endif // INCLUDE_OLA_CLOCK_H_
Used to get the current time.
Definition: Clock.h:221
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44