libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::MicrosecondTimestamp Class Reference

微秒时间戳 / Microsecond timestamp More...

#include <libxr_time.hpp>

Data Structures

class  Duration
 微秒时长 / Duration in microseconds More...
 

Public Member Functions

 MicrosecondTimestamp ()=default
 创建零值微秒时间戳 / Construct a zero microsecond timestamp
 
 MicrosecondTimestamp (uint64_t microsecond)
 从微秒计数构造时间戳 / Construct a timestamp from microsecond ticks
 
 operator uint64_t () const
 转换为微秒计数值 / Convert to the raw microsecond tick count
 
Duration operator- (const MicrosecondTimestamp &old_timestamp) const
 计算时间差,支持时间基准回绕 / Compute elapsed time with timebase wraparound
 
MicrosecondTimestampoperator= (const MicrosecondTimestamp &other)=default
 复制赋值 / Copy-assign from another timestamp
 

Private Attributes

uint64_t microsecond_ = 0
 

Detailed Description

微秒时间戳 / Microsecond timestamp

Definition at line 46 of file libxr_time.hpp.

Constructor & Destructor Documentation

◆ MicrosecondTimestamp()

LibXR::MicrosecondTimestamp::MicrosecondTimestamp ( uint64_t microsecond)
inline

从微秒计数构造时间戳 / Construct a timestamp from microsecond ticks

Parameters
microsecond微秒计数值 / Microsecond tick count

Definition at line 58 of file libxr_time.hpp.

58: microsecond_(microsecond) {}

Member Function Documentation

◆ operator uint64_t()

LibXR::MicrosecondTimestamp::operator uint64_t ( ) const
inline

转换为微秒计数值 / Convert to the raw microsecond tick count

Returns
微秒计数值 / Raw microsecond tick count

Definition at line 64 of file libxr_time.hpp.

64{ return microsecond_; }

◆ operator-()

Duration LibXR::MicrosecondTimestamp::operator- ( const MicrosecondTimestamp & old_timestamp) const
inlinenodiscard

计算时间差,支持时间基准回绕 / Compute elapsed time with timebase wraparound

Parameters
old_timestamp旧时间戳 / Older timestamp
Returns
当前时间戳相对旧时间戳的时长 / Elapsed duration from the older timestamp
Note
若当前时间戳小于旧时间戳,则按一次时间基准回绕处理,回绕上界由 当前已配置的微秒时间基准有效上界指定。 / If the current timestamp is smaller than the older one, the function treats it as one wraparound event whose upper bound is defined by the currently configured microsecond timebase limit.

Definition at line 129 of file libxr_time.hpp.

130 {
131 uint64_t elapsed = 0;
132 const uint64_t max_valid = Detail::TimebaseMaxValidUs();
133
134 if (microsecond_ >= old_timestamp.microsecond_)
135 {
136 elapsed = microsecond_ - old_timestamp.microsecond_;
137 }
138 else
139 {
140 elapsed = microsecond_ + (max_valid - old_timestamp.microsecond_) + 1ULL;
141 }
142
143 ASSERT(elapsed <= max_valid);
144
145 return Duration(elapsed);
146 }

◆ operator=()

MicrosecondTimestamp & LibXR::MicrosecondTimestamp::operator= ( const MicrosecondTimestamp & other)
default

复制赋值 / Copy-assign from another timestamp

Parameters
other源时间戳 / Source timestamp
Returns
当前对象引用 / Reference to this object

Field Documentation

◆ microsecond_

uint64_t LibXR::MicrosecondTimestamp::microsecond_ = 0
private

Definition at line 156 of file libxr_time.hpp.


The documentation for this class was generated from the following file: