diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor/debughelpers_p.h')
-rw-r--r-- | sources/shiboken6/ApiExtractor/debughelpers_p.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/sources/shiboken6/ApiExtractor/debughelpers_p.h b/sources/shiboken6/ApiExtractor/debughelpers_p.h new file mode 100644 index 000000000..81ebbb3b9 --- /dev/null +++ b/sources/shiboken6/ApiExtractor/debughelpers_p.h @@ -0,0 +1,56 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef DEBUGHELPERS_P_H +#define DEBUGHELPERS_P_H + +#include <QtCore/QDebug> +#include <memory> + +template <class T> +inline QDebug operator<<(QDebug debug, const std::shared_ptr<T> &ptr) +{ + QDebugStateSaver saver(debug); + debug.nospace(); + debug << "std::shared_ptr(" << ptr.get() << ")"; + return debug; +} + +template <class It> +inline void formatSequence(QDebug &d, It i1, It i2, + const char *separator=", ") +{ + for (It i = i1; i != i2; ++i) { + if (i != i1) + d << separator; + d << *i; + } +} + +template <class It> +inline static void formatPtrSequence(QDebug &d, It i1, It i2, + const char *separator=", ") +{ + for (It i = i1; i != i2; ++i) { + if (i != i1) + d << separator; + d << i->get(); + } +} + +template <class Container> +static void formatList(QDebug &d, const char *name, const Container &c, + const char *separator=", ") +{ + if (const auto size = c.size()) { + d << ", " << name << '[' << size << "]=("; + for (qsizetype i = 0; i < size; ++i) { + if (i) + d << separator; + d << c.at(i); + } + d << ')'; + } +} + +#endif // DEBUGHELPERS_P_H |