summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetatype.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-07-10 16:59:12 +0200
committerLars Knoll <lars.knoll@qt.io>2020-08-24 00:17:05 +0200
commit0e4ae4fbf8e320d18c29a55b5db2bba25b3d9d50 (patch)
treeb85e0d3122cac696bfddc0b81adaf401c3412fb6 /src/corelib/kernel/qmetatype.cpp
parent7f009b648f11c6f8fc032e335983ab0746198383 (diff)
Clean up the converter function handling
Use std::function to register the converter functions instead of our own handrolled interface. Change-Id: Ifc1d1d383d21ee8d4239dbc3970c1f31bf0f4037 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qmetatype.cpp')
-rw-r--r--src/corelib/kernel/qmetatype.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 24f095a66d..c410c510e6 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -880,20 +880,20 @@ public:
return map.contains(k);
}
- bool insertIfNotContains(Key k, const T *f)
+ bool insertIfNotContains(Key k, const T &f)
{
const QWriteLocker locker(&lock);
- const T* &fun = map[k];
- if (fun)
+ if (map.contains(k))
return false;
- fun = f;
+ map.insert(k, f);
return true;
}
const T *function(Key k) const
{
const QReadLocker locker(&lock);
- return map.value(k, nullptr);
+ auto it = map.find(k);
+ return it == map.end() ? nullptr : std::addressof(*it);
}
void remove(int from, int to)
@@ -904,10 +904,10 @@ public:
}
private:
mutable QReadWriteLock lock;
- QHash<Key, const T *> map;
+ QHash<Key, T> map;
};
-typedef QMetaTypeFunctionRegistry<QtPrivate::AbstractConverterFunction,QPair<int,int> >
+typedef QMetaTypeFunctionRegistry<QMetaType::ConverterFunction,QPair<int,int> >
QMetaTypeConverterRegistry;
Q_GLOBAL_STATIC(QMetaTypeConverterRegistry, customTypesConversionRegistry)
@@ -950,7 +950,7 @@ Q_GLOBAL_STATIC(QMetaTypeConverterRegistry, customTypesConversionRegistry)
\since 5.2
\internal
*/
-bool QMetaType::registerConverterFunction(const QtPrivate::AbstractConverterFunction *f, int from, int to)
+bool QMetaType::registerConverterFunction(const ConverterFunction &f, int from, int to)
{
if (!customTypesConversionRegistry()->insertIfNotContains(qMakePair(from, to), f)) {
qWarning("Type conversion already registered from type %s to type %s",
@@ -1036,9 +1036,9 @@ bool QMetaType::hasRegisteredDebugStreamOperator() const
*/
bool QMetaType::convert(const void *from, int fromTypeId, void *to, int toTypeId)
{
- const QtPrivate::AbstractConverterFunction * const f =
+ const QMetaType::ConverterFunction * const f =
customTypesConversionRegistry()->function(qMakePair(fromTypeId, toTypeId));
- return f && f->convert(f, from, to);
+ return f && (*f)(from, to);
}
/*!