Apollo  6.0
Open source self driving car software
duration.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_DURATION_H_
18 #define CYBER_TIME_DURATION_H_
19 
20 #include <cstdint>
21 #include <iostream>
22 
23 namespace apollo {
24 namespace cyber {
25 
26 class Duration {
27  public:
28  Duration() = default;
29  explicit Duration(int64_t nanoseconds);
30  explicit Duration(int nanoseconds);
31  explicit Duration(double seconds);
32  Duration(uint32_t seconds, uint32_t nanoseconds);
33  Duration(const Duration &other);
34  Duration &operator=(const Duration &other);
35  ~Duration() = default;
36 
37  double ToSecond() const;
38  int64_t ToNanosecond() const;
39  bool IsZero() const;
40  void Sleep() const;
41 
42  Duration operator+(const Duration &rhs) const;
43  Duration operator-(const Duration &rhs) const;
44  Duration operator-() const;
45  Duration operator*(double scale) const;
46  Duration &operator+=(const Duration &rhs);
47  Duration &operator-=(const Duration &rhs);
48  Duration &operator*=(double scale);
49  bool operator==(const Duration &rhs) const;
50  bool operator!=(const Duration &rhs) const;
51  bool operator>(const Duration &rhs) const;
52  bool operator<(const Duration &rhs) const;
53  bool operator>=(const Duration &rhs) const;
54  bool operator<=(const Duration &rhs) const;
55 
56  private:
57  int64_t nanoseconds_ = 0;
58 };
59 
60 std::ostream &operator<<(std::ostream &os, const Duration &rhs);
61 
62 } // namespace cyber
63 } // namespace apollo
64 
65 #endif // CYBER_TIME_DURATION_H_
Duration operator-() const
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::ostream & operator<<(std::ostream &os, const Duration &rhs)
Duration & operator-=(const Duration &rhs)
Duration & operator+=(const Duration &rhs)
Duration operator*(double scale) const
Duration operator+(const Duration &rhs) const
bool operator<=(const Duration &rhs) const
bool operator>(const Duration &rhs) const
double ToSecond() const
Duration & operator*=(double scale)
bool operator!=(const Duration &rhs) const
int64_t ToNanosecond() const
bool operator<(const Duration &rhs) const
bool operator==(const Duration &rhs) const
Definition: duration.h:26
bool operator>=(const Duration &rhs) const
Duration & operator=(const Duration &other)