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