Qt 4.8
Classes | Macros | Enumerations | Functions
qmetaobjectbuilder.cpp File Reference
#include "private/qmetaobjectbuilder_p.h"

Go to the source code of this file.

Classes

class  QMetaEnumBuilderPrivate
 
class  QMetaMethodBuilderPrivate
 
class  QMetaObjectBuilderPrivate
 
struct  QMetaObjectPrivate
 
class  QMetaPropertyBuilderPrivate
 

Macros

#define ALIGN(size, type)   (size) = ((size) + sizeof(type) - 1) & ~(sizeof(type) - 1)
 

Enumerations

enum  MethodFlags {
  AccessPrivate = 0x00, AccessProtected = 0x01, AccessPublic = 0x02, AccessMask = 0x03,
  MethodMethod = 0x00, MethodSignal = 0x04, MethodSlot = 0x08, MethodConstructor = 0x0c,
  MethodTypeMask = 0x0c, MethodCompatibility = 0x10, MethodCloned = 0x20, MethodScriptable = 0x40,
  MethodRevisioned = 0x80, AccessPrivate = 0x00, AccessProtected = 0x01, AccessPublic = 0x02,
  AccessMask = 0x03, MethodMethod = 0x00, MethodSignal = 0x04, MethodSlot = 0x08,
  MethodConstructor = 0x0c, MethodTypeMask = 0x0c, MethodCompatibility = 0x10, MethodCloned = 0x20,
  MethodScriptable = 0x40, MethodRevisioned = 0x80
}
 
enum  PropertyFlags {
  Invalid = 0x00000000, Readable = 0x00000001, Writable = 0x00000002, Resettable = 0x00000004,
  EnumOrFlag = 0x00000008, StdCppSet = 0x00000100, Constant = 0x00000400, Final = 0x00000800,
  Designable = 0x00001000, ResolveDesignable = 0x00002000, Scriptable = 0x00004000, ResolveScriptable = 0x00008000,
  Stored = 0x00010000, ResolveStored = 0x00020000, Editable = 0x00040000, ResolveEditable = 0x00080000,
  User = 0x00100000, ResolveUser = 0x00200000, Notify = 0x00400000, Revisioned = 0x00800000,
  Invalid = 0x00000000, Readable = 0x00000001, Writable = 0x00000002, Resettable = 0x00000004,
  EnumOrFlag = 0x00000008, StdCppSet = 0x00000100, Constant = 0x00000400, Final = 0x00000800,
  Designable = 0x00001000, ResolveDesignable = 0x00002000, Scriptable = 0x00004000, ResolveScriptable = 0x00008000,
  Stored = 0x00010000, ResolveStored = 0x00020000, Editable = 0x00040000, ResolveEditable = 0x00080000,
  User = 0x00100000, ResolveUser = 0x00200000, Notify = 0x00400000, Revisioned = 0x00800000
}
 

Functions

static int buildMetaObject (QMetaObjectBuilderPrivate *d, char *buf, bool relocatable)
 
static QByteArray buildParameterNames (const QByteArray &signature, const QList< QByteArray > &parameterNames)
 
static int buildString (char *buf, char *str, int *offset, const QByteArray &value, int empty)
 
bool isVariantType (const char *type)
 
static const QMetaObjectPrivatepriv (const uint *data)
 
uint qvariant_nameToType (const char *name)
 
static const QMetaObjectresolveClassName (const QMap< QByteArray, const QMetaObject *> &references, const QByteArray &name)
 

Macro Definition Documentation

◆ ALIGN

#define ALIGN (   size,
  type 
)    (size) = ((size) + sizeof(type) - 1) & ~(sizeof(type) - 1)

Definition at line 1122 of file qmetaobjectbuilder.cpp.

Referenced by buildMetaObject().

Enumeration Type Documentation

◆ MethodFlags

Enumerator
AccessPrivate 
AccessProtected 
AccessPublic 
AccessMask 
MethodMethod 
MethodSignal 
MethodSlot 
MethodConstructor 
MethodTypeMask 
MethodCompatibility 
MethodCloned 
MethodScriptable 
MethodRevisioned 
AccessPrivate 
AccessProtected 
AccessPublic 
AccessMask 
MethodMethod 
MethodSignal 
MethodSlot 
MethodConstructor 
MethodTypeMask 
MethodCompatibility 
MethodCloned 
MethodScriptable 
MethodRevisioned 

