summaryrefslogtreecommitdiffstats
path: root/src/multimedia/qmediatimerange.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimedia/qmediatimerange.h')
-rw-r--r--src/multimedia/qmediatimerange.h158
1 files changed, 78 insertions, 80 deletions
diff --git a/src/multimedia/qmediatimerange.h b/src/multimedia/qmediatimerange.h
index 97524f24a..7245a845a 100644
--- a/src/multimedia/qmediatimerange.h
+++ b/src/multimedia/qmediatimerange.h
@@ -1,131 +1,129 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMEDIATIMERANGE_H
#define QMEDIATIMERANGE_H
#include <QtMultimedia/qtmultimediaglobal.h>
-#include <QtMultimedia/qmultimedia.h>
#include <QtCore/qshareddata.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qmetatype.h>
QT_BEGIN_NAMESPACE
class QMediaTimeRangePrivate;
-class Q_MULTIMEDIA_EXPORT QMediaTimeInterval
-{
-public:
- QMediaTimeInterval();
- QMediaTimeInterval(qint64 start, qint64 end);
-
- qint64 start() const;
- qint64 end() const;
-
- bool contains(qint64 time) const;
-
- bool isNormal() const;
- QMediaTimeInterval normalized() const;
- QMediaTimeInterval translated(qint64 offset) const;
-
-private:
- friend class QMediaTimeRangePrivate;
- friend class QMediaTimeRange;
-
- qint64 s;
- qint64 e;
-};
-
-Q_MULTIMEDIA_EXPORT bool operator==(const QMediaTimeInterval&, const QMediaTimeInterval&);
-Q_MULTIMEDIA_EXPORT bool operator!=(const QMediaTimeInterval&, const QMediaTimeInterval&);
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QMediaTimeRangePrivate, Q_MULTIMEDIA_EXPORT)
class Q_MULTIMEDIA_EXPORT QMediaTimeRange
{
public:
+ struct Interval
+ {
+ constexpr Interval() noexcept = default;
+ explicit constexpr Interval(qint64 start, qint64 end) noexcept
+ : s(start), e(end)
+ {}
+
+ constexpr qint64 start() const noexcept { return s; }
+ constexpr qint64 end() const noexcept { return e; }
+
+ constexpr bool contains(qint64 time) const noexcept
+ {
+ return isNormal() ? (s <= time && time <= e)
+ : (e <= time && time <= s);
+ }
+
+ constexpr bool isNormal() const noexcept { return s <= e; }
+ constexpr Interval normalized() const
+ {
+ return s > e ? Interval(e, s) : *this;
+ }
+ constexpr Interval translated(qint64 offset) const
+ {
+ return Interval(s + offset, e + offset);
+ }
+
+ friend constexpr bool operator==(Interval lhs, Interval rhs) noexcept
+ {
+ return lhs.start() == rhs.start() && lhs.end() == rhs.end();
+ }
+ friend constexpr bool operator!=(Interval lhs, Interval rhs) noexcept
+ {
+ return lhs.start() != rhs.start() || lhs.end() != rhs.end();
+ }
+
+ private:
+ friend class QMediaTimeRangePrivate;
+ qint64 s = 0;
+ qint64 e = 0;
+ };
QMediaTimeRange();
- QMediaTimeRange(qint64 start, qint64 end);
- QMediaTimeRange(const QMediaTimeInterval&);
- QMediaTimeRange(const QMediaTimeRange &range);
+ explicit QMediaTimeRange(qint64 start, qint64 end);
+ QMediaTimeRange(const Interval&);
+ QMediaTimeRange(const QMediaTimeRange &range) noexcept;
~QMediaTimeRange();
- QMediaTimeRange &operator=(const QMediaTimeRange&);
- QMediaTimeRange &operator=(const QMediaTimeInterval&);
+ QMediaTimeRange &operator=(const QMediaTimeRange&) noexcept;
+
+ QMediaTimeRange(QMediaTimeRange &&other) noexcept = default;
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QMediaTimeRange)
+ void swap(QMediaTimeRange &other) noexcept
+ { d.swap(other.d); }
+ void detach();
+
+ QMediaTimeRange &operator=(const Interval&);
qint64 earliestTime() const;
qint64 latestTime() const;
- QList<QMediaTimeInterval> intervals() const;
+ QList<QMediaTimeRange::Interval> intervals() const;
bool isEmpty() const;
bool isContinuous() const;
bool contains(qint64 time) const;
void addInterval(qint64 start, qint64 end);
- void addInterval(const QMediaTimeInterval &interval);
+ void addInterval(const Interval &interval);
void addTimeRange(const QMediaTimeRange&);
void removeInterval(qint64 start, qint64 end);
- void removeInterval(const QMediaTimeInterval &interval);
+ void removeInterval(const Interval &interval);
void removeTimeRange(const QMediaTimeRange&);
QMediaTimeRange& operator+=(const QMediaTimeRange&);
- QMediaTimeRange& operator+=(const QMediaTimeInterval&);
+ QMediaTimeRange& operator+=(const Interval&);
QMediaTimeRange& operator-=(const QMediaTimeRange&);
- QMediaTimeRange& operator-=(const QMediaTimeInterval&);
+ QMediaTimeRange& operator-=(const Interval&);
void clear();
+ friend inline bool operator==(const QMediaTimeRange &lhs, const QMediaTimeRange &rhs)
+ { return lhs.intervals() == rhs.intervals(); }
+ friend inline bool operator!=(const QMediaTimeRange &lhs, const QMediaTimeRange &rhs)
+ { return lhs.intervals() != rhs.intervals(); }
+
private:
- QSharedDataPointer<QMediaTimeRangePrivate> d;
+ QExplicitlySharedDataPointer<QMediaTimeRangePrivate> d;
};
-Q_MULTIMEDIA_EXPORT bool operator==(const QMediaTimeRange&, const QMediaTimeRange&);
-Q_MULTIMEDIA_EXPORT bool operator!=(const QMediaTimeRange&, const QMediaTimeRange&);
-Q_MULTIMEDIA_EXPORT QMediaTimeRange operator+(const QMediaTimeRange&, const QMediaTimeRange&);
-Q_MULTIMEDIA_EXPORT QMediaTimeRange operator-(const QMediaTimeRange&, const QMediaTimeRange&);
-
#ifndef QT_NO_DEBUG_STREAM
+Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QMediaTimeRange::Interval &);
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QMediaTimeRange &);
#endif
+inline QMediaTimeRange operator+(const QMediaTimeRange &r1, const QMediaTimeRange &r2)
+{ return (QMediaTimeRange(r1) += r2); }
+inline QMediaTimeRange operator-(const QMediaTimeRange &r1, const QMediaTimeRange &r2)
+{ return (QMediaTimeRange(r1) -= r2); }
+
+Q_DECLARE_SHARED(QMediaTimeRange)
+
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QMediaTimeRange)
+Q_DECLARE_METATYPE(QMediaTimeRange::Interval)
#endif // QMEDIATIMERANGE_H