diff options
Diffstat (limited to 'src/corelib/kernel/qmetatype.cpp')
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 45d0b5df6c..754f5a13e4 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -51,6 +51,7 @@ #include "quuid.h" #include "qvariant.h" #include "qdatastream.h" +#include "qregexp.h" #include "qmetatypeswitcher_p.h" #if QT_CONFIG(regularexpression) @@ -516,12 +517,12 @@ static const struct { const char * typeName; int typeNameLength; int type; } typ QT_FOR_EACH_STATIC_TYPE(QT_ADD_STATIC_METATYPE) QT_FOR_EACH_STATIC_ALIAS_TYPE(QT_ADD_STATIC_METATYPE_ALIASES_ITER) QT_FOR_EACH_STATIC_HACKS_TYPE(QT_ADD_STATIC_METATYPE_HACKS_ITER) - {0, 0, QMetaType::UnknownType} + {nullptr, 0, QMetaType::UnknownType} }; -Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper = 0; -Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper = 0; -Q_CORE_EXPORT const QMetaObject *qMetaObjectWidgetsHelper = 0; +Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper = nullptr; +Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper = nullptr; +Q_CORE_EXPORT const QMetaObject *qMetaObjectWidgetsHelper = nullptr; class QCustomTypeInfo : public QMetaTypeInterface { @@ -556,7 +557,7 @@ public: { const QWriteLocker locker(&lock); const T* &fun = map[k]; - if (fun != 0) + if (fun) return false; fun = f; return true; @@ -565,7 +566,7 @@ public: const T *function(Key k) const { const QReadLocker locker(&lock); - return map.value(k, 0); + return map.value(k, nullptr); } void remove(int from, int to) @@ -586,13 +587,7 @@ QMetaTypeComparatorRegistry; typedef QMetaTypeFunctionRegistry<QtPrivate::AbstractDebugStreamFunction,int> QMetaTypeDebugStreamRegistry; -namespace -{ -union CheckThatItIsPod -{ // This should break if QMetaTypeInterface is not a POD type - QMetaTypeInterface iface; -}; -} +Q_STATIC_ASSERT(std::is_pod<QMetaTypeInterface>::value); Q_DECLARE_TYPEINFO(QCustomTypeInfo, Q_MOVABLE_TYPE); Q_GLOBAL_STATIC(QVector<QCustomTypeInfo>, customTypes) @@ -915,7 +910,7 @@ template <int... TypeIds> struct MetaTypeOffsets<QtPrivate::IndexesList<TypeIds. short offsets[sizeof...(TypeIds)]; constexpr MetaTypeOffsets() : offsets{calculateOffsetForTypeId(TypeIds)...} {} - const char *operator[](int typeId) const Q_DECL_NOTHROW + const char *operator[](int typeId) const noexcept { short o = offsets[typeId]; return o < 0 ? nullptr : metaTypeStrings + o; @@ -972,7 +967,7 @@ static inline int qMetaTypeStaticType(const char *typeName, int length) The extra \a firstInvalidIndex parameter is an easy way to avoid iterating over customTypes() a second time in registerNormalizedType(). */ -static int qMetaTypeCustomType_unlocked(const char *typeName, int length, int *firstInvalidIndex = 0) +static int qMetaTypeCustomType_unlocked(const char *typeName, int length, int *firstInvalidIndex = nullptr) { const QVector<QCustomTypeInfo> * const ct = customTypes(); if (!ct) @@ -1005,7 +1000,7 @@ int QMetaType::registerType(const char *typeName, Deleter deleter, { return registerType(typeName, deleter, creator, QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct, - QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct, 0, TypeFlags(), 0); + QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct, 0, TypeFlags(), nullptr); } /*! @@ -1612,7 +1607,7 @@ void *QMetaType::create(int type, const void *copy) QMetaType info(type); if (int size = info.sizeOf()) return info.construct(operator new(size), copy); - return 0; + return nullptr; } /*! @@ -1638,14 +1633,18 @@ class TypeConstructor { static void *Construct(const int type, void *where, const void *copy) { if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) - return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) : 0; + return Q_LIKELY(qMetaTypeGuiHelper) + ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) + : nullptr; if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) - return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].constructor(where, copy) : 0; + return Q_LIKELY(qMetaTypeWidgetsHelper) + ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].constructor(where, copy) + : nullptr; // This point can be reached only for known types that definition is not available, for example // in bootstrap mode. We have no other choice then ignore it. - return 0; + return nullptr; } }; public: @@ -1669,7 +1668,7 @@ private: { QReadLocker locker(customTypesLock()); if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) - return 0; + return nullptr; const auto &typeInfo = ct->at(type - QMetaType::User); ctor = typeInfo.constructor; tctor = typeInfo.typedConstructor; @@ -1714,7 +1713,7 @@ private: void *QMetaType::construct(int type, void *where, const void *copy) { if (!where) - return 0; + return nullptr; TypeConstructor constructor(type, where); return QMetaTypeSwitcher::switcher<void*>(constructor, type, copy); } @@ -1860,7 +1859,7 @@ private: int QMetaType::sizeOf(int type) { SizeOf sizeOf(type); - return QMetaTypeSwitcher::switcher<int>(sizeOf, type, 0); + return QMetaTypeSwitcher::switcher<int>(sizeOf, type); } namespace { @@ -1924,7 +1923,7 @@ private: QMetaType::TypeFlags QMetaType::typeFlags(int type) { Flags flags(type); - return static_cast<QMetaType::TypeFlags>(QMetaTypeSwitcher::switcher<quint32>(flags, type, 0)); + return static_cast<QMetaType::TypeFlags>(QMetaTypeSwitcher::switcher<quint32>(flags, type)); } #ifndef QT_BOOTSTRAPPED @@ -1947,17 +1946,21 @@ public: { static const QMetaObject *MetaObject(int type) { if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) - return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].metaObject : 0; + return Q_LIKELY(qMetaTypeGuiHelper) + ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].metaObject + : nullptr; if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) - return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].metaObject : 0; + return Q_LIKELY(qMetaTypeWidgetsHelper) + ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].metaObject + : nullptr; return 0; } }; template <typename T> const QMetaObject *delegate(const T *) { return MetaObjectImpl<T>::MetaObject(m_type); } - const QMetaObject *delegate(const void*) { return 0; } - const QMetaObject *delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; } + const QMetaObject *delegate(const void*) { return nullptr; } + const QMetaObject *delegate(const QMetaTypeSwitcher::UnknownType*) { return nullptr; } const QMetaObject *delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customMetaObject(m_type); } private: const int m_type; @@ -1965,10 +1968,10 @@ private: { const QVector<QCustomTypeInfo> * const ct = customTypes(); if (Q_UNLIKELY(!ct || type < QMetaType::User)) - return 0; + return nullptr; QReadLocker locker(customTypesLock()); if (Q_UNLIKELY(ct->count() <= type - QMetaType::User)) - return 0; + return nullptr; return ct->at(type - QMetaType::User).metaObject; } }; @@ -1986,10 +1989,10 @@ const QMetaObject *QMetaType::metaObjectForType(int type) { #ifndef QT_BOOTSTRAPPED MetaObject mo(type); - return QMetaTypeSwitcher::switcher<const QMetaObject*>(mo, type, 0); + return QMetaTypeSwitcher::switcher<const QMetaObject*>(mo, type); #else Q_UNUSED(type); - return 0; + return nullptr; #endif } @@ -2186,7 +2189,7 @@ private: QMetaType QMetaType::typeInfo(const int type) { TypeInfo typeInfo(type); - QMetaTypeSwitcher::switcher<void>(typeInfo, type, 0); + QMetaTypeSwitcher::switcher<void>(typeInfo, type); return (typeInfo.info.constructor || typeInfo.info.typedConstructor) ? QMetaType(static_cast<ExtensionFlag>(QMetaType::CreateEx | QMetaType::DestroyEx | (typeInfo.info.typedConstructor ? QMetaType::ConstructEx | QMetaType::DestructEx : 0)) @@ -2306,7 +2309,7 @@ void QMetaType::dtor() void *QMetaType::createExtended(const void *copy) const { if (m_typeId == QMetaType::UnknownType) - return 0; + return nullptr; if (Q_UNLIKELY(m_typedConstructor && !m_constructor)) return m_typedConstructor(m_typeId, operator new(m_size), copy); return m_constructor(operator new(m_size), copy); @@ -2386,7 +2389,7 @@ uint QMetaType::sizeExtended() const */ QMetaType::TypeFlags QMetaType::flagsExtended() const { - return 0; + return { }; } /*! @@ -2399,7 +2402,7 @@ QMetaType::TypeFlags QMetaType::flagsExtended() const */ const QMetaObject *QMetaType::metaObjectExtended() const { - return 0; + return nullptr; } @@ -2408,7 +2411,7 @@ namespace QtPrivate const QMetaObject *metaObjectForQWidget() { if (!qMetaTypeWidgetsHelper) - return 0; + return nullptr; return qMetaObjectWidgetsHelper; } } |