summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qdebug.h
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-05-11 03:03:32 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-05-11 22:17:38 +0200
commit18693916a4b6224b55d33c7cd650ea2849b3ac7b (patch)
tree1b7ed8e30d7ea5eff126d0dc960bf7455167bcc9 /src/corelib/io/qdebug.h
parentf35745a30c631b3ce6b5a435fd4571595b952749 (diff)
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>
Diffstat (limited to 'src/corelib/io/qdebug.h')
-rw-r--r--src/corelib/io/qdebug.h45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index aa69a1ae23..76fea1a3e0 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -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>