xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
time_point.hpp
浏览该文件的文档.
1#pragma once
2#include <chrono>
3#include <string>
6
7namespace xcal::property {
8
17 private:
18 Proxy<size_t> microseconds_since_epoch_{this, 0};
19
20 public:
26
27 TimePoint(const TimePoint&) = delete;
28 TimePoint(TimePoint&&) = delete;
29 TimePoint& operator=(const TimePoint&) = delete;
35 explicit TimePoint(float_t seconds_since_epoch) : MProperty() {
36 set_seconds_since_epoch(seconds_since_epoch);
37 }
38
39 // /**
40 // * @brief 获取当前时间点
41 // * @return TimePoint 当前时间点
42 // */
43 // static TimePoint now() {
44 // auto now = std::chrono::system_clock::now();
45 // auto duration = now.time_since_epoch();
46 // auto microseconds =
47 // std::chrono::duration_cast<std::chrono::microseconds>(duration)
48 // .count();
49 // TimePoint timePoint;
50 // timePoint.set_microseconds_since_epoch(
51 // static_cast<size_t>(microseconds));
52 // return timePoint;
53 // }
54
59 size_t microseconds_since_epoch() const {
60 return microseconds_since_epoch_;
61 }
62
68 return static_cast<float_t>(microseconds_since_epoch_) / 1000000.0f;
69 }
70
76 microseconds_since_epoch_ = us;
77 }
78
84 microseconds_since_epoch_ = static_cast<size_t>(seconds * 1000000.0f);
85 }
86
87 // /**
88 // * @brief 时间点加法运算(添加时间段)
89 // * @param duration 要添加的时间段
90 // * @return TimePoint 相加后的时间点
91 // */
92 // TimePoint operator+(const TimeDuration& duration) const {
93 // TimePoint result;
94 // result.set_microseconds_since_epoch(microseconds_since_epoch_ +
95 // duration.microseconds());
96 // return result;
97 // }
98
99 // /**
100 // * @brief 时间点减法运算(减去时间段)
101 // * @param duration 要减去的时间段
102 // * @return TimePoint 相减后的时间点
103 // */
104 // TimePoint operator-(const TimeDuration& duration) const {
105 // TimePoint result;
106 // result.set_microseconds_since_epoch(microseconds_since_epoch_ -
107 // duration.microseconds());
108 // return result;
109 // }
110
116 TimeDuration operator-(const TimePoint& other) const {
117 return TimeDuration(microseconds_since_epoch_ -
118 other.microseconds_since_epoch_);
119 }
120
126 bool operator==(const TimePoint& other) const {
127 return microseconds_since_epoch_ == other.microseconds_since_epoch_;
128 }
129
135 bool operator!=(const TimePoint& other) const { return !(*this == other); }
136
142 bool operator<(const TimePoint& other) const {
143 return microseconds_since_epoch_ < other.microseconds_since_epoch_;
144 }
145
151 bool operator>(const TimePoint& other) const {
152 return microseconds_since_epoch_ > other.microseconds_since_epoch_;
153 }
154
160 bool operator<=(const TimePoint& other) const {
161 return microseconds_since_epoch_ <= other.microseconds_since_epoch_;
162 }
163
169 bool operator>=(const TimePoint& other) const {
170 return microseconds_since_epoch_ >= other.microseconds_since_epoch_;
171 }
172
177 std::string to_string() const {
178 // 简单的字符串表示,可以扩展为更复杂的格式
179 return std::to_string(seconds_since_epoch()) + "s since epoch";
180 }
181
187 std::string format(const std::string&) const {
188 // 占位实现,可以根据需要扩展具体的格式化逻辑
189 return to_string();
190 }
191};
192
193} // namespace xcal::property
时间点属性类
bool operator!=(const TimePoint &other) const
时间点不等比较
TimePoint & operator=(TimePoint &&)=delete
TimePoint(float_t seconds_since_epoch)
从浮点数秒构造函数
std::string to_string() const
转换为字符串表示
TimePoint(const TimePoint &)=delete
bool operator==(const TimePoint &other) const
时间点相等比较
bool operator>=(const TimePoint &other) const
时间点大于等于比较
TimePoint(TimePoint &&)=delete
void set_microseconds_since_epoch(size_t us)
设置从纪元开始的微秒数
bool operator<(const TimePoint &other) const
时间点小于比较
bool operator>(const TimePoint &other) const
时间点大于比较
float_t seconds_since_epoch() const
获取从纪元开始的秒数
bool operator<=(const TimePoint &other) const
时间点小于等于比较
TimePoint & operator=(const TimePoint &)=delete
TimeDuration operator-(const TimePoint &other) const
时间点减法运算(计算时间差)
size_t microseconds_since_epoch() const
获取从纪元开始的微秒数
std::string format(const std::string &) const
格式化时间输出
TimePoint()
默认构造函数
void set_seconds_since_epoch(float_t seconds)
设置从纪元开始的秒数
XCAL_API const char * to_string(xcal::camera::CameraType type)
float float_t
Definition public.h:27
#define XCAL_PROPERTY_TYPE(type)
Definition property.hpp:6
#define XCAL_API
Definition public.h:69