KCalendarCore

duration.h
Go to the documentation of this file.
1 /*
2  This file is part of the kcalcore library.
3 
4  SPDX-FileCopyrightText: 2001-2003 Cornelius Schumacher <[email protected]>
5  SPDX-FileCopyrightText: 2007 David Jarvie <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
18 #ifndef KCALCORE_DURATION_H
19 #define KCALCORE_DURATION_H
20 
21 #include "kcalendarcore_export.h"
22 
23 #include <QDataStream>
24 #include <QHash>
25 #include <QMetaType>
26 
27 class QDateTime;
28 
29 namespace KCalendarCore
30 {
31 
44 class KCALENDARCORE_EXPORT Duration
45 {
46 public:
50  enum Type {
52  Days
53  };
54 
58  Duration();
59 
71  Duration(const QDateTime &start, const QDateTime &end);
72 
84  Duration(const QDateTime &start, const QDateTime &end, Type type);
85 
92  // Keep the following implicit since instances are often used in integer evaluations.
93  Duration(int duration, Type type = Seconds); //krazy:exclude=explicit
94 
100  Duration(const Duration &duration);
101 
105  ~Duration();
106 
112  Duration &operator=(const Duration &duration);
113 
117  operator bool() const;
118 
122  bool operator!() const
123  {
124  return !operator bool();
125  }
126 
131  bool operator<(const Duration &other) const;
132 
137  bool operator<=(const Duration &other) const
138  {
139  return !other.operator < (*this);
140  }
141 
146  bool operator>(const Duration &other) const
147  {
148  return other.operator < (*this);
149  }
150 
155  bool operator>=(const Duration &other) const
156  {
157  return !operator<(other);
158  }
159 
167  bool operator==(const Duration &other) const;
168 
176  bool operator!=(const Duration &other) const
177  {
178  return !operator==(other);
179  }
180 
187  Duration &operator+=(const Duration &other);
188 
197  Duration operator+(const Duration &other) const
198  {
199  return Duration(*this) += other;
200  }
201 
205  Duration operator-() const;
206 
214  Duration &operator-=(const Duration &other);
215 
224  Duration operator-(const Duration &other) const
225  {
226  return Duration(*this) += other;
227  }
228 
233  Duration &operator*=(int value);
234 
241  Duration operator*(int value) const
242  {
243  return Duration(*this) *= value;
244  }
245 
250  Duration &operator/=(int value);
251 
258  Duration operator/(int value) const
259  {
260  return Duration(*this) /= value;
261  }
262 
270  Q_REQUIRED_RESULT QDateTime end(const QDateTime &start) const;
271 
275  Q_REQUIRED_RESULT Type type() const;
276 
281  Q_REQUIRED_RESULT bool isDaily() const;
282 
286  Q_REQUIRED_RESULT int asSeconds() const;
287 
293  Q_REQUIRED_RESULT int asDays() const;
294 
300  Q_REQUIRED_RESULT int value() const;
301 
305  Q_REQUIRED_RESULT bool isNull() const;
306 
307 private:
308  //@cond PRIVATE
309  class Private;
310  Private *const d;
311  //@endcond
312 
313  friend KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalendarCore::Duration &);
314  friend KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &s, KCalendarCore::Duration &);
315 };
316 
322 KCALENDARCORE_EXPORT QDataStream &operator<<(QDataStream &out, const KCalendarCore::Duration &);
323 
329 KCALENDARCORE_EXPORT QDataStream &operator>>(QDataStream &in, KCalendarCore::Duration &);
330 
331 inline uint qHash(const Duration &duration, uint seed = 0)
332 {
333  return qHash(qMakePair(duration.isDaily(), duration.asSeconds()), seed);
334 }
335 
336 }
337 
338 Q_DECLARE_METATYPE(KCalendarCore::Duration)
339 
340 #endif
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
Alarm serializer.
Definition: alarm.cpp:825
Duration operator+(const Duration &other) const
Adds two durations.
Definition: duration.h:197
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
Alarm deserializer.
Definition: alarm.cpp:849
bool operator>=(const Duration &other) const
Returns true if this duration is greater than or equal to the other.
Definition: duration.h:155
Duration operator*(int value) const
Multiplies a duration by a value.
Definition: duration.h:241
Represents a span of time measured in seconds or days.
Definition: duration.h:44
bool isDaily() const
Returns whether the duration is specified in terms of days rather than seconds.
Definition: duration.cpp:183
bool operator<=(const Duration &other) const
Returns true if this duration is smaller than or equal to the other.
Definition: duration.h:137
duration is a number of seconds
Definition: duration.h:51
bool operator>(const Duration &other) const
Returns true if this duration is greater than the other.
Definition: duration.h:146
bool operator!() const
Returns true if this duration is zero.
Definition: duration.h:122
Duration operator-(const Duration &other) const
Returns the difference between another duration and this.
Definition: duration.h:224
Type
The unit of time used to define the duration.
Definition: duration.h:50
int asSeconds() const
Returns the length of the duration in seconds.
Definition: duration.cpp:188
bool operator!=(const Duration &other) const
Returns true if this duration is not equal to the other.
Definition: duration.h:176
Namespace for all KCalendarCore types.
Definition: alarm.h:36
Duration operator/(int value) const
Divides a duration by a value.
Definition: duration.h:258
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 10 2020 22:54:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.