1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtCore module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QMETAOBJECTBUILDER_P_H |
41 | #define QMETAOBJECTBUILDER_P_H |
42 | |
43 | // |
44 | // W A R N I N G |
45 | // ------------- |
46 | // |
47 | // This file is not part of the Qt API. It exists for the convenience |
48 | // of moc. This header file may change from version to version without notice, |
49 | // or even be removed. |
50 | // |
51 | // We mean it. |
52 | // |
53 | |
54 | #include <QtCore/private/qglobal_p.h> |
55 | #include <QtCore/qobject.h> |
56 | #include <QtCore/qmetaobject.h> |
57 | #include <QtCore/qdatastream.h> |
58 | #include <QtCore/qhash.h> |
59 | #include <QtCore/qmap.h> |
60 | |
61 | #include <private/qmetaobject_p.h> |
62 | |
63 | QT_BEGIN_NAMESPACE |
64 | |
65 | class QMetaObjectBuilderPrivate; |
66 | class QMetaMethodBuilder; |
67 | class QMetaMethodBuilderPrivate; |
68 | class QMetaPropertyBuilder; |
69 | class QMetaPropertyBuilderPrivate; |
70 | class QMetaEnumBuilder; |
71 | class QMetaEnumBuilderPrivate; |
72 | |
73 | class Q_CORE_EXPORT QMetaObjectBuilder |
74 | { |
75 | public: |
76 | enum AddMember |
77 | { |
78 | ClassName = 0x00000001, |
79 | SuperClass = 0x00000002, |
80 | Methods = 0x00000004, |
81 | Signals = 0x00000008, |
82 | Slots = 0x00000010, |
83 | Constructors = 0x00000020, |
84 | Properties = 0x00000040, |
85 | Enumerators = 0x00000080, |
86 | ClassInfos = 0x00000100, |
87 | RelatedMetaObjects = 0x00000200, |
88 | StaticMetacall = 0x00000400, |
89 | PublicMethods = 0x00000800, |
90 | ProtectedMethods = 0x00001000, |
91 | PrivateMethods = 0x00002000, |
92 | AllMembers = 0x7FFFFFFF, |
93 | AllPrimaryMembers = 0x7FFFFBFC |
94 | }; |
95 | Q_DECLARE_FLAGS(AddMembers, AddMember) |
96 | |
97 | QMetaObjectBuilder(); |
98 | explicit QMetaObjectBuilder(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers); |
99 | virtual ~QMetaObjectBuilder(); |
100 | |
101 | QByteArray className() const; |
102 | void setClassName(const QByteArray& name); |
103 | |
104 | const QMetaObject *superClass() const; |
105 | void setSuperClass(const QMetaObject *meta); |
106 | |
107 | MetaObjectFlags flags() const; |
108 | void setFlags(MetaObjectFlags); |
109 | |
110 | int methodCount() const; |
111 | int constructorCount() const; |
112 | int propertyCount() const; |
113 | int enumeratorCount() const; |
114 | int classInfoCount() const; |
115 | int relatedMetaObjectCount() const; |
116 | |
117 | QMetaMethodBuilder addMethod(const QByteArray& signature); |
118 | QMetaMethodBuilder addMethod(const QByteArray& signature, const QByteArray& returnType); |
119 | QMetaMethodBuilder addMethod(const QMetaMethod& prototype); |
120 | |
121 | QMetaMethodBuilder addSlot(const QByteArray& signature); |
122 | QMetaMethodBuilder addSignal(const QByteArray& signature); |
123 | |
124 | QMetaMethodBuilder addConstructor(const QByteArray& signature); |
125 | QMetaMethodBuilder addConstructor(const QMetaMethod& prototype); |
126 | |
127 | QMetaPropertyBuilder addProperty(const QByteArray& name, const QByteArray& type, int notifierId=-1); |
128 | QMetaPropertyBuilder addProperty(const QMetaProperty& prototype); |
129 | |
130 | QMetaEnumBuilder addEnumerator(const QByteArray& name); |
131 | QMetaEnumBuilder addEnumerator(const QMetaEnum& prototype); |
132 | |
133 | int addClassInfo(const QByteArray& name, const QByteArray& value); |
134 | |
135 | int addRelatedMetaObject(const QMetaObject *meta); |
136 | |
137 | void addMetaObject(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers); |
138 | |
139 | QMetaMethodBuilder method(int index) const; |
140 | QMetaMethodBuilder constructor(int index) const; |
141 | QMetaPropertyBuilder property(int index) const; |
142 | QMetaEnumBuilder enumerator(int index) const; |
143 | const QMetaObject *relatedMetaObject(int index) const; |
144 | |
145 | QByteArray classInfoName(int index) const; |
146 | QByteArray classInfoValue(int index) const; |
147 | |
148 | void removeMethod(int index); |
149 | void removeConstructor(int index); |
150 | void removeProperty(int index); |
151 | void removeEnumerator(int index); |
152 | void removeClassInfo(int index); |
153 | void removeRelatedMetaObject(int index); |
154 | |
155 | int indexOfMethod(const QByteArray& signature); |
156 | int indexOfSignal(const QByteArray& signature); |
157 | int indexOfSlot(const QByteArray& signature); |
158 | int indexOfConstructor(const QByteArray& signature); |
159 | int indexOfProperty(const QByteArray& name); |
160 | int indexOfEnumerator(const QByteArray& name); |
161 | int indexOfClassInfo(const QByteArray& name); |
162 | |
163 | typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **); |
164 | |
165 | QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction() const; |
166 | void setStaticMetacallFunction(QMetaObjectBuilder::StaticMetacallFunction value); |
167 | |
168 | QMetaObject *toMetaObject() const; |
169 | QByteArray toRelocatableData(bool * = nullptr) const; |
170 | static void fromRelocatableData(QMetaObject *, const QMetaObject *, const QByteArray &); |
171 | |
172 | #ifndef QT_NO_DATASTREAM |
173 | void serialize(QDataStream& stream) const; |
174 | void deserialize |
175 | (QDataStream& stream, |
176 | const QMap<QByteArray, const QMetaObject *>& references); |
177 | #endif |
178 | |
179 | private: |
180 | Q_DISABLE_COPY_MOVE(QMetaObjectBuilder) |
181 | |
182 | QMetaObjectBuilderPrivate *d; |
183 | |
184 | friend class QMetaMethodBuilder; |
185 | friend class QMetaPropertyBuilder; |
186 | friend class QMetaEnumBuilder; |
187 | }; |
188 | |
189 | class Q_CORE_EXPORT QMetaMethodBuilder |
190 | { |
191 | public: |
192 | QMetaMethodBuilder() : _mobj(nullptr), _index(0) {} |
193 | |
194 | int index() const; |
195 | |
196 | QMetaMethod::MethodType methodType() const; |
197 | QByteArray signature() const; |
198 | |
199 | QByteArray returnType() const; |
200 | void setReturnType(const QByteArray& value); |
201 | |
202 | QList<QByteArray> parameterTypes() const; |
203 | QList<QByteArray> parameterNames() const; |
204 | void setParameterNames(const QList<QByteArray>& value); |
205 | |
206 | QByteArray tag() const; |
207 | void setTag(const QByteArray& value); |
208 | |
209 | QMetaMethod::Access access() const; |
210 | void setAccess(QMetaMethod::Access value); |
211 | |
212 | int attributes() const; |
213 | void setAttributes(int value); |
214 | |
215 | int revision() const; |
216 | void setRevision(int revision); |
217 | |
218 | private: |
219 | const QMetaObjectBuilder *_mobj; |
220 | int _index; |
221 | |
222 | friend class QMetaObjectBuilder; |
223 | friend class QMetaPropertyBuilder; |
224 | |
225 | QMetaMethodBuilder(const QMetaObjectBuilder *mobj, int index) |
226 | : _mobj(mobj), _index(index) {} |
227 | |
228 | QMetaMethodBuilderPrivate *d_func() const; |
229 | }; |
230 | |
231 | class Q_CORE_EXPORT QMetaPropertyBuilder |
232 | { |
233 | public: |
234 | QMetaPropertyBuilder() : _mobj(nullptr), _index(0) {} |
235 | |
236 | int index() const { return _index; } |
237 | |
238 | QByteArray name() const; |
239 | QByteArray type() const; |
240 | |
241 | bool hasNotifySignal() const; |
242 | QMetaMethodBuilder notifySignal() const; |
243 | void setNotifySignal(const QMetaMethodBuilder& value); |
244 | void removeNotifySignal(); |
245 | |
246 | bool isReadable() const; |
247 | bool isWritable() const; |
248 | bool isResettable() const; |
249 | bool isDesignable() const; |
250 | bool isScriptable() const; |
251 | bool isStored() const; |
252 | bool isEditable() const; |
253 | bool isUser() const; |
254 | bool hasStdCppSet() const; |
255 | bool isEnumOrFlag() const; |
256 | bool isConstant() const; |
257 | bool isFinal() const; |
258 | bool isAlias() const; |
259 | bool isBindable() const; |
260 | |
261 | void setReadable(bool value); |
262 | void setWritable(bool value); |
263 | void setResettable(bool value); |
264 | void setDesignable(bool value); |
265 | void setScriptable(bool value); |
266 | void setStored(bool value); |
267 | void setUser(bool value); |
268 | void setStdCppSet(bool value); |
269 | void setEnumOrFlag(bool value); |
270 | void setConstant(bool value); |
271 | void setFinal(bool value); |
272 | void setAlias(bool value); |
273 | void setBindable(bool value); |
274 | |
275 | int revision() const; |
276 | void setRevision(int revision); |
277 | |
278 | private: |
279 | const QMetaObjectBuilder *_mobj; |
280 | int _index; |
281 | |
282 | friend class QMetaObjectBuilder; |
283 | |
284 | QMetaPropertyBuilder(const QMetaObjectBuilder *mobj, int index) |
285 | : _mobj(mobj), _index(index) {} |
286 | |
287 | QMetaPropertyBuilderPrivate *d_func() const; |
288 | }; |
289 | |
290 | class Q_CORE_EXPORT QMetaEnumBuilder |
291 | { |
292 | public: |
293 | QMetaEnumBuilder() : _mobj(nullptr), _index(0) {} |
294 | |
295 | int index() const { return _index; } |
296 | |
297 | QByteArray name() const; |
298 | |
299 | QByteArray enumName() const; |
300 | void setEnumName(const QByteArray &alias); |
301 | |
302 | bool isFlag() const; |
303 | void setIsFlag(bool value); |
304 | |
305 | bool isScoped() const; |
306 | void setIsScoped(bool value); |
307 | |
308 | int keyCount() const; |
309 | QByteArray key(int index) const; |
310 | int value(int index) const; |
311 | |
312 | int addKey(const QByteArray& name, int value); |
313 | void removeKey(int index); |
314 | |
315 | private: |
316 | const QMetaObjectBuilder *_mobj; |
317 | int _index; |
318 | |
319 | friend class QMetaObjectBuilder; |
320 | |
321 | QMetaEnumBuilder(const QMetaObjectBuilder *mobj, int index) |
322 | : _mobj(mobj), _index(index) {} |
323 | |
324 | QMetaEnumBuilderPrivate *d_func() const; |
325 | }; |
326 | |
327 | class Q_CORE_EXPORT QMetaStringTable |
328 | { |
329 | public: |
330 | explicit QMetaStringTable(const QByteArray &className); |
331 | |
332 | int enter(const QByteArray &value); |
333 | |
334 | static int preferredAlignment(); |
335 | int blobSize() const; |
336 | void writeBlob(char *out) const; |
337 | |
338 | private: |
339 | typedef QHash<QByteArray, int> Entries; // string --> index mapping |
340 | Entries m_entries; |
341 | int m_index; |
342 | QByteArray m_className; |
343 | }; |
344 | |
345 | Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::AddMembers) |
346 | |
347 | QT_END_NAMESPACE |
348 | |
349 | #endif |
350 | |