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
64enum PropertyFlags {
65 Invalid = 0x00000000,
66 Readable = 0x00000001,
67 Writable = 0x00000002,
68 Resettable = 0x00000004,
69 EnumOrFlag = 0x00000008,
70 StdCppSet = 0x00000100,
71// Override = 0x00000200,
72 Constant = 0x00000400,
73 Final = 0x00000800,
74 Designable = 0x00001000,
75 ResolveDesignable = 0x00002000,
76 Scriptable = 0x00004000,
77 ResolveScriptable = 0x00008000,
78 Stored = 0x00010000,
79 ResolveStored = 0x00020000,
80 Editable = 0x00040000,
81 ResolveEditable = 0x00080000,
82 User = 0x00100000,
83 ResolveUser = 0x00200000,
84 Notify = 0x00400000,
85 Revisioned = 0x00800000
86};
87
88enum MethodFlags {
89 AccessPrivate = 0x00,
90 AccessProtected = 0x01,
91 AccessPublic = 0x02,
92 AccessMask = 0x03, //mask
93
94 MethodMethod = 0x00,
95 MethodSignal = 0x04,
96 MethodSlot = 0x08,
97 MethodConstructor = 0x0c,
98 MethodTypeMask = 0x0c,
99
100 MethodCompatibility = 0x10,
101 MethodCloned = 0x20,
102 MethodScriptable = 0x40,
103 MethodRevisioned = 0x80
104};
105
106enum MetaObjectFlags {
107 DynamicMetaObject = 0x01,
108 RequiresVariantMetaObject = 0x02,
109 PropertyAccessInStaticMetaCall = 0x04 // since Qt 5.5, property code is in the static metacall
110};
111
112enum MetaDataFlags {
113 IsUnresolvedType = 0x80000000,
114 TypeNameIndexMask = 0x7FFFFFFF,
115 IsUnresolvedSignal = 0x70000000
116};
117
118enum EnumFlags {
119 EnumIsFlag = 0x1,
120 EnumIsScoped = 0x2
121};
122
123extern int qMetaTypeTypeInternal(const char *);
124
125class QArgumentType
126{
127public:
128 QArgumentType(int type)
129 : _type(type)
130 {}
131 QArgumentType(const QByteArray &name)
132 : _type(qMetaTypeTypeInternal(name.constData())), _name(name)
133 {}
134 QArgumentType()
135 : _type(0)
136 {}
137 int type() const
138 { return _type; }
139 QByteArray name() const
140 {
141 if (_type && _name.isEmpty())
142 const_cast<QArgumentType *>(this)->_name = QMetaType::typeName(_type);
143 return _name;
144 }
145 bool operator==(const QArgumentType &other) const
146 {
147 if (_type && other._type)
148 return _type == other._type;
149 else
150 return name() == other.name();
151 }
152 bool operator!=(const QArgumentType &other) const
153 {
154 if (_type && other._type)
155 return _type != other._type;
156 else
157 return name() != other.name();
158 }
159
160private:
161 int _type;
162 QByteArray _name;
163};
164Q_DECLARE_TYPEINFO(QArgumentType, Q_MOVABLE_TYPE);
165
166typedef QVarLengthArray<QArgumentType, 10> QArgumentTypeArray;
167
168class QMetaMethodPrivate;
169class QMutex;
170
171struct QMetaObjectPrivate
172{
173 // revision 7 is Qt 5.0 everything lower is not supported
174 enum { OutputRevision = 7 }; // Used by moc, qmetaobjectbuilder and qdbus
175
176 int revision;
177 int className;
178 int classInfoCount, classInfoData;
179 int methodCount, methodData;
180 int propertyCount, propertyData;
181 int enumeratorCount, enumeratorData;
182 int constructorCount, constructorData;
183 int flags;
184 int signalCount;
185
186 static inline const QMetaObjectPrivate *get(const QMetaObject *metaobject)
187 { return reinterpret_cast<const QMetaObjectPrivate*>(metaobject->d.data); }
188
189 static int originalClone(const QMetaObject *obj, int local_method_index);
190
191 static QByteArray decodeMethodSignature(const char *signature,
192 QArgumentTypeArray &types);
193 static int indexOfSignalRelative(const QMetaObject **baseObject,
194 const QByteArray &name, int argc,
195 const QArgumentType *types);
196 static int indexOfSlotRelative(const QMetaObject **m,
197 const QByteArray &name, int argc,
198 const QArgumentType *types);
199 static int indexOfSignal(const QMetaObject *m, const QByteArray &name,
200 int argc, const QArgumentType *types);
201 static int indexOfSlot(const QMetaObject *m, const QByteArray &name,
202 int argc, const QArgumentType *types);
203 static int indexOfMethod(const QMetaObject *m, const QByteArray &name,
204 int argc, const QArgumentType *types);
205 static int indexOfConstructor(const QMetaObject *m, const QByteArray &name,
206 int argc, const QArgumentType *types);
207 Q_CORE_EXPORT static QMetaMethod signal(const QMetaObject *m, int signal_index);
208 Q_CORE_EXPORT static int signalOffset(const QMetaObject *m);
209 Q_CORE_EXPORT static int absoluteSignalCount(const QMetaObject *m);
210 Q_CORE_EXPORT static int signalIndex(const QMetaMethod &m);
211 static bool checkConnectArgs(int signalArgc, const QArgumentType *signalTypes,
212 int methodArgc, const QArgumentType *methodTypes);
213 static bool checkConnectArgs(const QMetaMethodPrivate *signal,
214 const QMetaMethodPrivate *method);
215
216 static QList<QByteArray> parameterTypeNamesFromSignature(const char *signature);
217
218#ifndef QT_NO_QOBJECT
219 //defined in qobject.cpp
220 enum DisconnectType { DisconnectAll, DisconnectOne };
221 static void memberIndexes(const QObject *obj, const QMetaMethod &member,
222 int *signalIndex, int *methodIndex);
223 static QObjectPrivate::Connection *connect(const QObject *sender, int signal_index,
224 const QMetaObject *smeta,
225 const QObject *receiver, int method_index_relative,
226 const QMetaObject *rmeta = 0,
227 int type = 0, int *types = 0);
228 static bool disconnect(const QObject *sender, int signal_index,
229 const QMetaObject *smeta,
230 const QObject *receiver, int method_index, void **slot,
231 DisconnectType = DisconnectAll);
232 static inline bool disconnectHelper(QObjectPrivate::Connection *c,
233 const QObject *receiver, int method_index, void **slot,
234 QMutex *senderMutex, DisconnectType = DisconnectAll);
235#endif
236};
237
238// For meta-object generators
239
240enum { MetaObjectPrivateFieldCount = sizeof(QMetaObjectPrivate) / sizeof(int) };
241
242#ifndef UTILS_H
243// mirrored in moc's utils.h
244static inline bool is_ident_char(char s)
245{
246 return ((s >= 'a' && s <= 'z')
247 || (s >= 'A' && s <= 'Z')
248 || (s >= '0' && s <= '9')
249 || s == '_'
250 );
251}
252
253static inline bool is_space(char s)
254{
255 return (s == ' ' || s == '\t');
256}
257#endif
258
259/*
260 This function is shared with moc.cpp. The implementation lives in qmetaobject_moc_p.h, which
261 should be included where needed. The declaration here is not used to avoid warnings from
262 the compiler about unused functions.
263
264static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixScope = false, bool adjustConst = true);
265*/
266
267QT_END_NAMESPACE
268
269#endif
270
271