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

Side by Side Diff: third_party/protobuf/src/google/protobuf/generated_message_reflection.cc

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 6 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 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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 SWAP_ARRAYS(INT64 , int64 ); 405 SWAP_ARRAYS(INT64 , int64 );
406 SWAP_ARRAYS(UINT32, uint32); 406 SWAP_ARRAYS(UINT32, uint32);
407 SWAP_ARRAYS(UINT64, uint64); 407 SWAP_ARRAYS(UINT64, uint64);
408 SWAP_ARRAYS(FLOAT , float ); 408 SWAP_ARRAYS(FLOAT , float );
409 SWAP_ARRAYS(DOUBLE, double); 409 SWAP_ARRAYS(DOUBLE, double);
410 SWAP_ARRAYS(BOOL , bool ); 410 SWAP_ARRAYS(BOOL , bool );
411 SWAP_ARRAYS(ENUM , int ); 411 SWAP_ARRAYS(ENUM , int );
412 #undef SWAP_ARRAYS 412 #undef SWAP_ARRAYS
413 413
414 case FieldDescriptor::CPPTYPE_STRING: 414 case FieldDescriptor::CPPTYPE_STRING:
415 switch (field->options().ctype()) {
416 default: // TODO(kenton): Support other string reps.
417 case FieldOptions::STRING:
418 MutableRaw<RepeatedPtrFieldBase>(message1, field)->
419 Swap<GenericTypeHandler<string> >(
420 MutableRaw<RepeatedPtrFieldBase>(message2, field));
421 break;
422 }
423 break;
415 case FieldDescriptor::CPPTYPE_MESSAGE: 424 case FieldDescriptor::CPPTYPE_MESSAGE:
416 if (IsMapFieldInApi(field)) { 425 if (IsMapFieldInApi(field)) {
417 MutableRaw<MapFieldBase>(message1, field)-> 426 MutableRaw<MapFieldBase>(message1, field)->
418 MutableRepeatedField()-> 427 MutableRepeatedField()->
419 Swap<GenericTypeHandler<google::protobuf::Message> >( 428 Swap<GenericTypeHandler<google::protobuf::Message> >(
420 MutableRaw<MapFieldBase>(message2, field)-> 429 MutableRaw<MapFieldBase>(message2, field)->
421 MutableRepeatedField()); 430 MutableRepeatedField());
422 } else { 431 } else {
423 MutableRaw<RepeatedPtrFieldBase>(message1, field)-> 432 MutableRaw<RepeatedPtrFieldBase>(message1, field)->
424 Swap<GenericTypeHandler<google::protobuf::Message> >( 433 Swap<GenericTypeHandler<google::protobuf::Message> >(
(...skipping 15 matching lines...) Expand all
440 SWAP_VALUES(INT32 , int32 ); 449 SWAP_VALUES(INT32 , int32 );
441 SWAP_VALUES(INT64 , int64 ); 450 SWAP_VALUES(INT64 , int64 );
442 SWAP_VALUES(UINT32, uint32); 451 SWAP_VALUES(UINT32, uint32);
443 SWAP_VALUES(UINT64, uint64); 452 SWAP_VALUES(UINT64, uint64);
444 SWAP_VALUES(FLOAT , float ); 453 SWAP_VALUES(FLOAT , float );
445 SWAP_VALUES(DOUBLE, double); 454 SWAP_VALUES(DOUBLE, double);
446 SWAP_VALUES(BOOL , bool ); 455 SWAP_VALUES(BOOL , bool );
447 SWAP_VALUES(ENUM , int ); 456 SWAP_VALUES(ENUM , int );
448 #undef SWAP_VALUES 457 #undef SWAP_VALUES
449 case FieldDescriptor::CPPTYPE_MESSAGE: 458 case FieldDescriptor::CPPTYPE_MESSAGE:
450 std::swap(*MutableRaw<Message*>(message1, field), 459 if (GetArena(message1) == GetArena(message2)) {
451 *MutableRaw<Message*>(message2, field)); 460 std::swap(*MutableRaw<Message*>(message1, field),
461 *MutableRaw<Message*>(message2, field));
462 } else {
463 Message** sub_msg1 = MutableRaw<Message*>(message1, field);
464 Message** sub_msg2 = MutableRaw<Message*>(message2, field);
465 if (*sub_msg1 == NULL && *sub_msg2 == NULL) break;
466 if (*sub_msg1 && *sub_msg2) {
467 (*sub_msg1)->GetReflection()->Swap(*sub_msg1, *sub_msg2);
468 break;
469 }
470 if (*sub_msg1 == NULL) {
471 *sub_msg1 = (*sub_msg2)->New(message1->GetArena());
472 (*sub_msg1)->CopyFrom(**sub_msg2);
473 ClearField(message2, field);
474 } else {
475 *sub_msg2 = (*sub_msg1)->New(message2->GetArena());
476 (*sub_msg2)->CopyFrom(**sub_msg1);
477 ClearField(message1, field);
478 }
479 }
452 break; 480 break;
453 481
454 case FieldDescriptor::CPPTYPE_STRING: 482 case FieldDescriptor::CPPTYPE_STRING:
455 switch (field->options().ctype()) { 483 switch (field->options().ctype()) {
456 default: // TODO(kenton): Support other string reps. 484 default: // TODO(kenton): Support other string reps.
457 case FieldOptions::STRING: 485 case FieldOptions::STRING:
458 MutableRaw<ArenaStringPtr>(message1, field)->Swap( 486 {
459 MutableRaw<ArenaStringPtr>(message2, field)); 487 Arena* arena1 = GetArena(message1);
488 Arena* arena2 = GetArena(message2);
489 ArenaStringPtr* string1 =
490 MutableRaw<ArenaStringPtr>(message1, field);
491 ArenaStringPtr* string2 =
492 MutableRaw<ArenaStringPtr>(message2, field);
493 if (arena1 == arena2) {
494 string1->Swap(string2);
495 } else {
496 const string* default_ptr =
497 &DefaultRaw<ArenaStringPtr>(field).Get(NULL);
498 const string temp = string1->Get(default_ptr);
499 string1->Set(default_ptr, string2->Get(default_ptr), arena1);
500 string2->Set(default_ptr, temp, arena2);
501 }
502 }
460 break; 503 break;
461 } 504 }
462 break; 505 break;
463 506
464 default: 507 default:
465 GOOGLE_LOG(FATAL) << "Unimplemented type: " << field->cpp_type(); 508 GOOGLE_LOG(FATAL) << "Unimplemented type: " << field->cpp_type();
466 } 509 }
467 } 510 }
468 } 511 }
469 512
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 1788
1746 bool GeneratedMessageReflection::InsertOrLookupMapValue( 1789 bool GeneratedMessageReflection::InsertOrLookupMapValue(
1747 Message* message, 1790 Message* message,
1748 const FieldDescriptor* field, 1791 const FieldDescriptor* field,
1749 const MapKey& key, 1792 const MapKey& key,
1750 MapValueRef* val) const { 1793 MapValueRef* val) const {
1751 USAGE_CHECK(IsMapFieldInApi(field), 1794 USAGE_CHECK(IsMapFieldInApi(field),
1752 "InsertOrLookupMapValue", 1795 "InsertOrLookupMapValue",
1753 "Field is not a map field."); 1796 "Field is not a map field.");
1754 val->SetType(field->message_type()->FindFieldByName("value")->cpp_type()); 1797 val->SetType(field->message_type()->FindFieldByName("value")->cpp_type());
1755 return MutableRaw<MapFieldBase>(message, field)->InsertMapValue(key, val); 1798 return MutableRaw<MapFieldBase>(message, field)->InsertOrLookupMapValue(
1799 key, val);
1756 } 1800 }
1757 1801
1758 bool GeneratedMessageReflection::DeleteMapValue( 1802 bool GeneratedMessageReflection::DeleteMapValue(
1759 Message* message, 1803 Message* message,
1760 const FieldDescriptor* field, 1804 const FieldDescriptor* field,
1761 const MapKey& key) const { 1805 const MapKey& key) const {
1762 USAGE_CHECK(IsMapFieldInApi(field), 1806 USAGE_CHECK(IsMapFieldInApi(field),
1763 "DeleteMapValue", 1807 "DeleteMapValue",
1764 "Field is not a map field."); 1808 "Field is not a map field.");
1765 return MutableRaw<MapFieldBase>(message, field)->DeleteMapValue(key); 1809 return MutableRaw<MapFieldBase>(message, field)->DeleteMapValue(key);
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
2265 DescriptorPool::generated_pool(), 2309 DescriptorPool::generated_pool(),
2266 MessageFactory::generated_factory(), 2310 MessageFactory::generated_factory(),
2267 object_size, 2311 object_size,
2268 arena_offset, 2312 arena_offset,
2269 is_default_instance_offset); 2313 is_default_instance_offset);
2270 } 2314 }
2271 2315
2272 } // namespace internal 2316 } // namespace internal
2273 } // namespace protobuf 2317 } // namespace protobuf
2274 } // namespace google 2318 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698