// Copyright (C) 2022 The Qt Company Ltd. // Copyright (C) 2019 Alexey Edelev // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QTPROTOBUFTYPES_H #define QTPROTOBUFTYPES_H #include #include #include #include #include #include #include #include QT_BEGIN_NAMESPACE namespace QtProtobuf { Q_NAMESPACE_EXPORT(Q_PROTOBUF_EXPORT) [[maybe_unused]] constexpr int InvalidFieldNumber = 0; enum class WireTypes { Unknown = -1, Varint = 0, Fixed64 = 1, LengthDelimited = 2, StartGroup = 3, EndGroup = 4, Fixed32 = 5 }; Q_ENUM_NS(WireTypes) // The 'tag' template param exists only create a unique type template struct TransparentWrapper { TransparentWrapper(T t_ = T()) : t(t_) { } T t; operator T &() { return t; } operator T() const { return t; } TransparentWrapper &operator=(T t_) { t = t_; return *this; } static T toType(TransparentWrapper t) { return t.t; } static TransparentWrapper fromType(T t) { return TransparentWrapper(t); } static QString toString(TransparentWrapper t) { return QString::number(t.t); } private: friend constexpr TransparentWrapper qbswap(TransparentWrapper source) { return { QT_PREPEND_NAMESPACE(qbswap)(source.t) }; } friend size_t qHash(TransparentWrapper key, size_t seed = 0) noexcept { return QT_PREPEND_NAMESPACE(qHash)(seed, key.t); } }; using int32 = TransparentWrapper; using int64 = TransparentWrapper; using uint32 = uint32_t; using uint64 = uint64_t; using sint32 = int32_t; using sint64 = int64_t; using fixed32 = TransparentWrapper; using fixed64 = TransparentWrapper; using sfixed32 = TransparentWrapper; using sfixed64 = TransparentWrapper; using boolean = bool; using int32List = QList; using int64List = QList; using uint32List = QList; using uint64List = QList; using sint32List = QList; using sint64List = QList; using fixed32List = QList; using fixed64List = QList; using sfixed32List = QList; using sfixed64List = QList; using floatList = QList; using doubleList = QList; using boolList = QList; template using HasProtobufStaticPropertyOrdering = decltype(T::staticPropertyOrdering); template using has_q_protobuf_object_macro = qxp::is_detected; template constexpr bool has_q_protobuf_object_macro_v = has_q_protobuf_object_macro::value; template inline constexpr bool IsProtobufScalarValueType = false; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template <> constexpr inline bool IsProtobufScalarValueType = true; template using is_protobuf_scalar_value_type = std::bool_constant>; template using is_protobuf_message = std::conjunction>, std::is_base_of, has_q_protobuf_object_macro>; template using if_protobuf_message = std::enable_if_t::value, bool>; template using is_protobuf_non_message = std::disjunction, QtProtobuf::is_protobuf_scalar_value_type>; template using if_protobuf_non_message = std::enable_if_t::value, bool>; template using is_protobuf_type = std::disjunction, is_protobuf_non_message>; template using if_protobuf_type = std::enable_if_t::value, bool>; template using is_protobuf_message_without_ordering = std::conjunction< std::negation>, std::is_base_of, std::negation>>; template using if_protobuf_message_without_ordering = std::enable_if_t< is_protobuf_message_without_ordering::value, bool>; template inline constexpr bool IsProtobufMapKeyType = false; template <> constexpr inline bool IsProtobufMapKeyType = true; template <> constexpr inline bool IsProtobufMapKeyType = true; template <> constexpr inline bool IsProtobufMapKeyType = true; template <> constexpr inline bool IsProtobufMapKeyType = true; template <> constexpr inline bool IsProtobufMapKeyType = true; template <> constexpr inline bool IsProtobufMapKeyType = true; template <> constexpr inline bool IsProtobufMapKeyType = true; template <> constexpr inline bool IsProtobufMapKeyType = true; template <> constexpr inline bool IsProtobufMapKeyType = true; template <> constexpr inline bool IsProtobufMapKeyType = true; template <> constexpr inline bool IsProtobufMapKeyType = true; template <> constexpr inline bool IsProtobufMapKeyType = true; template using is_protobuf_map_key = std::bool_constant>; template using if_protobuf_map_key = std::enable_if_t::value, bool>; template using if_protobuf_map = std::enable_if_t, QtProtobuf::is_protobuf_type>, bool>; } // namespace QtProtobuf QT_END_NAMESPACE Q_DECLARE_METATYPE(QtProtobuf::int32) Q_DECLARE_METATYPE(QtProtobuf::int64) Q_DECLARE_METATYPE(QtProtobuf::fixed32) Q_DECLARE_METATYPE(QtProtobuf::fixed64) Q_DECLARE_METATYPE(QtProtobuf::sfixed32) Q_DECLARE_METATYPE(QtProtobuf::sfixed64) #endif // QTPROTOBUFTYPES_H