1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.core.deadlinetimer;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.global;
19 import qt.core.namespace;
20 import qt.core.pair;
21 import qt.core.typeinfo;
22 import qt.helpers;
23 
24 /+ #ifdef max
25 // un-pollute the namespace. We need std::numeric_limits::max() and std::chrono::duration::max()
26 #  undef max
27 #endif
28 
29 #if __has_include(<chrono>)
30 #endif +/
31 
32 
33 @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QDeadlineTimer
34 {
35 public:
36     enum ForeverConstant { Forever }
37 
38     @disable this();
39     this(/+ Qt:: +/qt.core.namespace.TimerType type_/+ = /+ Qt:: +/qt.core.namespace.TimerType.CoarseTimer+/)/+ noexcept+/
40     {
41         this.t1 = 0;
42         this.t2 = 0;
43         this.type = type_;
44     }
45     this(ForeverConstant, /+ Qt:: +/qt.core.namespace.TimerType type_ = /+ Qt:: +/qt.core.namespace.TimerType.CoarseTimer)/+ noexcept+/
46     {
47         this.t1 = qint64.max;
48         this.t2 = 0;
49         this.type = type_;
50     }
51     /+ explicit +/this(qint64 msecs, /+ Qt:: +/qt.core.namespace.TimerType type = /+ Qt:: +/qt.core.namespace.TimerType.CoarseTimer)/+ noexcept+/;
52 
53     /+ void swap(QDeadlineTimer &other) noexcept
54     { qSwap(t1, other.t1); qSwap(t2, other.t2); qSwap(type, other.type); } +/
55 
56     bool isForever() const/+ noexcept+/
57     { return t1 == qint64.max; }
58     bool hasExpired() const/+ noexcept+/;
59 
60     /+ Qt:: +/qt.core.namespace.TimerType timerType() const/+ noexcept+/
61     { return cast(/+ Qt:: +/qt.core.namespace.TimerType)(type & 0xff); }
62     void setTimerType(/+ Qt:: +/qt.core.namespace.TimerType type);
63 
64     qint64 remainingTime() const/+ noexcept+/;
65     qint64 remainingTimeNSecs() const/+ noexcept+/;
66     void setRemainingTime(qint64 msecs, /+ Qt:: +/qt.core.namespace.TimerType type = /+ Qt:: +/qt.core.namespace.TimerType.CoarseTimer)/+ noexcept+/;
67     void setPreciseRemainingTime(qint64 secs, qint64 nsecs = 0,
68                                      /+ Qt:: +/qt.core.namespace.TimerType type = /+ Qt:: +/qt.core.namespace.TimerType.CoarseTimer)/+ noexcept+/;
69 
70     qint64 deadline() const/+ noexcept /+ Q_DECL_PURE_FUNCTION +/__attribute__((pure))+/;
71     qint64 deadlineNSecs() const/+ noexcept /+ Q_DECL_PURE_FUNCTION +/__attribute__((pure))+/;
72     void setDeadline(qint64 msecs, /+ Qt:: +/qt.core.namespace.TimerType timerType = /+ Qt:: +/qt.core.namespace.TimerType.CoarseTimer)/+ noexcept+/;
73     void setPreciseDeadline(qint64 secs, qint64 nsecs = 0,
74                                 /+ Qt:: +/qt.core.namespace.TimerType type = /+ Qt:: +/qt.core.namespace.TimerType.CoarseTimer)/+ noexcept+/;
75 
76     static QDeadlineTimer addNSecs(QDeadlineTimer dt, qint64 nsecs)/+ noexcept /+ Q_DECL_PURE_FUNCTION +/__attribute__((pure))+/;
77     static QDeadlineTimer current(/+ Qt:: +/qt.core.namespace.TimerType timerType = /+ Qt:: +/qt.core.namespace.TimerType.CoarseTimer)/+ noexcept+/;
78 
79     /+ friend bool operator==(QDeadlineTimer d1, QDeadlineTimer d2) noexcept
80     { return d1.t1 == d2.t1 && d1.t2 == d2.t2; } +/
81     /+ friend bool operator!=(QDeadlineTimer d1, QDeadlineTimer d2) noexcept
82     { return !(d1 == d2); } +/
83     /+ friend bool operator<(QDeadlineTimer d1, QDeadlineTimer d2) noexcept
84     { return d1.t1 < d2.t1 || (d1.t1 == d2.t1 && d1.t2 < d2.t2); } +/
85     /+ friend bool operator<=(QDeadlineTimer d1, QDeadlineTimer d2) noexcept
86     { return d1 == d2 || d1 < d2; } +/
87     /+ friend bool operator>(QDeadlineTimer d1, QDeadlineTimer d2) noexcept
88     { return d2 < d1; } +/
89     /+ friend bool operator>=(QDeadlineTimer d1, QDeadlineTimer d2) noexcept
90     { return !(d1 < d2); } +/
91 
92     /+ friend Q_CORE_EXPORT QDeadlineTimer operator+(QDeadlineTimer dt, qint64 msecs); +/
93     /+ friend QDeadlineTimer operator+(qint64 msecs, QDeadlineTimer dt)
94     { return dt + msecs; } +/
95     /+ friend QDeadlineTimer operator-(QDeadlineTimer dt, qint64 msecs)
96     { return dt + (-msecs); } +/
97     /+ friend qint64 operator-(QDeadlineTimer dt1, QDeadlineTimer dt2)
98     { return (dt1.deadlineNSecs() - dt2.deadlineNSecs()) / (1000 * 1000); } +/
99     ref QDeadlineTimer opOpAssign(string op)(qint64 msecs) if(op == "+")
100     { this = this + msecs; return this; }
101     ref QDeadlineTimer opOpAssign(string op)(qint64 msecs) if(op == "-")
102     { this = this + (-msecs); return this; }
103 
104 /+ #if __has_include(<chrono>) || defined(Q_CLANG_QDOC) +/
105     /+ template <class Clock, class Duration> +/
106     /+ QDeadlineTimer(std::chrono::time_point<Clock, Duration> deadline_,
107                    Qt::TimerType type_ = Qt::CoarseTimer) : t2(0)
108     { setDeadline(deadline_, type_); } +/
109     /+ template <class Clock, class Duration> +/
110     /+ QDeadlineTimer &operator=(std::chrono::time_point<Clock, Duration> deadline_)
111     { setDeadline(deadline_); return *this; } +/
112 
113     /+ template <class Clock, class Duration> +/
114     /+ void setDeadline(std::chrono::time_point<Clock, Duration> deadline_,
115                      Qt::TimerType type_ = Qt::CoarseTimer)
116     { setRemainingTime(deadline_ == deadline_.max() ? Duration::max() : deadline_ - Clock::now(), type_); } +/
117 
118     /+ template <class Clock, class Duration = typename Clock::duration> +/
119     /+ std::chrono::time_point<Clock, Duration> deadline() const
120     {
121         auto val = std::chrono::nanoseconds(rawRemainingTimeNSecs()) + Clock::now();
122         return std::chrono::time_point_cast<Duration>(val);
123     } +/
124 
125     /+ template <class Rep, class Period> +/
126     /+ QDeadlineTimer(std::chrono::duration<Rep, Period> remaining, Qt::TimerType type_ = Qt::CoarseTimer)
127         : t2(0)
128     { setRemainingTime(remaining, type_); } +/
129 
130     /+ template <class Rep, class Period> +/
131     /+ QDeadlineTimer &operator=(std::chrono::duration<Rep, Period> remaining)
132     { setRemainingTime(remaining); return *this; } +/
133 
134     /+ template <class Rep, class Period> +/
135     /+ void setRemainingTime(std::chrono::duration<Rep, Period> remaining, Qt::TimerType type_ = Qt::CoarseTimer)
136     {
137         if (remaining == remaining.max())
138             *this = QDeadlineTimer(Forever, type_);
139         else
140             setPreciseRemainingTime(0, std::chrono::nanoseconds(remaining).count(), type_);
141     } +/
142 
143 /+    /+ std::chrono:: +/nanoseconds remainingTimeAsDuration() const/+ noexcept+/
144     {
145         if (isForever())
146             return /+ std:: +//+ chrono:: +/nanoseconds.max();
147         qint64 nsecs = rawRemainingTimeNSecs();
148         if (nsecs <= 0)
149             return /+ std:: +//+ chrono:: +/nanoseconds.zero();
150         return /+ std:: +//+ chrono:: +/nanoseconds(nsecs);
151     }+/
152 
153     /+ template <class Rep, class Period> +/
154     /+ friend QDeadlineTimer operator+(QDeadlineTimer dt, std::chrono::duration<Rep, Period> value)
155     { return QDeadlineTimer::addNSecs(dt, std::chrono::duration_cast<std::chrono::nanoseconds>(value).count()); } +/
156     /+ template <class Rep, class Period> +/
157     /+ friend QDeadlineTimer operator+(std::chrono::duration<Rep, Period> value, QDeadlineTimer dt)
158     { return dt + value; } +/
159     /+ template <class Rep, class Period> +/
160     /+ friend QDeadlineTimer operator+=(QDeadlineTimer &dt, std::chrono::duration<Rep, Period> value)
161     { return dt = dt + value; } +/
162 /+ #endif +/
163 
164 private:
165     qint64 t1;
166     uint t2;
167     uint type;
168 
169     qint64 rawRemainingTimeNSecs() const/+ noexcept+/;
170 
171 public:
172     // This is not a public function, it's here only for Qt's internal convenience...
173     QPair!(qint64, uint) _q_data() const { return qMakePair(t1, t2); }
174 }
175 
176 /+ Q_DECLARE_SHARED(QDeadlineTimer)
177 
178 
179 Q_DECLARE_METATYPE(QDeadlineTimer) +/
180