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