diff options
Diffstat (limited to 'src/google/protobuf/extension_set.h')
-rw-r--r-- | src/google/protobuf/extension_set.h | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index c371e011..09681259 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h @@ -45,6 +45,8 @@ #include <google/protobuf/stubs/common.h> +#include <google/protobuf/stubs/logging.h> +#include <google/protobuf/stubs/once.h> #include <google/protobuf/repeated_field.h> @@ -330,6 +332,8 @@ class LIBPROTOBUF_EXPORT ExtensionSet { const MessageLite& prototype, desc); MessageLite* AddMessage(const FieldDescriptor* descriptor, MessageFactory* factory); + void AddAllocatedMessage(const FieldDescriptor* descriptor, + MessageLite* new_entry); #undef desc void RemoveLast(int number); @@ -578,6 +582,10 @@ class LIBPROTOBUF_EXPORT ExtensionSet { bool MaybeNewExtension(int number, const FieldDescriptor* descriptor, Extension** result); + // Gets the repeated extension for the given descriptor, creating it if + // it does not exist. + Extension* MaybeNewRepeatedExtension(const FieldDescriptor* descriptor); + // Parse a single MessageSet item -- called just after the item group start // tag has been read. bool ParseMessageSetItem(io::CodedInputStream* input, @@ -716,15 +724,14 @@ class RepeatedPrimitiveTypeTraits { static const RepeatedFieldType* GetDefaultRepeatedField(); }; -// Declared here so that this can be friended below. -void InitializeDefaultRepeatedFields(); -void DestroyDefaultRepeatedFields(); +LIBPROTOBUF_EXPORT extern ProtobufOnceType +repeated_primitive_generic_type_traits_once_init_; class LIBPROTOBUF_EXPORT RepeatedPrimitiveGenericTypeTraits { private: template<typename Type> friend class RepeatedPrimitiveTypeTraits; - friend void InitializeDefaultRepeatedFields(); - friend void DestroyDefaultRepeatedFields(); + static void InitializeDefaultRepeatedFields(); + static void DestroyDefaultRepeatedFields(); static const RepeatedField<int32>* default_repeated_field_int32_; static const RepeatedField<int64>* default_repeated_field_int64_; static const RepeatedField<uint32>* default_repeated_field_uint32_; @@ -759,6 +766,9 @@ template<> inline void RepeatedPrimitiveTypeTraits<TYPE>::Add( \ } \ template<> inline const RepeatedField<TYPE>* \ RepeatedPrimitiveTypeTraits<TYPE>::GetDefaultRepeatedField() { \ + GoogleOnceInit( \ + &repeated_primitive_generic_type_traits_once_init_, \ + &RepeatedPrimitiveGenericTypeTraits::InitializeDefaultRepeatedFields); \ return RepeatedPrimitiveGenericTypeTraits:: \ default_repeated_field_##TYPE##_; \ } \ @@ -812,6 +822,9 @@ class LIBPROTOBUF_EXPORT StringTypeTraits { } }; +LIBPROTOBUF_EXPORT extern ProtobufOnceType +repeated_string_type_traits_once_init_; + class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { public: typedef const string& ConstType; @@ -855,12 +868,14 @@ class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { } static const RepeatedFieldType* GetDefaultRepeatedField() { + GoogleOnceInit(&repeated_string_type_traits_once_init_, + &InitializeDefaultRepeatedFields); return default_repeated_field_; } private: - friend void InitializeDefaultRepeatedFields(); - friend void DestroyDefaultRepeatedFields(); + static void InitializeDefaultRepeatedFields(); + static void DestroyDefaultRepeatedFields(); static const RepeatedFieldType *default_repeated_field_; }; @@ -1019,6 +1034,9 @@ class RepeatedMessageTypeTraits { static const RepeatedFieldType* GetDefaultRepeatedField(); }; +LIBPROTOBUF_EXPORT extern ProtobufOnceType +repeated_message_generic_type_traits_once_init_; + // This class exists only to hold a generic default empty repeated field for all // message-type repeated field extensions. class LIBPROTOBUF_EXPORT RepeatedMessageGenericTypeTraits { @@ -1026,14 +1044,17 @@ class LIBPROTOBUF_EXPORT RepeatedMessageGenericTypeTraits { typedef RepeatedPtrField< ::google::protobuf::MessageLite*> RepeatedFieldType; private: template<typename Type> friend class RepeatedMessageTypeTraits; - friend void InitializeDefaultRepeatedFields(); - friend void DestroyDefaultRepeatedFields(); + static void InitializeDefaultRepeatedFields(); + static void DestroyDefaultRepeatedFields(); static const RepeatedFieldType* default_repeated_field_; }; template<typename Type> inline const typename RepeatedMessageTypeTraits<Type>::RepeatedFieldType* RepeatedMessageTypeTraits<Type>::GetDefaultRepeatedField() { + GoogleOnceInit( + &repeated_message_generic_type_traits_once_init_, + &RepeatedMessageGenericTypeTraits::InitializeDefaultRepeatedFields); return reinterpret_cast<const RepeatedFieldType*>( RepeatedMessageGenericTypeTraits::default_repeated_field_); } |