Apollo 10.0
自动驾驶开放平台
time.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#ifndef CYBER_TIME_TIME_H_
18#define CYBER_TIME_TIME_H_
19
20#include <limits>
21#include <string>
22
23#include "cyber/time/duration.h"
24
25namespace apollo {
26namespace cyber {
27
31class Time {
32 public:
33 static const Time MAX;
34 static const Time MIN;
35 Time() = default;
36 explicit Time(uint64_t nanoseconds);
37 explicit Time(int nanoseconds);
38 explicit Time(double seconds);
39 Time(uint32_t seconds, uint32_t nanoseconds);
40 Time(const Time& other);
41 Time& operator=(const Time& other);
42
48 static Time Now();
49 static Time MonoTime();
50
56 static void SleepUntil(const Time& time);
57
63 double ToSecond() const;
64
70 uint64_t ToMicrosecond() const;
71
77 uint64_t ToNanosecond() const;
78
84 std::string ToString() const;
85
91 bool IsZero() const;
92
93 Duration operator-(const Time& rhs) const;
94 Time operator+(const Duration& rhs) const;
95 Time operator-(const Duration& rhs) const;
96 Time& operator+=(const Duration& rhs);
97 Time& operator-=(const Duration& rhs);
98 bool operator==(const Time& rhs) const;
99 bool operator!=(const Time& rhs) const;
100 bool operator>(const Time& rhs) const;
101 bool operator<(const Time& rhs) const;
102 bool operator>=(const Time& rhs) const;
103 bool operator<=(const Time& rhs) const;
104
105 private:
106 uint64_t nanoseconds_ = 0;
107};
108
109std::ostream& operator<<(std::ostream& os, const Time& rhs);
110
111} // namespace cyber
112} // namespace apollo
113
114#endif // CYBER_TIME_TIME_H_
Cyber has builtin time type Time.
Definition time.h:31
bool operator>(const Time &rhs) const
Definition time.cc:148
uint64_t ToMicrosecond() const
convert time to microsecond (us).
Definition time.cc:85
bool operator<(const Time &rhs) const
Definition time.cc:152
Time & operator+=(const Duration &rhs)
Definition time.cc:130
Time operator+(const Duration &rhs) const
Definition time.cc:122
Duration operator-(const Time &rhs) const
Definition time.cc:118
static const Time MAX
Definition time.h:33
bool operator!=(const Time &rhs) const
Definition time.cc:144
bool IsZero() const
determine if time is 0
Definition time.cc:81
static void SleepUntil(const Time &time)
Sleep Until time.
Definition time.cc:112
bool operator<=(const Time &rhs) const
Definition time.cc:160
bool operator==(const Time &rhs) const
Definition time.cc:140
bool operator>=(const Time &rhs) const
Definition time.cc:156
Time & operator-=(const Duration &rhs)
Definition time.cc:135
static Time MonoTime()
Definition time.cc:67
static const Time MIN
Definition time.h:34
uint64_t ToNanosecond() const
convert time to nanosecond.
Definition time.cc:83
static Time Now()
get the current time.
Definition time.cc:57
std::string ToString() const
convert time to a string.
Definition time.cc:89
Time & operator=(const Time &other)
Definition time.cc:52
double ToSecond() const
convert time to second.
Definition time.cc:77
std::ostream & operator<<(std::ostream &os, const Duration &rhs)
Definition duration.cc:114
class register implement
Definition arena_queue.h:37