Apollo 10.0
自动驾驶开放平台
apollo::cyber::Time类 参考

Cyber has builtin time type Time. 更多...

#include <time.h>

apollo::cyber::Time 的协作图:

Public 成员函数

 Time ()=default
 
 Time (uint64_t nanoseconds)
 
 Time (int nanoseconds)
 
 Time (double seconds)
 
 Time (uint32_t seconds, uint32_t nanoseconds)
 
 Time (const Time &other)
 
Timeoperator= (const Time &other)
 
double ToSecond () const
 convert time to second.
 
uint64_t ToMicrosecond () const
 convert time to microsecond (us).
 
uint64_t ToNanosecond () const
 convert time to nanosecond.
 
std::string ToString () const
 convert time to a string.
 
bool IsZero () const
 determine if time is 0
 
Duration operator- (const Time &rhs) const
 
Time operator+ (const Duration &rhs) const
 
Time operator- (const Duration &rhs) const
 
Timeoperator+= (const Duration &rhs)
 
Timeoperator-= (const Duration &rhs)
 
bool operator== (const Time &rhs) const
 
bool operator!= (const Time &rhs) const
 
bool operator> (const Time &rhs) const
 
bool operator< (const Time &rhs) const
 
bool operator>= (const Time &rhs) const
 
bool operator<= (const Time &rhs) const
 

静态 Public 成员函数

static Time Now ()
 get the current time.
 
static Time MonoTime ()
 
static void SleepUntil (const Time &time)
 Sleep Until time.
 

静态 Public 属性

static const Time MAX = Time(std::numeric_limits<uint64_t>::max())
 
static const Time MIN = Time(0)
 

详细描述

Cyber has builtin time type Time.

在文件 time.h31 行定义.

构造及析构函数说明

◆ Time() [1/6]

apollo::cyber::Time::Time ( )
default

◆ Time() [2/6]

apollo::cyber::Time::Time ( uint64_t  nanoseconds)
explicit

在文件 time.cc36 行定义.

36{ nanoseconds_ = nanoseconds; }

◆ Time() [3/6]

apollo::cyber::Time::Time ( int  nanoseconds)
explicit

在文件 time.cc38 行定义.

38 {
39 nanoseconds_ = static_cast<uint64_t>(nanoseconds);
40}

◆ Time() [4/6]

apollo::cyber::Time::Time ( double  seconds)
explicit

在文件 time.cc42 行定义.

42 {
43 nanoseconds_ = static_cast<uint64_t>(seconds * 1000000000UL);
44}

◆ Time() [5/6]

apollo::cyber::Time::Time ( uint32_t  seconds,
uint32_t  nanoseconds 
)

在文件 time.cc46 行定义.

46 {
47 nanoseconds_ = static_cast<uint64_t>(seconds) * 1000000000UL + nanoseconds;
48}

◆ Time() [6/6]

apollo::cyber::Time::Time ( const Time other)

在文件 time.cc50 行定义.

50{ nanoseconds_ = other.nanoseconds_; }

成员函数说明

◆ IsZero()

bool apollo::cyber::Time::IsZero ( ) const

determine if time is 0

返回
return true if time is 0

在文件 time.cc81 行定义.

81{ return nanoseconds_ == 0; }

◆ MonoTime()

Time apollo::cyber::Time::MonoTime ( )
static

在文件 time.cc67 行定义.

67 {
68 auto now = steady_clock::now();
69 auto nano_time_point =
70 std::chrono::time_point_cast<std::chrono::nanoseconds>(now);
71 auto epoch = nano_time_point.time_since_epoch();
72 uint64_t now_nano =
73 std::chrono::duration_cast<std::chrono::nanoseconds>(epoch).count();
74 return Time(now_nano);
75}

◆ Now()

Time apollo::cyber::Time::Now ( )
static

get the current time.

返回
return the current time.

在文件 time.cc57 行定义.

57 {
58 auto now = high_resolution_clock::now();
59 auto nano_time_point =
60 std::chrono::time_point_cast<std::chrono::nanoseconds>(now);
61 auto epoch = nano_time_point.time_since_epoch();
62 uint64_t now_nano =
63 std::chrono::duration_cast<std::chrono::nanoseconds>(epoch).count();
64 return Time(now_nano);
65}

◆ operator!=()

bool apollo::cyber::Time::operator!= ( const Time rhs) const

在文件 time.cc144 行定义.

144 {
145 return nanoseconds_ != rhs.nanoseconds_;
146}

◆ operator+()

Time apollo::cyber::Time::operator+ ( const Duration rhs) const

在文件 time.cc122 行定义.

122 {
123 return Time(nanoseconds_ + rhs.ToNanosecond());
124}

◆ operator+=()

Time & apollo::cyber::Time::operator+= ( const Duration rhs)

