SqpRange.h
58 lines
| 1.5 KiB
| text/x-c
|
CLexer
r511 | #ifndef SCIQLOP_SQPRANGE_H | |||
#define SCIQLOP_SQPRANGE_H | ||||
r191 | ||||
r234 | #include <QObject> | |||
r296 | ||||
#include <QDebug> | ||||
Alexandre Leroux
|
r488 | #include <Common/DateUtils.h> | ||
Alexandre Leroux
|
r308 | #include <Common/MetaTypes.h> | ||
Alexandre Leroux
|
r660 | #include <cmath> | ||
r191 | /** | |||
r511 | * @brief The SqpRange struct holds the information of time parameters | |||
r191 | */ | |||
r511 | struct SqpRange { | |||
Alexandre Leroux
|
r491 | /// Start time (UTC) | ||
r191 | double m_TStart; | |||
Alexandre Leroux
|
r491 | /// End time (UTC) | ||
r191 | double m_TEnd; | |||
r228 | ||||
r511 | bool contains(const SqpRange &dateTime) const noexcept | |||
r228 | { | |||
return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd); | ||||
} | ||||
r258 | ||||
r511 | bool intersect(const SqpRange &dateTime) const noexcept | |||
r258 | { | |||
return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd); | ||||
} | ||||
Alexandre Leroux
|
r654 | |||
bool operator==(const SqpRange &other) const | ||||
{ | ||||
auto equals = [](const auto &v1, const auto &v2) { | ||||
return (std::isnan(v1) && std::isnan(v2)) || v1 == v2; | ||||
}; | ||||
return equals(m_TStart, other.m_TStart) && equals(m_TEnd, other.m_TEnd); | ||||
} | ||||
bool operator!=(const SqpRange &other) const { return !(*this == other); } | ||||
r191 | }; | |||
Alexandre Leroux
|
r654 | const auto INVALID_RANGE | ||
= SqpRange{std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()}; | ||||
r511 | inline QDebug operator<<(QDebug d, SqpRange obj) | |||
r296 | { | |||
Alexandre Leroux
|
r488 | auto tendDateTimeStart = DateUtils::dateTime(obj.m_TStart); | ||
auto tendDateTimeEnd = DateUtils::dateTime(obj.m_TEnd); | ||||
r296 | ||||
d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd; | ||||
return d; | ||||
} | ||||
r234 | // Required for using shared_ptr in signals/slots | |||
r511 | SCIQLOP_REGISTER_META_TYPE(SQPRANGE_REGISTRY, SqpRange) | |||
r234 | ||||
r511 | #endif // SCIQLOP_SQPRANGE_H | |||