#ifndef QTJSONSERIALIZER_HELPERTYPES_H #define QTJSONSERIALIZER_HELPERTYPES_H #include #include #include #include #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace QtJsonSerializer::__private { template struct gadget_helper { static constexpr bool value = false; static inline QJsonValue convert(const QJsonValue &jsonValue) { return jsonValue; } }; template struct gadget_helper { static constexpr bool value = true; static inline QJsonObject convert(const QJsonValue &jsonValue) { return jsonValue.toObject(); } }; template struct is_serializable : public std::negation> {}; template struct is_serializable : public std::disjunction, gadget_helper> {}; template struct is_serializable> : public std::is_base_of {}; template struct is_serializable> : public std::is_base_of {}; template struct is_serializable> : public is_serializable {}; #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) template struct is_serializable> : public is_serializable {}; #endif #if !defined(QT_NO_LINKED_LIST) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) template struct is_serializable> : public is_serializable {}; #endif template struct is_serializable> : public is_serializable {}; template struct is_serializable> : public is_serializable {}; template struct is_serializable> : public std::conjunction, is_serializable> {}; template struct is_serializable> : public std::conjunction, is_serializable> {}; template struct is_serializable> : public std::conjunction, is_serializable> {}; template struct is_serializable> : public std::conjunction, is_serializable> {}; #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) template struct is_serializable> : public std::conjunction, is_serializable> {}; #endif template struct is_serializable> : public std::conjunction, is_serializable> {}; template struct is_serializable> : public std::conjunction...> {}; template struct is_serializable> : public is_serializable {}; template struct is_serializable> : public std::conjunction...> {}; template struct json_type_raw : public std::conditional::value, QJsonObject, QJsonValue> {}; template struct json_type : public json_type_raw { static_assert(is_serializable::value, "Type T must be serializable to be used in a generic expression"); static inline typename json_type_raw::type convert(const QJsonValue &jsonValue) { return gadget_helper::convert(jsonValue); } }; template struct json_type { static_assert(is_serializable::value, "Only QObject deriving classes or gadget pointers can be serialized as pointer"); using type = QJsonObject; using cborType = QCborMap; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toObject(); } }; template struct json_type> { static_assert(is_serializable>::value, "Only QObject deriving classes can be serialized as shared pointer"); using type = QJsonObject; using cborType = QCborMap; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toObject(); } }; template struct json_type> { static_assert(is_serializable>::value, "Only QObject deriving classes can be serialized as QPointer"); using type = QJsonObject; using cborType = QCborMap; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toObject(); } }; template struct json_type> { static_assert(is_serializable>::value, "The value type of a QList must be serializable for it to also be serializable"); using type = QJsonArray; using cborType = QCborArray; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toArray(); } }; #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) template struct json_type> { static_assert(is_serializable>::value, "The value type of a QVector must be serializable for it to also be serializable"); using type = QJsonArray; using cborType = QCborArray; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toArray(); } }; #endif #if !defined(QT_NO_LINKED_LIST) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) template struct json_type> { static_assert(is_serializable>::value, "The value type of a QLinkedList must be serializable for it to also be serializable"); using type = QJsonArray; using cborType = QCborArray; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toArray(); } }; #endif template struct json_type> { static_assert(is_serializable>::value, "The value type of a QStack must be serializable for it to also be serializable"); using type = QJsonArray; using cborType = QCborArray; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toArray(); } }; template struct json_type> { static_assert(is_serializable>::value, "The value type of a QQueue must be serializable for it to also be serializable"); using type = QJsonArray; using cborType = QCborArray; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toArray(); } }; template struct json_type> { static_assert(is_serializable>::value, "The key and value types of a QMap must be serializable for it to also be serializable"); using type = QJsonObject; using cborType = QCborMap; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toObject(); } }; template struct json_type> { static_assert(is_serializable>::value, "The key and value types of a QMultiMap must be serializable for it to also be serializable"); using type = QJsonObject; using cborType = QCborMap; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toObject(); } }; template struct json_type> { static_assert(is_serializable>::value, "The key and value types of a QHash must be serializable for it to also be serializable"); using type = QJsonObject; using cborType = QCborMap; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toObject(); } }; template struct json_type> { static_assert(is_serializable>::value, "The key and value types of a QMultiHash must be serializable for it to also be serializable"); using type = QJsonObject; using cborType = QCborMap; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toObject(); } }; #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) template struct json_type> { static_assert(is_serializable>::value, "All elements of a QPair must be serializable for it to also be serializable"); using type = QJsonArray; using cborType = QCborArray; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toArray(); } }; #endif template struct json_type> { static_assert(is_serializable>::value, "All elements of a std::pair must be serializable for it to also be serializable"); using type = QJsonArray; using cborType = QCborArray; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toArray(); } }; template struct json_type> { static_assert(is_serializable>::value, "All elements of a std::tuple must be serializable for it to also be serializable"); using type = QJsonArray; using cborType = QCborArray; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toArray(); } }; template struct json_type> { static_assert(is_serializable>::value, "All elements of a std::variant must be serializable for it to also be serializable"); using type = QJsonArray; using cborType = QCborArray; static inline type convert(const QJsonValue &jsonValue) { return jsonValue.toArray(); } }; template struct variant_helper { static inline QVariant toVariant(const T &data) { return QVariant::fromValue(data); } static inline T fromVariant(const QVariant &data) { return data.template value(); } }; template <> struct variant_helper { static inline QVariant toVariant(const QVariant &data) { return data; } static inline QVariant fromVariant(const QVariant &data) { return data; } }; } #endif // QTJSONSERIALIZER_HELPERTYPES_H