QDebug: clean up handling of QMap/QHash

Prepare for the fact that the multi-key containers will no longer
inherit from the single-key ones. Refactor the code to follow
the existing.

Change-Id: I5fd4d7e33f8184c015e18e169af72e11a5e84f0d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Giuseppe D'Angelo 2020-05-11 03:03:32 +02:00
parent f35745a30c
commit 18693916a4

View File

@ -250,6 +250,20 @@ inline QDebug printSequentialContainer(QDebug debug, const char *which, const Se
return debug.maybeSpace();
}
template <typename AssociativeContainer>
inline QDebug printAssociativeContainer(QDebug debug, const char *which, const AssociativeContainer &c)
{
const bool oldSetting = debug.autoInsertSpaces();
debug.nospace() << which << "(";
for (typename AssociativeContainer::const_iterator it = c.constBegin();
it != c.constEnd(); ++it) {
debug << '(' << it.key() << ", " << it.value() << ')';
}
debug << ')';
debug.setAutoInsertSpaces(oldSetting);
return debug.maybeSpace();
}
} // namespace QtPrivate
template <typename T>
@ -285,28 +299,25 @@ inline QDebug operator<<(QDebug debug, const std::multimap<Key, T, Compare, Allo
template <class Key, class T>
inline QDebug operator<<(QDebug debug, const QMap<Key, T> &map)
{
const bool oldSetting = debug.autoInsertSpaces();
debug.nospace() << "QMap(";
for (typename QMap<Key, T>::const_iterator it = map.constBegin();
it != map.constEnd(); ++it) {
debug << '(' << it.key() << ", " << it.value() << ')';
}
debug << ')';
debug.setAutoInsertSpaces(oldSetting);
return debug.maybeSpace();
return QtPrivate::printAssociativeContainer(debug, "QMap", map);
}
template <class Key, class T>
inline QDebug operator<<(QDebug debug, const QMultiMap<Key, T> &map)
{
return QtPrivate::printAssociativeContainer(debug, "QMultiMap", map);
}
template <class Key, class T>
inline QDebug operator<<(QDebug debug, const QHash<Key, T> &hash)
{
const bool oldSetting = debug.autoInsertSpaces();
debug.nospace() << "QHash(";
for (typename QHash<Key, T>::const_iterator it = hash.constBegin();
it != hash.constEnd(); ++it)
debug << '(' << it.key() << ", " << it.value() << ')';
debug << ')';
debug.setAutoInsertSpaces(oldSetting);
return debug.maybeSpace();
return QtPrivate::printAssociativeContainer(debug, "QHash", hash);
}
template <class Key, class T>
inline QDebug operator<<(QDebug debug, const QMultiHash<Key, T> &hash)
{
return QtPrivate::printAssociativeContainer(debug, "QMultiHash", hash);
}
template <class T1, class T2>