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

Side by Side Diff: third_party/protobuf/src/google/protobuf/util/message_differencer.h

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years 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 unified diff | Download patch
OLDNEW
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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // itself and the second will be the actual field in the embedded message 214 // itself and the second will be the actual field in the embedded message
215 // that was added/deleted/modified. 215 // that was added/deleted/modified.
216 class LIBPROTOBUF_EXPORT Reporter { 216 class LIBPROTOBUF_EXPORT Reporter {
217 public: 217 public:
218 Reporter(); 218 Reporter();
219 virtual ~Reporter(); 219 virtual ~Reporter();
220 220
221 // Reports that a field has been added into Message2. 221 // Reports that a field has been added into Message2.
222 virtual void ReportAdded( 222 virtual void ReportAdded(
223 const Message& message1, const Message& message2, 223 const Message& message1, const Message& message2,
224 const vector<SpecificField>& field_path) = 0; 224 const std::vector<SpecificField>& field_path) = 0;
225 225
226 // Reports that a field has been deleted from Message1. 226 // Reports that a field has been deleted from Message1.
227 virtual void ReportDeleted( 227 virtual void ReportDeleted(
228 const Message& message1, 228 const Message& message1,
229 const Message& message2, 229 const Message& message2,
230 const vector<SpecificField>& field_path) = 0; 230 const std::vector<SpecificField>& field_path) = 0;
231 231
232 // Reports that the value of a field has been modified. 232 // Reports that the value of a field has been modified.
233 virtual void ReportModified( 233 virtual void ReportModified(
234 const Message& message1, 234 const Message& message1,
235 const Message& message2, 235 const Message& message2,
236 const vector<SpecificField>& field_path) = 0; 236 const std::vector<SpecificField>& field_path) = 0;
237 237
238 // Reports that a repeated field has been moved to another location. This 238 // Reports that a repeated field has been moved to another location. This
239 // only applies when using TreatAsSet or TreatAsMap() -- see below. Also 239 // only applies when using TreatAsSet or TreatAsMap() -- see below. Also
240 // note that for any given field, ReportModified and ReportMoved are 240 // note that for any given field, ReportModified and ReportMoved are
241 // mutually exclusive. If a field has been both moved and modified, then 241 // mutually exclusive. If a field has been both moved and modified, then
242 // only ReportModified will be called. 242 // only ReportModified will be called.
243 virtual void ReportMoved( 243 virtual void ReportMoved(
244 const Message& message1, 244 const Message& message1,
245 const Message& message2, 245 const Message& message2,
246 const vector<SpecificField>& field_path) { } 246 const std::vector<SpecificField>& field_path) { }
247 247
248 // Reports that two fields match. Useful for doing side-by-side diffs. 248 // Reports that two fields match. Useful for doing side-by-side diffs.
249 // This function is mutually exclusive with ReportModified and ReportMoved. 249 // This function is mutually exclusive with ReportModified and ReportMoved.
250 // Note that you must call set_report_matches(true) before calling Compare 250 // Note that you must call set_report_matches(true) before calling Compare
251 // to make use of this function. 251 // to make use of this function.
252 virtual void ReportMatched( 252 virtual void ReportMatched(
253 const Message& message1, 253 const Message& message1,
254 const Message& message2, 254 const Message& message2,
255 const vector<SpecificField>& field_path) { } 255 const std::vector<SpecificField>& field_path) { }
256 256
257 // Reports that two fields would have been compared, but the 257 // Reports that two fields would have been compared, but the
258 // comparison has been skipped because the field was marked as 258 // comparison has been skipped because the field was marked as
259 // 'ignored' using IgnoreField(). This function is mutually 259 // 'ignored' using IgnoreField(). This function is mutually
260 // exclusive with all the other Report() functions. 260 // exclusive with all the other Report() functions.
261 // 261 //
262 // The contract of ReportIgnored is slightly different than the 262 // The contract of ReportIgnored is slightly different than the
263 // other Report() functions, in that |field_path.back().index| is 263 // other Report() functions, in that |field_path.back().index| is
264 // always equal to -1, even if the last field is repeated. This is 264 // always equal to -1, even if the last field is repeated. This is
265 // because while the other Report() functions indicate where in a 265 // because while the other Report() functions indicate where in a
266 // repeated field the action (Addition, Deletion, etc...) 266 // repeated field the action (Addition, Deletion, etc...)
267 // happened, when a repeated field is 'ignored', the differencer 267 // happened, when a repeated field is 'ignored', the differencer
268 // simply calls ReportIgnored on the repeated field as a whole and 268 // simply calls ReportIgnored on the repeated field as a whole and
269 // moves on without looking at its individual elements. 269 // moves on without looking at its individual elements.
270 // 270 //
271 // Furthermore, ReportIgnored() does not indicate whether the 271 // Furthermore, ReportIgnored() does not indicate whether the
272 // fields were in fact equal or not, as Compare() does not inspect 272 // fields were in fact equal or not, as Compare() does not inspect
273 // these fields at all. It is up to the Reporter to decide whether 273 // these fields at all. It is up to the Reporter to decide whether
274 // the fields are equal or not (perhaps with a second call to 274 // the fields are equal or not (perhaps with a second call to
275 // Compare()), if it cares. 275 // Compare()), if it cares.
276 virtual void ReportIgnored( 276 virtual void ReportIgnored(
277 const Message& message1, 277 const Message& message1,
278 const Message& message2, 278 const Message& message2,
279 const vector<SpecificField>& field_path) { } 279 const std::vector<SpecificField>& field_path) { }
280 280
281 // Report that an unkown field is ignored. (see comment above). 281 // Report that an unknown field is ignored. (see comment above).
282 // Note this is a different function since the last SpecificField in field 282 // Note this is a different function since the last SpecificField in field
283 // path has a null field. This could break existing Reporter. 283 // path has a null field. This could break existing Reporter.
284 virtual void ReportUnknownFieldIgnored( 284 virtual void ReportUnknownFieldIgnored(
285 const Message& message1, const Message& message2, 285 const Message& message1, const Message& message2,
286 const vector<SpecificField>& field_path) {} 286 const std::vector<SpecificField>& field_path) {}
287 287
288 private: 288 private:
289 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Reporter); 289 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Reporter);
290 }; 290 };
291 291
292 // MapKeyComparator is used to determine if two elements have the same key 292 // MapKeyComparator is used to determine if two elements have the same key
293 // when comparing elements of a repeated field as a map. 293 // when comparing elements of a repeated field as a map.
294 class LIBPROTOBUF_EXPORT MapKeyComparator { 294 class LIBPROTOBUF_EXPORT MapKeyComparator {
295 public: 295 public:
296 MapKeyComparator(); 296 MapKeyComparator();
297 virtual ~MapKeyComparator(); 297 virtual ~MapKeyComparator();
298 298
299 virtual bool IsMatch(const Message& message1, 299 virtual bool IsMatch(
300 const Message& message2, 300 const Message& message1,
301 const vector<SpecificField>& parent_fields) const { 301 const Message& message2,
302 const std::vector<SpecificField>& parent_fields) const {
302 GOOGLE_CHECK(false) << "IsMatch() is not implemented."; 303 GOOGLE_CHECK(false) << "IsMatch() is not implemented.";
303 return false; 304 return false;
304 } 305 }
305 306
306 private: 307 private:
307 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapKeyComparator); 308 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapKeyComparator);
308 }; 309 };
309 310
310 // Abstract base class from which all IgnoreCriteria derive. 311 // Abstract base class from which all IgnoreCriteria derive.
311 // By adding IgnoreCriteria more complex ignore logic can be implemented. 312 // By adding IgnoreCriteria more complex ignore logic can be implemented.
312 // IgnoreCriteria are registed with AddIgnoreCriteria. For each compared 313 // IgnoreCriteria are registed with AddIgnoreCriteria. For each compared
313 // field IsIgnored is called on each added IgnoreCriteria until one returns 314 // field IsIgnored is called on each added IgnoreCriteria until one returns
314 // true or all return false. 315 // true or all return false.
315 // IsIgnored is called for fields where at least one side has a value. 316 // IsIgnored is called for fields where at least one side has a value.
316 class LIBPROTOBUF_EXPORT IgnoreCriteria { 317 class LIBPROTOBUF_EXPORT IgnoreCriteria {
317 public: 318 public:
318 IgnoreCriteria(); 319 IgnoreCriteria();
319 virtual ~IgnoreCriteria(); 320 virtual ~IgnoreCriteria();
320 321
321 // Returns true if the field should be ignored. 322 // Returns true if the field should be ignored.
322 virtual bool IsIgnored( 323 virtual bool IsIgnored(
323 const Message& message1, 324 const Message& message1,
324 const Message& message2, 325 const Message& message2,
325 const FieldDescriptor* field, 326 const FieldDescriptor* field,
326 const vector<SpecificField>& parent_fields) = 0; 327 const std::vector<SpecificField>& parent_fields) = 0;
327 328
328 // Returns true if the unknown field should be ignored. 329 // Returns true if the unknown field should be ignored.
329 // Note: This will be called for unknown fields as well in which case 330 // Note: This will be called for unknown fields as well in which case
330 // field.field will be null. 331 // field.field will be null.
331 virtual bool IsUnknownFieldIgnored( 332 virtual bool IsUnknownFieldIgnored(
332 const Message& message1, const Message& message2, 333 const Message& message1, const Message& message2,
333 const SpecificField& field, 334 const SpecificField& field,
334 const vector<SpecificField>& parent_fields) { 335 const std::vector<SpecificField>& parent_fields) {
335 return false; 336 return false;
336 } 337 }
337 }; 338 };
338 339
339 // To add a Reporter, construct default here, then use ReportDifferencesTo or 340 // To add a Reporter, construct default here, then use ReportDifferencesTo or
340 // ReportDifferencesToString. 341 // ReportDifferencesToString.
341 explicit MessageDifferencer(); 342 explicit MessageDifferencer();
342 343
343 ~MessageDifferencer(); 344 ~MessageDifferencer();
344 345
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 // comparison. Those pairs of elements with the same key (with equal value 434 // comparison. Those pairs of elements with the same key (with equal value
434 // for every field in 'key_fields') will be compared in this step. 435 // for every field in 'key_fields') will be compared in this step.
435 // Time complexity of the first step is O(s * m * n ^ 2) where s is the 436 // Time complexity of the first step is O(s * m * n ^ 2) where s is the
436 // average size of the fields specified in 'key_fields', m is the number of 437 // average size of the fields specified in 'key_fields', m is the number of
437 // fields in 'key_fields' and n is the number of elements. If partial 438 // fields in 'key_fields' and n is the number of elements. If partial
438 // matching is enabled, an extra O(n^3) will be incured by the maximum 439 // matching is enabled, an extra O(n^3) will be incured by the maximum
439 // matching algorithm. The second step is O(k * n) where k is the average 440 // matching algorithm. The second step is O(k * n) where k is the average
440 // size of each element. 441 // size of each element.
441 void TreatAsMapWithMultipleFieldsAsKey( 442 void TreatAsMapWithMultipleFieldsAsKey(
442 const FieldDescriptor* field, 443 const FieldDescriptor* field,
443 const vector<const FieldDescriptor*>& key_fields); 444 const std::vector<const FieldDescriptor*>& key_fields);
444 // Same as TreatAsMapWithMultipleFieldsAsKey, except that each of the field 445 // Same as TreatAsMapWithMultipleFieldsAsKey, except that each of the field
445 // do not necessarily need to be a direct subfield. Each element in 446 // do not necessarily need to be a direct subfield. Each element in
446 // key_field_paths indicate a path from the message being compared, listing 447 // key_field_paths indicate a path from the message being compared, listing
447 // successive subfield to reach the key field. 448 // successive subfield to reach the key field.
448 // 449 //
449 // REQUIRES: 450 // REQUIRES:
450 // for key_field_path in key_field_paths: 451 // for key_field_path in key_field_paths:
451 // key_field_path[0]->containing_type() == field->message_type() 452 // key_field_path[0]->containing_type() == field->message_type()
452 // for i in [0, key_field_path.size() - 1): 453 // for i in [0, key_field_path.size() - 1):
453 // key_field_path[i+1]->containing_type() == 454 // key_field_path[i+1]->containing_type() ==
454 // key_field_path[i]->message_type() 455 // key_field_path[i]->message_type()
455 // key_field_path[i]->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE 456 // key_field_path[i]->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE
456 // !key_field_path[i]->is_repeated() 457 // !key_field_path[i]->is_repeated()
457 void TreatAsMapWithMultipleFieldPathsAsKey( 458 void TreatAsMapWithMultipleFieldPathsAsKey(
458 const FieldDescriptor* field, 459 const FieldDescriptor* field,
459 const vector<vector<const FieldDescriptor*> >& key_field_paths); 460 const std::vector<std::vector<const FieldDescriptor*> >& key_field_paths);
460 461
461 // Uses a custom MapKeyComparator to determine if two elements have the same 462 // Uses a custom MapKeyComparator to determine if two elements have the same
462 // key when comparing a repeated field as a map. 463 // key when comparing a repeated field as a map.
463 // The caller is responsible to delete the key_comparator. 464 // The caller is responsible to delete the key_comparator.
464 // This method varies from TreatAsMapWithMultipleFieldsAsKey only in the 465 // This method varies from TreatAsMapWithMultipleFieldsAsKey only in the
465 // first key matching step. Rather than comparing some specified fields, it 466 // first key matching step. Rather than comparing some specified fields, it
466 // will invoke the IsMatch method of the given 'key_comparator' to decide if 467 // will invoke the IsMatch method of the given 'key_comparator' to decide if
467 // two elements have the same key. 468 // two elements have the same key.
468 void TreatAsMapUsingKeyComparator( 469 void TreatAsMapUsingKeyComparator(
469 const FieldDescriptor* field, 470 const FieldDescriptor* field,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 // false otherwise. If this method returns false, any changes between the 543 // false otherwise. If this method returns false, any changes between the
543 // two messages will be reported if a Reporter was specified via 544 // two messages will be reported if a Reporter was specified via
544 // ReportDifferencesTo (see also ReportDifferencesToString). 545 // ReportDifferencesTo (see also ReportDifferencesToString).
545 // 546 //
546 // This method REQUIRES that the two messages have the same 547 // This method REQUIRES that the two messages have the same
547 // Descriptor (message1.GetDescriptor() == message2.GetDescriptor()). 548 // Descriptor (message1.GetDescriptor() == message2.GetDescriptor()).
548 bool Compare(const Message& message1, const Message& message2); 549 bool Compare(const Message& message1, const Message& message2);
549 550
550 // Same as above, except comparing only the list of fields specified by the 551 // Same as above, except comparing only the list of fields specified by the
551 // two vectors of FieldDescriptors. 552 // two vectors of FieldDescriptors.
552 bool CompareWithFields(const Message& message1, const Message& message2, 553 bool CompareWithFields(
553 const vector<const FieldDescriptor*>& message1_fields, 554 const Message& message1, const Message& message2,
554 const vector<const FieldDescriptor*>& message2_fields); 555 const std::vector<const FieldDescriptor*>& message1_fields,
556 const std::vector<const FieldDescriptor*>& message2_fields);
555 557
556 // Automatically creates a reporter that will output the differences 558 // Automatically creates a reporter that will output the differences
557 // found (if any) to the specified output string pointer. Note that this 559 // found (if any) to the specified output string pointer. Note that this
558 // method must be called before Compare. 560 // method must be called before Compare.
559 void ReportDifferencesToString(string* output); 561 void ReportDifferencesToString(string* output);
560 562
561 // Tells the MessageDifferencer to report differences via the specified 563 // Tells the MessageDifferencer to report differences via the specified
562 // reporter. Note that this method must be called before Compare for 564 // reporter. Note that this method must be called before Compare for
563 // the reporter to be used. It is the responsibility of the caller to delete 565 // the reporter to be used. It is the responsibility of the caller to delete
564 // this object. 566 // this object.
565 // If the provided pointer equals NULL, the MessageDifferencer stops reporting 567 // If the provided pointer equals NULL, the MessageDifferencer stops reporting
566 // differences to any previously set reporters or output strings. 568 // differences to any previously set reporters or output strings.
567 void ReportDifferencesTo(Reporter* reporter); 569 void ReportDifferencesTo(Reporter* reporter);
568 570
569 // An implementation of the MessageDifferencer Reporter that outputs 571 // An implementation of the MessageDifferencer Reporter that outputs
570 // any differences found in human-readable form to the supplied 572 // any differences found in human-readable form to the supplied
571 // ZeroCopyOutputStream or Printer. If a printer is used, the delimiter 573 // ZeroCopyOutputStream or Printer. If a printer is used, the delimiter
572 // *must* be '$'. 574 // *must* be '$'.
575 //
576 // WARNING: this reporter does not necessarily flush its output until it is
577 // destroyed. As a result, it is not safe to assume the output is valid or
578 // complete until after you destroy the reporter. For example, if you use a
579 // StreamReporter to write to a StringOutputStream, the target string may
580 // contain uninitialized data until the reporter is destroyed.
573 class LIBPROTOBUF_EXPORT StreamReporter : public Reporter { 581 class LIBPROTOBUF_EXPORT StreamReporter : public Reporter {
574 public: 582 public:
575 explicit StreamReporter(io::ZeroCopyOutputStream* output); 583 explicit StreamReporter(io::ZeroCopyOutputStream* output);
576 explicit StreamReporter(io::Printer* printer); // delimiter '$' 584 explicit StreamReporter(io::Printer* printer); // delimiter '$'
577 virtual ~StreamReporter(); 585 virtual ~StreamReporter();
578 586
579 // When set to true, the stream reporter will also output aggregates nodes 587 // When set to true, the stream reporter will also output aggregates nodes
580 // (i.e. messages and groups) whose subfields have been modified. When 588 // (i.e. messages and groups) whose subfields have been modified. When
581 // false, will only report the individual subfields. Defaults to false. 589 // false, will only report the individual subfields. Defaults to false.
582 void set_report_modified_aggregates(bool report) { 590 void set_report_modified_aggregates(bool report) {
583 report_modified_aggregates_ = report; 591 report_modified_aggregates_ = report;
584 } 592 }
585 593
586 // The following are implementations of the methods described above. 594 // The following are implementations of the methods described above.
587 virtual void ReportAdded(const Message& message1, const Message& message2, 595 virtual void ReportAdded(const Message& message1, const Message& message2,
588 const vector<SpecificField>& field_path); 596 const std::vector<SpecificField>& field_path);
589 597
590 virtual void ReportDeleted(const Message& message1, 598 virtual void ReportDeleted(const Message& message1,
591 const Message& message2, 599 const Message& message2,
592 const vector<SpecificField>& field_path); 600 const std::vector<SpecificField>& field_path);
593 601
594 virtual void ReportModified(const Message& message1, 602 virtual void ReportModified(const Message& message1,
595 const Message& message2, 603 const Message& message2,
596 const vector<SpecificField>& field_path); 604 const std::vector<SpecificField>& field_path);
597 605
598 virtual void ReportMoved(const Message& message1, 606 virtual void ReportMoved(const Message& message1,
599 const Message& message2, 607 const Message& message2,
600 const vector<SpecificField>& field_path); 608 const std::vector<SpecificField>& field_path);
601 609
602 virtual void ReportMatched(const Message& message1, 610 virtual void ReportMatched(const Message& message1,
603 const Message& message2, 611 const Message& message2,
604 const vector<SpecificField>& field_path); 612 const std::vector<SpecificField>& field_path);
605 613
606 virtual void ReportIgnored(const Message& message1, 614 virtual void ReportIgnored(const Message& message1,
607 const Message& message2, 615 const Message& message2,
608 const vector<SpecificField>& field_path); 616 const std::vector<SpecificField>& field_path);
609 617
610 virtual void ReportUnknownFieldIgnored( 618 virtual void ReportUnknownFieldIgnored(
611 const Message& message1, const Message& message2, 619 const Message& message1, const Message& message2,
612 const vector<SpecificField>& field_path); 620 const std::vector<SpecificField>& field_path);
613 621
614 protected: 622 protected:
615 // Prints the specified path of fields to the buffer. 623 // Prints the specified path of fields to the buffer.
616 virtual void PrintPath(const vector<SpecificField>& field_path, 624 virtual void PrintPath(const std::vector<SpecificField>& field_path,
617 bool left_side); 625 bool left_side);
618 626
619 // Prints the value of fields to the buffer. left_side is true if the 627 // Prints the value of fields to the buffer. left_side is true if the
620 // given message is from the left side of the comparison, false if it 628 // given message is from the left side of the comparison, false if it
621 // was the right. This is relevant only to decide whether to follow 629 // was the right. This is relevant only to decide whether to follow
622 // unknown_field_index1 or unknown_field_index2 when an unknown field 630 // unknown_field_index1 or unknown_field_index2 when an unknown field
623 // is encountered in field_path. 631 // is encountered in field_path.
624 virtual void PrintValue(const Message& message, 632 virtual void PrintValue(const Message& message,
625 const vector<SpecificField>& field_path, 633 const std::vector<SpecificField>& field_path,
626 bool left_side); 634 bool left_side);
627 635
628 // Prints the specified path of unknown fields to the buffer. 636 // Prints the specified path of unknown fields to the buffer.
629 virtual void PrintUnknownFieldValue(const UnknownField* unknown_field); 637 virtual void PrintUnknownFieldValue(const UnknownField* unknown_field);
630 638
631 // Just print a string 639 // Just print a string
632 void Print(const string& str); 640 void Print(const string& str);
633 641
634 private: 642 private:
635 io::Printer* printer_; 643 io::Printer* printer_;
(...skipping 10 matching lines...) Expand all
646 // class is declared as a nested class of MessageDifferencer. 654 // class is declared as a nested class of MessageDifferencer.
647 class MultipleFieldsMapKeyComparator; 655 class MultipleFieldsMapKeyComparator;
648 // Returns true if field1's number() is less than field2's. 656 // Returns true if field1's number() is less than field2's.
649 static bool FieldBefore(const FieldDescriptor* field1, 657 static bool FieldBefore(const FieldDescriptor* field1,
650 const FieldDescriptor* field2); 658 const FieldDescriptor* field2);
651 659
652 // Combine the two lists of fields into the combined_fields output vector. 660 // Combine the two lists of fields into the combined_fields output vector.
653 // All fields present in both lists will always be included in the combined 661 // All fields present in both lists will always be included in the combined
654 // list. Fields only present in one of the lists will only appear in the 662 // list. Fields only present in one of the lists will only appear in the
655 // combined list if the corresponding fields_scope option is set to FULL. 663 // combined list if the corresponding fields_scope option is set to FULL.
656 void CombineFields(const vector<const FieldDescriptor*>& fields1, 664 void CombineFields(const std::vector<const FieldDescriptor*>& fields1,
657 Scope fields1_scope, 665 Scope fields1_scope,
658 const vector<const FieldDescriptor*>& fields2, 666 const std::vector<const FieldDescriptor*>& fields2,
659 Scope fields2_scope, 667 Scope fields2_scope,
660 vector<const FieldDescriptor*>* combined_fields); 668 std::vector<const FieldDescriptor*>* combined_fields);
661 669
662 // Internal version of the Compare method which performs the actual 670 // Internal version of the Compare method which performs the actual
663 // comparison. The parent_fields vector is a vector containing field 671 // comparison. The parent_fields vector is a vector containing field
664 // descriptors of all fields accessed to get to this comparison operation 672 // descriptors of all fields accessed to get to this comparison operation
665 // (i.e. if the current message is an embedded message, the parent_fields 673 // (i.e. if the current message is an embedded message, the parent_fields
666 // vector will contain the field that has this embedded message). 674 // vector will contain the field that has this embedded message).
667 bool Compare(const Message& message1, const Message& message2, 675 bool Compare(const Message& message1, const Message& message2,
668 vector<SpecificField>* parent_fields); 676 std::vector<SpecificField>* parent_fields);
669 677
670 // Compares all the unknown fields in two messages. 678 // Compares all the unknown fields in two messages.
671 bool CompareUnknownFields(const Message& message1, const Message& message2, 679 bool CompareUnknownFields(const Message& message1, const Message& message2,
672 const google::protobuf::UnknownFieldSet&, 680 const google::protobuf::UnknownFieldSet&,
673 const google::protobuf::UnknownFieldSet&, 681 const google::protobuf::UnknownFieldSet&,
674 vector<SpecificField>* parent_fields); 682 std::vector<SpecificField>* parent_fields);
675 683
676 // Compares the specified messages for the requested field lists. The field 684 // Compares the specified messages for the requested field lists. The field
677 // lists are modified depending on comparison settings, and then passed to 685 // lists are modified depending on comparison settings, and then passed to
678 // CompareWithFieldsInternal. 686 // CompareWithFieldsInternal.
679 bool CompareRequestedFieldsUsingSettings( 687 bool CompareRequestedFieldsUsingSettings(
680 const Message& message1, const Message& message2, 688 const Message& message1, const Message& message2,
681 const vector<const FieldDescriptor*>& message1_fields, 689 const std::vector<const FieldDescriptor*>& message1_fields,
682 const vector<const FieldDescriptor*>& message2_fields, 690 const std::vector<const FieldDescriptor*>& message2_fields,
683 vector<SpecificField>* parent_fields); 691 std::vector<SpecificField>* parent_fields);
684 692
685 // Compares the specified messages with the specified field lists. 693 // Compares the specified messages with the specified field lists.
686 bool CompareWithFieldsInternal( 694 bool CompareWithFieldsInternal(
687 const Message& message1, const Message& message2, 695 const Message& message1, const Message& message2,
688 const vector<const FieldDescriptor*>& message1_fields, 696 const std::vector<const FieldDescriptor*>& message1_fields,
689 const vector<const FieldDescriptor*>& message2_fields, 697 const std::vector<const FieldDescriptor*>& message2_fields,
690 vector<SpecificField>* parent_fields); 698 std::vector<SpecificField>* parent_fields);
691 699
692 // Compares the repeated fields, and report the error. 700 // Compares the repeated fields, and report the error.
693 bool CompareRepeatedField(const Message& message1, const Message& message2, 701 bool CompareRepeatedField(const Message& message1, const Message& message2,
694 const FieldDescriptor* field, 702 const FieldDescriptor* field,
695 vector<SpecificField>* parent_fields); 703 std::vector<SpecificField>* parent_fields);
696 704
697 // Shorthand for CompareFieldValueUsingParentFields with NULL parent_fields. 705 // Shorthand for CompareFieldValueUsingParentFields with NULL parent_fields.
698 bool CompareFieldValue(const Message& message1, 706 bool CompareFieldValue(const Message& message1,
699 const Message& message2, 707 const Message& message2,
700 const FieldDescriptor* field, 708 const FieldDescriptor* field,
701 int index1, 709 int index1,
702 int index2); 710 int index2);
703 711
704 // Compares the specified field on the two messages, returning 712 // Compares the specified field on the two messages, returning
705 // true if they are the same, false otherwise. For repeated fields, 713 // true if they are the same, false otherwise. For repeated fields,
706 // this method only compares the value in the specified index. This method 714 // this method only compares the value in the specified index. This method
707 // uses Compare functions to recurse into submessages. 715 // uses Compare functions to recurse into submessages.
708 // The parent_fields vector is used in calls to a Reporter instance calls. 716 // The parent_fields vector is used in calls to a Reporter instance calls.
709 // It can be NULL, in which case the MessageDifferencer will create new 717 // It can be NULL, in which case the MessageDifferencer will create new
710 // list of parent messages if it needs to recursively compare the given field. 718 // list of parent messages if it needs to recursively compare the given field.
711 // To avoid confusing users you should not set it to NULL unless you modified 719 // To avoid confusing users you should not set it to NULL unless you modified
712 // Reporter to handle the change of parent_fields correctly. 720 // Reporter to handle the change of parent_fields correctly.
713 bool CompareFieldValueUsingParentFields(const Message& message1, 721 bool CompareFieldValueUsingParentFields(
714 const Message& message2, 722 const Message& message1,
715 const FieldDescriptor* field, 723 const Message& message2,
716 int index1, 724 const FieldDescriptor* field,
717 int index2, 725 int index1,
718 vector<SpecificField>* parent_fields); 726 int index2,
727 std::vector<SpecificField>* parent_fields);
719 728
720 // Compares the specified field on the two messages, returning comparison 729 // Compares the specified field on the two messages, returning comparison
721 // result, as returned by appropriate FieldComparator. 730 // result, as returned by appropriate FieldComparator.
722 FieldComparator::ComparisonResult GetFieldComparisonResult( 731 FieldComparator::ComparisonResult GetFieldComparisonResult(
723 const Message& message1, const Message& message2, 732 const Message& message1, const Message& message2,
724 const FieldDescriptor* field, int index1, int index2, 733 const FieldDescriptor* field, int index1, int index2,
725 const FieldContext* field_context); 734 const FieldContext* field_context);
726 735
727 // Check if the two elements in the repeated field are match to each other. 736 // Check if the two elements in the repeated field are match to each other.
728 // if the key_comprator is NULL, this function returns true when the two 737 // if the key_comprator is NULL, this function returns true when the two
729 // elements are equal. 738 // elements are equal.
730 bool IsMatch(const FieldDescriptor* repeated_field, 739 bool IsMatch(const FieldDescriptor* repeated_field,
731 const MapKeyComparator* key_comparator, 740 const MapKeyComparator* key_comparator,
732 const Message* message1, const Message* message2, 741 const Message* message1, const Message* message2,
733 const vector<SpecificField>& parent_fields, 742 const std::vector<SpecificField>& parent_fields,
734 int index1, int index2); 743 int index1, int index2);
735 744
736 // Returns true when this repeated field has been configured to be treated 745 // Returns true when this repeated field has been configured to be treated
737 // as a set. 746 // as a set.
738 bool IsTreatedAsSet(const FieldDescriptor* field); 747 bool IsTreatedAsSet(const FieldDescriptor* field);
739 748
740 // Returns true when this repeated field is to be compared as a subset, ie. 749 // Returns true when this repeated field is to be compared as a subset, ie.
741 // has been configured to be treated as a set or map and scope is set to 750 // has been configured to be treated as a set or map and scope is set to
742 // PARTIAL. 751 // PARTIAL.
743 bool IsTreatedAsSubset(const FieldDescriptor* field); 752 bool IsTreatedAsSubset(const FieldDescriptor* field);
744 753
745 // Returns true if this field is to be ignored when this 754 // Returns true if this field is to be ignored when this
746 // MessageDifferencer compares messages. 755 // MessageDifferencer compares messages.
747 bool IsIgnored( 756 bool IsIgnored(
748 const Message& message1, 757 const Message& message1,
749 const Message& message2, 758 const Message& message2,
750 const FieldDescriptor* field, 759 const FieldDescriptor* field,
751 const vector<SpecificField>& parent_fields); 760 const std::vector<SpecificField>& parent_fields);
752 761
753 // Returns true if this unknown field is to be ignored when this 762 // Returns true if this unknown field is to be ignored when this
754 // MessageDifferencer compares messages. 763 // MessageDifferencer compares messages.
755 bool IsUnknownFieldIgnored(const Message& message1, const Message& message2, 764 bool IsUnknownFieldIgnored(const Message& message1, const Message& message2,
756 const SpecificField& field, 765 const SpecificField& field,
757 const vector<SpecificField>& parent_fields); 766 const std::vector<SpecificField>& parent_fields);
758 767
759 // Returns MapKeyComparator* when this field has been configured to 768 // Returns MapKeyComparator* when this field has been configured to
760 // be treated as a map. If not, returns NULL. 769 // be treated as a map. If not, returns NULL.
761 const MapKeyComparator* GetMapKeyComparator(const FieldDescriptor* field); 770 const MapKeyComparator* GetMapKeyComparator(const FieldDescriptor* field);
762 771
763 // Attempts to match indices of a repeated field, so that the contained values 772 // Attempts to match indices of a repeated field, so that the contained values
764 // match. Clears output vectors and sets their values to indices of paired 773 // match. Clears output vectors and sets their values to indices of paired
765 // messages, ie. if message1[0] matches message2[1], then match_list1[0] == 1 774 // messages, ie. if message1[0] matches message2[1], then match_list1[0] == 1
766 // and match_list2[1] == 0. The unmatched indices are indicated by -1. 775 // and match_list2[1] == 0. The unmatched indices are indicated by -1.
767 // This method returns false if the match failed. However, it doesn't mean 776 // This method returns false if the match failed. However, it doesn't mean
768 // that the comparison succeeds when this method returns true (you need to 777 // that the comparison succeeds when this method returns true (you need to
769 // double-check in this case). 778 // double-check in this case).
770 bool MatchRepeatedFieldIndices(const Message& message1, 779 bool MatchRepeatedFieldIndices(
771 const Message& message2, 780 const Message& message1,
772 const FieldDescriptor* repeated_field, 781 const Message& message2,
773 const vector<SpecificField>& parent_fields, 782 const FieldDescriptor* repeated_field,
774 vector<int>* match_list1, 783 const std::vector<SpecificField>& parent_fields,
775 vector<int>* match_list2); 784 std::vector<int>* match_list1,
785 std::vector<int>* match_list2);
776 786
777 // If "any" is of type google.protobuf.Any, extract its payload using 787 // If "any" is of type google.protobuf.Any, extract its payload using
778 // DynamicMessageFactory and store in "data". 788 // DynamicMessageFactory and store in "data".
779 bool UnpackAny(const Message& any, google::protobuf::scoped_ptr<Message>* data ); 789 bool UnpackAny(const Message& any, google::protobuf::scoped_ptr<Message>* data );
780 790
781 // Checks if index is equal to new_index in all the specific fields. 791 // Checks if index is equal to new_index in all the specific fields.
782 static bool CheckPathChanged(const vector<SpecificField>& parent_fields); 792 static bool CheckPathChanged(const std::vector<SpecificField>& parent_fields);
783 793
784 // Defines a map between field descriptors and their MapKeyComparators. 794 // Defines a map between field descriptors and their MapKeyComparators.
785 // Used for repeated fields when they are configured as TreatAsMap. 795 // Used for repeated fields when they are configured as TreatAsMap.
786 typedef map<const FieldDescriptor*, 796 typedef std::map<const FieldDescriptor*,
787 const MapKeyComparator*> FieldKeyComparatorMap; 797 const MapKeyComparator*> FieldKeyComparatorMap;
788 798
789 // Defines a set to store field descriptors. Used for repeated fields when 799 // Defines a set to store field descriptors. Used for repeated fields when
790 // they are configured as TreatAsSet. 800 // they are configured as TreatAsSet.
791 typedef set<const FieldDescriptor*> FieldSet; 801 typedef std::set<const FieldDescriptor*> FieldSet;
792 802
793 Reporter* reporter_; 803 Reporter* reporter_;
794 DefaultFieldComparator default_field_comparator_; 804 DefaultFieldComparator default_field_comparator_;
795 FieldComparator* field_comparator_; 805 FieldComparator* field_comparator_;
796 MessageFieldComparison message_field_comparison_; 806 MessageFieldComparison message_field_comparison_;
797 Scope scope_; 807 Scope scope_;
798 RepeatedFieldComparison repeated_field_comparison_; 808 RepeatedFieldComparison repeated_field_comparison_;
799 809
800 FieldSet set_fields_; 810 FieldSet set_fields_;
801 FieldSet list_fields_; 811 FieldSet list_fields_;
802 // Keeps track of MapKeyComparators that are created within 812 // Keeps track of MapKeyComparators that are created within
803 // MessageDifferencer. These MapKeyComparators should be deleted 813 // MessageDifferencer. These MapKeyComparators should be deleted
804 // before MessageDifferencer is destroyed. 814 // before MessageDifferencer is destroyed.
805 // When TreatAsMap or TreatAsMapWithMultipleFieldsAsKey is called, we don't 815 // When TreatAsMap or TreatAsMapWithMultipleFieldsAsKey is called, we don't
806 // store the supplied FieldDescriptors directly. Instead, a new 816 // store the supplied FieldDescriptors directly. Instead, a new
807 // MapKeyComparator is created for comparison purpose. 817 // MapKeyComparator is created for comparison purpose.
808 vector<MapKeyComparator*> owned_key_comparators_; 818 std::vector<MapKeyComparator*> owned_key_comparators_;
809 FieldKeyComparatorMap map_field_key_comparator_; 819 FieldKeyComparatorMap map_field_key_comparator_;
810 vector<IgnoreCriteria*> ignore_criteria_; 820 std::vector<IgnoreCriteria*> ignore_criteria_;
811 821
812 FieldSet ignored_fields_; 822 FieldSet ignored_fields_;
813 823
814 bool compare_unknown_fields_;
815 bool report_matches_; 824 bool report_matches_;
816 825
817 string* output_string_; 826 string* output_string_;
818 827
819 google::protobuf::scoped_ptr<DynamicMessageFactory> dynamic_message_factory_; 828 google::protobuf::scoped_ptr<DynamicMessageFactory> dynamic_message_factory_;
820 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageDifferencer); 829 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageDifferencer);
821 }; 830 };
822 831
823 // This class provides extra information to the FieldComparator::Compare 832 // This class provides extra information to the FieldComparator::Compare
824 // function. 833 // function.
825 class LIBPROTOBUF_EXPORT FieldContext { 834 class LIBPROTOBUF_EXPORT FieldContext {
826 public: 835 public:
827 explicit FieldContext( 836 explicit FieldContext(
828 vector<MessageDifferencer::SpecificField>* parent_fields) 837 std::vector<MessageDifferencer::SpecificField>* parent_fields)
829 : parent_fields_(parent_fields) {} 838 : parent_fields_(parent_fields) {}
830 839
831 vector<MessageDifferencer::SpecificField>* parent_fields() const { 840 std::vector<MessageDifferencer::SpecificField>* parent_fields() const {
832 return parent_fields_; 841 return parent_fields_;
833 } 842 }
834 843
835 private: 844 private:
836 vector<MessageDifferencer::SpecificField>* parent_fields_; 845 std::vector<MessageDifferencer::SpecificField>* parent_fields_;
837 }; 846 };
838 847
839 } 848 }
840 } 849 }
841 850
842 } // namespace google 851 } // namespace google
843 #endif // GOOGLE_PROTOBUF_UTIL_MESSAGE_DIFFERENCER_H__ 852 #endif // GOOGLE_PROTOBUF_UTIL_MESSAGE_DIFFERENCER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698