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 <ivan.solovev@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Thiago Macieira 2025-01-22 11:38:43 -08:00
parent ac5ab8ce32
commit 0f128fd7c5
4 changed files with 34 additions and 40 deletions

View File

@ -1031,6 +1031,21 @@ QDataStream &QDataStream::operator>>(char32_t &c)
return *this; 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) #if QT_DEPRECATED_SINCE(6, 11)
/*! /*!
@ -1383,6 +1398,19 @@ QDataStream &QDataStream::operator<<(char32_t c)
return *this << qint32(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 Writes the length specifier \a len and the buffer \a s to the
stream and returns a reference to the stream. stream and returns a reference to the stream.

View File

@ -4,10 +4,11 @@
#ifndef QDATASTREAM_H #ifndef QDATASTREAM_H
#define QDATASTREAM_H #define QDATASTREAM_H
#include <QtCore/qscopedpointer.h> #include <QtCore/qchar.h>
#include <QtCore/qiodevicebase.h>
#include <QtCore/qcontainerfwd.h> #include <QtCore/qcontainerfwd.h>
#include <QtCore/qiodevicebase.h>
#include <QtCore/qnamespace.h> #include <QtCore/qnamespace.h>
#include <QtCore/qscopedpointer.h>
#include <QtCore/qttypetraits.h> #include <QtCore/qttypetraits.h>
#include <iterator> // std::distance(), std::next() #include <iterator> // std::distance(), std::next()
@ -548,6 +549,9 @@ operator>>(QDataStream &s, T &t)
return s; return s;
} }
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, QChar chr);
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QChar &chr);
#ifndef Q_QDOC #ifndef Q_QDOC
template<typename T> template<typename T>

View File

@ -3,8 +3,6 @@
#include "qchar.h" #include "qchar.h"
#include "qdatastream.h"
#include "qunicodetables_p.h" #include "qunicodetables_p.h"
#include "qunicodetables.cpp" #include "qunicodetables.cpp"
@ -1741,36 +1739,6 @@ char32_t QChar::toCaseFolded(char32_t ucs4) noexcept
\sa toLatin1(), unicode() \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() \fn QChar::unicode()

View File

@ -11,7 +11,6 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QDataStream;
class QString; class QString;
struct QLatin1Char struct QLatin1Char
@ -680,11 +679,6 @@ private:
Q_DECLARE_TYPEINFO(QChar, Q_PRIMITIVE_TYPE); 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 { namespace Qt {
inline namespace Literals { inline namespace Literals {
inline namespace StringLiterals { inline namespace StringLiterals {