From 2aa39be4c23ad837c6a09b5cf74c74da670d7ebf Mon Sep 17 00:00:00 2001 From: Tatiana Borisova Date: Thu, 11 Jul 2024 12:20:26 +0200 Subject: Add QDebug printing for the std/Qt::_ordering types [ChangeLog][QtCore][QDebug] Added possibility to print {std/Qt} weak/partial/strong_ordering values with QDebug << operator. Change-Id: Ie880cb34c19f79a404c692c2322b3460d72bfde4 Reviewed-by: Marc Mutz --- src/corelib/io/qdebug.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/corelib/io/qdebug.cpp') diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 9a00b0b2006..cd835f548c0 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -511,6 +511,46 @@ void QDebug::putUInt128([[maybe_unused]] const void *p) stream->ts << int128Warning(); } +/*! + \since 6.9 + \internal + Helper to the ::<>_ordering debug output. + It generates the string in following format: + ::_ordering:: + */ +void QDebug::putQtOrdering(QtOrderingPrivate::QtOrderingTypeFlag flags, Qt::partial_ordering order) +{ + using QtOrderingPrivate::QtOrderingType; + std::string result; + if ((flags & QtOrderingType::StdOrder) == QtOrderingType::StdOrder) + result += "std"; + else if ((flags & QtOrderingType::QtOrder) == QtOrderingType::QtOrder) + result += "Qt"; + + result += "::"; + const bool isStrong = ((flags & QtOrderingType::Strong) == QtOrderingType::Strong); + if (isStrong) + result += "strong"; + else if ((flags & QtOrderingType::Weak) == QtOrderingType::Weak) + result += "weak"; + else if ((flags & QtOrderingType::Partial) == QtOrderingType::Partial) + result += "partial"; + result += "_ordering::"; + + if (order == Qt::partial_ordering::equivalent) { + if (isStrong) + result += "equal"; + else + result += "equivalent"; + } else if (order == Qt::partial_ordering::greater) { + result += "greater"; + } else if (order == Qt::partial_ordering::less) { + result += "less"; + } else { + result += "unordered"; + } + stream->ts << result.data(); +} /*! \fn QDebug::swap(QDebug &other) @@ -948,6 +988,15 @@ QDebug &QDebug::resetFormat() \internal */ +/*! + \fn template > QDebug::operator<<(QDebug debug, T t) + \since 6.9 + Prints the Qt or std ordering value \a t to the \a debug object. + + \note This function only participates in overload resolution if \c T + is one of ::_ordering. +*/ + /*! \since 6.5 \fn template QDebug &QDebug::operator<<(const std::basic_string &s) -- cgit v1.2.3