Definition at line 133 of file qmetaobjectbuilder.cpp.

◆ PropertyFlags

Enumerator
Invalid 
Readable 
Writable 
Resettable 
EnumOrFlag 
StdCppSet 
Constant 
Final 
Designable 
ResolveDesignable 
Scriptable 
ResolveScriptable 
Stored 
ResolveStored 
Editable 
ResolveEditable 
User 
ResolveUser 
Notify 
Revisioned 
Invalid 
Readable 
Writable 
Resettable 
EnumOrFlag 
StdCppSet 
Constant 
Final 
Designable 
ResolveDesignable 
Scriptable 
ResolveScriptable 
Stored 
ResolveStored 
Editable 
ResolveEditable 
User 
ResolveUser 
Notify 
Revisioned 

Definition at line 109 of file qmetaobjectbuilder.cpp.

109  {
110  Invalid = 0x00000000,
111  Readable = 0x00000001,
112  Writable = 0x00000002,
113  Resettable = 0x00000004,
114  EnumOrFlag = 0x00000008,
115  StdCppSet = 0x00000100,
116 // Override = 0x00000200,
117  Constant = 0x00000400,
118  Final = 0x00000800,
119  Designable = 0x00001000,
120  ResolveDesignable = 0x00002000,
121  Scriptable = 0x00004000,
122  ResolveScriptable = 0x00008000,
123  Stored = 0x00010000,
124  ResolveStored = 0x00020000,
125  Editable = 0x00040000,
126  ResolveEditable = 0x00080000,
127  User = 0x00100000,
128  ResolveUser = 0x00200000,
129  Notify = 0x00400000,
130  Revisioned = 0x00800000
131 };

Function Documentation

◆ buildMetaObject()

static int buildMetaObject ( QMetaObjectBuilderPrivate d,
char *  buf,
bool  relocatable 
)
static

Definition at line 1186 of file qmetaobjectbuilder.cpp.

Referenced by QMetaObjectBuilder::toMetaObject(), and QMetaObjectBuilder::toRelocatableData().

