Apollo 10.0
自动驾驶开放平台
clock.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 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_CLOCK_H_
18#define CYBER_TIME_CLOCK_H_
19
20#include <mutex>
21
22#include "cyber/proto/run_mode_conf.pb.h"
23
25#include "cyber/common/macros.h"
26#include "cyber/time/time.h"
27
28namespace apollo {
29namespace cyber {
30
31using ::apollo::cyber::proto::ClockMode;
32
39class Clock {
40 public:
41 static constexpr int64_t PRECISION =
42 std::chrono::system_clock::duration::period::den /
43 std::chrono::system_clock::duration::period::num;
44
46 static_assert(PRECISION >= 1000000,
47 "The precision of the system clock should be at least 1 "
48 "microsecond.");
49
54 static Time Now();
55
60 static double NowInSeconds();
61
66 static void SetNow(const Time& now);
67
72 static void SetMode(ClockMode mode);
73
78 static ClockMode mode();
79
84 static void SetNowInSeconds(const double seconds) {
85 Clock::SetNow(Time(seconds));
86 }
87
88 private:
89 ClockMode mode_;
90 Time mock_now_;
92
94};
95
96} // namespace cyber
97} // namespace apollo
98
99#endif // CYBER_TIME_CLOCK_H_
a singleton clock that can be used to get the current timestamp.
Definition clock.h:39
static ClockMode mode()
Gets the current clock mode.
Definition clock.cc:76
static constexpr int64_t PRECISION
Definition clock.h:41
static void SetNowInSeconds(const double seconds)
This is for mock clock mode only.
Definition clock.h:84
static void SetMode(ClockMode mode)
Definition clock.cc:58
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56
static void SetNow(const Time &now)
This is for mock clock mode only.
Definition clock.cc:82
static Time Now()
PRECISION >= 1000000 means the precision is at least 1us.
Definition clock.cc:40
Cyber has builtin time type Time.
Definition time.h:31
#define DECLARE_SINGLETON(classname)
Definition macros.h:52
class register implement
Definition arena_queue.h:37