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>* default_repeated_field_int32_; | 734 static const RepeatedField<int32>* cr_default_repeated_field_int32_; |
735 static const RepeatedField<int64>* default_repeated_field_int64_; | 735 static const RepeatedField<int64>* cr_default_repeated_field_int64_; |
736 static const RepeatedField<uint32>* default_repeated_field_uint32_; | 736 static const RepeatedField<uint32>* cr_default_repeated_field_uint32_; |
737 static const RepeatedField<uint64>* default_repeated_field_uint64_; | 737 static const RepeatedField<uint64>* cr_default_repeated_field_uint64_; |
738 static const RepeatedField<double>* default_repeated_field_double_; | 738 static const RepeatedField<double>* cr_default_repeated_field_double_; |
739 static const RepeatedField<float>* default_repeated_field_float_; | 739 static const RepeatedField<float>* cr_default_repeated_field_float_; |
740 static const RepeatedField<bool>* default_repeated_field_bool_; | 740 static const RepeatedField<bool>* cr_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 default_repeated_field_##TYPE##_; \ | 772 cr_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 repeated_string_type_traits_once_init
_; | 824 LIBPROTOBUF_EXPORT extern ProtobufOnceType |
| 825 cr_repeated_string_type_traits_once_init_; |
825 | 826 |
826 class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { | 827 class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { |
827 public: | 828 public: |
828 typedef const string& ConstType; | 829 typedef const string& ConstType; |
829 typedef string* MutableType; | 830 typedef string* MutableType; |
830 typedef RepeatedStringTypeTraits Repeated; | 831 typedef RepeatedStringTypeTraits Repeated; |
831 | 832 |
832 typedef RepeatedPtrField<string> RepeatedFieldType; | 833 typedef RepeatedPtrField<string> RepeatedFieldType; |
833 | 834 |
834 static inline const string& Get(int number, const ExtensionSet& set, | 835 static inline const string& Get(int number, const ExtensionSet& set, |
(...skipping 24 matching lines...) Expand all Loading... |
859 | 860 |
860 static inline RepeatedPtrField<string>* | 861 static inline RepeatedPtrField<string>* |
861 MutableRepeated(int number, FieldType field_type, | 862 MutableRepeated(int number, FieldType field_type, |
862 bool is_packed, ExtensionSet* set) { | 863 bool is_packed, ExtensionSet* set) { |
863 return reinterpret_cast<RepeatedPtrField<string>*>( | 864 return reinterpret_cast<RepeatedPtrField<string>*>( |
864 set->MutableRawRepeatedField(number, field_type, | 865 set->MutableRawRepeatedField(number, field_type, |
865 is_packed, NULL)); | 866 is_packed, NULL)); |
866 } | 867 } |
867 | 868 |
868 static const RepeatedFieldType* GetDefaultRepeatedField() { | 869 static const RepeatedFieldType* GetDefaultRepeatedField() { |
869 ::google::protobuf::GoogleOnceInit(&repeated_string_type_traits_once_init_, | 870 ::google::protobuf::GoogleOnceInit( |
870 &InitializeDefaultRepeatedFields); | 871 &cr_repeated_string_type_traits_once_init_, |
871 return default_repeated_field_; | 872 &InitializeDefaultRepeatedFields); |
| 873 return cr_default_repeated_field_; |
872 } | 874 } |
873 | 875 |
874 private: | 876 private: |
875 static void InitializeDefaultRepeatedFields(); | 877 static void InitializeDefaultRepeatedFields(); |
876 static void DestroyDefaultRepeatedFields(); | 878 static void DestroyDefaultRepeatedFields(); |
877 static const RepeatedFieldType *default_repeated_field_; | 879 static const RepeatedFieldType* cr_default_repeated_field_; |
878 }; | 880 }; |
879 | 881 |
880 // ------------------------------------------------------------------- | 882 // ------------------------------------------------------------------- |
881 // EnumTypeTraits | 883 // EnumTypeTraits |
882 | 884 |
883 // ExtensionSet represents enums using integers internally, so we have to | 885 // ExtensionSet represents enums using integers internally, so we have to |
884 // static_cast around. | 886 // static_cast around. |
885 template <typename Type, bool IsValid(int)> | 887 template <typename Type, bool IsValid(int)> |
886 class EnumTypeTraits { | 888 class EnumTypeTraits { |
887 public: | 889 public: |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 | 1038 |
1037 // This class exists only to hold a generic default empty repeated field for all | 1039 // This class exists only to hold a generic default empty repeated field for all |
1038 // message-type repeated field extensions. | 1040 // message-type repeated field extensions. |
1039 class LIBPROTOBUF_EXPORT RepeatedMessageGenericTypeTraits { | 1041 class LIBPROTOBUF_EXPORT RepeatedMessageGenericTypeTraits { |
1040 public: | 1042 public: |
1041 typedef RepeatedPtrField< ::google::protobuf::MessageLite*> RepeatedFieldType; | 1043 typedef RepeatedPtrField< ::google::protobuf::MessageLite*> RepeatedFieldType; |
1042 private: | 1044 private: |
1043 template<typename Type> friend class RepeatedMessageTypeTraits; | 1045 template<typename Type> friend class RepeatedMessageTypeTraits; |
1044 static void InitializeDefaultRepeatedFields(); | 1046 static void InitializeDefaultRepeatedFields(); |
1045 static void DestroyDefaultRepeatedFields(); | 1047 static void DestroyDefaultRepeatedFields(); |
1046 static const RepeatedFieldType* default_repeated_field_; | 1048 static const RepeatedFieldType* cr_default_repeated_field_; |
1047 }; | 1049 }; |
1048 | 1050 |
1049 template<typename Type> inline | 1051 template<typename Type> inline |
1050 const typename RepeatedMessageTypeTraits<Type>::RepeatedFieldType* | 1052 const typename RepeatedMessageTypeTraits<Type>::RepeatedFieldType* |
1051 RepeatedMessageTypeTraits<Type>::GetDefaultRepeatedField() { | 1053 RepeatedMessageTypeTraits<Type>::GetDefaultRepeatedField() { |
1052 ::google::protobuf::GoogleOnceInit( | 1054 ::google::protobuf::GoogleOnceInit( |
1053 &repeated_message_generic_type_traits_once_init_, | 1055 &repeated_message_generic_type_traits_once_init_, |
1054 &RepeatedMessageGenericTypeTraits::InitializeDefaultRepeatedFields); | 1056 &RepeatedMessageGenericTypeTraits::InitializeDefaultRepeatedFields); |
1055 return reinterpret_cast<const RepeatedFieldType*>( | 1057 return reinterpret_cast<const RepeatedFieldType*>( |
1056 RepeatedMessageGenericTypeTraits::default_repeated_field_); | 1058 RepeatedMessageGenericTypeTraits::cr_default_repeated_field_); |
1057 } | 1059 } |
1058 | 1060 |
1059 // ------------------------------------------------------------------- | 1061 // ------------------------------------------------------------------- |
1060 // ExtensionIdentifier | 1062 // ExtensionIdentifier |
1061 | 1063 |
1062 // This is the type of actual extension objects. E.g. if you have: | 1064 // This is the type of actual extension objects. E.g. if you have: |
1063 // extends Foo with optional int32 bar = 1234; | 1065 // extends Foo with optional int32 bar = 1234; |
1064 // then "bar" will be defined in C++ as: | 1066 // then "bar" will be defined in C++ as: |
1065 // ExtensionIdentifier<Foo, PrimitiveTypeTraits<int32>, 1, false> bar(1234); | 1067 // ExtensionIdentifier<Foo, PrimitiveTypeTraits<int32>, 1, false> bar(1234); |
1066 // | 1068 // |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 _is_packed>& id) { \ | 1259 _is_packed>& id) { \ |
1258 return _proto_TypeTraits::MutableRepeated(id.number(), _field_type, \ | 1260 return _proto_TypeTraits::MutableRepeated(id.number(), _field_type, \ |
1259 _is_packed, &_extensions_); \ | 1261 _is_packed, &_extensions_); \ |
1260 } | 1262 } |
1261 | 1263 |
1262 } // namespace internal | 1264 } // namespace internal |
1263 } // namespace protobuf | 1265 } // namespace protobuf |
1264 | 1266 |
1265 } // namespace google | 1267 } // namespace google |
1266 #endif // GOOGLE_PROTOBUF_EXTENSION_SET_H__ | 1268 #endif // GOOGLE_PROTOBUF_EXTENSION_SET_H__ |
OLD | NEW |