1 | // Copyright (C) 2020 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQMLPROFILEREVENTLOCATION_P_H |
5 | #define QQMLPROFILEREVENTLOCATION_P_H |
6 | |
7 | #include <QtCore/qstring.h> |
8 | #include <QtCore/qhash.h> |
9 | #include <QtCore/qdatastream.h> |
10 | #include <QtCore/private/qglobal_p.h> |
11 | |
12 | // |
13 | // W A R N I N G |
14 | // ------------- |
15 | // |
16 | // This file is not part of the Qt API. It exists purely as an |
17 | // implementation detail. This header file may change from version to |
18 | // version without notice, or even be removed. |
19 | // |
20 | // We mean it. |
21 | // |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class QQmlProfilerEventLocation |
26 | { |
27 | public: |
28 | QQmlProfilerEventLocation() : m_line(-1),m_column(-1) {} |
29 | QQmlProfilerEventLocation(const QString &file, int lineNumber, int columnNumber) : |
30 | m_filename(file), m_line(lineNumber), m_column(columnNumber) |
31 | {} |
32 | |
33 | void clear() |
34 | { |
35 | m_filename.clear(); |
36 | m_line = m_column = -1; |
37 | } |
38 | |
39 | bool isValid() const |
40 | { |
41 | return !m_filename.isEmpty(); |
42 | } |
43 | |
44 | QString filename() const { return m_filename; } |
45 | int line() const { return m_line; } |
46 | int column() const { return m_column; } |
47 | |
48 | private: |
49 | friend QDataStream &operator>>(QDataStream &stream, QQmlProfilerEventLocation &location); |
50 | friend QDataStream &operator<<(QDataStream &stream, const QQmlProfilerEventLocation &location); |
51 | |
52 | QString m_filename; |
53 | int m_line; |
54 | int m_column; |
55 | }; |
56 | |
57 | inline bool operator==(const QQmlProfilerEventLocation &location1, |
58 | const QQmlProfilerEventLocation &location2) |
59 | { |
60 | // compare filename last as it's expensive. |
61 | return location1.line() == location2.line() && location1.column() == location2.column() |
62 | && location1.filename() == location2.filename(); |
63 | } |
64 | |
65 | inline bool operator!=(const QQmlProfilerEventLocation &location1, |
66 | const QQmlProfilerEventLocation &location2) |
67 | { |
68 | return !(location1 == location2); |
69 | } |
70 | |
71 | inline size_t qHash(const QQmlProfilerEventLocation &location) |
72 | { |
73 | return qHash(key: location.filename()) |
74 | ^ ((location.line() & 0xfff) // 12 bits of line number |
75 | | ((location.column() << 16) & 0xff0000)); // 8 bits of column |
76 | |
77 | } |
78 | |
79 | QDataStream &operator>>(QDataStream &stream, QQmlProfilerEventLocation &location); |
80 | QDataStream &operator<<(QDataStream &stream, const QQmlProfilerEventLocation &location); |
81 | |
82 | Q_DECLARE_TYPEINFO(QQmlProfilerEventLocation, Q_RELOCATABLE_TYPE); |
83 | |
84 | QT_END_NAMESPACE |
85 | |
86 | #endif // QQMLPROFILEREVENTLOCATION_P_H |
87 | |