From 0f128fd7c5a9ee721d1e631743f6eb61d927cf3b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 22 Jan 2025 11:38:43 -0800 Subject: [PATCH] QDataStream: move the QChar streaming operators to qdatastream.h That frees qchar.h/cpp from having to know about QDataStream. Change-Id: I7c217e32021f67ab27ecfffd47ba5ee025ecb1bf Reviewed-by: Ivan Solovev Reviewed-by: Edward Welbourne --- src/corelib/serialization/qdatastream.cpp | 28 ++++++++++++++++++++ src/corelib/serialization/qdatastream.h | 8 ++++-- src/corelib/text/qchar.cpp | 32 ----------------------- src/corelib/text/qchar.h | 6 ----- 4 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp index f9c08cd78e4..4a18c6b781e 100644 --- a/src/corelib/serialization/qdatastream.cpp +++ b/src/corelib/serialization/qdatastream.cpp @@ -1031,6 +1031,21 @@ QDataStream &QDataStream::operator>>(char32_t &c) return *this; } +/*! + \relates QChar + + Reads a char from the stream \a in into char \a chr. + + \sa {Serializing Qt Data Types} +*/ +QDataStream &operator>>(QDataStream &in, QChar &chr) +{ + quint16 u; + in >> u; + chr.unicode() = char16_t(u); + return in; +} + #if QT_DEPRECATED_SINCE(6, 11) /*! @@ -1383,6 +1398,19 @@ QDataStream &QDataStream::operator<<(char32_t c) return *this << qint32(c); } +/*! + \relates QChar + + Writes the char \a chr to the stream \a out. + + \sa {Serializing Qt Data Types} +*/ +QDataStream &operator<<(QDataStream &out, QChar chr) +{ + out << quint16(chr.unicode()); + return out; +} + /*! Writes the length specifier \a len and the buffer \a s to the stream and returns a reference to the stream. diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h index 76107aa93b0..730334ef83a 100644 --- a/src/corelib/serialization/qdatastream.h +++ b/src/corelib/serialization/qdatastream.h @@ -4,10 +4,11 @@ #ifndef QDATASTREAM_H #define QDATASTREAM_H -#include -#include +#include #include +#include #include +#include #include #include // std::distance(), std::next() @@ -548,6 +549,9 @@ operator>>(QDataStream &s, T &t) return s; } +Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, QChar chr); +Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QChar &chr); + #ifndef Q_QDOC template diff --git a/src/corelib/text/qchar.cpp b/src/corelib/text/qchar.cpp index 34d3d0898ed..7308d5dd888 100644 --- a/src/corelib/text/qchar.cpp +++ b/src/corelib/text/qchar.cpp @@ -3,8 +3,6 @@ #include "qchar.h" -#include "qdatastream.h" - #include "qunicodetables_p.h" #include "qunicodetables.cpp" @@ -1741,36 +1739,6 @@ char32_t QChar::toCaseFolded(char32_t ucs4) noexcept \sa toLatin1(), unicode() */ -#ifndef QT_NO_DATASTREAM -/*! - \relates QChar - - Writes the char \a chr to the stream \a out. - - \sa {Serializing Qt Data Types} -*/ -QDataStream &operator<<(QDataStream &out, QChar chr) -{ - out << quint16(chr.unicode()); - return out; -} - -/*! - \relates QChar - - Reads a char from the stream \a in into char \a chr. - - \sa {Serializing Qt Data Types} -*/ -QDataStream &operator>>(QDataStream &in, QChar &chr) -{ - quint16 u; - in >> u; - chr.unicode() = char16_t(u); - return in; -} -#endif // QT_NO_DATASTREAM - /*! \fn QChar::unicode() diff --git a/src/corelib/text/qchar.h b/src/corelib/text/qchar.h index c090da824ef..a0108d39b2b 100644 --- a/src/corelib/text/qchar.h +++ b/src/corelib/text/qchar.h @@ -11,7 +11,6 @@ QT_BEGIN_NAMESPACE -class QDataStream; class QString; struct QLatin1Char @@ -680,11 +679,6 @@ private: Q_DECLARE_TYPEINFO(QChar, Q_PRIMITIVE_TYPE); -#ifndef QT_NO_DATASTREAM -Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QChar); -Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QChar &); -#endif - namespace Qt { inline namespace Literals { inline namespace StringLiterals {