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