1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QMETAOBJECT_P_H
42#define QMETAOBJECT_P_H
43
44//
45// W A R N I N G
46// -------------
47//
48// This file is not part of the Qt API. It exists for the convenience
49// of moc. This header file may change from version to version without notice,
50// or even be removed.
51//
52// We mean it.
53//
54
55#include <QtCore/qglobal.h>
56#include <QtCore/qobjectdefs.h>
57#ifndef QT_NO_QOBJECT
58#include <private/qobject_p.h> // For QObjectPrivate::Connection
59#endif
60#include <QtCore/qvarlengtharray.h>
61
62QT_BEGIN_NAMESPACE
63// ### TODO Qt6: add a proper namespace with Q_NAMESPACE and use scoped enums
64// A namespace and scoped are needed to avoid enum clashes
65
66enum PropertyFlags {
67 Invalid = 0x00000000,
68 Readable = 0x00000001,
69 Writable = 0x00000002,
70 Resettable = 0x00000004,
71 EnumOrFlag = 0x00000008,
72 StdCppSet = 0x00000100,
73// Override = 0x00000200,
74 Constant = 0x00000400,
75 Final = 0x00000800,
76 Designable = 0x00001000,
77 ResolveDesignable = 0x00002000,
78 Scriptable = 0x00004000,
79 ResolveScriptable = 0x00008000,
80 Stored = 0x00010000,
81 ResolveStored = 0x00020000,
82 Editable = 0x00040000,
83 ResolveEditable = 0x00080000,
84 User = 0x00100000,
85 ResolveUser = 0x00200000,
86 Notify = 0x00400000,
87 Revisioned = 0x00800000
88};
89
90enum MethodFlags {
91 AccessPrivate = 0x00,
92 AccessProtected = 0x01,
93 AccessPublic = 0x02,
94 AccessMask = 0x03, //mask
95
96 MethodMethod = 0x00,
97 MethodSignal = 0x04,
98 MethodSlot = 0x08,
99 MethodConstructor = 0x0c,
100 MethodTypeMask = 0x0c,
101
102 MethodCompatibility = 0x10,
103 MethodCloned = 0x20,
104 MethodScriptable = 0x40,
105 MethodRevisioned = 0x80
106};
107
108enum MetaObjectFlags { // keep it in sync with QMetaObjectBuilder::MetaObjectFlag enum
109 DynamicMetaObject = 0x01,
110 RequiresVariantMetaObject = 0x02,
111 PropertyAccessInStaticMetaCall = 0x04 // since Qt 5.5, property code is in the static metacall
112};
113
114enum MetaDataFlags {
115 IsUnresolvedType = 0x80000000,
116 TypeNameIndexMask = 0x7FFFFFFF,
117 IsUnresolvedSignal = 0x70000000
118};
119
120enum EnumFlags {
121 EnumIsFlag = 0x1,
122 EnumIsScoped = 0x2
123};
124
125extern int qMetaTypeTypeInternal(const char *);
126
127class QArgumentType
128{
129public:
130 QArgumentType(int type)
131 : _type(type)
132 {}
133 QArgumentType(const QByteArray &name)
134 : _type(qMetaTypeTypeInternal(name.constData())), _name(name)
135 {}
136 QArgumentType()
137 : _type(0)
138 {}
139 int type() const
140 { return _type; }
141 QByteArray name() const
142 {
143 if (_type && _name.isEmpty())
144 const_cast<QArgumentType *>(this)->_name = QMetaType::typeName(_type);
145 return _name;
146 }
147 bool operator==(const QArgumentType &other) const
148 {
149 if (_type && other._type)
150 return _type == other._type;
151 else
152 return name() == other.name();
153 }
154 bool operator!=(const QArgumentType &other) const
155 {
156 if (_type && other._type)
157 return _type != other._type;
158 else
159 return name() != other.name();
160 }
161
162private:
163 int _type;
164 QByteArray _name;
165};
166Q_DECLARE_TYPEINFO(QArgumentType, Q_MOVABLE_TYPE);
167
168typedef QVarLengthArray<QArgumentType, 10> QArgumentTypeArray;
169
170class QMetaMethodPrivate;
171class QMutex;
172
173struct QMetaObjectPrivate
174{
175 // revision 7 is Qt 5.0 everything lower is not supported
176 // revision 8 is Qt 5.12: It adds the enum name to QMetaEnum
177 enum { OutputRevision = 8 }; // Used by moc, qmetaobjectbuilder and qdbus
178
179 int revision;
180 int className;
181 int classInfoCount, classInfoData;
182 int methodCount, methodData;
183 int propertyCount, propertyData;
184 int enumeratorCount, enumeratorData;
185 int constructorCount, constructorData;
186 int flags;
187 int signalCount;
188
189 static inline const QMetaObjectPrivate *get(const QMetaObject *metaobject)
190 { return reinterpret_cast<const QMetaObjectPrivate*>(metaobject->d.data); }
191
192 static int originalClone(const QMetaObject *obj, int local_method_index);
193
194 static QByteArray decodeMethodSignature(const char *signature,
195 QArgumentTypeArray &types);
196 static int indexOfSignalRelative(const QMetaObject **baseObject,
197 const QByteArray &name, int argc,
198 const QArgumentType *types);
199 static int indexOfSlotRelative(const QMetaObject **m,
200 const QByteArray &name, int argc,
201 const QArgumentType *types);
202 static int indexOfSignal(const QMetaObject *m, const QByteArray &name,
203 int argc, const QArgumentType *types);
204 static int indexOfSlot(const QMetaObject *m, const QByteArray &name,
205 int argc, const QArgumentType *types);
206 static int indexOfMethod(const QMetaObject *m, const QByteArray &name,
207 int argc, const QArgumentType *types);
208 static int indexOfConstructor(const QMetaObject *m, const QByteArray &name,
209 int argc, const QArgumentType *types);
210 Q_CORE_EXPORT static QMetaMethod signal(const QMetaObject *m, int signal_index);
211 Q_CORE_EXPORT static int signalOffset(const QMetaObject *m);
212 Q_CORE_EXPORT static int absoluteSignalCount(const QMetaObject *m);
213 Q_CORE_EXPORT static int signalIndex(const QMetaMethod &m);
214 static bool checkConnectArgs(int signalArgc, const QArgumentType *signalTypes,
215 int methodArgc, const QArgumentType *methodTypes);
216 static bool checkConnectArgs(const QMetaMethodPrivate *signal,
217 const QMetaMethodPrivate *method);
218
219 static QList<QByteArray> parameterTypeNamesFromSignature(const char *signature);
220
221#ifndef QT_NO_QOBJECT
222 //defined in qobject.cpp
223 enum DisconnectType { DisconnectAll, DisconnectOne };
224 static void memberIndexes(const QObject *obj, const QMetaMethod &member,
225 int *signalIndex, int *methodIndex);
226 static QObjectPrivate::Connection *connect(const QObject *sender, int signal_index,
227 const QMetaObject *smeta,
228 const QObject *receiver, int method_index_relative,
229 const QMetaObject *rmeta = 0,
230 int type = 0, int *types = 0);
231 static bool disconnect(const QObject *sender, int signal_index,
232 const QMetaObject *smeta,
233 const QObject *receiver, int method_index, void **slot,
234 DisconnectType = DisconnectAll);
235 static inline bool disconnectHelper(QObjectPrivate::Connection *c,
236 const QObject *receiver, int method_index, void **slot,
237 QMutex *senderMutex, DisconnectType = DisconnectAll);
238#endif
239};
240
241// For meta-object generators
242
243enum { MetaObjectPrivateFieldCount = sizeof(QMetaObjectPrivate) / sizeof(int) };
244
245#ifndef UTILS_H
246// mirrored in moc's utils.h
247static inline bool is_ident_char(char s)
248{
249 return ((s >= 'a' && s <= 'z')
250 || (s >= 'A' && s <= 'Z')
251 || (s >= '0' && s <= '9')
252 || s == '_'
253 );
254}
255
256static inline bool is_space(char s)
257{
258 return (s == ' ' || s == '\t');
259}
260#endif
261
262/*
263 This function is shared with moc.cpp. The implementation lives in qmetaobject_moc_p.h, which
264 should be included where needed. The declaration here is not used to avoid warnings from
265 the compiler about unused functions.
266
267static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixScope = false, bool adjustConst = true);
268*/
269
270QT_END_NAMESPACE
271
272#endif
273
274