1188 {
1189  int size = 0;
1190  int dataIndex;
1191  int enumIndex;
1192  int index;
1193  bool hasNotifySignals = false;
1194 
1195  if (relocatable &&
1197  return -1;
1198 
1199  // Create the main QMetaObject structure at the start of the buffer.
1200  QMetaObject *meta = reinterpret_cast<QMetaObject *>(buf);
1201  size += sizeof(QMetaObject);
1202  ALIGN(size, int);
1203  if (buf) {
1204  if (!relocatable) meta->d.superdata = d->superClass;
1205  meta->d.extradata = 0;
1206  }
1207 
1208  // Populate the QMetaObjectPrivate structure.
1209  QMetaObjectPrivate *pmeta
1210  = reinterpret_cast<QMetaObjectPrivate *>(buf + size);
1211  int pmetaSize = size;
1212  dataIndex = 13; // Number of fields in the QMetaObjectPrivate.
1213  for (index = 0; index < d->properties.size(); ++index) {
1214  if (d->properties[index].notifySignal != -1) {
1215  hasNotifySignals = true;
1216  break;
1217  }
1218  }
1219  if (buf) {
1220  pmeta->revision = 3;
1221  pmeta->flags = d->flags;
1222  pmeta->className = 0; // Class name is always the first string.
1223 
1224  pmeta->classInfoCount = d->classInfoNames.size();
1225  pmeta->classInfoData = dataIndex;
1226  dataIndex += 2 * d->classInfoNames.size();
1227 
1228  pmeta->methodCount = d->methods.size();
1229  pmeta->methodData = dataIndex;
1230  dataIndex += 5 * d->methods.size();
1231 
1232  pmeta->propertyCount = d->properties.size();
1233  pmeta->propertyData = dataIndex;
1234  dataIndex += 3 * d->properties.size();
1235  if (hasNotifySignals)
1236  dataIndex += d->properties.size();
1237 
1238  pmeta->enumeratorCount = d->enumerators.size();
1239  pmeta->enumeratorData = dataIndex;
1240  dataIndex += 4 * d->enumerators.size();
1241 
1242  pmeta->constructorCount = d->constructors.size();
1243  pmeta->constructorData = dataIndex;
1244  dataIndex += 5 * d->constructors.size();
1245  } else {
1246  dataIndex += 2 * d->classInfoNames.size();
1247  dataIndex += 5 * d->methods.size();
1248  dataIndex += 3 * d->properties.size();
1249  if (hasNotifySignals)
1250  dataIndex += d->properties.size();
1251  dataIndex += 4 * d->enumerators.size();
1252  dataIndex += 5 * d->constructors.size();
1253  }
1254 
1255  // Allocate space for the enumerator key names and values.
1256  enumIndex = dataIndex;
1257  for (index = 0; index < d->enumerators.size(); ++index) {
1258  QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1259  dataIndex += 2 * enumerator->keys.size();
1260  }
1261 
1262  // Zero terminator at the end of the data offset table.
1263  ++dataIndex;
1264 
1265  // Find the start of the data and string tables.
1266  int *data = reinterpret_cast<int *>(pmeta);
1267  size += dataIndex * sizeof(int);
1268  char *str = reinterpret_cast<char *>(buf + size);
1269  if (buf) {
1270  if (relocatable) {
1271  meta->d.stringdata = reinterpret_cast<const char *>((quintptr)size);
1272  meta->d.data = reinterpret_cast<uint *>((quintptr)pmetaSize);
1273  } else {
1274  meta->d.stringdata = str;
1275  meta->d.data = reinterpret_cast<uint *>(data);
1276  }
1277  }
1278 
1279  // Reset the current data position to just past the QMetaObjectPrivate.
1280  dataIndex = 13;
1281 
1282  // Add the class name to the string table.
1283  int offset = 0;
1284  buildString(buf, str, &offset, d->className, -1);
1285 
1286  // Add a common empty string, which is used to indicate "void"
1287  // method returns, empty tag strings, etc.
1288  int empty = buildString(buf, str, &offset, QByteArray(), -1);
1289 
1290  // Output the class infos,
1291  for (index = 0; index < d->classInfoNames.size(); ++index) {
1292  int name = buildString(buf, str, &offset, d->classInfoNames[index], empty);
1293  int value = buildString(buf, str, &offset, d->classInfoValues[index], empty);
1294  if (buf) {
1295  data[dataIndex] = name;
1296  data[dataIndex + 1] = value;
1297  }
1298  dataIndex += 2;
1299  }
1300 
1301  // Output the methods in the class.
1302  for (index = 0; index < d->methods.size(); ++index) {
1303  QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1304  int sig = buildString(buf, str, &offset, method->signature, empty);
1305  int params;
1307  (method->signature, method->parameterNames);
1308  params = buildString(buf, str, &offset, names, empty);
1309  int ret = buildString(buf, str, &offset, method->returnType, empty);
1310  int tag = buildString(buf, str, &offset, method->tag, empty);
1311  int attrs = method->attributes;
1312  if (buf) {
1313  data[dataIndex] = sig;
1314  data[dataIndex + 1] = params;
1315  data[dataIndex + 2] = ret;
1316  data[dataIndex + 3] = tag;
1317  data[dataIndex + 4] = attrs;
1318  }
1319  dataIndex += 5;
1320  }
1321 
1322  // Output the properties in the class.
1323  for (index = 0; index < d->properties.size(); ++index) {
1325  int name = buildString(buf, str, &offset, prop->name, empty);
1326  int type = buildString(buf, str, &offset, prop->type, empty);
1327  int flags = prop->flags;
1328 
1329  if (!isVariantType(prop->type)) {
1330  flags |= EnumOrFlag;
1331  } else {
1332  flags |= qvariant_nameToType(prop->type) << 24;
1333  }
1334 
1335  if (buf) {
1336  data[dataIndex] = name;
1337  data[dataIndex + 1] = type;
1338  data[dataIndex + 2] = flags;
1339  }
1340  dataIndex += 3;
1341  }
1342  if (hasNotifySignals) {
1343  for (index = 0; index < d->properties.size(); ++index) {
1345  if (buf) {
1346  if (prop->notifySignal != -1)
1347  data[dataIndex] = prop->notifySignal;
1348  else
1349  data[dataIndex] = 0;
1350  }
1351  ++dataIndex;
1352  }
1353  }
1354 
1355  // Output the enumerators in the class.
1356  for (index = 0; index < d->enumerators.size(); ++index) {
1357  QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1358  int name = buildString(buf, str, &offset, enumerator->name, empty);
1359  int isFlag = (int)(enumerator->isFlag);
1360  int count = enumerator->keys.size();
1361  int enumOffset = enumIndex;
1362  if (buf) {
1363  data[dataIndex] = name;
1364  data[dataIndex + 1] = isFlag;
1365  data[dataIndex + 2] = count;
1366  data[dataIndex + 3] = enumOffset;
1367  }
1368  for (int key = 0; key < count; ++key) {
1369  int keyIndex = buildString(buf, str, &offset, enumerator->keys[key], empty);
1370  if (buf) {
1371  data[enumOffset++] = keyIndex;
1372  data[enumOffset++] = enumerator->values[key];
1373  }
1374  }
1375  dataIndex += 4;
1376  enumIndex += 2 * count;
1377  }
1378 
1379  // Output the constructors in the class.
1380  for (index = 0; index < d->constructors.size(); ++index) {
1381  QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1382  int sig = buildString(buf, str, &offset, method->signature, empty);
1383  int params;
1385  (method->signature, method->parameterNames);
1386  params = buildString(buf, str, &offset, names, empty);
1387  int ret = buildString(buf, str, &offset, method->returnType, empty);
1388  int tag = buildString(buf, str, &offset, method->tag, empty);
1389  int attrs = method->attributes;
1390  if (buf) {
1391  data[dataIndex] = sig;
1392  data[dataIndex + 1] = params;
1393  data[dataIndex + 2] = ret;
1394  data[dataIndex + 3] = tag;
1395  data[dataIndex + 4] = attrs;
1396  }
1397  dataIndex += 5;
1398  }
1399 
1400  // One more empty string to act as a terminator.
1401  buildString(buf, str, &offset, QByteArray(), -1);
1402  size += offset;
1403 
1404  // Output the zero terminator in the data array.
1405  if (buf)
1406  data[enumIndex] = 0;
1407 
1408  // Create the extradata block if we need one.
1409  if (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction) {
1410  ALIGN(size, QMetaObject **);
1412  QMetaObjectExtraData *extra =
1413  reinterpret_cast<QMetaObjectExtraData *>(buf + size);
1414  size += sizeof(QMetaObjectExtraData);
1415  ALIGN(size, QMetaObject *);
1416 #ifdef Q_NO_DATA_RELOCATION
1417  QMetaObjectAccessor *objects =
1418  reinterpret_cast<QMetaObjectAccessor *>(buf + size);
1419 #else
1420  const QMetaObject **objects =
1421  reinterpret_cast<const QMetaObject **>(buf + size);
1422 #endif
1423  if (buf) {
1424  if (d->relatedMetaObjects.size() > 0) {
1425  extra->objects = objects;
1426  for (index = 0; index < d->relatedMetaObjects.size(); ++index)
1427  objects[index] = d->relatedMetaObjects[index];
1428  objects[index] = 0;
1429  } else {
1430  extra->objects = 0;
1431  }
1433  meta->d.extradata = reinterpret_cast<void *>(extra);
1434  }
1435  if (d->relatedMetaObjects.size() > 0)
1436  size += sizeof(QMetaObject *) * (d->relatedMetaObjects.size() + 1);
1437  }
1438 
1439  // Align the final size and return it.
1440  ALIGN(size, void *);
1441  return size;
1442 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
int type
Definition: qmetatype.cpp:239
const QMetaObject * superClass
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
const void * extradata
Definition: qobjectdefs.h:472
uint qvariant_nameToType(const char *name)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool isVariantType(const char *type)
QMetaObjectExtraData::StaticMetacallFunction StaticMetacallFunction
Typedef for static metacall functions.
const char * stringdata
Definition: qobjectdefs.h:470
#define ALIGN(size, type)
QList< QMetaEnumBuilderPrivate > enumerators
const QMetaObject &(* QMetaObjectAccessor)()
Definition: qobjectdefs.h:476
QList< QMetaMethodBuilderPrivate > constructors
const char * name
QList< QByteArray > classInfoValues
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
static QByteArray buildParameterNames(const QByteArray &signature, const QList< QByteArray > &parameterNames)
const uint * data
Definition: qobjectdefs.h:471
QList< QByteArray > parameterNames
StaticMetacallFunction static_metacall
Definition: qobjectdefs.h:488
static int buildString(char *buf, char *str, int *offset, const QByteArray &value, int empty)
QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction
QList< QMetaMethodBuilderPrivate > methods
QList< const QMetaObject * > relatedMetaObjects
int key
const QMetaObject * superdata
Definition: qobjectdefs.h:469
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
struct QMetaObject::@38 d
quint16 index
QList< QMetaPropertyBuilderPrivate > properties
const QMetaObject ** objects
Definition: qobjectdefs.h:483
QList< QByteArray > classInfoNames

◆ buildParameterNames()

static QByteArray buildParameterNames ( const QByteArray signature,
const QList< QByteArray > &  parameterNames 
)
static

Definition at line 1143 of file qmetaobjectbuilder.cpp.

Referenced by buildMetaObject(), and buildString().

1144 {
1145  // If the parameter name list is specified, then concatenate them.
1146  if (!parameterNames.isEmpty()) {
1147  QByteArray names;
1148  bool first = true;
1149  foreach (const QByteArray &name, parameterNames) {
1150  if (first)
1151  first = false;
1152  else
1153  names += (char)',';
1154  names += name;
1155  }
1156  return names;
1157  }
1158 
1159  // Count commas in the signature, excluding those inside template arguments.
1160  int index = signature.indexOf('(');
1161  if (index < 0)
1162  return QByteArray();
1163  ++index;
1164  if (index >= signature.size())
1165  return QByteArray();
1166  if (signature[index] == ')')
1167  return QByteArray();
1168  int count = 1;
1169  int brackets = 0;
1170  while (index < signature.size() && signature[index] != ',') {
1171  char ch = signature[index++];
1172  if (ch == '<')
1173  ++brackets;
1174  else if (ch == '>')
1175  --brackets;
1176  else if (ch == ',' && brackets <= 0)
1177  ++count;
1178  }
1179  return QByteArray(count - 1, ',');
1180 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const char * name
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
quint16 index

◆ buildString()

static int buildString ( char *  buf,
char *  str,
int *  offset,
const QByteArray value,
int  empty 
)
static

Definition at line 1128 of file qmetaobjectbuilder.cpp.

Referenced by buildMetaObject().

1129 {
1130  if (value.size() == 0 && empty >= 0)
1131  return empty;
1132  if (buf) {
1133  memcpy(str + *offset, value.constData(), value.size());
1134  str[*offset + value.size()] = '\0';
1135  }
1136  int posn = *offset;
1137  *offset += value.size() + 1;
1138  return posn;
1139 }
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ isVariantType()

bool isVariantType ( const char *  type)

Definition at line 102 of file qmetaobjectbuilder.cpp.

Referenced by buildMetaObject().

103 {
104  return qvariant_nameToType(type) != 0;
105 }
int type
Definition: qmetatype.cpp:239
uint qvariant_nameToType(const char *name)

◆ priv()

static const QMetaObjectPrivate* priv ( const uint data)
inlinestatic

Definition at line 163 of file qmetaobjectbuilder.cpp.

Referenced by QMetaObjectBuilder::addMetaObject().

164 { return reinterpret_cast<const QMetaObjectPrivate*>(data); }
static const char * data(const QByteArray &arr)

◆ qvariant_nameToType()

uint qvariant_nameToType ( const char *  name)

Definition at line 79 of file qmetaobjectbuilder.cpp.

Referenced by buildMetaObject(), and isVariantType().

80 {
81  if (!name)
82  return 0;
83 
84  if (strcmp(name, "QVariant") == 0)
85  return 0xffffffff;
86  if (strcmp(name, "QCString") == 0)
87  return QMetaType::QByteArray;
88  if (strcmp(name, "Q_LLONG") == 0)
89  return QMetaType::LongLong;
90  if (strcmp(name, "Q_ULLONG") == 0)
91  return QMetaType::ULongLong;
92  if (strcmp(name, "QIconSet") == 0)
93  return QMetaType::QIcon;
94 
96  return tp < QMetaType::User ? tp : 0;
97 }
const char * name
unsigned int uint
Definition: qglobal.h:996
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607

◆ resolveClassName()

static const QMetaObject* resolveClassName ( const QMap< QByteArray, const QMetaObject *> &  references,
const QByteArray name 
)
static

Definition at line 1641 of file qmetaobjectbuilder.cpp.

Referenced by QMetaObjectBuilder::deserialize(), and QMetaObjectBuilder::serialize().

1643 {
1644  if (name == QByteArray("QObject"))
1645  return &QObject::staticMetaObject;
1646  else
1647  return references.value(name, 0);
1648 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499