Browse Source

Move type-traits specications to types declaration

Alexey Edelev 5 years ago
parent
commit
9201791d4e
3 changed files with 47 additions and 17 deletions
  1. 4 13
      src/protobuf/qprotobufobject_p.h
  2. 4 4
      src/protobuf/qtprotobuf.cpp
  3. 39 0
      src/protobuf/qtprotobuftypes.h

+ 4 - 13
src/protobuf/qprotobufobject_p.h

@@ -46,15 +46,6 @@
 
 namespace qtprotobuf {
 
-template<typename V>
-struct make_unsigned { typedef typename std::make_unsigned<V>::type type; };
-
-template<>
-struct make_unsigned<int32> { typedef typename std::make_unsigned<decltype(int32::_t)>::type type; };
-
-template<>
-struct make_unsigned<int64> { typedef typename std::make_unsigned<decltype(int64::_t)>::type type; };
-
 class QTPROTOBUFSHARED_EXPORT ProtobufObjectPrivate
 {
     ProtobufObjectPrivate() = delete;
@@ -222,7 +213,7 @@ public:
                                         && std::is_signed<V>::value, int> = 0>
     static QByteArray serializeBasic(const V &value, int &outFieldIndex) {
         qProtoDebug() << __func__ << "value" << value;
-        using UV = typename qtprotobuf::make_unsigned<V>::type;
+        using UV = typename std::make_unsigned<V>::type;
         UV uValue = 0;
 
         //Use ZigZag convertion first and apply unsigned variant next
@@ -236,7 +227,7 @@ public:
                                         || std::is_same<V, int64>::value, int> = 0>
     static QByteArray serializeBasic(const V &value, int &outFieldIndex) {
         qProtoDebug() << __func__ << "value" << value;
-        using UV = typename qtprotobuf::make_unsigned<V>::type;
+        using UV = typename std::make_unsigned<V>::type;
         return serializeBasic(static_cast<UV>(value), outFieldIndex);
     }
 
@@ -485,7 +476,7 @@ public:
                                         && std::is_signed<V>::value,int> = 0>
     static QVariant deserializeBasic(SelfcheckIterator &it) {
         qProtoDebug() << __func__ << "currentByte:" << QString::number((*it), 16);
-        using  UV = typename qtprotobuf::make_unsigned<V>::type;
+        using  UV = typename std::make_unsigned<V>::type;
         UV unsignedValue = deserializeVarintCommon<UV>(it);
         V value = (unsignedValue >> 1) ^ (-1 * (unsignedValue & 1));
         return QVariant::fromValue<V>(value);
@@ -496,7 +487,7 @@ public:
                                         || std::is_same<int64, V>::value, int> = 0>
     static QVariant deserializeBasic(SelfcheckIterator &it) {
         qProtoDebug() << __func__ << "currentByte:" << QString::number((*it), 16);
-        using  UV = typename qtprotobuf::make_unsigned<V>::type;
+        using  UV = typename std::make_unsigned<V>::type;
         UV unsignedValue = deserializeVarintCommon<UV>(it);
         V value = static_cast<V>(unsignedValue);
         return QVariant::fromValue(value);

+ 4 - 4
src/protobuf/qtprotobuf.cpp

@@ -37,7 +37,7 @@ namespace qtprotobuf {
 namespace  {
 
 template<typename T, typename std::enable_if_t<sizeof(T) == sizeof(int32_t)
-                                      && std::is_signed<decltype(T::_t)>::value, int> = 0>
+                                      && std::is_signed<T>::value, int> = 0>
 void registerBasicConverters() {
     QMetaType::registerConverter<int32_t, T>(T::fromType);
     QMetaType::registerConverter<T, int32_t>(T::toType);
@@ -47,7 +47,7 @@ void registerBasicConverters() {
 }
 
 template<typename T, typename std::enable_if_t<sizeof(T) == sizeof(int64_t)
-                                      && std::is_signed<decltype(T::_t)>::value, int> = 0>
+                                      && std::is_signed<T>::value, int> = 0>
 void registerBasicConverters() {
     QMetaType::registerConverter<int64_t, T>(T::fromType);
     QMetaType::registerConverter<T, int64_t>(T::toType);
@@ -58,7 +58,7 @@ void registerBasicConverters() {
 }
 
 template<typename T, typename std::enable_if_t<sizeof(T) == sizeof(int32_t)
-                                      && !std::is_signed<decltype(T::_t)>::value, int> = 0>
+                                      && !std::is_signed<T>::value, int> = 0>
 void registerBasicConverters() {
     QMetaType::registerConverter<uint32_t, T>(T::fromType);
     QMetaType::registerConverter<T, uint32_t>(T::toType);
@@ -70,7 +70,7 @@ void registerBasicConverters() {
 }
 
 template<typename T, typename std::enable_if_t<sizeof(T) == sizeof(int64_t)
-                                      && !std::is_signed<decltype(T::_t)>::value, int> = 0>
+                                      && !std::is_signed<T>::value, int> = 0>
 void registerBasicConverters() {
     QMetaType::registerConverter<uint64_t, T>(T::fromType);
     QMetaType::registerConverter<T, uint64_t>(T::toType);

+ 39 - 0
src/protobuf/qtprotobuftypes.h

@@ -105,3 +105,42 @@ Q_DECLARE_METATYPE(qtprotobuf::sfixed64List)
 
 Q_DECLARE_METATYPE(qtprotobuf::FloatList)
 Q_DECLARE_METATYPE(qtprotobuf::DoubleList)
+
+template<>
+struct std::make_unsigned<qtprotobuf::int32> { typedef typename std::make_unsigned<decltype(qtprotobuf::int32::_t)>::type type; };
+template<>
+struct std::make_unsigned<qtprotobuf::int64> { typedef typename std::make_unsigned<decltype(qtprotobuf::int64::_t)>::type type; };
+template<>
+struct std::make_unsigned<qtprotobuf::fixed32> { typedef typename std::make_unsigned<decltype(qtprotobuf::fixed32::_t)>::type type; };
+template<>
+struct std::make_unsigned<qtprotobuf::fixed64> { typedef typename std::make_unsigned<decltype(qtprotobuf::fixed64::_t)>::type type; };
+template<>
+struct std::make_unsigned<qtprotobuf::sfixed32> { typedef typename std::make_unsigned<decltype(qtprotobuf::sfixed32::_t)>::type type; };
+template<>
+struct std::make_unsigned<qtprotobuf::sfixed64> { typedef typename std::make_unsigned<decltype(qtprotobuf::sfixed64::_t)>::type type; };
+
+template<>
+struct std::make_signed<qtprotobuf::int32> { typedef typename std::make_signed<decltype(qtprotobuf::int32::_t)>::type type; };
+template<>
+struct std::make_signed<qtprotobuf::int64> { typedef typename std::make_signed<decltype(qtprotobuf::int64::_t)>::type type; };
+template<>
+struct std::make_signed<qtprotobuf::fixed32> { typedef typename std::make_signed<decltype(qtprotobuf::fixed32::_t)>::type type; };
+template<>
+struct std::make_signed<qtprotobuf::fixed64> { typedef typename std::make_signed<decltype(qtprotobuf::fixed64::_t)>::type type; };
+template<>
+struct std::make_signed<qtprotobuf::sfixed32> { typedef typename std::make_signed<decltype(qtprotobuf::sfixed32::_t)>::type type; };
+template<>
+struct std::make_signed<qtprotobuf::sfixed64> { typedef typename std::make_signed<decltype(qtprotobuf::sfixed64::_t)>::type type; };
+
+template<>
+struct std::is_signed<qtprotobuf::int32> : public is_signed<decltype(qtprotobuf::int32::_t)> {};
+template<>
+struct std::is_signed<qtprotobuf::int64> : public is_signed<decltype(qtprotobuf::int64::_t)> {};
+template<>
+struct std::is_signed<qtprotobuf::fixed32> : public is_signed<decltype(qtprotobuf::fixed32::_t)> {};
+template<>
+struct std::is_signed<qtprotobuf::fixed64> : public is_signed<decltype(qtprotobuf::fixed64::_t)> {};
+template<>
+struct std::is_signed<qtprotobuf::sfixed32> : public is_signed<decltype(qtprotobuf::sfixed32::_t)> {};
+template<>
+struct std::is_signed<qtprotobuf::sfixed64> : public is_signed<decltype(qtprotobuf::sfixed64::_t)> {};