| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 static const RepeatedFieldType* GetDefaultRepeatedField(); | 724 static const RepeatedFieldType* GetDefaultRepeatedField(); |
| 725 }; | 725 }; |
| 726 | 726 |
| 727 LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_primitive_generic_type_trait
s_once_init_; | 727 LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_primitive_generic_type_trait
s_once_init_; |
| 728 | 728 |
| 729 class LIBPROTOBUF_EXPORT RepeatedPrimitiveGenericTypeTraits { | 729 class LIBPROTOBUF_EXPORT RepeatedPrimitiveGenericTypeTraits { |
| 730 private: | 730 private: |
| 731 template<typename Type> friend class RepeatedPrimitiveTypeTraits; | 731 template<typename Type> friend class RepeatedPrimitiveTypeTraits; |
| 732 static void InitializeDefaultRepeatedFields(); | 732 static void InitializeDefaultRepeatedFields(); |
| 733 static void DestroyDefaultRepeatedFields(); | 733 static void DestroyDefaultRepeatedFields(); |
| 734 static const RepeatedField<int32>* cr_default_repeated_field_int32_; | 734 static const RepeatedField<int32>* default_repeated_field_int32_; |
| 735 static const RepeatedField<int64>* cr_default_repeated_field_int64_; | 735 static const RepeatedField<int64>* default_repeated_field_int64_; |
| 736 static const RepeatedField<uint32>* cr_default_repeated_field_uint32_; | 736 static const RepeatedField<uint32>* default_repeated_field_uint32_; |
| 737 static const RepeatedField<uint64>* cr_default_repeated_field_uint64_; | 737 static const RepeatedField<uint64>* default_repeated_field_uint64_; |
| 738 static const RepeatedField<double>* cr_default_repeated_field_double_; | 738 static const RepeatedField<double>* default_repeated_field_double_; |
| 739 static const RepeatedField<float>* cr_default_repeated_field_float_; | 739 static const RepeatedField<float>* default_repeated_field_float_; |
| 740 static const RepeatedField<bool>* cr_default_repeated_field_bool_; | 740 static const RepeatedField<bool>* default_repeated_field_bool_; |
| 741 }; | 741 }; |
| 742 | 742 |
| 743 #define PROTOBUF_DEFINE_PRIMITIVE_TYPE(TYPE, METHOD) \ | 743 #define PROTOBUF_DEFINE_PRIMITIVE_TYPE(TYPE, METHOD) \ |
| 744 template<> inline TYPE PrimitiveTypeTraits<TYPE>::Get( \ | 744 template<> inline TYPE PrimitiveTypeTraits<TYPE>::Get( \ |
| 745 int number, const ExtensionSet& set, TYPE default_value) { \ | 745 int number, const ExtensionSet& set, TYPE default_value) { \ |
| 746 return set.Get##METHOD(number, default_value); \ | 746 return set.Get##METHOD(number, default_value); \ |
| 747 } \ | 747 } \ |
| 748 template<> inline void PrimitiveTypeTraits<TYPE>::Set( \ | 748 template<> inline void PrimitiveTypeTraits<TYPE>::Set( \ |
| 749 int number, FieldType field_type, TYPE value, ExtensionSet* set) { \ | 749 int number, FieldType field_type, TYPE value, ExtensionSet* set) { \ |
| 750 set->Set##METHOD(number, field_type, value, NULL); \ | 750 set->Set##METHOD(number, field_type, value, NULL); \ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 762 int number, FieldType field_type, bool is_packed, \ | 762 int number, FieldType field_type, bool is_packed, \ |
| 763 TYPE value, ExtensionSet* set) { \ | 763 TYPE value, ExtensionSet* set) { \ |
| 764 set->Add##METHOD(number, field_type, is_packed, value, NULL); \ | 764 set->Add##METHOD(number, field_type, is_packed, value, NULL); \ |
| 765 } \ | 765 } \ |
| 766 template<> inline const RepeatedField<TYPE>* \ | 766 template<> inline const RepeatedField<TYPE>* \ |
| 767 RepeatedPrimitiveTypeTraits<TYPE>::GetDefaultRepeatedField() { \ | 767 RepeatedPrimitiveTypeTraits<TYPE>::GetDefaultRepeatedField() { \ |
| 768 ::google::protobuf::GoogleOnceInit(
\ | 768 ::google::protobuf::GoogleOnceInit(
\ |
| 769 &repeated_primitive_generic_type_traits_once_init_, \ | 769 &repeated_primitive_generic_type_traits_once_init_, \ |
| 770 &RepeatedPrimitiveGenericTypeTraits::InitializeDefaultRepeatedFields); \ | 770 &RepeatedPrimitiveGenericTypeTraits::InitializeDefaultRepeatedFields); \ |
| 771 return RepeatedPrimitiveGenericTypeTraits:: \ | 771 return RepeatedPrimitiveGenericTypeTraits:: \ |
| 772 cr_default_repeated_field_##TYPE##_; \ | 772 default_repeated_field_##TYPE##_; \ |
| 773 } \ | 773 } \ |
| 774 template<> inline const RepeatedField<TYPE>& \ | 774 template<> inline const RepeatedField<TYPE>& \ |
| 775 RepeatedPrimitiveTypeTraits<TYPE>::GetRepeated(int number, \ | 775 RepeatedPrimitiveTypeTraits<TYPE>::GetRepeated(int number, \ |
| 776 const ExtensionSet& set) { \ | 776 const ExtensionSet& set) { \ |
| 777 return *reinterpret_cast<const RepeatedField<TYPE>*>( \ | 777 return *reinterpret_cast<const RepeatedField<TYPE>*>( \ |
| 778 set.GetRawRepeatedField( \ | 778 set.GetRawRepeatedField( \ |
| 779 number, GetDefaultRepeatedField())); \ | 779 number, GetDefaultRepeatedField())); \ |
| 780 } \ | 780 } \ |
| 781 template<> inline RepeatedField<TYPE>* \ | 781 template<> inline RepeatedField<TYPE>* \ |
| 782 RepeatedPrimitiveTypeTraits<TYPE>::MutableRepeated(int number, \ | 782 RepeatedPrimitiveTypeTraits<TYPE>::MutableRepeated(int number, \ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 static inline void Set(int number, FieldType field_type, | 814 static inline void Set(int number, FieldType field_type, |
| 815 const string& value, ExtensionSet* set) { | 815 const string& value, ExtensionSet* set) { |
| 816 set->SetString(number, field_type, value, NULL); | 816 set->SetString(number, field_type, value, NULL); |
| 817 } | 817 } |
| 818 static inline string* Mutable(int number, FieldType field_type, | 818 static inline string* Mutable(int number, FieldType field_type, |
| 819 ExtensionSet* set) { | 819 ExtensionSet* set) { |
| 820 return set->MutableString(number, field_type, NULL); | 820 return set->MutableString(number, field_type, NULL); |
| 821 } | 821 } |
| 822 }; | 822 }; |
| 823 | 823 |
| 824 LIBPROTOBUF_EXPORT extern ProtobufOnceType | 824 LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_string_type_traits_once_init
_; |
| 825 cr_repeated_string_type_traits_once_init_; | |
| 826 | 825 |
| 827 class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { | 826 class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { |
| 828 public: | 827 public: |
| 829 typedef const string& ConstType; | 828 typedef const string& ConstType; |
| 830 typedef string* MutableType; | 829 typedef string* MutableType; |
| 831 typedef RepeatedStringTypeTraits Repeated; | 830 typedef RepeatedStringTypeTraits Repeated; |
| 832 | 831 |
| 833 typedef RepeatedPtrField<string> RepeatedFieldType; | 832 typedef RepeatedPtrField<string> RepeatedFieldType; |
| 834 | 833 |
| 835 static inline const string& Get(int number, const ExtensionSet& set, | 834 static inline const string& Get(int number, const ExtensionSet& set, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 860 | 859 |
| 861 static inline RepeatedPtrField<string>* | 860 static inline RepeatedPtrField<string>* |
| 862 MutableRepeated(int number, FieldType field_type, | 861 MutableRepeated(int number, FieldType field_type, |
| 863 bool is_packed, ExtensionSet* set) { | 862 bool is_packed, ExtensionSet* set) { |
| 864 return reinterpret_cast<RepeatedPtrField<string>*>( | 863 return reinterpret_cast<RepeatedPtrField<string>*>( |
| 865 set->MutableRawRepeatedField(number, field_type, | 864 set->MutableRawRepeatedField(number, field_type, |
| 866 is_packed, NULL)); | 865 is_packed, NULL)); |
| 867 } | 866 } |
| 868 | 867 |
| 869 static const RepeatedFieldType* GetDefaultRepeatedField() { | 868 static const RepeatedFieldType* GetDefaultRepeatedField() { |
| 870 ::google::protobuf::GoogleOnceInit( | 869 ::google::protobuf::GoogleOnceInit(&repeated_string_type_traits_once_init_, |
| 871 &cr_repeated_string_type_traits_once_init_, | 870 &InitializeDefaultRepeatedFields); |
| 872 &InitializeDefaultRepeatedFields); | 871 return default_repeated_field_; |
| 873 return cr_default_repeated_field_; | |
| 874 } | 872 } |
| 875 | 873 |
| 876 private: | 874 private: |
| 877 static void InitializeDefaultRepeatedFields(); | 875 static void InitializeDefaultRepeatedFields(); |
| 878 static void DestroyDefaultRepeatedFields(); | 876 static void DestroyDefaultRepeatedFields(); |
| 879 static const RepeatedFieldType* cr_default_repeated_field_; | 877 static const RepeatedFieldType *default_repeated_field_; |
| 880 }; | 878 }; |
| 881 | 879 |
| 882 // ------------------------------------------------------------------- | 880 // ------------------------------------------------------------------- |
| 883 // EnumTypeTraits | 881 // EnumTypeTraits |
| 884 | 882 |
| 885 // ExtensionSet represents enums using integers internally, so we have to | 883 // ExtensionSet represents enums using integers internally, so we have to |
| 886 // static_cast around. | 884 // static_cast around. |
| 887 template <typename Type, bool IsValid(int)> | 885 template <typename Type, bool IsValid(int)> |
| 888 class EnumTypeTraits { | 886 class EnumTypeTraits { |
| 889 public: | 887 public: |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 | 1036 |
| 1039 // This class exists only to hold a generic default empty repeated field for all | 1037 // This class exists only to hold a generic default empty repeated field for all |
| 1040 // message-type repeated field extensions. | 1038 // message-type repeated field extensions. |
| 1041 class LIBPROTOBUF_EXPORT RepeatedMessageGenericTypeTraits { | 1039 class LIBPROTOBUF_EXPORT RepeatedMessageGenericTypeTraits { |
| 1042 public: | 1040 public: |
| 1043 typedef RepeatedPtrField< ::google::protobuf::MessageLite*> RepeatedFieldType; | 1041 typedef RepeatedPtrField< ::google::protobuf::MessageLite*> RepeatedFieldType; |
| 1044 private: | 1042 private: |
| 1045 template<typename Type> friend class RepeatedMessageTypeTraits; | 1043 template<typename Type> friend class RepeatedMessageTypeTraits; |
| 1046 static void InitializeDefaultRepeatedFields(); | 1044 static void InitializeDefaultRepeatedFields(); |
| 1047 static void DestroyDefaultRepeatedFields(); | 1045 static void DestroyDefaultRepeatedFields(); |
| 1048 static const RepeatedFieldType* cr_default_repeated_field_; | 1046 static const RepeatedFieldType* default_repeated_field_; |
| 1049 }; | 1047 }; |
| 1050 | 1048 |
| 1051 template<typename Type> inline | 1049 template<typename Type> inline |
| 1052 const typename RepeatedMessageTypeTraits<Type>::RepeatedFieldType* | 1050 const typename RepeatedMessageTypeTraits<Type>::RepeatedFieldType* |
| 1053 RepeatedMessageTypeTraits<Type>::GetDefaultRepeatedField() { | 1051 RepeatedMessageTypeTraits<Type>::GetDefaultRepeatedField() { |
| 1054 ::google::protobuf::GoogleOnceInit( | 1052 ::google::protobuf::GoogleOnceInit( |
| 1055 &repeated_message_generic_type_traits_once_init_, | 1053 &repeated_message_generic_type_traits_once_init_, |
| 1056 &RepeatedMessageGenericTypeTraits::InitializeDefaultRepeatedFields); | 1054 &RepeatedMessageGenericTypeTraits::InitializeDefaultRepeatedFields); |
| 1057 return reinterpret_cast<const RepeatedFieldType*>( | 1055 return reinterpret_cast<const RepeatedFieldType*>( |
| 1058 RepeatedMessageGenericTypeTraits::cr_default_repeated_field_); | 1056 RepeatedMessageGenericTypeTraits::default_repeated_field_); |
| 1059 } | 1057 } |
| 1060 | 1058 |
| 1061 // ------------------------------------------------------------------- | 1059 // ------------------------------------------------------------------- |
| 1062 // ExtensionIdentifier | 1060 // ExtensionIdentifier |
| 1063 | 1061 |
| 1064 // This is the type of actual extension objects. E.g. if you have: | 1062 // This is the type of actual extension objects. E.g. if you have: |
| 1065 // extends Foo with optional int32 bar = 1234; | 1063 // extends Foo with optional int32 bar = 1234; |
| 1066 // then "bar" will be defined in C++ as: | 1064 // then "bar" will be defined in C++ as: |
| 1067 // ExtensionIdentifier<Foo, PrimitiveTypeTraits<int32>, 1, false> bar(1234); | 1065 // ExtensionIdentifier<Foo, PrimitiveTypeTraits<int32>, 1, false> bar(1234); |
| 1068 // | 1066 // |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 _is_packed>& id) { \ | 1257 _is_packed>& id) { \ |
| 1260 return _proto_TypeTraits::MutableRepeated(id.number(), _field_type, \ | 1258 return _proto_TypeTraits::MutableRepeated(id.number(), _field_type, \ |
| 1261 _is_packed, &_extensions_); \ | 1259 _is_packed, &_extensions_); \ |
| 1262 } | 1260 } |
| 1263 | 1261 |
| 1264 } // namespace internal | 1262 } // namespace internal |
| 1265 } // namespace protobuf | 1263 } // namespace protobuf |
| 1266 | 1264 |
| 1267 } // namespace google | 1265 } // namespace google |
| 1268 #endif // GOOGLE_PROTOBUF_EXTENSION_SET_H__ | 1266 #endif // GOOGLE_PROTOBUF_EXTENSION_SET_H__ |
| OLD | NEW |