4#ifndef QDEADLINETIMER_H
5#define QDEADLINETIMER_H
7#include <QtCore/qelapsedtimer.h>
8#include <QtCore/qmetatype.h>
9#include <QtCore/qnamespace.h>
10#include <QtCore/qpair.h>
32 :
t1((std::numeric_limits<qint64>::max)()),
type(type_) {}
39 {
return t1 == (std::numeric_limits<qint64>::max)(); }
40 bool hasExpired() const noexcept;
42 Qt::TimerType timerType() const noexcept
46 qint64 remainingTime() const noexcept;
47 qint64 remainingTimeNSecs() const noexcept;
49 void setPreciseRemainingTime(
qint64 secs,
qint64 nsecs = 0,
50 Qt::TimerType
type =
Qt::CoarseTimer) noexcept;
54 void setDeadline(
qint64 msecs,
Qt::TimerType timerType =
Qt::CoarseTimer) noexcept;
56 Qt::TimerType
type =
Qt::CoarseTimer) noexcept;
62 {
return d1.t1 ==
d2.t1; }
64 {
return !(
d1 ==
d2); }
66 {
return d1.t1 <
d2.t1; }
72 {
return !(
d1 <
d2); }
76 {
return dt + msecs; }
78 {
return dt + (-msecs); }
82 { *
this = *
this + msecs;
return *
this; }
84 { *
this = *
this + (-msecs);
return *
this; }
86 template <
class Clock,
class Duration =
typename Clock::duration>
89 { setDeadline(deadline_, type_); }
90 template <
class Clock,
class Duration =
typename Clock::duration>
92 { setDeadline(deadline_);
return *
this; }
94 template <
class Clock,
class Duration =
typename Clock::duration>
95 void setDeadline(std::chrono::time_point<Clock, Duration> tp,
98 template <
class Clock,
class Duration =
typename Clock::duration>
99 std::chrono::time_point<Clock, Duration>
deadline()
const;
101 template <
class Rep,
class Period>
106 template <
class Rep,
class Period>
110 template <
class Rep,
class Period>
113 using namespace std::chrono;
114 if (remaining == remaining.max())
117 setPreciseRemainingTime(0, ceil<nanoseconds>(remaining).
count(), type_);
123 return std::chrono::nanoseconds::max();
124 qint64 nsecs = rawRemainingTimeNSecs();
126 return std::chrono::nanoseconds::zero();
127 return std::chrono::nanoseconds(nsecs);
130 template <
class Rep,
class Period>
133 template <
class Rep,
class Period>
135 {
return dt +
value; }
136 template <
class Rep,
class Period>
138 {
return dt = dt +
value; }
142#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
147 qint64 rawRemainingTimeNSecs() const noexcept;
150template<class Clock, class Duration>
153 using namespace std::chrono;
154 if constexpr (std::is_same_v<Clock, steady_clock>) {
156 return time_point<Clock, Duration>(
val);
158 auto val = nanoseconds(rawRemainingTimeNSecs()) + Clock::now();
159 return time_point_cast<Duration>(
val);
163template<
class Clock,
class Duration>
166 using namespace std::chrono;
167 if (tp == tp.max()) {
170 }
else if constexpr (std::is_same_v<Clock, steady_clock>) {
171 setPreciseDeadline(0,
172 duration_cast<nanoseconds>(tp.time_since_epoch()).count(),
175 setPreciseRemainingTime(0, duration_cast<nanoseconds>(tp - Clock::now()).
count(), type_);
friend bool operator>(QDeadlineTimer d1, QDeadlineTimer d2) noexcept
Returns true if the deadline on d1 is later than the deadline in d2, false otherwise.
void setDeadline(qint64 msecs, Qt::TimerType timerType=Qt::CoarseTimer) noexcept
Sets the deadline for this QDeadlineTimer object to be the msecs absolute time point,...
friend QDeadlineTimer operator+(std::chrono::duration< Rep, Period > value, QDeadlineTimer dt)
friend bool operator<=(QDeadlineTimer d1, QDeadlineTimer d2) noexcept
Returns true if the deadline on d1 is earlier than or the same as the deadline in d2,...
friend bool operator!=(QDeadlineTimer d1, QDeadlineTimer d2) noexcept
Returns true if the deadline on d1 and the deadline in d2 are different, false otherwise.
QDeadlineTimer(std::chrono::duration< Rep, Period > remaining, Qt::TimerType type_=Qt::CoarseTimer)
Constructs a QDeadlineTimer object with a remaining time of remaining.
friend QDeadlineTimer operator+=(QDeadlineTimer &dt, std::chrono::duration< Rep, Period > value)
static QDeadlineTimer addNSecs(QDeadlineTimer dt, qint64 nsecs) noexcept Q_DECL_PURE_FUNCTION
Returns a QDeadlineTimer object whose deadline is extended from dt's deadline by nsecs nanoseconds.
QDeadlineTimer & operator=(std::chrono::duration< Rep, Period > remaining)
Sets this deadline timer to the remaining time.
friend QDeadlineTimer operator+(qint64 msecs, QDeadlineTimer dt)
Returns a QDeadlineTimer object whose deadline is msecs later than the deadline stored in dt.
QDeadlineTimer(std::chrono::time_point< Clock, Duration > deadline_, Qt::TimerType type_=Qt::CoarseTimer)
Constructs a QDeadlineTimer object with a deadline at deadline time point, converting from the clock ...
ForeverConstant
\value Forever Used when creating a QDeadlineTimer to indicate the deadline should not expire
constexpr QDeadlineTimer(ForeverConstant, Qt::TimerType type_=Qt::CoarseTimer) noexcept
QDeadlineTimer objects created with ForeverConstant never expire.
QDeadlineTimer & operator=(std::chrono::time_point< Clock, Duration > deadline_)
Assigns deadline_ to this deadline timer.
friend bool operator>=(QDeadlineTimer d1, QDeadlineTimer d2) noexcept
Returns true if the deadline on d1 is later than or the same as the deadline in d2,...
friend bool operator<(QDeadlineTimer d1, QDeadlineTimer d2) noexcept
Returns true if the deadline on d1 is earlier than the deadline in d2, false otherwise.
constexpr bool isForever() const noexcept
Returns true if this QDeadlineTimer object never expires, false otherwise.
friend qint64 operator-(QDeadlineTimer dt1, QDeadlineTimer dt2)
void swap(QDeadlineTimer &other) noexcept
Swaps this deadline timer with the other deadline timer.
friend QDeadlineTimer operator-(QDeadlineTimer dt, qint64 msecs)
Returns a QDeadlineTimer object whose deadline is msecs before the deadline stored in dt.
friend QDeadlineTimer operator+(QDeadlineTimer dt, std::chrono::duration< Rep, Period > value)
std::chrono::nanoseconds remainingTimeAsDuration() const noexcept
Returns the time remaining before the deadline.
qint64 deadlineNSecs() const noexcept Q_DECL_PURE_FUNCTION
Returns the absolute time point for the deadline stored in QDeadlineTimer object, calculated in nanos...
QDeadlineTimer & operator-=(qint64 msecs)
Shortens this QDeadlineTimer object by msecs milliseconds and returns itself.
QDeadlineTimer & operator+=(qint64 msecs)
Extends this QDeadlineTimer object by msecs milliseconds and returns itself.
void setRemainingTime(std::chrono::duration< Rep, Period > remaining, Qt::TimerType type_=Qt::CoarseTimer)
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr QDeadlineTimer(Qt::TimerType type_=Qt::CoarseTimer) noexcept
Constructs an expired QDeadlineTimer object.
Combined button and popup list for selecting options.
#define Q_DECL_PURE_FUNCTION
constexpr timespec operator+(const timespec &t1, const timespec &t2)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLenum GLsizei count
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
QDeadlineTimer deadline(30s)
return d1 deadlineNSecs()
[7]
deadline setRemainingTime(250ms)