16 #include <QReadWriteLock> 25 CustomTypeInfo() : typeName(), constr(nullptr), destr(nullptr)
36 Q_GLOBAL_STATIC(QVector<CustomTypeInfo>, customTypes)
37 Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
42 const QVector<CustomTypeInfo>*
const ct = customTypes();
43 QReadLocker locker(customTypesLock());
44 return ct && ct->count() > type && !ct->at(type).typeName.isEmpty()
45 ? ct->at(type).typeName.constData()
46 :
static_cast<const char *
>(
nullptr);
55 const QVector<CustomTypeInfo>*
const ct = customTypes();
58 for (
int v = 0; v < ct->count(); ++v)
60 const CustomTypeInfo& customInfo = ct->at(v);
61 if ((length == customInfo.typeName.size())
62 && !std::strcmp(typeName, customInfo.typeName.constData()))
64 if (customInfo.alias >= 0)
65 return customInfo.alias;
73 Constructor constructor)
75 QVector<CustomTypeInfo>* ct = customTypes();
76 if (!ct || !typeName || !destructor || !constructor)
79 QByteArray normalizedTypeName = QMetaObject::normalizedType(typeName);
81 QWriteLocker locker(customTypesLock());
83 normalizedTypeName.size());
87 inf.typeName = normalizedTypeName;
88 inf.constr = constructor;
89 inf.destr = destructor;
100 QVector<CustomTypeInfo>* ct = customTypes();
101 if (!ct || !typeName)
return -1;
103 QByteArray normalizedTypeName = QMetaObject::normalizedType(typeName);
105 QWriteLocker locker(customTypesLock());
107 normalizedTypeName.size());
112 inf.typeName = normalizedTypeName;
114 inf.constr =
nullptr;
122 QVector<CustomTypeInfo> *ct = customTypes();
123 if (!ct || !typeName)
return;
125 QByteArray normalizedTypeName = QMetaObject::normalizedType(typeName);
127 QWriteLocker locker(customTypesLock());
128 for (
int v = 0; v < ct->count(); ++v)
130 if (ct->at(v).typeName == typeName)
132 CustomTypeInfo &inf = (*ct)[v];
133 inf.typeName.clear();
134 inf.constr =
nullptr;
143 QReadLocker locker(customTypesLock());
144 const QVector<CustomTypeInfo>*
const ct = customTypes();
145 return ((type > 0) && (ct && ct->count() > type - 1) &&
146 !ct->at(type - 1).typeName.isEmpty());
151 int length =
static_cast<int>(std::strlen(typeName));
152 if (!length)
return 0;
154 QReadLocker locker(customTypesLock());
158 const QByteArray normalizedTypeName = QMetaObject::normalizedType(typeName);
160 normalizedTypeName.size());
168 const QVector<CustomTypeInfo> *
const ct = customTypes();
170 Constructor constr =
nullptr;
172 QReadLocker locker(customTypesLock());
173 if (!ct || ct->count() <= type - 1)
175 if (ct->at(type - 1).typeName.isEmpty())
177 constr = ct->at(type - 1).constr;
185 const QVector<CustomTypeInfo> *
const ct = customTypes();
186 if (!ct || ct->count() <= type - 1)
return;
188 Destructor destr =
nullptr;
190 QReadLocker locker(customTypesLock());
191 if (ct->at(type - 1).typeName.isEmpty())
193 destr = ct->at(type - 1).destr;
void(* Destructor)(QObject *)
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)()