1 | // Copyright (C) 2016 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 | #include <QtGui/private/qtguiglobal_p.h> |
5 | #include <QtCore/qpoint.h> |
6 | #include <QtCore/qstring.h> |
7 | #include <QtGui/qpolygon.h> |
8 | #include <QtCore/qstringbuilder.h> |
9 | |
10 | #ifndef QHEXSTRING_P_H |
11 | #define QHEXSTRING_P_H |
12 | |
13 | // |
14 | // W A R N I N G |
15 | // ------------- |
16 | // |
17 | // This file is not part of the Qt API. It exists purely as an |
18 | // implementation detail. This header file may change from version to |
19 | // version without notice, or even be removed. |
20 | // |
21 | // We mean it. |
22 | // |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | // internal helper. Converts an integer value to a unique string token |
27 | template <typename T> |
28 | struct HexString |
29 | { |
30 | inline HexString(const T t) |
31 | : val(t) |
32 | {} |
33 | |
34 | inline void write(QChar *&dest) const |
35 | { |
36 | const char16_t hexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; |
37 | const char *c = reinterpret_cast<const char *>(&val); |
38 | for (uint i = 0; i < sizeof(T); ++i) { |
39 | *dest++ = hexChars[*c & 0xf]; |
40 | *dest++ = hexChars[(*c & 0xf0) >> 4]; |
41 | ++c; |
42 | } |
43 | } |
44 | const T val; |
45 | }; |
46 | |
47 | // specialization to enable fast concatenating of our string tokens to a string |
48 | template <typename T> |
49 | struct QConcatenable<HexString<T> > |
50 | { |
51 | typedef HexString<T> type; |
52 | enum { ExactSize = true }; |
53 | static int size(const HexString<T> &) { return sizeof(T) * 2; } |
54 | static inline void appendTo(const HexString<T> &str, QChar *&out) { str.write(out); } |
55 | typedef QString ConvertTo; |
56 | }; |
57 | |
58 | QT_END_NAMESPACE |
59 | |
60 | #endif // QHEXSTRING_P_H |
61 | |