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#include <QtCore/qmutex.h>
58#ifndef QT_NO_QOBJECT
59#include <private/qobject_p.h> // For QObjectPrivate::Connection
60#endif
61#include <QtCore/qvarlengtharray.h>
62
63QT_BEGIN_NAMESPACE
64// ### TODO Qt6: add a proper namespace with Q_NAMESPACE and use scoped enums
65// A namespace and scoped are needed to avoid enum clashes
66
67enum PropertyFlags {
68 Invalid = 0x00000000,
69 Readable = 0x00000001,
70 Writable = 0x00000002,
71 Resettable = 0x00000004,
72 EnumOrFlag = 0x00000008,
73 StdCppSet = 0x00000100,
74// Override = 0x00000200,
75 Constant = 0x00000400,
76 Final = 0x00000800,
77 Designable = 0x00001000,
78 ResolveDesignable = 0x00002000,
79 Scriptable = 0x00004000,
80 ResolveScriptable = 0x00008000,
81 Stored = 0x00010000,
82 ResolveStored = 0x00020000,
83 Editable = 0x00040000,
84 ResolveEditable = 0x00080000,
85 User = 0x00100000,
86 ResolveUser = 0x00200000,
87 Notify = 0x00400000,
88 Revisioned = 0x00800000
89};
90
91enum MethodFlags {
92 AccessPrivate = 0x00,
93 AccessProtected = 0x01,
94 AccessPublic = 0x02,
95 AccessMask = 0x03, //mask
96
97 MethodMethod = 0x00,
98 MethodSignal = 0x04,
99 MethodSlot = 0x08,
100 MethodConstructor = 0x0c,
101 MethodTypeMask = 0x0c,
102
103 MethodCompatibility = 0x10,
104 MethodCloned = 0x20,
105 MethodScriptable = 0x40,
106 MethodRevisioned = 0x80
107};
108
109enum MetaObjectFlags { // keep it in sync with QMetaObjectBuilder::MetaObjectFlag enum
110 DynamicMetaObject = 0x01,
111 RequiresVariantMetaObject = 0x02,
112 PropertyAccessInStaticMetaCall = 0x04 // since Qt 5.5, property code is in the static metacall
113};
114
115enum MetaDataFlags {
116 IsUnresolvedType = 0x80000000,
117 TypeNameIndexMask = 0x7FFFFFFF,
118 IsUnresolvedSignal = 0x70000000
119};
120
121enum EnumFlags {
122 EnumIsFlag = 0x1,
123 EnumIsScoped = 0x2
124};
125
126extern int qMetaTypeTypeInternal(const char *);
127
128class QArgumentType
129{
130public:
131 QArgumentType(int type)
132 : _type(type)
133 {}
134 QArgumentType(const QByteArray &name)
135 : _type(qMetaTypeTypeInternal(name.constData())), _name(name)
136 {}
137 QArgumentType()
138 : _type(0)
139 {}
140 int type() const
141 { return _type; }
142 QByteArray name() const
143 {
144 if (_type && _name.isEmpty())
145 const_cast<QArgumentType *>(this)->_name = QMetaType::typeName(_type);
146 return _name;
147 }
148 bool operator==(const QArgumentType &other) const
149 {
150 if (_type && other._type)
151 return _type == other._type;
152 else
153 return name() == other.name();
154 }
155 bool operator!=(const QArgumentType &other) const
156 {
157 if (_type && other._type)
158 return _type != other._type;
159 else
160 return name() != other.name();
161 }
162
163private:
164 int _type;
165 QByteArray _name;
166};
167Q_DECLARE_TYPEINFO(QArgumentType, Q_MOVABLE_TYPE);
168
169typedef QVarLengthArray<QArgumentType, 10> QArgumentTypeArray;
170
171class QMetaMethodPrivate;
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 QBasicMutex *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