28 #include "qtprotobufglobal.h"
33 #include <unordered_map>
36 #include <type_traits>
38 namespace QtProtobuf {
58 struct PropertyOrderingInfo {
59 PropertyOrderingInfo(
int _qtProperty,
const QString &_jsonName) : qtProperty(_qtProperty)
60 , jsonName(_jsonName) {}
65 typename std::enable_if_t<std::is_integral<T>::value,
int> = 0>
66 operator T()
const {
return qtProperty; }
67 operator QString()
const {
return jsonName; }
70 typename std::enable_if_t<std::is_integral<T>::value,
int> = 0>
71 bool operator==(
const T _qtProperty)
const {
return _qtProperty == qtProperty; }
72 bool operator==(
const QString &_jsonName)
const {
return _jsonName == jsonName; }
77 using QProtobufPropertyOrdering = std::unordered_map<int, PropertyOrderingInfo>;
84 template<
typename T,
int = 0>
86 transparent(T t = T()) : _t(t) {}
88 operator T &() {
return _t; }
89 operator T()
const {
return _t; }
90 transparent &operator =(
const T &t) { _t = t;
return *
this; }
92 static T toType(transparent t) {
return t._t; }
93 static transparent fromType(T _t) {
return transparent(_t); }
95 static QString toString(transparent t) {
return QString::number(t._t); }
112 using int64 = transparent<int64_t>;
264 using RegisterFunction = std::function<void(
void)>;
267 Q_PROTOBUF_EXPORT std::list<RegisterFunction>& registerFunctions();
270 template <
typename T>
271 struct ProtoTypeRegistrar {
272 ProtoTypeRegistrar(RegisterFunction initializer) {
273 registerFunctions().push_back(initializer);
280 Q_DECLARE_METATYPE(QtProtobuf::int64)
307 struct make_unsigned<QtProtobuf::
int32> {
typedef typename make_unsigned<decltype(QtProtobuf::int32::_t)>::type type; };
310 struct make_unsigned<QtProtobuf::int64> {
typedef typename make_unsigned<decltype(QtProtobuf::int64::_t)>::type type; };
313 struct make_unsigned<QtProtobuf::
fixed32> {
typedef typename make_unsigned<decltype(QtProtobuf::fixed32::_t)>::type type; };
316 struct make_unsigned<QtProtobuf::
fixed64> {
typedef typename make_unsigned<decltype(QtProtobuf::fixed64::_t)>::type type; };
319 struct make_unsigned<QtProtobuf::
sfixed32> {
typedef typename make_unsigned<decltype(QtProtobuf::sfixed32::_t)>::type type; };
322 struct make_unsigned<QtProtobuf::
sfixed64> {
typedef typename make_unsigned<decltype(QtProtobuf::sfixed64::_t)>::type type; };
326 struct make_signed<QtProtobuf::
int32> {
typedef typename make_signed<decltype(QtProtobuf::int32::_t)>::type type; };
329 struct make_signed<QtProtobuf::int64> {
typedef typename make_signed<decltype(QtProtobuf::int64::_t)>::type type; };
332 struct make_signed<QtProtobuf::
fixed32> {
typedef typename make_signed<decltype(QtProtobuf::fixed32::_t)>::type type; };
335 struct make_signed<QtProtobuf::
fixed64> {
typedef typename make_signed<decltype(QtProtobuf::fixed64::_t)>::type type; };
338 struct make_signed<QtProtobuf::
sfixed32> {
typedef typename make_signed<decltype(QtProtobuf::sfixed32::_t)>::type type; };
341 struct make_signed<QtProtobuf::
sfixed64> {
typedef typename make_signed<decltype(QtProtobuf::sfixed64::_t)>::type type; };
345 struct is_signed<QtProtobuf::
int32> :
public is_signed<decltype(QtProtobuf::int32::_t)> {};
348 struct is_signed<QtProtobuf::int64> :
public is_signed<decltype(QtProtobuf::int64::_t)> {};
351 struct is_signed<QtProtobuf::
fixed32> :
public is_signed<decltype(QtProtobuf::fixed32::_t)> {};
354 struct is_signed<QtProtobuf::
fixed64> :
public is_signed<decltype(QtProtobuf::fixed64::_t)> {};
357 struct is_signed<QtProtobuf::
sfixed32> :
public is_signed<decltype(QtProtobuf::sfixed32::_t)> {};
360 struct is_signed<QtProtobuf::
sfixed64> :
public is_signed<decltype(QtProtobuf::sfixed64::_t)> {};
362 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
363 template<>
struct hash<QString> {
364 std::size_t operator()(
const QString &s)
const {
365 return std::hash<std::string>()(s.toStdString());
QList< double > DoubleList
alias for list of QtProtobuf::double
Definition: qtprotobuftypes.h:252
QList< sint64 > sint64List
alias for list of QtProtobuf::sint64
Definition: qtprotobuftypes.h:216
transparent< uint32_t, 1 > fixed32
fixed32 unsigned 32-bit fixed size integer
Definition: qtprotobuftypes.h:156
void qRegisterProtobufTypes()
qRegisterProtobufTypes This method should be called in all applications that supposed to use QtProtob...
Definition: qtprotobuf.cpp:62
uint64_t uint64
uint64 unsigned 64-bit integer
Definition: qtprotobuftypes.h:128
WireTypes
The WireTypes enumeration reflects protobuf default wiretypes.
Definition: qtprotobuftypes.h:47
transparent< int32_t > int32
int32 signed 32-bit integer
Definition: qtprotobuftypes.h:104
transparent< uint64_t, 1 > fixed64
fixed64 unsigned 64-bit fixed size integer
Definition: qtprotobuftypes.h:164
QList< sfixed32 > sfixed32List
alias for list of QtProtobuf::sfixed32
Definition: qtprotobuftypes.h:234
transparent< int64_t, 1 > sfixed64
fixed64 signed 64-bit fixed size integer
Definition: qtprotobuftypes.h:180
QList< fixed32 > fixed32List
alias for list of QtProtobuf::fixed32
Definition: qtprotobuftypes.h:222
QList< float > FloatList
alias for list of QtProtobuf::float
Definition: qtprotobuftypes.h:246
QList< sint32 > sint32List
alias for list of QtProtobuf::sint32
Definition: qtprotobuftypes.h:210
int64_t sint64
sint64 signed 64-bit ZigZag integer
Definition: qtprotobuftypes.h:148
QList< int64 > int64List
alias for list of QtProtobuf::int64
Definition: qtprotobuftypes.h:192
transparent< int32_t, 1 > sfixed32
fixed32 signed 32-bit fixed size integer
Definition: qtprotobuftypes.h:172
QList< fixed64 > fixed64List
alias for list of QtProtobuf::fixed64
Definition: qtprotobuftypes.h:228
QList< int32 > int32List
alias for list of QtProtobuf::int32
Definition: qtprotobuftypes.h:186
QList< uint64 > uint64List
alias for list of QtProtobuf::uint64
Definition: qtprotobuftypes.h:204
QList< sfixed64 > sfixed64List
alias for list of QtProtobuf::sfixed64
Definition: qtprotobuftypes.h:240
QList< uint32 > uint32List
alias for list of QtProtobuf::uint32
Definition: qtprotobuftypes.h:198
int32_t sint32
sint32 signed 32-bit ZigZag integer
Definition: qtprotobuftypes.h:138
uint32_t uint32
uint32 unsigned 32-bit integer
Definition: qtprotobuftypes.h:120
@ StartGroup
groups
Definition: qtprotobuftypes.h:52
@ UnknownWireType
Invalid wire type.
Definition: qtprotobuftypes.h:48
@ Varint
int32, int64, uint32, uint64, sint32, sint64, bool, enum
Definition: qtprotobuftypes.h:49
@ Fixed32
fixed32, sfixed32, float
Definition: qtprotobuftypes.h:54
@ Fixed64
fixed64, sfixed64, double
Definition: qtprotobuftypes.h:50
@ LengthDelimited
string, bytes, embedded messages, packed repeated fields
Definition: qtprotobuftypes.h:51
@ EndGroup
groups
Definition: qtprotobuftypes.h:53