Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qelapsedtimer.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QELAPSEDTIMER_H
0006 #define QELAPSEDTIMER_H
0007 
0008 #include <QtCore/qcompare.h>
0009 #include <QtCore/qglobal.h>
0010 
0011 #include <chrono>
0012 
0013 QT_BEGIN_NAMESPACE
0014 
0015 class Q_CORE_EXPORT QElapsedTimer
0016 {
0017 public:
0018     enum ClockType {
0019         SystemTime,
0020         MonotonicClock,
0021         TickCounter Q_DECL_ENUMERATOR_DEPRECATED_X(
0022                 "Not supported anymore. Use PerformanceCounter instead."),
0023         MachAbsoluteTime,
0024         PerformanceCounter
0025     };
0026 
0027     // similar to std::chrono::*_clock
0028     using Duration = std::chrono::nanoseconds;
0029     using TimePoint = std::chrono::time_point<std::chrono::steady_clock, Duration>;
0030 
0031     constexpr QElapsedTimer() = default;
0032 
0033     static ClockType clockType() noexcept;
0034     static bool isMonotonic() noexcept;
0035 
0036     void start() noexcept;
0037     qint64 restart() noexcept;
0038     void invalidate() noexcept;
0039     bool isValid() const noexcept;
0040 
0041     Duration durationElapsed() const noexcept;
0042     qint64 nsecsElapsed() const noexcept;
0043     qint64 elapsed() const noexcept;
0044     bool hasExpired(qint64 timeout) const noexcept;
0045 
0046     qint64 msecsSinceReference() const noexcept;
0047     Duration durationTo(const QElapsedTimer &other) const noexcept;
0048     qint64 msecsTo(const QElapsedTimer &other) const noexcept;
0049     qint64 secsTo(const QElapsedTimer &other) const noexcept;
0050     friend bool Q_CORE_EXPORT operator<(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept;
0051 
0052 private:
0053     friend bool comparesEqual(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
0054     {
0055         return lhs.t1 == rhs.t1 && lhs.t2 == rhs.t2;
0056     }
0057     Q_DECLARE_EQUALITY_COMPARABLE(QElapsedTimer)
0058 
0059     friend Qt::strong_ordering compareThreeWay(const QElapsedTimer &lhs,
0060                                                const QElapsedTimer &rhs) noexcept
0061     {
0062         return Qt::compareThreeWay(lhs.t1, rhs.t1);
0063     }
0064 
0065 #if defined(__cpp_lib_three_way_comparison)
0066     friend std::strong_ordering
0067     operator<=>(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
0068     {
0069         return compareThreeWay(lhs, rhs);
0070     }
0071 #else
0072     friend bool operator>(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
0073     {
0074         return is_gt(compareThreeWay(lhs, rhs));
0075     }
0076     friend bool operator<=(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
0077     {
0078         return is_lteq(compareThreeWay(lhs, rhs));
0079     }
0080     friend bool operator>=(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
0081     {
0082         return is_gteq(compareThreeWay(lhs, rhs));
0083     }
0084 #endif // defined(__cpp_lib_three_way_comparison)
0085     qint64 t1 = Q_INT64_C(0x8000000000000000);
0086     qint64 t2 = Q_INT64_C(0x8000000000000000);
0087 };
0088 
0089 QT_END_NAMESPACE
0090 
0091 #endif // QELAPSEDTIMER_H