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
qmetaassociation.cpp
Go to the documentation of this file.
1
// Copyright (C) 2025 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
<
QtCore
/
qmetacontainer
.
h
>
5
#
include
<
QtCore
/
qmetatype
.
h
>
6
7
QT_BEGIN_NAMESPACE
8
9
/*!
10
\class QMetaAssociation
11
\inmodule QtCore
12
\since 6.0
13
\brief The QMetaAssociation class allows type erased access to associative containers.
14
15
\ingroup objectmodel
16
17
\compares equality
18
19
The class provides a number of primitive container operations, using void*
20
as operands. This way, you can manipulate a generic container retrieved from
21
a Variant without knowing its type.
22
23
QMetaAssociation covers both, containers with mapped values such as QMap or
24
QHash, and containers that only hold keys such as QSet.
25
26
The void* arguments to the various methods are typically created by using
27
a \l QVariant of the respective container or value type, and calling
28
its \l QVariant::data() or \l QVariant::constData() methods. However, you
29
can also pass plain pointers to objects of the container or value type.
30
31
Iterator invalidation follows the rules given by the underlying containers
32
and is not expressed in the API. Therefore, for a truly generic container,
33
any iterators should be considered invalid after any write operation.
34
35
\sa QMetaContainer, QMetaSequence, QIterable, QIterator
36
*/
37
38
/*!
39
\fn template<typename C> QMetaAssociation QMetaAssociation::fromContainer()
40
\since 6.0
41
42
Returns the QMetaAssociation corresponding to the type given as template parameter.
43
*/
44
45
/*!
46
Returns the meta type for keys in the container.
47
*/
48
QMetaType
QMetaAssociation::keyMetaType()
const
49
{
50
if
(
auto
iface = d())
51
return
QMetaType(iface->keyMetaType);
52
return
QMetaType();
53
}
54
55
/*!
56
Returns the meta type for mapped values in the container.
57
*/
58
QMetaType QMetaAssociation::mappedMetaType()
const
59
{
60
if
(
auto
iface = d())
61
return
QMetaType(iface->mappedMetaType);
62
return
QMetaType();
63
}
64
65
/*!
66
\fn bool QMetaAssociation::canInsertKey() const
67
68
Returns \c true if keys can be added to the container using \l insertKey(),
69
otherwise returns \c false.
70
71
\sa insertKey()
72
*/
73
74
/*!
75
\fn void QMetaAssociation::insertKey(void *container, const void *key) const
76
77
Inserts the \a key into the \a container if possible. If the container has
78
mapped values a default-create mapped value is associated with the \a key.
79
80
\sa canInsertKey()
81
*/
82
83
/*!
84
\fn bool QMetaAssociation::canRemoveKey() const
85
86
Returns \c true if keys can be removed from the container using
87
\l removeKey(), otherwise returns \c false.
88
89
\sa removeKey()
90
*/
91
92
/*!
93
\fn void QMetaAssociation::removeKey(void *container, const void *key) const
94
95
Removes the \a key and its associated mapped value from the \a container if
96
possible.
97
98
\sa canRemoveKey()
99
*/
100
101
/*!
102
\fn bool QMetaAssociation::canContainsKey() const
103
104
Returns \c true if the container can be queried for keys using
105
\l containsKey(), otherwise returns \c false.
106
*/
107
108
/*!
109
\fn bool QMetaAssociation::containsKey(const void *container, const void *key) const
110
111
Returns \c true if the \a container can be queried for keys and contains the
112
\a key, otherwise returns \c false.
113
114
\sa canContainsKey()
115
*/
116
117
/*!
118
\fn bool QMetaAssociation::canGetMappedAtKey() const
119
120
Returns \c true if the container can be queried for values using
121
\l mappedAtKey(), otherwise returns \c false.
122
*/
123
124
/*!
125
\fn void QMetaAssociation::mappedAtKey(const void *container, const void *key, void *mapped) const
126
127
Retrieves the mapped value associated with the \a key in the \a container
128
and places it in the memory location pointed to by \a mapped, if that is
129
possible.
130
131
\sa canGetMappedAtKey()
132
*/
133
134
/*!
135
\fn bool QMetaAssociation::canSetMappedAtKey() const
136
137
Returns \c true if mapped values can be modified in the container using
138
\l setMappedAtKey(), otherwise returns \c false.
139
140
\sa setMappedAtKey()
141
*/
142
143
/*!
144
\fn void QMetaAssociation::setMappedAtKey(void *container, const void *key, const void *mapped) const
145
146
Overwrites the value associated with the \a key in the \a container using
147
the \a mapped value passed as argument if that is possible.
148
149
\sa canSetMappedAtKey()
150
*/
151
152
/*!
153
\fn bool QMetaAssociation::canGetKeyAtIterator() const
154
155
Returns \c true if a key can be retrieved from a non-const iterator using
156
\l keyAtIterator(), otherwise returns \c false.
157
158
\sa keyAtIterator()
159
*/
160
161
/*!
162
\fn void QMetaAssociation::keyAtIterator(const void *iterator, void *key) const
163
164
Retrieves the key pointed to by the non-const \a iterator and stores it
165
in the memory location pointed to by \a key, if possible.
166
167
\sa canGetKeyAtIterator(), begin(), end(), createIteratorAtKey()
168
*/
169
170
/*!
171
\fn bool QMetaAssociation::canGetKeyAtConstIterator() const
172
173
Returns \c true if a key can be retrieved from a const iterator using
174
\l keyAtConstIterator(), otherwise returns \c false.
175
176
\sa keyAtConstIterator()
177
*/
178
179
/*!
180
\fn void QMetaAssociation::keyAtConstIterator(const void *iterator, void *key) const
181
182
Retrieves the key pointed to by the const \a iterator and stores it
183
in the memory location pointed to by \a key, if possible.
184
185
\sa canGetKeyAtConstIterator(), constBegin(), constEnd(), createConstIteratorAtKey()
186
*/
187
188
/*!
189
\fn bool QMetaAssociation::canGetMappedAtIterator() const
190
191
Returns \c true if a mapped value can be retrieved from a non-const
192
iterator using \l mappedAtIterator(), otherwise returns \c false.
193
194
\sa mappedAtIterator()
195
*/
196
197
/*!
198
\fn void QMetaAssociation::mappedAtIterator(const void *iterator, void *mapped) const
199
200
Retrieves the mapped value pointed to by the non-const \a iterator and
201
stores it in the memory location pointed to by \a mapped, if possible.
202
203
\sa canGetMappedAtIterator(), begin(), end(), createIteratorAtKey()
204
*/
205
206
/*!
207
\fn bool QMetaAssociation::canGetMappedAtConstIterator() const
208
209
Returns \c true if a mapped value can be retrieved from a const iterator
210
using \l mappedAtConstIterator(), otherwise returns \c false.
211
212
\sa mappedAtConstIterator()
213
*/
214
215
/*!
216
\fn void QMetaAssociation::mappedAtConstIterator(const void *iterator, void *mapped) const
217
218
Retrieves the mapped value pointed to by the const \a iterator and
219
stores it in the memory location pointed to by \a mapped, if possible.
220
221
\sa canGetMappedAtConstIterator(), constBegin(), constEnd(), createConstIteratorAtKey()
222
*/
223
224
/*!
225
\fn bool QMetaAssociation::canSetMappedAtIterator() const
226
227
Returns \c true if a mapped value can be set via a non-const iterator using
228
\l setMappedAtIterator(), otherwise returns \c false.
229
230
\sa setMappedAtIterator()
231
*/
232
233
/*!
234
\fn void QMetaAssociation::setMappedAtIterator(const void *iterator, const void *mapped) const
235
236
Writes the \a mapped value to the container location pointed to by the
237
non-const \a iterator, if possible.
238
239
\sa canSetMappedAtIterator(), begin(), end(), createIteratorAtKey()
240
*/
241
242
/*!
243
\fn bool QMetaAssociation::canCreateIteratorAtKey() const
244
245
Returns \c true if an iterator pointing to an entry in the container can be
246
created using \l createIteratorAtKey(), otherwise returns false.
247
248
\sa createIteratorAtKey()
249
*/
250
251
/*!
252
\fn void *QMetaAssociation::createIteratorAtKey(void *container, const void *key) const
253
254
Returns a non-const iterator pointing to the entry of \a key in the
255
\a container, if possible. If the entry doesn't exist, creates a non-const
256
iterator pointing to the end of the \a container. If no non-const iterator
257
can be created, returns \c nullptr.
258
259
The non-const iterator has to be destroyed using destroyIterator().
260
261
\sa canCreateIteratorAtKey(), begin(), end(), destroyIterator()
262
*/
263
264
/*!
265
\fn bool QMetaAssociation::canCreateConstIteratorAtKey() const
266
267
Returns \c true if a const iterator pointing to an entry in the container
268
can be created using \l createConstIteratorAtKey(), otherwise returns false.
269
*/
270
271
/*!
272
\fn void *QMetaAssociation::createConstIteratorAtKey(const void *container, const void *key) const
273
274
Returns a const iterator pointing to the entry of \a key in the
275
\a container, if possible. If the entry doesn't exist, creates a const
276
iterator pointing to the end of the \a container. If no const iterator can
277
be created, returns \c nullptr.
278
279
The const iterator has to be destroyed using destroyConstIterator().
280
281
\sa canCreateConstIteratorAtKey(), constBegin(), constEnd(), destroyConstIterator()
282
*/
283
284
/*!
285
\fn bool QMetaAssociation::operator==(const QMetaAssociation &lhs, const QMetaAssociation &rhs)
286
287
Returns \c true if the QMetaAssociation \a lhs represents the same container type
288
as the QMetaAssociation \a rhs, otherwise returns \c false.
289
*/
290
291
/*!
292
\fn bool QMetaAssociation::operator!=(const QMetaAssociation &lhs, const QMetaAssociation &rhs)
293
294
Returns \c true if the QMetaAssociation \a lhs represents a different container
295
type than the QMetaAssociation \a rhs, otherwise returns \c false.
296
*/
297
298
299
QT_END_NAMESPACE
QMetaType
\inmodule QtCore
Definition
qmetatype.h:339
qtbase
src
corelib
kernel
qmetaassociation.cpp
Generated on
for Qt by
1.14.0