Apollo  6.0
Open source self driving car software
time.h
Go to the documentation of this file.
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 
25 namespace apollo {
26 namespace cyber {
27 
31 class 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 
109 std::ostream& operator<<(std::ostream& os, const Time& rhs);
110 
111 } // namespace cyber
112 } // namespace apollo
113 
114 #endif // CYBER_TIME_TIME_H_
Duration operator-(const Time &rhs) const
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
static void SleepUntil(const Time &time)
Sleep Until time.
std::ostream & operator<<(std::ostream &os, const Duration &rhs)
static const Time MAX
Definition: time.h:33
Time & operator+=(const Duration &rhs)
bool operator<(const Time &rhs) const
static Time MonoTime()
Time & operator=(const Time &other)
bool operator>(const Time &rhs) const
bool operator!=(const Time &rhs) const
static const Time MIN
Definition: time.h:34
bool operator>=(const Time &rhs) const
double ToSecond() const
convert time to second.
bool operator<=(const Time &rhs) const
bool IsZero() const
determine if time is 0
uint64_t ToNanosecond() const
convert time to nanosecond.
Time & operator-=(const Duration &rhs)
static Time Now()
get the current time.
std::string ToString() const
convert time to a string.
bool operator==(const Time &rhs) const
Cyber has builtin time type Time.
Definition: time.h:31
Definition: duration.h:26
Time operator+(const Duration &rhs) const
uint64_t ToMicrosecond() const
convert time to microsecond (us).