diff options
Diffstat (limited to 'src/corelib/io/qdebug.h')
-rw-r--r-- | src/corelib/io/qdebug.h | 162 |
1 files changed, 112 insertions, 50 deletions
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index b1a0396f35..5087e3b532 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -1,31 +1,38 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -45,6 +52,12 @@ #include <QtCore/qset.h> #include <QtCore/qcontiguouscache.h> +// all these have already been included by various headers above, but don't rely on indirect includes: +#include <vector> +#include <list> +#include <map> +#include <utility> + QT_BEGIN_NAMESPACE @@ -53,14 +66,14 @@ class Q_CORE_EXPORT QDebug friend class QMessageLogger; friend class QDebugStateSaverPrivate; struct Stream { - enum { defaultVerbosity = 2, verbosityShift = 29, verbosityMask = 0x7 }; + enum { DefaultVerbosity = 2, VerbosityShift = 29, VerbosityMask = 0x7 }; Stream(QIODevice *device) : ts(device), ref(1), type(QtDebugMsg), - space(true), message_output(false), flags(defaultVerbosity << verbosityShift) {} + space(true), message_output(false), flags(DefaultVerbosity << VerbosityShift) {} Stream(QString *string) : ts(string, QIODevice::WriteOnly), ref(1), type(QtDebugMsg), - space(true), message_output(false), flags(defaultVerbosity << verbosityShift) {} + space(true), message_output(false), flags(DefaultVerbosity << VerbosityShift) {} Stream(QtMsgType t) : ts(&buffer, QIODevice::WriteOnly), ref(1), type(t), - space(true), message_output(true), flags(defaultVerbosity << verbosityShift) {} + space(true), message_output(true), flags(DefaultVerbosity << VerbosityShift) {} QTextStream ts; QString buffer; int ref; @@ -78,12 +91,12 @@ class Q_CORE_EXPORT QDebug void setFlag(FormatFlag flag) { if (context.version > 1) { flags |= flag; } } void unsetFlag(FormatFlag flag) { if (context.version > 1) { flags &= ~flag; } } int verbosity() const - { return context.version > 1 ? (flags >> verbosityShift) & verbosityMask : int(Stream::defaultVerbosity); } + { return context.version > 1 ? (flags >> VerbosityShift) & VerbosityMask : int(Stream::DefaultVerbosity); } void setVerbosity(int v) { if (context.version > 1) { - flags &= ~(verbosityMask << verbosityShift); - flags |= (v & verbosityMask) << verbosityShift; + flags &= ~(VerbosityMask << VerbosityShift); + flags |= (v & VerbosityMask) << VerbosityShift; } } // added in 5.4 @@ -192,28 +205,63 @@ inline QDebug &QDebug::operator=(const QDebug &other) return *this; } -template <class T> -inline QDebug operator<<(QDebug debug, const QList<T> &list) +namespace QtPrivate { + +template <typename SequentialContainer> +inline QDebug printSequentialContainer(QDebug debug, const char *which, const SequentialContainer &c) { const bool oldSetting = debug.autoInsertSpaces(); - debug.nospace() << '('; - for (typename QList<T>::size_type i = 0; i < list.count(); ++i) { - if (i) - debug << ", "; - debug << list.at(i); + debug.nospace() << which << '('; + typename SequentialContainer::const_iterator it = c.begin(), end = c.end(); + if (it != end) { + debug << *it; + ++it; + } + while (it != end) { + debug << ", " << *it; + ++it; } debug << ')'; debug.setAutoInsertSpaces(oldSetting); return debug.maybeSpace(); } +} // namespace QtPrivate + +template <class T> +inline QDebug operator<<(QDebug debug, const QList<T> &list) +{ + return QtPrivate::printSequentialContainer(debug, "" /*for historical reasons*/, list); +} + template <typename T> inline QDebug operator<<(QDebug debug, const QVector<T> &vec) { - const bool oldSetting = debug.autoInsertSpaces(); - debug.nospace() << "QVector"; - debug.setAutoInsertSpaces(oldSetting); - return operator<<(debug, vec.toList()); + return QtPrivate::printSequentialContainer(debug, "QVector", vec); +} + +template <typename T, typename Alloc> +inline QDebug operator<<(QDebug debug, const std::vector<T, Alloc> &vec) +{ + return QtPrivate::printSequentialContainer(debug, "std::vector", vec); +} + +template <typename T, typename Alloc> +inline QDebug operator<<(QDebug debug, const std::list<T, Alloc> &vec) +{ + return QtPrivate::printSequentialContainer(debug, "std::list", vec); +} + +template <typename Key, typename T, typename Compare, typename Alloc> +inline QDebug operator<<(QDebug debug, const std::map<Key, T, Compare, Alloc> &map) +{ + return QtPrivate::printSequentialContainer(debug, "std::map", map); // yes, sequential: *it is std::pair +} + +template <typename Key, typename T, typename Compare, typename Alloc> +inline QDebug operator<<(QDebug debug, const std::multimap<Key, T, Compare, Alloc> &map) +{ + return QtPrivate::printSequentialContainer(debug, "std::multimap", map); // yes, sequential: *it is std::pair } template <class Key, class T> @@ -252,13 +300,19 @@ inline QDebug operator<<(QDebug debug, const QPair<T1, T2> &pair) return debug.maybeSpace(); } -template <typename T> -inline QDebug operator<<(QDebug debug, const QSet<T> &set) +template <class T1, class T2> +inline QDebug operator<<(QDebug debug, const std::pair<T1, T2> &pair) { const bool oldSetting = debug.autoInsertSpaces(); - debug.nospace() << "QSet"; + debug.nospace() << "std::pair(" << pair.first << ',' << pair.second << ')'; debug.setAutoInsertSpaces(oldSetting); - return operator<<(debug, set.toList()); + return debug.maybeSpace(); +} + +template <typename T> +inline QDebug operator<<(QDebug debug, const QSet<T> &set) +{ + return QtPrivate::printSequentialContainer(debug, "QSet", set); } template <class T> @@ -276,6 +330,27 @@ inline QDebug operator<<(QDebug debug, const QContiguousCache<T> &cache) return debug.maybeSpace(); } +Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, int value); + +template <typename Int> +void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, Int value) +{ + const QDebugStateSaver saver(debug); + debug.resetFormat(); + debug.nospace() << "QFlags(" << hex << showbase; + bool needSeparator = false; + for (uint i = 0; i < sizeofT * 8; ++i) { + if (value & (Int(1) << i)) { + if (needSeparator) + debug << '|'; + else + needSeparator = true; + debug << (Int(1) << i); + } + } + debug << ')'; +} + #if !defined(QT_NO_QOBJECT) && !defined(Q_QDOC) Q_CORE_EXPORT QDebug qt_QMetaEnum_debugOperator(QDebug&, int value, const QMetaObject *meta, const char *name); Q_CORE_EXPORT QDebug qt_QMetaEnum_flagDebugOperator(QDebug &dbg, quint64 value, const QMetaObject *meta, const char *name); @@ -310,20 +385,7 @@ template <class T> inline QDebug qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags) #endif { - QDebugStateSaver saver(debug); - debug.resetFormat(); - debug.nospace() << "QFlags(" << hex << showbase; - bool needSeparator = false; - for (uint i = 0; i < sizeof(T) * 8; ++i) { - if (flags.testFlag(T(1 << i))) { - if (needSeparator) - debug << '|'; - else - needSeparator = true; - debug << (typename QFlags<T>::Int(1) << i); - } - } - debug << ')'; + qt_QMetaEnum_flagDebugOperator(debug, sizeof(T), typename QFlags<T>::Int(flags)); return debug; } |