Revert "Allow moc to handle symbols that have been redefined."
[profile/ivi/qtbase.git] / src / corelib / kernel / qobjectdefs.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QOBJECTDEFS_H
43 #define QOBJECTDEFS_H
44
45 #include <QtCore/qnamespace.h>
46
47 #include <QtCore/qobjectdefs_impl.h>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53
54 class QByteArray;
55 struct QArrayData;
56 typedef QArrayData QByteArrayData;
57
58 class QString;
59
60 #ifndef Q_MOC_OUTPUT_REVISION
61 #define Q_MOC_OUTPUT_REVISION 67
62 #endif
63
64 // The following macros are our "extensions" to C++
65 // They are used, strictly speaking, only by the moc.
66
67 #ifndef Q_MOC_RUN
68 #ifndef QT_NO_META_MACROS
69 # if defined(QT_NO_KEYWORDS)
70 #  define QT_NO_EMIT
71 # else
72 #   ifndef QT_NO_SIGNALS_SLOTS_KEYWORDS
73 #     define slots
74 #     define signals public
75 #   endif
76 # endif
77 # define Q_SLOTS
78 # define Q_SIGNALS public
79 # define Q_PRIVATE_SLOT(d, signature)
80 # define Q_EMIT
81 #ifndef QT_NO_EMIT
82 # define emit
83 #endif
84 #define Q_CLASSINFO(name, value)
85 #define Q_PLUGIN_METADATA(x)
86 #define Q_INTERFACES(x)
87 #define Q_PROPERTY(text)
88 #define Q_PRIVATE_PROPERTY(d, text)
89 #define Q_REVISION(v)
90 #define Q_OVERRIDE(text)
91 #define Q_ENUMS(x)
92 #define Q_FLAGS(x)
93 #define Q_SCRIPTABLE
94 #define Q_INVOKABLE
95 #define Q_SIGNAL
96 #define Q_SLOT
97 #endif // QT_NO_META_MACROS
98
99 #ifndef QT_NO_TRANSLATION
100 // full set of tr functions
101 #  define QT_TR_FUNCTIONS \
102     static inline QString tr(const char *s, const char *c = 0, int n = -1) \
103         { return staticMetaObject.tr(s, c, n); } \
104     QT_DEPRECATED static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) \
105         { return staticMetaObject.tr(s, c, n); }
106 #else
107 // inherit the ones from QObject
108 # define QT_TR_FUNCTIONS
109 #endif
110
111 #if defined(QT_NO_QOBJECT_CHECK)
112 /* qmake ignore Q_OBJECT */
113 #define Q_OBJECT_CHECK
114 #else
115
116 /* This is a compile time check that ensures that any class cast with qobject_cast
117    actually contains a Q_OBJECT macro. Note: qobject_cast will fail if a QObject
118    subclass doesn't contain Q_OBJECT.
119
120    In qt_check_for_QOBJECT_macro, we call a dummy templated function with two
121    parameters, the first being "this" and the other the target of the qobject
122    cast. If the types are not identical, we know that a Q_OBJECT macro is missing.
123
124    If you get a compiler error here, make sure that the class you are casting
125    to contains a Q_OBJECT macro.
126 */
127
128 /* qmake ignore Q_OBJECT */
129 #define Q_OBJECT_CHECK \
130     template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const \
131     { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }
132
133 template <typename T>
134 inline int qYouForgotTheQ_OBJECT_Macro(T, T) { return 0; }
135
136 template <typename T1, typename T2>
137 inline void qYouForgotTheQ_OBJECT_Macro(T1, T2) {}
138 #endif // QT_NO_QOBJECT_CHECK
139
140 #if defined(Q_CC_INTEL)
141 // Cannot redefine the visibility of a method in an exported class
142 # define Q_DECL_HIDDEN_STATIC_METACALL
143 #else
144 # define Q_DECL_HIDDEN_STATIC_METACALL Q_DECL_HIDDEN
145 #endif
146
147 /* qmake ignore Q_OBJECT */
148 #define Q_OBJECT \
149 public: \
150     Q_OBJECT_CHECK \
151     static const QMetaObject staticMetaObject; \
152     virtual const QMetaObject *metaObject() const; \
153     virtual void *qt_metacast(const char *); \
154     QT_TR_FUNCTIONS \
155     virtual int qt_metacall(QMetaObject::Call, int, void **); \
156 private: \
157     Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);
158
159 /* qmake ignore Q_OBJECT */
160 #define Q_OBJECT_FAKE Q_OBJECT
161
162 #ifndef QT_NO_META_MACROS
163 /* qmake ignore Q_GADGET */
164 #define Q_GADGET \
165 public: \
166     static const QMetaObject staticMetaObject; \
167 private:
168 #endif // QT_NO_META_MACROS
169
170 #else // Q_MOC_RUN
171 #define slots slots
172 #define signals signals
173 #define Q_SLOTS Q_SLOTS
174 #define Q_SIGNALS Q_SIGNALS
175 #define Q_CLASSINFO(name, value) Q_CLASSINFO(name, value)
176 #define Q_INTERFACES(x) Q_INTERFACES(x)
177 #define Q_PROPERTY(text) Q_PROPERTY(text)
178 #define Q_PRIVATE_PROPERTY(d, text) Q_PRIVATE_PROPERTY(d, text)
179 #define Q_REVISION(v) Q_REVISION(v)
180 #define Q_OVERRIDE(text) Q_OVERRIDE(text)
181 #define Q_ENUMS(x) Q_ENUMS(x)
182 #define Q_FLAGS(x) Q_FLAGS(x)
183  /* qmake ignore Q_OBJECT */
184 #define Q_OBJECT Q_OBJECT
185  /* qmake ignore Q_OBJECT */
186 #define Q_OBJECT_FAKE Q_OBJECT_FAKE
187  /* qmake ignore Q_GADGET */
188 #define Q_GADGET Q_GADGET
189 #define Q_SCRIPTABLE Q_SCRIPTABLE
190 #define Q_INVOKABLE Q_INVOKABLE
191 #define Q_SIGNAL Q_SIGNAL
192 #define Q_SLOT Q_SLOT
193 #endif //Q_MOC_RUN
194
195 #ifndef QT_NO_META_MACROS
196 // macro for onaming members
197 #ifdef METHOD
198 #undef METHOD
199 #endif
200 #ifdef SLOT
201 #undef SLOT
202 #endif
203 #ifdef SIGNAL
204 #undef SIGNAL
205 #endif
206 #endif // QT_NO_META_MACROS
207
208 Q_CORE_EXPORT const char *qFlagLocation(const char *method);
209
210 #ifndef QT_NO_META_MACROS
211 #define QTOSTRING_HELPER(s) #s
212 #define QTOSTRING(s) QTOSTRING_HELPER(s)
213 #ifndef QT_NO_DEBUG
214 # define QLOCATION "\0" __FILE__ ":" QTOSTRING(__LINE__)
215 # ifndef QT_NO_KEYWORDS
216 #  define METHOD(a)   qFlagLocation("0"#a QLOCATION)
217 # endif
218 # define SLOT(a)     qFlagLocation("1"#a QLOCATION)
219 # define SIGNAL(a)   qFlagLocation("2"#a QLOCATION)
220 #else
221 # ifndef QT_NO_KEYWORDS
222 #  define METHOD(a)   "0"#a
223 # endif
224 # define SLOT(a)     "1"#a
225 # define SIGNAL(a)   "2"#a
226 #endif
227
228 #define QMETHOD_CODE  0                        // member type codes
229 #define QSLOT_CODE    1
230 #define QSIGNAL_CODE  2
231 #endif // QT_NO_META_MACROS
232
233 #define Q_ARG(type, data) QArgument<type >(#type, data)
234 #define Q_RETURN_ARG(type, data) QReturnArgument<type >(#type, data)
235
236 class QObject;
237 class QMetaMethod;
238 class QMetaEnum;
239 class QMetaProperty;
240 class QMetaClassInfo;
241
242
243 class Q_CORE_EXPORT QGenericArgument
244 {
245 public:
246     inline QGenericArgument(const char *aName = 0, const void *aData = 0)
247         : _data(aData), _name(aName) {}
248     inline void *data() const { return const_cast<void *>(_data); }
249     inline const char *name() const { return _name; }
250
251 private:
252     const void *_data;
253     const char *_name;
254 };
255
256 class Q_CORE_EXPORT QGenericReturnArgument: public QGenericArgument
257 {
258 public:
259     inline QGenericReturnArgument(const char *aName = 0, void *aData = 0)
260         : QGenericArgument(aName, aData)
261         {}
262 };
263
264 template <class T>
265 class QArgument: public QGenericArgument
266 {
267 public:
268     inline QArgument(const char *aName, const T &aData)
269         : QGenericArgument(aName, static_cast<const void *>(&aData))
270         {}
271 };
272 template <class T>
273 class QArgument<T &>: public QGenericArgument
274 {
275 public:
276     inline QArgument(const char *aName, T &aData)
277         : QGenericArgument(aName, static_cast<const void *>(&aData))
278         {}
279 };
280
281
282 template <typename T>
283 class QReturnArgument: public QGenericReturnArgument
284 {
285 public:
286     inline QReturnArgument(const char *aName, T &aData)
287         : QGenericReturnArgument(aName, static_cast<void *>(&aData))
288         {}
289 };
290
291 struct Q_CORE_EXPORT QMetaObject
292 {
293     class Connection;
294     const char *className() const;
295     const QMetaObject *superClass() const;
296
297     QObject *cast(QObject *obj) const;
298     const QObject *cast(const QObject *obj) const;
299
300 #ifndef QT_NO_TRANSLATION
301     QString tr(const char *s, const char *c, int n = -1) const;
302 #endif // QT_NO_TRANSLATION
303
304     int methodOffset() const;
305     int enumeratorOffset() const;
306     int propertyOffset() const;
307     int classInfoOffset() const;
308
309     int constructorCount() const;
310     int methodCount() const;
311     int enumeratorCount() const;
312     int propertyCount() const;
313     int classInfoCount() const;
314
315     int indexOfConstructor(const char *constructor) const;
316     int indexOfMethod(const char *method) const;
317     int indexOfSignal(const char *signal) const;
318     int indexOfSlot(const char *slot) const;
319     int indexOfEnumerator(const char *name) const;
320     int indexOfProperty(const char *name) const;
321     int indexOfClassInfo(const char *name) const;
322
323     QMetaMethod constructor(int index) const;
324     QMetaMethod method(int index) const;
325     QMetaEnum enumerator(int index) const;
326     QMetaProperty property(int index) const;
327     QMetaClassInfo classInfo(int index) const;
328     QMetaProperty userProperty() const;
329
330     static bool checkConnectArgs(const char *signal, const char *method);
331     static bool checkConnectArgs(const QMetaMethod &signal,
332                                  const QMetaMethod &method);
333     static QByteArray normalizedSignature(const char *method);
334     static QByteArray normalizedType(const char *type);
335
336     // internal index-based connect
337     static Connection connect(const QObject *sender, int signal_index,
338                         const QObject *receiver, int method_index,
339                         int type = 0, int *types = 0);
340     // internal index-based disconnect
341     static bool disconnect(const QObject *sender, int signal_index,
342                            const QObject *receiver, int method_index);
343     static bool disconnectOne(const QObject *sender, int signal_index,
344                               const QObject *receiver, int method_index);
345     // internal slot-name based connect
346     static void connectSlotsByName(QObject *o);
347
348     // internal index-based signal activation
349     static void activate(QObject *sender, int signal_index, void **argv);
350     static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
351     static void activate(QObject *sender, int signal_offset, int local_signal_index, void **argv);
352
353     static bool invokeMethod(QObject *obj, const char *member,
354                              Qt::ConnectionType,
355                              QGenericReturnArgument ret,
356                              QGenericArgument val0 = QGenericArgument(0),
357                              QGenericArgument val1 = QGenericArgument(),
358                              QGenericArgument val2 = QGenericArgument(),
359                              QGenericArgument val3 = QGenericArgument(),
360                              QGenericArgument val4 = QGenericArgument(),
361                              QGenericArgument val5 = QGenericArgument(),
362                              QGenericArgument val6 = QGenericArgument(),
363                              QGenericArgument val7 = QGenericArgument(),
364                              QGenericArgument val8 = QGenericArgument(),
365                              QGenericArgument val9 = QGenericArgument());
366
367     static inline bool invokeMethod(QObject *obj, const char *member,
368                              QGenericReturnArgument ret,
369                              QGenericArgument val0 = QGenericArgument(0),
370                              QGenericArgument val1 = QGenericArgument(),
371                              QGenericArgument val2 = QGenericArgument(),
372                              QGenericArgument val3 = QGenericArgument(),
373                              QGenericArgument val4 = QGenericArgument(),
374                              QGenericArgument val5 = QGenericArgument(),
375                              QGenericArgument val6 = QGenericArgument(),
376                              QGenericArgument val7 = QGenericArgument(),
377                              QGenericArgument val8 = QGenericArgument(),
378                              QGenericArgument val9 = QGenericArgument())
379     {
380         return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
381                 val4, val5, val6, val7, val8, val9);
382     }
383
384     static inline bool invokeMethod(QObject *obj, const char *member,
385                              Qt::ConnectionType type,
386                              QGenericArgument val0 = QGenericArgument(0),
387                              QGenericArgument val1 = QGenericArgument(),
388                              QGenericArgument val2 = QGenericArgument(),
389                              QGenericArgument val3 = QGenericArgument(),
390                              QGenericArgument val4 = QGenericArgument(),
391                              QGenericArgument val5 = QGenericArgument(),
392                              QGenericArgument val6 = QGenericArgument(),
393                              QGenericArgument val7 = QGenericArgument(),
394                              QGenericArgument val8 = QGenericArgument(),
395                              QGenericArgument val9 = QGenericArgument())
396     {
397         return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
398                                  val3, val4, val5, val6, val7, val8, val9);
399     }
400
401     static inline bool invokeMethod(QObject *obj, const char *member,
402                              QGenericArgument val0 = QGenericArgument(0),
403                              QGenericArgument val1 = QGenericArgument(),
404                              QGenericArgument val2 = QGenericArgument(),
405                              QGenericArgument val3 = QGenericArgument(),
406                              QGenericArgument val4 = QGenericArgument(),
407                              QGenericArgument val5 = QGenericArgument(),
408                              QGenericArgument val6 = QGenericArgument(),
409                              QGenericArgument val7 = QGenericArgument(),
410                              QGenericArgument val8 = QGenericArgument(),
411                              QGenericArgument val9 = QGenericArgument())
412     {
413         return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
414                 val1, val2, val3, val4, val5, val6, val7, val8, val9);
415     }
416
417     QObject *newInstance(QGenericArgument val0 = QGenericArgument(0),
418                          QGenericArgument val1 = QGenericArgument(),
419                          QGenericArgument val2 = QGenericArgument(),
420                          QGenericArgument val3 = QGenericArgument(),
421                          QGenericArgument val4 = QGenericArgument(),
422                          QGenericArgument val5 = QGenericArgument(),
423                          QGenericArgument val6 = QGenericArgument(),
424                          QGenericArgument val7 = QGenericArgument(),
425                          QGenericArgument val8 = QGenericArgument(),
426                          QGenericArgument val9 = QGenericArgument()) const;
427
428     enum Call {
429         InvokeMetaMethod,
430         ReadProperty,
431         WriteProperty,
432         ResetProperty,
433         QueryPropertyDesignable,
434         QueryPropertyScriptable,
435         QueryPropertyStored,
436         QueryPropertyEditable,
437         QueryPropertyUser,
438         CreateInstance,
439         IndexOfMethod
440     };
441
442     int static_metacall(Call, int, void **) const;
443     static int metacall(QObject *, Call, int, void **);
444
445     struct { // private data
446         const QMetaObject *superdata;
447         const QByteArrayData *stringdata;
448         const uint *data;
449         typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
450         StaticMetacallFunction static_metacall;
451         const QMetaObject **relatedMetaObjects;
452         void *extradata; //reserved for future use
453     } d;
454 };
455
456 class Q_CORE_EXPORT QMetaObject::Connection {
457     void *d_ptr; //QObjectPrivate::Connection*
458     explicit Connection(void *data) : d_ptr(data) {  }
459     friend class QObject;
460     friend struct QMetaObject;
461 public:
462     ~Connection();
463     Connection();
464     Connection(const Connection &other);
465     Connection &operator=(const Connection &other);
466 #ifdef Q_QDOC
467     operator bool() const;
468 #else
469     typedef void *Connection::*RestrictedBool;
470     operator RestrictedBool() const { return d_ptr ? &Connection::d_ptr : 0; }
471 #endif
472
473 #ifdef Q_COMPILER_RVALUE_REFS
474     inline Connection(Connection &&o) : d_ptr(o.d_ptr) { o.d_ptr = 0; }
475     inline Connection &operator=(Connection &&other)
476     { qSwap(d_ptr, other.d_ptr); return *this; }
477 #endif
478 };
479
480 inline const QMetaObject *QMetaObject::superClass() const
481 { return d.superdata; }
482
483 QT_END_NAMESPACE
484
485 QT_END_HEADER
486
487 #endif // QOBJECTDEFS_H