Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtmochelpers.h
Go to the documentation of this file.
1// Copyright (C) 2022 Intel Corporation.
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 QTMOCHELPERS_H
5#define QTMOCHELPERS_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists to be used by the code that
12// moc generates. This file will not change quickly, but it over the long term,
13// it will likely change or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qglobal.h>
19
20#include <algorithm> // std::min
21#include <limits>
22
23#if 0
24#pragma qt_no_master_include
25#endif
26
28namespace QtMocHelpers {
29// The maximum Size of a string literal is 2 GB on 32-bit and 4 GB on 64-bit
30// (but the compiler is likely to give up before you get anywhere near that much)
31static constexpr size_t MaxStringSize =
32 (std::min)(size_t((std::numeric_limits<uint>::max)()),
33 size_t((std::numeric_limits<qsizetype>::max)()));
34
35template <uint... Nx> constexpr size_t stringDataSizeHelper(std::integer_sequence<uint, Nx...>)
36{
37 // same as:
38 // return (0 + ... + Nx);
39 // but not using the fold expression to avoid exceeding compiler limits
40 size_t total = 0;
41 uint sizes[] = { Nx... };
42 for (uint n : sizes)
43 total += n;
44 return total;
45}
46
47template <int Count, size_t StringSize> struct StringData
48{
49 static_assert(StringSize <= MaxStringSize, "Meta Object data is too big");
50 uint offsetsAndSizes[Count] = {};
51 char stringdata0[StringSize] = {};
52 constexpr StringData() = default;
53};
54
55template <uint... Nx> constexpr auto stringData(const char (&...strings)[Nx])
56{
57 constexpr size_t StringSize = stringDataSizeHelper<Nx...>({});
58 constexpr size_t Count = 2 * sizeof...(Nx);
59
60 StringData<Count, StringSize> result;
61 const char *inputs[] = { strings... };
62 uint sizes[] = { Nx... };
63
64 uint offset = 0;
65 char *output = result.stringdata0;
66 for (size_t i = 0; i < sizeof...(Nx); ++i) {
67 // copy the input string, including the terminating null
68 uint len = sizes[i];
69 for (uint j = 0; j < len; ++j)
70 output[offset + j] = inputs[i][j];
71 result.offsetsAndSizes[2 * i] = offset + sizeof(result.offsetsAndSizes);
72 result.offsetsAndSizes[2 * i + 1] = len - 1;
73 offset += len;
74 }
75
76 return result;
77}
78
79# define QT_MOC_HAS_STRINGDATA 1
80
81} // namespace QtMocHelpers
83
85
86#endif // QTMOCHELPERS_H
Combined button and popup list for selecting options.
constexpr auto stringData(const char(&...strings)[Nx])
static constexpr size_t MaxStringSize
constexpr size_t stringDataSizeHelper(std::integer_sequence< uint, Nx... >)
GLsizei const GLchar ** strings
[1]
GLenum GLuint GLintptr offset
GLfloat n
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
GLuint64EXT * result
[6]
GLenum GLsizei len
unsigned int uint
Definition qtypes.h:34
QT_BEGIN_NAMESPACE typedef uchar * output
char stringdata0[StringSize]
constexpr StringData()=default