20 #include <QReadWriteLock>
29 CustomTypeInfo() : typeName(), constr(nullptr), destr(nullptr)
40 Q_GLOBAL_STATIC(QVector<CustomTypeInfo>, customTypes)
41 Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
46 const QVector<CustomTypeInfo>*
const ct = customTypes();
47 QReadLocker locker(customTypesLock());
48 return ct && ct->count() > type && !ct->at(type).typeName.isEmpty()
49 ? ct->at(type).typeName.constData()
50 :
static_cast<const char *
>(
nullptr);
59 const QVector<CustomTypeInfo>*
const ct = customTypes();
62 for (
int v = 0; v < ct->count(); ++v)
64 const CustomTypeInfo& customInfo = ct->at(v);
65 if ((length == customInfo.typeName.size())
66 && !std::strcmp(typeName, customInfo.typeName.constData()))
68 if (customInfo.alias >= 0)
69 return customInfo.alias;
77 Constructor constructor)
79 QVector<CustomTypeInfo>* ct = customTypes();
80 if (!ct || !typeName || !destructor || !constructor)
83 QByteArray normalizedTypeName = QMetaObject::normalizedType(typeName);
85 QWriteLocker locker(customTypesLock());
87 normalizedTypeName.size());
91 inf.typeName = normalizedTypeName;
92 inf.constr = constructor;
93 inf.destr = destructor;
104 QVector<CustomTypeInfo>* ct = customTypes();
105 if (!ct || !typeName)
return -1;
107 QByteArray normalizedTypeName = QMetaObject::normalizedType(typeName);
109 QWriteLocker locker(customTypesLock());
111 normalizedTypeName.size());
116 inf.typeName = normalizedTypeName;
118 inf.constr =
nullptr;
126 QVector<CustomTypeInfo> *ct = customTypes();
127 if (!ct || !typeName)
return;
129 QByteArray normalizedTypeName = QMetaObject::normalizedType(typeName);
131 QWriteLocker locker(customTypesLock());
132 for (
int v = 0; v < ct->count(); ++v)
136 CustomTypeInfo &inf = (*ct)[v];
137 inf.typeName.clear();
138 inf.constr =
nullptr;
147 QReadLocker locker(customTypesLock());
148 const QVector<CustomTypeInfo>*
const ct = customTypes();
149 return ((type > 0) && (ct && ct->count() > type - 1) &&
150 !ct->at(type - 1).typeName.isEmpty());
155 int length =
static_cast<int>(std::strlen(typeName));
156 if (!length)
return 0;
158 QReadLocker locker(customTypesLock());
162 const QByteArray normalizedTypeName = QMetaObject::normalizedType(typeName);
164 normalizedTypeName.size());
172 const QVector<CustomTypeInfo> *
const ct = customTypes();
176 QReadLocker locker(customTypesLock());
177 if (!ct || ct->count() <= type - 1)
179 if (ct->at(type - 1).typeName.isEmpty())
181 constr = ct->at(type - 1).constr;
189 const QVector<CustomTypeInfo> *
const ct = customTypes();
190 if (!ct || ct->count() <= type - 1)
return;
194 QReadLocker locker(customTypesLock());
195 if (ct->at(type - 1).typeName.isEmpty())
197 destr = ct->at(type - 1).destr;
void(* Destructor)(QObject *)
static const char * typeName(int type)
static int type(const char *typeName)
The ExtensionType class manages named types .
static QObject * construct(int type)
static int registerType(const char *typeName, Destructor destructor, Constructor constructor)
static bool isRegistered(int type)
static void unregisterType(const char *typeName)
static int extensionTypeCustomType_unlocked(const char *typeName, int length)
static int registerTypedef(const char *typeName, int aliasId)
static void destroy(int type, QObject *data)
QObject *(* Constructor)()