Qt 4.8
qmetaobject_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QMETAOBJECT_P_H
43 #define QMETAOBJECT_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists for the convenience
50 // of moc. This header file may change from version to version without notice,
51 // or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include <QtCore/qglobal.h>
57 #include <QtCore/qobjectdefs.h>
58 
60 
62  Invalid = 0x00000000,
63  Readable = 0x00000001,
64  Writable = 0x00000002,
65  Resettable = 0x00000004,
66  EnumOrFlag = 0x00000008,
67  StdCppSet = 0x00000100,
68 // Override = 0x00000200,
69  Constant = 0x00000400,
70  Final = 0x00000800,
71  Designable = 0x00001000,
72  ResolveDesignable = 0x00002000,
73  Scriptable = 0x00004000,
74  ResolveScriptable = 0x00008000,
75  Stored = 0x00010000,
76  ResolveStored = 0x00020000,
77  Editable = 0x00040000,
78  ResolveEditable = 0x00080000,
79  User = 0x00100000,
80  ResolveUser = 0x00200000,
81  Notify = 0x00400000,
82  Revisioned = 0x00800000
83 };
84 
86  AccessPrivate = 0x00,
88  AccessPublic = 0x02,
89  AccessMask = 0x03, //mask
90 
91  MethodMethod = 0x00,
92  MethodSignal = 0x04,
93  MethodSlot = 0x08,
96 
98  MethodCloned = 0x20,
101 };
102 
105 };
106 
107 class QMutex;
108 
110 {
111  int revision;
117  int constructorCount, constructorData; //since revision 2
118  int flags; //since revision 3
119  int signalCount; //since revision 4
120  // revision 5 introduces changes in normalized signatures, no new members
121  // revision 6 added qt_static_metacall as a member of each Q_OBJECT and inside QMetaObject itself
122 
123  static inline const QMetaObjectPrivate *get(const QMetaObject *metaobject)
124  { return reinterpret_cast<const QMetaObjectPrivate*>(metaobject->d.data); }
125 
126  static int indexOfSignalRelative(const QMetaObject **baseObject,
127  const char* name,
128  bool normalizeStringData);
129  static int indexOfSlotRelative(const QMetaObject **m,
130  const char *slot,
131  bool normalizeStringData);
132  static int originalClone(const QMetaObject *obj, int local_method_index);
133 
134 #ifndef QT_NO_QOBJECT
135  //defined in qobject.cpp
137  static void memberIndexes(const QObject *obj, const QMetaMethod &member,
138  int *signalIndex, int *methodIndex);
139  static bool connect(const QObject *sender, int signal_index,
140  const QObject *receiver, int method_index_relative,
141  const QMetaObject *rmeta = 0,
142  int type = 0, int *types = 0);
143  static bool disconnect(const QObject *sender, int signal_index,
144  const QObject *receiver, int method_index,
146  static inline bool disconnectHelper(QObjectPrivate::Connection *c,
147  const QObject *receiver, int method_index,
148  QMutex *senderMutex, DisconnectType);
149 #endif
150 };
151 
152 #ifndef UTILS_H
153 // mirrored in moc's utils.h
154 static inline bool is_ident_char(char s)
155 {
156  return ((s >= 'a' && s <= 'z')
157  || (s >= 'A' && s <= 'Z')
158  || (s >= '0' && s <= '9')
159  || s == '_'
160  );
161 }
162 
163 static inline bool is_space(char s)
164 {
165  return (s == ' ' || s == '\t');
166 }
167 #endif
168 
169 // This code is shared with moc.cpp
170 static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixScope = false, bool adjustConst = true)
171 {
172  int len = e - t;
173  /*
174  Convert 'char const *' into 'const char *'. Start at index 1,
175  not 0, because 'const char *' is already OK.
176  */
177  QByteArray constbuf;
178  for (int i = 1; i < len; i++) {
179  if ( t[i] == 'c'
180  && strncmp(t + i + 1, "onst", 4) == 0
181  && (i + 5 >= len || !is_ident_char(t[i + 5]))
182  && !is_ident_char(t[i-1])
183  ) {
184  constbuf = QByteArray(t, len);
185  if (is_space(t[i-1]))
186  constbuf.remove(i-1, 6);
187  else
188  constbuf.remove(i, 5);
189  constbuf.prepend("const ");
190  t = constbuf.data();
191  e = constbuf.data() + constbuf.length();
192  break;
193  }
194  /*
195  We musn't convert 'char * const *' into 'const char **'
196  and we must beware of 'Bar<const Bla>'.
197  */
198  if (t[i] == '&' || t[i] == '*' ||t[i] == '<')
199  break;
200  }
201  if (adjustConst && e > t + 6 && strncmp("const ", t, 6) == 0) {
202  if (*(e-1) == '&') { // treat const reference as value
203  t += 6;
204  --e;
205  } else if (is_ident_char(*(e-1)) || *(e-1) == '>') { // treat const value as value
206  t += 6;
207  }
208  }
209  QByteArray result;
210  result.reserve(len);
211 
212 #if 1
213  // consume initial 'const '
214  if (strncmp("const ", t, 6) == 0) {
215  t+= 6;
216  result += "const ";
217  }
218 #endif
219 
220  // some type substitutions for 'unsigned x'
221  if (strncmp("unsigned", t, 8) == 0) {
222  // make sure "unsigned" is an isolated word before making substitutions
223  if (!t[8] || !is_ident_char(t[8])) {
224  if (strncmp(" int", t+8, 4) == 0) {
225  t += 8+4;
226  result += "uint";
227  } else if (strncmp(" long", t+8, 5) == 0) {
228  if ((strlen(t + 8 + 5) < 4 || strncmp(t + 8 + 5, " int", 4) != 0) // preserve '[unsigned] long int'
229  && (strlen(t + 8 + 5) < 5 || strncmp(t + 8 + 5, " long", 5) != 0) // preserve '[unsigned] long long'
230  ) {
231  t += 8+5;
232  result += "ulong";
233  }
234  } else if (strncmp(" short", t+8, 6) != 0 // preserve unsigned short
235  && strncmp(" char", t+8, 5) != 0) { // preserve unsigned char
236  // treat rest (unsigned) as uint
237  t += 8;
238  result += "uint";
239  }
240  }
241  } else {
242  // discard 'struct', 'class', and 'enum'; they are optional
243  // and we don't want them in the normalized signature
244  struct {
245  const char *keyword;
246  int len;
247  } optional[] = {
248  { "struct ", 7 },
249  { "class ", 6 },
250  { "enum ", 5 },
251  { 0, 0 }
252  };
253  int i = 0;
254  do {
255  if (strncmp(optional[i].keyword, t, optional[i].len) == 0) {
256  t += optional[i].len;
257  break;
258  }
259  } while (optional[++i].keyword != 0);
260  }
261 
262  bool star = false;
263  while (t != e) {
264  char c = *t++;
265  if (fixScope && c == ':' && *t == ':' ) {
266  ++t;
267  c = *t++;
268  int i = result.size() - 1;
269  while (i >= 0 && is_ident_char(result.at(i)))
270  --i;
271  result.resize(i + 1);
272  }
273  star = star || c == '*';
274  result += c;
275  if (c == '<') {
276  //template recursion
277  const char* tt = t;
278  int templdepth = 1;
279  while (t != e) {
280  c = *t++;
281  if (c == '<')
282  ++templdepth;
283  if (c == '>')
284  --templdepth;
285  if (templdepth == 0 || (templdepth == 1 && c == ',')) {
286  result += normalizeTypeInternal(tt, t-1, fixScope, false);
287  result += c;
288  if (templdepth == 0) {
289  if (*t == '>')
290  result += ' '; // avoid >>
291  break;
292  }
293  tt = t;
294  }
295  }
296  }
297 
298  // cv qualifers can appear after the type as well
299  if (!is_ident_char(c) && t != e && (e - t >= 5 && strncmp("const", t, 5) == 0)
300  && (e - t == 5 || !is_ident_char(t[5]))) {
301  t += 5;
302  while (t != e && is_space(*t))
303  ++t;
304  if (adjustConst && t != e && *t == '&') {
305  // treat const ref as value
306  ++t;
307  } else if (adjustConst && !star) {
308  // treat const as value
309  } else if (!star) {
310  // move const to the front (but not if const comes after a *)
311  result.prepend("const ");
312  } else {
313  // keep const after a *
314  result += "const";
315  }
316  }
317  }
318 
319  return result;
320 }
321 
322 
324 
325 #endif
326 
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
int type
Definition: qmetatype.cpp:239
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
static bool is_ident_char(char s)
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index_relative, const QMetaObject *rmeta=0, int type=0, int *types=0)
Definition: qobject.cpp:3209
static void memberIndexes(const QObject *obj, const QMetaMethod &member, int *signalIndex, int *methodIndex)
This helper function calculates signal and method index for the given member in the specified class...
Definition: qobject.cpp:2468
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray & prepend(char c)
Prepends the character ch to this byte array.
static int indexOfSignalRelative(const QMetaObject **baseObject, const char *name, bool normalizeStringData)
Same as QMetaObject::indexOfSignal, but the result is the local offset to the base object...
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static bool disconnectHelper(QObjectPrivate::Connection *c, const QObject *receiver, int method_index, QMutex *senderMutex, DisconnectType)
Definition: qobject.cpp:3302
static bool is_space(char s)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const char * name
static int originalClone(const QMetaObject *obj, int local_method_index)
int length() const
Same as size().
Definition: qbytearray.h:356
MetaObjectFlags
static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixScope=false, bool adjustConst=true)
static const struct @32 types[]
PropertyFlags
Definition: qmetaobject_p.h:61
static int indexOfSlotRelative(const QMetaObject **m, const char *slot, bool normalizeStringData)
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static bool disconnect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, DisconnectType=DisconnectAll)
Definition: qobject.cpp:3342
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
QByteArray & remove(int index, int len)
Removes len bytes from the array, starting at index position pos, and returns a reference to the arra...
MethodFlags
Definition: qmetaobject_p.h:85