Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qtmochelpers.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2022 Intel Corporation.
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 QTMOCHELPERS_H
0005 #define QTMOCHELPERS_H
0006 
0007 //
0008 //  W A R N I N G
0009 //  -------------
0010 //
0011 // This file is not part of the Qt API. It exists to be used by the code that
0012 // moc generates. This file will not change quickly, but it over the long term,
0013 // it will likely change or even be removed.
0014 //
0015 // We mean it.
0016 //
0017 
0018 #include <QtCore/qglobal.h>
0019 
0020 #include <algorithm> // std::min
0021 #include <limits>
0022 
0023 #if 0
0024 #pragma qt_no_master_include
0025 #endif
0026 
0027 QT_BEGIN_NAMESPACE
0028 namespace QtMocHelpers {
0029 // The maximum Size of a string literal is 2 GB on 32-bit and 4 GB on 64-bit
0030 // (but the compiler is likely to give up before you get anywhere near that much)
0031 static constexpr size_t MaxStringSize =
0032         (std::min)(size_t((std::numeric_limits<uint>::max)()),
0033                    size_t((std::numeric_limits<qsizetype>::max)()));
0034 
0035 template <uint... Nx> constexpr size_t stringDataSizeHelper(std::integer_sequence<uint, Nx...>)
0036 {
0037     // same as:
0038     //   return (0 + ... + Nx);
0039     // but not using the fold expression to avoid exceeding compiler limits
0040     size_t total = 0;
0041     uint sizes[] = { Nx... };
0042     for (uint n : sizes)
0043         total += n;
0044     return total;
0045 }
0046 
0047 template <int Count, size_t StringSize> struct StringData
0048 {
0049     static_assert(StringSize <= MaxStringSize, "Meta Object data is too big");
0050     uint offsetsAndSizes[Count] = {};
0051     char stringdata0[StringSize] = {};
0052     constexpr StringData() = default;
0053 };
0054 
0055 template <uint... Nx> constexpr auto stringData(const char (&...strings)[Nx])
0056 {
0057     constexpr size_t StringSize = stringDataSizeHelper<Nx...>({});
0058     constexpr size_t Count = 2 * sizeof...(Nx);
0059 
0060     StringData<Count, StringSize> result;
0061     const char *inputs[] = { strings... };
0062     uint sizes[] = { Nx... };
0063 
0064     uint offset = 0;
0065     char *output = result.stringdata0;
0066     for (size_t i = 0; i < sizeof...(Nx); ++i) {
0067         // copy the input string, including the terminating null
0068         uint len = sizes[i];
0069         for (uint j = 0; j < len; ++j)
0070             output[offset + j] = inputs[i][j];
0071         result.offsetsAndSizes[2 * i] = offset + sizeof(result.offsetsAndSizes);
0072         result.offsetsAndSizes[2 * i + 1] = len - 1;
0073         offset += len;
0074     }
0075 
0076     return result;
0077 }
0078 
0079 #  define QT_MOC_HAS_STRINGDATA       1
0080 
0081 } // namespace QtMocHelpers
0082 QT_END_NAMESPACE
0083 
0084 QT_USE_NAMESPACE
0085 
0086 #endif // QTMOCHELPERS_H