diff options
Diffstat (limited to 'src/google/protobuf/util/message_differencer.h')
-rw-r--r-- | src/google/protobuf/util/message_differencer.h | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/google/protobuf/util/message_differencer.h b/src/google/protobuf/util/message_differencer.h index b7d4de00..b3e65515 100644 --- a/src/google/protobuf/util/message_differencer.h +++ b/src/google/protobuf/util/message_differencer.h @@ -64,6 +64,7 @@ class Printer; namespace util { +class DefaultFieldComparator; class FieldContext; // declared below MessageDifferencer // A basic differencer that can be used to determine @@ -174,10 +175,8 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { // If "field" is a repeated field which is being treated as a map or // a set (see TreatAsMap() and TreatAsSet(), below), new_index indicates - // the index the position to which the element has moved. This only - // applies to ReportMoved() and (in the case of TreatAsMap()) - // ReportModified(). In all other cases, "new_index" will have the same - // value as "index". + // the index the position to which the element has moved. If the element + // has not moved, "new_index" will have the same value as "index". int new_index; // For unknown fields, these are the pointers to the UnknownFieldSet @@ -372,7 +371,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { // repeated fields have different numbers of elements, the // unpaired elements are reported using ReportAdded() or // ReportDeleted(). - AS_SET, // Treat all the repeated fields as sets by default. + AS_SET, // Treat all the repeated fields as sets. // See TreatAsSet(), as below. }; @@ -386,6 +385,11 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { // the only differences between the compared messages is that some fields // have been moved, then the comparison returns true. // + // Note that despite the name of this method, this is really + // comparison as multisets: if one side of the comparison has a duplicate + // in the repeated field but the other side doesn't, this will count as + // a mismatch. + // // If the scope of comparison is set to PARTIAL, then in addition to what's // above, extra values added to repeated fields of the second message will // not cause the comparison to fail. @@ -470,6 +474,10 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { const FieldDescriptor* field, const MapKeyComparator* key_comparator); + // Initiates and returns a new instance of MultipleFieldsMapKeyComparator. + MapKeyComparator* CreateMultipleFieldsMapKeyComparator( + const std::vector<std::vector<const FieldDescriptor*> >& key_field_paths); + // Add a custom ignore criteria that is evaluated in addition to the // ignored fields added with IgnoreField. // Takes ownership of ignore_criteria. @@ -589,7 +597,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { public: explicit StreamReporter(io::ZeroCopyOutputStream* output); explicit StreamReporter(io::Printer* printer); // delimiter '$' - virtual ~StreamReporter(); + virtual ~StreamReporter() override; // When set to true, the stream reporter will also output aggregates nodes // (i.e. messages and groups) whose subfields have been modified. When @@ -599,32 +607,33 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { } // The following are implementations of the methods described above. + virtual void ReportAdded(const Message& message1, const Message& message2, - const std::vector<SpecificField>& field_path); + const std::vector<SpecificField>& field_path) override; virtual void ReportDeleted(const Message& message1, const Message& message2, - const std::vector<SpecificField>& field_path); + const std::vector<SpecificField>& field_path) override; virtual void ReportModified(const Message& message1, const Message& message2, - const std::vector<SpecificField>& field_path); + const std::vector<SpecificField>& field_path) override; virtual void ReportMoved(const Message& message1, const Message& message2, - const std::vector<SpecificField>& field_path); + const std::vector<SpecificField>& field_path) override; virtual void ReportMatched(const Message& message1, const Message& message2, - const std::vector<SpecificField>& field_path); + const std::vector<SpecificField>& field_path) override; virtual void ReportIgnored(const Message& message1, const Message& message2, - const std::vector<SpecificField>& field_path); + const std::vector<SpecificField>& field_path) override; - virtual void ReportUnknownFieldIgnored( + void ReportUnknownFieldIgnored( const Message& message1, const Message& message2, - const std::vector<SpecificField>& field_path); + const std::vector<SpecificField>& field_path) override; protected: // Prints the specified path of fields to the buffer. message is used to @@ -660,6 +669,8 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { }; private: + friend class DefaultFieldComparator; + // A MapKeyComparator to be used in TreatAsMapUsingKeyComparator. // Implementation of this class needs to do field value comparison which // relies on some private methods of MessageDifferencer. That's why this @@ -671,7 +682,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { public: explicit MapEntryKeyComparator(MessageDifferencer* message_differencer); virtual bool IsMatch(const Message& message1, const Message& message2, - const std::vector<SpecificField>& parent_fields) const; + const std::vector<SpecificField>& parent_fields) const override; private: MessageDifferencer* message_differencer_; @@ -811,7 +822,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { // If "any" is of type google.protobuf.Any, extract its payload using // DynamicMessageFactory and store in "data". - bool UnpackAny(const Message& any, google::protobuf::scoped_ptr<Message>* data); + bool UnpackAny(const Message& any, std::unique_ptr<Message>* data); // Checks if index is equal to new_index in all the specific fields. static bool CheckPathChanged(const std::vector<SpecificField>& parent_fields); @@ -852,7 +863,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { string* output_string_; - google::protobuf::scoped_ptr<DynamicMessageFactory> dynamic_message_factory_; + std::unique_ptr<DynamicMessageFactory> dynamic_message_factory_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageDifferencer); }; |