Skip to content

Commit

Permalink
QDataStream: move the QChar streaming operators to qdatastream.h
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
thiagomacieira committed Jan 30, 2025
1 parent ac5ab8c commit 0f128fd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 40 deletions.
28 changes: 28 additions & 0 deletions src/corelib/serialization/qdatastream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

/*!
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions src/corelib/serialization/qdatastream.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#ifndef QDATASTREAM_H
#define QDATASTREAM_H

#include <QtCore/qscopedpointer.h>
#include <QtCore/qiodevicebase.h>
#include <QtCore/qchar.h>
#include <QtCore/qcontainerfwd.h>
#include <QtCore/qiodevicebase.h>
#include <QtCore/qnamespace.h>
#include <QtCore/qscopedpointer.h>
#include <QtCore/qttypetraits.h>

#include <iterator> // std::distance(), std::next()
Expand Down Expand Up @@ -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<typename T>
Expand Down
32 changes: 0 additions & 32 deletions src/corelib/text/qchar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include "qchar.h"

#include "qdatastream.h"

#include "qunicodetables_p.h"
#include "qunicodetables.cpp"

Expand Down Expand Up @@ -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()
Expand Down
6 changes: 0 additions & 6 deletions src/corelib/text/qchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

QT_BEGIN_NAMESPACE

class QDataStream;
class QString;

struct QLatin1Char
Expand Down Expand Up @@ -680,11 +679,6 @@ class QT6_ONLY(Q_CORE_EXPORT) QChar {

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 {
Expand Down

0 comments on commit 0f128fd

Please sign in to comment.