summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qjsonvalue.h
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-06-19 13:43:00 +0200
committerUlf Hermann <ulf.hermann@qt.io>2019-10-21 19:12:51 +0200
commit35adb74ddd915831789f0175423660f8e898942e (patch)
tree3ac0fd8be75f0b7e0391149d13aab51a7f02dd3f /src/corelib/serialization/qjsonvalue.h
parent559b563d711db0760a51b0dce26536dbc8766a9d (diff)
Reimplement JSON support on top of Cbor
In turn, deprecate the QJsonDocument methods that deal with JSON binary data. You should use CBOR for data serialization these days. [ChangeLog][Deprecation Notice] The binary JSON representation is deprecated. The CBOR format should be used instead. Fixes: QTBUG-47629 Change-Id: Ic8b92ea36de87815b12307a9d8b1095f07166db8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qjsonvalue.h')
-rw-r--r--src/corelib/serialization/qjsonvalue.h54
1 files changed, 18 insertions, 36 deletions
diff --git a/src/corelib/serialization/qjsonvalue.h b/src/corelib/serialization/qjsonvalue.h
index 8ade18509b..5adcd64176 100644
--- a/src/corelib/serialization/qjsonvalue.h
+++ b/src/corelib/serialization/qjsonvalue.h
@@ -42,22 +42,18 @@
#include <QtCore/qglobal.h>
#include <QtCore/qstring.h>
+#include <QtCore/qshareddata.h>
+#include <QtCore/qcborvalue.h>
QT_BEGIN_NAMESPACE
-class QDebug;
class QVariant;
class QJsonArray;
class QJsonObject;
+class QCborContainerPrivate;
namespace QJsonPrivate {
- class Data;
- class Base;
- class Object;
- class Header;
- class Array;
- class Value;
- class Entry;
+class Value;
}
class Q_CORE_EXPORT QJsonValue
@@ -77,12 +73,12 @@ public:
QJsonValue(bool b);
QJsonValue(double n);
QJsonValue(int n);
- QJsonValue(qint64 n);
+ QJsonValue(qint64 v);
QJsonValue(const QString &s);
QJsonValue(QLatin1String s);
#ifndef QT_NO_CAST_FROM_ASCII
inline QT_ASCII_CAST_WARN QJsonValue(const char *s)
- : d(nullptr), t(String) { stringDataFromQStringHelper(QString::fromUtf8(s)); }
+ : QJsonValue(QString::fromUtf8(s)) {}
#endif
QJsonValue(const QJsonArray &a);
QJsonValue(const QJsonObject &o);
@@ -92,15 +88,7 @@ public:
QJsonValue(const QJsonValue &other);
QJsonValue &operator =(const QJsonValue &other);
- QJsonValue(QJsonValue &&other) noexcept
- : ui(other.ui),
- d(other.d),
- t(other.t)
- {
- other.ui = 0;
- other.d = nullptr;
- other.t = Null;
- }
+ QJsonValue(QJsonValue &&other) noexcept;
QJsonValue &operator =(QJsonValue &&other) noexcept
{
@@ -108,12 +96,7 @@ public:
return *this;
}
- void swap(QJsonValue &other) noexcept
- {
- qSwap(ui, other.ui);
- qSwap(d, other.d);
- qSwap(t, other.t);
- }
+ void swap(QJsonValue &other) noexcept;
static QJsonValue fromVariant(const QVariant &variant);
QVariant toVariant() const;
@@ -149,7 +132,7 @@ public:
private:
// avoid implicit conversions from char * to bool
- inline QJsonValue(const void *) {}
+ QJsonValue(const void *) = delete;
friend class QJsonPrivate::Value;
friend class QJsonArray;
friend class QJsonObject;
@@ -157,20 +140,19 @@ private:
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonValue &);
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QJsonValue &);
- QJsonValue(QJsonPrivate::Data *d, QJsonPrivate::Base *b, const QJsonPrivate::Value& v);
+ // ### Qt6: Remove this.
void stringDataFromQStringHelper(const QString &string);
void detach();
- union {
- quint64 ui;
- bool b;
- double dbl;
- QStringData *stringData;
- QJsonPrivate::Base *base;
- };
- QJsonPrivate::Data *d; // needed for Objects and Arrays
- Type t;
+ // ### Qt6: change to an actual QCborValue
+ qint64 n = 0;
+ QExplicitlySharedDataPointer<QCborContainerPrivate> d; // needed for Objects, Arrays, Strings
+ QCborValue::Type t;
+
+ // Assert binary compatibility with pre-5.15 QJsonValue
+ Q_STATIC_ASSERT(sizeof(QExplicitlySharedDataPointer<QCborContainerPrivate>) == sizeof(void *));
+ Q_STATIC_ASSERT(sizeof(QCborValue::Type) == sizeof(QJsonValue::Type));
};
class Q_CORE_EXPORT QJsonValueRef