diff options
-rw-r--r-- | src/corelib/compat/removed_api.cpp | 17 | ||||
-rw-r--r-- | src/corelib/global/qfloat16.cpp | 37 | ||||
-rw-r--r-- | src/corelib/global/qfloat16.h | 9 | ||||
-rw-r--r-- | src/corelib/serialization/qdatastream.cpp | 27 | ||||
-rw-r--r-- | src/corelib/serialization/qdatastream.h | 8 |
5 files changed, 69 insertions, 29 deletions
diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index 16811bf37e..b856f6b495 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -103,6 +103,23 @@ QByteArray QCryptographicHash::hash(const QByteArray &data, Algorithm method) return hash(QByteArrayView{data}, method); } +#include "qdatastream.h" + +# ifndef QT_NO_DATASTREAM +# include "qfloat16.h" + +QDataStream &QDataStream::operator>>(qfloat16 &f) +{ + return *this >> reinterpret_cast<qint16&>(f); +} + +QDataStream &QDataStream::operator<<(qfloat16 f) +{ + return *this << reinterpret_cast<qint16&>(f); +} + +# endif + #include "quuid.h" QUuid::QUuid(const QString &text) diff --git a/src/corelib/global/qfloat16.cpp b/src/corelib/global/qfloat16.cpp index 0eb6ec1010..62c87234a2 100644 --- a/src/corelib/global/qfloat16.cpp +++ b/src/corelib/global/qfloat16.cpp @@ -42,6 +42,8 @@ #include "private/qsimd_p.h" #include <cmath> // for fpclassify()'s return values +#include <QtCore/qdatastream.h> + QT_BEGIN_NAMESPACE QT_IMPL_METATYPE_EXTERN(qfloat16) @@ -394,6 +396,41 @@ Q_CORE_EXPORT void qFloatFromFloat16(float *out, const qfloat16 *in, qsizetype l out[i] = float(in[i]); } +#ifndef QT_NO_DATASTREAM +/*! + \fn qfloat16::operator<<(QDataStream &ds, qfloat16 f) + \relates QDataStream + \since 5.9 + + Writes a floating point number, \a f, to the stream \a ds using + the standard IEEE 754 format. Returns a reference to the stream. + + \note In Qt versions prior to 6.3, this was a member function on + QDataStream. +*/ +QDataStream &operator<<(QDataStream &ds, qfloat16 f) +{ + return ds << f.b16; +} + +/*! + \fn qfloat16::operator>>(QDataStream &ds, qfloat16 &f) + \relates QDataStream + \since 5.9 + + Reads a floating point number from the stream \a ds into \a f, + using the standard IEEE 754 format. Returns a reference to the + stream. + + \note In Qt versions prior to 6.3, this was a member function on + QDataStream. +*/ +QDataStream &operator>>(QDataStream &ds, qfloat16 &f) +{ + return ds >> f.b16; +} +#endif + QT_END_NAMESPACE #include "qfloat16tables.cpp" diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index 8361dd8764..d9fd89215d 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -67,6 +67,10 @@ QT_BEGIN_NAMESPACE #pragma qt_no_master_include #endif +#ifndef QT_NO_DATASTREAM +class QDataStream; +#endif + class qfloat16 { struct Wrap @@ -200,6 +204,11 @@ QT_WARNING_DISABLE_FLOAT_COMPARE #undef QF16_MAKE_BOOL_OP_INT QT_WARNING_POP + +#ifndef QT_NO_DATASTREAM + friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &ds, qfloat16 f); + friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &ds, qfloat16 &f); +#endif }; Q_DECLARE_TYPEINFO(qfloat16, Q_PRIMITIVE_TYPE); diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp index 67423ee62c..69b497d0e5 100644 --- a/src/corelib/serialization/qdatastream.cpp +++ b/src/corelib/serialization/qdatastream.cpp @@ -993,20 +993,6 @@ QDataStream &QDataStream::operator>>(double &f) /*! \overload - \since 5.9 - - Reads a floating point number from the stream into \a f, - using the standard IEEE 754 format. Returns a reference to the - stream. -*/ -QDataStream &QDataStream::operator>>(qfloat16 &f) -{ - return *this >> reinterpret_cast<qint16&>(f); -} - - -/*! - \overload Reads the '\\0'-terminated string \a s from the stream and returns a reference to the stream. @@ -1341,19 +1327,6 @@ QDataStream &QDataStream::operator<<(double f) /*! - \fn QDataStream &QDataStream::operator<<(qfloat16 f) - \overload - \since 5.9 - - Writes a floating point number, \a f, to the stream using - the standard IEEE 754 format. Returns a reference to the stream. -*/ -QDataStream &QDataStream::operator<<(qfloat16 f) -{ - return *this << reinterpret_cast<qint16&>(f); -} - -/*! \overload Writes the '\\0'-terminated string \a s to the stream and returns a diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h index 584de3166a..ac0adc1bf9 100644 --- a/src/corelib/serialization/qdatastream.h +++ b/src/corelib/serialization/qdatastream.h @@ -51,7 +51,9 @@ QT_BEGIN_NAMESPACE +#if QT_CORE_REMOVED_SINCE(6, 3) class qfloat16; +#endif class QByteArray; class QIODevice; @@ -160,8 +162,9 @@ public: QDataStream &operator>>(std::nullptr_t &ptr) { ptr = nullptr; return *this; } QDataStream &operator>>(bool &i); - // ### Qt 7: remove the operator or make qfloat16 fully defined, see QTBUG-93499 +#if QT_CORE_REMOVED_SINCE(6, 3) QDataStream &operator>>(qfloat16 &f); +#endif QDataStream &operator>>(float &f); QDataStream &operator>>(double &f); QDataStream &operator>>(char *&str); @@ -179,8 +182,9 @@ public: QDataStream &operator<<(quint64 i); QDataStream &operator<<(std::nullptr_t) { return *this; } QDataStream &operator<<(bool i); - // ### Qt 7: remove the operator or make qfloat16 fully defined, see QTBUG-93499 +#if QT_CORE_REMOVED_SINCE(6, 3) QDataStream &operator<<(qfloat16 f); +#endif QDataStream &operator<<(float f); QDataStream &operator<<(double f); QDataStream &operator<<(const char *str); |