28#include "AstUtil/Logger.hpp"
51AST_CORE_CAPI errc_t
aTimeIntervalFormat(
const TimeInterval& interval, std::string& strStart, std::string& strEnd,
int precision = kTimePointDefaultFormatPrecision);
58AST_CORE_CAPI errc_t
aTimeIntervalParse(StringView strStart, StringView strEnd, TimeInterval& interval);
76 TimePoint{0, -std::numeric_limits<double>::infinity()});
83 TimePoint{0, +std::numeric_limits<double>::infinity()});
91 ~TimeInterval() =
default;
97 : start_(start), stop_(stop) {}
104 : start_(epoch + start), stop_(epoch + stop) {}
142 start_ = epoch + start;
143 stop_ = epoch + stop;
151 start_ = epoch + interval.start();
152 stop_ = epoch + interval.stop();
166 return Interval{getStart() - epoch, getStop() - epoch};
172 start_ = {0, -std::numeric_limits<double>::infinity()};
173 stop_ = {0, +std::numeric_limits<double>::infinity()};
178 start_ = {0, +std::numeric_limits<double>::infinity()};
179 stop_ = {0, -std::numeric_limits<double>::infinity()};
186 bool isEmpty()
const {
return !(start_ <= stop_); }
188 bool isPoint()
const {
return start_ == stop_; }
192 bool isValid()
const {
return start_ <= stop_; }
200 bool isWhole()
const{
return start_.isInf() && stop_.isInf();}
202 bool isInf()
const {
return start_.isInf() || stop_.isInf();}
207 std::string
toString(
int precision = kTimePointDefaultFormatPrecision)
const{
208 std::string strStart, strEnd;
210 return strStart +
" - " + strEnd;
219 errc_t discretize(
const TimePoint& epoch,
double step, std::vector<double>& times)
const;
226 errc_t discretize(
double step, std::vector<TimePoint>& times)
const;
233 errc_t discretize(
double step,
TimeList& times)
const;
254 double dur = duration();
255 if (step > 0 && dur >= 0)
315 double dur = duration();
316 if (step > 0 && dur >= 0)
326 double dur = duration();
327 if (step > 0 && dur >= 0)
329 double start = getStart() - epoch;
330 double stop = getStop() - epoch;
344A_ALWAYS_INLINE
bool operator!=(
const TimeInterval& lhs,
const TimeInterval& rhs)
346 return !(lhs == rhs);
按步长采样的相对秒范围(惰性可迭代)
定义 DoubleRange.hpp:43
时间区间
定义 TimeInterval.hpp:64
bool isValid() const
是否非空(start_ <= stop_,即点区间或有效区间)
定义 TimeInterval.hpp:192
Interval toInterval(const TimePoint &epoch) const
将绝对时间区间转换为相对于给定基准历元的相对时间区间
定义 TimeInterval.hpp:164
double duration() const
时间区间的持续时间(秒)
定义 TimeInterval.hpp:183
TimeInterval & operator|=(const TimeInterval &other)
原地并集(等价于 unite)
定义 TimeInterval.hpp:297
bool isNonEmpty() const
isValid() 的别名
定义 TimeInterval.hpp:194
static TimeInterval Empty()
空区间哨兵({+∞, -∞},IEEE 1788 惯例)
定义 TimeInterval.hpp:74
TimeInterval(const TimePoint &epoch, double start, double stop)
构造函数
定义 TimeInterval.hpp:103
static TimeInterval Whole()
时间区间全集({-∞, +∞})
定义 TimeInterval.hpp:80
const TimePoint & getStart() const
时间区间的开始时间点
定义 TimeInterval.hpp:110
void setBounds(TimePoint epoch, const Interval &interval)
设置时间区间的开始时间点和结束时间点
定义 TimeInterval.hpp:150
void setBounds(TimePoint start, TimePoint stop)
设置时间区间的开始时间点和结束时间点
定义 TimeInterval.hpp:130
bool isDegenerate() const
isPoint() 的别名
定义 TimeInterval.hpp:190
TimeInterval operator&(const TimeInterval &other) const
交集(返回副本,等价于 intersected)
定义 TimeInterval.hpp:306
void setEmpty()
设置时间区间为空区间
定义 TimeInterval.hpp:176
void setStart(const TimePoint &start)
设置时间区间的开始时间点
定义 TimeInterval.hpp:113
bool isEmpty() const
是否为空区间(start_ > stop_,弱序否定;反向 / {+∞,-∞} 哨兵 / NaN → true)
定义 TimeInterval.hpp:186
bool contains(const TimePoint &t) const
是否包含绝对时间点 t(闭区间含端点)
定义 TimeInterval.hpp:196
size_t discretizedCount(double step) const
计算离散化采样点数量
定义 TimeInterval.hpp:252
bool isPoint() const
是否为点区间(start_ == stop_,恰含一个瞬时,非空)
定义 TimeInterval.hpp:188
const TimePoint & stop() const
时间区间的结束时间点
定义 TimeInterval.hpp:116
void setBounds(TimePoint epoch, double start, double stop)
设置时间区间的开始时间点和结束时间点
定义 TimeInterval.hpp:141
const TimePoint & start() const
时间区间的开始时间点
定义 TimeInterval.hpp:107
std::string toString(int precision=kTimePointDefaultFormatPrecision) const
将时间区间转换为字符串
定义 TimeInterval.hpp:207
const TimePoint & getStop() const
时间区间的结束时间点
定义 TimeInterval.hpp:119
TimeInterval operator|(const TimeInterval &other) const
并集(返回副本,等价于 united)
定义 TimeInterval.hpp:300
bool isInf() const
是否有区间至少一个端点为无穷大/无穷小
定义 TimeInterval.hpp:202
TimeInterval(const TimePoint &start, const TimePoint &stop)
构造函数
定义 TimeInterval.hpp:96
TimeInterval & operator&=(const TimeInterval &other)
原地交集(等价于 intersect)
定义 TimeInterval.hpp:303
void setWhole()
设置时间区间为全区间
定义 TimeInterval.hpp:170
void setStop(const TimePoint &stop)
设置时间区间的结束时间点
定义 TimeInterval.hpp:122
bool isWhole() const
是否为全区间(start_ == -∞, stop_ == +∞)
定义 TimeInterval.hpp:200
bool contains(const TimeInterval &interval) const
是否包含时间区间 interval(闭区间含端点)
定义 TimeInterval.hpp:198
按步长采样的时间点范围(惰性可迭代)
定义 TimePointRange.hpp:43
绝对时间点
定义 TimePoint.hpp:108
errc_t aTimeIntervalParse(StringView strStart, StringView strStop, TimeInterval &interval)
从字符串解析时间区间
定义 TimeInterval.cpp:37
errc_t aTimeIntervalFormat(const TimeInterval &interval, std::string &strStart, std::string &strStop, int precision)
将时间区间格式化为字符串
定义 TimeInterval.cpp:27
A_ALWAYS_INLINE size_t aDiscretizedCount(double span, double step)
计算闭区间 [0, span] 按 step 步长采样(含两端点)的采样点数
定义 Math.hpp:107