Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:22

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 
0004 #ifndef QELAPSEDTIMER_H
0005 #define QELAPSEDTIMER_H
0006 
0007 #include <QtCore/qglobal.h>
0008 
0009 #include <chrono>
0010 
0011 QT_BEGIN_NAMESPACE
0012 
0013 class Q_CORE_EXPORT QElapsedTimer
0014 {
0015 public:
0016     enum ClockType {
0017         SystemTime,
0018         MonotonicClock,
0019         TickCounter Q_DECL_ENUMERATOR_DEPRECATED_X(
0020                 "Not supported anymore. Use PerformanceCounter instead."),
0021         MachAbsoluteTime,
0022         PerformanceCounter
0023     };
0024 
0025     // similar to std::chrono::*_clock
0026     using Duration = std::chrono::nanoseconds;
0027     using TimePoint = std::chrono::time_point<std::chrono::steady_clock, Duration>;
0028 
0029     constexpr QElapsedTimer() = default;
0030 
0031     static ClockType clockType() noexcept;
0032     static bool isMonotonic() noexcept;
0033 
0034     void start() noexcept;
0035     qint64 restart() noexcept;
0036     void invalidate() noexcept;
0037     bool isValid() const noexcept;
0038 
0039     Duration durationElapsed() const noexcept;
0040     qint64 nsecsElapsed() const noexcept;
0041     qint64 elapsed() const noexcept;
0042     bool hasExpired(qint64 timeout) const noexcept;
0043 
0044     qint64 msecsSinceReference() const noexcept;
0045     Duration durationTo(const QElapsedTimer &other) const noexcept;
0046     qint64 msecsTo(const QElapsedTimer &other) const noexcept;
0047     qint64 secsTo(const QElapsedTimer &other) const noexcept;
0048 
0049     friend bool operator==(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
0050     { return lhs.t1 == rhs.t1 && lhs.t2 == rhs.t2; }
0051     friend bool operator!=(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
0052     { return !(lhs == rhs); }
0053 
0054     friend bool Q_CORE_EXPORT operator<(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept;
0055 
0056 private:
0057     qint64 t1 = Q_INT64_C(0x8000000000000000);
0058     qint64 t2 = Q_INT64_C(0x8000000000000000);
0059 };
0060 
0061 QT_END_NAMESPACE
0062 
0063 #endif // QELAPSEDTIMER_H