qfloat16: make it a built-in metatype
I've reserved the IDs for int128, uint128, bfloat16, and float128, because the mask in qvariant.cpp's qIsNumericType() requires primitives to be less than 64 to operate properly. Added a QMetaType/QDataStream test to confirm it is indeed built-in. Change-Id: I3d74c753055744deb8acfffd17247f7f57bada02 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
parent
5838074912
commit
f6f1ee63dc
@ -353,8 +353,12 @@ const char *QtMetaTypePrivate::typedefNameForType(const QtPrivate::QMetaTypeInte
|
|||||||
\value SChar \c{signed char}
|
\value SChar \c{signed char}
|
||||||
\value UChar \c{unsigned char}
|
\value UChar \c{unsigned char}
|
||||||
\value Float \c float
|
\value Float \c float
|
||||||
|
\value Float16 qfloat16
|
||||||
|
\omitvalue Float128
|
||||||
|
\omitvalue BFloat16
|
||||||
|
\omitvalue Int128
|
||||||
|
\omitvalue UInt128
|
||||||
\value QObjectStar QObject *
|
\value QObjectStar QObject *
|
||||||
\value QVariant QVariant
|
|
||||||
|
|
||||||
\value QCursor QCursor
|
\value QCursor QCursor
|
||||||
\value QDate QDate
|
\value QDate QDate
|
||||||
@ -413,6 +417,7 @@ const char *QtMetaTypePrivate::typedefNameForType(const QtPrivate::QMetaTypeInte
|
|||||||
\value QPersistentModelIndex QPersistentModelIndex (introduced in Qt 5.5)
|
\value QPersistentModelIndex QPersistentModelIndex (introduced in Qt 5.5)
|
||||||
\value QUuid QUuid
|
\value QUuid QUuid
|
||||||
\value QByteArrayList QByteArrayList
|
\value QByteArrayList QByteArrayList
|
||||||
|
\value QVariant QVariant
|
||||||
|
|
||||||
\value User Base value for user types
|
\value User Base value for user types
|
||||||
\value UnknownType This is an invalid type id. It is returned from QMetaType for types that are not registered
|
\value UnknownType This is an invalid type id. It is returned from QMetaType for types that are not registered
|
||||||
|
@ -10,13 +10,14 @@
|
|||||||
#include <QtCore/qatomic.h>
|
#include <QtCore/qatomic.h>
|
||||||
#include <QtCore/qbytearray.h>
|
#include <QtCore/qbytearray.h>
|
||||||
#include <QtCore/qcompare.h>
|
#include <QtCore/qcompare.h>
|
||||||
#include <QtCore/qscopeguard.h>
|
|
||||||
#include <QtCore/qdatastream.h>
|
#include <QtCore/qdatastream.h>
|
||||||
|
#include <QtCore/qfloat16.h>
|
||||||
|
#include <QtCore/qhashfunctions.h>
|
||||||
#include <QtCore/qiterable.h>
|
#include <QtCore/qiterable.h>
|
||||||
#ifndef QT_NO_QOBJECT
|
#ifndef QT_NO_QOBJECT
|
||||||
#include <QtCore/qobjectdefs.h>
|
#include <QtCore/qobjectdefs.h>
|
||||||
#endif
|
#endif
|
||||||
#include <QtCore/qhashfunctions.h>
|
#include <QtCore/qscopeguard.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <new>
|
#include <new>
|
||||||
@ -121,6 +122,7 @@ inline constexpr int qMetaTypeId();
|
|||||||
F(QCborValue, 53, QCborValue) \
|
F(QCborValue, 53, QCborValue) \
|
||||||
F(QCborArray, 54, QCborArray) \
|
F(QCborArray, 54, QCborArray) \
|
||||||
F(QCborMap, 55, QCborMap) \
|
F(QCborMap, 55, QCborMap) \
|
||||||
|
F(Float16, 63, qfloat16) \
|
||||||
QT_FOR_EACH_STATIC_ITEMMODEL_CLASS(F)
|
QT_FOR_EACH_STATIC_ITEMMODEL_CLASS(F)
|
||||||
|
|
||||||
#define QT_FOR_EACH_STATIC_CORE_POINTER(F)\
|
#define QT_FOR_EACH_STATIC_CORE_POINTER(F)\
|
||||||
@ -317,7 +319,7 @@ public:
|
|||||||
QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID)
|
QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID)
|
||||||
|
|
||||||
FirstCoreType = Bool,
|
FirstCoreType = Bool,
|
||||||
LastCoreType = QVariantPair,
|
LastCoreType = Float16,
|
||||||
FirstGuiType = QFont,
|
FirstGuiType = QFont,
|
||||||
LastGuiType = QColorSpace,
|
LastGuiType = QColorSpace,
|
||||||
FirstWidgetsType = QSizePolicy,
|
FirstWidgetsType = QSizePolicy,
|
||||||
@ -349,6 +351,7 @@ public:
|
|||||||
QVariantMap = 8, QVariantList = 9, QVariantHash = 28, QVariantPair = 58,
|
QVariantMap = 8, QVariantList = 9, QVariantHash = 28, QVariantPair = 58,
|
||||||
QCborSimpleType = 52, QCborValue = 53, QCborArray = 54, QCborMap = 55,
|
QCborSimpleType = 52, QCborValue = 53, QCborArray = 54, QCborMap = 55,
|
||||||
Char16 = 56, Char32 = 57,
|
Char16 = 56, Char32 = 57,
|
||||||
|
Int128 = 59, UInt128 = 60, Float128 = 61, BFloat16 = 62, Float16 = 63,
|
||||||
|
|
||||||
// Gui types
|
// Gui types
|
||||||
QFont = 0x1000, QPixmap = 0x1001, QBrush = 0x1002, QColor = 0x1003, QPalette = 0x1004,
|
QFont = 0x1000, QPixmap = 0x1001, QBrush = 0x1002, QColor = 0x1003, QPalette = 0x1004,
|
||||||
|
@ -183,6 +183,8 @@ static std::optional<qreal> qConvertToRealNumber(const QVariant::Private *d)
|
|||||||
return qreal(d->get<double>());
|
return qreal(d->get<double>());
|
||||||
case QMetaType::Float:
|
case QMetaType::Float:
|
||||||
return qreal(d->get<float>());
|
return qreal(d->get<float>());
|
||||||
|
case QMetaType::Float16:
|
||||||
|
return qreal(d->get<qfloat16>());
|
||||||
case QMetaType::ULongLong:
|
case QMetaType::ULongLong:
|
||||||
case QMetaType::UInt:
|
case QMetaType::UInt:
|
||||||
case QMetaType::UChar:
|
case QMetaType::UChar:
|
||||||
@ -2161,7 +2163,7 @@ static bool qIsNumericType(uint tp)
|
|||||||
|
|
||||||
static bool qIsFloatingPoint(uint tp)
|
static bool qIsFloatingPoint(uint tp)
|
||||||
{
|
{
|
||||||
return tp == QMetaType::Double || tp == QMetaType::Float;
|
return tp == QMetaType::Double || tp == QMetaType::Float || tp == QMetaType::Float16;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool canBeNumericallyCompared(const QtPrivate::QMetaTypeInterface *iface1,
|
static bool canBeNumericallyCompared(const QtPrivate::QMetaTypeInterface *iface1,
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <QFloat16>
|
#include <QFloat16>
|
||||||
|
#include <QMetaType>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@ -656,6 +657,17 @@ void tst_qfloat16::dataStream()
|
|||||||
ds >> zero;
|
ds >> zero;
|
||||||
QCOMPARE(ds.status(), QDataStream::Ok);
|
QCOMPARE(ds.status(), QDataStream::Ok);
|
||||||
QCOMPARE(zero, qfloat16(0));
|
QCOMPARE(zero, qfloat16(0));
|
||||||
|
|
||||||
|
ds.device()->seek(0);
|
||||||
|
ds.resetStatus();
|
||||||
|
QMetaType mt = QMetaType(QMetaType::Float16);
|
||||||
|
QVERIFY(mt.save(ds, &zero));
|
||||||
|
|
||||||
|
ds.device()->seek(0);
|
||||||
|
ds.resetStatus();
|
||||||
|
zero = -1;
|
||||||
|
QVERIFY(mt.load(ds, &zero));
|
||||||
|
QCOMPARE(zero, qfloat16(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_qfloat16::textStream()
|
void tst_qfloat16::textStream()
|
||||||
|
@ -129,6 +129,9 @@ template<> struct TestValueFactory<QMetaType::UChar> {
|
|||||||
template<> struct TestValueFactory<QMetaType::Float> {
|
template<> struct TestValueFactory<QMetaType::Float> {
|
||||||
static float *create() { return new float(FLT_MIN); }
|
static float *create() { return new float(FLT_MIN); }
|
||||||
};
|
};
|
||||||
|
template<> struct TestValueFactory<QMetaType::Float16> {
|
||||||
|
static auto create() { return new qfloat16(std::numeric_limits<qfloat16>::min()); }
|
||||||
|
};
|
||||||
template<> struct TestValueFactory<QMetaType::QObjectStar> {
|
template<> struct TestValueFactory<QMetaType::QObjectStar> {
|
||||||
static QObject * *create() { return new QObject *(0); }
|
static QObject * *create() { return new QObject *(0); }
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user