Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Unified Diff: third_party/protobuf/src/google/protobuf/message.h

Issue 1842653006: Update //third_party/protobuf to version 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/src/google/protobuf/message.h
diff --git a/third_party/protobuf/src/google/protobuf/message.h b/third_party/protobuf/src/google/protobuf/message.h
index 0f90bc1a15bd6d0001129796dd09de4f30641d2f..7c27afd9996d1c67c1f9abd9b97e54bc93c3a698 100644
--- a/third_party/protobuf/src/google/protobuf/message.h
+++ b/third_party/protobuf/src/google/protobuf/message.h
@@ -1,6 +1,6 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
-// http://code.google.com/p/protobuf/
+// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -98,11 +98,11 @@
//
// // Use the reflection interface to examine the contents.
// const Reflection* reflection = foo->GetReflection();
-// assert(reflection->GetString(foo, text_field) == "Hello World!");
-// assert(reflection->FieldSize(foo, numbers_field) == 3);
-// assert(reflection->GetRepeatedInt32(foo, numbers_field, 0) == 1);
-// assert(reflection->GetRepeatedInt32(foo, numbers_field, 1) == 5);
-// assert(reflection->GetRepeatedInt32(foo, numbers_field, 2) == 42);
+// assert(reflection->GetString(*foo, text_field) == "Hello World!");
+// assert(reflection->FieldSize(*foo, numbers_field) == 3);
+// assert(reflection->GetRepeatedInt32(*foo, numbers_field, 0) == 1);
+// assert(reflection->GetRepeatedInt32(*foo, numbers_field, 1) == 5);
+// assert(reflection->GetRepeatedInt32(*foo, numbers_field, 2) == 42);
//
// delete foo;
// }
@@ -110,22 +110,21 @@
#ifndef GOOGLE_PROTOBUF_MESSAGE_H__
#define GOOGLE_PROTOBUF_MESSAGE_H__
-#include <vector>
-#include <string>
-
-#ifdef __DECCXX
-// HP C++'s iosfwd doesn't work.
-#include <iostream>
-#else
#include <iosfwd>
-#endif
+#include <string>
+#include <google/protobuf/stubs/type_traits.h>
+#include <vector>
+#include <google/protobuf/arena.h>
#include <google/protobuf/message_lite.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/descriptor.h>
+#define GOOGLE_PROTOBUF_HAS_ONEOF
+#define GOOGLE_PROTOBUF_HAS_ARENAS
+
namespace google {
namespace protobuf {
@@ -135,12 +134,23 @@ class Reflection;
class MessageFactory;
// Defined in other files.
+class MapKey;
+class MapValueRef;
+class MapIterator;
+class MapReflectionTester;
+
+namespace internal {
+class MapFieldBase;
+}
class UnknownFieldSet; // unknown_field_set.h
namespace io {
- class ZeroCopyInputStream; // zero_copy_stream.h
- class ZeroCopyOutputStream; // zero_copy_stream.h
- class CodedInputStream; // coded_stream.h
- class CodedOutputStream; // coded_stream.h
+class ZeroCopyInputStream; // zero_copy_stream.h
+class ZeroCopyOutputStream; // zero_copy_stream.h
+class CodedInputStream; // coded_stream.h
+class CodedOutputStream; // coded_stream.h
+}
+namespace python {
+class MapReflectionFriend; // scalar_map_container.h
}
@@ -178,15 +188,27 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite {
// for return-type covariance.)
virtual Message* New() const = 0;
+ // Construct a new instance on the arena. Ownership is passed to the caller
+ // if arena is a NULL. Default implementation allows for API compatibility
+ // during the Arena transition.
+ virtual Message* New(::google::protobuf::Arena* arena) const {
+ Message* message = New();
+ if (arena != NULL) {
+ arena->Own(message);
+ }
+ return message;
+ }
+
// Make this message into a copy of the given message. The given message
// must have the same descriptor, but need not necessarily be the same class.
// By default this is just implemented as "Clear(); MergeFrom(from);".
virtual void CopyFrom(const Message& from);
// Merge the fields from the given message into this message. Singular
- // fields will be overwritten, except for embedded messages which will
- // be merged. Repeated fields will be concatenated. The given message
- // must be of the same type as this message (i.e. the exact same class).
+ // fields will be overwritten, if specified in from, except for embedded
+ // messages which will be merged. Repeated fields will be concatenated.
+ // The given message must be of the same type as this message (i.e. the
+ // exact same class).
virtual void MergeFrom(const Message& from);
// Verifies that IsInitialized() returns true. GOOGLE_CHECK-fails otherwise, with
@@ -197,7 +219,7 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite {
// This is much, much slower than IsInitialized() as it is implemented
// purely via reflection. Generally, you should not call this unless you
// have already determined that an error exists by calling IsInitialized().
- void FindInitializationErrors(vector<string>* errors) const;
+ void FindInitializationErrors(std::vector<string>* errors) const;
// Like FindInitializationErrors, but joins all the strings, delimited by
// commas, and returns them.
@@ -218,6 +240,11 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite {
// Computes (an estimate of) the total number of bytes currently used for
// storing the message in memory. The default implementation calls the
// Reflection object's SpaceUsed() method.
+ //
+ // SpaceUsed() is noticeably slower than ByteSize(), as it is implemented
+ // using reflection (rather than the generated code implementation for
+ // ByteSize()). Like ByteSize(), its CPU time is linear in the number of
+ // fields defined for the proto.
virtual int SpaceUsed() const;
// Debugging & Testing----------------------------------------------
@@ -316,6 +343,20 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Message);
};
+namespace internal {
+// Forward-declare interfaces used to implement RepeatedFieldRef.
+// These are protobuf internals that users shouldn't care about.
+class RepeatedFieldAccessor;
+} // namespace internal
+
+// Forward-declare RepeatedFieldRef templates. The second type parameter is
+// used for SFINAE tricks. Users should ignore it.
+template<typename T, typename Enable = void>
+class RepeatedFieldRef;
+
+template<typename T, typename Enable = void>
+class MutableRepeatedFieldRef;
+
// This interface contains methods that can be used to dynamically access
// and modify the fields of a protocol message. Their semantics are
// similar to the accessors the protocol compiler generates.
@@ -364,12 +405,15 @@ class LIBPROTOBUF_EXPORT Reflection {
// Get the UnknownFieldSet for the message. This contains fields which
// were seen when the Message was parsed but were not recognized according
- // to the Message's definition.
+ // to the Message's definition. For proto3 protos, this method will always
+ // return an empty UnknownFieldSet.
virtual const UnknownFieldSet& GetUnknownFields(
const Message& message) const = 0;
// Get a mutable pointer to the UnknownFieldSet for the message. This
// contains fields which were seen when the Message was parsed but were not
- // recognized according to the Message's definition.
+ // recognized according to the Message's definition. For proto3 protos, this
+ // method will return a valid mutable UnknownFieldSet pointer but modifying
+ // it won't affect the serialized bytes of the message.
virtual UnknownFieldSet* MutableUnknownFields(Message* message) const = 0;
// Estimate the amount of memory used by the message object.
@@ -388,6 +432,26 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual void ClearField(Message* message,
const FieldDescriptor* field) const = 0;
+ // Check if the oneof is set. Returns true if any field in oneof
+ // is set, false otherwise.
+ // TODO(jieluo) - make it pure virtual after updating all
+ // the subclasses.
+ virtual bool HasOneof(const Message& /*message*/,
+ const OneofDescriptor* /*oneof_descriptor*/) const {
+ return false;
+ }
+
+ virtual void ClearOneof(Message* /*message*/,
+ const OneofDescriptor* /*oneof_descriptor*/) const {}
+
+ // Returns the field descriptor if the oneof is set. NULL otherwise.
+ // TODO(jieluo) - make it pure virtual.
+ virtual const FieldDescriptor* GetOneofFieldDescriptor(
+ const Message& /*message*/,
+ const OneofDescriptor* /*oneof_descriptor*/) const {
+ return NULL;
+ }
+
// Removes the last element of a repeated field.
// We don't provide a way to remove any element other than the last
// because it invites inefficient use, such as O(n^2) filtering loops
@@ -405,19 +469,26 @@ class LIBPROTOBUF_EXPORT Reflection {
// Swap the complete contents of two messages.
virtual void Swap(Message* message1, Message* message2) const = 0;
+ // Swap fields listed in fields vector of two messages.
+ virtual void SwapFields(Message* message1,
+ Message* message2,
+ const std::vector<const FieldDescriptor*>& fields)
+ const = 0;
+
// Swap two elements of a repeated field.
virtual void SwapElements(Message* message,
- const FieldDescriptor* field,
- int index1,
- int index2) const = 0;
+ const FieldDescriptor* field,
+ int index1,
+ int index2) const = 0;
// List all fields of the message which are currently set. This includes
// extensions. Singular fields will only be listed if HasField(field) would
// return true and repeated fields will only be listed if FieldSize(field)
// would return non-zero. Fields (both normal fields and extension fields)
// will be listed ordered by field number.
- virtual void ListFields(const Message& message,
- vector<const FieldDescriptor*>* output) const = 0;
+ virtual void ListFields(
+ const Message& message,
+ std::vector<const FieldDescriptor*>* output) const = 0;
// Singular field getters ------------------------------------------
// These get the value of a non-repeated field. They return the default
@@ -441,6 +512,15 @@ class LIBPROTOBUF_EXPORT Reflection {
const FieldDescriptor* field) const = 0;
virtual const EnumValueDescriptor* GetEnum(
const Message& message, const FieldDescriptor* field) const = 0;
+
+ // GetEnumValue() returns an enum field's value as an integer rather than
+ // an EnumValueDescriptor*. If the integer value does not correspond to a
+ // known value descriptor, a new value descriptor is created. (Such a value
+ // will only be present when the new unknown-enum-value semantics are enabled
+ // for a message.)
+ virtual int GetEnumValue(
+ const Message& message, const FieldDescriptor* field) const;
+
// See MutableMessage() for the meaning of the "factory" parameter.
virtual const Message& GetMessage(const Message& message,
const FieldDescriptor* field,
@@ -460,7 +540,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// regardless of the field's underlying representation. When initializing
// a newly-constructed string, though, it's just as fast and more readable
// to use code like:
- // string str = reflection->GetString(field);
+ // string str = reflection->GetString(message, field);
virtual const string& GetStringReference(const Message& message,
const FieldDescriptor* field,
string* scratch) const = 0;
@@ -489,6 +569,14 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual void SetEnum (Message* message,
const FieldDescriptor* field,
const EnumValueDescriptor* value) const = 0;
+ // Set an enum field's value with an integer rather than EnumValueDescriptor.
+ // If the value does not correspond to a known enum value, either behavior is
+ // undefined (for proto2 messages), or the value is accepted silently for
+ // messages with new unknown-enum-value semantics.
+ virtual void SetEnumValue(Message* message,
+ const FieldDescriptor* field,
+ int value) const;
+
// Get a mutable pointer to a field with a message type. If a MessageFactory
// is provided, it will be used to construct instances of the sub-message;
// otherwise, the default factory is used. If the field is an extension that
@@ -502,6 +590,13 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual Message* MutableMessage(Message* message,
const FieldDescriptor* field,
MessageFactory* factory = NULL) const = 0;
+ // Replaces the message specified by 'field' with the already-allocated object
+ // sub_message, passing ownership to the message. If the field contained a
+ // message, that message is deleted. If sub_message is NULL, the field is
+ // cleared.
+ virtual void SetAllocatedMessage(Message* message,
+ Message* sub_message,
+ const FieldDescriptor* field) const = 0;
// Releases the message specified by 'field' and returns the pointer,
// ReleaseMessage() will return the message the message object if it exists.
// Otherwise, it may or may not return NULL. In any case, if the return value
@@ -544,6 +639,14 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual const EnumValueDescriptor* GetRepeatedEnum(
const Message& message,
const FieldDescriptor* field, int index) const = 0;
+ // GetRepeatedEnumValue() returns an enum field's value as an integer rather
+ // than an EnumValueDescriptor*. If the integer value does not correspond to a
+ // known value descriptor, a new value descriptor is created. (Such a value
+ // will only be present when the new unknown-enum-value semantics are enabled
+ // for a message.)
+ virtual int GetRepeatedEnumValue(
+ const Message& message,
+ const FieldDescriptor* field, int index) const;
virtual const Message& GetRepeatedMessage(
const Message& message,
const FieldDescriptor* field, int index) const = 0;
@@ -584,6 +687,13 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual void SetRepeatedEnum(Message* message,
const FieldDescriptor* field, int index,
const EnumValueDescriptor* value) const = 0;
+ // Set an enum field's value with an integer rather than EnumValueDescriptor.
+ // If the value does not correspond to a known enum value, either behavior is
+ // undefined (for proto2 messages), or the value is accepted silently for
+ // messages with new unknown-enum-value semantics.
+ virtual void SetRepeatedEnumValue(Message* message,
+ const FieldDescriptor* field, int index,
+ int value) const;
// Get a mutable pointer to an element of a repeated field with a message
// type.
virtual Message* MutableRepeatedMessage(
@@ -613,12 +723,65 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual void AddEnum (Message* message,
const FieldDescriptor* field,
const EnumValueDescriptor* value) const = 0;
+ // Set an enum field's value with an integer rather than EnumValueDescriptor.
+ // If the value does not correspond to a known enum value, either behavior is
+ // undefined (for proto2 messages), or the value is accepted silently for
+ // messages with new unknown-enum-value semantics.
+ virtual void AddEnumValue(Message* message,
+ const FieldDescriptor* field,
+ int value) const;
// See MutableMessage() for comments on the "factory" parameter.
virtual Message* AddMessage(Message* message,
const FieldDescriptor* field,
MessageFactory* factory = NULL) const = 0;
+ // Appends an already-allocated object 'new_entry' to the repeated field
+ // specifyed by 'field' passing ownership to the message.
+ // TODO(tmarek): Make virtual after all subclasses have been
+ // updated.
+ virtual void AddAllocatedMessage(Message* message,
+ const FieldDescriptor* field,
+ Message* new_entry) const {}
+
+ // Get a RepeatedFieldRef object that can be used to read the underlying
+ // repeated field. The type parameter T must be set according to the
+ // field's cpp type. The following table shows the mapping from cpp type
+ // to acceptable T.
+ //
+ // field->cpp_type() T
+ // CPPTYPE_INT32 int32
+ // CPPTYPE_UINT32 uint32
+ // CPPTYPE_INT64 int64
+ // CPPTYPE_UINT64 uint64
+ // CPPTYPE_DOUBLE double
+ // CPPTYPE_FLOAT float
+ // CPPTYPE_BOOL bool
+ // CPPTYPE_ENUM generated enum type or int32
+ // CPPTYPE_STRING string
+ // CPPTYPE_MESSAGE generated message type or google::protobuf::Message
+ //
+ // A RepeatedFieldRef object can be copied and the resulted object will point
+ // to the same repeated field in the same message. The object can be used as
+ // long as the message is not destroyed.
+ //
+ // Note that to use this method users need to include the header file
+ // "google/protobuf/reflection.h" (which defines the RepeatedFieldRef
+ // class templates).
+ template<typename T>
+ RepeatedFieldRef<T> GetRepeatedFieldRef(
+ const Message& message, const FieldDescriptor* field) const;
+
+ // Like GetRepeatedFieldRef() but return an object that can also be used
+ // manipulate the underlying repeated field.
+ template<typename T>
+ MutableRepeatedFieldRef<T> GetMutableRepeatedFieldRef(
+ Message* message, const FieldDescriptor* field) const;
+
+ // DEPRECATED. Please use Get(Mutable)RepeatedFieldRef() for repeated field
+ // access. The following repeated field accesors will be removed in the
+ // future.
+ //
// Repeated field accessors -------------------------------------------------
// The methods above, e.g. GetRepeatedInt32(msg, fd, index), provide singular
// access to the data in a RepeatedField. The methods below provide aggregate
@@ -629,22 +792,30 @@ class LIBPROTOBUF_EXPORT Reflection {
//
// Usage example: my_doubs = refl->GetRepeatedField<double>(msg, fd);
+ // DEPRECATED. Please use GetRepeatedFieldRef().
+ //
// for T = Cord and all protobuf scalar types except enums.
template<typename T>
const RepeatedField<T>& GetRepeatedField(
const Message&, const FieldDescriptor*) const;
+ // DEPRECATED. Please use GetMutableRepeatedFieldRef().
+ //
// for T = Cord and all protobuf scalar types except enums.
template<typename T>
RepeatedField<T>* MutableRepeatedField(
Message*, const FieldDescriptor*) const;
+ // DEPRECATED. Please use GetRepeatedFieldRef().
+ //
// for T = string, google::protobuf::internal::StringPieceField
// google::protobuf::Message & descendants.
template<typename T>
const RepeatedPtrField<T>& GetRepeatedPtrField(
const Message&, const FieldDescriptor*) const;
+ // DEPRECATED. Please use GetMutableRepeatedFieldRef().
+ //
// for T = string, google::protobuf::internal::StringPieceField
// google::protobuf::Message & descendants.
template<typename T>
@@ -663,6 +834,52 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual const FieldDescriptor* FindKnownExtensionByNumber(
int number) const = 0;
+ // Feature Flags -------------------------------------------------------------
+
+ // Does this message support storing arbitrary integer values in enum fields?
+ // If |true|, GetEnumValue/SetEnumValue and associated repeated-field versions
+ // take arbitrary integer values, and the legacy GetEnum() getter will
+ // dynamically create an EnumValueDescriptor for any integer value without
+ // one. If |false|, setting an unknown enum value via the integer-based
+ // setters results in undefined behavior (in practice, GOOGLE_DCHECK-fails).
+ //
+ // Generic code that uses reflection to handle messages with enum fields
+ // should check this flag before using the integer-based setter, and either
+ // downgrade to a compatible value or use the UnknownFieldSet if not. For
+ // example:
+ //
+ // int new_value = GetValueFromApplicationLogic();
+ // if (reflection->SupportsUnknownEnumValues()) {
+ // reflection->SetEnumValue(message, field, new_value);
+ // } else {
+ // if (field_descriptor->enum_type()->
+ // FindValueByNumver(new_value) != NULL) {
+ // reflection->SetEnumValue(message, field, new_value);
+ // } else if (emit_unknown_enum_values) {
+ // reflection->MutableUnknownFields(message)->AddVarint(
+ // field->number(),
+ // new_value);
+ // } else {
+ // // convert value to a compatible/default value.
+ // new_value = CompatibleDowngrade(new_value);
+ // reflection->SetEnumValue(message, field, new_value);
+ // }
+ // }
+ virtual bool SupportsUnknownEnumValues() const { return false; }
+
+ // Returns the MessageFactory associated with this message. This can be
+ // useful for determining if a message is a generated message or not, for
+ // example:
+ //
+ // if (message->GetReflection()->GetMessageFactory() ==
+ // google::protobuf::MessageFactory::generated_factory()) {
+ // // This is a generated message.
+ // }
+ //
+ // It can also be used to create more messages of this type, though
+ // Message::New() is an easier way to accomplish this.
+ virtual MessageFactory* GetMessageFactory() const;
+
// ---------------------------------------------------------------------------
protected:
@@ -670,19 +887,118 @@ class LIBPROTOBUF_EXPORT Reflection {
// on field->cpp_type(),
// on field->field_option().ctype() (if ctype >= 0)
// of field->message_type() (if message_type != NULL).
- // We use 1 routine rather than 4 (const vs mutable) x (scalar vs pointer).
+ // We use 2 routine rather than 4 (const vs mutable) x (scalar vs pointer).
virtual void* MutableRawRepeatedField(
Message* message, const FieldDescriptor* field, FieldDescriptor::CppType,
int ctype, const Descriptor* message_type) const = 0;
+ // TODO(jieluo) - make it pure virtual after updating all the subclasses.
+ virtual const void* GetRawRepeatedField(
+ const Message& message, const FieldDescriptor* field,
+ FieldDescriptor::CppType cpptype, int ctype,
+ const Descriptor* message_type) const {
+ return MutableRawRepeatedField(
+ const_cast<Message*>(&message), field, cpptype, ctype, message_type);
+ }
+
+ // The following methods are used to implement (Mutable)RepeatedFieldRef.
+ // A Ref object will store a raw pointer to the repeated field data (obtained
+ // from RepeatedFieldData()) and a pointer to a Accessor (obtained from
+ // RepeatedFieldAccessor) which will be used to access the raw data.
+ //
+ // TODO(xiaofeng): Make these methods pure-virtual.
+
+ // Returns a raw pointer to the repeated field
+ //
+ // "cpp_type" and "message_type" are decuded from the type parameter T passed
+ // to Get(Mutable)RepeatedFieldRef. If T is a generated message type,
+ // "message_type" should be set to its descriptor. Otherwise "message_type"
+ // should be set to NULL. Implementations of this method should check whether
+ // "cpp_type"/"message_type" is consistent with the actual type of the field.
+ // We use 1 routine rather than 2 (const vs mutable) because it is protected
+ // and it doesn't change the message.
+ virtual void* RepeatedFieldData(
+ Message* message, const FieldDescriptor* field,
+ FieldDescriptor::CppType cpp_type,
+ const Descriptor* message_type) const;
+
+ // The returned pointer should point to a singleton instance which implements
+ // the RepeatedFieldAccessor interface.
+ virtual const internal::RepeatedFieldAccessor* RepeatedFieldAccessor(
+ const FieldDescriptor* field) const;
+
private:
+ template<typename T, typename Enable>
+ friend class RepeatedFieldRef;
+ template<typename T, typename Enable>
+ friend class MutableRepeatedFieldRef;
+ friend class ::google::protobuf::python::MapReflectionFriend;
+
// Special version for specialized implementations of string. We can't call
// MutableRawRepeatedField directly here because we don't have access to
// FieldOptions::* which are defined in descriptor.pb.h. Including that
// file here is not possible because it would cause a circular include cycle.
+ // We use 1 routine rather than 2 (const vs mutable) because it is private
+ // and mutable a repeated string field doesn't change the message.
void* MutableRawRepeatedString(
Message* message, const FieldDescriptor* field, bool is_string) const;
+ friend class MapReflectionTester;
+ // TODO(jieluo) - make the map APIs pure virtual after updating
+ // all the subclasses.
+ // Returns true if key is in map. Returns false if key is not in map field.
+ virtual bool ContainsMapKey(const Message& message,
+ const FieldDescriptor* field,
+ const MapKey& key) const {
+ return false;
+ }
+
+ // If key is in map field: Saves the value pointer to val and returns
+ // false. If key in not in map field: Insert the key into map, saves
+ // value pointer to val and retuns true.
+ virtual bool InsertOrLookupMapValue(Message* message,
+ const FieldDescriptor* field,
+ const MapKey& key,
+ MapValueRef* val) const {
+ return false;
+ }
+
+ // Delete and returns true if key is in the map field. Returns false
+ // otherwise.
+ virtual bool DeleteMapValue(Message* message,
+ const FieldDescriptor* field,
+ const MapKey& key) const {
+ return false;
+ }
+
+ // Returns a MapIterator referring to the first element in the map field.
+ // If the map field is empty, this function returns the same as
+ // reflection::MapEnd. Mutation to the field may invalidate the iterator.
+ virtual MapIterator MapBegin(
+ Message* message,
+ const FieldDescriptor* field) const;
+
+ // Returns a MapIterator referring to the theoretical element that would
+ // follow the last element in the map field. It does not point to any
+ // real element. Mutation to the field may invalidate the iterator.
+ virtual MapIterator MapEnd(
+ Message* message,
+ const FieldDescriptor* field) const;
+
+ // Get the number of <key, value> pair of a map field. The result may be
+ // different from FieldSize which can have duplicate keys.
+ virtual int MapSize(const Message& message,
+ const FieldDescriptor* field) const {
+ return 0;
+ }
+
+ // Help method for MapIterator.
+ friend class MapIterator;
+ virtual internal::MapFieldBase* MapData(
+ Message* message, const FieldDescriptor* field) const {
+ return NULL;
+ }
+
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Reflection);
};
@@ -699,7 +1015,7 @@ class LIBPROTOBUF_EXPORT MessageFactory {
// Calling this method twice with the same Descriptor returns the same
// object. The returned object remains property of the factory. Also, any
// objects created by calling the prototype's New() method share some data
- // with the prototype, so these must be destoyed before the MessageFactory
+ // with the prototype, so these must be destroyed before the MessageFactory
// is destroyed.
//
// The given descriptor must outlive the returned message, and hence must
@@ -798,10 +1114,9 @@ inline RepeatedPtrField<string>* Reflection::MutableRepeatedPtrField<string>(
template<>
inline const RepeatedPtrField<Message>& Reflection::GetRepeatedPtrField(
const Message& message, const FieldDescriptor* field) const {
- return *static_cast<RepeatedPtrField<Message>* >(
- MutableRawRepeatedField(const_cast<Message*>(&message), field,
- FieldDescriptor::CPPTYPE_MESSAGE, -1,
- NULL));
+ return *static_cast<const RepeatedPtrField<Message>* >(
+ GetRawRepeatedField(message, field, FieldDescriptor::CPPTYPE_MESSAGE,
+ -1, NULL));
}
template<>
@@ -816,10 +1131,9 @@ inline RepeatedPtrField<Message>* Reflection::MutableRepeatedPtrField(
template<typename PB>
inline const RepeatedPtrField<PB>& Reflection::GetRepeatedPtrField(
const Message& message, const FieldDescriptor* field) const {
- return *static_cast<RepeatedPtrField<PB>* >(
- MutableRawRepeatedField(const_cast<Message*>(&message), field,
- FieldDescriptor::CPPTYPE_MESSAGE, -1,
- PB::default_instance().GetDescriptor()));
+ return *static_cast<const RepeatedPtrField<PB>* >(
+ GetRawRepeatedField(message, field, FieldDescriptor::CPPTYPE_MESSAGE,
+ -1, PB::default_instance().GetDescriptor()));
}
template<typename PB>
@@ -830,7 +1144,6 @@ inline RepeatedPtrField<PB>* Reflection::MutableRepeatedPtrField(
FieldDescriptor::CPPTYPE_MESSAGE, -1,
PB::default_instance().GetDescriptor()));
}
-
} // namespace protobuf
} // namespace google

Powered by Google App Engine
This is Rietveld 408576698