在文件 time.cc130 行定义.

130 {
131 *this = *this + rhs;
132 return *this;
133}

◆ operator-() [1/2]

Time apollo::cyber::Time::operator- ( const Duration rhs) const

在文件 time.cc126 行定义.

126 {
127 return Time(nanoseconds_ - rhs.ToNanosecond());
128}

◆ operator-() [2/2]

Duration apollo::cyber::Time::operator- ( const Time rhs) const

在文件 time.cc118 行定义.

118 {
119 return Duration(static_cast<int64_t>(nanoseconds_ - rhs.nanoseconds_));
120}
std::chrono::microseconds Duration
Definition croutine.h:36

◆ operator-=()

Time & apollo::cyber::Time::operator-= ( const Duration rhs)

在文件 time.cc135 行定义.

135 {
136 *this = *this - rhs;
137 return *this;
138}

◆ operator<()

bool apollo::cyber::Time::operator< ( const Time rhs) const

在文件 time.cc152 行定义.

152 {
153 return nanoseconds_ < rhs.nanoseconds_;
154}

◆ operator<=()

bool apollo::cyber::Time::operator<= ( const Time rhs) const

在文件 time.cc160 行定义.

160 {
161 return nanoseconds_ <= rhs.nanoseconds_;
162}

◆ operator=()

Time & apollo::cyber::Time::operator= ( const Time other)

在文件 time.cc52 行定义.

52 {
53 this->nanoseconds_ = other.nanoseconds_;
54 return *this;
55}

◆ operator==()

bool apollo::cyber::Time::operator== ( const Time rhs) const

在文件 time.cc140 行定义.

140 {
141 return nanoseconds_ == rhs.nanoseconds_;
142}

◆ operator>()

bool apollo::cyber::Time::operator> ( const Time rhs) const

在文件 time.cc148 行定义.

148 {
149 return nanoseconds_ > rhs.nanoseconds_;
150}

◆ operator>=()

bool apollo::cyber::Time::operator>= ( const Time rhs) const

在文件 time.cc156 行定义.

156 {
157 return nanoseconds_ >= rhs.nanoseconds_;
158}

◆ SleepUntil()

void apollo::cyber::Time::SleepUntil ( const Time time)
static

Sleep Until time.

参数
timethe Time object.

在文件 time.cc112 行定义.

112 {
113 auto nano = std::chrono::nanoseconds(time.ToNanosecond());
114 system_clock::time_point tp(nano);
115 std::this_thread::sleep_until(tp);
116}
uint64_t ToNanosecond() const
convert time to nanosecond.
Definition time.cc:83

◆ ToMicrosecond()

uint64_t apollo::cyber::Time::ToMicrosecond ( ) const

convert time to microsecond (us).

返回
return a unit64_t value unit is us.

在文件 time.cc85 行定义.

85 {
86 return static_cast<uint64_t>(nanoseconds_ / 1000.0);
87}

◆ ToNanosecond()

uint64_t apollo::cyber::Time::ToNanosecond ( ) const

convert time to nanosecond.

返回
return a unit64_t value unit is nanosecond.

在文件 time.cc83 行定义.

83{ return nanoseconds_; }

◆ ToSecond()

double apollo::cyber::Time::ToSecond ( ) const

convert time to second.

返回
return a double value unit is second.

在文件 time.cc77 行定义.

77 {
78 return static_cast<double>(nanoseconds_) / 1000000000UL;
79}

◆ ToString()

std::string apollo::cyber::Time::ToString ( ) const

convert time to a string.

返回
return a string.

在文件 time.cc89 行定义.

89 {
90 auto nano = std::chrono::nanoseconds(nanoseconds_);
91 system_clock::time_point tp(nano);
92 auto time = system_clock::to_time_t(tp);
93 struct tm stm;
94 auto ret = localtime_r(&time, &stm);
95 if (ret == nullptr) {
96 return std::to_string(static_cast<double>(nanoseconds_) / 1000000000.0);
97 }
98
99 std::stringstream ss;
100#if __GNUC__ >= 5
101 ss << std::put_time(ret, "%F %T");
102 ss << "." << std::setw(9) << std::setfill('0') << nanoseconds_ % 1000000000UL;
103#else
104 char date_time[128];
105 strftime(date_time, sizeof(date_time), "%F %T", ret);
106 ss << std::string(date_time) << "." << std::setw(9) << std::setfill('0')
107 << nanoseconds_ % 1000000000UL;
108#endif
109 return ss.str();
110}

类成员变量说明

◆ MAX

const Time apollo::cyber::Time::MAX = Time(std::numeric_limits<uint64_t>::max())
static

在文件 time.h33 行定义.

◆ MIN

const Time apollo::cyber::Time::MIN = Time(0)
static

在文件 time.h34 行定义.


该类的文档由以下文件生成: