Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qtypeinfo.h
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// Copyright (C) 2016 Intel Corporation.
3
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
// Qt-Security score:significant reason:default
5
6
#
ifndef
QTYPEINFO_H
7
#
define
QTYPEINFO_H
8
9
#
include
<
QtCore
/
qcompilerdetection
.
h
>
10
#
include
<
QtCore
/
qcontainerfwd
.
h
>
11
12
#
include
<
type_traits
>
13
14
QT_BEGIN_NAMESPACE
15
16
class
QDebug;
17
18
/*
19
QTypeInfo - type trait functionality
20
*/
21
22
namespace
QtPrivate
{
23
24
// Helper for QTypeInfo<T>::isComplex, which used to be simply
25
// !std::is_trivial_v but P3247 deprecated it for C++26. It used to be defined
26
// (since C++11) by [class]/7 as: "A trivial class is a class that is trivially
27
// copyable and has one or more default constructors, all of which are either
28
// trivial or deleted and at least one of which is not deleted. [ Note: In
29
// particular, a trivially copyable or trivial class does not have virtual
30
// functions or virtual base classes. — end note ]".
31
32
template
<
typename
T
>
33
inline
constexpr
bool
qIsComplex
=
34
!
std
::
is_trivially_default_constructible_v
<
T
> || !
std
::
is_trivially_copyable_v
<
T
>;
35
36
// A trivially copyable class must also have a trivial, non-deleted
37
// destructor [class.prop/1.3], CWG1734. Some implementations don't
38
// check for a trivial destructor, because of backwards compatibility
39
// with C++98's definition of trivial copyability.
40
// Since trivial copiability has implications for the ABI, implementations
41
// can't "just fix" their traits. So, although formally redundant, we
42
// explicitly check for trivial destruction here.
43
template
<
typename
T
>
44
inline
constexpr
bool
qIsRelocatable
=
std
::
is_trivially_copyable_v
<
T
> &&
std
::
is_trivially_destructible_v
<
T
>;
45
46
template
<
typename
T
>
inline
constexpr
bool
qIsQtRelocatableContainer
=
false
;
47
48
// Denotes types that are trivially default constructible, and for which
49
// value-initialization can be achieved by filling their storage with 0 bits.
50
// There is no type trait we can use for this, so we hardcode a list of
51
// possibilities that we know are OK on the architectures that we support.
52
// The most notable exception are pointers to data members, which for instance
53
// on the Itanium ABI are initialized to -1.
54
template
<
typename
T
>
55
inline
constexpr
bool
qIsValueInitializationBitwiseZero
=
56
std
::
is_scalar_v
<
T
> && !
std
::
is_member_object_pointer_v
<
T
>;
57
58
}
59
60
/*
61
The catch-all template.
62
*/
63
64
template
<
typename
T>
65
class
QTypeInfo
66
{
67
public
:
68
enum
{
69
isPointer
[[deprecated(
"Use std::is_pointer instead"
)]] =
std
::is_pointer_v<T>,
70
isIntegral
[[deprecated(
"Use std::is_integral instead"
)]] =
std
::is_integral_v<T>,
71
isComplex
=
QtPrivate
::qIsComplex<T>,
72
isRelocatable
=
QtPrivate
::qIsRelocatable<T>,
73
isValueInitializationBitwiseZero
=
QtPrivate
::qIsValueInitializationBitwiseZero<T>,
74
};
75
};
76
77
template
<>
78
class
QTypeInfo
<
void
>
79
{
80
public
:
81
enum
{
82
isPointer
[[deprecated(
"Use std::is_pointer instead"
)]] =
false
,
83
isIntegral
[[deprecated(
"Use std::is_integral instead"
)]] =
false
,
84
isComplex
=
false
,
85
isRelocatable
=
false
,
86
isValueInitializationBitwiseZero
=
false
,
87
};
88
};
89
90
/*!
91
\class QTypeInfoMerger
92
\inmodule QtCore
93
\internal
94
95
\brief QTypeInfoMerger merges the QTypeInfo flags of T1, T2... and presents them
96
as a QTypeInfo<T> would do.
97
98
Let's assume that we have a simple set of structs:
99
100
\snippet code/src_corelib_global_qglobal.cpp 50
101
102
To create a proper QTypeInfo specialization for A struct, we have to check
103
all sub-components; B, C and D, then take the lowest common denominator and call
104
Q_DECLARE_TYPEINFO with the resulting flags. An easier and less fragile approach is to
105
use QTypeInfoMerger, which does that automatically. So struct A would have
106
the following QTypeInfo definition:
107
108
\snippet code/src_corelib_global_qglobal.cpp 51
109
*/
110
template
<
class
T,
class
...Ts>
111
class
QTypeInfoMerger
112
{
113
static_assert
(
sizeof
...(Ts) > 0);
114
public
:
115
static
constexpr
bool
isComplex
= ((
QTypeInfo
<Ts>::isComplex) || ...);
116
static
constexpr
bool
isRelocatable
= ((
QTypeInfo
<Ts>::isRelocatable) && ...);
117
[[deprecated(
"Use std::is_pointer instead"
)]]
static
constexpr
bool
isPointer
=
false
;
118
[[deprecated(
"Use std::is_integral instead"
)]]
static
constexpr
bool
isIntegral
=
false
;
119
static
constexpr
bool
isValueInitializationBitwiseZero
=
false
;
120
static_assert
(!
isRelocatable
||
121
std
::is_copy_constructible_v<T> ||
122
std
::is_move_constructible_v<T>,
123
"All Ts... are Q_RELOCATABLE_TYPE, but T is neither copy- nor move-constructible, "
124
"so cannot be Q_RELOCATABLE_TYPE. Please mark T as Q_COMPLEX_TYPE manually."
);
125
};
126
127
// QTypeInfo for std::pair:
128
// std::pair is spec'ed to be struct { T1 first; T2 second; }, so, unlike tuple<>,
129
// we _can_ specialize QTypeInfo for pair<>:
130
template
<
class
T1,
class
T2>
131
class
QTypeInfo
<
std
::pair<T1, T2>> :
public
QTypeInfoMerger
<
std
::pair<T1, T2>, T1, T2> {};
132
133
#
define
Q_DECLARE_MOVABLE_CONTAINER
(
CONTAINER
)
namespace
134
QtPrivate
{
template
135
<
typename
...
T
>
constexpr
bool
qIsQtRelocatableContainer
<
CONTAINER
<
T
...
>>
=
true
;
\
136
}
template
137
<
typename
...
T
>
class
138
QTypeInfo
<
CONTAINER
<
T
...
>>
\
139
{
public
140
:
141
enum
{
142
isPointer
[
[
deprecated
(
"Use std::is_pointer instead"
)
]
]
=
false
,
143
isIntegral
[
[
deprecated
(
"Use std::is_integral instead"
)
]
]
=
false
,
144
isComplex
=
true
,
145
isRelocatable
=
true
,
146
isValueInitializationBitwiseZero
=
false
,
147
}
;
\
148
}
149
150
Q_DECLARE_MOVABLE_CONTAINER
(
QList
);
151
Q_DECLARE_MOVABLE_CONTAINER
(QQueue);
152
Q_DECLARE_MOVABLE_CONTAINER
(QStack);
153
Q_DECLARE_MOVABLE_CONTAINER
(QSet);
154
Q_DECLARE_MOVABLE_CONTAINER
(QMap);
155
Q_DECLARE_MOVABLE_CONTAINER
(QMultiMap);
156
Q_DECLARE_MOVABLE_CONTAINER
(QHash);
157
Q_DECLARE_MOVABLE_CONTAINER
(QMultiHash);
158
Q_DECLARE_MOVABLE_CONTAINER
(QCache);
159
// if you add a new container here after a .0 release, see qvariant.h for
160
// QVariant::Private::hasAlwaysBeenAbleToUseInternalSpace()
161
162
#
undef
Q_DECLARE_MOVABLE_CONTAINER
163
164
/*
165
Specialize a specific type with:
166
167
Q_DECLARE_TYPEINFO(type, flags);
168
169
where 'type' is the name of the type to specialize and 'flags' is
170
logically-OR'ed combination of the flags below.
171
*/
172
enum
{
/* TYPEINFO flags */
173
Q_COMPLEX_TYPE
= 0,
174
Q_PRIMITIVE_TYPE
= 0x1,
175
Q_RELOCATABLE_TYPE
= 0x2,
176
Q_MOVABLE_TYPE
= 0x2,
177
Q_DUMMY_TYPE
= 0x4,
178
};
179
180
#
define
Q_DECLARE_TYPEINFO_BODY
(
TYPE
,
FLAGS
)
class
181
QTypeInfo
<
TYPE
>
\
182
{
public
183
:
184
enum
{
185
isComplex
=
(
(
(
FLAGS
)
&
Q_PRIMITIVE_TYPE
)
==
0
)
&&
QtPrivate
::
qIsComplex
<
TYPE
>
,
186
isRelocatable
=
!
isComplex
||
(
(
FLAGS
)
&
Q_RELOCATABLE_TYPE
)
||
QtPrivate
::
qIsRelocatable
<
TYPE
>
,
187
isPointer
[
[
deprecated
(
"Use std::is_pointer instead"
)
]
]
=
std
::
is_pointer_v
<
TYPE
>
,
188
isIntegral
[
[
deprecated
(
"Use std::is_integral instead"
)
]
]
=
std
::
is_integral
<
TYPE
>
::
value
,
189
isValueInitializationBitwiseZero
=
QtPrivate
::
qIsValueInitializationBitwiseZero
<
TYPE
>
,
190
}
;
191
static_assert
(
!
QTypeInfo
<
TYPE
>
::
isRelocatable
||
192
std
::
is_copy_constructible_v
<
TYPE
>
||
193
std
::
is_move_constructible_v
<
TYPE
>
,
194
#
TYPE
" is neither copy- nor move-constructible, so cannot be Q_RELOCATABLE_TYPE"
)
;
\
195
}
196
197
#
define
Q_DECLARE_TYPEINFO
(
TYPE
,
FLAGS
)
template
198
<
>
Q_DECLARE_TYPEINFO_BODY
199
(
TYPE
,
FLAGS
)
200
201
/* Specialize QTypeInfo for QFlags<T> */
202
template
<
typename
T>
class
QFlags
;
203
template
<
typename
T>
204
Q_DECLARE_TYPEINFO_BODY
(
QFlags
<T>,
Q_PRIMITIVE_TYPE
);
205
206
QT_END_NAMESPACE
207
#
endif
// QTYPEINFO_H
writeEpilogue
static void writeEpilogue(QTextStream &stream, const QString &fileName)
Definition
callback.cpp:44
writeCallback
void writeCallback(QFile &file, const Provider &provider)
Definition
callback.cpp:96
writeWrapper
static void writeWrapper(QTextStream &stream, const Tracepoint &tracepoint, const Provider &provider)
Definition
callback.cpp:51
writePrologue
static void writePrologue(QTextStream &stream, const QString &fileName, const Provider &provider)
Definition
callback.cpp:20
QFlags
Definition
qflags.h:108
QList
Definition
qlist.h:82
QTypeInfoMerger
\inmodule QtCore
Definition
qtypeinfo.h:112
QTypeInfoMerger::isValueInitializationBitwiseZero
static constexpr bool isValueInitializationBitwiseZero
Definition
qtypeinfo.h:119
QTypeInfoMerger::isIntegral
static constexpr bool isIntegral
Definition
qtypeinfo.h:118
QTypeInfoMerger::isPointer
static constexpr bool isPointer
Definition
qtypeinfo.h:117
QTypeInfoMerger::isComplex
static constexpr bool isComplex
Definition
qtypeinfo.h:115
QTypeInfoMerger::isRelocatable
static constexpr bool isRelocatable
Definition
qtypeinfo.h:116
QTypeInfo< QLEInteger< T > >
Definition
qendian.h:387
QTypeInfo< std::pair< T1, T2 > >
Definition
qtypeinfo.h:131
QTypeInfo< void >
Definition
qtypeinfo.h:79
QTypeInfo< void >::isPointer
@ isPointer
Definition
qtypeinfo.h:82
QTypeInfo< void >::isIntegral
@ isIntegral
Definition
qtypeinfo.h:83
QTypeInfo< void >::isRelocatable
@ isRelocatable
Definition
qtypeinfo.h:85
QTypeInfo< void >::isValueInitializationBitwiseZero
@ isValueInitializationBitwiseZero
Definition
qtypeinfo.h:86
QTypeInfo< void >::isComplex
@ isComplex
Definition
qtypeinfo.h:84
QTypeInfo::isPointer
@ isPointer
Definition
qtypeinfo.h:69
QTypeInfo::isComplex
@ isComplex
Definition
qtypeinfo.h:71
QTypeInfo::isValueInitializationBitwiseZero
@ isValueInitializationBitwiseZero
Definition
qtypeinfo.h:73
QTypeInfo::isRelocatable
@ isRelocatable
Definition
qtypeinfo.h:72
QTypeInfo::isIntegral
@ isIntegral
Definition
qtypeinfo.h:70
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtPrivate
Definition
qalloc.h:29
QtPrivate::qIsRelocatable
constexpr bool qIsRelocatable
Definition
qtypeinfo.h:44
QtPrivate::qIsQtRelocatableContainer
constexpr bool qIsQtRelocatableContainer
Definition
qtypeinfo.h:46
QtPrivate::qIsValueInitializationBitwiseZero
constexpr bool qIsValueInitializationBitwiseZero
Definition
qtypeinfo.h:55
QtPrivate::qIsComplex
constexpr bool qIsComplex
Definition
qtypeinfo.h:33
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
parseProvider
Provider parseProvider(const QString &filename)
Definition
provider.cpp:292
QStringLiteral
#define QStringLiteral(str)
Definition
qstring.h:1865
Q_DECLARE_MOVABLE_CONTAINER
#define Q_DECLARE_MOVABLE_CONTAINER(CONTAINER)
Definition
qtypeinfo.h:133
Q_DECLARE_TYPEINFO
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition
qtypeinfo.h:197
Q_DECLARE_TYPEINFO_BODY
#define Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS)
Definition
qtypeinfo.h:180
Q_PRIMITIVE_TYPE
@ Q_PRIMITIVE_TYPE
Definition
qtypeinfo.h:174
Q_DUMMY_TYPE
@ Q_DUMMY_TYPE
Definition
qtypeinfo.h:177
Q_RELOCATABLE_TYPE
@ Q_RELOCATABLE_TYPE
Definition
qtypeinfo.h:175
Q_COMPLEX_TYPE
@ Q_COMPLEX_TYPE
Definition
qtypeinfo.h:173
Q_MOVABLE_TYPE
@ Q_MOVABLE_TYPE
Definition
qtypeinfo.h:176
Provider
Definition
provider.h:82
Provider::prefixText
QStringList prefixText
Definition
provider.h:85
Provider::enumerations
QList< TraceEnum > enumerations
Definition
provider.h:86
Provider::flags
QList< TraceFlags > flags
Definition
provider.h:87
Provider::name
QString name
Definition
provider.h:83
Provider::tracepoints
QList< Tracepoint > tracepoints
Definition
provider.h:84
TraceEnum::EnumValue
Definition
provider.h:57
TraceEnum::EnumValue::name
QString name
Definition
provider.h:58
TraceEnum::EnumValue::value
int value
Definition
provider.h:59
TraceEnum::EnumValue::range
int range
Definition
provider.h:60
TraceEnum
Definition
provider.h:55
TraceEnum::valueSize
int valueSize
Definition
provider.h:63
TraceEnum::name
QString name
Definition
provider.h:56
TraceEnum::values
QList< EnumValue > values
Definition
provider.h:62
TraceFlags::FlagValue
Definition
provider.h:68
TraceFlags::FlagValue::value
int value
Definition
provider.h:70
TraceFlags::FlagValue::name
QString name
Definition
provider.h:69
TraceFlags
Definition
provider.h:66
TraceFlags::name
QString name
Definition
provider.h:67
TraceFlags::values
QList< FlagValue > values
Definition
provider.h:72
qtbase
src
corelib
global
qtypeinfo.h
Generated on
for Qt by
1.18.0