OLD | NEW |
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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 // ------------------------------ NOTE ------------------------------ | 39 // ------------------------------ NOTE ------------------------------ |
40 // At the moment, this is all using NSNumbers in NSDictionaries under | 40 // At the moment, this is all using NSNumbers in NSDictionaries under |
41 // the hood, but it is all hidden so we can come back and optimize | 41 // the hood, but it is all hidden so we can come back and optimize |
42 // with direct CFDictionary usage later. The reason that wasn't | 42 // with direct CFDictionary usage later. The reason that wasn't |
43 // done yet is needing to support 32bit iOS builds. Otherwise | 43 // done yet is needing to support 32bit iOS builds. Otherwise |
44 // it would be pretty simple to store all this data in CFDictionaries | 44 // it would be pretty simple to store all this data in CFDictionaries |
45 // directly. | 45 // directly. |
46 // ------------------------------------------------------------------ | 46 // ------------------------------------------------------------------ |
47 | 47 |
48 // Direct access is use for speed, to avoid even internally declaring things | |
49 // read/write, etc. The warning is enabled in the project to ensure code calling | |
50 // protos can turn on -Wdirect-ivar-access without issues. | |
51 #pragma clang diagnostic push | |
52 #pragma clang diagnostic ignored "-Wdirect-ivar-access" | |
53 | |
54 // Used to include code only visible to specific versions of the static | 48 // Used to include code only visible to specific versions of the static |
55 // analyzer. Useful for wrapping code that only exists to silence the analyzer. | 49 // analyzer. Useful for wrapping code that only exists to silence the analyzer. |
56 // Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION, | 50 // Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION, |
57 // END_APPLE_BUILD_VERSION using: | 51 // END_APPLE_BUILD_VERSION using: |
58 // xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__ | 52 // xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__ |
59 // Example usage: | 53 // Example usage: |
60 // #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif | 54 // #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif |
61 #define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERS
ION) \ | 55 #define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERS
ION) \ |
62 (defined(__clang_analyzer__) && \ | 56 (defined(__clang_analyzer__) && \ |
63 (__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \ | 57 (__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \ |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 } | 477 } |
484 } | 478 } |
485 } | 479 } |
486 | 480 |
487 if (!hitError) { | 481 if (!hitError) { |
488 // Handle the special defaults and/or missing key/value. | 482 // Handle the special defaults and/or missing key/value. |
489 if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) { | 483 if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) { |
490 key.valueString = [@"" retain]; | 484 key.valueString = [@"" retain]; |
491 } | 485 } |
492 if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) { | 486 if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) { |
493 #pragma clang diagnostic push | |
494 #pragma clang diagnostic ignored "-Wswitch-enum" | |
495 switch (valueDataType) { | 487 switch (valueDataType) { |
496 case GPBDataTypeString: | 488 case GPBDataTypeString: |
497 value.valueString = [@"" retain]; | 489 value.valueString = [@"" retain]; |
498 break; | 490 break; |
499 case GPBDataTypeBytes: | 491 case GPBDataTypeBytes: |
500 value.valueData = [GPBEmptyNSData() retain]; | 492 value.valueData = [GPBEmptyNSData() retain]; |
501 break; | 493 break; |
502 #if defined(__clang_analyzer__) | 494 #if defined(__clang_analyzer__) |
503 case GPBDataTypeGroup: | 495 case GPBDataTypeGroup: |
504 // Maps can't really have Groups as the value type, but this case is n
eeded | 496 // Maps can't really have Groups as the value type, but this case is n
eeded |
505 // so the analyzer won't report the posibility of send nil in for the
value | 497 // so the analyzer won't report the posibility of send nil in for the
value |
506 // in the NSMutableDictionary case below. | 498 // in the NSMutableDictionary case below. |
507 #endif | 499 #endif |
508 case GPBDataTypeMessage: { | 500 case GPBDataTypeMessage: { |
509 value.valueMessage = [[field.msgClass alloc] init]; | 501 value.valueMessage = [[field.msgClass alloc] init]; |
510 break; | 502 break; |
511 } | 503 } |
512 default: | 504 default: |
513 // Nothing | 505 // Nothing |
514 break; | 506 break; |
515 } | 507 } |
516 #pragma clang diagnostic pop | |
517 } | 508 } |
518 | 509 |
519 if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)
) { | 510 if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)
) { |
520 #if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181) | 511 #if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181) |
521 // Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can | 512 // Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can |
522 // be raised as needed for new Xcodes. | 513 // be raised as needed for new Xcodes. |
523 // | 514 // |
524 // This is only needed on a "shallow" analyze; on a "deep" analyze, the | 515 // This is only needed on a "shallow" analyze; on a "deep" analyze, the |
525 // existing code path gets this correct. In shallow, the analyzer decides | 516 // existing code path gets this correct. In shallow, the analyzer decides |
526 // GPBDataTypeIsObject(valueDataType) is both false and true on a single | 517 // GPBDataTypeIsObject(valueDataType) is both false and true on a single |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPE
R) | 561 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPE
R) |
571 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER) | 562 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER) |
572 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPE
R) | 563 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPE
R) |
573 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER) | 564 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER) |
574 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER) | 565 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER) |
575 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER) | 566 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER) |
576 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER) | 567 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER) |
577 //%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER) | 568 //%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER) |
578 | 569 |
579 //%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME,
VALUE_TYPE, KHELPER) | 570 //%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME,
VALUE_TYPE, KHELPER) |
580 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHEL
PER, POD, VALUE_NAME, value) | 571 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHEL
PER, POD, value) |
581 | 572 |
582 //%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME,
VALUE_TYPE) | 573 //%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME,
VALUE_TYPE) |
583 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJ
ECT, Object, object) | 574 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJ
ECT, object) |
584 | 575 |
585 //%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALU
E_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR) | 576 //%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALU
E_TYPE, KHELPER, VHELPER, VNAME) |
586 //%#pragma mark - KEY_NAME -> VALUE_NAME | 577 //%#pragma mark - KEY_NAME -> VALUE_NAME |
587 //% | 578 //% |
588 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { | 579 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { |
589 //% @package | 580 //% @package |
590 //% NSMutableDictionary *_dictionary; | 581 //% NSMutableDictionary *_dictionary; |
591 //%} | 582 //%} |
592 //% | 583 //% |
593 //%+ (instancetype)dictionary { | 584 //%+ (instancetype)dictionary { |
594 //% return [[[self alloc] initWith##VNAME##s:NULL forKeys:NULL count:0] autorel
ease]; | 585 //% return [[[self alloc] initWith##VNAME$u##s:NULL forKeys:NULL count:0] autor
elease]; |
595 //%} | 586 //%} |
596 //% | 587 //% |
597 //%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)##VNAME_VAR | 588 //%+ (instancetype)dictionaryWith##VNAME$u##:(VALUE_TYPE)##VNAME |
598 //% ##VNAME$S## forKey:(KEY_TYPE##KisP$S##KisP)key { | 589 //% ##VNAME$S## forKey:(KEY_TYPE##KisP$S##KisP)key { |
599 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME##s:forKeys:count: | 590 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME$u##s:forKeys:count: |
600 //% // on to get the type correct. | 591 //% // on to get the type correct. |
601 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNA
ME##s:&##VNAME_VAR | 592 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNA
ME$u##s:&##VNAME |
602 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## fo
rKeys:&key | 593 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## fo
rKeys:&key |
603 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S##
count:1] autorelease]; | 594 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S##
count:1] autorelease]; |
604 //%} | 595 //%} |
605 //% | 596 //% |
606 //%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s | 597 //%+ (instancetype)dictionaryWith##VNAME$u##s:(const VALUE_TYPE [])##VNAME##s |
607 //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])k
eys | 598 //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])k
eys |
608 //% ##VNAME$S## count:(NSUInteger)count { | 599 //% ##VNAME$S## count:(NSUInteger)count { |
609 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME##s:forKeys:count: | 600 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME$u##s:forKeys:count: |
610 //% // on to get the type correct. | 601 //% // on to get the type correct. |
611 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNA
ME##s:##VNAME_VAR##s | 602 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNA
ME$u##s:##VNAME##s |
612 //% KEY_NAME$S VALUE_NAME$S forKeys:
keys | 603 //% KEY_NAME$S VALUE_NAME$S forKeys:
keys |
613 //% KEY_NAME$S VALUE_NAME$S count:
count] autorelease]; | 604 //% KEY_NAME$S VALUE_NAME$S count:
count] autorelease]; |
614 //%} | 605 //%} |
615 //% | 606 //% |
616 //%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictiona
ry *)dictionary { | 607 //%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictiona
ry *)dictionary { |
617 //% // Cast is needed so the compiler knows what class we are invoking initWith
Dictionary: | 608 //% // Cast is needed so the compiler knows what class we are invoking initWith
Dictionary: |
618 //% // on to get the type correct. | 609 //% // on to get the type correct. |
619 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDicti
onary:dictionary] autorelease]; | 610 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDicti
onary:dictionary] autorelease]; |
620 //%} | 611 //%} |
621 //% | 612 //% |
622 //%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 613 //%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
623 //% return [[[self alloc] initWithCapacity:numItems] autorelease]; | 614 //% return [[[self alloc] initWithCapacity:numItems] autorelease]; |
624 //%} | 615 //%} |
625 //% | 616 //% |
626 //%- (instancetype)init { | 617 //%- (instancetype)init { |
627 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; | 618 //% return [self initWith##VNAME$u##s:NULL forKeys:NULL count:0]; |
628 //%} | 619 //%} |
629 //% | 620 //% |
630 //%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s | 621 //%- (instancetype)initWith##VNAME$u##s:(const VALUE_TYPE [])##VNAME##s |
631 //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys | 622 //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys |
632 //% ##VNAME$S## count:(NSUInteger)count { | 623 //% ##VNAME$S## count:(NSUInteger)count { |
633 //% self = [super init]; | 624 //% self = [super init]; |
634 //% if (self) { | 625 //% if (self) { |
635 //% _dictionary = [[NSMutableDictionary alloc] init]; | 626 //% _dictionary = [[NSMutableDictionary alloc] init]; |
636 //% if (count && VNAME_VAR##s && keys) { | 627 //% if (count && VNAME##s && keys) { |
637 //% for (NSUInteger i = 0; i < count; ++i) { | 628 //% for (NSUInteger i = 0; i < count; ++i) { |
638 //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR##s[i], ______)##DICTIONARY_VALI
DATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELP
ER(VNAME_VAR##s[i]) forKey:WRAPPED##KHELPER(keys[i])]; | 629 //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME##s[i], ______)##DICTIONARY_VALIDATE
_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(V
NAME##s[i]) forKey:WRAPPED##KHELPER(keys[i])]; |
639 //% } | 630 //% } |
640 //% } | 631 //% } |
641 //% } | 632 //% } |
642 //% return self; | 633 //% return self; |
643 //%} | 634 //%} |
644 //% | 635 //% |
645 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)d
ictionary { | 636 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)d
ictionary { |
646 //% self = [self initWith##VNAME##s:NULL forKeys:NULL count:0]; | 637 //% self = [self initWith##VNAME$u##s:NULL forKeys:NULL count:0]; |
647 //% if (self) { | 638 //% if (self) { |
648 //% if (dictionary) { | 639 //% if (dictionary) { |
649 //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 640 //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
650 //% } | 641 //% } |
651 //% } | 642 //% } |
652 //% return self; | 643 //% return self; |
653 //%} | 644 //%} |
654 //% | 645 //% |
655 //%- (instancetype)initWithCapacity:(NSUInteger)numItems { | 646 //%- (instancetype)initWithCapacity:(NSUInteger)numItems { |
656 //% #pragma unused(numItems) | 647 //% #pragma unused(numItems) |
657 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; | 648 //% return [self initWith##VNAME$u##s:NULL forKeys:NULL count:0]; |
658 //%} | 649 //%} |
659 //% | 650 //% |
660 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, K
HELPER, VHELPER, VNAME, VNAME_VAR, ) | 651 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, K
HELPER, VHELPER, VNAME, ) |
661 //% | 652 //% |
662 //%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELP
ER) | 653 //%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELP
ER) |
663 //% | 654 //% |
664 //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHE
LPER, VHELPER, VNAME, VNAME_VAR, ) | 655 //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHE
LPER, VHELPER, VNAME, ) |
665 //% | 656 //% |
666 //%@end | 657 //%@end |
667 //% | 658 //% |
668 | 659 |
669 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME,
VALUE_TYPE, KHELPER) | 660 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME,
VALUE_TYPE, KHELPER) |
670 //%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE
, KHELPER, POD) | 661 //%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE
, KHELPER, POD) |
671 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME
, VALUE_TYPE, KHELPER, VHELPER) | 662 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME
, VALUE_TYPE, KHELPER, VHELPER) |
672 //%#pragma mark - KEY_NAME -> VALUE_NAME | 663 //%#pragma mark - KEY_NAME -> VALUE_NAME |
673 //% | 664 //% |
674 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { | 665 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 //% } | 755 //% } |
765 //% return self; | 756 //% return self; |
766 //%} | 757 //%} |
767 //% | 758 //% |
768 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | 759 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func |
769 //% capacity:(NSUInteger)numItems { | 760 //% capacity:(NSUInteger)numItems { |
770 //% #pragma unused(numItems) | 761 //% #pragma unused(numItems) |
771 //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL co
unt:0]; | 762 //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL co
unt:0]; |
772 //%} | 763 //%} |
773 //% | 764 //% |
774 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, K
HELPER, VHELPER, Value, value, Raw) | 765 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, K
HELPER, VHELPER, value, Raw) |
775 //% | 766 //% |
776 //%- (BOOL)getEnum:(VALUE_TYPE *)value forKey:(KEY_TYPE##KisP$S##KisP)key { | 767 //%- (BOOL)valueForKey:(KEY_TYPE##KisP$S##KisP)key value:(VALUE_TYPE *)value { |
777 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; | 768 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; |
778 //% if (wrapped && value) { | 769 //% if (wrapped && value) { |
779 //% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped); | 770 //% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped); |
780 //% if (!_validationFunc(result)) { | 771 //% if (!_validationFunc(result)) { |
781 //% result = kGPBUnrecognizedEnumeratorValue; | 772 //% result = kGPBUnrecognizedEnumeratorValue; |
782 //% } | 773 //% } |
783 //% *value = result; | 774 //% *value = result; |
784 //% } | 775 //% } |
785 //% return (wrapped != NULL); | 776 //% return (wrapped != NULL); |
786 //%} | 777 //%} |
787 //% | 778 //% |
788 //%- (BOOL)getRawValue:(VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key
{ | 779 //%- (BOOL)valueForKey:(KEY_TYPE##KisP$S##KisP)key rawValue:(VALUE_TYPE *)rawVal
ue { |
789 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; | 780 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; |
790 //% if (wrapped && rawValue) { | 781 //% if (wrapped && rawValue) { |
791 //% *rawValue = UNWRAP##VALUE_NAME(wrapped); | 782 //% *rawValue = UNWRAP##VALUE_NAME(wrapped); |
792 //% } | 783 //% } |
793 //% return (wrapped != NULL); | 784 //% return (wrapped != NULL); |
794 //%} | 785 //%} |
795 //% | 786 //% |
796 //%- (void)enumerateKeysAndEnumsUsingBlock: | 787 //%- (void)enumerateKeysAndValuesUsingBlock: |
797 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block { | 788 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block { |
798 //% GPBEnumValidationFunc func = _validationFunc; | 789 //% GPBEnumValidationFunc func = _validationFunc; |
799 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | 790 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, |
800 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##aValue, | 791 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##aValue, |
801 //% BOOL *stop) { | 792 //% BOOL *stop) { |
802 //% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue); | 793 //% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue); |
803 //% if (!func(unwrapped)) { | 794 //% if (!func(unwrapped)) { |
804 //% unwrapped = kGPBUnrecognizedEnumeratorValue; | 795 //% unwrapped = kGPBUnrecognizedEnumeratorValue; |
805 //% } | 796 //% } |
806 //% block(UNWRAP##KEY_NAME(aKey), unwrapped, stop); | 797 //% block(UNWRAP##KEY_NAME(aKey), unwrapped, stop); |
807 //% }]; | 798 //% }]; |
808 //%} | 799 //%} |
809 //% | 800 //% |
810 //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KH
ELPER, VHELPER, Value, Enum, value, Raw) | 801 //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHE
LPER, VHELPER, value, Raw) |
811 //% | 802 //% |
812 //%- (void)setEnum:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key { | 803 //%- (void)setValue:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key { |
813 //%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) { | 804 //%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) { |
814 //% [NSException raise:NSInvalidArgumentException | 805 //% [NSException raise:NSInvalidArgumentException |
815 //% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to se
t an unknown enum value (%d)", | 806 //% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to se
t an unknown enum value (%d)", |
816 //% value]; | 807 //% value]; |
817 //% } | 808 //% } |
818 //% | 809 //% |
819 //% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)
]; | 810 //% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)
]; |
820 //% if (_autocreator) { | 811 //% if (_autocreator) { |
821 //% GPBAutocreatedDictionaryModified(_autocreator, self); | 812 //% GPBAutocreatedDictionaryModified(_autocreator, self); |
822 //% } | 813 //% } |
823 //%} | 814 //%} |
824 //% | 815 //% |
825 //%@end | 816 //%@end |
826 //% | 817 //% |
827 | 818 |
828 //%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, V
ALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME) | 819 //%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, V
ALUE_TYPE, KHELPER, VHELPER, VNAME, ACCESSOR_NAME) |
829 //%- (void)dealloc { | 820 //%- (void)dealloc { |
830 //% NSAssert(!_autocreator, | 821 //% NSAssert(!_autocreator, |
831 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, | 822 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, |
832 //% [self class], _autocreator); | 823 //% [self class], _autocreator); |
833 //% [_dictionary release]; | 824 //% [_dictionary release]; |
834 //% [super dealloc]; | 825 //% [super dealloc]; |
835 //%} | 826 //%} |
836 //% | 827 //% |
837 //%- (instancetype)copyWithZone:(NSZone *)zone { | 828 //%- (instancetype)copyWithZone:(NSZone *)zone { |
838 //% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWith
Dictionary:self]; | 829 //% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWith
Dictionary:self]; |
839 //%} | 830 //%} |
840 //% | 831 //% |
841 //%- (BOOL)isEqual:(id)other { | 832 //%- (BOOL)isEqual:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)other { |
842 //% if (self == other) { | 833 //% if (self == other) { |
843 //% return YES; | 834 //% return YES; |
844 //% } | 835 //% } |
845 //% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) { | 836 //% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) { |
846 //% return NO; | 837 //% return NO; |
847 //% } | 838 //% } |
848 //% GPB##KEY_NAME##VALUE_NAME##Dictionary *otherDictionary = other; | 839 //% return [_dictionary isEqual:other->_dictionary]; |
849 //% return [_dictionary isEqual:otherDictionary->_dictionary]; | |
850 //%} | 840 //%} |
851 //% | 841 //% |
852 //%- (NSUInteger)hash { | 842 //%- (NSUInteger)hash { |
853 //% return _dictionary.count; | 843 //% return _dictionary.count; |
854 //%} | 844 //%} |
855 //% | 845 //% |
856 //%- (NSString *)description { | 846 //%- (NSString *)description { |
857 //% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _d
ictionary]; | 847 //% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _d
ictionary]; |
858 //%} | 848 //%} |
859 //% | 849 //% |
860 //%- (NSUInteger)count { | 850 //%- (NSUInteger)count { |
861 //% return _dictionary.count; | 851 //% return _dictionary.count; |
862 //%} | 852 //%} |
863 //% | 853 //% |
864 //%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock: | 854 //%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME$u##sUsingBlock: |
865 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block { | 855 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME, BOOL *stop))block { |
866 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | 856 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, |
867 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME_VAR$u, | 857 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME$u, |
868 //% BOOL *stop) { | 858 //% BOOL *stop) { |
869 //% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), stop)
; | 859 //% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME$u), stop); |
870 //% }]; | 860 //% }]; |
871 //%} | 861 //%} |
872 //% | 862 //% |
873 //%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeA
sField:(GPBFieldDescriptor *)field { | 863 //%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeA
sField:(GPBFieldDescriptor *)field { |
874 //% NSUInteger count = _dictionary.count; | 864 //% NSUInteger count = _dictionary.count; |
875 //% if (count == 0) { | 865 //% if (count == 0) { |
876 //% return 0; | 866 //% return 0; |
877 //% } | 867 //% } |
878 //% | 868 //% |
879 //% GPBDataType valueDataType = GPBGetFieldDataType(field); | 869 //% GPBDataType valueDataType = GPBGetFieldDataType(field); |
880 //% GPBDataType keyDataType = field.mapKeyDataType; | 870 //% GPBDataType keyDataType = field.mapKeyDataType; |
881 //% __block size_t result = 0; | 871 //% __block size_t result = 0; |
882 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | 872 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, |
883 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME_VAR$u##, | 873 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME$u##, |
884 //% BOOL *stop) { | 874 //% BOOL *stop) { |
885 //% #pragma unused(stop) | 875 //% #pragma unused(stop) |
886 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey),
kMapKeyFieldNumber, keyDataType); | 876 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey),
kMapKeyFieldNumber, keyDataType); |
887 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME
_VAR$u), kMapValueFieldNumber, valueDataType); | 877 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME
$u), kMapValueFieldNumber, valueDataType); |
888 //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | 878 //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; |
889 //% }]; | 879 //% }]; |
890 //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBData
TypeMessage); | 880 //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBData
TypeMessage); |
891 //% result += tagSize * count; | 881 //% result += tagSize * count; |
892 //% return result; | 882 //% return result; |
893 //%} | 883 //%} |
894 //% | 884 //% |
895 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | 885 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream |
896 //% asField:(GPBFieldDescriptor *)field { | 886 //% asField:(GPBFieldDescriptor *)field { |
897 //% GPBDataType valueDataType = GPBGetFieldDataType(field); | 887 //% GPBDataType valueDataType = GPBGetFieldDataType(field); |
898 //% GPBDataType keyDataType = field.mapKeyDataType; | 888 //% GPBDataType keyDataType = field.mapKeyDataType; |
899 //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLen
gthDelimited); | 889 //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLen
gthDelimited); |
900 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | 890 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, |
901 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME_VAR$u, | 891 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME$u, |
902 //% BOOL *stop) { | 892 //% BOOL *stop) { |
903 //% #pragma unused(stop) | 893 //% #pragma unused(stop) |
904 //% // Write the tag. | 894 //% // Write the tag. |
905 //% [outputStream writeInt32NoTag:tag]; | 895 //% [outputStream writeInt32NoTag:tag]; |
906 //% // Write the size of the message. | 896 //% // Write the size of the message. |
907 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey),
kMapKeyFieldNumber, keyDataType); | 897 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey),
kMapKeyFieldNumber, keyDataType); |
908 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME
_VAR$u), kMapValueFieldNumber, valueDataType); | 898 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME
$u), kMapValueFieldNumber, valueDataType); |
909 //% [outputStream writeInt32NoTag:(int32_t)msgSize]; | 899 //% [outputStream writeInt32NoTag:(int32_t)msgSize]; |
910 //% // Write the fields. | 900 //% // Write the fields. |
911 //% WriteDict##KEY_NAME##Field(outputStream, UNWRAP##KEY_NAME(aKey), kMapKeyF
ieldNumber, keyDataType); | 901 //% WriteDict##KEY_NAME##Field(outputStream, UNWRAP##KEY_NAME(aKey), kMapKeyF
ieldNumber, keyDataType); |
912 //% WriteDict##VALUE_NAME##Field(outputStream, UNWRAP##VALUE_NAME(a##VNAME_VA
R$u), kMapValueFieldNumber, valueDataType); | 902 //% WriteDict##VALUE_NAME##Field(outputStream, UNWRAP##VALUE_NAME(a##VNAME$u)
, kMapValueFieldNumber, valueDataType); |
913 //% }]; | 903 //% }]; |
914 //%} | 904 //%} |
915 //% | 905 //% |
916 //%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericVal
ue:(GPBGenericValue *)value | 906 //%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericVal
ue:(GPBGenericValue *)value |
917 //% forGPBGenericValueKey:(GPBGenericValue *)key { | 907 //% forGPBGenericValueKey:(GPBGenericValue *)key { |
918 //% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_N
AME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)]; | 908 //% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_N
AME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)]; |
919 //%} | 909 //%} |
920 //% | 910 //% |
921 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 911 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
922 //% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##
key, VALUE_TYPE VNAME_VAR, BOOL *stop) { | 912 //% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME$u##sUsingBlock:^(KEY_TYPE KisP
##key, VALUE_TYPE VNAME, BOOL *stop) { |
923 //% #pragma unused(stop) | 913 //% #pragma unused(stop) |
924 //% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME
_VAR)); | 914 //% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME
)); |
925 //% }]; | 915 //% }]; |
926 //%} | 916 //%} |
927 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VAL
UE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME) | 917 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VAL
UE_TYPE, KHELPER, VHELPER, VNAME, ACCESSOR_NAME) |
928 //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KH
ELPER, VHELPER, VNAME, VNAME, VNAME_VAR, ACCESSOR_NAME) | |
929 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VA
LUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_REMOVE, VNAME_VAR, ACCESSOR_NAME) | |
930 //%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME#
#Dictionary *)otherDictionary { | 918 //%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME#
#Dictionary *)otherDictionary { |
931 //% if (otherDictionary) { | 919 //% if (otherDictionary) { |
932 //% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 920 //% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
933 //% if (_autocreator) { | 921 //% if (_autocreator) { |
934 //% GPBAutocreatedDictionaryModified(_autocreator, self); | 922 //% GPBAutocreatedDictionaryModified(_autocreator, self); |
935 //% } | 923 //% } |
936 //% } | 924 //% } |
937 //%} | 925 //%} |
938 //% | 926 //% |
939 //%- (void)set##ACCESSOR_NAME##VNAME##:(VALUE_TYPE)VNAME_VAR forKey:(KEY_TYPE##K
isP$S##KisP)key { | 927 //%- (void)set##ACCESSOR_NAME##VNAME$u##:(VALUE_TYPE)VNAME forKey:(KEY_TYPE##Kis
P$S##KisP)key { |
940 //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR, )##DICTIONARY_VALIDATE_KEY_##K
HELPER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR) forKey:WRAPPED
##KHELPER(key)]; | 928 //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME, )##DICTIONARY_VALIDATE_KEY_##KHELP
ER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME) forKey:WRAPPED##KHELPE
R(key)]; |
941 //% if (_autocreator) { | 929 //% if (_autocreator) { |
942 //% GPBAutocreatedDictionaryModified(_autocreator, self); | 930 //% GPBAutocreatedDictionaryModified(_autocreator, self); |
943 //% } | 931 //% } |
944 //%} | 932 //%} |
945 //% | 933 //% |
946 //%- (void)remove##VNAME_REMOVE##ForKey:(KEY_TYPE##KisP$S##KisP)aKey { | 934 //%- (void)remove##VNAME$u##ForKey:(KEY_TYPE##KisP$S##KisP)aKey { |
947 //% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)]; | 935 //% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)]; |
948 //%} | 936 //%} |
949 //% | 937 //% |
950 //%- (void)removeAll { | 938 //%- (void)removeAll { |
951 //% [_dictionary removeAllObjects]; | 939 //% [_dictionary removeAllObjects]; |
952 //%} | 940 //%} |
953 | 941 |
954 // | 942 // |
955 // Custom Generation for Bool keys | 943 // Custom Generation for Bool keys |
956 // | 944 // |
957 | 945 |
958 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE) | 946 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE) |
959 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, va
lue) | 947 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, value) |
960 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE) | 948 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE) |
961 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, Object, obj
ect) | 949 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, object) |
962 | 950 |
963 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER,
VNAME, VNAME_VAR) | 951 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER,
VNAME) |
964 //%#pragma mark - Bool -> VALUE_NAME | 952 //%#pragma mark - Bool -> VALUE_NAME |
965 //% | 953 //% |
966 //%@implementation GPBBool##VALUE_NAME##Dictionary { | 954 //%@implementation GPBBool##VALUE_NAME##Dictionary { |
967 //% @package | 955 //% @package |
968 //% VALUE_TYPE _values[2]; | 956 //% VALUE_TYPE _values[2]; |
969 //%BOOL_DICT_HAS_STORAGE_##HELPER()} | 957 //%BOOL_DICT_HAS_STORAGE_##HELPER()} |
970 //% | 958 //% |
971 //%+ (instancetype)dictionary { | 959 //%+ (instancetype)dictionary { |
972 //% return [[[self alloc] initWith##VNAME##s:NULL forKeys:NULL count:0] autorel
ease]; | 960 //% return [[[self alloc] initWith##VNAME$u##s:NULL forKeys:NULL count:0] autor
elease]; |
973 //%} | 961 //%} |
974 //% | 962 //% |
975 //%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)VNAME_VAR | 963 //%+ (instancetype)dictionaryWith##VNAME$u##:(VALUE_TYPE)VNAME |
976 //% ##VNAME$S## forKey:(BOOL)key { | 964 //% ##VNAME$S## forKey:(BOOL)key { |
977 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME##s:forKeys:count: | 965 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME$u##s:forKeys:count: |
978 //% // on to get the type correct. | 966 //% // on to get the type correct. |
979 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:
&##VNAME_VAR | 967 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME$u##
s:&##VNAME |
980 //% VALUE_NAME$S ##VNAME$S## forKeys:
&key | 968 //% VALUE_NAME$S ##VNAME$S## forKeys:
&key |
981 //% VALUE_NAME$S ##VNAME$S## count:
1] autorelease]; | 969 //% VALUE_NAME$S ##VNAME$S## count:
1] autorelease]; |
982 //%} | 970 //%} |
983 //% | 971 //% |
984 //%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s | 972 //%+ (instancetype)dictionaryWith##VNAME$u##s:(const VALUE_TYPE [])##VNAME##s |
985 //% ##VNAME$S## forKeys:(const BOOL [])keys | 973 //% ##VNAME$S## forKeys:(const BOOL [])keys |
986 //% ##VNAME$S## count:(NSUInteger)count { | 974 //% ##VNAME$S## count:(NSUInteger)count { |
987 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME##s:forKeys:count: | 975 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME$u##s:forKeys:count: |
988 //% // on to get the type correct. | 976 //% // on to get the type correct. |
989 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:
##VNAME_VAR##s | 977 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME$u##
s:##VNAME##s |
990 //% VALUE_NAME$S ##VNAME$S## forKeys:
keys | 978 //% VALUE_NAME$S ##VNAME$S## forKeys:
keys |
991 //% VALUE_NAME$S ##VNAME$S## count:
count] autorelease]; | 979 //% VALUE_NAME$S ##VNAME$S## count:
count] autorelease]; |
992 //%} | 980 //%} |
993 //% | 981 //% |
994 //%+ (instancetype)dictionaryWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)d
ictionary { | 982 //%+ (instancetype)dictionaryWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)d
ictionary { |
995 //% // Cast is needed so the compiler knows what class we are invoking initWith
Dictionary: | 983 //% // Cast is needed so the compiler knows what class we are invoking initWith
Dictionary: |
996 //% // on to get the type correct. | 984 //% // on to get the type correct. |
997 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:
dictionary] autorelease]; | 985 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:
dictionary] autorelease]; |
998 //%} | 986 //%} |
999 //% | 987 //% |
1000 //%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 988 //%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
1001 //% return [[[self alloc] initWithCapacity:numItems] autorelease]; | 989 //% return [[[self alloc] initWithCapacity:numItems] autorelease]; |
1002 //%} | 990 //%} |
1003 //% | 991 //% |
1004 //%- (instancetype)init { | 992 //%- (instancetype)init { |
1005 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; | 993 //% return [self initWith##VNAME$u##s:NULL forKeys:NULL count:0]; |
1006 //%} | 994 //%} |
1007 //% | 995 //% |
1008 //%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE) | 996 //%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE) |
1009 //% | 997 //% |
1010 //%- (instancetype)initWithCapacity:(NSUInteger)numItems { | 998 //%- (instancetype)initWithCapacity:(NSUInteger)numItems { |
1011 //% #pragma unused(numItems) | 999 //% #pragma unused(numItems) |
1012 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; | 1000 //% return [self initWith##VNAME$u##s:NULL forKeys:NULL count:0]; |
1013 //%} | 1001 //%} |
1014 //% | 1002 //% |
1015 //%BOOL_DICT_DEALLOC##HELPER() | 1003 //%BOOL_DICT_DEALLOC##HELPER() |
1016 //% | 1004 //% |
1017 //%- (instancetype)copyWithZone:(NSZone *)zone { | 1005 //%- (instancetype)copyWithZone:(NSZone *)zone { |
1018 //% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictio
nary:self]; | 1006 //% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictio
nary:self]; |
1019 //%} | 1007 //%} |
1020 //% | 1008 //% |
1021 //%- (BOOL)isEqual:(id)other { | 1009 //%- (BOOL)isEqual:(GPBBool##VALUE_NAME##Dictionary *)other { |
1022 //% if (self == other) { | 1010 //% if (self == other) { |
1023 //% return YES; | 1011 //% return YES; |
1024 //% } | 1012 //% } |
1025 //% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) { | 1013 //% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) { |
1026 //% return NO; | 1014 //% return NO; |
1027 //% } | 1015 //% } |
1028 //% GPBBool##VALUE_NAME##Dictionary *otherDictionary = other; | 1016 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, other->)) |
| |
1029 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, otherDictio
nary->)) || | 1017 //% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, other->)))
{ |
1030 //% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, otherDictio
nary->))) { | |
1031 //% return NO; | 1018 //% return NO; |
1032 //% } | 1019 //% } |
1033 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], otherDiction
ary->_values[0]))) || | 1020 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], other->_valu
es[0]))) || |
1034 //% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], otherDiction
ary->_values[1])))) { | 1021 //% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], other->_valu
es[1])))) { |
1035 //% return NO; | 1022 //% return NO; |
1036 //% } | 1023 //% } |
1037 //% return YES; | 1024 //% return YES; |
1038 //%} | 1025 //%} |
1039 //% | 1026 //% |
1040 //%- (NSUInteger)hash { | 1027 //%- (NSUInteger)hash { |
1041 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1,
) ? 1 : 0); | 1028 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1,
) ? 1 : 0); |
1042 //%} | 1029 //%} |
1043 //% | 1030 //% |
1044 //%- (NSString *)description { | 1031 //%- (NSString *)description { |
1045 //% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [
self class], self]; | 1032 //% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [
self class], self]; |
1046 //% if (BOOL_DICT_W_HAS##HELPER(0, )) { | 1033 //% if (BOOL_DICT_W_HAS##HELPER(0, )) { |
1047 //% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]]; | 1034 //% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]]; |
1048 //% } | 1035 //% } |
1049 //% if (BOOL_DICT_W_HAS##HELPER(1, )) { | 1036 //% if (BOOL_DICT_W_HAS##HELPER(1, )) { |
1050 //% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]]
; | 1037 //% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]]
; |
1051 //% } | 1038 //% } |
1052 //% [result appendString:@" }"]; | 1039 //% [result appendString:@" }"]; |
1053 //% return result; | 1040 //% return result; |
1054 //%} | 1041 //%} |
1055 //% | 1042 //% |
1056 //%- (NSUInteger)count { | 1043 //%- (NSUInteger)count { |
1057 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1,
) ? 1 : 0); | 1044 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1,
) ? 1 : 0); |
1058 //%} | 1045 //%} |
1059 //% | 1046 //% |
1060 //%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE) | 1047 //%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_TYPE) |
1061 //% | 1048 //% |
1062 //%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP) | 1049 //%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP) |
1063 //% | 1050 //% |
1064 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 1051 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
1065 //% if (BOOL_DICT_HAS##HELPER(0, )) { | 1052 //% if (BOOL_DICT_HAS##HELPER(0, )) { |
1066 //% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0])); | 1053 //% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0])); |
1067 //% } | 1054 //% } |
1068 //% if (BOOL_DICT_W_HAS##HELPER(1, )) { | 1055 //% if (BOOL_DICT_W_HAS##HELPER(1, )) { |
1069 //% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1])); | 1056 //% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1])); |
1070 //% } | 1057 //% } |
1071 //%} | 1058 //%} |
1072 //% | 1059 //% |
1073 //%- (void)enumerateKeysAnd##VNAME##sUsingBlock: | 1060 //%- (void)enumerateKeysAnd##VNAME$u##sUsingBlock: |
1074 //% (void (^)(BOOL key, VALUE_TYPE VNAME_VAR, BOOL *stop))block { | 1061 //% (void (^)(BOOL key, VALUE_TYPE VNAME, BOOL *stop))block { |
1075 //% BOOL stop = NO; | 1062 //% BOOL stop = NO; |
1076 //% if (BOOL_DICT_HAS##HELPER(0, )) { | 1063 //% if (BOOL_DICT_HAS##HELPER(0, )) { |
1077 //% block(NO, _values[0], &stop); | 1064 //% block(NO, _values[0], &stop); |
1078 //% } | 1065 //% } |
1079 //% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) { | 1066 //% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) { |
1080 //% block(YES, _values[1], &stop); | 1067 //% block(YES, _values[1], &stop); |
1081 //% } | 1068 //% } |
1082 //%} | 1069 //%} |
1083 //% | 1070 //% |
1084 //%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeA
sField:(GPBFieldDescriptor *)field { | 1071 //%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeA
sField:(GPBFieldDescriptor *)field { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 //% | 1108 //% |
1122 //%@end | 1109 //%@end |
1123 //% | 1110 //% |
1124 | 1111 |
1125 | 1112 |
1126 // | 1113 // |
1127 // Helpers for PODs | 1114 // Helpers for PODs |
1128 // | 1115 // |
1129 | 1116 |
1130 //%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER) | 1117 //%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER) |
1131 //%- (BOOL)get##VALUE_NAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key { | 1118 //%- (BOOL)valueForKey:(KEY_TYPE)key value:(VALUE_TYPE *)value { |
1132 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; | 1119 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; |
1133 //% if (wrapped && value) { | 1120 //% if (wrapped && value) { |
1134 //% *value = UNWRAP##VALUE_NAME(wrapped); | 1121 //% *value = UNWRAP##VALUE_NAME(wrapped); |
1135 //% } | 1122 //% } |
1136 //% return (wrapped != NULL); | 1123 //% return (wrapped != NULL); |
1137 //%} | 1124 //%} |
1138 //%PDDM-DEFINE WRAPPEDPOD(VALUE) | 1125 //%PDDM-DEFINE WRAPPEDPOD(VALUE) |
1139 //%@(VALUE) | 1126 //%@(VALUE) |
1140 //%PDDM-DEFINE UNWRAPUInt32(VALUE) | 1127 //%PDDM-DEFINE UNWRAPUInt32(VALUE) |
1141 //%[VALUE unsignedIntValue] | 1128 //%[VALUE unsignedIntValue] |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 //%value##VALUE_NAME | 1198 //%value##VALUE_NAME |
1212 //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT) | 1199 //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT) |
1213 // Empty | 1200 // Empty |
1214 //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT) | 1201 //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT) |
1215 // Empty | 1202 // Empty |
1216 | 1203 |
1217 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD() | 1204 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD() |
1218 //% BOOL _valueSet[2]; | 1205 //% BOOL _valueSet[2]; |
1219 //% | 1206 //% |
1220 //%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE) | 1207 //%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE) |
1221 //%- (instancetype)initWith##VALUE_NAME##s:(const VALUE_TYPE [])values | 1208 //%- (instancetype)initWithValues:(const VALUE_TYPE [])values |
1222 //% ##VALUE_NAME$S## forKeys:(const BOOL [])keys | 1209 //% forKeys:(const BOOL [])keys |
1223 //% ##VALUE_NAME$S## count:(NSUInteger)count { | 1210 //% count:(NSUInteger)count { |
1224 //% self = [super init]; | 1211 //% self = [super init]; |
1225 //% if (self) { | 1212 //% if (self) { |
1226 //% for (NSUInteger i = 0; i < count; ++i) { | 1213 //% for (NSUInteger i = 0; i < count; ++i) { |
1227 //% int idx = keys[i] ? 1 : 0; | 1214 //% int idx = keys[i] ? 1 : 0; |
1228 //% _values[idx] = values[i]; | 1215 //% _values[idx] = values[i]; |
1229 //% _valueSet[idx] = YES; | 1216 //% _valueSet[idx] = YES; |
1230 //% } | 1217 //% } |
1231 //% } | 1218 //% } |
1232 //% return self; | 1219 //% return self; |
1233 //%} | 1220 //%} |
1234 //% | 1221 //% |
1235 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)diction
ary { | 1222 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)diction
ary { |
1236 //% self = [self initWith##VALUE_NAME##s:NULL forKeys:NULL count:0]; | 1223 //% self = [self initWithValues:NULL forKeys:NULL count:0]; |
1237 //% if (self) { | 1224 //% if (self) { |
1238 //% if (dictionary) { | 1225 //% if (dictionary) { |
1239 //% for (int i = 0; i < 2; ++i) { | 1226 //% for (int i = 0; i < 2; ++i) { |
1240 //% if (dictionary->_valueSet[i]) { | 1227 //% if (dictionary->_valueSet[i]) { |
1241 //% _values[i] = dictionary->_values[i]; | 1228 //% _values[i] = dictionary->_values[i]; |
1242 //% _valueSet[i] = YES; | 1229 //% _valueSet[i] = YES; |
1243 //% } | 1230 //% } |
1244 //% } | 1231 //% } |
1245 //% } | 1232 //% } |
1246 //% } | 1233 //% } |
1247 //% return self; | 1234 //% return self; |
1248 //%} | 1235 //%} |
1249 //%PDDM-DEFINE BOOL_DICT_DEALLOCPOD() | 1236 //%PDDM-DEFINE BOOL_DICT_DEALLOCPOD() |
1250 //%#if !defined(NS_BLOCK_ASSERTIONS) | 1237 //%#if !defined(NS_BLOCK_ASSERTIONS) |
1251 //%- (void)dealloc { | 1238 //%- (void)dealloc { |
1252 //% NSAssert(!_autocreator, | 1239 //% NSAssert(!_autocreator, |
1253 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, | 1240 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, |
1254 //% [self class], _autocreator); | 1241 //% [self class], _autocreator); |
1255 //% [super dealloc]; | 1242 //% [super dealloc]; |
1256 //%} | 1243 //%} |
1257 //%#endif // !defined(NS_BLOCK_ASSERTIONS) | 1244 //%#endif // !defined(NS_BLOCK_ASSERTIONS) |
1258 //%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF) | 1245 //%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF) |
1259 //%BOOL_DICT_HASPOD(IDX, REF) | 1246 //%BOOL_DICT_HASPOD(IDX, REF) |
1260 //%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF) | 1247 //%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF) |
1261 //%REF##_valueSet[IDX] | 1248 //%REF##_valueSet[IDX] |
1262 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE) | 1249 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_TYPE) |
1263 //%- (BOOL)get##VALUE_NAME##:(VALUE_TYPE *)value forKey:(BOOL)key { | 1250 //%- (BOOL)valueForKey:(BOOL)key value:(VALUE_TYPE *)value { |
1264 //% int idx = (key ? 1 : 0); | 1251 //% int idx = (key ? 1 : 0); |
1265 //% if (_valueSet[idx]) { | 1252 //% if (_valueSet[idx]) { |
1266 //% if (value) { | 1253 //% if (value) { |
1267 //% *value = _values[idx]; | 1254 //% *value = _values[idx]; |
1268 //% } | 1255 //% } |
1269 //% return YES; | 1256 //% return YES; |
1270 //% } | 1257 //% } |
1271 //% return NO; | 1258 //% return NO; |
1272 //%} | 1259 //%} |
1273 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP) | 1260 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP) |
(...skipping 11 matching lines...) Expand all Loading... |
1285 //% _valueSet[i] = YES; | 1272 //% _valueSet[i] = YES; |
1286 //% _values[i] = otherDictionary->_values[i]; | 1273 //% _values[i] = otherDictionary->_values[i]; |
1287 //% } | 1274 //% } |
1288 //% } | 1275 //% } |
1289 //% if (_autocreator) { | 1276 //% if (_autocreator) { |
1290 //% GPBAutocreatedDictionaryModified(_autocreator, self); | 1277 //% GPBAutocreatedDictionaryModified(_autocreator, self); |
1291 //% } | 1278 //% } |
1292 //% } | 1279 //% } |
1293 //%} | 1280 //%} |
1294 //% | 1281 //% |
1295 //%- (void)set##VALUE_NAME:(VALUE_TYPE)value forKey:(BOOL)key { | 1282 //%- (void)setValue:(VALUE_TYPE)value forKey:(BOOL)key { |
1296 //% int idx = (key ? 1 : 0); | 1283 //% int idx = (key ? 1 : 0); |
1297 //% _values[idx] = value; | 1284 //% _values[idx] = value; |
1298 //% _valueSet[idx] = YES; | 1285 //% _valueSet[idx] = YES; |
1299 //% if (_autocreator) { | 1286 //% if (_autocreator) { |
1300 //% GPBAutocreatedDictionaryModified(_autocreator, self); | 1287 //% GPBAutocreatedDictionaryModified(_autocreator, self); |
1301 //% } | 1288 //% } |
1302 //%} | 1289 //%} |
1303 //% | 1290 //% |
1304 //%- (void)remove##VALUE_NAME##ForKey:(BOOL)aKey { | 1291 //%- (void)removeValueForKey:(BOOL)aKey { |
1305 //% _valueSet[aKey ? 1 : 0] = NO; | 1292 //% _valueSet[aKey ? 1 : 0] = NO; |
1306 //%} | 1293 //%} |
1307 //% | 1294 //% |
1308 //%- (void)removeAll { | 1295 //%- (void)removeAll { |
1309 //% _valueSet[0] = NO; | 1296 //% _valueSet[0] = NO; |
1310 //% _valueSet[1] = NO; | 1297 //% _valueSet[1] = NO; |
1311 //%} | 1298 //%} |
1312 //%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME) | 1299 //%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME) |
1313 //%STR_FORMAT_##VALUE_NAME() | 1300 //%STR_FORMAT_##VALUE_NAME() |
1314 //%PDDM-DEFINE STR_FORMAT_UInt32() | 1301 //%PDDM-DEFINE STR_FORMAT_UInt32() |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, | 1442 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, |
1456 //% [self class], _autocreator); | 1443 //% [self class], _autocreator); |
1457 //% [_values[0] release]; | 1444 //% [_values[0] release]; |
1458 //% [_values[1] release]; | 1445 //% [_values[1] release]; |
1459 //% [super dealloc]; | 1446 //% [super dealloc]; |
1460 //%} | 1447 //%} |
1461 //%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF) | 1448 //%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF) |
1462 //%(BOOL_DICT_HASOBJECT(IDX, REF)) | 1449 //%(BOOL_DICT_HASOBJECT(IDX, REF)) |
1463 //%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF) | 1450 //%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF) |
1464 //%REF##_values[IDX] != nil | 1451 //%REF##_values[IDX] != nil |
1465 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE) | 1452 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_TYPE) |
1466 //%- (VALUE_TYPE)objectForKey:(BOOL)key { | 1453 //%- (VALUE_TYPE)objectForKey:(BOOL)key { |
1467 //% return _values[key ? 1 : 0]; | 1454 //% return _values[key ? 1 : 0]; |
1468 //%} | 1455 //%} |
1469 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP) | 1456 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP) |
1470 //%- (void)setGPBGenericValue:(GPBGenericValue *)value | 1457 //%- (void)setGPBGenericValue:(GPBGenericValue *)value |
1471 //% forGPBGenericValueKey:(GPBGenericValue *)key { | 1458 //% forGPBGenericValueKey:(GPBGenericValue *)key { |
1472 //% int idx = (key->valueBool ? 1 : 0); | 1459 //% int idx = (key->valueBool ? 1 : 0); |
1473 //% [_values[idx] release]; | 1460 //% [_values[idx] release]; |
1474 //% _values[idx] = [value->valueString retain]; | 1461 //% _values[idx] = [value->valueString retain]; |
1475 //%} | 1462 //%} |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 // This block of code is generated, do not edit it directly. | 1509 // This block of code is generated, do not edit it directly. |
1523 | 1510 |
1524 #pragma mark - UInt32 -> UInt32 | 1511 #pragma mark - UInt32 -> UInt32 |
1525 | 1512 |
1526 @implementation GPBUInt32UInt32Dictionary { | 1513 @implementation GPBUInt32UInt32Dictionary { |
1527 @package | 1514 @package |
1528 NSMutableDictionary *_dictionary; | 1515 NSMutableDictionary *_dictionary; |
1529 } | 1516 } |
1530 | 1517 |
1531 + (instancetype)dictionary { | 1518 + (instancetype)dictionary { |
1532 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; | 1519 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
1533 } | 1520 } |
1534 | 1521 |
1535 + (instancetype)dictionaryWithUInt32:(uint32_t)value | 1522 + (instancetype)dictionaryWithValue:(uint32_t)value |
1536 forKey:(uint32_t)key { | 1523 forKey:(uint32_t)key { |
1537 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 1524 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
1538 // on to get the type correct. | 1525 // on to get the type correct. |
1539 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithUInt32s:&value | 1526 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithValues:&value |
1540 forKeys:&key | 1527 forKeys:&key |
1541 count:1] autorelea
se]; | 1528 count:1] autoreleas
e]; |
1542 } | 1529 } |
1543 | 1530 |
1544 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values | 1531 + (instancetype)dictionaryWithValues:(const uint32_t [])values |
1545 forKeys:(const uint32_t [])keys | 1532 forKeys:(const uint32_t [])keys |
1546 count:(NSUInteger)count { | 1533 count:(NSUInteger)count { |
1547 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 1534 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
1548 // on to get the type correct. | 1535 // on to get the type correct. |
1549 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithUInt32s:values | 1536 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithValues:values |
1550 forKeys:keys | 1537 forKeys:keys |
1551 count:count] autore
lease]; | 1538 count:count] autore
lease]; |
1552 } | 1539 } |
1553 | 1540 |
1554 + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary
{ | 1541 + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary
{ |
1555 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 1542 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
1556 // on to get the type correct. | 1543 // on to get the type correct. |
1557 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 1544 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
1558 } | 1545 } |
1559 | 1546 |
1560 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 1547 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
1561 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 1548 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
1562 } | 1549 } |
1563 | 1550 |
1564 - (instancetype)init { | 1551 - (instancetype)init { |
1565 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 1552 return [self initWithValues:NULL forKeys:NULL count:0]; |
1566 } | 1553 } |
1567 | 1554 |
1568 - (instancetype)initWithUInt32s:(const uint32_t [])values | 1555 - (instancetype)initWithValues:(const uint32_t [])values |
1569 forKeys:(const uint32_t [])keys | 1556 forKeys:(const uint32_t [])keys |
1570 count:(NSUInteger)count { | 1557 count:(NSUInteger)count { |
1571 self = [super init]; | 1558 self = [super init]; |
1572 if (self) { | 1559 if (self) { |
1573 _dictionary = [[NSMutableDictionary alloc] init]; | 1560 _dictionary = [[NSMutableDictionary alloc] init]; |
1574 if (count && values && keys) { | 1561 if (count && values && keys) { |
1575 for (NSUInteger i = 0; i < count; ++i) { | 1562 for (NSUInteger i = 0; i < count; ++i) { |
1576 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 1563 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
1577 } | 1564 } |
1578 } | 1565 } |
1579 } | 1566 } |
1580 return self; | 1567 return self; |
1581 } | 1568 } |
1582 | 1569 |
1583 - (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary { | 1570 - (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary { |
1584 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; | 1571 self = [self initWithValues:NULL forKeys:NULL count:0]; |
1585 if (self) { | 1572 if (self) { |
1586 if (dictionary) { | 1573 if (dictionary) { |
1587 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 1574 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
1588 } | 1575 } |
1589 } | 1576 } |
1590 return self; | 1577 return self; |
1591 } | 1578 } |
1592 | 1579 |
1593 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 1580 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
1594 #pragma unused(numItems) | 1581 #pragma unused(numItems) |
1595 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 1582 return [self initWithValues:NULL forKeys:NULL count:0]; |
1596 } | 1583 } |
1597 | 1584 |
1598 - (void)dealloc { | 1585 - (void)dealloc { |
1599 NSAssert(!_autocreator, | 1586 NSAssert(!_autocreator, |
1600 @"%@: Autocreator must be cleared before release, autocreator: %@", | 1587 @"%@: Autocreator must be cleared before release, autocreator: %@", |
1601 [self class], _autocreator); | 1588 [self class], _autocreator); |
1602 [_dictionary release]; | 1589 [_dictionary release]; |
1603 [super dealloc]; | 1590 [super dealloc]; |
1604 } | 1591 } |
1605 | 1592 |
1606 - (instancetype)copyWithZone:(NSZone *)zone { | 1593 - (instancetype)copyWithZone:(NSZone *)zone { |
1607 return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; | 1594 return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; |
1608 } | 1595 } |
1609 | 1596 |
1610 - (BOOL)isEqual:(id)other { | 1597 - (BOOL)isEqual:(GPBUInt32UInt32Dictionary *)other { |
1611 if (self == other) { | 1598 if (self == other) { |
1612 return YES; | 1599 return YES; |
1613 } | 1600 } |
1614 if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) { | 1601 if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) { |
1615 return NO; | 1602 return NO; |
1616 } | 1603 } |
1617 GPBUInt32UInt32Dictionary *otherDictionary = other; | 1604 return [_dictionary isEqual:other->_dictionary]; |
1618 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
1619 } | 1605 } |
1620 | 1606 |
1621 - (NSUInteger)hash { | 1607 - (NSUInteger)hash { |
1622 return _dictionary.count; | 1608 return _dictionary.count; |
1623 } | 1609 } |
1624 | 1610 |
1625 - (NSString *)description { | 1611 - (NSString *)description { |
1626 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 1612 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
1627 } | 1613 } |
1628 | 1614 |
1629 - (NSUInteger)count { | 1615 - (NSUInteger)count { |
1630 return _dictionary.count; | 1616 return _dictionary.count; |
1631 } | 1617 } |
1632 | 1618 |
1633 - (void)enumerateKeysAndUInt32sUsingBlock: | 1619 - (void)enumerateKeysAndValuesUsingBlock: |
1634 (void (^)(uint32_t key, uint32_t value, BOOL *stop))block { | 1620 (void (^)(uint32_t key, uint32_t value, BOOL *stop))block { |
1635 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 1621 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
1636 NSNumber *aValue, | 1622 NSNumber *aValue, |
1637 BOOL *stop) { | 1623 BOOL *stop) { |
1638 block([aKey unsignedIntValue], [aValue unsignedIntValue], stop); | 1624 block([aKey unsignedIntValue], [aValue unsignedIntValue], stop); |
1639 }]; | 1625 }]; |
1640 } | 1626 } |
1641 | 1627 |
1642 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 1628 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
1643 NSUInteger count = _dictionary.count; | 1629 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | 1667 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); |
1682 }]; | 1668 }]; |
1683 } | 1669 } |
1684 | 1670 |
1685 - (void)setGPBGenericValue:(GPBGenericValue *)value | 1671 - (void)setGPBGenericValue:(GPBGenericValue *)value |
1686 forGPBGenericValueKey:(GPBGenericValue *)key { | 1672 forGPBGenericValueKey:(GPBGenericValue *)key { |
1687 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)]; | 1673 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)]; |
1688 } | 1674 } |
1689 | 1675 |
1690 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 1676 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
1691 [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, BOOL *
stop) { | 1677 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, uint32_t value, BOOL *s
top) { |
1692 #pragma unused(stop) | 1678 #pragma unused(stop) |
1693 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%u", value]); | 1679 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%u", value]); |
1694 }]; | 1680 }]; |
1695 } | 1681 } |
1696 | 1682 |
1697 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key { | 1683 - (BOOL)valueForKey:(uint32_t)key value:(uint32_t *)value { |
1698 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 1684 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
1699 if (wrapped && value) { | 1685 if (wrapped && value) { |
1700 *value = [wrapped unsignedIntValue]; | 1686 *value = [wrapped unsignedIntValue]; |
1701 } | 1687 } |
1702 return (wrapped != NULL); | 1688 return (wrapped != NULL); |
1703 } | 1689 } |
1704 | 1690 |
1705 - (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary { | 1691 - (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary { |
1706 if (otherDictionary) { | 1692 if (otherDictionary) { |
1707 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 1693 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
1708 if (_autocreator) { | 1694 if (_autocreator) { |
1709 GPBAutocreatedDictionaryModified(_autocreator, self); | 1695 GPBAutocreatedDictionaryModified(_autocreator, self); |
1710 } | 1696 } |
1711 } | 1697 } |
1712 } | 1698 } |
1713 | 1699 |
1714 - (void)setUInt32:(uint32_t)value forKey:(uint32_t)key { | 1700 - (void)setValue:(uint32_t)value forKey:(uint32_t)key { |
1715 [_dictionary setObject:@(value) forKey:@(key)]; | 1701 [_dictionary setObject:@(value) forKey:@(key)]; |
1716 if (_autocreator) { | 1702 if (_autocreator) { |
1717 GPBAutocreatedDictionaryModified(_autocreator, self); | 1703 GPBAutocreatedDictionaryModified(_autocreator, self); |
1718 } | 1704 } |
1719 } | 1705 } |
1720 | 1706 |
1721 - (void)removeUInt32ForKey:(uint32_t)aKey { | 1707 - (void)removeValueForKey:(uint32_t)aKey { |
1722 [_dictionary removeObjectForKey:@(aKey)]; | 1708 [_dictionary removeObjectForKey:@(aKey)]; |
1723 } | 1709 } |
1724 | 1710 |
1725 - (void)removeAll { | 1711 - (void)removeAll { |
1726 [_dictionary removeAllObjects]; | 1712 [_dictionary removeAllObjects]; |
1727 } | 1713 } |
1728 | 1714 |
1729 @end | 1715 @end |
1730 | 1716 |
1731 #pragma mark - UInt32 -> Int32 | 1717 #pragma mark - UInt32 -> Int32 |
1732 | 1718 |
1733 @implementation GPBUInt32Int32Dictionary { | 1719 @implementation GPBUInt32Int32Dictionary { |
1734 @package | 1720 @package |
1735 NSMutableDictionary *_dictionary; | 1721 NSMutableDictionary *_dictionary; |
1736 } | 1722 } |
1737 | 1723 |
1738 + (instancetype)dictionary { | 1724 + (instancetype)dictionary { |
1739 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; | 1725 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
1740 } | 1726 } |
1741 | 1727 |
1742 + (instancetype)dictionaryWithInt32:(int32_t)value | 1728 + (instancetype)dictionaryWithValue:(int32_t)value |
1743 forKey:(uint32_t)key { | 1729 forKey:(uint32_t)key { |
1744 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 1730 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
1745 // on to get the type correct. | 1731 // on to get the type correct. |
1746 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithInt32s:&value | 1732 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithValues:&value |
1747 forKeys:&key | 1733 forKeys:&key |
1748 count:1] autorelease
]; | 1734 count:1] autorelease
]; |
1749 } | 1735 } |
1750 | 1736 |
1751 + (instancetype)dictionaryWithInt32s:(const int32_t [])values | 1737 + (instancetype)dictionaryWithValues:(const int32_t [])values |
1752 forKeys:(const uint32_t [])keys | 1738 forKeys:(const uint32_t [])keys |
1753 count:(NSUInteger)count { | 1739 count:(NSUInteger)count { |
1754 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 1740 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
1755 // on to get the type correct. | 1741 // on to get the type correct. |
1756 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithInt32s:values | 1742 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithValues:values |
1757 forKeys:keys | 1743 forKeys:keys |
1758 count:count] autorel
ease]; | 1744 count:count] autorel
ease]; |
1759 } | 1745 } |
1760 | 1746 |
1761 + (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary
{ | 1747 + (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary
{ |
1762 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 1748 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
1763 // on to get the type correct. | 1749 // on to get the type correct. |
1764 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 1750 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
1765 } | 1751 } |
1766 | 1752 |
1767 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 1753 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
1768 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 1754 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
1769 } | 1755 } |
1770 | 1756 |
1771 - (instancetype)init { | 1757 - (instancetype)init { |
1772 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 1758 return [self initWithValues:NULL forKeys:NULL count:0]; |
1773 } | 1759 } |
1774 | 1760 |
1775 - (instancetype)initWithInt32s:(const int32_t [])values | 1761 - (instancetype)initWithValues:(const int32_t [])values |
1776 forKeys:(const uint32_t [])keys | 1762 forKeys:(const uint32_t [])keys |
1777 count:(NSUInteger)count { | 1763 count:(NSUInteger)count { |
1778 self = [super init]; | 1764 self = [super init]; |
1779 if (self) { | 1765 if (self) { |
1780 _dictionary = [[NSMutableDictionary alloc] init]; | 1766 _dictionary = [[NSMutableDictionary alloc] init]; |
1781 if (count && values && keys) { | 1767 if (count && values && keys) { |
1782 for (NSUInteger i = 0; i < count; ++i) { | 1768 for (NSUInteger i = 0; i < count; ++i) { |
1783 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 1769 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
1784 } | 1770 } |
1785 } | 1771 } |
1786 } | 1772 } |
1787 return self; | 1773 return self; |
1788 } | 1774 } |
1789 | 1775 |
1790 - (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary { | 1776 - (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary { |
1791 self = [self initWithInt32s:NULL forKeys:NULL count:0]; | 1777 self = [self initWithValues:NULL forKeys:NULL count:0]; |
1792 if (self) { | 1778 if (self) { |
1793 if (dictionary) { | 1779 if (dictionary) { |
1794 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 1780 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
1795 } | 1781 } |
1796 } | 1782 } |
1797 return self; | 1783 return self; |
1798 } | 1784 } |
1799 | 1785 |
1800 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 1786 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
1801 #pragma unused(numItems) | 1787 #pragma unused(numItems) |
1802 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 1788 return [self initWithValues:NULL forKeys:NULL count:0]; |
1803 } | 1789 } |
1804 | 1790 |
1805 - (void)dealloc { | 1791 - (void)dealloc { |
1806 NSAssert(!_autocreator, | 1792 NSAssert(!_autocreator, |
1807 @"%@: Autocreator must be cleared before release, autocreator: %@", | 1793 @"%@: Autocreator must be cleared before release, autocreator: %@", |
1808 [self class], _autocreator); | 1794 [self class], _autocreator); |
1809 [_dictionary release]; | 1795 [_dictionary release]; |
1810 [super dealloc]; | 1796 [super dealloc]; |
1811 } | 1797 } |
1812 | 1798 |
1813 - (instancetype)copyWithZone:(NSZone *)zone { | 1799 - (instancetype)copyWithZone:(NSZone *)zone { |
1814 return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]
; | 1800 return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]
; |
1815 } | 1801 } |
1816 | 1802 |
1817 - (BOOL)isEqual:(id)other { | 1803 - (BOOL)isEqual:(GPBUInt32Int32Dictionary *)other { |
1818 if (self == other) { | 1804 if (self == other) { |
1819 return YES; | 1805 return YES; |
1820 } | 1806 } |
1821 if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) { | 1807 if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) { |
1822 return NO; | 1808 return NO; |
1823 } | 1809 } |
1824 GPBUInt32Int32Dictionary *otherDictionary = other; | 1810 return [_dictionary isEqual:other->_dictionary]; |
1825 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
1826 } | 1811 } |
1827 | 1812 |
1828 - (NSUInteger)hash { | 1813 - (NSUInteger)hash { |
1829 return _dictionary.count; | 1814 return _dictionary.count; |
1830 } | 1815 } |
1831 | 1816 |
1832 - (NSString *)description { | 1817 - (NSString *)description { |
1833 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 1818 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
1834 } | 1819 } |
1835 | 1820 |
1836 - (NSUInteger)count { | 1821 - (NSUInteger)count { |
1837 return _dictionary.count; | 1822 return _dictionary.count; |
1838 } | 1823 } |
1839 | 1824 |
1840 - (void)enumerateKeysAndInt32sUsingBlock: | 1825 - (void)enumerateKeysAndValuesUsingBlock: |
1841 (void (^)(uint32_t key, int32_t value, BOOL *stop))block { | 1826 (void (^)(uint32_t key, int32_t value, BOOL *stop))block { |
1842 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 1827 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
1843 NSNumber *aValue, | 1828 NSNumber *aValue, |
1844 BOOL *stop) { | 1829 BOOL *stop) { |
1845 block([aKey unsignedIntValue], [aValue intValue], stop); | 1830 block([aKey unsignedIntValue], [aValue intValue], stop); |
1846 }]; | 1831 }]; |
1847 } | 1832 } |
1848 | 1833 |
1849 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 1834 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
1850 NSUInteger count = _dictionary.count; | 1835 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1888 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | 1873 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); |
1889 }]; | 1874 }]; |
1890 } | 1875 } |
1891 | 1876 |
1892 - (void)setGPBGenericValue:(GPBGenericValue *)value | 1877 - (void)setGPBGenericValue:(GPBGenericValue *)value |
1893 forGPBGenericValueKey:(GPBGenericValue *)key { | 1878 forGPBGenericValueKey:(GPBGenericValue *)key { |
1894 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)]; | 1879 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)]; |
1895 } | 1880 } |
1896 | 1881 |
1897 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 1882 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
1898 [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, BOOL *st
op) { | 1883 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, int32_t value, BOOL *st
op) { |
1899 #pragma unused(stop) | 1884 #pragma unused(stop) |
1900 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%d", value]); | 1885 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%d", value]); |
1901 }]; | 1886 }]; |
1902 } | 1887 } |
1903 | 1888 |
1904 - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key { | 1889 - (BOOL)valueForKey:(uint32_t)key value:(int32_t *)value { |
1905 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 1890 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
1906 if (wrapped && value) { | 1891 if (wrapped && value) { |
1907 *value = [wrapped intValue]; | 1892 *value = [wrapped intValue]; |
1908 } | 1893 } |
1909 return (wrapped != NULL); | 1894 return (wrapped != NULL); |
1910 } | 1895 } |
1911 | 1896 |
1912 - (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary { | 1897 - (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary { |
1913 if (otherDictionary) { | 1898 if (otherDictionary) { |
1914 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 1899 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
1915 if (_autocreator) { | 1900 if (_autocreator) { |
1916 GPBAutocreatedDictionaryModified(_autocreator, self); | 1901 GPBAutocreatedDictionaryModified(_autocreator, self); |
1917 } | 1902 } |
1918 } | 1903 } |
1919 } | 1904 } |
1920 | 1905 |
1921 - (void)setInt32:(int32_t)value forKey:(uint32_t)key { | 1906 - (void)setValue:(int32_t)value forKey:(uint32_t)key { |
1922 [_dictionary setObject:@(value) forKey:@(key)]; | 1907 [_dictionary setObject:@(value) forKey:@(key)]; |
1923 if (_autocreator) { | 1908 if (_autocreator) { |
1924 GPBAutocreatedDictionaryModified(_autocreator, self); | 1909 GPBAutocreatedDictionaryModified(_autocreator, self); |
1925 } | 1910 } |
1926 } | 1911 } |
1927 | 1912 |
1928 - (void)removeInt32ForKey:(uint32_t)aKey { | 1913 - (void)removeValueForKey:(uint32_t)aKey { |
1929 [_dictionary removeObjectForKey:@(aKey)]; | 1914 [_dictionary removeObjectForKey:@(aKey)]; |
1930 } | 1915 } |
1931 | 1916 |
1932 - (void)removeAll { | 1917 - (void)removeAll { |
1933 [_dictionary removeAllObjects]; | 1918 [_dictionary removeAllObjects]; |
1934 } | 1919 } |
1935 | 1920 |
1936 @end | 1921 @end |
1937 | 1922 |
1938 #pragma mark - UInt32 -> UInt64 | 1923 #pragma mark - UInt32 -> UInt64 |
1939 | 1924 |
1940 @implementation GPBUInt32UInt64Dictionary { | 1925 @implementation GPBUInt32UInt64Dictionary { |
1941 @package | 1926 @package |
1942 NSMutableDictionary *_dictionary; | 1927 NSMutableDictionary *_dictionary; |
1943 } | 1928 } |
1944 | 1929 |
1945 + (instancetype)dictionary { | 1930 + (instancetype)dictionary { |
1946 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; | 1931 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
1947 } | 1932 } |
1948 | 1933 |
1949 + (instancetype)dictionaryWithUInt64:(uint64_t)value | 1934 + (instancetype)dictionaryWithValue:(uint64_t)value |
1950 forKey:(uint32_t)key { | 1935 forKey:(uint32_t)key { |
1951 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 1936 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
1952 // on to get the type correct. | 1937 // on to get the type correct. |
1953 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithUInt64s:&value | 1938 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithValues:&value |
1954 forKeys:&key | 1939 forKeys:&key |
1955 count:1] autorelea
se]; | 1940 count:1] autoreleas
e]; |
1956 } | 1941 } |
1957 | 1942 |
1958 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values | 1943 + (instancetype)dictionaryWithValues:(const uint64_t [])values |
1959 forKeys:(const uint32_t [])keys | 1944 forKeys:(const uint32_t [])keys |
1960 count:(NSUInteger)count { | 1945 count:(NSUInteger)count { |
1961 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 1946 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
1962 // on to get the type correct. | 1947 // on to get the type correct. |
1963 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithUInt64s:values | 1948 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithValues:values |
1964 forKeys:keys | 1949 forKeys:keys |
1965 count:count] autore
lease]; | 1950 count:count] autore
lease]; |
1966 } | 1951 } |
1967 | 1952 |
1968 + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary
{ | 1953 + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary
{ |
1969 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 1954 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
1970 // on to get the type correct. | 1955 // on to get the type correct. |
1971 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 1956 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
1972 } | 1957 } |
1973 | 1958 |
1974 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 1959 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
1975 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 1960 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
1976 } | 1961 } |
1977 | 1962 |
1978 - (instancetype)init { | 1963 - (instancetype)init { |
1979 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 1964 return [self initWithValues:NULL forKeys:NULL count:0]; |
1980 } | 1965 } |
1981 | 1966 |
1982 - (instancetype)initWithUInt64s:(const uint64_t [])values | 1967 - (instancetype)initWithValues:(const uint64_t [])values |
1983 forKeys:(const uint32_t [])keys | 1968 forKeys:(const uint32_t [])keys |
1984 count:(NSUInteger)count { | 1969 count:(NSUInteger)count { |
1985 self = [super init]; | 1970 self = [super init]; |
1986 if (self) { | 1971 if (self) { |
1987 _dictionary = [[NSMutableDictionary alloc] init]; | 1972 _dictionary = [[NSMutableDictionary alloc] init]; |
1988 if (count && values && keys) { | 1973 if (count && values && keys) { |
1989 for (NSUInteger i = 0; i < count; ++i) { | 1974 for (NSUInteger i = 0; i < count; ++i) { |
1990 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 1975 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
1991 } | 1976 } |
1992 } | 1977 } |
1993 } | 1978 } |
1994 return self; | 1979 return self; |
1995 } | 1980 } |
1996 | 1981 |
1997 - (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary { | 1982 - (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary { |
1998 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; | 1983 self = [self initWithValues:NULL forKeys:NULL count:0]; |
1999 if (self) { | 1984 if (self) { |
2000 if (dictionary) { | 1985 if (dictionary) { |
2001 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 1986 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
2002 } | 1987 } |
2003 } | 1988 } |
2004 return self; | 1989 return self; |
2005 } | 1990 } |
2006 | 1991 |
2007 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 1992 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
2008 #pragma unused(numItems) | 1993 #pragma unused(numItems) |
2009 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 1994 return [self initWithValues:NULL forKeys:NULL count:0]; |
2010 } | 1995 } |
2011 | 1996 |
2012 - (void)dealloc { | 1997 - (void)dealloc { |
2013 NSAssert(!_autocreator, | 1998 NSAssert(!_autocreator, |
2014 @"%@: Autocreator must be cleared before release, autocreator: %@", | 1999 @"%@: Autocreator must be cleared before release, autocreator: %@", |
2015 [self class], _autocreator); | 2000 [self class], _autocreator); |
2016 [_dictionary release]; | 2001 [_dictionary release]; |
2017 [super dealloc]; | 2002 [super dealloc]; |
2018 } | 2003 } |
2019 | 2004 |
2020 - (instancetype)copyWithZone:(NSZone *)zone { | 2005 - (instancetype)copyWithZone:(NSZone *)zone { |
2021 return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; | 2006 return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; |
2022 } | 2007 } |
2023 | 2008 |
2024 - (BOOL)isEqual:(id)other { | 2009 - (BOOL)isEqual:(GPBUInt32UInt64Dictionary *)other { |
2025 if (self == other) { | 2010 if (self == other) { |
2026 return YES; | 2011 return YES; |
2027 } | 2012 } |
2028 if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) { | 2013 if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) { |
2029 return NO; | 2014 return NO; |
2030 } | 2015 } |
2031 GPBUInt32UInt64Dictionary *otherDictionary = other; | 2016 return [_dictionary isEqual:other->_dictionary]; |
2032 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
2033 } | 2017 } |
2034 | 2018 |
2035 - (NSUInteger)hash { | 2019 - (NSUInteger)hash { |
2036 return _dictionary.count; | 2020 return _dictionary.count; |
2037 } | 2021 } |
2038 | 2022 |
2039 - (NSString *)description { | 2023 - (NSString *)description { |
2040 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 2024 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
2041 } | 2025 } |
2042 | 2026 |
2043 - (NSUInteger)count { | 2027 - (NSUInteger)count { |
2044 return _dictionary.count; | 2028 return _dictionary.count; |
2045 } | 2029 } |
2046 | 2030 |
2047 - (void)enumerateKeysAndUInt64sUsingBlock: | 2031 - (void)enumerateKeysAndValuesUsingBlock: |
2048 (void (^)(uint32_t key, uint64_t value, BOOL *stop))block { | 2032 (void (^)(uint32_t key, uint64_t value, BOOL *stop))block { |
2049 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 2033 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
2050 NSNumber *aValue, | 2034 NSNumber *aValue, |
2051 BOOL *stop) { | 2035 BOOL *stop) { |
2052 block([aKey unsignedIntValue], [aValue unsignedLongLongValue], stop); | 2036 block([aKey unsignedIntValue], [aValue unsignedLongLongValue], stop); |
2053 }]; | 2037 }]; |
2054 } | 2038 } |
2055 | 2039 |
2056 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 2040 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
2057 NSUInteger count = _dictionary.count; | 2041 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2095 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | 2079 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); |
2096 }]; | 2080 }]; |
2097 } | 2081 } |
2098 | 2082 |
2099 - (void)setGPBGenericValue:(GPBGenericValue *)value | 2083 - (void)setGPBGenericValue:(GPBGenericValue *)value |
2100 forGPBGenericValueKey:(GPBGenericValue *)key { | 2084 forGPBGenericValueKey:(GPBGenericValue *)key { |
2101 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)]; | 2085 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)]; |
2102 } | 2086 } |
2103 | 2087 |
2104 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 2088 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
2105 [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, BOOL *
stop) { | 2089 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, uint64_t value, BOOL *s
top) { |
2106 #pragma unused(stop) | 2090 #pragma unused(stop) |
2107 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%llu", value]); | 2091 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%llu", value]); |
2108 }]; | 2092 }]; |
2109 } | 2093 } |
2110 | 2094 |
2111 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key { | 2095 - (BOOL)valueForKey:(uint32_t)key value:(uint64_t *)value { |
2112 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 2096 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
2113 if (wrapped && value) { | 2097 if (wrapped && value) { |
2114 *value = [wrapped unsignedLongLongValue]; | 2098 *value = [wrapped unsignedLongLongValue]; |
2115 } | 2099 } |
2116 return (wrapped != NULL); | 2100 return (wrapped != NULL); |
2117 } | 2101 } |
2118 | 2102 |
2119 - (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary { | 2103 - (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary { |
2120 if (otherDictionary) { | 2104 if (otherDictionary) { |
2121 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 2105 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
2122 if (_autocreator) { | 2106 if (_autocreator) { |
2123 GPBAutocreatedDictionaryModified(_autocreator, self); | 2107 GPBAutocreatedDictionaryModified(_autocreator, self); |
2124 } | 2108 } |
2125 } | 2109 } |
2126 } | 2110 } |
2127 | 2111 |
2128 - (void)setUInt64:(uint64_t)value forKey:(uint32_t)key { | 2112 - (void)setValue:(uint64_t)value forKey:(uint32_t)key { |
2129 [_dictionary setObject:@(value) forKey:@(key)]; | 2113 [_dictionary setObject:@(value) forKey:@(key)]; |
2130 if (_autocreator) { | 2114 if (_autocreator) { |
2131 GPBAutocreatedDictionaryModified(_autocreator, self); | 2115 GPBAutocreatedDictionaryModified(_autocreator, self); |
2132 } | 2116 } |
2133 } | 2117 } |
2134 | 2118 |
2135 - (void)removeUInt64ForKey:(uint32_t)aKey { | 2119 - (void)removeValueForKey:(uint32_t)aKey { |
2136 [_dictionary removeObjectForKey:@(aKey)]; | 2120 [_dictionary removeObjectForKey:@(aKey)]; |
2137 } | 2121 } |
2138 | 2122 |
2139 - (void)removeAll { | 2123 - (void)removeAll { |
2140 [_dictionary removeAllObjects]; | 2124 [_dictionary removeAllObjects]; |
2141 } | 2125 } |
2142 | 2126 |
2143 @end | 2127 @end |
2144 | 2128 |
2145 #pragma mark - UInt32 -> Int64 | 2129 #pragma mark - UInt32 -> Int64 |
2146 | 2130 |
2147 @implementation GPBUInt32Int64Dictionary { | 2131 @implementation GPBUInt32Int64Dictionary { |
2148 @package | 2132 @package |
2149 NSMutableDictionary *_dictionary; | 2133 NSMutableDictionary *_dictionary; |
2150 } | 2134 } |
2151 | 2135 |
2152 + (instancetype)dictionary { | 2136 + (instancetype)dictionary { |
2153 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; | 2137 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
2154 } | 2138 } |
2155 | 2139 |
2156 + (instancetype)dictionaryWithInt64:(int64_t)value | 2140 + (instancetype)dictionaryWithValue:(int64_t)value |
2157 forKey:(uint32_t)key { | 2141 forKey:(uint32_t)key { |
2158 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 2142 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
2159 // on to get the type correct. | 2143 // on to get the type correct. |
2160 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithInt64s:&value | 2144 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithValues:&value |
2161 forKeys:&key | 2145 forKeys:&key |
2162 count:1] autorelease
]; | 2146 count:1] autorelease
]; |
2163 } | 2147 } |
2164 | 2148 |
2165 + (instancetype)dictionaryWithInt64s:(const int64_t [])values | 2149 + (instancetype)dictionaryWithValues:(const int64_t [])values |
2166 forKeys:(const uint32_t [])keys | 2150 forKeys:(const uint32_t [])keys |
2167 count:(NSUInteger)count { | 2151 count:(NSUInteger)count { |
2168 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 2152 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
2169 // on to get the type correct. | 2153 // on to get the type correct. |
2170 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithInt64s:values | 2154 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithValues:values |
2171 forKeys:keys | 2155 forKeys:keys |
2172 count:count] autorel
ease]; | 2156 count:count] autorel
ease]; |
2173 } | 2157 } |
2174 | 2158 |
2175 + (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary
{ | 2159 + (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary
{ |
2176 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 2160 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
2177 // on to get the type correct. | 2161 // on to get the type correct. |
2178 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 2162 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
2179 } | 2163 } |
2180 | 2164 |
2181 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 2165 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
2182 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 2166 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
2183 } | 2167 } |
2184 | 2168 |
2185 - (instancetype)init { | 2169 - (instancetype)init { |
2186 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 2170 return [self initWithValues:NULL forKeys:NULL count:0]; |
2187 } | 2171 } |
2188 | 2172 |
2189 - (instancetype)initWithInt64s:(const int64_t [])values | 2173 - (instancetype)initWithValues:(const int64_t [])values |
2190 forKeys:(const uint32_t [])keys | 2174 forKeys:(const uint32_t [])keys |
2191 count:(NSUInteger)count { | 2175 count:(NSUInteger)count { |
2192 self = [super init]; | 2176 self = [super init]; |
2193 if (self) { | 2177 if (self) { |
2194 _dictionary = [[NSMutableDictionary alloc] init]; | 2178 _dictionary = [[NSMutableDictionary alloc] init]; |
2195 if (count && values && keys) { | 2179 if (count && values && keys) { |
2196 for (NSUInteger i = 0; i < count; ++i) { | 2180 for (NSUInteger i = 0; i < count; ++i) { |
2197 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 2181 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
2198 } | 2182 } |
2199 } | 2183 } |
2200 } | 2184 } |
2201 return self; | 2185 return self; |
2202 } | 2186 } |
2203 | 2187 |
2204 - (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary { | 2188 - (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary { |
2205 self = [self initWithInt64s:NULL forKeys:NULL count:0]; | 2189 self = [self initWithValues:NULL forKeys:NULL count:0]; |
2206 if (self) { | 2190 if (self) { |
2207 if (dictionary) { | 2191 if (dictionary) { |
2208 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 2192 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
2209 } | 2193 } |
2210 } | 2194 } |
2211 return self; | 2195 return self; |
2212 } | 2196 } |
2213 | 2197 |
2214 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 2198 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
2215 #pragma unused(numItems) | 2199 #pragma unused(numItems) |
2216 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 2200 return [self initWithValues:NULL forKeys:NULL count:0]; |
2217 } | 2201 } |
2218 | 2202 |
2219 - (void)dealloc { | 2203 - (void)dealloc { |
2220 NSAssert(!_autocreator, | 2204 NSAssert(!_autocreator, |
2221 @"%@: Autocreator must be cleared before release, autocreator: %@", | 2205 @"%@: Autocreator must be cleared before release, autocreator: %@", |
2222 [self class], _autocreator); | 2206 [self class], _autocreator); |
2223 [_dictionary release]; | 2207 [_dictionary release]; |
2224 [super dealloc]; | 2208 [super dealloc]; |
2225 } | 2209 } |
2226 | 2210 |
2227 - (instancetype)copyWithZone:(NSZone *)zone { | 2211 - (instancetype)copyWithZone:(NSZone *)zone { |
2228 return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]
; | 2212 return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]
; |
2229 } | 2213 } |
2230 | 2214 |
2231 - (BOOL)isEqual:(id)other { | 2215 - (BOOL)isEqual:(GPBUInt32Int64Dictionary *)other { |
2232 if (self == other) { | 2216 if (self == other) { |
2233 return YES; | 2217 return YES; |
2234 } | 2218 } |
2235 if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) { | 2219 if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) { |
2236 return NO; | 2220 return NO; |
2237 } | 2221 } |
2238 GPBUInt32Int64Dictionary *otherDictionary = other; | 2222 return [_dictionary isEqual:other->_dictionary]; |
2239 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
2240 } | 2223 } |
2241 | 2224 |
2242 - (NSUInteger)hash { | 2225 - (NSUInteger)hash { |
2243 return _dictionary.count; | 2226 return _dictionary.count; |
2244 } | 2227 } |
2245 | 2228 |
2246 - (NSString *)description { | 2229 - (NSString *)description { |
2247 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 2230 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
2248 } | 2231 } |
2249 | 2232 |
2250 - (NSUInteger)count { | 2233 - (NSUInteger)count { |
2251 return _dictionary.count; | 2234 return _dictionary.count; |
2252 } | 2235 } |
2253 | 2236 |
2254 - (void)enumerateKeysAndInt64sUsingBlock: | 2237 - (void)enumerateKeysAndValuesUsingBlock: |
2255 (void (^)(uint32_t key, int64_t value, BOOL *stop))block { | 2238 (void (^)(uint32_t key, int64_t value, BOOL *stop))block { |
2256 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 2239 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
2257 NSNumber *aValue, | 2240 NSNumber *aValue, |
2258 BOOL *stop) { | 2241 BOOL *stop) { |
2259 block([aKey unsignedIntValue], [aValue longLongValue], stop); | 2242 block([aKey unsignedIntValue], [aValue longLongValue], stop); |
2260 }]; | 2243 }]; |
2261 } | 2244 } |
2262 | 2245 |
2263 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 2246 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
2264 NSUInteger count = _dictionary.count; | 2247 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2302 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | 2285 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); |
2303 }]; | 2286 }]; |
2304 } | 2287 } |
2305 | 2288 |
2306 - (void)setGPBGenericValue:(GPBGenericValue *)value | 2289 - (void)setGPBGenericValue:(GPBGenericValue *)value |
2307 forGPBGenericValueKey:(GPBGenericValue *)key { | 2290 forGPBGenericValueKey:(GPBGenericValue *)key { |
2308 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)]; | 2291 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)]; |
2309 } | 2292 } |
2310 | 2293 |
2311 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 2294 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
2312 [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, BOOL *st
op) { | 2295 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, int64_t value, BOOL *st
op) { |
2313 #pragma unused(stop) | 2296 #pragma unused(stop) |
2314 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%lld", value]); | 2297 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%lld", value]); |
2315 }]; | 2298 }]; |
2316 } | 2299 } |
2317 | 2300 |
2318 - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key { | 2301 - (BOOL)valueForKey:(uint32_t)key value:(int64_t *)value { |
2319 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 2302 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
2320 if (wrapped && value) { | 2303 if (wrapped && value) { |
2321 *value = [wrapped longLongValue]; | 2304 *value = [wrapped longLongValue]; |
2322 } | 2305 } |
2323 return (wrapped != NULL); | 2306 return (wrapped != NULL); |
2324 } | 2307 } |
2325 | 2308 |
2326 - (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary { | 2309 - (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary { |
2327 if (otherDictionary) { | 2310 if (otherDictionary) { |
2328 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 2311 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
2329 if (_autocreator) { | 2312 if (_autocreator) { |
2330 GPBAutocreatedDictionaryModified(_autocreator, self); | 2313 GPBAutocreatedDictionaryModified(_autocreator, self); |
2331 } | 2314 } |
2332 } | 2315 } |
2333 } | 2316 } |
2334 | 2317 |
2335 - (void)setInt64:(int64_t)value forKey:(uint32_t)key { | 2318 - (void)setValue:(int64_t)value forKey:(uint32_t)key { |
2336 [_dictionary setObject:@(value) forKey:@(key)]; | 2319 [_dictionary setObject:@(value) forKey:@(key)]; |
2337 if (_autocreator) { | 2320 if (_autocreator) { |
2338 GPBAutocreatedDictionaryModified(_autocreator, self); | 2321 GPBAutocreatedDictionaryModified(_autocreator, self); |
2339 } | 2322 } |
2340 } | 2323 } |
2341 | 2324 |
2342 - (void)removeInt64ForKey:(uint32_t)aKey { | 2325 - (void)removeValueForKey:(uint32_t)aKey { |
2343 [_dictionary removeObjectForKey:@(aKey)]; | 2326 [_dictionary removeObjectForKey:@(aKey)]; |
2344 } | 2327 } |
2345 | 2328 |
2346 - (void)removeAll { | 2329 - (void)removeAll { |
2347 [_dictionary removeAllObjects]; | 2330 [_dictionary removeAllObjects]; |
2348 } | 2331 } |
2349 | 2332 |
2350 @end | 2333 @end |
2351 | 2334 |
2352 #pragma mark - UInt32 -> Bool | 2335 #pragma mark - UInt32 -> Bool |
2353 | 2336 |
2354 @implementation GPBUInt32BoolDictionary { | 2337 @implementation GPBUInt32BoolDictionary { |
2355 @package | 2338 @package |
2356 NSMutableDictionary *_dictionary; | 2339 NSMutableDictionary *_dictionary; |
2357 } | 2340 } |
2358 | 2341 |
2359 + (instancetype)dictionary { | 2342 + (instancetype)dictionary { |
2360 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; | 2343 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
2361 } | 2344 } |
2362 | 2345 |
2363 + (instancetype)dictionaryWithBool:(BOOL)value | 2346 + (instancetype)dictionaryWithValue:(BOOL)value |
2364 forKey:(uint32_t)key { | 2347 forKey:(uint32_t)key { |
2365 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 2348 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
2366 // on to get the type correct. | 2349 // on to get the type correct. |
2367 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithBools:&value | 2350 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithValues:&value |
2368 forKeys:&key | 2351 forKeys:&key |
2369 count:1] autorelease]; | 2352 count:1] autorelease]
; |
2370 } | 2353 } |
2371 | 2354 |
2372 + (instancetype)dictionaryWithBools:(const BOOL [])values | 2355 + (instancetype)dictionaryWithValues:(const BOOL [])values |
2373 forKeys:(const uint32_t [])keys | 2356 forKeys:(const uint32_t [])keys |
2374 count:(NSUInteger)count { | 2357 count:(NSUInteger)count { |
2375 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 2358 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
2376 // on to get the type correct. | 2359 // on to get the type correct. |
2377 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithBools:values | 2360 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithValues:values |
2378 forKeys:keys | 2361 forKeys:keys |
2379 count:count] autorele
ase]; | 2362 count:count] autorele
ase]; |
2380 } | 2363 } |
2381 | 2364 |
2382 + (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary { | 2365 + (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary { |
2383 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 2366 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
2384 // on to get the type correct. | 2367 // on to get the type correct. |
2385 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 2368 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
2386 } | 2369 } |
2387 | 2370 |
2388 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 2371 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
2389 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 2372 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
2390 } | 2373 } |
2391 | 2374 |
2392 - (instancetype)init { | 2375 - (instancetype)init { |
2393 return [self initWithBools:NULL forKeys:NULL count:0]; | 2376 return [self initWithValues:NULL forKeys:NULL count:0]; |
2394 } | 2377 } |
2395 | 2378 |
2396 - (instancetype)initWithBools:(const BOOL [])values | 2379 - (instancetype)initWithValues:(const BOOL [])values |
2397 forKeys:(const uint32_t [])keys | 2380 forKeys:(const uint32_t [])keys |
2398 count:(NSUInteger)count { | 2381 count:(NSUInteger)count { |
2399 self = [super init]; | 2382 self = [super init]; |
2400 if (self) { | 2383 if (self) { |
2401 _dictionary = [[NSMutableDictionary alloc] init]; | 2384 _dictionary = [[NSMutableDictionary alloc] init]; |
2402 if (count && values && keys) { | 2385 if (count && values && keys) { |
2403 for (NSUInteger i = 0; i < count; ++i) { | 2386 for (NSUInteger i = 0; i < count; ++i) { |
2404 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 2387 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
2405 } | 2388 } |
2406 } | 2389 } |
2407 } | 2390 } |
2408 return self; | 2391 return self; |
2409 } | 2392 } |
2410 | 2393 |
2411 - (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary { | 2394 - (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary { |
2412 self = [self initWithBools:NULL forKeys:NULL count:0]; | 2395 self = [self initWithValues:NULL forKeys:NULL count:0]; |
2413 if (self) { | 2396 if (self) { |
2414 if (dictionary) { | 2397 if (dictionary) { |
2415 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 2398 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
2416 } | 2399 } |
2417 } | 2400 } |
2418 return self; | 2401 return self; |
2419 } | 2402 } |
2420 | 2403 |
2421 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 2404 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
2422 #pragma unused(numItems) | 2405 #pragma unused(numItems) |
2423 return [self initWithBools:NULL forKeys:NULL count:0]; | 2406 return [self initWithValues:NULL forKeys:NULL count:0]; |
2424 } | 2407 } |
2425 | 2408 |
2426 - (void)dealloc { | 2409 - (void)dealloc { |
2427 NSAssert(!_autocreator, | 2410 NSAssert(!_autocreator, |
2428 @"%@: Autocreator must be cleared before release, autocreator: %@", | 2411 @"%@: Autocreator must be cleared before release, autocreator: %@", |
2429 [self class], _autocreator); | 2412 [self class], _autocreator); |
2430 [_dictionary release]; | 2413 [_dictionary release]; |
2431 [super dealloc]; | 2414 [super dealloc]; |
2432 } | 2415 } |
2433 | 2416 |
2434 - (instancetype)copyWithZone:(NSZone *)zone { | 2417 - (instancetype)copyWithZone:(NSZone *)zone { |
2435 return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; | 2418 return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; |
2436 } | 2419 } |
2437 | 2420 |
2438 - (BOOL)isEqual:(id)other { | 2421 - (BOOL)isEqual:(GPBUInt32BoolDictionary *)other { |
2439 if (self == other) { | 2422 if (self == other) { |
2440 return YES; | 2423 return YES; |
2441 } | 2424 } |
2442 if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) { | 2425 if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) { |
2443 return NO; | 2426 return NO; |
2444 } | 2427 } |
2445 GPBUInt32BoolDictionary *otherDictionary = other; | 2428 return [_dictionary isEqual:other->_dictionary]; |
2446 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
2447 } | 2429 } |
2448 | 2430 |
2449 - (NSUInteger)hash { | 2431 - (NSUInteger)hash { |
2450 return _dictionary.count; | 2432 return _dictionary.count; |
2451 } | 2433 } |
2452 | 2434 |
2453 - (NSString *)description { | 2435 - (NSString *)description { |
2454 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 2436 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
2455 } | 2437 } |
2456 | 2438 |
2457 - (NSUInteger)count { | 2439 - (NSUInteger)count { |
2458 return _dictionary.count; | 2440 return _dictionary.count; |
2459 } | 2441 } |
2460 | 2442 |
2461 - (void)enumerateKeysAndBoolsUsingBlock: | 2443 - (void)enumerateKeysAndValuesUsingBlock: |
2462 (void (^)(uint32_t key, BOOL value, BOOL *stop))block { | 2444 (void (^)(uint32_t key, BOOL value, BOOL *stop))block { |
2463 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 2445 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
2464 NSNumber *aValue, | 2446 NSNumber *aValue, |
2465 BOOL *stop) { | 2447 BOOL *stop) { |
2466 block([aKey unsignedIntValue], [aValue boolValue], stop); | 2448 block([aKey unsignedIntValue], [aValue boolValue], stop); |
2467 }]; | 2449 }]; |
2468 } | 2450 } |
2469 | 2451 |
2470 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 2452 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
2471 NSUInteger count = _dictionary.count; | 2453 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2509 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | 2491 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); |
2510 }]; | 2492 }]; |
2511 } | 2493 } |
2512 | 2494 |
2513 - (void)setGPBGenericValue:(GPBGenericValue *)value | 2495 - (void)setGPBGenericValue:(GPBGenericValue *)value |
2514 forGPBGenericValueKey:(GPBGenericValue *)key { | 2496 forGPBGenericValueKey:(GPBGenericValue *)key { |
2515 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)]; | 2497 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)]; |
2516 } | 2498 } |
2517 | 2499 |
2518 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 2500 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
2519 [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, BOOL *stop)
{ | 2501 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, BOOL value, BOOL *stop)
{ |
2520 #pragma unused(stop) | 2502 #pragma unused(stop) |
2521 block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false")
); | 2503 block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false")
); |
2522 }]; | 2504 }]; |
2523 } | 2505 } |
2524 | 2506 |
2525 - (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key { | 2507 - (BOOL)valueForKey:(uint32_t)key value:(BOOL *)value { |
2526 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 2508 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
2527 if (wrapped && value) { | 2509 if (wrapped && value) { |
2528 *value = [wrapped boolValue]; | 2510 *value = [wrapped boolValue]; |
2529 } | 2511 } |
2530 return (wrapped != NULL); | 2512 return (wrapped != NULL); |
2531 } | 2513 } |
2532 | 2514 |
2533 - (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary { | 2515 - (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary { |
2534 if (otherDictionary) { | 2516 if (otherDictionary) { |
2535 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 2517 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
2536 if (_autocreator) { | 2518 if (_autocreator) { |
2537 GPBAutocreatedDictionaryModified(_autocreator, self); | 2519 GPBAutocreatedDictionaryModified(_autocreator, self); |
2538 } | 2520 } |
2539 } | 2521 } |
2540 } | 2522 } |
2541 | 2523 |
2542 - (void)setBool:(BOOL)value forKey:(uint32_t)key { | 2524 - (void)setValue:(BOOL)value forKey:(uint32_t)key { |
2543 [_dictionary setObject:@(value) forKey:@(key)]; | 2525 [_dictionary setObject:@(value) forKey:@(key)]; |
2544 if (_autocreator) { | 2526 if (_autocreator) { |
2545 GPBAutocreatedDictionaryModified(_autocreator, self); | 2527 GPBAutocreatedDictionaryModified(_autocreator, self); |
2546 } | 2528 } |
2547 } | 2529 } |
2548 | 2530 |
2549 - (void)removeBoolForKey:(uint32_t)aKey { | 2531 - (void)removeValueForKey:(uint32_t)aKey { |
2550 [_dictionary removeObjectForKey:@(aKey)]; | 2532 [_dictionary removeObjectForKey:@(aKey)]; |
2551 } | 2533 } |
2552 | 2534 |
2553 - (void)removeAll { | 2535 - (void)removeAll { |
2554 [_dictionary removeAllObjects]; | 2536 [_dictionary removeAllObjects]; |
2555 } | 2537 } |
2556 | 2538 |
2557 @end | 2539 @end |
2558 | 2540 |
2559 #pragma mark - UInt32 -> Float | 2541 #pragma mark - UInt32 -> Float |
2560 | 2542 |
2561 @implementation GPBUInt32FloatDictionary { | 2543 @implementation GPBUInt32FloatDictionary { |
2562 @package | 2544 @package |
2563 NSMutableDictionary *_dictionary; | 2545 NSMutableDictionary *_dictionary; |
2564 } | 2546 } |
2565 | 2547 |
2566 + (instancetype)dictionary { | 2548 + (instancetype)dictionary { |
2567 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; | 2549 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
2568 } | 2550 } |
2569 | 2551 |
2570 + (instancetype)dictionaryWithFloat:(float)value | 2552 + (instancetype)dictionaryWithValue:(float)value |
2571 forKey:(uint32_t)key { | 2553 forKey:(uint32_t)key { |
2572 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 2554 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
2573 // on to get the type correct. | 2555 // on to get the type correct. |
2574 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithFloats:&value | 2556 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithValues:&value |
2575 forKeys:&key | 2557 forKeys:&key |
2576 count:1] autorelease
]; | 2558 count:1] autorelease
]; |
2577 } | 2559 } |
2578 | 2560 |
2579 + (instancetype)dictionaryWithFloats:(const float [])values | 2561 + (instancetype)dictionaryWithValues:(const float [])values |
2580 forKeys:(const uint32_t [])keys | 2562 forKeys:(const uint32_t [])keys |
2581 count:(NSUInteger)count { | 2563 count:(NSUInteger)count { |
2582 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 2564 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
2583 // on to get the type correct. | 2565 // on to get the type correct. |
2584 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithFloats:values | 2566 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithValues:values |
2585 forKeys:keys | 2567 forKeys:keys |
2586 count:count] autorel
ease]; | 2568 count:count] autorel
ease]; |
2587 } | 2569 } |
2588 | 2570 |
2589 + (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary
{ | 2571 + (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary
{ |
2590 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 2572 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
2591 // on to get the type correct. | 2573 // on to get the type correct. |
2592 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 2574 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
2593 } | 2575 } |
2594 | 2576 |
2595 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 2577 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
2596 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 2578 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
2597 } | 2579 } |
2598 | 2580 |
2599 - (instancetype)init { | 2581 - (instancetype)init { |
2600 return [self initWithFloats:NULL forKeys:NULL count:0]; | 2582 return [self initWithValues:NULL forKeys:NULL count:0]; |
2601 } | 2583 } |
2602 | 2584 |
2603 - (instancetype)initWithFloats:(const float [])values | 2585 - (instancetype)initWithValues:(const float [])values |
2604 forKeys:(const uint32_t [])keys | 2586 forKeys:(const uint32_t [])keys |
2605 count:(NSUInteger)count { | 2587 count:(NSUInteger)count { |
2606 self = [super init]; | 2588 self = [super init]; |
2607 if (self) { | 2589 if (self) { |
2608 _dictionary = [[NSMutableDictionary alloc] init]; | 2590 _dictionary = [[NSMutableDictionary alloc] init]; |
2609 if (count && values && keys) { | 2591 if (count && values && keys) { |
2610 for (NSUInteger i = 0; i < count; ++i) { | 2592 for (NSUInteger i = 0; i < count; ++i) { |
2611 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 2593 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
2612 } | 2594 } |
2613 } | 2595 } |
2614 } | 2596 } |
2615 return self; | 2597 return self; |
2616 } | 2598 } |
2617 | 2599 |
2618 - (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary { | 2600 - (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary { |
2619 self = [self initWithFloats:NULL forKeys:NULL count:0]; | 2601 self = [self initWithValues:NULL forKeys:NULL count:0]; |
2620 if (self) { | 2602 if (self) { |
2621 if (dictionary) { | 2603 if (dictionary) { |
2622 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 2604 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
2623 } | 2605 } |
2624 } | 2606 } |
2625 return self; | 2607 return self; |
2626 } | 2608 } |
2627 | 2609 |
2628 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 2610 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
2629 #pragma unused(numItems) | 2611 #pragma unused(numItems) |
2630 return [self initWithFloats:NULL forKeys:NULL count:0]; | 2612 return [self initWithValues:NULL forKeys:NULL count:0]; |
2631 } | 2613 } |
2632 | 2614 |
2633 - (void)dealloc { | 2615 - (void)dealloc { |
2634 NSAssert(!_autocreator, | 2616 NSAssert(!_autocreator, |
2635 @"%@: Autocreator must be cleared before release, autocreator: %@", | 2617 @"%@: Autocreator must be cleared before release, autocreator: %@", |
2636 [self class], _autocreator); | 2618 [self class], _autocreator); |
2637 [_dictionary release]; | 2619 [_dictionary release]; |
2638 [super dealloc]; | 2620 [super dealloc]; |
2639 } | 2621 } |
2640 | 2622 |
2641 - (instancetype)copyWithZone:(NSZone *)zone { | 2623 - (instancetype)copyWithZone:(NSZone *)zone { |
2642 return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]
; | 2624 return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]
; |
2643 } | 2625 } |
2644 | 2626 |
2645 - (BOOL)isEqual:(id)other { | 2627 - (BOOL)isEqual:(GPBUInt32FloatDictionary *)other { |
2646 if (self == other) { | 2628 if (self == other) { |
2647 return YES; | 2629 return YES; |
2648 } | 2630 } |
2649 if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) { | 2631 if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) { |
2650 return NO; | 2632 return NO; |
2651 } | 2633 } |
2652 GPBUInt32FloatDictionary *otherDictionary = other; | 2634 return [_dictionary isEqual:other->_dictionary]; |
2653 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
2654 } | 2635 } |
2655 | 2636 |
2656 - (NSUInteger)hash { | 2637 - (NSUInteger)hash { |
2657 return _dictionary.count; | 2638 return _dictionary.count; |
2658 } | 2639 } |
2659 | 2640 |
2660 - (NSString *)description { | 2641 - (NSString *)description { |
2661 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 2642 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
2662 } | 2643 } |
2663 | 2644 |
2664 - (NSUInteger)count { | 2645 - (NSUInteger)count { |
2665 return _dictionary.count; | 2646 return _dictionary.count; |
2666 } | 2647 } |
2667 | 2648 |
2668 - (void)enumerateKeysAndFloatsUsingBlock: | 2649 - (void)enumerateKeysAndValuesUsingBlock: |
2669 (void (^)(uint32_t key, float value, BOOL *stop))block { | 2650 (void (^)(uint32_t key, float value, BOOL *stop))block { |
2670 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 2651 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
2671 NSNumber *aValue, | 2652 NSNumber *aValue, |
2672 BOOL *stop) { | 2653 BOOL *stop) { |
2673 block([aKey unsignedIntValue], [aValue floatValue], stop); | 2654 block([aKey unsignedIntValue], [aValue floatValue], stop); |
2674 }]; | 2655 }]; |
2675 } | 2656 } |
2676 | 2657 |
2677 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 2658 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
2678 NSUInteger count = _dictionary.count; | 2659 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2716 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | 2697 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); |
2717 }]; | 2698 }]; |
2718 } | 2699 } |
2719 | 2700 |
2720 - (void)setGPBGenericValue:(GPBGenericValue *)value | 2701 - (void)setGPBGenericValue:(GPBGenericValue *)value |
2721 forGPBGenericValueKey:(GPBGenericValue *)key { | 2702 forGPBGenericValueKey:(GPBGenericValue *)key { |
2722 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)]; | 2703 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)]; |
2723 } | 2704 } |
2724 | 2705 |
2725 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 2706 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
2726 [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, BOOL *stop
) { | 2707 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, float value, BOOL *stop
) { |
2727 #pragma unused(stop) | 2708 #pragma unused(stop) |
2728 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%.*g", FLT_DIG, value]); | 2709 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%.*g", FLT_DIG, value]); |
2729 }]; | 2710 }]; |
2730 } | 2711 } |
2731 | 2712 |
2732 - (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key { | 2713 - (BOOL)valueForKey:(uint32_t)key value:(float *)value { |
2733 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 2714 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
2734 if (wrapped && value) { | 2715 if (wrapped && value) { |
2735 *value = [wrapped floatValue]; | 2716 *value = [wrapped floatValue]; |
2736 } | 2717 } |
2737 return (wrapped != NULL); | 2718 return (wrapped != NULL); |
2738 } | 2719 } |
2739 | 2720 |
2740 - (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary { | 2721 - (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary { |
2741 if (otherDictionary) { | 2722 if (otherDictionary) { |
2742 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 2723 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
2743 if (_autocreator) { | 2724 if (_autocreator) { |
2744 GPBAutocreatedDictionaryModified(_autocreator, self); | 2725 GPBAutocreatedDictionaryModified(_autocreator, self); |
2745 } | 2726 } |
2746 } | 2727 } |
2747 } | 2728 } |
2748 | 2729 |
2749 - (void)setFloat:(float)value forKey:(uint32_t)key { | 2730 - (void)setValue:(float)value forKey:(uint32_t)key { |
2750 [_dictionary setObject:@(value) forKey:@(key)]; | 2731 [_dictionary setObject:@(value) forKey:@(key)]; |
2751 if (_autocreator) { | 2732 if (_autocreator) { |
2752 GPBAutocreatedDictionaryModified(_autocreator, self); | 2733 GPBAutocreatedDictionaryModified(_autocreator, self); |
2753 } | 2734 } |
2754 } | 2735 } |
2755 | 2736 |
2756 - (void)removeFloatForKey:(uint32_t)aKey { | 2737 - (void)removeValueForKey:(uint32_t)aKey { |
2757 [_dictionary removeObjectForKey:@(aKey)]; | 2738 [_dictionary removeObjectForKey:@(aKey)]; |
2758 } | 2739 } |
2759 | 2740 |
2760 - (void)removeAll { | 2741 - (void)removeAll { |
2761 [_dictionary removeAllObjects]; | 2742 [_dictionary removeAllObjects]; |
2762 } | 2743 } |
2763 | 2744 |
2764 @end | 2745 @end |
2765 | 2746 |
2766 #pragma mark - UInt32 -> Double | 2747 #pragma mark - UInt32 -> Double |
2767 | 2748 |
2768 @implementation GPBUInt32DoubleDictionary { | 2749 @implementation GPBUInt32DoubleDictionary { |
2769 @package | 2750 @package |
2770 NSMutableDictionary *_dictionary; | 2751 NSMutableDictionary *_dictionary; |
2771 } | 2752 } |
2772 | 2753 |
2773 + (instancetype)dictionary { | 2754 + (instancetype)dictionary { |
2774 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; | 2755 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
2775 } | 2756 } |
2776 | 2757 |
2777 + (instancetype)dictionaryWithDouble:(double)value | 2758 + (instancetype)dictionaryWithValue:(double)value |
2778 forKey:(uint32_t)key { | 2759 forKey:(uint32_t)key { |
2779 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 2760 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
2780 // on to get the type correct. | 2761 // on to get the type correct. |
2781 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDoubles:&value | 2762 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithValues:&value |
2782 forKeys:&key | 2763 forKeys:&key |
2783 count:1] autorelea
se]; | 2764 count:1] autoreleas
e]; |
2784 } | 2765 } |
2785 | 2766 |
2786 + (instancetype)dictionaryWithDoubles:(const double [])values | 2767 + (instancetype)dictionaryWithValues:(const double [])values |
2787 forKeys:(const uint32_t [])keys | 2768 forKeys:(const uint32_t [])keys |
2788 count:(NSUInteger)count { | 2769 count:(NSUInteger)count { |
2789 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 2770 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
2790 // on to get the type correct. | 2771 // on to get the type correct. |
2791 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDoubles:values | 2772 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithValues:values |
2792 forKeys:keys | 2773 forKeys:keys |
2793 count:count] autore
lease]; | 2774 count:count] autore
lease]; |
2794 } | 2775 } |
2795 | 2776 |
2796 + (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary
{ | 2777 + (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary
{ |
2797 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 2778 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
2798 // on to get the type correct. | 2779 // on to get the type correct. |
2799 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 2780 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
2800 } | 2781 } |
2801 | 2782 |
2802 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 2783 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
2803 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 2784 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
2804 } | 2785 } |
2805 | 2786 |
2806 - (instancetype)init { | 2787 - (instancetype)init { |
2807 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 2788 return [self initWithValues:NULL forKeys:NULL count:0]; |
2808 } | 2789 } |
2809 | 2790 |
2810 - (instancetype)initWithDoubles:(const double [])values | 2791 - (instancetype)initWithValues:(const double [])values |
2811 forKeys:(const uint32_t [])keys | 2792 forKeys:(const uint32_t [])keys |
2812 count:(NSUInteger)count { | 2793 count:(NSUInteger)count { |
2813 self = [super init]; | 2794 self = [super init]; |
2814 if (self) { | 2795 if (self) { |
2815 _dictionary = [[NSMutableDictionary alloc] init]; | 2796 _dictionary = [[NSMutableDictionary alloc] init]; |
2816 if (count && values && keys) { | 2797 if (count && values && keys) { |
2817 for (NSUInteger i = 0; i < count; ++i) { | 2798 for (NSUInteger i = 0; i < count; ++i) { |
2818 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 2799 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
2819 } | 2800 } |
2820 } | 2801 } |
2821 } | 2802 } |
2822 return self; | 2803 return self; |
2823 } | 2804 } |
2824 | 2805 |
2825 - (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary { | 2806 - (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary { |
2826 self = [self initWithDoubles:NULL forKeys:NULL count:0]; | 2807 self = [self initWithValues:NULL forKeys:NULL count:0]; |
2827 if (self) { | 2808 if (self) { |
2828 if (dictionary) { | 2809 if (dictionary) { |
2829 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 2810 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
2830 } | 2811 } |
2831 } | 2812 } |
2832 return self; | 2813 return self; |
2833 } | 2814 } |
2834 | 2815 |
2835 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 2816 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
2836 #pragma unused(numItems) | 2817 #pragma unused(numItems) |
2837 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 2818 return [self initWithValues:NULL forKeys:NULL count:0]; |
2838 } | 2819 } |
2839 | 2820 |
2840 - (void)dealloc { | 2821 - (void)dealloc { |
2841 NSAssert(!_autocreator, | 2822 NSAssert(!_autocreator, |
2842 @"%@: Autocreator must be cleared before release, autocreator: %@", | 2823 @"%@: Autocreator must be cleared before release, autocreator: %@", |
2843 [self class], _autocreator); | 2824 [self class], _autocreator); |
2844 [_dictionary release]; | 2825 [_dictionary release]; |
2845 [super dealloc]; | 2826 [super dealloc]; |
2846 } | 2827 } |
2847 | 2828 |
2848 - (instancetype)copyWithZone:(NSZone *)zone { | 2829 - (instancetype)copyWithZone:(NSZone *)zone { |
2849 return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self
]; | 2830 return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self
]; |
2850 } | 2831 } |
2851 | 2832 |
2852 - (BOOL)isEqual:(id)other { | 2833 - (BOOL)isEqual:(GPBUInt32DoubleDictionary *)other { |
2853 if (self == other) { | 2834 if (self == other) { |
2854 return YES; | 2835 return YES; |
2855 } | 2836 } |
2856 if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) { | 2837 if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) { |
2857 return NO; | 2838 return NO; |
2858 } | 2839 } |
2859 GPBUInt32DoubleDictionary *otherDictionary = other; | 2840 return [_dictionary isEqual:other->_dictionary]; |
2860 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
2861 } | 2841 } |
2862 | 2842 |
2863 - (NSUInteger)hash { | 2843 - (NSUInteger)hash { |
2864 return _dictionary.count; | 2844 return _dictionary.count; |
2865 } | 2845 } |
2866 | 2846 |
2867 - (NSString *)description { | 2847 - (NSString *)description { |
2868 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 2848 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
2869 } | 2849 } |
2870 | 2850 |
2871 - (NSUInteger)count { | 2851 - (NSUInteger)count { |
2872 return _dictionary.count; | 2852 return _dictionary.count; |
2873 } | 2853 } |
2874 | 2854 |
2875 - (void)enumerateKeysAndDoublesUsingBlock: | 2855 - (void)enumerateKeysAndValuesUsingBlock: |
2876 (void (^)(uint32_t key, double value, BOOL *stop))block { | 2856 (void (^)(uint32_t key, double value, BOOL *stop))block { |
2877 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 2857 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
2878 NSNumber *aValue, | 2858 NSNumber *aValue, |
2879 BOOL *stop) { | 2859 BOOL *stop) { |
2880 block([aKey unsignedIntValue], [aValue doubleValue], stop); | 2860 block([aKey unsignedIntValue], [aValue doubleValue], stop); |
2881 }]; | 2861 }]; |
2882 } | 2862 } |
2883 | 2863 |
2884 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 2864 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
2885 NSUInteger count = _dictionary.count; | 2865 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2923 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | 2903 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); |
2924 }]; | 2904 }]; |
2925 } | 2905 } |
2926 | 2906 |
2927 - (void)setGPBGenericValue:(GPBGenericValue *)value | 2907 - (void)setGPBGenericValue:(GPBGenericValue *)value |
2928 forGPBGenericValueKey:(GPBGenericValue *)key { | 2908 forGPBGenericValueKey:(GPBGenericValue *)key { |
2929 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)]; | 2909 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)]; |
2930 } | 2910 } |
2931 | 2911 |
2932 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 2912 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
2933 [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, BOOL *st
op) { | 2913 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, double value, BOOL *sto
p) { |
2934 #pragma unused(stop) | 2914 #pragma unused(stop) |
2935 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%.*lg", DBL_DIG, value]); | 2915 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%.*lg", DBL_DIG, value]); |
2936 }]; | 2916 }]; |
2937 } | 2917 } |
2938 | 2918 |
2939 - (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key { | 2919 - (BOOL)valueForKey:(uint32_t)key value:(double *)value { |
2940 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 2920 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
2941 if (wrapped && value) { | 2921 if (wrapped && value) { |
2942 *value = [wrapped doubleValue]; | 2922 *value = [wrapped doubleValue]; |
2943 } | 2923 } |
2944 return (wrapped != NULL); | 2924 return (wrapped != NULL); |
2945 } | 2925 } |
2946 | 2926 |
2947 - (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary { | 2927 - (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary { |
2948 if (otherDictionary) { | 2928 if (otherDictionary) { |
2949 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 2929 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
2950 if (_autocreator) { | 2930 if (_autocreator) { |
2951 GPBAutocreatedDictionaryModified(_autocreator, self); | 2931 GPBAutocreatedDictionaryModified(_autocreator, self); |
2952 } | 2932 } |
2953 } | 2933 } |
2954 } | 2934 } |
2955 | 2935 |
2956 - (void)setDouble:(double)value forKey:(uint32_t)key { | 2936 - (void)setValue:(double)value forKey:(uint32_t)key { |
2957 [_dictionary setObject:@(value) forKey:@(key)]; | 2937 [_dictionary setObject:@(value) forKey:@(key)]; |
2958 if (_autocreator) { | 2938 if (_autocreator) { |
2959 GPBAutocreatedDictionaryModified(_autocreator, self); | 2939 GPBAutocreatedDictionaryModified(_autocreator, self); |
2960 } | 2940 } |
2961 } | 2941 } |
2962 | 2942 |
2963 - (void)removeDoubleForKey:(uint32_t)aKey { | 2943 - (void)removeValueForKey:(uint32_t)aKey { |
2964 [_dictionary removeObjectForKey:@(aKey)]; | 2944 [_dictionary removeObjectForKey:@(aKey)]; |
2965 } | 2945 } |
2966 | 2946 |
2967 - (void)removeAll { | 2947 - (void)removeAll { |
2968 [_dictionary removeAllObjects]; | 2948 [_dictionary removeAllObjects]; |
2969 } | 2949 } |
2970 | 2950 |
2971 @end | 2951 @end |
2972 | 2952 |
2973 #pragma mark - UInt32 -> Enum | 2953 #pragma mark - UInt32 -> Enum |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3077 @"%@: Autocreator must be cleared before release, autocreator: %@", | 3057 @"%@: Autocreator must be cleared before release, autocreator: %@", |
3078 [self class], _autocreator); | 3058 [self class], _autocreator); |
3079 [_dictionary release]; | 3059 [_dictionary release]; |
3080 [super dealloc]; | 3060 [super dealloc]; |
3081 } | 3061 } |
3082 | 3062 |
3083 - (instancetype)copyWithZone:(NSZone *)zone { | 3063 - (instancetype)copyWithZone:(NSZone *)zone { |
3084 return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; | 3064 return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; |
3085 } | 3065 } |
3086 | 3066 |
3087 - (BOOL)isEqual:(id)other { | 3067 - (BOOL)isEqual:(GPBUInt32EnumDictionary *)other { |
3088 if (self == other) { | 3068 if (self == other) { |
3089 return YES; | 3069 return YES; |
3090 } | 3070 } |
3091 if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) { | 3071 if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) { |
3092 return NO; | 3072 return NO; |
3093 } | 3073 } |
3094 GPBUInt32EnumDictionary *otherDictionary = other; | 3074 return [_dictionary isEqual:other->_dictionary]; |
3095 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
3096 } | 3075 } |
3097 | 3076 |
3098 - (NSUInteger)hash { | 3077 - (NSUInteger)hash { |
3099 return _dictionary.count; | 3078 return _dictionary.count; |
3100 } | 3079 } |
3101 | 3080 |
3102 - (NSString *)description { | 3081 - (NSString *)description { |
3103 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 3082 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
3104 } | 3083 } |
3105 | 3084 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3176 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)]; | 3155 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)]; |
3177 } | 3156 } |
3178 | 3157 |
3179 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 3158 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
3180 [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL
*stop) { | 3159 [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL
*stop) { |
3181 #pragma unused(stop) | 3160 #pragma unused(stop) |
3182 block([NSString stringWithFormat:@"%u", key], @(value)); | 3161 block([NSString stringWithFormat:@"%u", key], @(value)); |
3183 }]; | 3162 }]; |
3184 } | 3163 } |
3185 | 3164 |
3186 - (BOOL)getEnum:(int32_t *)value forKey:(uint32_t)key { | 3165 - (BOOL)valueForKey:(uint32_t)key value:(int32_t *)value { |
3187 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 3166 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
3188 if (wrapped && value) { | 3167 if (wrapped && value) { |
3189 int32_t result = [wrapped intValue]; | 3168 int32_t result = [wrapped intValue]; |
3190 if (!_validationFunc(result)) { | 3169 if (!_validationFunc(result)) { |
3191 result = kGPBUnrecognizedEnumeratorValue; | 3170 result = kGPBUnrecognizedEnumeratorValue; |
3192 } | 3171 } |
3193 *value = result; | 3172 *value = result; |
3194 } | 3173 } |
3195 return (wrapped != NULL); | 3174 return (wrapped != NULL); |
3196 } | 3175 } |
3197 | 3176 |
3198 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint32_t)key { | 3177 - (BOOL)valueForKey:(uint32_t)key rawValue:(int32_t *)rawValue { |
3199 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 3178 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
3200 if (wrapped && rawValue) { | 3179 if (wrapped && rawValue) { |
3201 *rawValue = [wrapped intValue]; | 3180 *rawValue = [wrapped intValue]; |
3202 } | 3181 } |
3203 return (wrapped != NULL); | 3182 return (wrapped != NULL); |
3204 } | 3183 } |
3205 | 3184 |
3206 - (void)enumerateKeysAndEnumsUsingBlock: | 3185 - (void)enumerateKeysAndValuesUsingBlock: |
3207 (void (^)(uint32_t key, int32_t value, BOOL *stop))block { | 3186 (void (^)(uint32_t key, int32_t value, BOOL *stop))block { |
3208 GPBEnumValidationFunc func = _validationFunc; | 3187 GPBEnumValidationFunc func = _validationFunc; |
3209 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 3188 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
3210 NSNumber *aValue, | 3189 NSNumber *aValue, |
3211 BOOL *stop) { | 3190 BOOL *stop) { |
3212 int32_t unwrapped = [aValue intValue]; | 3191 int32_t unwrapped = [aValue intValue]; |
3213 if (!func(unwrapped)) { | 3192 if (!func(unwrapped)) { |
3214 unwrapped = kGPBUnrecognizedEnumeratorValue; | 3193 unwrapped = kGPBUnrecognizedEnumeratorValue; |
3215 } | 3194 } |
3216 block([aKey unsignedIntValue], unwrapped, stop); | 3195 block([aKey unsignedIntValue], unwrapped, stop); |
3217 }]; | 3196 }]; |
3218 } | 3197 } |
3219 | 3198 |
3220 - (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary { | 3199 - (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary { |
3221 if (otherDictionary) { | 3200 if (otherDictionary) { |
3222 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 3201 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
3223 if (_autocreator) { | 3202 if (_autocreator) { |
3224 GPBAutocreatedDictionaryModified(_autocreator, self); | 3203 GPBAutocreatedDictionaryModified(_autocreator, self); |
3225 } | 3204 } |
3226 } | 3205 } |
3227 } | 3206 } |
3228 | 3207 |
3229 - (void)setRawValue:(int32_t)value forKey:(uint32_t)key { | 3208 - (void)setRawValue:(int32_t)value forKey:(uint32_t)key { |
3230 [_dictionary setObject:@(value) forKey:@(key)]; | 3209 [_dictionary setObject:@(value) forKey:@(key)]; |
3231 if (_autocreator) { | 3210 if (_autocreator) { |
3232 GPBAutocreatedDictionaryModified(_autocreator, self); | 3211 GPBAutocreatedDictionaryModified(_autocreator, self); |
3233 } | 3212 } |
3234 } | 3213 } |
3235 | 3214 |
3236 - (void)removeEnumForKey:(uint32_t)aKey { | 3215 - (void)removeValueForKey:(uint32_t)aKey { |
3237 [_dictionary removeObjectForKey:@(aKey)]; | 3216 [_dictionary removeObjectForKey:@(aKey)]; |
3238 } | 3217 } |
3239 | 3218 |
3240 - (void)removeAll { | 3219 - (void)removeAll { |
3241 [_dictionary removeAllObjects]; | 3220 [_dictionary removeAllObjects]; |
3242 } | 3221 } |
3243 | 3222 |
3244 - (void)setEnum:(int32_t)value forKey:(uint32_t)key { | 3223 - (void)setValue:(int32_t)value forKey:(uint32_t)key { |
3245 if (!_validationFunc(value)) { | 3224 if (!_validationFunc(value)) { |
3246 [NSException raise:NSInvalidArgumentException | 3225 [NSException raise:NSInvalidArgumentException |
3247 format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum
value (%d)", | 3226 format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum
value (%d)", |
3248 value]; | 3227 value]; |
3249 } | 3228 } |
3250 | 3229 |
3251 [_dictionary setObject:@(value) forKey:@(key)]; | 3230 [_dictionary setObject:@(value) forKey:@(key)]; |
3252 if (_autocreator) { | 3231 if (_autocreator) { |
3253 GPBAutocreatedDictionaryModified(_autocreator, self); | 3232 GPBAutocreatedDictionaryModified(_autocreator, self); |
3254 } | 3233 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3339 @"%@: Autocreator must be cleared before release, autocreator: %@", | 3318 @"%@: Autocreator must be cleared before release, autocreator: %@", |
3340 [self class], _autocreator); | 3319 [self class], _autocreator); |
3341 [_dictionary release]; | 3320 [_dictionary release]; |
3342 [super dealloc]; | 3321 [super dealloc]; |
3343 } | 3322 } |
3344 | 3323 |
3345 - (instancetype)copyWithZone:(NSZone *)zone { | 3324 - (instancetype)copyWithZone:(NSZone *)zone { |
3346 return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self
]; | 3325 return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self
]; |
3347 } | 3326 } |
3348 | 3327 |
3349 - (BOOL)isEqual:(id)other { | 3328 - (BOOL)isEqual:(GPBUInt32ObjectDictionary *)other { |
3350 if (self == other) { | 3329 if (self == other) { |
3351 return YES; | 3330 return YES; |
3352 } | 3331 } |
3353 if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) { | 3332 if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) { |
3354 return NO; | 3333 return NO; |
3355 } | 3334 } |
3356 GPBUInt32ObjectDictionary *otherDictionary = other; | 3335 return [_dictionary isEqual:other->_dictionary]; |
3357 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
3358 } | 3336 } |
3359 | 3337 |
3360 - (NSUInteger)hash { | 3338 - (NSUInteger)hash { |
3361 return _dictionary.count; | 3339 return _dictionary.count; |
3362 } | 3340 } |
3363 | 3341 |
3364 - (NSString *)description { | 3342 - (NSString *)description { |
3365 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 3343 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
3366 } | 3344 } |
3367 | 3345 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3495 // This block of code is generated, do not edit it directly. | 3473 // This block of code is generated, do not edit it directly. |
3496 | 3474 |
3497 #pragma mark - Int32 -> UInt32 | 3475 #pragma mark - Int32 -> UInt32 |
3498 | 3476 |
3499 @implementation GPBInt32UInt32Dictionary { | 3477 @implementation GPBInt32UInt32Dictionary { |
3500 @package | 3478 @package |
3501 NSMutableDictionary *_dictionary; | 3479 NSMutableDictionary *_dictionary; |
3502 } | 3480 } |
3503 | 3481 |
3504 + (instancetype)dictionary { | 3482 + (instancetype)dictionary { |
3505 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; | 3483 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
3506 } | 3484 } |
3507 | 3485 |
3508 + (instancetype)dictionaryWithUInt32:(uint32_t)value | 3486 + (instancetype)dictionaryWithValue:(uint32_t)value |
3509 forKey:(int32_t)key { | 3487 forKey:(int32_t)key { |
3510 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 3488 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
3511 // on to get the type correct. | 3489 // on to get the type correct. |
3512 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithUInt32s:&value | 3490 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithValues:&value |
3513 forKeys:&key | 3491 forKeys:&key |
3514 count:1] autoreleas
e]; | 3492 count:1] autorelease
]; |
3515 } | 3493 } |
3516 | 3494 |
3517 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values | 3495 + (instancetype)dictionaryWithValues:(const uint32_t [])values |
3518 forKeys:(const int32_t [])keys | 3496 forKeys:(const int32_t [])keys |
3519 count:(NSUInteger)count { | 3497 count:(NSUInteger)count { |
3520 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 3498 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
3521 // on to get the type correct. | 3499 // on to get the type correct. |
3522 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithUInt32s:values | 3500 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithValues:values |
3523 forKeys:keys | 3501 forKeys:keys |
3524 count:count] autorel
ease]; | 3502 count:count] autorel
ease]; |
3525 } | 3503 } |
3526 | 3504 |
3527 + (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary
{ | 3505 + (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary
{ |
3528 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 3506 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
3529 // on to get the type correct. | 3507 // on to get the type correct. |
3530 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 3508 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
3531 } | 3509 } |
3532 | 3510 |
3533 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 3511 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
3534 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 3512 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
3535 } | 3513 } |
3536 | 3514 |
3537 - (instancetype)init { | 3515 - (instancetype)init { |
3538 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 3516 return [self initWithValues:NULL forKeys:NULL count:0]; |
3539 } | 3517 } |
3540 | 3518 |
3541 - (instancetype)initWithUInt32s:(const uint32_t [])values | 3519 - (instancetype)initWithValues:(const uint32_t [])values |
3542 forKeys:(const int32_t [])keys | 3520 forKeys:(const int32_t [])keys |
3543 count:(NSUInteger)count { | 3521 count:(NSUInteger)count { |
3544 self = [super init]; | 3522 self = [super init]; |
3545 if (self) { | 3523 if (self) { |
3546 _dictionary = [[NSMutableDictionary alloc] init]; | 3524 _dictionary = [[NSMutableDictionary alloc] init]; |
3547 if (count && values && keys) { | 3525 if (count && values && keys) { |
3548 for (NSUInteger i = 0; i < count; ++i) { | 3526 for (NSUInteger i = 0; i < count; ++i) { |
3549 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 3527 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
3550 } | 3528 } |
3551 } | 3529 } |
3552 } | 3530 } |
3553 return self; | 3531 return self; |
3554 } | 3532 } |
3555 | 3533 |
3556 - (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary { | 3534 - (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary { |
3557 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; | 3535 self = [self initWithValues:NULL forKeys:NULL count:0]; |
3558 if (self) { | 3536 if (self) { |
3559 if (dictionary) { | 3537 if (dictionary) { |
3560 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 3538 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
3561 } | 3539 } |
3562 } | 3540 } |
3563 return self; | 3541 return self; |
3564 } | 3542 } |
3565 | 3543 |
3566 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 3544 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
3567 #pragma unused(numItems) | 3545 #pragma unused(numItems) |
3568 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 3546 return [self initWithValues:NULL forKeys:NULL count:0]; |
3569 } | 3547 } |
3570 | 3548 |
3571 - (void)dealloc { | 3549 - (void)dealloc { |
3572 NSAssert(!_autocreator, | 3550 NSAssert(!_autocreator, |
3573 @"%@: Autocreator must be cleared before release, autocreator: %@", | 3551 @"%@: Autocreator must be cleared before release, autocreator: %@", |
3574 [self class], _autocreator); | 3552 [self class], _autocreator); |
3575 [_dictionary release]; | 3553 [_dictionary release]; |
3576 [super dealloc]; | 3554 [super dealloc]; |
3577 } | 3555 } |
3578 | 3556 |
3579 - (instancetype)copyWithZone:(NSZone *)zone { | 3557 - (instancetype)copyWithZone:(NSZone *)zone { |
3580 return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; | 3558 return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; |
3581 } | 3559 } |
3582 | 3560 |
3583 - (BOOL)isEqual:(id)other { | 3561 - (BOOL)isEqual:(GPBInt32UInt32Dictionary *)other { |
3584 if (self == other) { | 3562 if (self == other) { |
3585 return YES; | 3563 return YES; |
3586 } | 3564 } |
3587 if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) { | 3565 if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) { |
3588 return NO; | 3566 return NO; |
3589 } | 3567 } |
3590 GPBInt32UInt32Dictionary *otherDictionary = other; | 3568 return [_dictionary isEqual:other->_dictionary]; |
3591 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
3592 } | 3569 } |
3593 | 3570 |
3594 - (NSUInteger)hash { | 3571 - (NSUInteger)hash { |
3595 return _dictionary.count; | 3572 return _dictionary.count; |
3596 } | 3573 } |
3597 | 3574 |
3598 - (NSString *)description { | 3575 - (NSString *)description { |
3599 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 3576 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
3600 } | 3577 } |
3601 | 3578 |
3602 - (NSUInteger)count { | 3579 - (NSUInteger)count { |
3603 return _dictionary.count; | 3580 return _dictionary.count; |
3604 } | 3581 } |
3605 | 3582 |
3606 - (void)enumerateKeysAndUInt32sUsingBlock: | 3583 - (void)enumerateKeysAndValuesUsingBlock: |
3607 (void (^)(int32_t key, uint32_t value, BOOL *stop))block { | 3584 (void (^)(int32_t key, uint32_t value, BOOL *stop))block { |
3608 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 3585 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
3609 NSNumber *aValue, | 3586 NSNumber *aValue, |
3610 BOOL *stop) { | 3587 BOOL *stop) { |
3611 block([aKey intValue], [aValue unsignedIntValue], stop); | 3588 block([aKey intValue], [aValue unsignedIntValue], stop); |
3612 }]; | 3589 }]; |
3613 } | 3590 } |
3614 | 3591 |
3615 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 3592 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
3616 NSUInteger count = _dictionary.count; | 3593 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3654 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | 3631 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); |
3655 }]; | 3632 }]; |
3656 } | 3633 } |
3657 | 3634 |
3658 - (void)setGPBGenericValue:(GPBGenericValue *)value | 3635 - (void)setGPBGenericValue:(GPBGenericValue *)value |
3659 forGPBGenericValueKey:(GPBGenericValue *)key { | 3636 forGPBGenericValueKey:(GPBGenericValue *)key { |
3660 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)]; | 3637 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)]; |
3661 } | 3638 } |
3662 | 3639 |
3663 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 3640 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
3664 [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, BOOL *s
top) { | 3641 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, uint32_t value, BOOL *st
op) { |
3665 #pragma unused(stop) | 3642 #pragma unused(stop) |
3666 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%u", value]); | 3643 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%u", value]); |
3667 }]; | 3644 }]; |
3668 } | 3645 } |
3669 | 3646 |
3670 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key { | 3647 - (BOOL)valueForKey:(int32_t)key value:(uint32_t *)value { |
3671 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 3648 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
3672 if (wrapped && value) { | 3649 if (wrapped && value) { |
3673 *value = [wrapped unsignedIntValue]; | 3650 *value = [wrapped unsignedIntValue]; |
3674 } | 3651 } |
3675 return (wrapped != NULL); | 3652 return (wrapped != NULL); |
3676 } | 3653 } |
3677 | 3654 |
3678 - (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary { | 3655 - (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary { |
3679 if (otherDictionary) { | 3656 if (otherDictionary) { |
3680 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 3657 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
3681 if (_autocreator) { | 3658 if (_autocreator) { |
3682 GPBAutocreatedDictionaryModified(_autocreator, self); | 3659 GPBAutocreatedDictionaryModified(_autocreator, self); |
3683 } | 3660 } |
3684 } | 3661 } |
3685 } | 3662 } |
3686 | 3663 |
3687 - (void)setUInt32:(uint32_t)value forKey:(int32_t)key { | 3664 - (void)setValue:(uint32_t)value forKey:(int32_t)key { |
3688 [_dictionary setObject:@(value) forKey:@(key)]; | 3665 [_dictionary setObject:@(value) forKey:@(key)]; |
3689 if (_autocreator) { | 3666 if (_autocreator) { |
3690 GPBAutocreatedDictionaryModified(_autocreator, self); | 3667 GPBAutocreatedDictionaryModified(_autocreator, self); |
3691 } | 3668 } |
3692 } | 3669 } |
3693 | 3670 |
3694 - (void)removeUInt32ForKey:(int32_t)aKey { | 3671 - (void)removeValueForKey:(int32_t)aKey { |
3695 [_dictionary removeObjectForKey:@(aKey)]; | 3672 [_dictionary removeObjectForKey:@(aKey)]; |
3696 } | 3673 } |
3697 | 3674 |
3698 - (void)removeAll { | 3675 - (void)removeAll { |
3699 [_dictionary removeAllObjects]; | 3676 [_dictionary removeAllObjects]; |
3700 } | 3677 } |
3701 | 3678 |
3702 @end | 3679 @end |
3703 | 3680 |
3704 #pragma mark - Int32 -> Int32 | 3681 #pragma mark - Int32 -> Int32 |
3705 | 3682 |
3706 @implementation GPBInt32Int32Dictionary { | 3683 @implementation GPBInt32Int32Dictionary { |
3707 @package | 3684 @package |
3708 NSMutableDictionary *_dictionary; | 3685 NSMutableDictionary *_dictionary; |
3709 } | 3686 } |
3710 | 3687 |
3711 + (instancetype)dictionary { | 3688 + (instancetype)dictionary { |
3712 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; | 3689 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
3713 } | 3690 } |
3714 | 3691 |
3715 + (instancetype)dictionaryWithInt32:(int32_t)value | 3692 + (instancetype)dictionaryWithValue:(int32_t)value |
3716 forKey:(int32_t)key { | 3693 forKey:(int32_t)key { |
3717 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 3694 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
3718 // on to get the type correct. | 3695 // on to get the type correct. |
3719 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithInt32s:&value | 3696 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithValues:&value |
3720 forKeys:&key | 3697 forKeys:&key |
3721 count:1] autorelease]
; | 3698 count:1] autorelease]
; |
3722 } | 3699 } |
3723 | 3700 |
3724 + (instancetype)dictionaryWithInt32s:(const int32_t [])values | 3701 + (instancetype)dictionaryWithValues:(const int32_t [])values |
3725 forKeys:(const int32_t [])keys | 3702 forKeys:(const int32_t [])keys |
3726 count:(NSUInteger)count { | 3703 count:(NSUInteger)count { |
3727 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 3704 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
3728 // on to get the type correct. | 3705 // on to get the type correct. |
3729 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithInt32s:values | 3706 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithValues:values |
3730 forKeys:keys | 3707 forKeys:keys |
3731 count:count] autorele
ase]; | 3708 count:count] autorele
ase]; |
3732 } | 3709 } |
3733 | 3710 |
3734 + (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary { | 3711 + (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary { |
3735 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 3712 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
3736 // on to get the type correct. | 3713 // on to get the type correct. |
3737 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 3714 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
3738 } | 3715 } |
3739 | 3716 |
3740 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 3717 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
3741 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 3718 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
3742 } | 3719 } |
3743 | 3720 |
3744 - (instancetype)init { | 3721 - (instancetype)init { |
3745 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 3722 return [self initWithValues:NULL forKeys:NULL count:0]; |
3746 } | 3723 } |
3747 | 3724 |
3748 - (instancetype)initWithInt32s:(const int32_t [])values | 3725 - (instancetype)initWithValues:(const int32_t [])values |
3749 forKeys:(const int32_t [])keys | 3726 forKeys:(const int32_t [])keys |
3750 count:(NSUInteger)count { | 3727 count:(NSUInteger)count { |
3751 self = [super init]; | 3728 self = [super init]; |
3752 if (self) { | 3729 if (self) { |
3753 _dictionary = [[NSMutableDictionary alloc] init]; | 3730 _dictionary = [[NSMutableDictionary alloc] init]; |
3754 if (count && values && keys) { | 3731 if (count && values && keys) { |
3755 for (NSUInteger i = 0; i < count; ++i) { | 3732 for (NSUInteger i = 0; i < count; ++i) { |
3756 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 3733 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
3757 } | 3734 } |
3758 } | 3735 } |
3759 } | 3736 } |
3760 return self; | 3737 return self; |
3761 } | 3738 } |
3762 | 3739 |
3763 - (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary { | 3740 - (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary { |
3764 self = [self initWithInt32s:NULL forKeys:NULL count:0]; | 3741 self = [self initWithValues:NULL forKeys:NULL count:0]; |
3765 if (self) { | 3742 if (self) { |
3766 if (dictionary) { | 3743 if (dictionary) { |
3767 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 3744 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
3768 } | 3745 } |
3769 } | 3746 } |
3770 return self; | 3747 return self; |
3771 } | 3748 } |
3772 | 3749 |
3773 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 3750 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
3774 #pragma unused(numItems) | 3751 #pragma unused(numItems) |
3775 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 3752 return [self initWithValues:NULL forKeys:NULL count:0]; |
3776 } | 3753 } |
3777 | 3754 |
3778 - (void)dealloc { | 3755 - (void)dealloc { |
3779 NSAssert(!_autocreator, | 3756 NSAssert(!_autocreator, |
3780 @"%@: Autocreator must be cleared before release, autocreator: %@", | 3757 @"%@: Autocreator must be cleared before release, autocreator: %@", |
3781 [self class], _autocreator); | 3758 [self class], _autocreator); |
3782 [_dictionary release]; | 3759 [_dictionary release]; |
3783 [super dealloc]; | 3760 [super dealloc]; |
3784 } | 3761 } |
3785 | 3762 |
3786 - (instancetype)copyWithZone:(NSZone *)zone { | 3763 - (instancetype)copyWithZone:(NSZone *)zone { |
3787 return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]; | 3764 return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]; |
3788 } | 3765 } |
3789 | 3766 |
3790 - (BOOL)isEqual:(id)other { | 3767 - (BOOL)isEqual:(GPBInt32Int32Dictionary *)other { |
3791 if (self == other) { | 3768 if (self == other) { |
3792 return YES; | 3769 return YES; |
3793 } | 3770 } |
3794 if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) { | 3771 if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) { |
3795 return NO; | 3772 return NO; |
3796 } | 3773 } |
3797 GPBInt32Int32Dictionary *otherDictionary = other; | 3774 return [_dictionary isEqual:other->_dictionary]; |
3798 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
3799 } | 3775 } |
3800 | 3776 |
3801 - (NSUInteger)hash { | 3777 - (NSUInteger)hash { |
3802 return _dictionary.count; | 3778 return _dictionary.count; |
3803 } | 3779 } |
3804 | 3780 |
3805 - (NSString *)description { | 3781 - (NSString *)description { |
3806 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 3782 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
3807 } | 3783 } |
3808 | 3784 |
3809 - (NSUInteger)count { | 3785 - (NSUInteger)count { |
3810 return _dictionary.count; | 3786 return _dictionary.count; |
3811 } | 3787 } |
3812 | 3788 |
3813 - (void)enumerateKeysAndInt32sUsingBlock: | 3789 - (void)enumerateKeysAndValuesUsingBlock: |
3814 (void (^)(int32_t key, int32_t value, BOOL *stop))block { | 3790 (void (^)(int32_t key, int32_t value, BOOL *stop))block { |
3815 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 3791 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
3816 NSNumber *aValue, | 3792 NSNumber *aValue, |
3817 BOOL *stop) { | 3793 BOOL *stop) { |
3818 block([aKey intValue], [aValue intValue], stop); | 3794 block([aKey intValue], [aValue intValue], stop); |
3819 }]; | 3795 }]; |
3820 } | 3796 } |
3821 | 3797 |
3822 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 3798 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
3823 NSUInteger count = _dictionary.count; | 3799 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3861 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | 3837 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); |
3862 }]; | 3838 }]; |
3863 } | 3839 } |
3864 | 3840 |
3865 - (void)setGPBGenericValue:(GPBGenericValue *)value | 3841 - (void)setGPBGenericValue:(GPBGenericValue *)value |
3866 forGPBGenericValueKey:(GPBGenericValue *)key { | 3842 forGPBGenericValueKey:(GPBGenericValue *)key { |
3867 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)]; | 3843 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)]; |
3868 } | 3844 } |
3869 | 3845 |
3870 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 3846 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
3871 [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, BOOL *sto
p) { | 3847 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, int32_t value, BOOL *sto
p) { |
3872 #pragma unused(stop) | 3848 #pragma unused(stop) |
3873 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%d", value]); | 3849 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%d", value]); |
3874 }]; | 3850 }]; |
3875 } | 3851 } |
3876 | 3852 |
3877 - (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key { | 3853 - (BOOL)valueForKey:(int32_t)key value:(int32_t *)value { |
3878 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 3854 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
3879 if (wrapped && value) { | 3855 if (wrapped && value) { |
3880 *value = [wrapped intValue]; | 3856 *value = [wrapped intValue]; |
3881 } | 3857 } |
3882 return (wrapped != NULL); | 3858 return (wrapped != NULL); |
3883 } | 3859 } |
3884 | 3860 |
3885 - (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary { | 3861 - (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary { |
3886 if (otherDictionary) { | 3862 if (otherDictionary) { |
3887 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 3863 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
3888 if (_autocreator) { | 3864 if (_autocreator) { |
3889 GPBAutocreatedDictionaryModified(_autocreator, self); | 3865 GPBAutocreatedDictionaryModified(_autocreator, self); |
3890 } | 3866 } |
3891 } | 3867 } |
3892 } | 3868 } |
3893 | 3869 |
3894 - (void)setInt32:(int32_t)value forKey:(int32_t)key { | 3870 - (void)setValue:(int32_t)value forKey:(int32_t)key { |
3895 [_dictionary setObject:@(value) forKey:@(key)]; | 3871 [_dictionary setObject:@(value) forKey:@(key)]; |
3896 if (_autocreator) { | 3872 if (_autocreator) { |
3897 GPBAutocreatedDictionaryModified(_autocreator, self); | 3873 GPBAutocreatedDictionaryModified(_autocreator, self); |
3898 } | 3874 } |
3899 } | 3875 } |
3900 | 3876 |
3901 - (void)removeInt32ForKey:(int32_t)aKey { | 3877 - (void)removeValueForKey:(int32_t)aKey { |
3902 [_dictionary removeObjectForKey:@(aKey)]; | 3878 [_dictionary removeObjectForKey:@(aKey)]; |
3903 } | 3879 } |
3904 | 3880 |
3905 - (void)removeAll { | 3881 - (void)removeAll { |
3906 [_dictionary removeAllObjects]; | 3882 [_dictionary removeAllObjects]; |
3907 } | 3883 } |
3908 | 3884 |
3909 @end | 3885 @end |
3910 | 3886 |
3911 #pragma mark - Int32 -> UInt64 | 3887 #pragma mark - Int32 -> UInt64 |
3912 | 3888 |
3913 @implementation GPBInt32UInt64Dictionary { | 3889 @implementation GPBInt32UInt64Dictionary { |
3914 @package | 3890 @package |
3915 NSMutableDictionary *_dictionary; | 3891 NSMutableDictionary *_dictionary; |
3916 } | 3892 } |
3917 | 3893 |
3918 + (instancetype)dictionary { | 3894 + (instancetype)dictionary { |
3919 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; | 3895 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
3920 } | 3896 } |
3921 | 3897 |
3922 + (instancetype)dictionaryWithUInt64:(uint64_t)value | 3898 + (instancetype)dictionaryWithValue:(uint64_t)value |
3923 forKey:(int32_t)key { | 3899 forKey:(int32_t)key { |
3924 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 3900 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
3925 // on to get the type correct. | 3901 // on to get the type correct. |
3926 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithUInt64s:&value | 3902 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithValues:&value |
3927 forKeys:&key | 3903 forKeys:&key |
3928 count:1] autoreleas
e]; | 3904 count:1] autorelease
]; |
3929 } | 3905 } |
3930 | 3906 |
3931 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values | 3907 + (instancetype)dictionaryWithValues:(const uint64_t [])values |
3932 forKeys:(const int32_t [])keys | 3908 forKeys:(const int32_t [])keys |
3933 count:(NSUInteger)count { | 3909 count:(NSUInteger)count { |
3934 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 3910 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
3935 // on to get the type correct. | 3911 // on to get the type correct. |
3936 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithUInt64s:values | 3912 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithValues:values |
3937 forKeys:keys | 3913 forKeys:keys |
3938 count:count] autorel
ease]; | 3914 count:count] autorel
ease]; |
3939 } | 3915 } |
3940 | 3916 |
3941 + (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary
{ | 3917 + (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary
{ |
3942 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 3918 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
3943 // on to get the type correct. | 3919 // on to get the type correct. |
3944 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 3920 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
3945 } | 3921 } |
3946 | 3922 |
3947 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 3923 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
3948 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 3924 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
3949 } | 3925 } |
3950 | 3926 |
3951 - (instancetype)init { | 3927 - (instancetype)init { |
3952 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 3928 return [self initWithValues:NULL forKeys:NULL count:0]; |
3953 } | 3929 } |
3954 | 3930 |
3955 - (instancetype)initWithUInt64s:(const uint64_t [])values | 3931 - (instancetype)initWithValues:(const uint64_t [])values |
3956 forKeys:(const int32_t [])keys | 3932 forKeys:(const int32_t [])keys |
3957 count:(NSUInteger)count { | 3933 count:(NSUInteger)count { |
3958 self = [super init]; | 3934 self = [super init]; |
3959 if (self) { | 3935 if (self) { |
3960 _dictionary = [[NSMutableDictionary alloc] init]; | 3936 _dictionary = [[NSMutableDictionary alloc] init]; |
3961 if (count && values && keys) { | 3937 if (count && values && keys) { |
3962 for (NSUInteger i = 0; i < count; ++i) { | 3938 for (NSUInteger i = 0; i < count; ++i) { |
3963 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 3939 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
3964 } | 3940 } |
3965 } | 3941 } |
3966 } | 3942 } |
3967 return self; | 3943 return self; |
3968 } | 3944 } |
3969 | 3945 |
3970 - (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary { | 3946 - (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary { |
3971 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; | 3947 self = [self initWithValues:NULL forKeys:NULL count:0]; |
3972 if (self) { | 3948 if (self) { |
3973 if (dictionary) { | 3949 if (dictionary) { |
3974 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 3950 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
3975 } | 3951 } |
3976 } | 3952 } |
3977 return self; | 3953 return self; |
3978 } | 3954 } |
3979 | 3955 |
3980 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 3956 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
3981 #pragma unused(numItems) | 3957 #pragma unused(numItems) |
3982 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 3958 return [self initWithValues:NULL forKeys:NULL count:0]; |
3983 } | 3959 } |
3984 | 3960 |
3985 - (void)dealloc { | 3961 - (void)dealloc { |
3986 NSAssert(!_autocreator, | 3962 NSAssert(!_autocreator, |
3987 @"%@: Autocreator must be cleared before release, autocreator: %@", | 3963 @"%@: Autocreator must be cleared before release, autocreator: %@", |
3988 [self class], _autocreator); | 3964 [self class], _autocreator); |
3989 [_dictionary release]; | 3965 [_dictionary release]; |
3990 [super dealloc]; | 3966 [super dealloc]; |
3991 } | 3967 } |
3992 | 3968 |
3993 - (instancetype)copyWithZone:(NSZone *)zone { | 3969 - (instancetype)copyWithZone:(NSZone *)zone { |
3994 return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; | 3970 return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; |
3995 } | 3971 } |
3996 | 3972 |
3997 - (BOOL)isEqual:(id)other { | 3973 - (BOOL)isEqual:(GPBInt32UInt64Dictionary *)other { |
3998 if (self == other) { | 3974 if (self == other) { |
3999 return YES; | 3975 return YES; |
4000 } | 3976 } |
4001 if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) { | 3977 if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) { |
4002 return NO; | 3978 return NO; |
4003 } | 3979 } |
4004 GPBInt32UInt64Dictionary *otherDictionary = other; | 3980 return [_dictionary isEqual:other->_dictionary]; |
4005 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
4006 } | 3981 } |
4007 | 3982 |
4008 - (NSUInteger)hash { | 3983 - (NSUInteger)hash { |
4009 return _dictionary.count; | 3984 return _dictionary.count; |
4010 } | 3985 } |
4011 | 3986 |
4012 - (NSString *)description { | 3987 - (NSString *)description { |
4013 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 3988 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
4014 } | 3989 } |
4015 | 3990 |
4016 - (NSUInteger)count { | 3991 - (NSUInteger)count { |
4017 return _dictionary.count; | 3992 return _dictionary.count; |
4018 } | 3993 } |
4019 | 3994 |
4020 - (void)enumerateKeysAndUInt64sUsingBlock: | 3995 - (void)enumerateKeysAndValuesUsingBlock: |
4021 (void (^)(int32_t key, uint64_t value, BOOL *stop))block { | 3996 (void (^)(int32_t key, uint64_t value, BOOL *stop))block { |
4022 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 3997 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
4023 NSNumber *aValue, | 3998 NSNumber *aValue, |
4024 BOOL *stop) { | 3999 BOOL *stop) { |
4025 block([aKey intValue], [aValue unsignedLongLongValue], stop); | 4000 block([aKey intValue], [aValue unsignedLongLongValue], stop); |
4026 }]; | 4001 }]; |
4027 } | 4002 } |
4028 | 4003 |
4029 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 4004 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
4030 NSUInteger count = _dictionary.count; | 4005 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4068 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | 4043 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); |
4069 }]; | 4044 }]; |
4070 } | 4045 } |
4071 | 4046 |
4072 - (void)setGPBGenericValue:(GPBGenericValue *)value | 4047 - (void)setGPBGenericValue:(GPBGenericValue *)value |
4073 forGPBGenericValueKey:(GPBGenericValue *)key { | 4048 forGPBGenericValueKey:(GPBGenericValue *)key { |
4074 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)]; | 4049 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)]; |
4075 } | 4050 } |
4076 | 4051 |
4077 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 4052 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
4078 [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, BOOL *s
top) { | 4053 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, uint64_t value, BOOL *st
op) { |
4079 #pragma unused(stop) | 4054 #pragma unused(stop) |
4080 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%llu", value]); | 4055 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%llu", value]); |
4081 }]; | 4056 }]; |
4082 } | 4057 } |
4083 | 4058 |
4084 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key { | 4059 - (BOOL)valueForKey:(int32_t)key value:(uint64_t *)value { |
4085 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 4060 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
4086 if (wrapped && value) { | 4061 if (wrapped && value) { |
4087 *value = [wrapped unsignedLongLongValue]; | 4062 *value = [wrapped unsignedLongLongValue]; |
4088 } | 4063 } |
4089 return (wrapped != NULL); | 4064 return (wrapped != NULL); |
4090 } | 4065 } |
4091 | 4066 |
4092 - (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary { | 4067 - (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary { |
4093 if (otherDictionary) { | 4068 if (otherDictionary) { |
4094 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 4069 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
4095 if (_autocreator) { | 4070 if (_autocreator) { |
4096 GPBAutocreatedDictionaryModified(_autocreator, self); | 4071 GPBAutocreatedDictionaryModified(_autocreator, self); |
4097 } | 4072 } |
4098 } | 4073 } |
4099 } | 4074 } |
4100 | 4075 |
4101 - (void)setUInt64:(uint64_t)value forKey:(int32_t)key { | 4076 - (void)setValue:(uint64_t)value forKey:(int32_t)key { |
4102 [_dictionary setObject:@(value) forKey:@(key)]; | 4077 [_dictionary setObject:@(value) forKey:@(key)]; |
4103 if (_autocreator) { | 4078 if (_autocreator) { |
4104 GPBAutocreatedDictionaryModified(_autocreator, self); | 4079 GPBAutocreatedDictionaryModified(_autocreator, self); |
4105 } | 4080 } |
4106 } | 4081 } |
4107 | 4082 |
4108 - (void)removeUInt64ForKey:(int32_t)aKey { | 4083 - (void)removeValueForKey:(int32_t)aKey { |
4109 [_dictionary removeObjectForKey:@(aKey)]; | 4084 [_dictionary removeObjectForKey:@(aKey)]; |
4110 } | 4085 } |
4111 | 4086 |
4112 - (void)removeAll { | 4087 - (void)removeAll { |
4113 [_dictionary removeAllObjects]; | 4088 [_dictionary removeAllObjects]; |
4114 } | 4089 } |
4115 | 4090 |
4116 @end | 4091 @end |
4117 | 4092 |
4118 #pragma mark - Int32 -> Int64 | 4093 #pragma mark - Int32 -> Int64 |
4119 | 4094 |
4120 @implementation GPBInt32Int64Dictionary { | 4095 @implementation GPBInt32Int64Dictionary { |
4121 @package | 4096 @package |
4122 NSMutableDictionary *_dictionary; | 4097 NSMutableDictionary *_dictionary; |
4123 } | 4098 } |
4124 | 4099 |
4125 + (instancetype)dictionary { | 4100 + (instancetype)dictionary { |
4126 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; | 4101 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
4127 } | 4102 } |
4128 | 4103 |
4129 + (instancetype)dictionaryWithInt64:(int64_t)value | 4104 + (instancetype)dictionaryWithValue:(int64_t)value |
4130 forKey:(int32_t)key { | 4105 forKey:(int32_t)key { |
4131 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 4106 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
4132 // on to get the type correct. | 4107 // on to get the type correct. |
4133 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithInt64s:&value | 4108 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithValues:&value |
4134 forKeys:&key | 4109 forKeys:&key |
4135 count:1] autorelease]
; | 4110 count:1] autorelease]
; |
4136 } | 4111 } |
4137 | 4112 |
4138 + (instancetype)dictionaryWithInt64s:(const int64_t [])values | 4113 + (instancetype)dictionaryWithValues:(const int64_t [])values |
4139 forKeys:(const int32_t [])keys | 4114 forKeys:(const int32_t [])keys |
4140 count:(NSUInteger)count { | 4115 count:(NSUInteger)count { |
4141 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 4116 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
4142 // on to get the type correct. | 4117 // on to get the type correct. |
4143 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithInt64s:values | 4118 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithValues:values |
4144 forKeys:keys | 4119 forKeys:keys |
4145 count:count] autorele
ase]; | 4120 count:count] autorele
ase]; |
4146 } | 4121 } |
4147 | 4122 |
4148 + (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary { | 4123 + (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary { |
4149 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 4124 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
4150 // on to get the type correct. | 4125 // on to get the type correct. |
4151 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 4126 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
4152 } | 4127 } |
4153 | 4128 |
4154 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 4129 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
4155 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 4130 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
4156 } | 4131 } |
4157 | 4132 |
4158 - (instancetype)init { | 4133 - (instancetype)init { |
4159 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 4134 return [self initWithValues:NULL forKeys:NULL count:0]; |
4160 } | 4135 } |
4161 | 4136 |
4162 - (instancetype)initWithInt64s:(const int64_t [])values | 4137 - (instancetype)initWithValues:(const int64_t [])values |
4163 forKeys:(const int32_t [])keys | 4138 forKeys:(const int32_t [])keys |
4164 count:(NSUInteger)count { | 4139 count:(NSUInteger)count { |
4165 self = [super init]; | 4140 self = [super init]; |
4166 if (self) { | 4141 if (self) { |
4167 _dictionary = [[NSMutableDictionary alloc] init]; | 4142 _dictionary = [[NSMutableDictionary alloc] init]; |
4168 if (count && values && keys) { | 4143 if (count && values && keys) { |
4169 for (NSUInteger i = 0; i < count; ++i) { | 4144 for (NSUInteger i = 0; i < count; ++i) { |
4170 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 4145 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
4171 } | 4146 } |
4172 } | 4147 } |
4173 } | 4148 } |
4174 return self; | 4149 return self; |
4175 } | 4150 } |
4176 | 4151 |
4177 - (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary { | 4152 - (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary { |
4178 self = [self initWithInt64s:NULL forKeys:NULL count:0]; | 4153 self = [self initWithValues:NULL forKeys:NULL count:0]; |
4179 if (self) { | 4154 if (self) { |
4180 if (dictionary) { | 4155 if (dictionary) { |
4181 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 4156 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
4182 } | 4157 } |
4183 } | 4158 } |
4184 return self; | 4159 return self; |
4185 } | 4160 } |
4186 | 4161 |
4187 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 4162 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
4188 #pragma unused(numItems) | 4163 #pragma unused(numItems) |
4189 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 4164 return [self initWithValues:NULL forKeys:NULL count:0]; |
4190 } | 4165 } |
4191 | 4166 |
4192 - (void)dealloc { | 4167 - (void)dealloc { |
4193 NSAssert(!_autocreator, | 4168 NSAssert(!_autocreator, |
4194 @"%@: Autocreator must be cleared before release, autocreator: %@", | 4169 @"%@: Autocreator must be cleared before release, autocreator: %@", |
4195 [self class], _autocreator); | 4170 [self class], _autocreator); |
4196 [_dictionary release]; | 4171 [_dictionary release]; |
4197 [super dealloc]; | 4172 [super dealloc]; |
4198 } | 4173 } |
4199 | 4174 |
4200 - (instancetype)copyWithZone:(NSZone *)zone { | 4175 - (instancetype)copyWithZone:(NSZone *)zone { |
4201 return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]; | 4176 return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]; |
4202 } | 4177 } |
4203 | 4178 |
4204 - (BOOL)isEqual:(id)other { | 4179 - (BOOL)isEqual:(GPBInt32Int64Dictionary *)other { |
4205 if (self == other) { | 4180 if (self == other) { |
4206 return YES; | 4181 return YES; |
4207 } | 4182 } |
4208 if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) { | 4183 if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) { |
4209 return NO; | 4184 return NO; |
4210 } | 4185 } |
4211 GPBInt32Int64Dictionary *otherDictionary = other; | 4186 return [_dictionary isEqual:other->_dictionary]; |
4212 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
4213 } | 4187 } |
4214 | 4188 |
4215 - (NSUInteger)hash { | 4189 - (NSUInteger)hash { |
4216 return _dictionary.count; | 4190 return _dictionary.count; |
4217 } | 4191 } |
4218 | 4192 |
4219 - (NSString *)description { | 4193 - (NSString *)description { |
4220 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 4194 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
4221 } | 4195 } |
4222 | 4196 |
4223 - (NSUInteger)count { | 4197 - (NSUInteger)count { |
4224 return _dictionary.count; | 4198 return _dictionary.count; |
4225 } | 4199 } |
4226 | 4200 |
4227 - (void)enumerateKeysAndInt64sUsingBlock: | 4201 - (void)enumerateKeysAndValuesUsingBlock: |
4228 (void (^)(int32_t key, int64_t value, BOOL *stop))block { | 4202 (void (^)(int32_t key, int64_t value, BOOL *stop))block { |
4229 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 4203 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
4230 NSNumber *aValue, | 4204 NSNumber *aValue, |
4231 BOOL *stop) { | 4205 BOOL *stop) { |
4232 block([aKey intValue], [aValue longLongValue], stop); | 4206 block([aKey intValue], [aValue longLongValue], stop); |
4233 }]; | 4207 }]; |
4234 } | 4208 } |
4235 | 4209 |
4236 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 4210 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
4237 NSUInteger count = _dictionary.count; | 4211 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4275 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | 4249 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); |
4276 }]; | 4250 }]; |
4277 } | 4251 } |
4278 | 4252 |
4279 - (void)setGPBGenericValue:(GPBGenericValue *)value | 4253 - (void)setGPBGenericValue:(GPBGenericValue *)value |
4280 forGPBGenericValueKey:(GPBGenericValue *)key { | 4254 forGPBGenericValueKey:(GPBGenericValue *)key { |
4281 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)]; | 4255 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)]; |
4282 } | 4256 } |
4283 | 4257 |
4284 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 4258 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
4285 [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, BOOL *sto
p) { | 4259 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, int64_t value, BOOL *sto
p) { |
4286 #pragma unused(stop) | 4260 #pragma unused(stop) |
4287 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%lld", value]); | 4261 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%lld", value]); |
4288 }]; | 4262 }]; |
4289 } | 4263 } |
4290 | 4264 |
4291 - (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key { | 4265 - (BOOL)valueForKey:(int32_t)key value:(int64_t *)value { |
4292 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 4266 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
4293 if (wrapped && value) { | 4267 if (wrapped && value) { |
4294 *value = [wrapped longLongValue]; | 4268 *value = [wrapped longLongValue]; |
4295 } | 4269 } |
4296 return (wrapped != NULL); | 4270 return (wrapped != NULL); |
4297 } | 4271 } |
4298 | 4272 |
4299 - (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary { | 4273 - (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary { |
4300 if (otherDictionary) { | 4274 if (otherDictionary) { |
4301 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 4275 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
4302 if (_autocreator) { | 4276 if (_autocreator) { |
4303 GPBAutocreatedDictionaryModified(_autocreator, self); | 4277 GPBAutocreatedDictionaryModified(_autocreator, self); |
4304 } | 4278 } |
4305 } | 4279 } |
4306 } | 4280 } |
4307 | 4281 |
4308 - (void)setInt64:(int64_t)value forKey:(int32_t)key { | 4282 - (void)setValue:(int64_t)value forKey:(int32_t)key { |
4309 [_dictionary setObject:@(value) forKey:@(key)]; | 4283 [_dictionary setObject:@(value) forKey:@(key)]; |
4310 if (_autocreator) { | 4284 if (_autocreator) { |
4311 GPBAutocreatedDictionaryModified(_autocreator, self); | 4285 GPBAutocreatedDictionaryModified(_autocreator, self); |
4312 } | 4286 } |
4313 } | 4287 } |
4314 | 4288 |
4315 - (void)removeInt64ForKey:(int32_t)aKey { | 4289 - (void)removeValueForKey:(int32_t)aKey { |
4316 [_dictionary removeObjectForKey:@(aKey)]; | 4290 [_dictionary removeObjectForKey:@(aKey)]; |
4317 } | 4291 } |
4318 | 4292 |
4319 - (void)removeAll { | 4293 - (void)removeAll { |
4320 [_dictionary removeAllObjects]; | 4294 [_dictionary removeAllObjects]; |
4321 } | 4295 } |
4322 | 4296 |
4323 @end | 4297 @end |
4324 | 4298 |
4325 #pragma mark - Int32 -> Bool | 4299 #pragma mark - Int32 -> Bool |
4326 | 4300 |
4327 @implementation GPBInt32BoolDictionary { | 4301 @implementation GPBInt32BoolDictionary { |
4328 @package | 4302 @package |
4329 NSMutableDictionary *_dictionary; | 4303 NSMutableDictionary *_dictionary; |
4330 } | 4304 } |
4331 | 4305 |
4332 + (instancetype)dictionary { | 4306 + (instancetype)dictionary { |
4333 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; | 4307 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
4334 } | 4308 } |
4335 | 4309 |
4336 + (instancetype)dictionaryWithBool:(BOOL)value | 4310 + (instancetype)dictionaryWithValue:(BOOL)value |
4337 forKey:(int32_t)key { | 4311 forKey:(int32_t)key { |
4338 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 4312 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
4339 // on to get the type correct. | 4313 // on to get the type correct. |
4340 return [[(GPBInt32BoolDictionary*)[self alloc] initWithBools:&value | 4314 return [[(GPBInt32BoolDictionary*)[self alloc] initWithValues:&value |
4341 forKeys:&key | 4315 forKeys:&key |
4342 count:1] autorelease]; | 4316 count:1] autorelease]; |
4343 } | 4317 } |
4344 | 4318 |
4345 + (instancetype)dictionaryWithBools:(const BOOL [])values | 4319 + (instancetype)dictionaryWithValues:(const BOOL [])values |
4346 forKeys:(const int32_t [])keys | 4320 forKeys:(const int32_t [])keys |
4347 count:(NSUInteger)count { | 4321 count:(NSUInteger)count { |
4348 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 4322 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
4349 // on to get the type correct. | 4323 // on to get the type correct. |
4350 return [[(GPBInt32BoolDictionary*)[self alloc] initWithBools:values | 4324 return [[(GPBInt32BoolDictionary*)[self alloc] initWithValues:values |
4351 forKeys:keys | 4325 forKeys:keys |
4352 count:count] autorelea
se]; | 4326 count:count] autorelea
se]; |
4353 } | 4327 } |
4354 | 4328 |
4355 + (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary { | 4329 + (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary { |
4356 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 4330 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
4357 // on to get the type correct. | 4331 // on to get the type correct. |
4358 return [[(GPBInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 4332 return [[(GPBInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
4359 } | 4333 } |
4360 | 4334 |
4361 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 4335 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
4362 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 4336 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
4363 } | 4337 } |
4364 | 4338 |
4365 - (instancetype)init { | 4339 - (instancetype)init { |
4366 return [self initWithBools:NULL forKeys:NULL count:0]; | 4340 return [self initWithValues:NULL forKeys:NULL count:0]; |
4367 } | 4341 } |
4368 | 4342 |
4369 - (instancetype)initWithBools:(const BOOL [])values | 4343 - (instancetype)initWithValues:(const BOOL [])values |
4370 forKeys:(const int32_t [])keys | 4344 forKeys:(const int32_t [])keys |
4371 count:(NSUInteger)count { | 4345 count:(NSUInteger)count { |
4372 self = [super init]; | 4346 self = [super init]; |
4373 if (self) { | 4347 if (self) { |
4374 _dictionary = [[NSMutableDictionary alloc] init]; | 4348 _dictionary = [[NSMutableDictionary alloc] init]; |
4375 if (count && values && keys) { | 4349 if (count && values && keys) { |
4376 for (NSUInteger i = 0; i < count; ++i) { | 4350 for (NSUInteger i = 0; i < count; ++i) { |
4377 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 4351 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
4378 } | 4352 } |
4379 } | 4353 } |
4380 } | 4354 } |
4381 return self; | 4355 return self; |
4382 } | 4356 } |
4383 | 4357 |
4384 - (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary { | 4358 - (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary { |
4385 self = [self initWithBools:NULL forKeys:NULL count:0]; | 4359 self = [self initWithValues:NULL forKeys:NULL count:0]; |
4386 if (self) { | 4360 if (self) { |
4387 if (dictionary) { | 4361 if (dictionary) { |
4388 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 4362 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
4389 } | 4363 } |
4390 } | 4364 } |
4391 return self; | 4365 return self; |
4392 } | 4366 } |
4393 | 4367 |
4394 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 4368 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
4395 #pragma unused(numItems) | 4369 #pragma unused(numItems) |
4396 return [self initWithBools:NULL forKeys:NULL count:0]; | 4370 return [self initWithValues:NULL forKeys:NULL count:0]; |
4397 } | 4371 } |
4398 | 4372 |
4399 - (void)dealloc { | 4373 - (void)dealloc { |
4400 NSAssert(!_autocreator, | 4374 NSAssert(!_autocreator, |
4401 @"%@: Autocreator must be cleared before release, autocreator: %@", | 4375 @"%@: Autocreator must be cleared before release, autocreator: %@", |
4402 [self class], _autocreator); | 4376 [self class], _autocreator); |
4403 [_dictionary release]; | 4377 [_dictionary release]; |
4404 [super dealloc]; | 4378 [super dealloc]; |
4405 } | 4379 } |
4406 | 4380 |
4407 - (instancetype)copyWithZone:(NSZone *)zone { | 4381 - (instancetype)copyWithZone:(NSZone *)zone { |
4408 return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; | 4382 return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; |
4409 } | 4383 } |
4410 | 4384 |
4411 - (BOOL)isEqual:(id)other { | 4385 - (BOOL)isEqual:(GPBInt32BoolDictionary *)other { |
4412 if (self == other) { | 4386 if (self == other) { |
4413 return YES; | 4387 return YES; |
4414 } | 4388 } |
4415 if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) { | 4389 if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) { |
4416 return NO; | 4390 return NO; |
4417 } | 4391 } |
4418 GPBInt32BoolDictionary *otherDictionary = other; | 4392 return [_dictionary isEqual:other->_dictionary]; |
4419 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
4420 } | 4393 } |
4421 | 4394 |
4422 - (NSUInteger)hash { | 4395 - (NSUInteger)hash { |
4423 return _dictionary.count; | 4396 return _dictionary.count; |
4424 } | 4397 } |
4425 | 4398 |
4426 - (NSString *)description { | 4399 - (NSString *)description { |
4427 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 4400 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
4428 } | 4401 } |
4429 | 4402 |
4430 - (NSUInteger)count { | 4403 - (NSUInteger)count { |
4431 return _dictionary.count; | 4404 return _dictionary.count; |
4432 } | 4405 } |
4433 | 4406 |
4434 - (void)enumerateKeysAndBoolsUsingBlock: | 4407 - (void)enumerateKeysAndValuesUsingBlock: |
4435 (void (^)(int32_t key, BOOL value, BOOL *stop))block { | 4408 (void (^)(int32_t key, BOOL value, BOOL *stop))block { |
4436 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 4409 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
4437 NSNumber *aValue, | 4410 NSNumber *aValue, |
4438 BOOL *stop) { | 4411 BOOL *stop) { |
4439 block([aKey intValue], [aValue boolValue], stop); | 4412 block([aKey intValue], [aValue boolValue], stop); |
4440 }]; | 4413 }]; |
4441 } | 4414 } |
4442 | 4415 |
4443 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 4416 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
4444 NSUInteger count = _dictionary.count; | 4417 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4482 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | 4455 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); |
4483 }]; | 4456 }]; |
4484 } | 4457 } |
4485 | 4458 |
4486 - (void)setGPBGenericValue:(GPBGenericValue *)value | 4459 - (void)setGPBGenericValue:(GPBGenericValue *)value |
4487 forGPBGenericValueKey:(GPBGenericValue *)key { | 4460 forGPBGenericValueKey:(GPBGenericValue *)key { |
4488 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)]; | 4461 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)]; |
4489 } | 4462 } |
4490 | 4463 |
4491 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 4464 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
4492 [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, BOOL *stop) { | 4465 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, BOOL value, BOOL *stop)
{ |
4493 #pragma unused(stop) | 4466 #pragma unused(stop) |
4494 block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false")
); | 4467 block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false")
); |
4495 }]; | 4468 }]; |
4496 } | 4469 } |
4497 | 4470 |
4498 - (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key { | 4471 - (BOOL)valueForKey:(int32_t)key value:(BOOL *)value { |
4499 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 4472 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
4500 if (wrapped && value) { | 4473 if (wrapped && value) { |
4501 *value = [wrapped boolValue]; | 4474 *value = [wrapped boolValue]; |
4502 } | 4475 } |
4503 return (wrapped != NULL); | 4476 return (wrapped != NULL); |
4504 } | 4477 } |
4505 | 4478 |
4506 - (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary { | 4479 - (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary { |
4507 if (otherDictionary) { | 4480 if (otherDictionary) { |
4508 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 4481 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
4509 if (_autocreator) { | 4482 if (_autocreator) { |
4510 GPBAutocreatedDictionaryModified(_autocreator, self); | 4483 GPBAutocreatedDictionaryModified(_autocreator, self); |
4511 } | 4484 } |
4512 } | 4485 } |
4513 } | 4486 } |
4514 | 4487 |
4515 - (void)setBool:(BOOL)value forKey:(int32_t)key { | 4488 - (void)setValue:(BOOL)value forKey:(int32_t)key { |
4516 [_dictionary setObject:@(value) forKey:@(key)]; | 4489 [_dictionary setObject:@(value) forKey:@(key)]; |
4517 if (_autocreator) { | 4490 if (_autocreator) { |
4518 GPBAutocreatedDictionaryModified(_autocreator, self); | 4491 GPBAutocreatedDictionaryModified(_autocreator, self); |
4519 } | 4492 } |
4520 } | 4493 } |
4521 | 4494 |
4522 - (void)removeBoolForKey:(int32_t)aKey { | 4495 - (void)removeValueForKey:(int32_t)aKey { |
4523 [_dictionary removeObjectForKey:@(aKey)]; | 4496 [_dictionary removeObjectForKey:@(aKey)]; |
4524 } | 4497 } |
4525 | 4498 |
4526 - (void)removeAll { | 4499 - (void)removeAll { |
4527 [_dictionary removeAllObjects]; | 4500 [_dictionary removeAllObjects]; |
4528 } | 4501 } |
4529 | 4502 |
4530 @end | 4503 @end |
4531 | 4504 |
4532 #pragma mark - Int32 -> Float | 4505 #pragma mark - Int32 -> Float |
4533 | 4506 |
4534 @implementation GPBInt32FloatDictionary { | 4507 @implementation GPBInt32FloatDictionary { |
4535 @package | 4508 @package |
4536 NSMutableDictionary *_dictionary; | 4509 NSMutableDictionary *_dictionary; |
4537 } | 4510 } |
4538 | 4511 |
4539 + (instancetype)dictionary { | 4512 + (instancetype)dictionary { |
4540 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; | 4513 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
4541 } | 4514 } |
4542 | 4515 |
4543 + (instancetype)dictionaryWithFloat:(float)value | 4516 + (instancetype)dictionaryWithValue:(float)value |
4544 forKey:(int32_t)key { | 4517 forKey:(int32_t)key { |
4545 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 4518 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
4546 // on to get the type correct. | 4519 // on to get the type correct. |
4547 return [[(GPBInt32FloatDictionary*)[self alloc] initWithFloats:&value | 4520 return [[(GPBInt32FloatDictionary*)[self alloc] initWithValues:&value |
4548 forKeys:&key | 4521 forKeys:&key |
4549 count:1] autorelease]
; | 4522 count:1] autorelease]
; |
4550 } | 4523 } |
4551 | 4524 |
4552 + (instancetype)dictionaryWithFloats:(const float [])values | 4525 + (instancetype)dictionaryWithValues:(const float [])values |
4553 forKeys:(const int32_t [])keys | 4526 forKeys:(const int32_t [])keys |
4554 count:(NSUInteger)count { | 4527 count:(NSUInteger)count { |
4555 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 4528 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
4556 // on to get the type correct. | 4529 // on to get the type correct. |
4557 return [[(GPBInt32FloatDictionary*)[self alloc] initWithFloats:values | 4530 return [[(GPBInt32FloatDictionary*)[self alloc] initWithValues:values |
4558 forKeys:keys | 4531 forKeys:keys |
4559 count:count] autorele
ase]; | 4532 count:count] autorele
ase]; |
4560 } | 4533 } |
4561 | 4534 |
4562 + (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary { | 4535 + (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary { |
4563 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 4536 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
4564 // on to get the type correct. | 4537 // on to get the type correct. |
4565 return [[(GPBInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 4538 return [[(GPBInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
4566 } | 4539 } |
4567 | 4540 |
4568 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 4541 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
4569 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 4542 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
4570 } | 4543 } |
4571 | 4544 |
4572 - (instancetype)init { | 4545 - (instancetype)init { |
4573 return [self initWithFloats:NULL forKeys:NULL count:0]; | 4546 return [self initWithValues:NULL forKeys:NULL count:0]; |
4574 } | 4547 } |
4575 | 4548 |
4576 - (instancetype)initWithFloats:(const float [])values | 4549 - (instancetype)initWithValues:(const float [])values |
4577 forKeys:(const int32_t [])keys | 4550 forKeys:(const int32_t [])keys |
4578 count:(NSUInteger)count { | 4551 count:(NSUInteger)count { |
4579 self = [super init]; | 4552 self = [super init]; |
4580 if (self) { | 4553 if (self) { |
4581 _dictionary = [[NSMutableDictionary alloc] init]; | 4554 _dictionary = [[NSMutableDictionary alloc] init]; |
4582 if (count && values && keys) { | 4555 if (count && values && keys) { |
4583 for (NSUInteger i = 0; i < count; ++i) { | 4556 for (NSUInteger i = 0; i < count; ++i) { |
4584 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 4557 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
4585 } | 4558 } |
4586 } | 4559 } |
4587 } | 4560 } |
4588 return self; | 4561 return self; |
4589 } | 4562 } |
4590 | 4563 |
4591 - (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary { | 4564 - (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary { |
4592 self = [self initWithFloats:NULL forKeys:NULL count:0]; | 4565 self = [self initWithValues:NULL forKeys:NULL count:0]; |
4593 if (self) { | 4566 if (self) { |
4594 if (dictionary) { | 4567 if (dictionary) { |
4595 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 4568 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
4596 } | 4569 } |
4597 } | 4570 } |
4598 return self; | 4571 return self; |
4599 } | 4572 } |
4600 | 4573 |
4601 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 4574 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
4602 #pragma unused(numItems) | 4575 #pragma unused(numItems) |
4603 return [self initWithFloats:NULL forKeys:NULL count:0]; | 4576 return [self initWithValues:NULL forKeys:NULL count:0]; |
4604 } | 4577 } |
4605 | 4578 |
4606 - (void)dealloc { | 4579 - (void)dealloc { |
4607 NSAssert(!_autocreator, | 4580 NSAssert(!_autocreator, |
4608 @"%@: Autocreator must be cleared before release, autocreator: %@", | 4581 @"%@: Autocreator must be cleared before release, autocreator: %@", |
4609 [self class], _autocreator); | 4582 [self class], _autocreator); |
4610 [_dictionary release]; | 4583 [_dictionary release]; |
4611 [super dealloc]; | 4584 [super dealloc]; |
4612 } | 4585 } |
4613 | 4586 |
4614 - (instancetype)copyWithZone:(NSZone *)zone { | 4587 - (instancetype)copyWithZone:(NSZone *)zone { |
4615 return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]; | 4588 return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]; |
4616 } | 4589 } |
4617 | 4590 |
4618 - (BOOL)isEqual:(id)other { | 4591 - (BOOL)isEqual:(GPBInt32FloatDictionary *)other { |
4619 if (self == other) { | 4592 if (self == other) { |
4620 return YES; | 4593 return YES; |
4621 } | 4594 } |
4622 if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) { | 4595 if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) { |
4623 return NO; | 4596 return NO; |
4624 } | 4597 } |
4625 GPBInt32FloatDictionary *otherDictionary = other; | 4598 return [_dictionary isEqual:other->_dictionary]; |
4626 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
4627 } | 4599 } |
4628 | 4600 |
4629 - (NSUInteger)hash { | 4601 - (NSUInteger)hash { |
4630 return _dictionary.count; | 4602 return _dictionary.count; |
4631 } | 4603 } |
4632 | 4604 |
4633 - (NSString *)description { | 4605 - (NSString *)description { |
4634 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 4606 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
4635 } | 4607 } |
4636 | 4608 |
4637 - (NSUInteger)count { | 4609 - (NSUInteger)count { |
4638 return _dictionary.count; | 4610 return _dictionary.count; |
4639 } | 4611 } |
4640 | 4612 |
4641 - (void)enumerateKeysAndFloatsUsingBlock: | 4613 - (void)enumerateKeysAndValuesUsingBlock: |
4642 (void (^)(int32_t key, float value, BOOL *stop))block { | 4614 (void (^)(int32_t key, float value, BOOL *stop))block { |
4643 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 4615 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
4644 NSNumber *aValue, | 4616 NSNumber *aValue, |
4645 BOOL *stop) { | 4617 BOOL *stop) { |
4646 block([aKey intValue], [aValue floatValue], stop); | 4618 block([aKey intValue], [aValue floatValue], stop); |
4647 }]; | 4619 }]; |
4648 } | 4620 } |
4649 | 4621 |
4650 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 4622 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
4651 NSUInteger count = _dictionary.count; | 4623 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4689 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | 4661 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); |
4690 }]; | 4662 }]; |
4691 } | 4663 } |
4692 | 4664 |
4693 - (void)setGPBGenericValue:(GPBGenericValue *)value | 4665 - (void)setGPBGenericValue:(GPBGenericValue *)value |
4694 forGPBGenericValueKey:(GPBGenericValue *)key { | 4666 forGPBGenericValueKey:(GPBGenericValue *)key { |
4695 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)]; | 4667 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)]; |
4696 } | 4668 } |
4697 | 4669 |
4698 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 4670 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
4699 [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, BOOL *stop)
{ | 4671 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, float value, BOOL *stop)
{ |
4700 #pragma unused(stop) | 4672 #pragma unused(stop) |
4701 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%.*g", FLT_DIG, value]); | 4673 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%.*g", FLT_DIG, value]); |
4702 }]; | 4674 }]; |
4703 } | 4675 } |
4704 | 4676 |
4705 - (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key { | 4677 - (BOOL)valueForKey:(int32_t)key value:(float *)value { |
4706 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 4678 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
4707 if (wrapped && value) { | 4679 if (wrapped && value) { |
4708 *value = [wrapped floatValue]; | 4680 *value = [wrapped floatValue]; |
4709 } | 4681 } |
4710 return (wrapped != NULL); | 4682 return (wrapped != NULL); |
4711 } | 4683 } |
4712 | 4684 |
4713 - (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary { | 4685 - (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary { |
4714 if (otherDictionary) { | 4686 if (otherDictionary) { |
4715 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 4687 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
4716 if (_autocreator) { | 4688 if (_autocreator) { |
4717 GPBAutocreatedDictionaryModified(_autocreator, self); | 4689 GPBAutocreatedDictionaryModified(_autocreator, self); |
4718 } | 4690 } |
4719 } | 4691 } |
4720 } | 4692 } |
4721 | 4693 |
4722 - (void)setFloat:(float)value forKey:(int32_t)key { | 4694 - (void)setValue:(float)value forKey:(int32_t)key { |
4723 [_dictionary setObject:@(value) forKey:@(key)]; | 4695 [_dictionary setObject:@(value) forKey:@(key)]; |
4724 if (_autocreator) { | 4696 if (_autocreator) { |
4725 GPBAutocreatedDictionaryModified(_autocreator, self); | 4697 GPBAutocreatedDictionaryModified(_autocreator, self); |
4726 } | 4698 } |
4727 } | 4699 } |
4728 | 4700 |
4729 - (void)removeFloatForKey:(int32_t)aKey { | 4701 - (void)removeValueForKey:(int32_t)aKey { |
4730 [_dictionary removeObjectForKey:@(aKey)]; | 4702 [_dictionary removeObjectForKey:@(aKey)]; |
4731 } | 4703 } |
4732 | 4704 |
4733 - (void)removeAll { | 4705 - (void)removeAll { |
4734 [_dictionary removeAllObjects]; | 4706 [_dictionary removeAllObjects]; |
4735 } | 4707 } |
4736 | 4708 |
4737 @end | 4709 @end |
4738 | 4710 |
4739 #pragma mark - Int32 -> Double | 4711 #pragma mark - Int32 -> Double |
4740 | 4712 |
4741 @implementation GPBInt32DoubleDictionary { | 4713 @implementation GPBInt32DoubleDictionary { |
4742 @package | 4714 @package |
4743 NSMutableDictionary *_dictionary; | 4715 NSMutableDictionary *_dictionary; |
4744 } | 4716 } |
4745 | 4717 |
4746 + (instancetype)dictionary { | 4718 + (instancetype)dictionary { |
4747 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; | 4719 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
4748 } | 4720 } |
4749 | 4721 |
4750 + (instancetype)dictionaryWithDouble:(double)value | 4722 + (instancetype)dictionaryWithValue:(double)value |
4751 forKey:(int32_t)key { | 4723 forKey:(int32_t)key { |
4752 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 4724 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
4753 // on to get the type correct. | 4725 // on to get the type correct. |
4754 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDoubles:&value | 4726 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithValues:&value |
4755 forKeys:&key | 4727 forKeys:&key |
4756 count:1] autoreleas
e]; | 4728 count:1] autorelease
]; |
4757 } | 4729 } |
4758 | 4730 |
4759 + (instancetype)dictionaryWithDoubles:(const double [])values | 4731 + (instancetype)dictionaryWithValues:(const double [])values |
4760 forKeys:(const int32_t [])keys | 4732 forKeys:(const int32_t [])keys |
4761 count:(NSUInteger)count { | 4733 count:(NSUInteger)count { |
4762 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 4734 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
4763 // on to get the type correct. | 4735 // on to get the type correct. |
4764 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDoubles:values | 4736 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithValues:values |
4765 forKeys:keys | 4737 forKeys:keys |
4766 count:count] autorel
ease]; | 4738 count:count] autorel
ease]; |
4767 } | 4739 } |
4768 | 4740 |
4769 + (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary
{ | 4741 + (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary
{ |
4770 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 4742 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
4771 // on to get the type correct. | 4743 // on to get the type correct. |
4772 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 4744 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
4773 } | 4745 } |
4774 | 4746 |
4775 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 4747 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
4776 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 4748 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
4777 } | 4749 } |
4778 | 4750 |
4779 - (instancetype)init { | 4751 - (instancetype)init { |
4780 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 4752 return [self initWithValues:NULL forKeys:NULL count:0]; |
4781 } | 4753 } |
4782 | 4754 |
4783 - (instancetype)initWithDoubles:(const double [])values | 4755 - (instancetype)initWithValues:(const double [])values |
4784 forKeys:(const int32_t [])keys | 4756 forKeys:(const int32_t [])keys |
4785 count:(NSUInteger)count { | 4757 count:(NSUInteger)count { |
4786 self = [super init]; | 4758 self = [super init]; |
4787 if (self) { | 4759 if (self) { |
4788 _dictionary = [[NSMutableDictionary alloc] init]; | 4760 _dictionary = [[NSMutableDictionary alloc] init]; |
4789 if (count && values && keys) { | 4761 if (count && values && keys) { |
4790 for (NSUInteger i = 0; i < count; ++i) { | 4762 for (NSUInteger i = 0; i < count; ++i) { |
4791 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 4763 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
4792 } | 4764 } |
4793 } | 4765 } |
4794 } | 4766 } |
4795 return self; | 4767 return self; |
4796 } | 4768 } |
4797 | 4769 |
4798 - (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary { | 4770 - (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary { |
4799 self = [self initWithDoubles:NULL forKeys:NULL count:0]; | 4771 self = [self initWithValues:NULL forKeys:NULL count:0]; |
4800 if (self) { | 4772 if (self) { |
4801 if (dictionary) { | 4773 if (dictionary) { |
4802 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 4774 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
4803 } | 4775 } |
4804 } | 4776 } |
4805 return self; | 4777 return self; |
4806 } | 4778 } |
4807 | 4779 |
4808 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 4780 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
4809 #pragma unused(numItems) | 4781 #pragma unused(numItems) |
4810 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 4782 return [self initWithValues:NULL forKeys:NULL count:0]; |
4811 } | 4783 } |
4812 | 4784 |
4813 - (void)dealloc { | 4785 - (void)dealloc { |
4814 NSAssert(!_autocreator, | 4786 NSAssert(!_autocreator, |
4815 @"%@: Autocreator must be cleared before release, autocreator: %@", | 4787 @"%@: Autocreator must be cleared before release, autocreator: %@", |
4816 [self class], _autocreator); | 4788 [self class], _autocreator); |
4817 [_dictionary release]; | 4789 [_dictionary release]; |
4818 [super dealloc]; | 4790 [super dealloc]; |
4819 } | 4791 } |
4820 | 4792 |
4821 - (instancetype)copyWithZone:(NSZone *)zone { | 4793 - (instancetype)copyWithZone:(NSZone *)zone { |
4822 return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self]
; | 4794 return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self]
; |
4823 } | 4795 } |
4824 | 4796 |
4825 - (BOOL)isEqual:(id)other { | 4797 - (BOOL)isEqual:(GPBInt32DoubleDictionary *)other { |
4826 if (self == other) { | 4798 if (self == other) { |
4827 return YES; | 4799 return YES; |
4828 } | 4800 } |
4829 if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) { | 4801 if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) { |
4830 return NO; | 4802 return NO; |
4831 } | 4803 } |
4832 GPBInt32DoubleDictionary *otherDictionary = other; | 4804 return [_dictionary isEqual:other->_dictionary]; |
4833 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
4834 } | 4805 } |
4835 | 4806 |
4836 - (NSUInteger)hash { | 4807 - (NSUInteger)hash { |
4837 return _dictionary.count; | 4808 return _dictionary.count; |
4838 } | 4809 } |
4839 | 4810 |
4840 - (NSString *)description { | 4811 - (NSString *)description { |
4841 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 4812 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
4842 } | 4813 } |
4843 | 4814 |
4844 - (NSUInteger)count { | 4815 - (NSUInteger)count { |
4845 return _dictionary.count; | 4816 return _dictionary.count; |
4846 } | 4817 } |
4847 | 4818 |
4848 - (void)enumerateKeysAndDoublesUsingBlock: | 4819 - (void)enumerateKeysAndValuesUsingBlock: |
4849 (void (^)(int32_t key, double value, BOOL *stop))block { | 4820 (void (^)(int32_t key, double value, BOOL *stop))block { |
4850 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 4821 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
4851 NSNumber *aValue, | 4822 NSNumber *aValue, |
4852 BOOL *stop) { | 4823 BOOL *stop) { |
4853 block([aKey intValue], [aValue doubleValue], stop); | 4824 block([aKey intValue], [aValue doubleValue], stop); |
4854 }]; | 4825 }]; |
4855 } | 4826 } |
4856 | 4827 |
4857 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 4828 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
4858 NSUInteger count = _dictionary.count; | 4829 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4896 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | 4867 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); |
4897 }]; | 4868 }]; |
4898 } | 4869 } |
4899 | 4870 |
4900 - (void)setGPBGenericValue:(GPBGenericValue *)value | 4871 - (void)setGPBGenericValue:(GPBGenericValue *)value |
4901 forGPBGenericValueKey:(GPBGenericValue *)key { | 4872 forGPBGenericValueKey:(GPBGenericValue *)key { |
4902 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)]; | 4873 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)]; |
4903 } | 4874 } |
4904 | 4875 |
4905 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 4876 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
4906 [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, BOOL *sto
p) { | 4877 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, double value, BOOL *stop
) { |
4907 #pragma unused(stop) | 4878 #pragma unused(stop) |
4908 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%.*lg", DBL_DIG, value]); | 4879 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%.*lg", DBL_DIG, value]); |
4909 }]; | 4880 }]; |
4910 } | 4881 } |
4911 | 4882 |
4912 - (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key { | 4883 - (BOOL)valueForKey:(int32_t)key value:(double *)value { |
4913 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 4884 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
4914 if (wrapped && value) { | 4885 if (wrapped && value) { |
4915 *value = [wrapped doubleValue]; | 4886 *value = [wrapped doubleValue]; |
4916 } | 4887 } |
4917 return (wrapped != NULL); | 4888 return (wrapped != NULL); |
4918 } | 4889 } |
4919 | 4890 |
4920 - (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary { | 4891 - (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary { |
4921 if (otherDictionary) { | 4892 if (otherDictionary) { |
4922 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 4893 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
4923 if (_autocreator) { | 4894 if (_autocreator) { |
4924 GPBAutocreatedDictionaryModified(_autocreator, self); | 4895 GPBAutocreatedDictionaryModified(_autocreator, self); |
4925 } | 4896 } |
4926 } | 4897 } |
4927 } | 4898 } |
4928 | 4899 |
4929 - (void)setDouble:(double)value forKey:(int32_t)key { | 4900 - (void)setValue:(double)value forKey:(int32_t)key { |
4930 [_dictionary setObject:@(value) forKey:@(key)]; | 4901 [_dictionary setObject:@(value) forKey:@(key)]; |
4931 if (_autocreator) { | 4902 if (_autocreator) { |
4932 GPBAutocreatedDictionaryModified(_autocreator, self); | 4903 GPBAutocreatedDictionaryModified(_autocreator, self); |
4933 } | 4904 } |
4934 } | 4905 } |
4935 | 4906 |
4936 - (void)removeDoubleForKey:(int32_t)aKey { | 4907 - (void)removeValueForKey:(int32_t)aKey { |
4937 [_dictionary removeObjectForKey:@(aKey)]; | 4908 [_dictionary removeObjectForKey:@(aKey)]; |
4938 } | 4909 } |
4939 | 4910 |
4940 - (void)removeAll { | 4911 - (void)removeAll { |
4941 [_dictionary removeAllObjects]; | 4912 [_dictionary removeAllObjects]; |
4942 } | 4913 } |
4943 | 4914 |
4944 @end | 4915 @end |
4945 | 4916 |
4946 #pragma mark - Int32 -> Enum | 4917 #pragma mark - Int32 -> Enum |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5050 @"%@: Autocreator must be cleared before release, autocreator: %@", | 5021 @"%@: Autocreator must be cleared before release, autocreator: %@", |
5051 [self class], _autocreator); | 5022 [self class], _autocreator); |
5052 [_dictionary release]; | 5023 [_dictionary release]; |
5053 [super dealloc]; | 5024 [super dealloc]; |
5054 } | 5025 } |
5055 | 5026 |
5056 - (instancetype)copyWithZone:(NSZone *)zone { | 5027 - (instancetype)copyWithZone:(NSZone *)zone { |
5057 return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; | 5028 return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; |
5058 } | 5029 } |
5059 | 5030 |
5060 - (BOOL)isEqual:(id)other { | 5031 - (BOOL)isEqual:(GPBInt32EnumDictionary *)other { |
5061 if (self == other) { | 5032 if (self == other) { |
5062 return YES; | 5033 return YES; |
5063 } | 5034 } |
5064 if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) { | 5035 if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) { |
5065 return NO; | 5036 return NO; |
5066 } | 5037 } |
5067 GPBInt32EnumDictionary *otherDictionary = other; | 5038 return [_dictionary isEqual:other->_dictionary]; |
5068 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
5069 } | 5039 } |
5070 | 5040 |
5071 - (NSUInteger)hash { | 5041 - (NSUInteger)hash { |
5072 return _dictionary.count; | 5042 return _dictionary.count; |
5073 } | 5043 } |
5074 | 5044 |
5075 - (NSString *)description { | 5045 - (NSString *)description { |
5076 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 5046 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
5077 } | 5047 } |
5078 | 5048 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5149 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)]; | 5119 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)]; |
5150 } | 5120 } |
5151 | 5121 |
5152 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 5122 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
5153 [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *
stop) { | 5123 [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *
stop) { |
5154 #pragma unused(stop) | 5124 #pragma unused(stop) |
5155 block([NSString stringWithFormat:@"%d", key], @(value)); | 5125 block([NSString stringWithFormat:@"%d", key], @(value)); |
5156 }]; | 5126 }]; |
5157 } | 5127 } |
5158 | 5128 |
5159 - (BOOL)getEnum:(int32_t *)value forKey:(int32_t)key { | 5129 - (BOOL)valueForKey:(int32_t)key value:(int32_t *)value { |
5160 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 5130 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
5161 if (wrapped && value) { | 5131 if (wrapped && value) { |
5162 int32_t result = [wrapped intValue]; | 5132 int32_t result = [wrapped intValue]; |
5163 if (!_validationFunc(result)) { | 5133 if (!_validationFunc(result)) { |
5164 result = kGPBUnrecognizedEnumeratorValue; | 5134 result = kGPBUnrecognizedEnumeratorValue; |
5165 } | 5135 } |
5166 *value = result; | 5136 *value = result; |
5167 } | 5137 } |
5168 return (wrapped != NULL); | 5138 return (wrapped != NULL); |
5169 } | 5139 } |
5170 | 5140 |
5171 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int32_t)key { | 5141 - (BOOL)valueForKey:(int32_t)key rawValue:(int32_t *)rawValue { |
5172 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 5142 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
5173 if (wrapped && rawValue) { | 5143 if (wrapped && rawValue) { |
5174 *rawValue = [wrapped intValue]; | 5144 *rawValue = [wrapped intValue]; |
5175 } | 5145 } |
5176 return (wrapped != NULL); | 5146 return (wrapped != NULL); |
5177 } | 5147 } |
5178 | 5148 |
5179 - (void)enumerateKeysAndEnumsUsingBlock: | 5149 - (void)enumerateKeysAndValuesUsingBlock: |
5180 (void (^)(int32_t key, int32_t value, BOOL *stop))block { | 5150 (void (^)(int32_t key, int32_t value, BOOL *stop))block { |
5181 GPBEnumValidationFunc func = _validationFunc; | 5151 GPBEnumValidationFunc func = _validationFunc; |
5182 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 5152 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
5183 NSNumber *aValue, | 5153 NSNumber *aValue, |
5184 BOOL *stop) { | 5154 BOOL *stop) { |
5185 int32_t unwrapped = [aValue intValue]; | 5155 int32_t unwrapped = [aValue intValue]; |
5186 if (!func(unwrapped)) { | 5156 if (!func(unwrapped)) { |
5187 unwrapped = kGPBUnrecognizedEnumeratorValue; | 5157 unwrapped = kGPBUnrecognizedEnumeratorValue; |
5188 } | 5158 } |
5189 block([aKey intValue], unwrapped, stop); | 5159 block([aKey intValue], unwrapped, stop); |
5190 }]; | 5160 }]; |
5191 } | 5161 } |
5192 | 5162 |
5193 - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary { | 5163 - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary { |
5194 if (otherDictionary) { | 5164 if (otherDictionary) { |
5195 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 5165 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
5196 if (_autocreator) { | 5166 if (_autocreator) { |
5197 GPBAutocreatedDictionaryModified(_autocreator, self); | 5167 GPBAutocreatedDictionaryModified(_autocreator, self); |
5198 } | 5168 } |
5199 } | 5169 } |
5200 } | 5170 } |
5201 | 5171 |
5202 - (void)setRawValue:(int32_t)value forKey:(int32_t)key { | 5172 - (void)setRawValue:(int32_t)value forKey:(int32_t)key { |
5203 [_dictionary setObject:@(value) forKey:@(key)]; | 5173 [_dictionary setObject:@(value) forKey:@(key)]; |
5204 if (_autocreator) { | 5174 if (_autocreator) { |
5205 GPBAutocreatedDictionaryModified(_autocreator, self); | 5175 GPBAutocreatedDictionaryModified(_autocreator, self); |
5206 } | 5176 } |
5207 } | 5177 } |
5208 | 5178 |
5209 - (void)removeEnumForKey:(int32_t)aKey { | 5179 - (void)removeValueForKey:(int32_t)aKey { |
5210 [_dictionary removeObjectForKey:@(aKey)]; | 5180 [_dictionary removeObjectForKey:@(aKey)]; |
5211 } | 5181 } |
5212 | 5182 |
5213 - (void)removeAll { | 5183 - (void)removeAll { |
5214 [_dictionary removeAllObjects]; | 5184 [_dictionary removeAllObjects]; |
5215 } | 5185 } |
5216 | 5186 |
5217 - (void)setEnum:(int32_t)value forKey:(int32_t)key { | 5187 - (void)setValue:(int32_t)value forKey:(int32_t)key { |
5218 if (!_validationFunc(value)) { | 5188 if (!_validationFunc(value)) { |
5219 [NSException raise:NSInvalidArgumentException | 5189 [NSException raise:NSInvalidArgumentException |
5220 format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum
value (%d)", | 5190 format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum
value (%d)", |
5221 value]; | 5191 value]; |
5222 } | 5192 } |
5223 | 5193 |
5224 [_dictionary setObject:@(value) forKey:@(key)]; | 5194 [_dictionary setObject:@(value) forKey:@(key)]; |
5225 if (_autocreator) { | 5195 if (_autocreator) { |
5226 GPBAutocreatedDictionaryModified(_autocreator, self); | 5196 GPBAutocreatedDictionaryModified(_autocreator, self); |
5227 } | 5197 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5312 @"%@: Autocreator must be cleared before release, autocreator: %@", | 5282 @"%@: Autocreator must be cleared before release, autocreator: %@", |
5313 [self class], _autocreator); | 5283 [self class], _autocreator); |
5314 [_dictionary release]; | 5284 [_dictionary release]; |
5315 [super dealloc]; | 5285 [super dealloc]; |
5316 } | 5286 } |
5317 | 5287 |
5318 - (instancetype)copyWithZone:(NSZone *)zone { | 5288 - (instancetype)copyWithZone:(NSZone *)zone { |
5319 return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self]
; | 5289 return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self]
; |
5320 } | 5290 } |
5321 | 5291 |
5322 - (BOOL)isEqual:(id)other { | 5292 - (BOOL)isEqual:(GPBInt32ObjectDictionary *)other { |
5323 if (self == other) { | 5293 if (self == other) { |
5324 return YES; | 5294 return YES; |
5325 } | 5295 } |
5326 if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) { | 5296 if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) { |
5327 return NO; | 5297 return NO; |
5328 } | 5298 } |
5329 GPBInt32ObjectDictionary *otherDictionary = other; | 5299 return [_dictionary isEqual:other->_dictionary]; |
5330 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
5331 } | 5300 } |
5332 | 5301 |
5333 - (NSUInteger)hash { | 5302 - (NSUInteger)hash { |
5334 return _dictionary.count; | 5303 return _dictionary.count; |
5335 } | 5304 } |
5336 | 5305 |
5337 - (NSString *)description { | 5306 - (NSString *)description { |
5338 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 5307 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
5339 } | 5308 } |
5340 | 5309 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5468 // This block of code is generated, do not edit it directly. | 5437 // This block of code is generated, do not edit it directly. |
5469 | 5438 |
5470 #pragma mark - UInt64 -> UInt32 | 5439 #pragma mark - UInt64 -> UInt32 |
5471 | 5440 |
5472 @implementation GPBUInt64UInt32Dictionary { | 5441 @implementation GPBUInt64UInt32Dictionary { |
5473 @package | 5442 @package |
5474 NSMutableDictionary *_dictionary; | 5443 NSMutableDictionary *_dictionary; |
5475 } | 5444 } |
5476 | 5445 |
5477 + (instancetype)dictionary { | 5446 + (instancetype)dictionary { |
5478 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; | 5447 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
5479 } | 5448 } |
5480 | 5449 |
5481 + (instancetype)dictionaryWithUInt32:(uint32_t)value | 5450 + (instancetype)dictionaryWithValue:(uint32_t)value |
5482 forKey:(uint64_t)key { | 5451 forKey:(uint64_t)key { |
5483 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 5452 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
5484 // on to get the type correct. | 5453 // on to get the type correct. |
5485 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithUInt32s:&value | 5454 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithValues:&value |
5486 forKeys:&key | 5455 forKeys:&key |
5487 count:1] autorelea
se]; | 5456 count:1] autoreleas
e]; |
5488 } | 5457 } |
5489 | 5458 |
5490 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values | 5459 + (instancetype)dictionaryWithValues:(const uint32_t [])values |
5491 forKeys:(const uint64_t [])keys | 5460 forKeys:(const uint64_t [])keys |
5492 count:(NSUInteger)count { | 5461 count:(NSUInteger)count { |
5493 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 5462 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
5494 // on to get the type correct. | 5463 // on to get the type correct. |
5495 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithUInt32s:values | 5464 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithValues:values |
5496 forKeys:keys | 5465 forKeys:keys |
5497 count:count] autore
lease]; | 5466 count:count] autore
lease]; |
5498 } | 5467 } |
5499 | 5468 |
5500 + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary
{ | 5469 + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary
{ |
5501 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 5470 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
5502 // on to get the type correct. | 5471 // on to get the type correct. |
5503 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 5472 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
5504 } | 5473 } |
5505 | 5474 |
5506 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 5475 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
5507 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 5476 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
5508 } | 5477 } |
5509 | 5478 |
5510 - (instancetype)init { | 5479 - (instancetype)init { |
5511 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 5480 return [self initWithValues:NULL forKeys:NULL count:0]; |
5512 } | 5481 } |
5513 | 5482 |
5514 - (instancetype)initWithUInt32s:(const uint32_t [])values | 5483 - (instancetype)initWithValues:(const uint32_t [])values |
5515 forKeys:(const uint64_t [])keys | 5484 forKeys:(const uint64_t [])keys |
5516 count:(NSUInteger)count { | 5485 count:(NSUInteger)count { |
5517 self = [super init]; | 5486 self = [super init]; |
5518 if (self) { | 5487 if (self) { |
5519 _dictionary = [[NSMutableDictionary alloc] init]; | 5488 _dictionary = [[NSMutableDictionary alloc] init]; |
5520 if (count && values && keys) { | 5489 if (count && values && keys) { |
5521 for (NSUInteger i = 0; i < count; ++i) { | 5490 for (NSUInteger i = 0; i < count; ++i) { |
5522 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 5491 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
5523 } | 5492 } |
5524 } | 5493 } |
5525 } | 5494 } |
5526 return self; | 5495 return self; |
5527 } | 5496 } |
5528 | 5497 |
5529 - (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary { | 5498 - (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary { |
5530 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; | 5499 self = [self initWithValues:NULL forKeys:NULL count:0]; |
5531 if (self) { | 5500 if (self) { |
5532 if (dictionary) { | 5501 if (dictionary) { |
5533 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 5502 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
5534 } | 5503 } |
5535 } | 5504 } |
5536 return self; | 5505 return self; |
5537 } | 5506 } |
5538 | 5507 |
5539 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 5508 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
5540 #pragma unused(numItems) | 5509 #pragma unused(numItems) |
5541 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 5510 return [self initWithValues:NULL forKeys:NULL count:0]; |
5542 } | 5511 } |
5543 | 5512 |
5544 - (void)dealloc { | 5513 - (void)dealloc { |
5545 NSAssert(!_autocreator, | 5514 NSAssert(!_autocreator, |
5546 @"%@: Autocreator must be cleared before release, autocreator: %@", | 5515 @"%@: Autocreator must be cleared before release, autocreator: %@", |
5547 [self class], _autocreator); | 5516 [self class], _autocreator); |
5548 [_dictionary release]; | 5517 [_dictionary release]; |
5549 [super dealloc]; | 5518 [super dealloc]; |
5550 } | 5519 } |
5551 | 5520 |
5552 - (instancetype)copyWithZone:(NSZone *)zone { | 5521 - (instancetype)copyWithZone:(NSZone *)zone { |
5553 return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; | 5522 return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; |
5554 } | 5523 } |
5555 | 5524 |
5556 - (BOOL)isEqual:(id)other { | 5525 - (BOOL)isEqual:(GPBUInt64UInt32Dictionary *)other { |
5557 if (self == other) { | 5526 if (self == other) { |
5558 return YES; | 5527 return YES; |
5559 } | 5528 } |
5560 if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) { | 5529 if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) { |
5561 return NO; | 5530 return NO; |
5562 } | 5531 } |
5563 GPBUInt64UInt32Dictionary *otherDictionary = other; | 5532 return [_dictionary isEqual:other->_dictionary]; |
5564 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
5565 } | 5533 } |
5566 | 5534 |
5567 - (NSUInteger)hash { | 5535 - (NSUInteger)hash { |
5568 return _dictionary.count; | 5536 return _dictionary.count; |
5569 } | 5537 } |
5570 | 5538 |
5571 - (NSString *)description { | 5539 - (NSString *)description { |
5572 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 5540 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
5573 } | 5541 } |
5574 | 5542 |
5575 - (NSUInteger)count { | 5543 - (NSUInteger)count { |
5576 return _dictionary.count; | 5544 return _dictionary.count; |
5577 } | 5545 } |
5578 | 5546 |
5579 - (void)enumerateKeysAndUInt32sUsingBlock: | 5547 - (void)enumerateKeysAndValuesUsingBlock: |
5580 (void (^)(uint64_t key, uint32_t value, BOOL *stop))block { | 5548 (void (^)(uint64_t key, uint32_t value, BOOL *stop))block { |
5581 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 5549 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
5582 NSNumber *aValue, | 5550 NSNumber *aValue, |
5583 BOOL *stop) { | 5551 BOOL *stop) { |
5584 block([aKey unsignedLongLongValue], [aValue unsignedIntValue], stop); | 5552 block([aKey unsignedLongLongValue], [aValue unsignedIntValue], stop); |
5585 }]; | 5553 }]; |
5586 } | 5554 } |
5587 | 5555 |
5588 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 5556 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
5589 NSUInteger count = _dictionary.count; | 5557 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5627 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | 5595 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); |
5628 }]; | 5596 }]; |
5629 } | 5597 } |
5630 | 5598 |
5631 - (void)setGPBGenericValue:(GPBGenericValue *)value | 5599 - (void)setGPBGenericValue:(GPBGenericValue *)value |
5632 forGPBGenericValueKey:(GPBGenericValue *)key { | 5600 forGPBGenericValueKey:(GPBGenericValue *)key { |
5633 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)]; | 5601 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)]; |
5634 } | 5602 } |
5635 | 5603 |
5636 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 5604 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
5637 [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, BOOL *
stop) { | 5605 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, uint32_t value, BOOL *s
top) { |
5638 #pragma unused(stop) | 5606 #pragma unused(stop) |
5639 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%u", value]); | 5607 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%u", value]); |
5640 }]; | 5608 }]; |
5641 } | 5609 } |
5642 | 5610 |
5643 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key { | 5611 - (BOOL)valueForKey:(uint64_t)key value:(uint32_t *)value { |
5644 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 5612 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
5645 if (wrapped && value) { | 5613 if (wrapped && value) { |
5646 *value = [wrapped unsignedIntValue]; | 5614 *value = [wrapped unsignedIntValue]; |
5647 } | 5615 } |
5648 return (wrapped != NULL); | 5616 return (wrapped != NULL); |
5649 } | 5617 } |
5650 | 5618 |
5651 - (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary { | 5619 - (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary { |
5652 if (otherDictionary) { | 5620 if (otherDictionary) { |
5653 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 5621 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
5654 if (_autocreator) { | 5622 if (_autocreator) { |
5655 GPBAutocreatedDictionaryModified(_autocreator, self); | 5623 GPBAutocreatedDictionaryModified(_autocreator, self); |
5656 } | 5624 } |
5657 } | 5625 } |
5658 } | 5626 } |
5659 | 5627 |
5660 - (void)setUInt32:(uint32_t)value forKey:(uint64_t)key { | 5628 - (void)setValue:(uint32_t)value forKey:(uint64_t)key { |
5661 [_dictionary setObject:@(value) forKey:@(key)]; | 5629 [_dictionary setObject:@(value) forKey:@(key)]; |
5662 if (_autocreator) { | 5630 if (_autocreator) { |
5663 GPBAutocreatedDictionaryModified(_autocreator, self); | 5631 GPBAutocreatedDictionaryModified(_autocreator, self); |
5664 } | 5632 } |
5665 } | 5633 } |
5666 | 5634 |
5667 - (void)removeUInt32ForKey:(uint64_t)aKey { | 5635 - (void)removeValueForKey:(uint64_t)aKey { |
5668 [_dictionary removeObjectForKey:@(aKey)]; | 5636 [_dictionary removeObjectForKey:@(aKey)]; |
5669 } | 5637 } |
5670 | 5638 |
5671 - (void)removeAll { | 5639 - (void)removeAll { |
5672 [_dictionary removeAllObjects]; | 5640 [_dictionary removeAllObjects]; |
5673 } | 5641 } |
5674 | 5642 |
5675 @end | 5643 @end |
5676 | 5644 |
5677 #pragma mark - UInt64 -> Int32 | 5645 #pragma mark - UInt64 -> Int32 |
5678 | 5646 |
5679 @implementation GPBUInt64Int32Dictionary { | 5647 @implementation GPBUInt64Int32Dictionary { |
5680 @package | 5648 @package |
5681 NSMutableDictionary *_dictionary; | 5649 NSMutableDictionary *_dictionary; |
5682 } | 5650 } |
5683 | 5651 |
5684 + (instancetype)dictionary { | 5652 + (instancetype)dictionary { |
5685 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; | 5653 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
5686 } | 5654 } |
5687 | 5655 |
5688 + (instancetype)dictionaryWithInt32:(int32_t)value | 5656 + (instancetype)dictionaryWithValue:(int32_t)value |
5689 forKey:(uint64_t)key { | 5657 forKey:(uint64_t)key { |
5690 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 5658 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
5691 // on to get the type correct. | 5659 // on to get the type correct. |
5692 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithInt32s:&value | 5660 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithValues:&value |
5693 forKeys:&key | 5661 forKeys:&key |
5694 count:1] autorelease
]; | 5662 count:1] autorelease
]; |
5695 } | 5663 } |
5696 | 5664 |
5697 + (instancetype)dictionaryWithInt32s:(const int32_t [])values | 5665 + (instancetype)dictionaryWithValues:(const int32_t [])values |
5698 forKeys:(const uint64_t [])keys | 5666 forKeys:(const uint64_t [])keys |
5699 count:(NSUInteger)count { | 5667 count:(NSUInteger)count { |
5700 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 5668 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
5701 // on to get the type correct. | 5669 // on to get the type correct. |
5702 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithInt32s:values | 5670 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithValues:values |
5703 forKeys:keys | 5671 forKeys:keys |
5704 count:count] autorel
ease]; | 5672 count:count] autorel
ease]; |
5705 } | 5673 } |
5706 | 5674 |
5707 + (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary
{ | 5675 + (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary
{ |
5708 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 5676 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
5709 // on to get the type correct. | 5677 // on to get the type correct. |
5710 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 5678 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
5711 } | 5679 } |
5712 | 5680 |
5713 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 5681 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
5714 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 5682 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
5715 } | 5683 } |
5716 | 5684 |
5717 - (instancetype)init { | 5685 - (instancetype)init { |
5718 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 5686 return [self initWithValues:NULL forKeys:NULL count:0]; |
5719 } | 5687 } |
5720 | 5688 |
5721 - (instancetype)initWithInt32s:(const int32_t [])values | 5689 - (instancetype)initWithValues:(const int32_t [])values |
5722 forKeys:(const uint64_t [])keys | 5690 forKeys:(const uint64_t [])keys |
5723 count:(NSUInteger)count { | 5691 count:(NSUInteger)count { |
5724 self = [super init]; | 5692 self = [super init]; |
5725 if (self) { | 5693 if (self) { |
5726 _dictionary = [[NSMutableDictionary alloc] init]; | 5694 _dictionary = [[NSMutableDictionary alloc] init]; |
5727 if (count && values && keys) { | 5695 if (count && values && keys) { |
5728 for (NSUInteger i = 0; i < count; ++i) { | 5696 for (NSUInteger i = 0; i < count; ++i) { |
5729 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 5697 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
5730 } | 5698 } |
5731 } | 5699 } |
5732 } | 5700 } |
5733 return self; | 5701 return self; |
5734 } | 5702 } |
5735 | 5703 |
5736 - (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary { | 5704 - (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary { |
5737 self = [self initWithInt32s:NULL forKeys:NULL count:0]; | 5705 self = [self initWithValues:NULL forKeys:NULL count:0]; |
5738 if (self) { | 5706 if (self) { |
5739 if (dictionary) { | 5707 if (dictionary) { |
5740 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 5708 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
5741 } | 5709 } |
5742 } | 5710 } |
5743 return self; | 5711 return self; |
5744 } | 5712 } |
5745 | 5713 |
5746 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 5714 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
5747 #pragma unused(numItems) | 5715 #pragma unused(numItems) |
5748 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 5716 return [self initWithValues:NULL forKeys:NULL count:0]; |
5749 } | 5717 } |
5750 | 5718 |
5751 - (void)dealloc { | 5719 - (void)dealloc { |
5752 NSAssert(!_autocreator, | 5720 NSAssert(!_autocreator, |
5753 @"%@: Autocreator must be cleared before release, autocreator: %@", | 5721 @"%@: Autocreator must be cleared before release, autocreator: %@", |
5754 [self class], _autocreator); | 5722 [self class], _autocreator); |
5755 [_dictionary release]; | 5723 [_dictionary release]; |
5756 [super dealloc]; | 5724 [super dealloc]; |
5757 } | 5725 } |
5758 | 5726 |
5759 - (instancetype)copyWithZone:(NSZone *)zone { | 5727 - (instancetype)copyWithZone:(NSZone *)zone { |
5760 return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]
; | 5728 return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]
; |
5761 } | 5729 } |
5762 | 5730 |
5763 - (BOOL)isEqual:(id)other { | 5731 - (BOOL)isEqual:(GPBUInt64Int32Dictionary *)other { |
5764 if (self == other) { | 5732 if (self == other) { |
5765 return YES; | 5733 return YES; |
5766 } | 5734 } |
5767 if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) { | 5735 if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) { |
5768 return NO; | 5736 return NO; |
5769 } | 5737 } |
5770 GPBUInt64Int32Dictionary *otherDictionary = other; | 5738 return [_dictionary isEqual:other->_dictionary]; |
5771 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
5772 } | 5739 } |
5773 | 5740 |
5774 - (NSUInteger)hash { | 5741 - (NSUInteger)hash { |
5775 return _dictionary.count; | 5742 return _dictionary.count; |
5776 } | 5743 } |
5777 | 5744 |
5778 - (NSString *)description { | 5745 - (NSString *)description { |
5779 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 5746 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
5780 } | 5747 } |
5781 | 5748 |
5782 - (NSUInteger)count { | 5749 - (NSUInteger)count { |
5783 return _dictionary.count; | 5750 return _dictionary.count; |
5784 } | 5751 } |
5785 | 5752 |
5786 - (void)enumerateKeysAndInt32sUsingBlock: | 5753 - (void)enumerateKeysAndValuesUsingBlock: |
5787 (void (^)(uint64_t key, int32_t value, BOOL *stop))block { | 5754 (void (^)(uint64_t key, int32_t value, BOOL *stop))block { |
5788 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 5755 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
5789 NSNumber *aValue, | 5756 NSNumber *aValue, |
5790 BOOL *stop) { | 5757 BOOL *stop) { |
5791 block([aKey unsignedLongLongValue], [aValue intValue], stop); | 5758 block([aKey unsignedLongLongValue], [aValue intValue], stop); |
5792 }]; | 5759 }]; |
5793 } | 5760 } |
5794 | 5761 |
5795 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 5762 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
5796 NSUInteger count = _dictionary.count; | 5763 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5834 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | 5801 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); |
5835 }]; | 5802 }]; |
5836 } | 5803 } |
5837 | 5804 |
5838 - (void)setGPBGenericValue:(GPBGenericValue *)value | 5805 - (void)setGPBGenericValue:(GPBGenericValue *)value |
5839 forGPBGenericValueKey:(GPBGenericValue *)key { | 5806 forGPBGenericValueKey:(GPBGenericValue *)key { |
5840 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)]; | 5807 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)]; |
5841 } | 5808 } |
5842 | 5809 |
5843 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 5810 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
5844 [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, BOOL *st
op) { | 5811 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, int32_t value, BOOL *st
op) { |
5845 #pragma unused(stop) | 5812 #pragma unused(stop) |
5846 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%d", value]); | 5813 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%d", value]); |
5847 }]; | 5814 }]; |
5848 } | 5815 } |
5849 | 5816 |
5850 - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key { | 5817 - (BOOL)valueForKey:(uint64_t)key value:(int32_t *)value { |
5851 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 5818 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
5852 if (wrapped && value) { | 5819 if (wrapped && value) { |
5853 *value = [wrapped intValue]; | 5820 *value = [wrapped intValue]; |
5854 } | 5821 } |
5855 return (wrapped != NULL); | 5822 return (wrapped != NULL); |
5856 } | 5823 } |
5857 | 5824 |
5858 - (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary { | 5825 - (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary { |
5859 if (otherDictionary) { | 5826 if (otherDictionary) { |
5860 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 5827 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
5861 if (_autocreator) { | 5828 if (_autocreator) { |
5862 GPBAutocreatedDictionaryModified(_autocreator, self); | 5829 GPBAutocreatedDictionaryModified(_autocreator, self); |
5863 } | 5830 } |
5864 } | 5831 } |
5865 } | 5832 } |
5866 | 5833 |
5867 - (void)setInt32:(int32_t)value forKey:(uint64_t)key { | 5834 - (void)setValue:(int32_t)value forKey:(uint64_t)key { |
5868 [_dictionary setObject:@(value) forKey:@(key)]; | 5835 [_dictionary setObject:@(value) forKey:@(key)]; |
5869 if (_autocreator) { | 5836 if (_autocreator) { |
5870 GPBAutocreatedDictionaryModified(_autocreator, self); | 5837 GPBAutocreatedDictionaryModified(_autocreator, self); |
5871 } | 5838 } |
5872 } | 5839 } |
5873 | 5840 |
5874 - (void)removeInt32ForKey:(uint64_t)aKey { | 5841 - (void)removeValueForKey:(uint64_t)aKey { |
5875 [_dictionary removeObjectForKey:@(aKey)]; | 5842 [_dictionary removeObjectForKey:@(aKey)]; |
5876 } | 5843 } |
5877 | 5844 |
5878 - (void)removeAll { | 5845 - (void)removeAll { |
5879 [_dictionary removeAllObjects]; | 5846 [_dictionary removeAllObjects]; |
5880 } | 5847 } |
5881 | 5848 |
5882 @end | 5849 @end |
5883 | 5850 |
5884 #pragma mark - UInt64 -> UInt64 | 5851 #pragma mark - UInt64 -> UInt64 |
5885 | 5852 |
5886 @implementation GPBUInt64UInt64Dictionary { | 5853 @implementation GPBUInt64UInt64Dictionary { |
5887 @package | 5854 @package |
5888 NSMutableDictionary *_dictionary; | 5855 NSMutableDictionary *_dictionary; |
5889 } | 5856 } |
5890 | 5857 |
5891 + (instancetype)dictionary { | 5858 + (instancetype)dictionary { |
5892 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; | 5859 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
5893 } | 5860 } |
5894 | 5861 |
5895 + (instancetype)dictionaryWithUInt64:(uint64_t)value | 5862 + (instancetype)dictionaryWithValue:(uint64_t)value |
5896 forKey:(uint64_t)key { | 5863 forKey:(uint64_t)key { |
5897 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 5864 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
5898 // on to get the type correct. | 5865 // on to get the type correct. |
5899 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithUInt64s:&value | 5866 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithValues:&value |
5900 forKeys:&key | 5867 forKeys:&key |
5901 count:1] autorelea
se]; | 5868 count:1] autoreleas
e]; |
5902 } | 5869 } |
5903 | 5870 |
5904 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values | 5871 + (instancetype)dictionaryWithValues:(const uint64_t [])values |
5905 forKeys:(const uint64_t [])keys | 5872 forKeys:(const uint64_t [])keys |
5906 count:(NSUInteger)count { | 5873 count:(NSUInteger)count { |
5907 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 5874 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
5908 // on to get the type correct. | 5875 // on to get the type correct. |
5909 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithUInt64s:values | 5876 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithValues:values |
5910 forKeys:keys | 5877 forKeys:keys |
5911 count:count] autore
lease]; | 5878 count:count] autore
lease]; |
5912 } | 5879 } |
5913 | 5880 |
5914 + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary
{ | 5881 + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary
{ |
5915 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 5882 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
5916 // on to get the type correct. | 5883 // on to get the type correct. |
5917 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 5884 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
5918 } | 5885 } |
5919 | 5886 |
5920 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 5887 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
5921 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 5888 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
5922 } | 5889 } |
5923 | 5890 |
5924 - (instancetype)init { | 5891 - (instancetype)init { |
5925 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 5892 return [self initWithValues:NULL forKeys:NULL count:0]; |
5926 } | 5893 } |
5927 | 5894 |
5928 - (instancetype)initWithUInt64s:(const uint64_t [])values | 5895 - (instancetype)initWithValues:(const uint64_t [])values |
5929 forKeys:(const uint64_t [])keys | 5896 forKeys:(const uint64_t [])keys |
5930 count:(NSUInteger)count { | 5897 count:(NSUInteger)count { |
5931 self = [super init]; | 5898 self = [super init]; |
5932 if (self) { | 5899 if (self) { |
5933 _dictionary = [[NSMutableDictionary alloc] init]; | 5900 _dictionary = [[NSMutableDictionary alloc] init]; |
5934 if (count && values && keys) { | 5901 if (count && values && keys) { |
5935 for (NSUInteger i = 0; i < count; ++i) { | 5902 for (NSUInteger i = 0; i < count; ++i) { |
5936 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 5903 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
5937 } | 5904 } |
5938 } | 5905 } |
5939 } | 5906 } |
5940 return self; | 5907 return self; |
5941 } | 5908 } |
5942 | 5909 |
5943 - (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary { | 5910 - (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary { |
5944 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; | 5911 self = [self initWithValues:NULL forKeys:NULL count:0]; |
5945 if (self) { | 5912 if (self) { |
5946 if (dictionary) { | 5913 if (dictionary) { |
5947 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 5914 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
5948 } | 5915 } |
5949 } | 5916 } |
5950 return self; | 5917 return self; |
5951 } | 5918 } |
5952 | 5919 |
5953 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 5920 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
5954 #pragma unused(numItems) | 5921 #pragma unused(numItems) |
5955 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 5922 return [self initWithValues:NULL forKeys:NULL count:0]; |
5956 } | 5923 } |
5957 | 5924 |
5958 - (void)dealloc { | 5925 - (void)dealloc { |
5959 NSAssert(!_autocreator, | 5926 NSAssert(!_autocreator, |
5960 @"%@: Autocreator must be cleared before release, autocreator: %@", | 5927 @"%@: Autocreator must be cleared before release, autocreator: %@", |
5961 [self class], _autocreator); | 5928 [self class], _autocreator); |
5962 [_dictionary release]; | 5929 [_dictionary release]; |
5963 [super dealloc]; | 5930 [super dealloc]; |
5964 } | 5931 } |
5965 | 5932 |
5966 - (instancetype)copyWithZone:(NSZone *)zone { | 5933 - (instancetype)copyWithZone:(NSZone *)zone { |
5967 return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; | 5934 return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; |
5968 } | 5935 } |
5969 | 5936 |
5970 - (BOOL)isEqual:(id)other { | 5937 - (BOOL)isEqual:(GPBUInt64UInt64Dictionary *)other { |
5971 if (self == other) { | 5938 if (self == other) { |
5972 return YES; | 5939 return YES; |
5973 } | 5940 } |
5974 if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) { | 5941 if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) { |
5975 return NO; | 5942 return NO; |
5976 } | 5943 } |
5977 GPBUInt64UInt64Dictionary *otherDictionary = other; | 5944 return [_dictionary isEqual:other->_dictionary]; |
5978 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
5979 } | 5945 } |
5980 | 5946 |
5981 - (NSUInteger)hash { | 5947 - (NSUInteger)hash { |
5982 return _dictionary.count; | 5948 return _dictionary.count; |
5983 } | 5949 } |
5984 | 5950 |
5985 - (NSString *)description { | 5951 - (NSString *)description { |
5986 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 5952 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
5987 } | 5953 } |
5988 | 5954 |
5989 - (NSUInteger)count { | 5955 - (NSUInteger)count { |
5990 return _dictionary.count; | 5956 return _dictionary.count; |
5991 } | 5957 } |
5992 | 5958 |
5993 - (void)enumerateKeysAndUInt64sUsingBlock: | 5959 - (void)enumerateKeysAndValuesUsingBlock: |
5994 (void (^)(uint64_t key, uint64_t value, BOOL *stop))block { | 5960 (void (^)(uint64_t key, uint64_t value, BOOL *stop))block { |
5995 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 5961 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
5996 NSNumber *aValue, | 5962 NSNumber *aValue, |
5997 BOOL *stop) { | 5963 BOOL *stop) { |
5998 block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], stop); | 5964 block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], stop); |
5999 }]; | 5965 }]; |
6000 } | 5966 } |
6001 | 5967 |
6002 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 5968 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
6003 NSUInteger count = _dictionary.count; | 5969 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6041 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | 6007 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); |
6042 }]; | 6008 }]; |
6043 } | 6009 } |
6044 | 6010 |
6045 - (void)setGPBGenericValue:(GPBGenericValue *)value | 6011 - (void)setGPBGenericValue:(GPBGenericValue *)value |
6046 forGPBGenericValueKey:(GPBGenericValue *)key { | 6012 forGPBGenericValueKey:(GPBGenericValue *)key { |
6047 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)]; | 6013 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)]; |
6048 } | 6014 } |
6049 | 6015 |
6050 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 6016 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
6051 [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, BOOL *
stop) { | 6017 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, uint64_t value, BOOL *s
top) { |
6052 #pragma unused(stop) | 6018 #pragma unused(stop) |
6053 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%llu", value]); | 6019 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%llu", value]); |
6054 }]; | 6020 }]; |
6055 } | 6021 } |
6056 | 6022 |
6057 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key { | 6023 - (BOOL)valueForKey:(uint64_t)key value:(uint64_t *)value { |
6058 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 6024 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
6059 if (wrapped && value) { | 6025 if (wrapped && value) { |
6060 *value = [wrapped unsignedLongLongValue]; | 6026 *value = [wrapped unsignedLongLongValue]; |
6061 } | 6027 } |
6062 return (wrapped != NULL); | 6028 return (wrapped != NULL); |
6063 } | 6029 } |
6064 | 6030 |
6065 - (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary { | 6031 - (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary { |
6066 if (otherDictionary) { | 6032 if (otherDictionary) { |
6067 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 6033 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
6068 if (_autocreator) { | 6034 if (_autocreator) { |
6069 GPBAutocreatedDictionaryModified(_autocreator, self); | 6035 GPBAutocreatedDictionaryModified(_autocreator, self); |
6070 } | 6036 } |
6071 } | 6037 } |
6072 } | 6038 } |
6073 | 6039 |
6074 - (void)setUInt64:(uint64_t)value forKey:(uint64_t)key { | 6040 - (void)setValue:(uint64_t)value forKey:(uint64_t)key { |
6075 [_dictionary setObject:@(value) forKey:@(key)]; | 6041 [_dictionary setObject:@(value) forKey:@(key)]; |
6076 if (_autocreator) { | 6042 if (_autocreator) { |
6077 GPBAutocreatedDictionaryModified(_autocreator, self); | 6043 GPBAutocreatedDictionaryModified(_autocreator, self); |
6078 } | 6044 } |
6079 } | 6045 } |
6080 | 6046 |
6081 - (void)removeUInt64ForKey:(uint64_t)aKey { | 6047 - (void)removeValueForKey:(uint64_t)aKey { |
6082 [_dictionary removeObjectForKey:@(aKey)]; | 6048 [_dictionary removeObjectForKey:@(aKey)]; |
6083 } | 6049 } |
6084 | 6050 |
6085 - (void)removeAll { | 6051 - (void)removeAll { |
6086 [_dictionary removeAllObjects]; | 6052 [_dictionary removeAllObjects]; |
6087 } | 6053 } |
6088 | 6054 |
6089 @end | 6055 @end |
6090 | 6056 |
6091 #pragma mark - UInt64 -> Int64 | 6057 #pragma mark - UInt64 -> Int64 |
6092 | 6058 |
6093 @implementation GPBUInt64Int64Dictionary { | 6059 @implementation GPBUInt64Int64Dictionary { |
6094 @package | 6060 @package |
6095 NSMutableDictionary *_dictionary; | 6061 NSMutableDictionary *_dictionary; |
6096 } | 6062 } |
6097 | 6063 |
6098 + (instancetype)dictionary { | 6064 + (instancetype)dictionary { |
6099 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; | 6065 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
6100 } | 6066 } |
6101 | 6067 |
6102 + (instancetype)dictionaryWithInt64:(int64_t)value | 6068 + (instancetype)dictionaryWithValue:(int64_t)value |
6103 forKey:(uint64_t)key { | 6069 forKey:(uint64_t)key { |
6104 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 6070 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
6105 // on to get the type correct. | 6071 // on to get the type correct. |
6106 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithInt64s:&value | 6072 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithValues:&value |
6107 forKeys:&key | 6073 forKeys:&key |
6108 count:1] autorelease
]; | 6074 count:1] autorelease
]; |
6109 } | 6075 } |
6110 | 6076 |
6111 + (instancetype)dictionaryWithInt64s:(const int64_t [])values | 6077 + (instancetype)dictionaryWithValues:(const int64_t [])values |
6112 forKeys:(const uint64_t [])keys | 6078 forKeys:(const uint64_t [])keys |
6113 count:(NSUInteger)count { | 6079 count:(NSUInteger)count { |
6114 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 6080 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
6115 // on to get the type correct. | 6081 // on to get the type correct. |
6116 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithInt64s:values | 6082 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithValues:values |
6117 forKeys:keys | 6083 forKeys:keys |
6118 count:count] autorel
ease]; | 6084 count:count] autorel
ease]; |
6119 } | 6085 } |
6120 | 6086 |
6121 + (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary
{ | 6087 + (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary
{ |
6122 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 6088 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
6123 // on to get the type correct. | 6089 // on to get the type correct. |
6124 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 6090 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
6125 } | 6091 } |
6126 | 6092 |
6127 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 6093 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
6128 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 6094 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
6129 } | 6095 } |
6130 | 6096 |
6131 - (instancetype)init { | 6097 - (instancetype)init { |
6132 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 6098 return [self initWithValues:NULL forKeys:NULL count:0]; |
6133 } | 6099 } |
6134 | 6100 |
6135 - (instancetype)initWithInt64s:(const int64_t [])values | 6101 - (instancetype)initWithValues:(const int64_t [])values |
6136 forKeys:(const uint64_t [])keys | 6102 forKeys:(const uint64_t [])keys |
6137 count:(NSUInteger)count { | 6103 count:(NSUInteger)count { |
6138 self = [super init]; | 6104 self = [super init]; |
6139 if (self) { | 6105 if (self) { |
6140 _dictionary = [[NSMutableDictionary alloc] init]; | 6106 _dictionary = [[NSMutableDictionary alloc] init]; |
6141 if (count && values && keys) { | 6107 if (count && values && keys) { |
6142 for (NSUInteger i = 0; i < count; ++i) { | 6108 for (NSUInteger i = 0; i < count; ++i) { |
6143 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 6109 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
6144 } | 6110 } |
6145 } | 6111 } |
6146 } | 6112 } |
6147 return self; | 6113 return self; |
6148 } | 6114 } |
6149 | 6115 |
6150 - (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary { | 6116 - (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary { |
6151 self = [self initWithInt64s:NULL forKeys:NULL count:0]; | 6117 self = [self initWithValues:NULL forKeys:NULL count:0]; |
6152 if (self) { | 6118 if (self) { |
6153 if (dictionary) { | 6119 if (dictionary) { |
6154 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 6120 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
6155 } | 6121 } |
6156 } | 6122 } |
6157 return self; | 6123 return self; |
6158 } | 6124 } |
6159 | 6125 |
6160 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 6126 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
6161 #pragma unused(numItems) | 6127 #pragma unused(numItems) |
6162 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 6128 return [self initWithValues:NULL forKeys:NULL count:0]; |
6163 } | 6129 } |
6164 | 6130 |
6165 - (void)dealloc { | 6131 - (void)dealloc { |
6166 NSAssert(!_autocreator, | 6132 NSAssert(!_autocreator, |
6167 @"%@: Autocreator must be cleared before release, autocreator: %@", | 6133 @"%@: Autocreator must be cleared before release, autocreator: %@", |
6168 [self class], _autocreator); | 6134 [self class], _autocreator); |
6169 [_dictionary release]; | 6135 [_dictionary release]; |
6170 [super dealloc]; | 6136 [super dealloc]; |
6171 } | 6137 } |
6172 | 6138 |
6173 - (instancetype)copyWithZone:(NSZone *)zone { | 6139 - (instancetype)copyWithZone:(NSZone *)zone { |
6174 return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]
; | 6140 return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]
; |
6175 } | 6141 } |
6176 | 6142 |
6177 - (BOOL)isEqual:(id)other { | 6143 - (BOOL)isEqual:(GPBUInt64Int64Dictionary *)other { |
6178 if (self == other) { | 6144 if (self == other) { |
6179 return YES; | 6145 return YES; |
6180 } | 6146 } |
6181 if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) { | 6147 if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) { |
6182 return NO; | 6148 return NO; |
6183 } | 6149 } |
6184 GPBUInt64Int64Dictionary *otherDictionary = other; | 6150 return [_dictionary isEqual:other->_dictionary]; |
6185 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
6186 } | 6151 } |
6187 | 6152 |
6188 - (NSUInteger)hash { | 6153 - (NSUInteger)hash { |
6189 return _dictionary.count; | 6154 return _dictionary.count; |
6190 } | 6155 } |
6191 | 6156 |
6192 - (NSString *)description { | 6157 - (NSString *)description { |
6193 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 6158 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
6194 } | 6159 } |
6195 | 6160 |
6196 - (NSUInteger)count { | 6161 - (NSUInteger)count { |
6197 return _dictionary.count; | 6162 return _dictionary.count; |
6198 } | 6163 } |
6199 | 6164 |
6200 - (void)enumerateKeysAndInt64sUsingBlock: | 6165 - (void)enumerateKeysAndValuesUsingBlock: |
6201 (void (^)(uint64_t key, int64_t value, BOOL *stop))block { | 6166 (void (^)(uint64_t key, int64_t value, BOOL *stop))block { |
6202 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 6167 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
6203 NSNumber *aValue, | 6168 NSNumber *aValue, |
6204 BOOL *stop) { | 6169 BOOL *stop) { |
6205 block([aKey unsignedLongLongValue], [aValue longLongValue], stop); | 6170 block([aKey unsignedLongLongValue], [aValue longLongValue], stop); |
6206 }]; | 6171 }]; |
6207 } | 6172 } |
6208 | 6173 |
6209 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 6174 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
6210 NSUInteger count = _dictionary.count; | 6175 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6248 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | 6213 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); |
6249 }]; | 6214 }]; |
6250 } | 6215 } |
6251 | 6216 |
6252 - (void)setGPBGenericValue:(GPBGenericValue *)value | 6217 - (void)setGPBGenericValue:(GPBGenericValue *)value |
6253 forGPBGenericValueKey:(GPBGenericValue *)key { | 6218 forGPBGenericValueKey:(GPBGenericValue *)key { |
6254 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)]; | 6219 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)]; |
6255 } | 6220 } |
6256 | 6221 |
6257 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 6222 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
6258 [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, BOOL *st
op) { | 6223 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, int64_t value, BOOL *st
op) { |
6259 #pragma unused(stop) | 6224 #pragma unused(stop) |
6260 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%lld", value]); | 6225 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%lld", value]); |
6261 }]; | 6226 }]; |
6262 } | 6227 } |
6263 | 6228 |
6264 - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key { | 6229 - (BOOL)valueForKey:(uint64_t)key value:(int64_t *)value { |
6265 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 6230 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
6266 if (wrapped && value) { | 6231 if (wrapped && value) { |
6267 *value = [wrapped longLongValue]; | 6232 *value = [wrapped longLongValue]; |
6268 } | 6233 } |
6269 return (wrapped != NULL); | 6234 return (wrapped != NULL); |
6270 } | 6235 } |
6271 | 6236 |
6272 - (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary { | 6237 - (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary { |
6273 if (otherDictionary) { | 6238 if (otherDictionary) { |
6274 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 6239 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
6275 if (_autocreator) { | 6240 if (_autocreator) { |
6276 GPBAutocreatedDictionaryModified(_autocreator, self); | 6241 GPBAutocreatedDictionaryModified(_autocreator, self); |
6277 } | 6242 } |
6278 } | 6243 } |
6279 } | 6244 } |
6280 | 6245 |
6281 - (void)setInt64:(int64_t)value forKey:(uint64_t)key { | 6246 - (void)setValue:(int64_t)value forKey:(uint64_t)key { |
6282 [_dictionary setObject:@(value) forKey:@(key)]; | 6247 [_dictionary setObject:@(value) forKey:@(key)]; |
6283 if (_autocreator) { | 6248 if (_autocreator) { |
6284 GPBAutocreatedDictionaryModified(_autocreator, self); | 6249 GPBAutocreatedDictionaryModified(_autocreator, self); |
6285 } | 6250 } |
6286 } | 6251 } |
6287 | 6252 |
6288 - (void)removeInt64ForKey:(uint64_t)aKey { | 6253 - (void)removeValueForKey:(uint64_t)aKey { |
6289 [_dictionary removeObjectForKey:@(aKey)]; | 6254 [_dictionary removeObjectForKey:@(aKey)]; |
6290 } | 6255 } |
6291 | 6256 |
6292 - (void)removeAll { | 6257 - (void)removeAll { |
6293 [_dictionary removeAllObjects]; | 6258 [_dictionary removeAllObjects]; |
6294 } | 6259 } |
6295 | 6260 |
6296 @end | 6261 @end |
6297 | 6262 |
6298 #pragma mark - UInt64 -> Bool | 6263 #pragma mark - UInt64 -> Bool |
6299 | 6264 |
6300 @implementation GPBUInt64BoolDictionary { | 6265 @implementation GPBUInt64BoolDictionary { |
6301 @package | 6266 @package |
6302 NSMutableDictionary *_dictionary; | 6267 NSMutableDictionary *_dictionary; |
6303 } | 6268 } |
6304 | 6269 |
6305 + (instancetype)dictionary { | 6270 + (instancetype)dictionary { |
6306 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; | 6271 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
6307 } | 6272 } |
6308 | 6273 |
6309 + (instancetype)dictionaryWithBool:(BOOL)value | 6274 + (instancetype)dictionaryWithValue:(BOOL)value |
6310 forKey:(uint64_t)key { | 6275 forKey:(uint64_t)key { |
6311 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 6276 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
6312 // on to get the type correct. | 6277 // on to get the type correct. |
6313 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithBools:&value | 6278 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithValues:&value |
6314 forKeys:&key | 6279 forKeys:&key |
6315 count:1] autorelease]; | 6280 count:1] autorelease]
; |
6316 } | 6281 } |
6317 | 6282 |
6318 + (instancetype)dictionaryWithBools:(const BOOL [])values | 6283 + (instancetype)dictionaryWithValues:(const BOOL [])values |
6319 forKeys:(const uint64_t [])keys | 6284 forKeys:(const uint64_t [])keys |
6320 count:(NSUInteger)count { | 6285 count:(NSUInteger)count { |
6321 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 6286 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
6322 // on to get the type correct. | 6287 // on to get the type correct. |
6323 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithBools:values | 6288 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithValues:values |
6324 forKeys:keys | 6289 forKeys:keys |
6325 count:count] autorele
ase]; | 6290 count:count] autorele
ase]; |
6326 } | 6291 } |
6327 | 6292 |
6328 + (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary { | 6293 + (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary { |
6329 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 6294 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
6330 // on to get the type correct. | 6295 // on to get the type correct. |
6331 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 6296 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
6332 } | 6297 } |
6333 | 6298 |
6334 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 6299 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
6335 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 6300 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
6336 } | 6301 } |
6337 | 6302 |
6338 - (instancetype)init { | 6303 - (instancetype)init { |
6339 return [self initWithBools:NULL forKeys:NULL count:0]; | 6304 return [self initWithValues:NULL forKeys:NULL count:0]; |
6340 } | 6305 } |
6341 | 6306 |
6342 - (instancetype)initWithBools:(const BOOL [])values | 6307 - (instancetype)initWithValues:(const BOOL [])values |
6343 forKeys:(const uint64_t [])keys | 6308 forKeys:(const uint64_t [])keys |
6344 count:(NSUInteger)count { | 6309 count:(NSUInteger)count { |
6345 self = [super init]; | 6310 self = [super init]; |
6346 if (self) { | 6311 if (self) { |
6347 _dictionary = [[NSMutableDictionary alloc] init]; | 6312 _dictionary = [[NSMutableDictionary alloc] init]; |
6348 if (count && values && keys) { | 6313 if (count && values && keys) { |
6349 for (NSUInteger i = 0; i < count; ++i) { | 6314 for (NSUInteger i = 0; i < count; ++i) { |
6350 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 6315 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
6351 } | 6316 } |
6352 } | 6317 } |
6353 } | 6318 } |
6354 return self; | 6319 return self; |
6355 } | 6320 } |
6356 | 6321 |
6357 - (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary { | 6322 - (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary { |
6358 self = [self initWithBools:NULL forKeys:NULL count:0]; | 6323 self = [self initWithValues:NULL forKeys:NULL count:0]; |
6359 if (self) { | 6324 if (self) { |
6360 if (dictionary) { | 6325 if (dictionary) { |
6361 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 6326 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
6362 } | 6327 } |
6363 } | 6328 } |
6364 return self; | 6329 return self; |
6365 } | 6330 } |
6366 | 6331 |
6367 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 6332 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
6368 #pragma unused(numItems) | 6333 #pragma unused(numItems) |
6369 return [self initWithBools:NULL forKeys:NULL count:0]; | 6334 return [self initWithValues:NULL forKeys:NULL count:0]; |
6370 } | 6335 } |
6371 | 6336 |
6372 - (void)dealloc { | 6337 - (void)dealloc { |
6373 NSAssert(!_autocreator, | 6338 NSAssert(!_autocreator, |
6374 @"%@: Autocreator must be cleared before release, autocreator: %@", | 6339 @"%@: Autocreator must be cleared before release, autocreator: %@", |
6375 [self class], _autocreator); | 6340 [self class], _autocreator); |
6376 [_dictionary release]; | 6341 [_dictionary release]; |
6377 [super dealloc]; | 6342 [super dealloc]; |
6378 } | 6343 } |
6379 | 6344 |
6380 - (instancetype)copyWithZone:(NSZone *)zone { | 6345 - (instancetype)copyWithZone:(NSZone *)zone { |
6381 return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; | 6346 return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; |
6382 } | 6347 } |
6383 | 6348 |
6384 - (BOOL)isEqual:(id)other { | 6349 - (BOOL)isEqual:(GPBUInt64BoolDictionary *)other { |
6385 if (self == other) { | 6350 if (self == other) { |
6386 return YES; | 6351 return YES; |
6387 } | 6352 } |
6388 if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) { | 6353 if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) { |
6389 return NO; | 6354 return NO; |
6390 } | 6355 } |
6391 GPBUInt64BoolDictionary *otherDictionary = other; | 6356 return [_dictionary isEqual:other->_dictionary]; |
6392 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
6393 } | 6357 } |
6394 | 6358 |
6395 - (NSUInteger)hash { | 6359 - (NSUInteger)hash { |
6396 return _dictionary.count; | 6360 return _dictionary.count; |
6397 } | 6361 } |
6398 | 6362 |
6399 - (NSString *)description { | 6363 - (NSString *)description { |
6400 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 6364 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
6401 } | 6365 } |
6402 | 6366 |
6403 - (NSUInteger)count { | 6367 - (NSUInteger)count { |
6404 return _dictionary.count; | 6368 return _dictionary.count; |
6405 } | 6369 } |
6406 | 6370 |
6407 - (void)enumerateKeysAndBoolsUsingBlock: | 6371 - (void)enumerateKeysAndValuesUsingBlock: |
6408 (void (^)(uint64_t key, BOOL value, BOOL *stop))block { | 6372 (void (^)(uint64_t key, BOOL value, BOOL *stop))block { |
6409 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 6373 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
6410 NSNumber *aValue, | 6374 NSNumber *aValue, |
6411 BOOL *stop) { | 6375 BOOL *stop) { |
6412 block([aKey unsignedLongLongValue], [aValue boolValue], stop); | 6376 block([aKey unsignedLongLongValue], [aValue boolValue], stop); |
6413 }]; | 6377 }]; |
6414 } | 6378 } |
6415 | 6379 |
6416 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 6380 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
6417 NSUInteger count = _dictionary.count; | 6381 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6455 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | 6419 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); |
6456 }]; | 6420 }]; |
6457 } | 6421 } |
6458 | 6422 |
6459 - (void)setGPBGenericValue:(GPBGenericValue *)value | 6423 - (void)setGPBGenericValue:(GPBGenericValue *)value |
6460 forGPBGenericValueKey:(GPBGenericValue *)key { | 6424 forGPBGenericValueKey:(GPBGenericValue *)key { |
6461 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)]; | 6425 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)]; |
6462 } | 6426 } |
6463 | 6427 |
6464 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 6428 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
6465 [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, BOOL *stop)
{ | 6429 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, BOOL value, BOOL *stop)
{ |
6466 #pragma unused(stop) | 6430 #pragma unused(stop) |
6467 block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false
")); | 6431 block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false
")); |
6468 }]; | 6432 }]; |
6469 } | 6433 } |
6470 | 6434 |
6471 - (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key { | 6435 - (BOOL)valueForKey:(uint64_t)key value:(BOOL *)value { |
6472 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 6436 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
6473 if (wrapped && value) { | 6437 if (wrapped && value) { |
6474 *value = [wrapped boolValue]; | 6438 *value = [wrapped boolValue]; |
6475 } | 6439 } |
6476 return (wrapped != NULL); | 6440 return (wrapped != NULL); |
6477 } | 6441 } |
6478 | 6442 |
6479 - (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary { | 6443 - (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary { |
6480 if (otherDictionary) { | 6444 if (otherDictionary) { |
6481 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 6445 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
6482 if (_autocreator) { | 6446 if (_autocreator) { |
6483 GPBAutocreatedDictionaryModified(_autocreator, self); | 6447 GPBAutocreatedDictionaryModified(_autocreator, self); |
6484 } | 6448 } |
6485 } | 6449 } |
6486 } | 6450 } |
6487 | 6451 |
6488 - (void)setBool:(BOOL)value forKey:(uint64_t)key { | 6452 - (void)setValue:(BOOL)value forKey:(uint64_t)key { |
6489 [_dictionary setObject:@(value) forKey:@(key)]; | 6453 [_dictionary setObject:@(value) forKey:@(key)]; |
6490 if (_autocreator) { | 6454 if (_autocreator) { |
6491 GPBAutocreatedDictionaryModified(_autocreator, self); | 6455 GPBAutocreatedDictionaryModified(_autocreator, self); |
6492 } | 6456 } |
6493 } | 6457 } |
6494 | 6458 |
6495 - (void)removeBoolForKey:(uint64_t)aKey { | 6459 - (void)removeValueForKey:(uint64_t)aKey { |
6496 [_dictionary removeObjectForKey:@(aKey)]; | 6460 [_dictionary removeObjectForKey:@(aKey)]; |
6497 } | 6461 } |
6498 | 6462 |
6499 - (void)removeAll { | 6463 - (void)removeAll { |
6500 [_dictionary removeAllObjects]; | 6464 [_dictionary removeAllObjects]; |
6501 } | 6465 } |
6502 | 6466 |
6503 @end | 6467 @end |
6504 | 6468 |
6505 #pragma mark - UInt64 -> Float | 6469 #pragma mark - UInt64 -> Float |
6506 | 6470 |
6507 @implementation GPBUInt64FloatDictionary { | 6471 @implementation GPBUInt64FloatDictionary { |
6508 @package | 6472 @package |
6509 NSMutableDictionary *_dictionary; | 6473 NSMutableDictionary *_dictionary; |
6510 } | 6474 } |
6511 | 6475 |
6512 + (instancetype)dictionary { | 6476 + (instancetype)dictionary { |
6513 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; | 6477 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
6514 } | 6478 } |
6515 | 6479 |
6516 + (instancetype)dictionaryWithFloat:(float)value | 6480 + (instancetype)dictionaryWithValue:(float)value |
6517 forKey:(uint64_t)key { | 6481 forKey:(uint64_t)key { |
6518 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 6482 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
6519 // on to get the type correct. | 6483 // on to get the type correct. |
6520 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithFloats:&value | 6484 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithValues:&value |
6521 forKeys:&key | 6485 forKeys:&key |
6522 count:1] autorelease
]; | 6486 count:1] autorelease
]; |
6523 } | 6487 } |
6524 | 6488 |
6525 + (instancetype)dictionaryWithFloats:(const float [])values | 6489 + (instancetype)dictionaryWithValues:(const float [])values |
6526 forKeys:(const uint64_t [])keys | 6490 forKeys:(const uint64_t [])keys |
6527 count:(NSUInteger)count { | 6491 count:(NSUInteger)count { |
6528 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 6492 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
6529 // on to get the type correct. | 6493 // on to get the type correct. |
6530 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithFloats:values | 6494 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithValues:values |
6531 forKeys:keys | 6495 forKeys:keys |
6532 count:count] autorel
ease]; | 6496 count:count] autorel
ease]; |
6533 } | 6497 } |
6534 | 6498 |
6535 + (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary
{ | 6499 + (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary
{ |
6536 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 6500 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
6537 // on to get the type correct. | 6501 // on to get the type correct. |
6538 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 6502 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
6539 } | 6503 } |
6540 | 6504 |
6541 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 6505 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
6542 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 6506 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
6543 } | 6507 } |
6544 | 6508 |
6545 - (instancetype)init { | 6509 - (instancetype)init { |
6546 return [self initWithFloats:NULL forKeys:NULL count:0]; | 6510 return [self initWithValues:NULL forKeys:NULL count:0]; |
6547 } | 6511 } |
6548 | 6512 |
6549 - (instancetype)initWithFloats:(const float [])values | 6513 - (instancetype)initWithValues:(const float [])values |
6550 forKeys:(const uint64_t [])keys | 6514 forKeys:(const uint64_t [])keys |
6551 count:(NSUInteger)count { | 6515 count:(NSUInteger)count { |
6552 self = [super init]; | 6516 self = [super init]; |
6553 if (self) { | 6517 if (self) { |
6554 _dictionary = [[NSMutableDictionary alloc] init]; | 6518 _dictionary = [[NSMutableDictionary alloc] init]; |
6555 if (count && values && keys) { | 6519 if (count && values && keys) { |
6556 for (NSUInteger i = 0; i < count; ++i) { | 6520 for (NSUInteger i = 0; i < count; ++i) { |
6557 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 6521 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
6558 } | 6522 } |
6559 } | 6523 } |
6560 } | 6524 } |
6561 return self; | 6525 return self; |
6562 } | 6526 } |
6563 | 6527 |
6564 - (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary { | 6528 - (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary { |
6565 self = [self initWithFloats:NULL forKeys:NULL count:0]; | 6529 self = [self initWithValues:NULL forKeys:NULL count:0]; |
6566 if (self) { | 6530 if (self) { |
6567 if (dictionary) { | 6531 if (dictionary) { |
6568 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 6532 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
6569 } | 6533 } |
6570 } | 6534 } |
6571 return self; | 6535 return self; |
6572 } | 6536 } |
6573 | 6537 |
6574 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 6538 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
6575 #pragma unused(numItems) | 6539 #pragma unused(numItems) |
6576 return [self initWithFloats:NULL forKeys:NULL count:0]; | 6540 return [self initWithValues:NULL forKeys:NULL count:0]; |
6577 } | 6541 } |
6578 | 6542 |
6579 - (void)dealloc { | 6543 - (void)dealloc { |
6580 NSAssert(!_autocreator, | 6544 NSAssert(!_autocreator, |
6581 @"%@: Autocreator must be cleared before release, autocreator: %@", | 6545 @"%@: Autocreator must be cleared before release, autocreator: %@", |
6582 [self class], _autocreator); | 6546 [self class], _autocreator); |
6583 [_dictionary release]; | 6547 [_dictionary release]; |
6584 [super dealloc]; | 6548 [super dealloc]; |
6585 } | 6549 } |
6586 | 6550 |
6587 - (instancetype)copyWithZone:(NSZone *)zone { | 6551 - (instancetype)copyWithZone:(NSZone *)zone { |
6588 return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]
; | 6552 return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]
; |
6589 } | 6553 } |
6590 | 6554 |
6591 - (BOOL)isEqual:(id)other { | 6555 - (BOOL)isEqual:(GPBUInt64FloatDictionary *)other { |
6592 if (self == other) { | 6556 if (self == other) { |
6593 return YES; | 6557 return YES; |
6594 } | 6558 } |
6595 if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) { | 6559 if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) { |
6596 return NO; | 6560 return NO; |
6597 } | 6561 } |
6598 GPBUInt64FloatDictionary *otherDictionary = other; | 6562 return [_dictionary isEqual:other->_dictionary]; |
6599 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
6600 } | 6563 } |
6601 | 6564 |
6602 - (NSUInteger)hash { | 6565 - (NSUInteger)hash { |
6603 return _dictionary.count; | 6566 return _dictionary.count; |
6604 } | 6567 } |
6605 | 6568 |
6606 - (NSString *)description { | 6569 - (NSString *)description { |
6607 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 6570 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
6608 } | 6571 } |
6609 | 6572 |
6610 - (NSUInteger)count { | 6573 - (NSUInteger)count { |
6611 return _dictionary.count; | 6574 return _dictionary.count; |
6612 } | 6575 } |
6613 | 6576 |
6614 - (void)enumerateKeysAndFloatsUsingBlock: | 6577 - (void)enumerateKeysAndValuesUsingBlock: |
6615 (void (^)(uint64_t key, float value, BOOL *stop))block { | 6578 (void (^)(uint64_t key, float value, BOOL *stop))block { |
6616 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 6579 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
6617 NSNumber *aValue, | 6580 NSNumber *aValue, |
6618 BOOL *stop) { | 6581 BOOL *stop) { |
6619 block([aKey unsignedLongLongValue], [aValue floatValue], stop); | 6582 block([aKey unsignedLongLongValue], [aValue floatValue], stop); |
6620 }]; | 6583 }]; |
6621 } | 6584 } |
6622 | 6585 |
6623 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 6586 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
6624 NSUInteger count = _dictionary.count; | 6587 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6662 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | 6625 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); |
6663 }]; | 6626 }]; |
6664 } | 6627 } |
6665 | 6628 |
6666 - (void)setGPBGenericValue:(GPBGenericValue *)value | 6629 - (void)setGPBGenericValue:(GPBGenericValue *)value |
6667 forGPBGenericValueKey:(GPBGenericValue *)key { | 6630 forGPBGenericValueKey:(GPBGenericValue *)key { |
6668 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)]; | 6631 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)]; |
6669 } | 6632 } |
6670 | 6633 |
6671 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 6634 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
6672 [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, BOOL *stop
) { | 6635 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, float value, BOOL *stop
) { |
6673 #pragma unused(stop) | 6636 #pragma unused(stop) |
6674 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%.*g", FLT_DIG, value]); | 6637 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%.*g", FLT_DIG, value]); |
6675 }]; | 6638 }]; |
6676 } | 6639 } |
6677 | 6640 |
6678 - (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key { | 6641 - (BOOL)valueForKey:(uint64_t)key value:(float *)value { |
6679 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 6642 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
6680 if (wrapped && value) { | 6643 if (wrapped && value) { |
6681 *value = [wrapped floatValue]; | 6644 *value = [wrapped floatValue]; |
6682 } | 6645 } |
6683 return (wrapped != NULL); | 6646 return (wrapped != NULL); |
6684 } | 6647 } |
6685 | 6648 |
6686 - (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary { | 6649 - (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary { |
6687 if (otherDictionary) { | 6650 if (otherDictionary) { |
6688 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 6651 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
6689 if (_autocreator) { | 6652 if (_autocreator) { |
6690 GPBAutocreatedDictionaryModified(_autocreator, self); | 6653 GPBAutocreatedDictionaryModified(_autocreator, self); |
6691 } | 6654 } |
6692 } | 6655 } |
6693 } | 6656 } |
6694 | 6657 |
6695 - (void)setFloat:(float)value forKey:(uint64_t)key { | 6658 - (void)setValue:(float)value forKey:(uint64_t)key { |
6696 [_dictionary setObject:@(value) forKey:@(key)]; | 6659 [_dictionary setObject:@(value) forKey:@(key)]; |
6697 if (_autocreator) { | 6660 if (_autocreator) { |
6698 GPBAutocreatedDictionaryModified(_autocreator, self); | 6661 GPBAutocreatedDictionaryModified(_autocreator, self); |
6699 } | 6662 } |
6700 } | 6663 } |
6701 | 6664 |
6702 - (void)removeFloatForKey:(uint64_t)aKey { | 6665 - (void)removeValueForKey:(uint64_t)aKey { |
6703 [_dictionary removeObjectForKey:@(aKey)]; | 6666 [_dictionary removeObjectForKey:@(aKey)]; |
6704 } | 6667 } |
6705 | 6668 |
6706 - (void)removeAll { | 6669 - (void)removeAll { |
6707 [_dictionary removeAllObjects]; | 6670 [_dictionary removeAllObjects]; |
6708 } | 6671 } |
6709 | 6672 |
6710 @end | 6673 @end |
6711 | 6674 |
6712 #pragma mark - UInt64 -> Double | 6675 #pragma mark - UInt64 -> Double |
6713 | 6676 |
6714 @implementation GPBUInt64DoubleDictionary { | 6677 @implementation GPBUInt64DoubleDictionary { |
6715 @package | 6678 @package |
6716 NSMutableDictionary *_dictionary; | 6679 NSMutableDictionary *_dictionary; |
6717 } | 6680 } |
6718 | 6681 |
6719 + (instancetype)dictionary { | 6682 + (instancetype)dictionary { |
6720 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; | 6683 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
6721 } | 6684 } |
6722 | 6685 |
6723 + (instancetype)dictionaryWithDouble:(double)value | 6686 + (instancetype)dictionaryWithValue:(double)value |
6724 forKey:(uint64_t)key { | 6687 forKey:(uint64_t)key { |
6725 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 6688 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
6726 // on to get the type correct. | 6689 // on to get the type correct. |
6727 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDoubles:&value | 6690 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithValues:&value |
6728 forKeys:&key | 6691 forKeys:&key |
6729 count:1] autorelea
se]; | 6692 count:1] autoreleas
e]; |
6730 } | 6693 } |
6731 | 6694 |
6732 + (instancetype)dictionaryWithDoubles:(const double [])values | 6695 + (instancetype)dictionaryWithValues:(const double [])values |
6733 forKeys:(const uint64_t [])keys | 6696 forKeys:(const uint64_t [])keys |
6734 count:(NSUInteger)count { | 6697 count:(NSUInteger)count { |
6735 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 6698 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
6736 // on to get the type correct. | 6699 // on to get the type correct. |
6737 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDoubles:values | 6700 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithValues:values |
6738 forKeys:keys | 6701 forKeys:keys |
6739 count:count] autore
lease]; | 6702 count:count] autore
lease]; |
6740 } | 6703 } |
6741 | 6704 |
6742 + (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary
{ | 6705 + (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary
{ |
6743 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 6706 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
6744 // on to get the type correct. | 6707 // on to get the type correct. |
6745 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 6708 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
6746 } | 6709 } |
6747 | 6710 |
6748 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 6711 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
6749 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 6712 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
6750 } | 6713 } |
6751 | 6714 |
6752 - (instancetype)init { | 6715 - (instancetype)init { |
6753 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 6716 return [self initWithValues:NULL forKeys:NULL count:0]; |
6754 } | 6717 } |
6755 | 6718 |
6756 - (instancetype)initWithDoubles:(const double [])values | 6719 - (instancetype)initWithValues:(const double [])values |
6757 forKeys:(const uint64_t [])keys | 6720 forKeys:(const uint64_t [])keys |
6758 count:(NSUInteger)count { | 6721 count:(NSUInteger)count { |
6759 self = [super init]; | 6722 self = [super init]; |
6760 if (self) { | 6723 if (self) { |
6761 _dictionary = [[NSMutableDictionary alloc] init]; | 6724 _dictionary = [[NSMutableDictionary alloc] init]; |
6762 if (count && values && keys) { | 6725 if (count && values && keys) { |
6763 for (NSUInteger i = 0; i < count; ++i) { | 6726 for (NSUInteger i = 0; i < count; ++i) { |
6764 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 6727 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
6765 } | 6728 } |
6766 } | 6729 } |
6767 } | 6730 } |
6768 return self; | 6731 return self; |
6769 } | 6732 } |
6770 | 6733 |
6771 - (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary { | 6734 - (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary { |
6772 self = [self initWithDoubles:NULL forKeys:NULL count:0]; | 6735 self = [self initWithValues:NULL forKeys:NULL count:0]; |
6773 if (self) { | 6736 if (self) { |
6774 if (dictionary) { | 6737 if (dictionary) { |
6775 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 6738 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
6776 } | 6739 } |
6777 } | 6740 } |
6778 return self; | 6741 return self; |
6779 } | 6742 } |
6780 | 6743 |
6781 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 6744 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
6782 #pragma unused(numItems) | 6745 #pragma unused(numItems) |
6783 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 6746 return [self initWithValues:NULL forKeys:NULL count:0]; |
6784 } | 6747 } |
6785 | 6748 |
6786 - (void)dealloc { | 6749 - (void)dealloc { |
6787 NSAssert(!_autocreator, | 6750 NSAssert(!_autocreator, |
6788 @"%@: Autocreator must be cleared before release, autocreator: %@", | 6751 @"%@: Autocreator must be cleared before release, autocreator: %@", |
6789 [self class], _autocreator); | 6752 [self class], _autocreator); |
6790 [_dictionary release]; | 6753 [_dictionary release]; |
6791 [super dealloc]; | 6754 [super dealloc]; |
6792 } | 6755 } |
6793 | 6756 |
6794 - (instancetype)copyWithZone:(NSZone *)zone { | 6757 - (instancetype)copyWithZone:(NSZone *)zone { |
6795 return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self
]; | 6758 return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self
]; |
6796 } | 6759 } |
6797 | 6760 |
6798 - (BOOL)isEqual:(id)other { | 6761 - (BOOL)isEqual:(GPBUInt64DoubleDictionary *)other { |
6799 if (self == other) { | 6762 if (self == other) { |
6800 return YES; | 6763 return YES; |
6801 } | 6764 } |
6802 if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) { | 6765 if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) { |
6803 return NO; | 6766 return NO; |
6804 } | 6767 } |
6805 GPBUInt64DoubleDictionary *otherDictionary = other; | 6768 return [_dictionary isEqual:other->_dictionary]; |
6806 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
6807 } | 6769 } |
6808 | 6770 |
6809 - (NSUInteger)hash { | 6771 - (NSUInteger)hash { |
6810 return _dictionary.count; | 6772 return _dictionary.count; |
6811 } | 6773 } |
6812 | 6774 |
6813 - (NSString *)description { | 6775 - (NSString *)description { |
6814 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 6776 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
6815 } | 6777 } |
6816 | 6778 |
6817 - (NSUInteger)count { | 6779 - (NSUInteger)count { |
6818 return _dictionary.count; | 6780 return _dictionary.count; |
6819 } | 6781 } |
6820 | 6782 |
6821 - (void)enumerateKeysAndDoublesUsingBlock: | 6783 - (void)enumerateKeysAndValuesUsingBlock: |
6822 (void (^)(uint64_t key, double value, BOOL *stop))block { | 6784 (void (^)(uint64_t key, double value, BOOL *stop))block { |
6823 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 6785 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
6824 NSNumber *aValue, | 6786 NSNumber *aValue, |
6825 BOOL *stop) { | 6787 BOOL *stop) { |
6826 block([aKey unsignedLongLongValue], [aValue doubleValue], stop); | 6788 block([aKey unsignedLongLongValue], [aValue doubleValue], stop); |
6827 }]; | 6789 }]; |
6828 } | 6790 } |
6829 | 6791 |
6830 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 6792 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
6831 NSUInteger count = _dictionary.count; | 6793 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6869 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | 6831 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); |
6870 }]; | 6832 }]; |
6871 } | 6833 } |
6872 | 6834 |
6873 - (void)setGPBGenericValue:(GPBGenericValue *)value | 6835 - (void)setGPBGenericValue:(GPBGenericValue *)value |
6874 forGPBGenericValueKey:(GPBGenericValue *)key { | 6836 forGPBGenericValueKey:(GPBGenericValue *)key { |
6875 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)]; | 6837 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)]; |
6876 } | 6838 } |
6877 | 6839 |
6878 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 6840 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
6879 [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, BOOL *st
op) { | 6841 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, double value, BOOL *sto
p) { |
6880 #pragma unused(stop) | 6842 #pragma unused(stop) |
6881 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%.*lg", DBL_DIG, value]); | 6843 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%.*lg", DBL_DIG, value]); |
6882 }]; | 6844 }]; |
6883 } | 6845 } |
6884 | 6846 |
6885 - (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key { | 6847 - (BOOL)valueForKey:(uint64_t)key value:(double *)value { |
6886 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 6848 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
6887 if (wrapped && value) { | 6849 if (wrapped && value) { |
6888 *value = [wrapped doubleValue]; | 6850 *value = [wrapped doubleValue]; |
6889 } | 6851 } |
6890 return (wrapped != NULL); | 6852 return (wrapped != NULL); |
6891 } | 6853 } |
6892 | 6854 |
6893 - (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary { | 6855 - (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary { |
6894 if (otherDictionary) { | 6856 if (otherDictionary) { |
6895 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 6857 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
6896 if (_autocreator) { | 6858 if (_autocreator) { |
6897 GPBAutocreatedDictionaryModified(_autocreator, self); | 6859 GPBAutocreatedDictionaryModified(_autocreator, self); |
6898 } | 6860 } |
6899 } | 6861 } |
6900 } | 6862 } |
6901 | 6863 |
6902 - (void)setDouble:(double)value forKey:(uint64_t)key { | 6864 - (void)setValue:(double)value forKey:(uint64_t)key { |
6903 [_dictionary setObject:@(value) forKey:@(key)]; | 6865 [_dictionary setObject:@(value) forKey:@(key)]; |
6904 if (_autocreator) { | 6866 if (_autocreator) { |
6905 GPBAutocreatedDictionaryModified(_autocreator, self); | 6867 GPBAutocreatedDictionaryModified(_autocreator, self); |
6906 } | 6868 } |
6907 } | 6869 } |
6908 | 6870 |
6909 - (void)removeDoubleForKey:(uint64_t)aKey { | 6871 - (void)removeValueForKey:(uint64_t)aKey { |
6910 [_dictionary removeObjectForKey:@(aKey)]; | 6872 [_dictionary removeObjectForKey:@(aKey)]; |
6911 } | 6873 } |
6912 | 6874 |
6913 - (void)removeAll { | 6875 - (void)removeAll { |
6914 [_dictionary removeAllObjects]; | 6876 [_dictionary removeAllObjects]; |
6915 } | 6877 } |
6916 | 6878 |
6917 @end | 6879 @end |
6918 | 6880 |
6919 #pragma mark - UInt64 -> Enum | 6881 #pragma mark - UInt64 -> Enum |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7023 @"%@: Autocreator must be cleared before release, autocreator: %@", | 6985 @"%@: Autocreator must be cleared before release, autocreator: %@", |
7024 [self class], _autocreator); | 6986 [self class], _autocreator); |
7025 [_dictionary release]; | 6987 [_dictionary release]; |
7026 [super dealloc]; | 6988 [super dealloc]; |
7027 } | 6989 } |
7028 | 6990 |
7029 - (instancetype)copyWithZone:(NSZone *)zone { | 6991 - (instancetype)copyWithZone:(NSZone *)zone { |
7030 return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; | 6992 return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; |
7031 } | 6993 } |
7032 | 6994 |
7033 - (BOOL)isEqual:(id)other { | 6995 - (BOOL)isEqual:(GPBUInt64EnumDictionary *)other { |
7034 if (self == other) { | 6996 if (self == other) { |
7035 return YES; | 6997 return YES; |
7036 } | 6998 } |
7037 if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) { | 6999 if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) { |
7038 return NO; | 7000 return NO; |
7039 } | 7001 } |
7040 GPBUInt64EnumDictionary *otherDictionary = other; | 7002 return [_dictionary isEqual:other->_dictionary]; |
7041 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
7042 } | 7003 } |
7043 | 7004 |
7044 - (NSUInteger)hash { | 7005 - (NSUInteger)hash { |
7045 return _dictionary.count; | 7006 return _dictionary.count; |
7046 } | 7007 } |
7047 | 7008 |
7048 - (NSString *)description { | 7009 - (NSString *)description { |
7049 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 7010 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
7050 } | 7011 } |
7051 | 7012 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7122 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)]; | 7083 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)]; |
7123 } | 7084 } |
7124 | 7085 |
7125 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 7086 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
7126 [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL
*stop) { | 7087 [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL
*stop) { |
7127 #pragma unused(stop) | 7088 #pragma unused(stop) |
7128 block([NSString stringWithFormat:@"%llu", key], @(value)); | 7089 block([NSString stringWithFormat:@"%llu", key], @(value)); |
7129 }]; | 7090 }]; |
7130 } | 7091 } |
7131 | 7092 |
7132 - (BOOL)getEnum:(int32_t *)value forKey:(uint64_t)key { | 7093 - (BOOL)valueForKey:(uint64_t)key value:(int32_t *)value { |
7133 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 7094 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
7134 if (wrapped && value) { | 7095 if (wrapped && value) { |
7135 int32_t result = [wrapped intValue]; | 7096 int32_t result = [wrapped intValue]; |
7136 if (!_validationFunc(result)) { | 7097 if (!_validationFunc(result)) { |
7137 result = kGPBUnrecognizedEnumeratorValue; | 7098 result = kGPBUnrecognizedEnumeratorValue; |
7138 } | 7099 } |
7139 *value = result; | 7100 *value = result; |
7140 } | 7101 } |
7141 return (wrapped != NULL); | 7102 return (wrapped != NULL); |
7142 } | 7103 } |
7143 | 7104 |
7144 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint64_t)key { | 7105 - (BOOL)valueForKey:(uint64_t)key rawValue:(int32_t *)rawValue { |
7145 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 7106 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
7146 if (wrapped && rawValue) { | 7107 if (wrapped && rawValue) { |
7147 *rawValue = [wrapped intValue]; | 7108 *rawValue = [wrapped intValue]; |
7148 } | 7109 } |
7149 return (wrapped != NULL); | 7110 return (wrapped != NULL); |
7150 } | 7111 } |
7151 | 7112 |
7152 - (void)enumerateKeysAndEnumsUsingBlock: | 7113 - (void)enumerateKeysAndValuesUsingBlock: |
7153 (void (^)(uint64_t key, int32_t value, BOOL *stop))block { | 7114 (void (^)(uint64_t key, int32_t value, BOOL *stop))block { |
7154 GPBEnumValidationFunc func = _validationFunc; | 7115 GPBEnumValidationFunc func = _validationFunc; |
7155 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 7116 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
7156 NSNumber *aValue, | 7117 NSNumber *aValue, |
7157 BOOL *stop) { | 7118 BOOL *stop) { |
7158 int32_t unwrapped = [aValue intValue]; | 7119 int32_t unwrapped = [aValue intValue]; |
7159 if (!func(unwrapped)) { | 7120 if (!func(unwrapped)) { |
7160 unwrapped = kGPBUnrecognizedEnumeratorValue; | 7121 unwrapped = kGPBUnrecognizedEnumeratorValue; |
7161 } | 7122 } |
7162 block([aKey unsignedLongLongValue], unwrapped, stop); | 7123 block([aKey unsignedLongLongValue], unwrapped, stop); |
7163 }]; | 7124 }]; |
7164 } | 7125 } |
7165 | 7126 |
7166 - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary { | 7127 - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary { |
7167 if (otherDictionary) { | 7128 if (otherDictionary) { |
7168 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 7129 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
7169 if (_autocreator) { | 7130 if (_autocreator) { |
7170 GPBAutocreatedDictionaryModified(_autocreator, self); | 7131 GPBAutocreatedDictionaryModified(_autocreator, self); |
7171 } | 7132 } |
7172 } | 7133 } |
7173 } | 7134 } |
7174 | 7135 |
7175 - (void)setRawValue:(int32_t)value forKey:(uint64_t)key { | 7136 - (void)setRawValue:(int32_t)value forKey:(uint64_t)key { |
7176 [_dictionary setObject:@(value) forKey:@(key)]; | 7137 [_dictionary setObject:@(value) forKey:@(key)]; |
7177 if (_autocreator) { | 7138 if (_autocreator) { |
7178 GPBAutocreatedDictionaryModified(_autocreator, self); | 7139 GPBAutocreatedDictionaryModified(_autocreator, self); |
7179 } | 7140 } |
7180 } | 7141 } |
7181 | 7142 |
7182 - (void)removeEnumForKey:(uint64_t)aKey { | 7143 - (void)removeValueForKey:(uint64_t)aKey { |
7183 [_dictionary removeObjectForKey:@(aKey)]; | 7144 [_dictionary removeObjectForKey:@(aKey)]; |
7184 } | 7145 } |
7185 | 7146 |
7186 - (void)removeAll { | 7147 - (void)removeAll { |
7187 [_dictionary removeAllObjects]; | 7148 [_dictionary removeAllObjects]; |
7188 } | 7149 } |
7189 | 7150 |
7190 - (void)setEnum:(int32_t)value forKey:(uint64_t)key { | 7151 - (void)setValue:(int32_t)value forKey:(uint64_t)key { |
7191 if (!_validationFunc(value)) { | 7152 if (!_validationFunc(value)) { |
7192 [NSException raise:NSInvalidArgumentException | 7153 [NSException raise:NSInvalidArgumentException |
7193 format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum
value (%d)", | 7154 format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum
value (%d)", |
7194 value]; | 7155 value]; |
7195 } | 7156 } |
7196 | 7157 |
7197 [_dictionary setObject:@(value) forKey:@(key)]; | 7158 [_dictionary setObject:@(value) forKey:@(key)]; |
7198 if (_autocreator) { | 7159 if (_autocreator) { |
7199 GPBAutocreatedDictionaryModified(_autocreator, self); | 7160 GPBAutocreatedDictionaryModified(_autocreator, self); |
7200 } | 7161 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7285 @"%@: Autocreator must be cleared before release, autocreator: %@", | 7246 @"%@: Autocreator must be cleared before release, autocreator: %@", |
7286 [self class], _autocreator); | 7247 [self class], _autocreator); |
7287 [_dictionary release]; | 7248 [_dictionary release]; |
7288 [super dealloc]; | 7249 [super dealloc]; |
7289 } | 7250 } |
7290 | 7251 |
7291 - (instancetype)copyWithZone:(NSZone *)zone { | 7252 - (instancetype)copyWithZone:(NSZone *)zone { |
7292 return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self
]; | 7253 return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self
]; |
7293 } | 7254 } |
7294 | 7255 |
7295 - (BOOL)isEqual:(id)other { | 7256 - (BOOL)isEqual:(GPBUInt64ObjectDictionary *)other { |
7296 if (self == other) { | 7257 if (self == other) { |
7297 return YES; | 7258 return YES; |
7298 } | 7259 } |
7299 if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) { | 7260 if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) { |
7300 return NO; | 7261 return NO; |
7301 } | 7262 } |
7302 GPBUInt64ObjectDictionary *otherDictionary = other; | 7263 return [_dictionary isEqual:other->_dictionary]; |
7303 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
7304 } | 7264 } |
7305 | 7265 |
7306 - (NSUInteger)hash { | 7266 - (NSUInteger)hash { |
7307 return _dictionary.count; | 7267 return _dictionary.count; |
7308 } | 7268 } |
7309 | 7269 |
7310 - (NSString *)description { | 7270 - (NSString *)description { |
7311 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 7271 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
7312 } | 7272 } |
7313 | 7273 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7441 // This block of code is generated, do not edit it directly. | 7401 // This block of code is generated, do not edit it directly. |
7442 | 7402 |
7443 #pragma mark - Int64 -> UInt32 | 7403 #pragma mark - Int64 -> UInt32 |
7444 | 7404 |
7445 @implementation GPBInt64UInt32Dictionary { | 7405 @implementation GPBInt64UInt32Dictionary { |
7446 @package | 7406 @package |
7447 NSMutableDictionary *_dictionary; | 7407 NSMutableDictionary *_dictionary; |
7448 } | 7408 } |
7449 | 7409 |
7450 + (instancetype)dictionary { | 7410 + (instancetype)dictionary { |
7451 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; | 7411 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
7452 } | 7412 } |
7453 | 7413 |
7454 + (instancetype)dictionaryWithUInt32:(uint32_t)value | 7414 + (instancetype)dictionaryWithValue:(uint32_t)value |
7455 forKey:(int64_t)key { | 7415 forKey:(int64_t)key { |
7456 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 7416 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
7457 // on to get the type correct. | 7417 // on to get the type correct. |
7458 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithUInt32s:&value | 7418 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithValues:&value |
7459 forKeys:&key | 7419 forKeys:&key |
7460 count:1] autoreleas
e]; | 7420 count:1] autorelease
]; |
7461 } | 7421 } |
7462 | 7422 |
7463 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values | 7423 + (instancetype)dictionaryWithValues:(const uint32_t [])values |
7464 forKeys:(const int64_t [])keys | 7424 forKeys:(const int64_t [])keys |
7465 count:(NSUInteger)count { | 7425 count:(NSUInteger)count { |
7466 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 7426 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
7467 // on to get the type correct. | 7427 // on to get the type correct. |
7468 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithUInt32s:values | 7428 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithValues:values |
7469 forKeys:keys | 7429 forKeys:keys |
7470 count:count] autorel
ease]; | 7430 count:count] autorel
ease]; |
7471 } | 7431 } |
7472 | 7432 |
7473 + (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary
{ | 7433 + (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary
{ |
7474 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 7434 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
7475 // on to get the type correct. | 7435 // on to get the type correct. |
7476 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 7436 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
7477 } | 7437 } |
7478 | 7438 |
7479 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 7439 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
7480 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 7440 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
7481 } | 7441 } |
7482 | 7442 |
7483 - (instancetype)init { | 7443 - (instancetype)init { |
7484 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 7444 return [self initWithValues:NULL forKeys:NULL count:0]; |
7485 } | 7445 } |
7486 | 7446 |
7487 - (instancetype)initWithUInt32s:(const uint32_t [])values | 7447 - (instancetype)initWithValues:(const uint32_t [])values |
7488 forKeys:(const int64_t [])keys | 7448 forKeys:(const int64_t [])keys |
7489 count:(NSUInteger)count { | 7449 count:(NSUInteger)count { |
7490 self = [super init]; | 7450 self = [super init]; |
7491 if (self) { | 7451 if (self) { |
7492 _dictionary = [[NSMutableDictionary alloc] init]; | 7452 _dictionary = [[NSMutableDictionary alloc] init]; |
7493 if (count && values && keys) { | 7453 if (count && values && keys) { |
7494 for (NSUInteger i = 0; i < count; ++i) { | 7454 for (NSUInteger i = 0; i < count; ++i) { |
7495 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 7455 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
7496 } | 7456 } |
7497 } | 7457 } |
7498 } | 7458 } |
7499 return self; | 7459 return self; |
7500 } | 7460 } |
7501 | 7461 |
7502 - (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary { | 7462 - (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary { |
7503 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; | 7463 self = [self initWithValues:NULL forKeys:NULL count:0]; |
7504 if (self) { | 7464 if (self) { |
7505 if (dictionary) { | 7465 if (dictionary) { |
7506 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 7466 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
7507 } | 7467 } |
7508 } | 7468 } |
7509 return self; | 7469 return self; |
7510 } | 7470 } |
7511 | 7471 |
7512 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 7472 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
7513 #pragma unused(numItems) | 7473 #pragma unused(numItems) |
7514 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 7474 return [self initWithValues:NULL forKeys:NULL count:0]; |
7515 } | 7475 } |
7516 | 7476 |
7517 - (void)dealloc { | 7477 - (void)dealloc { |
7518 NSAssert(!_autocreator, | 7478 NSAssert(!_autocreator, |
7519 @"%@: Autocreator must be cleared before release, autocreator: %@", | 7479 @"%@: Autocreator must be cleared before release, autocreator: %@", |
7520 [self class], _autocreator); | 7480 [self class], _autocreator); |
7521 [_dictionary release]; | 7481 [_dictionary release]; |
7522 [super dealloc]; | 7482 [super dealloc]; |
7523 } | 7483 } |
7524 | 7484 |
7525 - (instancetype)copyWithZone:(NSZone *)zone { | 7485 - (instancetype)copyWithZone:(NSZone *)zone { |
7526 return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; | 7486 return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; |
7527 } | 7487 } |
7528 | 7488 |
7529 - (BOOL)isEqual:(id)other { | 7489 - (BOOL)isEqual:(GPBInt64UInt32Dictionary *)other { |
7530 if (self == other) { | 7490 if (self == other) { |
7531 return YES; | 7491 return YES; |
7532 } | 7492 } |
7533 if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) { | 7493 if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) { |
7534 return NO; | 7494 return NO; |
7535 } | 7495 } |
7536 GPBInt64UInt32Dictionary *otherDictionary = other; | 7496 return [_dictionary isEqual:other->_dictionary]; |
7537 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
7538 } | 7497 } |
7539 | 7498 |
7540 - (NSUInteger)hash { | 7499 - (NSUInteger)hash { |
7541 return _dictionary.count; | 7500 return _dictionary.count; |
7542 } | 7501 } |
7543 | 7502 |
7544 - (NSString *)description { | 7503 - (NSString *)description { |
7545 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 7504 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
7546 } | 7505 } |
7547 | 7506 |
7548 - (NSUInteger)count { | 7507 - (NSUInteger)count { |
7549 return _dictionary.count; | 7508 return _dictionary.count; |
7550 } | 7509 } |
7551 | 7510 |
7552 - (void)enumerateKeysAndUInt32sUsingBlock: | 7511 - (void)enumerateKeysAndValuesUsingBlock: |
7553 (void (^)(int64_t key, uint32_t value, BOOL *stop))block { | 7512 (void (^)(int64_t key, uint32_t value, BOOL *stop))block { |
7554 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 7513 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
7555 NSNumber *aValue, | 7514 NSNumber *aValue, |
7556 BOOL *stop) { | 7515 BOOL *stop) { |
7557 block([aKey longLongValue], [aValue unsignedIntValue], stop); | 7516 block([aKey longLongValue], [aValue unsignedIntValue], stop); |
7558 }]; | 7517 }]; |
7559 } | 7518 } |
7560 | 7519 |
7561 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 7520 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
7562 NSUInteger count = _dictionary.count; | 7521 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7600 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | 7559 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); |
7601 }]; | 7560 }]; |
7602 } | 7561 } |
7603 | 7562 |
7604 - (void)setGPBGenericValue:(GPBGenericValue *)value | 7563 - (void)setGPBGenericValue:(GPBGenericValue *)value |
7605 forGPBGenericValueKey:(GPBGenericValue *)key { | 7564 forGPBGenericValueKey:(GPBGenericValue *)key { |
7606 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)]; | 7565 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)]; |
7607 } | 7566 } |
7608 | 7567 |
7609 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 7568 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
7610 [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, BOOL *s
top) { | 7569 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, uint32_t value, BOOL *st
op) { |
7611 #pragma unused(stop) | 7570 #pragma unused(stop) |
7612 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%u", value]); | 7571 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%u", value]); |
7613 }]; | 7572 }]; |
7614 } | 7573 } |
7615 | 7574 |
7616 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key { | 7575 - (BOOL)valueForKey:(int64_t)key value:(uint32_t *)value { |
7617 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 7576 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
7618 if (wrapped && value) { | 7577 if (wrapped && value) { |
7619 *value = [wrapped unsignedIntValue]; | 7578 *value = [wrapped unsignedIntValue]; |
7620 } | 7579 } |
7621 return (wrapped != NULL); | 7580 return (wrapped != NULL); |
7622 } | 7581 } |
7623 | 7582 |
7624 - (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary { | 7583 - (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary { |
7625 if (otherDictionary) { | 7584 if (otherDictionary) { |
7626 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 7585 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
7627 if (_autocreator) { | 7586 if (_autocreator) { |
7628 GPBAutocreatedDictionaryModified(_autocreator, self); | 7587 GPBAutocreatedDictionaryModified(_autocreator, self); |
7629 } | 7588 } |
7630 } | 7589 } |
7631 } | 7590 } |
7632 | 7591 |
7633 - (void)setUInt32:(uint32_t)value forKey:(int64_t)key { | 7592 - (void)setValue:(uint32_t)value forKey:(int64_t)key { |
7634 [_dictionary setObject:@(value) forKey:@(key)]; | 7593 [_dictionary setObject:@(value) forKey:@(key)]; |
7635 if (_autocreator) { | 7594 if (_autocreator) { |
7636 GPBAutocreatedDictionaryModified(_autocreator, self); | 7595 GPBAutocreatedDictionaryModified(_autocreator, self); |
7637 } | 7596 } |
7638 } | 7597 } |
7639 | 7598 |
7640 - (void)removeUInt32ForKey:(int64_t)aKey { | 7599 - (void)removeValueForKey:(int64_t)aKey { |
7641 [_dictionary removeObjectForKey:@(aKey)]; | 7600 [_dictionary removeObjectForKey:@(aKey)]; |
7642 } | 7601 } |
7643 | 7602 |
7644 - (void)removeAll { | 7603 - (void)removeAll { |
7645 [_dictionary removeAllObjects]; | 7604 [_dictionary removeAllObjects]; |
7646 } | 7605 } |
7647 | 7606 |
7648 @end | 7607 @end |
7649 | 7608 |
7650 #pragma mark - Int64 -> Int32 | 7609 #pragma mark - Int64 -> Int32 |
7651 | 7610 |
7652 @implementation GPBInt64Int32Dictionary { | 7611 @implementation GPBInt64Int32Dictionary { |
7653 @package | 7612 @package |
7654 NSMutableDictionary *_dictionary; | 7613 NSMutableDictionary *_dictionary; |
7655 } | 7614 } |
7656 | 7615 |
7657 + (instancetype)dictionary { | 7616 + (instancetype)dictionary { |
7658 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; | 7617 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
7659 } | 7618 } |
7660 | 7619 |
7661 + (instancetype)dictionaryWithInt32:(int32_t)value | 7620 + (instancetype)dictionaryWithValue:(int32_t)value |
7662 forKey:(int64_t)key { | 7621 forKey:(int64_t)key { |
7663 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 7622 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
7664 // on to get the type correct. | 7623 // on to get the type correct. |
7665 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithInt32s:&value | 7624 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithValues:&value |
7666 forKeys:&key | 7625 forKeys:&key |
7667 count:1] autorelease]
; | 7626 count:1] autorelease]
; |
7668 } | 7627 } |
7669 | 7628 |
7670 + (instancetype)dictionaryWithInt32s:(const int32_t [])values | 7629 + (instancetype)dictionaryWithValues:(const int32_t [])values |
7671 forKeys:(const int64_t [])keys | 7630 forKeys:(const int64_t [])keys |
7672 count:(NSUInteger)count { | 7631 count:(NSUInteger)count { |
7673 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 7632 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
7674 // on to get the type correct. | 7633 // on to get the type correct. |
7675 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithInt32s:values | 7634 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithValues:values |
7676 forKeys:keys | 7635 forKeys:keys |
7677 count:count] autorele
ase]; | 7636 count:count] autorele
ase]; |
7678 } | 7637 } |
7679 | 7638 |
7680 + (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary { | 7639 + (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary { |
7681 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 7640 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
7682 // on to get the type correct. | 7641 // on to get the type correct. |
7683 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 7642 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
7684 } | 7643 } |
7685 | 7644 |
7686 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 7645 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
7687 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 7646 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
7688 } | 7647 } |
7689 | 7648 |
7690 - (instancetype)init { | 7649 - (instancetype)init { |
7691 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 7650 return [self initWithValues:NULL forKeys:NULL count:0]; |
7692 } | 7651 } |
7693 | 7652 |
7694 - (instancetype)initWithInt32s:(const int32_t [])values | 7653 - (instancetype)initWithValues:(const int32_t [])values |
7695 forKeys:(const int64_t [])keys | 7654 forKeys:(const int64_t [])keys |
7696 count:(NSUInteger)count { | 7655 count:(NSUInteger)count { |
7697 self = [super init]; | 7656 self = [super init]; |
7698 if (self) { | 7657 if (self) { |
7699 _dictionary = [[NSMutableDictionary alloc] init]; | 7658 _dictionary = [[NSMutableDictionary alloc] init]; |
7700 if (count && values && keys) { | 7659 if (count && values && keys) { |
7701 for (NSUInteger i = 0; i < count; ++i) { | 7660 for (NSUInteger i = 0; i < count; ++i) { |
7702 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 7661 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
7703 } | 7662 } |
7704 } | 7663 } |
7705 } | 7664 } |
7706 return self; | 7665 return self; |
7707 } | 7666 } |
7708 | 7667 |
7709 - (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary { | 7668 - (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary { |
7710 self = [self initWithInt32s:NULL forKeys:NULL count:0]; | 7669 self = [self initWithValues:NULL forKeys:NULL count:0]; |
7711 if (self) { | 7670 if (self) { |
7712 if (dictionary) { | 7671 if (dictionary) { |
7713 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 7672 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
7714 } | 7673 } |
7715 } | 7674 } |
7716 return self; | 7675 return self; |
7717 } | 7676 } |
7718 | 7677 |
7719 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 7678 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
7720 #pragma unused(numItems) | 7679 #pragma unused(numItems) |
7721 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 7680 return [self initWithValues:NULL forKeys:NULL count:0]; |
7722 } | 7681 } |
7723 | 7682 |
7724 - (void)dealloc { | 7683 - (void)dealloc { |
7725 NSAssert(!_autocreator, | 7684 NSAssert(!_autocreator, |
7726 @"%@: Autocreator must be cleared before release, autocreator: %@", | 7685 @"%@: Autocreator must be cleared before release, autocreator: %@", |
7727 [self class], _autocreator); | 7686 [self class], _autocreator); |
7728 [_dictionary release]; | 7687 [_dictionary release]; |
7729 [super dealloc]; | 7688 [super dealloc]; |
7730 } | 7689 } |
7731 | 7690 |
7732 - (instancetype)copyWithZone:(NSZone *)zone { | 7691 - (instancetype)copyWithZone:(NSZone *)zone { |
7733 return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]; | 7692 return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]; |
7734 } | 7693 } |
7735 | 7694 |
7736 - (BOOL)isEqual:(id)other { | 7695 - (BOOL)isEqual:(GPBInt64Int32Dictionary *)other { |
7737 if (self == other) { | 7696 if (self == other) { |
7738 return YES; | 7697 return YES; |
7739 } | 7698 } |
7740 if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) { | 7699 if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) { |
7741 return NO; | 7700 return NO; |
7742 } | 7701 } |
7743 GPBInt64Int32Dictionary *otherDictionary = other; | 7702 return [_dictionary isEqual:other->_dictionary]; |
7744 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
7745 } | 7703 } |
7746 | 7704 |
7747 - (NSUInteger)hash { | 7705 - (NSUInteger)hash { |
7748 return _dictionary.count; | 7706 return _dictionary.count; |
7749 } | 7707 } |
7750 | 7708 |
7751 - (NSString *)description { | 7709 - (NSString *)description { |
7752 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 7710 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
7753 } | 7711 } |
7754 | 7712 |
7755 - (NSUInteger)count { | 7713 - (NSUInteger)count { |
7756 return _dictionary.count; | 7714 return _dictionary.count; |
7757 } | 7715 } |
7758 | 7716 |
7759 - (void)enumerateKeysAndInt32sUsingBlock: | 7717 - (void)enumerateKeysAndValuesUsingBlock: |
7760 (void (^)(int64_t key, int32_t value, BOOL *stop))block { | 7718 (void (^)(int64_t key, int32_t value, BOOL *stop))block { |
7761 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 7719 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
7762 NSNumber *aValue, | 7720 NSNumber *aValue, |
7763 BOOL *stop) { | 7721 BOOL *stop) { |
7764 block([aKey longLongValue], [aValue intValue], stop); | 7722 block([aKey longLongValue], [aValue intValue], stop); |
7765 }]; | 7723 }]; |
7766 } | 7724 } |
7767 | 7725 |
7768 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 7726 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
7769 NSUInteger count = _dictionary.count; | 7727 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7807 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | 7765 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); |
7808 }]; | 7766 }]; |
7809 } | 7767 } |
7810 | 7768 |
7811 - (void)setGPBGenericValue:(GPBGenericValue *)value | 7769 - (void)setGPBGenericValue:(GPBGenericValue *)value |
7812 forGPBGenericValueKey:(GPBGenericValue *)key { | 7770 forGPBGenericValueKey:(GPBGenericValue *)key { |
7813 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)]; | 7771 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)]; |
7814 } | 7772 } |
7815 | 7773 |
7816 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 7774 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
7817 [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, BOOL *sto
p) { | 7775 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, int32_t value, BOOL *sto
p) { |
7818 #pragma unused(stop) | 7776 #pragma unused(stop) |
7819 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%d", value]); | 7777 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%d", value]); |
7820 }]; | 7778 }]; |
7821 } | 7779 } |
7822 | 7780 |
7823 - (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key { | 7781 - (BOOL)valueForKey:(int64_t)key value:(int32_t *)value { |
7824 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 7782 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
7825 if (wrapped && value) { | 7783 if (wrapped && value) { |
7826 *value = [wrapped intValue]; | 7784 *value = [wrapped intValue]; |
7827 } | 7785 } |
7828 return (wrapped != NULL); | 7786 return (wrapped != NULL); |
7829 } | 7787 } |
7830 | 7788 |
7831 - (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary { | 7789 - (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary { |
7832 if (otherDictionary) { | 7790 if (otherDictionary) { |
7833 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 7791 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
7834 if (_autocreator) { | 7792 if (_autocreator) { |
7835 GPBAutocreatedDictionaryModified(_autocreator, self); | 7793 GPBAutocreatedDictionaryModified(_autocreator, self); |
7836 } | 7794 } |
7837 } | 7795 } |
7838 } | 7796 } |
7839 | 7797 |
7840 - (void)setInt32:(int32_t)value forKey:(int64_t)key { | 7798 - (void)setValue:(int32_t)value forKey:(int64_t)key { |
7841 [_dictionary setObject:@(value) forKey:@(key)]; | 7799 [_dictionary setObject:@(value) forKey:@(key)]; |
7842 if (_autocreator) { | 7800 if (_autocreator) { |
7843 GPBAutocreatedDictionaryModified(_autocreator, self); | 7801 GPBAutocreatedDictionaryModified(_autocreator, self); |
7844 } | 7802 } |
7845 } | 7803 } |
7846 | 7804 |
7847 - (void)removeInt32ForKey:(int64_t)aKey { | 7805 - (void)removeValueForKey:(int64_t)aKey { |
7848 [_dictionary removeObjectForKey:@(aKey)]; | 7806 [_dictionary removeObjectForKey:@(aKey)]; |
7849 } | 7807 } |
7850 | 7808 |
7851 - (void)removeAll { | 7809 - (void)removeAll { |
7852 [_dictionary removeAllObjects]; | 7810 [_dictionary removeAllObjects]; |
7853 } | 7811 } |
7854 | 7812 |
7855 @end | 7813 @end |
7856 | 7814 |
7857 #pragma mark - Int64 -> UInt64 | 7815 #pragma mark - Int64 -> UInt64 |
7858 | 7816 |
7859 @implementation GPBInt64UInt64Dictionary { | 7817 @implementation GPBInt64UInt64Dictionary { |
7860 @package | 7818 @package |
7861 NSMutableDictionary *_dictionary; | 7819 NSMutableDictionary *_dictionary; |
7862 } | 7820 } |
7863 | 7821 |
7864 + (instancetype)dictionary { | 7822 + (instancetype)dictionary { |
7865 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; | 7823 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
7866 } | 7824 } |
7867 | 7825 |
7868 + (instancetype)dictionaryWithUInt64:(uint64_t)value | 7826 + (instancetype)dictionaryWithValue:(uint64_t)value |
7869 forKey:(int64_t)key { | 7827 forKey:(int64_t)key { |
7870 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 7828 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
7871 // on to get the type correct. | 7829 // on to get the type correct. |
7872 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithUInt64s:&value | 7830 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithValues:&value |
7873 forKeys:&key | 7831 forKeys:&key |
7874 count:1] autoreleas
e]; | 7832 count:1] autorelease
]; |
7875 } | 7833 } |
7876 | 7834 |
7877 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values | 7835 + (instancetype)dictionaryWithValues:(const uint64_t [])values |
7878 forKeys:(const int64_t [])keys | 7836 forKeys:(const int64_t [])keys |
7879 count:(NSUInteger)count { | 7837 count:(NSUInteger)count { |
7880 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 7838 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
7881 // on to get the type correct. | 7839 // on to get the type correct. |
7882 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithUInt64s:values | 7840 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithValues:values |
7883 forKeys:keys | 7841 forKeys:keys |
7884 count:count] autorel
ease]; | 7842 count:count] autorel
ease]; |
7885 } | 7843 } |
7886 | 7844 |
7887 + (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary
{ | 7845 + (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary
{ |
7888 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 7846 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
7889 // on to get the type correct. | 7847 // on to get the type correct. |
7890 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 7848 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
7891 } | 7849 } |
7892 | 7850 |
7893 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 7851 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
7894 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 7852 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
7895 } | 7853 } |
7896 | 7854 |
7897 - (instancetype)init { | 7855 - (instancetype)init { |
7898 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 7856 return [self initWithValues:NULL forKeys:NULL count:0]; |
7899 } | 7857 } |
7900 | 7858 |
7901 - (instancetype)initWithUInt64s:(const uint64_t [])values | 7859 - (instancetype)initWithValues:(const uint64_t [])values |
7902 forKeys:(const int64_t [])keys | 7860 forKeys:(const int64_t [])keys |
7903 count:(NSUInteger)count { | 7861 count:(NSUInteger)count { |
7904 self = [super init]; | 7862 self = [super init]; |
7905 if (self) { | 7863 if (self) { |
7906 _dictionary = [[NSMutableDictionary alloc] init]; | 7864 _dictionary = [[NSMutableDictionary alloc] init]; |
7907 if (count && values && keys) { | 7865 if (count && values && keys) { |
7908 for (NSUInteger i = 0; i < count; ++i) { | 7866 for (NSUInteger i = 0; i < count; ++i) { |
7909 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 7867 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
7910 } | 7868 } |
7911 } | 7869 } |
7912 } | 7870 } |
7913 return self; | 7871 return self; |
7914 } | 7872 } |
7915 | 7873 |
7916 - (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary { | 7874 - (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary { |
7917 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; | 7875 self = [self initWithValues:NULL forKeys:NULL count:0]; |
7918 if (self) { | 7876 if (self) { |
7919 if (dictionary) { | 7877 if (dictionary) { |
7920 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 7878 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
7921 } | 7879 } |
7922 } | 7880 } |
7923 return self; | 7881 return self; |
7924 } | 7882 } |
7925 | 7883 |
7926 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 7884 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
7927 #pragma unused(numItems) | 7885 #pragma unused(numItems) |
7928 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 7886 return [self initWithValues:NULL forKeys:NULL count:0]; |
7929 } | 7887 } |
7930 | 7888 |
7931 - (void)dealloc { | 7889 - (void)dealloc { |
7932 NSAssert(!_autocreator, | 7890 NSAssert(!_autocreator, |
7933 @"%@: Autocreator must be cleared before release, autocreator: %@", | 7891 @"%@: Autocreator must be cleared before release, autocreator: %@", |
7934 [self class], _autocreator); | 7892 [self class], _autocreator); |
7935 [_dictionary release]; | 7893 [_dictionary release]; |
7936 [super dealloc]; | 7894 [super dealloc]; |
7937 } | 7895 } |
7938 | 7896 |
7939 - (instancetype)copyWithZone:(NSZone *)zone { | 7897 - (instancetype)copyWithZone:(NSZone *)zone { |
7940 return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; | 7898 return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; |
7941 } | 7899 } |
7942 | 7900 |
7943 - (BOOL)isEqual:(id)other { | 7901 - (BOOL)isEqual:(GPBInt64UInt64Dictionary *)other { |
7944 if (self == other) { | 7902 if (self == other) { |
7945 return YES; | 7903 return YES; |
7946 } | 7904 } |
7947 if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) { | 7905 if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) { |
7948 return NO; | 7906 return NO; |
7949 } | 7907 } |
7950 GPBInt64UInt64Dictionary *otherDictionary = other; | 7908 return [_dictionary isEqual:other->_dictionary]; |
7951 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
7952 } | 7909 } |
7953 | 7910 |
7954 - (NSUInteger)hash { | 7911 - (NSUInteger)hash { |
7955 return _dictionary.count; | 7912 return _dictionary.count; |
7956 } | 7913 } |
7957 | 7914 |
7958 - (NSString *)description { | 7915 - (NSString *)description { |
7959 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 7916 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
7960 } | 7917 } |
7961 | 7918 |
7962 - (NSUInteger)count { | 7919 - (NSUInteger)count { |
7963 return _dictionary.count; | 7920 return _dictionary.count; |
7964 } | 7921 } |
7965 | 7922 |
7966 - (void)enumerateKeysAndUInt64sUsingBlock: | 7923 - (void)enumerateKeysAndValuesUsingBlock: |
7967 (void (^)(int64_t key, uint64_t value, BOOL *stop))block { | 7924 (void (^)(int64_t key, uint64_t value, BOOL *stop))block { |
7968 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 7925 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
7969 NSNumber *aValue, | 7926 NSNumber *aValue, |
7970 BOOL *stop) { | 7927 BOOL *stop) { |
7971 block([aKey longLongValue], [aValue unsignedLongLongValue], stop); | 7928 block([aKey longLongValue], [aValue unsignedLongLongValue], stop); |
7972 }]; | 7929 }]; |
7973 } | 7930 } |
7974 | 7931 |
7975 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 7932 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
7976 NSUInteger count = _dictionary.count; | 7933 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8014 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | 7971 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); |
8015 }]; | 7972 }]; |
8016 } | 7973 } |
8017 | 7974 |
8018 - (void)setGPBGenericValue:(GPBGenericValue *)value | 7975 - (void)setGPBGenericValue:(GPBGenericValue *)value |
8019 forGPBGenericValueKey:(GPBGenericValue *)key { | 7976 forGPBGenericValueKey:(GPBGenericValue *)key { |
8020 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)]; | 7977 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)]; |
8021 } | 7978 } |
8022 | 7979 |
8023 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 7980 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
8024 [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, BOOL *s
top) { | 7981 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, uint64_t value, BOOL *st
op) { |
8025 #pragma unused(stop) | 7982 #pragma unused(stop) |
8026 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%llu", value]); | 7983 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%llu", value]); |
8027 }]; | 7984 }]; |
8028 } | 7985 } |
8029 | 7986 |
8030 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key { | 7987 - (BOOL)valueForKey:(int64_t)key value:(uint64_t *)value { |
8031 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 7988 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
8032 if (wrapped && value) { | 7989 if (wrapped && value) { |
8033 *value = [wrapped unsignedLongLongValue]; | 7990 *value = [wrapped unsignedLongLongValue]; |
8034 } | 7991 } |
8035 return (wrapped != NULL); | 7992 return (wrapped != NULL); |
8036 } | 7993 } |
8037 | 7994 |
8038 - (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary { | 7995 - (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary { |
8039 if (otherDictionary) { | 7996 if (otherDictionary) { |
8040 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 7997 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
8041 if (_autocreator) { | 7998 if (_autocreator) { |
8042 GPBAutocreatedDictionaryModified(_autocreator, self); | 7999 GPBAutocreatedDictionaryModified(_autocreator, self); |
8043 } | 8000 } |
8044 } | 8001 } |
8045 } | 8002 } |
8046 | 8003 |
8047 - (void)setUInt64:(uint64_t)value forKey:(int64_t)key { | 8004 - (void)setValue:(uint64_t)value forKey:(int64_t)key { |
8048 [_dictionary setObject:@(value) forKey:@(key)]; | 8005 [_dictionary setObject:@(value) forKey:@(key)]; |
8049 if (_autocreator) { | 8006 if (_autocreator) { |
8050 GPBAutocreatedDictionaryModified(_autocreator, self); | 8007 GPBAutocreatedDictionaryModified(_autocreator, self); |
8051 } | 8008 } |
8052 } | 8009 } |
8053 | 8010 |
8054 - (void)removeUInt64ForKey:(int64_t)aKey { | 8011 - (void)removeValueForKey:(int64_t)aKey { |
8055 [_dictionary removeObjectForKey:@(aKey)]; | 8012 [_dictionary removeObjectForKey:@(aKey)]; |
8056 } | 8013 } |
8057 | 8014 |
8058 - (void)removeAll { | 8015 - (void)removeAll { |
8059 [_dictionary removeAllObjects]; | 8016 [_dictionary removeAllObjects]; |
8060 } | 8017 } |
8061 | 8018 |
8062 @end | 8019 @end |
8063 | 8020 |
8064 #pragma mark - Int64 -> Int64 | 8021 #pragma mark - Int64 -> Int64 |
8065 | 8022 |
8066 @implementation GPBInt64Int64Dictionary { | 8023 @implementation GPBInt64Int64Dictionary { |
8067 @package | 8024 @package |
8068 NSMutableDictionary *_dictionary; | 8025 NSMutableDictionary *_dictionary; |
8069 } | 8026 } |
8070 | 8027 |
8071 + (instancetype)dictionary { | 8028 + (instancetype)dictionary { |
8072 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; | 8029 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
8073 } | 8030 } |
8074 | 8031 |
8075 + (instancetype)dictionaryWithInt64:(int64_t)value | 8032 + (instancetype)dictionaryWithValue:(int64_t)value |
8076 forKey:(int64_t)key { | 8033 forKey:(int64_t)key { |
8077 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 8034 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
8078 // on to get the type correct. | 8035 // on to get the type correct. |
8079 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithInt64s:&value | 8036 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithValues:&value |
8080 forKeys:&key | 8037 forKeys:&key |
8081 count:1] autorelease]
; | 8038 count:1] autorelease]
; |
8082 } | 8039 } |
8083 | 8040 |
8084 + (instancetype)dictionaryWithInt64s:(const int64_t [])values | 8041 + (instancetype)dictionaryWithValues:(const int64_t [])values |
8085 forKeys:(const int64_t [])keys | 8042 forKeys:(const int64_t [])keys |
8086 count:(NSUInteger)count { | 8043 count:(NSUInteger)count { |
8087 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 8044 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
8088 // on to get the type correct. | 8045 // on to get the type correct. |
8089 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithInt64s:values | 8046 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithValues:values |
8090 forKeys:keys | 8047 forKeys:keys |
8091 count:count] autorele
ase]; | 8048 count:count] autorele
ase]; |
8092 } | 8049 } |
8093 | 8050 |
8094 + (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary { | 8051 + (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary { |
8095 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 8052 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
8096 // on to get the type correct. | 8053 // on to get the type correct. |
8097 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 8054 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
8098 } | 8055 } |
8099 | 8056 |
8100 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 8057 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
8101 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 8058 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
8102 } | 8059 } |
8103 | 8060 |
8104 - (instancetype)init { | 8061 - (instancetype)init { |
8105 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 8062 return [self initWithValues:NULL forKeys:NULL count:0]; |
8106 } | 8063 } |
8107 | 8064 |
8108 - (instancetype)initWithInt64s:(const int64_t [])values | 8065 - (instancetype)initWithValues:(const int64_t [])values |
8109 forKeys:(const int64_t [])keys | 8066 forKeys:(const int64_t [])keys |
8110 count:(NSUInteger)count { | 8067 count:(NSUInteger)count { |
8111 self = [super init]; | 8068 self = [super init]; |
8112 if (self) { | 8069 if (self) { |
8113 _dictionary = [[NSMutableDictionary alloc] init]; | 8070 _dictionary = [[NSMutableDictionary alloc] init]; |
8114 if (count && values && keys) { | 8071 if (count && values && keys) { |
8115 for (NSUInteger i = 0; i < count; ++i) { | 8072 for (NSUInteger i = 0; i < count; ++i) { |
8116 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 8073 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
8117 } | 8074 } |
8118 } | 8075 } |
8119 } | 8076 } |
8120 return self; | 8077 return self; |
8121 } | 8078 } |
8122 | 8079 |
8123 - (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary { | 8080 - (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary { |
8124 self = [self initWithInt64s:NULL forKeys:NULL count:0]; | 8081 self = [self initWithValues:NULL forKeys:NULL count:0]; |
8125 if (self) { | 8082 if (self) { |
8126 if (dictionary) { | 8083 if (dictionary) { |
8127 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 8084 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
8128 } | 8085 } |
8129 } | 8086 } |
8130 return self; | 8087 return self; |
8131 } | 8088 } |
8132 | 8089 |
8133 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 8090 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
8134 #pragma unused(numItems) | 8091 #pragma unused(numItems) |
8135 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 8092 return [self initWithValues:NULL forKeys:NULL count:0]; |
8136 } | 8093 } |
8137 | 8094 |
8138 - (void)dealloc { | 8095 - (void)dealloc { |
8139 NSAssert(!_autocreator, | 8096 NSAssert(!_autocreator, |
8140 @"%@: Autocreator must be cleared before release, autocreator: %@", | 8097 @"%@: Autocreator must be cleared before release, autocreator: %@", |
8141 [self class], _autocreator); | 8098 [self class], _autocreator); |
8142 [_dictionary release]; | 8099 [_dictionary release]; |
8143 [super dealloc]; | 8100 [super dealloc]; |
8144 } | 8101 } |
8145 | 8102 |
8146 - (instancetype)copyWithZone:(NSZone *)zone { | 8103 - (instancetype)copyWithZone:(NSZone *)zone { |
8147 return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]; | 8104 return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]; |
8148 } | 8105 } |
8149 | 8106 |
8150 - (BOOL)isEqual:(id)other { | 8107 - (BOOL)isEqual:(GPBInt64Int64Dictionary *)other { |
8151 if (self == other) { | 8108 if (self == other) { |
8152 return YES; | 8109 return YES; |
8153 } | 8110 } |
8154 if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) { | 8111 if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) { |
8155 return NO; | 8112 return NO; |
8156 } | 8113 } |
8157 GPBInt64Int64Dictionary *otherDictionary = other; | 8114 return [_dictionary isEqual:other->_dictionary]; |
8158 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
8159 } | 8115 } |
8160 | 8116 |
8161 - (NSUInteger)hash { | 8117 - (NSUInteger)hash { |
8162 return _dictionary.count; | 8118 return _dictionary.count; |
8163 } | 8119 } |
8164 | 8120 |
8165 - (NSString *)description { | 8121 - (NSString *)description { |
8166 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 8122 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
8167 } | 8123 } |
8168 | 8124 |
8169 - (NSUInteger)count { | 8125 - (NSUInteger)count { |
8170 return _dictionary.count; | 8126 return _dictionary.count; |
8171 } | 8127 } |
8172 | 8128 |
8173 - (void)enumerateKeysAndInt64sUsingBlock: | 8129 - (void)enumerateKeysAndValuesUsingBlock: |
8174 (void (^)(int64_t key, int64_t value, BOOL *stop))block { | 8130 (void (^)(int64_t key, int64_t value, BOOL *stop))block { |
8175 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 8131 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
8176 NSNumber *aValue, | 8132 NSNumber *aValue, |
8177 BOOL *stop) { | 8133 BOOL *stop) { |
8178 block([aKey longLongValue], [aValue longLongValue], stop); | 8134 block([aKey longLongValue], [aValue longLongValue], stop); |
8179 }]; | 8135 }]; |
8180 } | 8136 } |
8181 | 8137 |
8182 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 8138 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
8183 NSUInteger count = _dictionary.count; | 8139 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8221 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | 8177 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); |
8222 }]; | 8178 }]; |
8223 } | 8179 } |
8224 | 8180 |
8225 - (void)setGPBGenericValue:(GPBGenericValue *)value | 8181 - (void)setGPBGenericValue:(GPBGenericValue *)value |
8226 forGPBGenericValueKey:(GPBGenericValue *)key { | 8182 forGPBGenericValueKey:(GPBGenericValue *)key { |
8227 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)]; | 8183 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)]; |
8228 } | 8184 } |
8229 | 8185 |
8230 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 8186 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
8231 [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, BOOL *sto
p) { | 8187 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, int64_t value, BOOL *sto
p) { |
8232 #pragma unused(stop) | 8188 #pragma unused(stop) |
8233 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%lld", value]); | 8189 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%lld", value]); |
8234 }]; | 8190 }]; |
8235 } | 8191 } |
8236 | 8192 |
8237 - (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key { | 8193 - (BOOL)valueForKey:(int64_t)key value:(int64_t *)value { |
8238 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 8194 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
8239 if (wrapped && value) { | 8195 if (wrapped && value) { |
8240 *value = [wrapped longLongValue]; | 8196 *value = [wrapped longLongValue]; |
8241 } | 8197 } |
8242 return (wrapped != NULL); | 8198 return (wrapped != NULL); |
8243 } | 8199 } |
8244 | 8200 |
8245 - (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary { | 8201 - (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary { |
8246 if (otherDictionary) { | 8202 if (otherDictionary) { |
8247 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 8203 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
8248 if (_autocreator) { | 8204 if (_autocreator) { |
8249 GPBAutocreatedDictionaryModified(_autocreator, self); | 8205 GPBAutocreatedDictionaryModified(_autocreator, self); |
8250 } | 8206 } |
8251 } | 8207 } |
8252 } | 8208 } |
8253 | 8209 |
8254 - (void)setInt64:(int64_t)value forKey:(int64_t)key { | 8210 - (void)setValue:(int64_t)value forKey:(int64_t)key { |
8255 [_dictionary setObject:@(value) forKey:@(key)]; | 8211 [_dictionary setObject:@(value) forKey:@(key)]; |
8256 if (_autocreator) { | 8212 if (_autocreator) { |
8257 GPBAutocreatedDictionaryModified(_autocreator, self); | 8213 GPBAutocreatedDictionaryModified(_autocreator, self); |
8258 } | 8214 } |
8259 } | 8215 } |
8260 | 8216 |
8261 - (void)removeInt64ForKey:(int64_t)aKey { | 8217 - (void)removeValueForKey:(int64_t)aKey { |
8262 [_dictionary removeObjectForKey:@(aKey)]; | 8218 [_dictionary removeObjectForKey:@(aKey)]; |
8263 } | 8219 } |
8264 | 8220 |
8265 - (void)removeAll { | 8221 - (void)removeAll { |
8266 [_dictionary removeAllObjects]; | 8222 [_dictionary removeAllObjects]; |
8267 } | 8223 } |
8268 | 8224 |
8269 @end | 8225 @end |
8270 | 8226 |
8271 #pragma mark - Int64 -> Bool | 8227 #pragma mark - Int64 -> Bool |
8272 | 8228 |
8273 @implementation GPBInt64BoolDictionary { | 8229 @implementation GPBInt64BoolDictionary { |
8274 @package | 8230 @package |
8275 NSMutableDictionary *_dictionary; | 8231 NSMutableDictionary *_dictionary; |
8276 } | 8232 } |
8277 | 8233 |
8278 + (instancetype)dictionary { | 8234 + (instancetype)dictionary { |
8279 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; | 8235 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
8280 } | 8236 } |
8281 | 8237 |
8282 + (instancetype)dictionaryWithBool:(BOOL)value | 8238 + (instancetype)dictionaryWithValue:(BOOL)value |
8283 forKey:(int64_t)key { | 8239 forKey:(int64_t)key { |
8284 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 8240 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
8285 // on to get the type correct. | 8241 // on to get the type correct. |
8286 return [[(GPBInt64BoolDictionary*)[self alloc] initWithBools:&value | 8242 return [[(GPBInt64BoolDictionary*)[self alloc] initWithValues:&value |
8287 forKeys:&key | 8243 forKeys:&key |
8288 count:1] autorelease]; | 8244 count:1] autorelease]; |
8289 } | 8245 } |
8290 | 8246 |
8291 + (instancetype)dictionaryWithBools:(const BOOL [])values | 8247 + (instancetype)dictionaryWithValues:(const BOOL [])values |
8292 forKeys:(const int64_t [])keys | 8248 forKeys:(const int64_t [])keys |
8293 count:(NSUInteger)count { | 8249 count:(NSUInteger)count { |
8294 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 8250 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
8295 // on to get the type correct. | 8251 // on to get the type correct. |
8296 return [[(GPBInt64BoolDictionary*)[self alloc] initWithBools:values | 8252 return [[(GPBInt64BoolDictionary*)[self alloc] initWithValues:values |
8297 forKeys:keys | 8253 forKeys:keys |
8298 count:count] autorelea
se]; | 8254 count:count] autorelea
se]; |
8299 } | 8255 } |
8300 | 8256 |
8301 + (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary { | 8257 + (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary { |
8302 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 8258 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
8303 // on to get the type correct. | 8259 // on to get the type correct. |
8304 return [[(GPBInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 8260 return [[(GPBInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
8305 } | 8261 } |
8306 | 8262 |
8307 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 8263 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
8308 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 8264 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
8309 } | 8265 } |
8310 | 8266 |
8311 - (instancetype)init { | 8267 - (instancetype)init { |
8312 return [self initWithBools:NULL forKeys:NULL count:0]; | 8268 return [self initWithValues:NULL forKeys:NULL count:0]; |
8313 } | 8269 } |
8314 | 8270 |
8315 - (instancetype)initWithBools:(const BOOL [])values | 8271 - (instancetype)initWithValues:(const BOOL [])values |
8316 forKeys:(const int64_t [])keys | 8272 forKeys:(const int64_t [])keys |
8317 count:(NSUInteger)count { | 8273 count:(NSUInteger)count { |
8318 self = [super init]; | 8274 self = [super init]; |
8319 if (self) { | 8275 if (self) { |
8320 _dictionary = [[NSMutableDictionary alloc] init]; | 8276 _dictionary = [[NSMutableDictionary alloc] init]; |
8321 if (count && values && keys) { | 8277 if (count && values && keys) { |
8322 for (NSUInteger i = 0; i < count; ++i) { | 8278 for (NSUInteger i = 0; i < count; ++i) { |
8323 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 8279 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
8324 } | 8280 } |
8325 } | 8281 } |
8326 } | 8282 } |
8327 return self; | 8283 return self; |
8328 } | 8284 } |
8329 | 8285 |
8330 - (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary { | 8286 - (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary { |
8331 self = [self initWithBools:NULL forKeys:NULL count:0]; | 8287 self = [self initWithValues:NULL forKeys:NULL count:0]; |
8332 if (self) { | 8288 if (self) { |
8333 if (dictionary) { | 8289 if (dictionary) { |
8334 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 8290 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
8335 } | 8291 } |
8336 } | 8292 } |
8337 return self; | 8293 return self; |
8338 } | 8294 } |
8339 | 8295 |
8340 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 8296 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
8341 #pragma unused(numItems) | 8297 #pragma unused(numItems) |
8342 return [self initWithBools:NULL forKeys:NULL count:0]; | 8298 return [self initWithValues:NULL forKeys:NULL count:0]; |
8343 } | 8299 } |
8344 | 8300 |
8345 - (void)dealloc { | 8301 - (void)dealloc { |
8346 NSAssert(!_autocreator, | 8302 NSAssert(!_autocreator, |
8347 @"%@: Autocreator must be cleared before release, autocreator: %@", | 8303 @"%@: Autocreator must be cleared before release, autocreator: %@", |
8348 [self class], _autocreator); | 8304 [self class], _autocreator); |
8349 [_dictionary release]; | 8305 [_dictionary release]; |
8350 [super dealloc]; | 8306 [super dealloc]; |
8351 } | 8307 } |
8352 | 8308 |
8353 - (instancetype)copyWithZone:(NSZone *)zone { | 8309 - (instancetype)copyWithZone:(NSZone *)zone { |
8354 return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; | 8310 return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; |
8355 } | 8311 } |
8356 | 8312 |
8357 - (BOOL)isEqual:(id)other { | 8313 - (BOOL)isEqual:(GPBInt64BoolDictionary *)other { |
8358 if (self == other) { | 8314 if (self == other) { |
8359 return YES; | 8315 return YES; |
8360 } | 8316 } |
8361 if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) { | 8317 if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) { |
8362 return NO; | 8318 return NO; |
8363 } | 8319 } |
8364 GPBInt64BoolDictionary *otherDictionary = other; | 8320 return [_dictionary isEqual:other->_dictionary]; |
8365 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
8366 } | 8321 } |
8367 | 8322 |
8368 - (NSUInteger)hash { | 8323 - (NSUInteger)hash { |
8369 return _dictionary.count; | 8324 return _dictionary.count; |
8370 } | 8325 } |
8371 | 8326 |
8372 - (NSString *)description { | 8327 - (NSString *)description { |
8373 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 8328 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
8374 } | 8329 } |
8375 | 8330 |
8376 - (NSUInteger)count { | 8331 - (NSUInteger)count { |
8377 return _dictionary.count; | 8332 return _dictionary.count; |
8378 } | 8333 } |
8379 | 8334 |
8380 - (void)enumerateKeysAndBoolsUsingBlock: | 8335 - (void)enumerateKeysAndValuesUsingBlock: |
8381 (void (^)(int64_t key, BOOL value, BOOL *stop))block { | 8336 (void (^)(int64_t key, BOOL value, BOOL *stop))block { |
8382 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 8337 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
8383 NSNumber *aValue, | 8338 NSNumber *aValue, |
8384 BOOL *stop) { | 8339 BOOL *stop) { |
8385 block([aKey longLongValue], [aValue boolValue], stop); | 8340 block([aKey longLongValue], [aValue boolValue], stop); |
8386 }]; | 8341 }]; |
8387 } | 8342 } |
8388 | 8343 |
8389 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 8344 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
8390 NSUInteger count = _dictionary.count; | 8345 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8428 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | 8383 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); |
8429 }]; | 8384 }]; |
8430 } | 8385 } |
8431 | 8386 |
8432 - (void)setGPBGenericValue:(GPBGenericValue *)value | 8387 - (void)setGPBGenericValue:(GPBGenericValue *)value |
8433 forGPBGenericValueKey:(GPBGenericValue *)key { | 8388 forGPBGenericValueKey:(GPBGenericValue *)key { |
8434 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)]; | 8389 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)]; |
8435 } | 8390 } |
8436 | 8391 |
8437 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 8392 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
8438 [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, BOOL *stop) { | 8393 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, BOOL value, BOOL *stop)
{ |
8439 #pragma unused(stop) | 8394 #pragma unused(stop) |
8440 block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false
")); | 8395 block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false
")); |
8441 }]; | 8396 }]; |
8442 } | 8397 } |
8443 | 8398 |
8444 - (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key { | 8399 - (BOOL)valueForKey:(int64_t)key value:(BOOL *)value { |
8445 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 8400 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
8446 if (wrapped && value) { | 8401 if (wrapped && value) { |
8447 *value = [wrapped boolValue]; | 8402 *value = [wrapped boolValue]; |
8448 } | 8403 } |
8449 return (wrapped != NULL); | 8404 return (wrapped != NULL); |
8450 } | 8405 } |
8451 | 8406 |
8452 - (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary { | 8407 - (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary { |
8453 if (otherDictionary) { | 8408 if (otherDictionary) { |
8454 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 8409 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
8455 if (_autocreator) { | 8410 if (_autocreator) { |
8456 GPBAutocreatedDictionaryModified(_autocreator, self); | 8411 GPBAutocreatedDictionaryModified(_autocreator, self); |
8457 } | 8412 } |
8458 } | 8413 } |
8459 } | 8414 } |
8460 | 8415 |
8461 - (void)setBool:(BOOL)value forKey:(int64_t)key { | 8416 - (void)setValue:(BOOL)value forKey:(int64_t)key { |
8462 [_dictionary setObject:@(value) forKey:@(key)]; | 8417 [_dictionary setObject:@(value) forKey:@(key)]; |
8463 if (_autocreator) { | 8418 if (_autocreator) { |
8464 GPBAutocreatedDictionaryModified(_autocreator, self); | 8419 GPBAutocreatedDictionaryModified(_autocreator, self); |
8465 } | 8420 } |
8466 } | 8421 } |
8467 | 8422 |
8468 - (void)removeBoolForKey:(int64_t)aKey { | 8423 - (void)removeValueForKey:(int64_t)aKey { |
8469 [_dictionary removeObjectForKey:@(aKey)]; | 8424 [_dictionary removeObjectForKey:@(aKey)]; |
8470 } | 8425 } |
8471 | 8426 |
8472 - (void)removeAll { | 8427 - (void)removeAll { |
8473 [_dictionary removeAllObjects]; | 8428 [_dictionary removeAllObjects]; |
8474 } | 8429 } |
8475 | 8430 |
8476 @end | 8431 @end |
8477 | 8432 |
8478 #pragma mark - Int64 -> Float | 8433 #pragma mark - Int64 -> Float |
8479 | 8434 |
8480 @implementation GPBInt64FloatDictionary { | 8435 @implementation GPBInt64FloatDictionary { |
8481 @package | 8436 @package |
8482 NSMutableDictionary *_dictionary; | 8437 NSMutableDictionary *_dictionary; |
8483 } | 8438 } |
8484 | 8439 |
8485 + (instancetype)dictionary { | 8440 + (instancetype)dictionary { |
8486 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; | 8441 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
8487 } | 8442 } |
8488 | 8443 |
8489 + (instancetype)dictionaryWithFloat:(float)value | 8444 + (instancetype)dictionaryWithValue:(float)value |
8490 forKey:(int64_t)key { | 8445 forKey:(int64_t)key { |
8491 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 8446 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
8492 // on to get the type correct. | 8447 // on to get the type correct. |
8493 return [[(GPBInt64FloatDictionary*)[self alloc] initWithFloats:&value | 8448 return [[(GPBInt64FloatDictionary*)[self alloc] initWithValues:&value |
8494 forKeys:&key | 8449 forKeys:&key |
8495 count:1] autorelease]
; | 8450 count:1] autorelease]
; |
8496 } | 8451 } |
8497 | 8452 |
8498 + (instancetype)dictionaryWithFloats:(const float [])values | 8453 + (instancetype)dictionaryWithValues:(const float [])values |
8499 forKeys:(const int64_t [])keys | 8454 forKeys:(const int64_t [])keys |
8500 count:(NSUInteger)count { | 8455 count:(NSUInteger)count { |
8501 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 8456 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
8502 // on to get the type correct. | 8457 // on to get the type correct. |
8503 return [[(GPBInt64FloatDictionary*)[self alloc] initWithFloats:values | 8458 return [[(GPBInt64FloatDictionary*)[self alloc] initWithValues:values |
8504 forKeys:keys | 8459 forKeys:keys |
8505 count:count] autorele
ase]; | 8460 count:count] autorele
ase]; |
8506 } | 8461 } |
8507 | 8462 |
8508 + (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary { | 8463 + (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary { |
8509 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 8464 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
8510 // on to get the type correct. | 8465 // on to get the type correct. |
8511 return [[(GPBInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 8466 return [[(GPBInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
8512 } | 8467 } |
8513 | 8468 |
8514 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 8469 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
8515 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 8470 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
8516 } | 8471 } |
8517 | 8472 |
8518 - (instancetype)init { | 8473 - (instancetype)init { |
8519 return [self initWithFloats:NULL forKeys:NULL count:0]; | 8474 return [self initWithValues:NULL forKeys:NULL count:0]; |
8520 } | 8475 } |
8521 | 8476 |
8522 - (instancetype)initWithFloats:(const float [])values | 8477 - (instancetype)initWithValues:(const float [])values |
8523 forKeys:(const int64_t [])keys | 8478 forKeys:(const int64_t [])keys |
8524 count:(NSUInteger)count { | 8479 count:(NSUInteger)count { |
8525 self = [super init]; | 8480 self = [super init]; |
8526 if (self) { | 8481 if (self) { |
8527 _dictionary = [[NSMutableDictionary alloc] init]; | 8482 _dictionary = [[NSMutableDictionary alloc] init]; |
8528 if (count && values && keys) { | 8483 if (count && values && keys) { |
8529 for (NSUInteger i = 0; i < count; ++i) { | 8484 for (NSUInteger i = 0; i < count; ++i) { |
8530 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 8485 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
8531 } | 8486 } |
8532 } | 8487 } |
8533 } | 8488 } |
8534 return self; | 8489 return self; |
8535 } | 8490 } |
8536 | 8491 |
8537 - (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary { | 8492 - (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary { |
8538 self = [self initWithFloats:NULL forKeys:NULL count:0]; | 8493 self = [self initWithValues:NULL forKeys:NULL count:0]; |
8539 if (self) { | 8494 if (self) { |
8540 if (dictionary) { | 8495 if (dictionary) { |
8541 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 8496 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
8542 } | 8497 } |
8543 } | 8498 } |
8544 return self; | 8499 return self; |
8545 } | 8500 } |
8546 | 8501 |
8547 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 8502 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
8548 #pragma unused(numItems) | 8503 #pragma unused(numItems) |
8549 return [self initWithFloats:NULL forKeys:NULL count:0]; | 8504 return [self initWithValues:NULL forKeys:NULL count:0]; |
8550 } | 8505 } |
8551 | 8506 |
8552 - (void)dealloc { | 8507 - (void)dealloc { |
8553 NSAssert(!_autocreator, | 8508 NSAssert(!_autocreator, |
8554 @"%@: Autocreator must be cleared before release, autocreator: %@", | 8509 @"%@: Autocreator must be cleared before release, autocreator: %@", |
8555 [self class], _autocreator); | 8510 [self class], _autocreator); |
8556 [_dictionary release]; | 8511 [_dictionary release]; |
8557 [super dealloc]; | 8512 [super dealloc]; |
8558 } | 8513 } |
8559 | 8514 |
8560 - (instancetype)copyWithZone:(NSZone *)zone { | 8515 - (instancetype)copyWithZone:(NSZone *)zone { |
8561 return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]; | 8516 return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]; |
8562 } | 8517 } |
8563 | 8518 |
8564 - (BOOL)isEqual:(id)other { | 8519 - (BOOL)isEqual:(GPBInt64FloatDictionary *)other { |
8565 if (self == other) { | 8520 if (self == other) { |
8566 return YES; | 8521 return YES; |
8567 } | 8522 } |
8568 if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) { | 8523 if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) { |
8569 return NO; | 8524 return NO; |
8570 } | 8525 } |
8571 GPBInt64FloatDictionary *otherDictionary = other; | 8526 return [_dictionary isEqual:other->_dictionary]; |
8572 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
8573 } | 8527 } |
8574 | 8528 |
8575 - (NSUInteger)hash { | 8529 - (NSUInteger)hash { |
8576 return _dictionary.count; | 8530 return _dictionary.count; |
8577 } | 8531 } |
8578 | 8532 |
8579 - (NSString *)description { | 8533 - (NSString *)description { |
8580 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 8534 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
8581 } | 8535 } |
8582 | 8536 |
8583 - (NSUInteger)count { | 8537 - (NSUInteger)count { |
8584 return _dictionary.count; | 8538 return _dictionary.count; |
8585 } | 8539 } |
8586 | 8540 |
8587 - (void)enumerateKeysAndFloatsUsingBlock: | 8541 - (void)enumerateKeysAndValuesUsingBlock: |
8588 (void (^)(int64_t key, float value, BOOL *stop))block { | 8542 (void (^)(int64_t key, float value, BOOL *stop))block { |
8589 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 8543 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
8590 NSNumber *aValue, | 8544 NSNumber *aValue, |
8591 BOOL *stop) { | 8545 BOOL *stop) { |
8592 block([aKey longLongValue], [aValue floatValue], stop); | 8546 block([aKey longLongValue], [aValue floatValue], stop); |
8593 }]; | 8547 }]; |
8594 } | 8548 } |
8595 | 8549 |
8596 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 8550 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
8597 NSUInteger count = _dictionary.count; | 8551 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8635 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | 8589 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); |
8636 }]; | 8590 }]; |
8637 } | 8591 } |
8638 | 8592 |
8639 - (void)setGPBGenericValue:(GPBGenericValue *)value | 8593 - (void)setGPBGenericValue:(GPBGenericValue *)value |
8640 forGPBGenericValueKey:(GPBGenericValue *)key { | 8594 forGPBGenericValueKey:(GPBGenericValue *)key { |
8641 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)]; | 8595 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)]; |
8642 } | 8596 } |
8643 | 8597 |
8644 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 8598 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
8645 [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, BOOL *stop)
{ | 8599 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, float value, BOOL *stop)
{ |
8646 #pragma unused(stop) | 8600 #pragma unused(stop) |
8647 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%.*g", FLT_DIG, value]); | 8601 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%.*g", FLT_DIG, value]); |
8648 }]; | 8602 }]; |
8649 } | 8603 } |
8650 | 8604 |
8651 - (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key { | 8605 - (BOOL)valueForKey:(int64_t)key value:(float *)value { |
8652 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 8606 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
8653 if (wrapped && value) { | 8607 if (wrapped && value) { |
8654 *value = [wrapped floatValue]; | 8608 *value = [wrapped floatValue]; |
8655 } | 8609 } |
8656 return (wrapped != NULL); | 8610 return (wrapped != NULL); |
8657 } | 8611 } |
8658 | 8612 |
8659 - (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary { | 8613 - (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary { |
8660 if (otherDictionary) { | 8614 if (otherDictionary) { |
8661 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 8615 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
8662 if (_autocreator) { | 8616 if (_autocreator) { |
8663 GPBAutocreatedDictionaryModified(_autocreator, self); | 8617 GPBAutocreatedDictionaryModified(_autocreator, self); |
8664 } | 8618 } |
8665 } | 8619 } |
8666 } | 8620 } |
8667 | 8621 |
8668 - (void)setFloat:(float)value forKey:(int64_t)key { | 8622 - (void)setValue:(float)value forKey:(int64_t)key { |
8669 [_dictionary setObject:@(value) forKey:@(key)]; | 8623 [_dictionary setObject:@(value) forKey:@(key)]; |
8670 if (_autocreator) { | 8624 if (_autocreator) { |
8671 GPBAutocreatedDictionaryModified(_autocreator, self); | 8625 GPBAutocreatedDictionaryModified(_autocreator, self); |
8672 } | 8626 } |
8673 } | 8627 } |
8674 | 8628 |
8675 - (void)removeFloatForKey:(int64_t)aKey { | 8629 - (void)removeValueForKey:(int64_t)aKey { |
8676 [_dictionary removeObjectForKey:@(aKey)]; | 8630 [_dictionary removeObjectForKey:@(aKey)]; |
8677 } | 8631 } |
8678 | 8632 |
8679 - (void)removeAll { | 8633 - (void)removeAll { |
8680 [_dictionary removeAllObjects]; | 8634 [_dictionary removeAllObjects]; |
8681 } | 8635 } |
8682 | 8636 |
8683 @end | 8637 @end |
8684 | 8638 |
8685 #pragma mark - Int64 -> Double | 8639 #pragma mark - Int64 -> Double |
8686 | 8640 |
8687 @implementation GPBInt64DoubleDictionary { | 8641 @implementation GPBInt64DoubleDictionary { |
8688 @package | 8642 @package |
8689 NSMutableDictionary *_dictionary; | 8643 NSMutableDictionary *_dictionary; |
8690 } | 8644 } |
8691 | 8645 |
8692 + (instancetype)dictionary { | 8646 + (instancetype)dictionary { |
8693 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; | 8647 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
8694 } | 8648 } |
8695 | 8649 |
8696 + (instancetype)dictionaryWithDouble:(double)value | 8650 + (instancetype)dictionaryWithValue:(double)value |
8697 forKey:(int64_t)key { | 8651 forKey:(int64_t)key { |
8698 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 8652 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
8699 // on to get the type correct. | 8653 // on to get the type correct. |
8700 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDoubles:&value | 8654 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithValues:&value |
8701 forKeys:&key | 8655 forKeys:&key |
8702 count:1] autoreleas
e]; | 8656 count:1] autorelease
]; |
8703 } | 8657 } |
8704 | 8658 |
8705 + (instancetype)dictionaryWithDoubles:(const double [])values | 8659 + (instancetype)dictionaryWithValues:(const double [])values |
8706 forKeys:(const int64_t [])keys | 8660 forKeys:(const int64_t [])keys |
8707 count:(NSUInteger)count { | 8661 count:(NSUInteger)count { |
8708 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 8662 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
8709 // on to get the type correct. | 8663 // on to get the type correct. |
8710 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDoubles:values | 8664 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithValues:values |
8711 forKeys:keys | 8665 forKeys:keys |
8712 count:count] autorel
ease]; | 8666 count:count] autorel
ease]; |
8713 } | 8667 } |
8714 | 8668 |
8715 + (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary
{ | 8669 + (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary
{ |
8716 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 8670 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
8717 // on to get the type correct. | 8671 // on to get the type correct. |
8718 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 8672 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
8719 } | 8673 } |
8720 | 8674 |
8721 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 8675 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
8722 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 8676 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
8723 } | 8677 } |
8724 | 8678 |
8725 - (instancetype)init { | 8679 - (instancetype)init { |
8726 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 8680 return [self initWithValues:NULL forKeys:NULL count:0]; |
8727 } | 8681 } |
8728 | 8682 |
8729 - (instancetype)initWithDoubles:(const double [])values | 8683 - (instancetype)initWithValues:(const double [])values |
8730 forKeys:(const int64_t [])keys | 8684 forKeys:(const int64_t [])keys |
8731 count:(NSUInteger)count { | 8685 count:(NSUInteger)count { |
8732 self = [super init]; | 8686 self = [super init]; |
8733 if (self) { | 8687 if (self) { |
8734 _dictionary = [[NSMutableDictionary alloc] init]; | 8688 _dictionary = [[NSMutableDictionary alloc] init]; |
8735 if (count && values && keys) { | 8689 if (count && values && keys) { |
8736 for (NSUInteger i = 0; i < count; ++i) { | 8690 for (NSUInteger i = 0; i < count; ++i) { |
8737 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 8691 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
8738 } | 8692 } |
8739 } | 8693 } |
8740 } | 8694 } |
8741 return self; | 8695 return self; |
8742 } | 8696 } |
8743 | 8697 |
8744 - (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary { | 8698 - (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary { |
8745 self = [self initWithDoubles:NULL forKeys:NULL count:0]; | 8699 self = [self initWithValues:NULL forKeys:NULL count:0]; |
8746 if (self) { | 8700 if (self) { |
8747 if (dictionary) { | 8701 if (dictionary) { |
8748 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 8702 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
8749 } | 8703 } |
8750 } | 8704 } |
8751 return self; | 8705 return self; |
8752 } | 8706 } |
8753 | 8707 |
8754 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 8708 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
8755 #pragma unused(numItems) | 8709 #pragma unused(numItems) |
8756 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 8710 return [self initWithValues:NULL forKeys:NULL count:0]; |
8757 } | 8711 } |
8758 | 8712 |
8759 - (void)dealloc { | 8713 - (void)dealloc { |
8760 NSAssert(!_autocreator, | 8714 NSAssert(!_autocreator, |
8761 @"%@: Autocreator must be cleared before release, autocreator: %@", | 8715 @"%@: Autocreator must be cleared before release, autocreator: %@", |
8762 [self class], _autocreator); | 8716 [self class], _autocreator); |
8763 [_dictionary release]; | 8717 [_dictionary release]; |
8764 [super dealloc]; | 8718 [super dealloc]; |
8765 } | 8719 } |
8766 | 8720 |
8767 - (instancetype)copyWithZone:(NSZone *)zone { | 8721 - (instancetype)copyWithZone:(NSZone *)zone { |
8768 return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self]
; | 8722 return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self]
; |
8769 } | 8723 } |
8770 | 8724 |
8771 - (BOOL)isEqual:(id)other { | 8725 - (BOOL)isEqual:(GPBInt64DoubleDictionary *)other { |
8772 if (self == other) { | 8726 if (self == other) { |
8773 return YES; | 8727 return YES; |
8774 } | 8728 } |
8775 if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) { | 8729 if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) { |
8776 return NO; | 8730 return NO; |
8777 } | 8731 } |
8778 GPBInt64DoubleDictionary *otherDictionary = other; | 8732 return [_dictionary isEqual:other->_dictionary]; |
8779 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
8780 } | 8733 } |
8781 | 8734 |
8782 - (NSUInteger)hash { | 8735 - (NSUInteger)hash { |
8783 return _dictionary.count; | 8736 return _dictionary.count; |
8784 } | 8737 } |
8785 | 8738 |
8786 - (NSString *)description { | 8739 - (NSString *)description { |
8787 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 8740 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
8788 } | 8741 } |
8789 | 8742 |
8790 - (NSUInteger)count { | 8743 - (NSUInteger)count { |
8791 return _dictionary.count; | 8744 return _dictionary.count; |
8792 } | 8745 } |
8793 | 8746 |
8794 - (void)enumerateKeysAndDoublesUsingBlock: | 8747 - (void)enumerateKeysAndValuesUsingBlock: |
8795 (void (^)(int64_t key, double value, BOOL *stop))block { | 8748 (void (^)(int64_t key, double value, BOOL *stop))block { |
8796 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 8749 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
8797 NSNumber *aValue, | 8750 NSNumber *aValue, |
8798 BOOL *stop) { | 8751 BOOL *stop) { |
8799 block([aKey longLongValue], [aValue doubleValue], stop); | 8752 block([aKey longLongValue], [aValue doubleValue], stop); |
8800 }]; | 8753 }]; |
8801 } | 8754 } |
8802 | 8755 |
8803 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 8756 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
8804 NSUInteger count = _dictionary.count; | 8757 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8842 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | 8795 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); |
8843 }]; | 8796 }]; |
8844 } | 8797 } |
8845 | 8798 |
8846 - (void)setGPBGenericValue:(GPBGenericValue *)value | 8799 - (void)setGPBGenericValue:(GPBGenericValue *)value |
8847 forGPBGenericValueKey:(GPBGenericValue *)key { | 8800 forGPBGenericValueKey:(GPBGenericValue *)key { |
8848 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)]; | 8801 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)]; |
8849 } | 8802 } |
8850 | 8803 |
8851 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 8804 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
8852 [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, BOOL *sto
p) { | 8805 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, double value, BOOL *stop
) { |
8853 #pragma unused(stop) | 8806 #pragma unused(stop) |
8854 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%.*lg", DBL_DIG, value]); | 8807 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%.*lg", DBL_DIG, value]); |
8855 }]; | 8808 }]; |
8856 } | 8809 } |
8857 | 8810 |
8858 - (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key { | 8811 - (BOOL)valueForKey:(int64_t)key value:(double *)value { |
8859 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 8812 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
8860 if (wrapped && value) { | 8813 if (wrapped && value) { |
8861 *value = [wrapped doubleValue]; | 8814 *value = [wrapped doubleValue]; |
8862 } | 8815 } |
8863 return (wrapped != NULL); | 8816 return (wrapped != NULL); |
8864 } | 8817 } |
8865 | 8818 |
8866 - (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary { | 8819 - (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary { |
8867 if (otherDictionary) { | 8820 if (otherDictionary) { |
8868 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 8821 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
8869 if (_autocreator) { | 8822 if (_autocreator) { |
8870 GPBAutocreatedDictionaryModified(_autocreator, self); | 8823 GPBAutocreatedDictionaryModified(_autocreator, self); |
8871 } | 8824 } |
8872 } | 8825 } |
8873 } | 8826 } |
8874 | 8827 |
8875 - (void)setDouble:(double)value forKey:(int64_t)key { | 8828 - (void)setValue:(double)value forKey:(int64_t)key { |
8876 [_dictionary setObject:@(value) forKey:@(key)]; | 8829 [_dictionary setObject:@(value) forKey:@(key)]; |
8877 if (_autocreator) { | 8830 if (_autocreator) { |
8878 GPBAutocreatedDictionaryModified(_autocreator, self); | 8831 GPBAutocreatedDictionaryModified(_autocreator, self); |
8879 } | 8832 } |
8880 } | 8833 } |
8881 | 8834 |
8882 - (void)removeDoubleForKey:(int64_t)aKey { | 8835 - (void)removeValueForKey:(int64_t)aKey { |
8883 [_dictionary removeObjectForKey:@(aKey)]; | 8836 [_dictionary removeObjectForKey:@(aKey)]; |
8884 } | 8837 } |
8885 | 8838 |
8886 - (void)removeAll { | 8839 - (void)removeAll { |
8887 [_dictionary removeAllObjects]; | 8840 [_dictionary removeAllObjects]; |
8888 } | 8841 } |
8889 | 8842 |
8890 @end | 8843 @end |
8891 | 8844 |
8892 #pragma mark - Int64 -> Enum | 8845 #pragma mark - Int64 -> Enum |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8996 @"%@: Autocreator must be cleared before release, autocreator: %@", | 8949 @"%@: Autocreator must be cleared before release, autocreator: %@", |
8997 [self class], _autocreator); | 8950 [self class], _autocreator); |
8998 [_dictionary release]; | 8951 [_dictionary release]; |
8999 [super dealloc]; | 8952 [super dealloc]; |
9000 } | 8953 } |
9001 | 8954 |
9002 - (instancetype)copyWithZone:(NSZone *)zone { | 8955 - (instancetype)copyWithZone:(NSZone *)zone { |
9003 return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; | 8956 return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; |
9004 } | 8957 } |
9005 | 8958 |
9006 - (BOOL)isEqual:(id)other { | 8959 - (BOOL)isEqual:(GPBInt64EnumDictionary *)other { |
9007 if (self == other) { | 8960 if (self == other) { |
9008 return YES; | 8961 return YES; |
9009 } | 8962 } |
9010 if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) { | 8963 if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) { |
9011 return NO; | 8964 return NO; |
9012 } | 8965 } |
9013 GPBInt64EnumDictionary *otherDictionary = other; | 8966 return [_dictionary isEqual:other->_dictionary]; |
9014 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
9015 } | 8967 } |
9016 | 8968 |
9017 - (NSUInteger)hash { | 8969 - (NSUInteger)hash { |
9018 return _dictionary.count; | 8970 return _dictionary.count; |
9019 } | 8971 } |
9020 | 8972 |
9021 - (NSString *)description { | 8973 - (NSString *)description { |
9022 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 8974 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
9023 } | 8975 } |
9024 | 8976 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9095 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)]; | 9047 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)]; |
9096 } | 9048 } |
9097 | 9049 |
9098 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 9050 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
9099 [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *
stop) { | 9051 [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *
stop) { |
9100 #pragma unused(stop) | 9052 #pragma unused(stop) |
9101 block([NSString stringWithFormat:@"%lld", key], @(value)); | 9053 block([NSString stringWithFormat:@"%lld", key], @(value)); |
9102 }]; | 9054 }]; |
9103 } | 9055 } |
9104 | 9056 |
9105 - (BOOL)getEnum:(int32_t *)value forKey:(int64_t)key { | 9057 - (BOOL)valueForKey:(int64_t)key value:(int32_t *)value { |
9106 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 9058 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
9107 if (wrapped && value) { | 9059 if (wrapped && value) { |
9108 int32_t result = [wrapped intValue]; | 9060 int32_t result = [wrapped intValue]; |
9109 if (!_validationFunc(result)) { | 9061 if (!_validationFunc(result)) { |
9110 result = kGPBUnrecognizedEnumeratorValue; | 9062 result = kGPBUnrecognizedEnumeratorValue; |
9111 } | 9063 } |
9112 *value = result; | 9064 *value = result; |
9113 } | 9065 } |
9114 return (wrapped != NULL); | 9066 return (wrapped != NULL); |
9115 } | 9067 } |
9116 | 9068 |
9117 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int64_t)key { | 9069 - (BOOL)valueForKey:(int64_t)key rawValue:(int32_t *)rawValue { |
9118 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 9070 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
9119 if (wrapped && rawValue) { | 9071 if (wrapped && rawValue) { |
9120 *rawValue = [wrapped intValue]; | 9072 *rawValue = [wrapped intValue]; |
9121 } | 9073 } |
9122 return (wrapped != NULL); | 9074 return (wrapped != NULL); |
9123 } | 9075 } |
9124 | 9076 |
9125 - (void)enumerateKeysAndEnumsUsingBlock: | 9077 - (void)enumerateKeysAndValuesUsingBlock: |
9126 (void (^)(int64_t key, int32_t value, BOOL *stop))block { | 9078 (void (^)(int64_t key, int32_t value, BOOL *stop))block { |
9127 GPBEnumValidationFunc func = _validationFunc; | 9079 GPBEnumValidationFunc func = _validationFunc; |
9128 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 9080 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
9129 NSNumber *aValue, | 9081 NSNumber *aValue, |
9130 BOOL *stop) { | 9082 BOOL *stop) { |
9131 int32_t unwrapped = [aValue intValue]; | 9083 int32_t unwrapped = [aValue intValue]; |
9132 if (!func(unwrapped)) { | 9084 if (!func(unwrapped)) { |
9133 unwrapped = kGPBUnrecognizedEnumeratorValue; | 9085 unwrapped = kGPBUnrecognizedEnumeratorValue; |
9134 } | 9086 } |
9135 block([aKey longLongValue], unwrapped, stop); | 9087 block([aKey longLongValue], unwrapped, stop); |
9136 }]; | 9088 }]; |
9137 } | 9089 } |
9138 | 9090 |
9139 - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary { | 9091 - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary { |
9140 if (otherDictionary) { | 9092 if (otherDictionary) { |
9141 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 9093 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
9142 if (_autocreator) { | 9094 if (_autocreator) { |
9143 GPBAutocreatedDictionaryModified(_autocreator, self); | 9095 GPBAutocreatedDictionaryModified(_autocreator, self); |
9144 } | 9096 } |
9145 } | 9097 } |
9146 } | 9098 } |
9147 | 9099 |
9148 - (void)setRawValue:(int32_t)value forKey:(int64_t)key { | 9100 - (void)setRawValue:(int32_t)value forKey:(int64_t)key { |
9149 [_dictionary setObject:@(value) forKey:@(key)]; | 9101 [_dictionary setObject:@(value) forKey:@(key)]; |
9150 if (_autocreator) { | 9102 if (_autocreator) { |
9151 GPBAutocreatedDictionaryModified(_autocreator, self); | 9103 GPBAutocreatedDictionaryModified(_autocreator, self); |
9152 } | 9104 } |
9153 } | 9105 } |
9154 | 9106 |
9155 - (void)removeEnumForKey:(int64_t)aKey { | 9107 - (void)removeValueForKey:(int64_t)aKey { |
9156 [_dictionary removeObjectForKey:@(aKey)]; | 9108 [_dictionary removeObjectForKey:@(aKey)]; |
9157 } | 9109 } |
9158 | 9110 |
9159 - (void)removeAll { | 9111 - (void)removeAll { |
9160 [_dictionary removeAllObjects]; | 9112 [_dictionary removeAllObjects]; |
9161 } | 9113 } |
9162 | 9114 |
9163 - (void)setEnum:(int32_t)value forKey:(int64_t)key { | 9115 - (void)setValue:(int32_t)value forKey:(int64_t)key { |
9164 if (!_validationFunc(value)) { | 9116 if (!_validationFunc(value)) { |
9165 [NSException raise:NSInvalidArgumentException | 9117 [NSException raise:NSInvalidArgumentException |
9166 format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum
value (%d)", | 9118 format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum
value (%d)", |
9167 value]; | 9119 value]; |
9168 } | 9120 } |
9169 | 9121 |
9170 [_dictionary setObject:@(value) forKey:@(key)]; | 9122 [_dictionary setObject:@(value) forKey:@(key)]; |
9171 if (_autocreator) { | 9123 if (_autocreator) { |
9172 GPBAutocreatedDictionaryModified(_autocreator, self); | 9124 GPBAutocreatedDictionaryModified(_autocreator, self); |
9173 } | 9125 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9258 @"%@: Autocreator must be cleared before release, autocreator: %@", | 9210 @"%@: Autocreator must be cleared before release, autocreator: %@", |
9259 [self class], _autocreator); | 9211 [self class], _autocreator); |
9260 [_dictionary release]; | 9212 [_dictionary release]; |
9261 [super dealloc]; | 9213 [super dealloc]; |
9262 } | 9214 } |
9263 | 9215 |
9264 - (instancetype)copyWithZone:(NSZone *)zone { | 9216 - (instancetype)copyWithZone:(NSZone *)zone { |
9265 return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self]
; | 9217 return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self]
; |
9266 } | 9218 } |
9267 | 9219 |
9268 - (BOOL)isEqual:(id)other { | 9220 - (BOOL)isEqual:(GPBInt64ObjectDictionary *)other { |
9269 if (self == other) { | 9221 if (self == other) { |
9270 return YES; | 9222 return YES; |
9271 } | 9223 } |
9272 if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) { | 9224 if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) { |
9273 return NO; | 9225 return NO; |
9274 } | 9226 } |
9275 GPBInt64ObjectDictionary *otherDictionary = other; | 9227 return [_dictionary isEqual:other->_dictionary]; |
9276 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
9277 } | 9228 } |
9278 | 9229 |
9279 - (NSUInteger)hash { | 9230 - (NSUInteger)hash { |
9280 return _dictionary.count; | 9231 return _dictionary.count; |
9281 } | 9232 } |
9282 | 9233 |
9283 - (NSString *)description { | 9234 - (NSString *)description { |
9284 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 9235 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
9285 } | 9236 } |
9286 | 9237 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9414 // This block of code is generated, do not edit it directly. | 9365 // This block of code is generated, do not edit it directly. |
9415 | 9366 |
9416 #pragma mark - String -> UInt32 | 9367 #pragma mark - String -> UInt32 |
9417 | 9368 |
9418 @implementation GPBStringUInt32Dictionary { | 9369 @implementation GPBStringUInt32Dictionary { |
9419 @package | 9370 @package |
9420 NSMutableDictionary *_dictionary; | 9371 NSMutableDictionary *_dictionary; |
9421 } | 9372 } |
9422 | 9373 |
9423 + (instancetype)dictionary { | 9374 + (instancetype)dictionary { |
9424 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; | 9375 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
9425 } | 9376 } |
9426 | 9377 |
9427 + (instancetype)dictionaryWithUInt32:(uint32_t)value | 9378 + (instancetype)dictionaryWithValue:(uint32_t)value |
9428 forKey:(NSString *)key { | 9379 forKey:(NSString *)key { |
9429 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 9380 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
9430 // on to get the type correct. | 9381 // on to get the type correct. |
9431 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithUInt32s:&value | 9382 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithValues:&value |
9432 forKeys:&key | 9383 forKeys:&key |
9433 count:1] autorelea
se]; | 9384 count:1] autoreleas
e]; |
9434 } | 9385 } |
9435 | 9386 |
9436 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values | 9387 + (instancetype)dictionaryWithValues:(const uint32_t [])values |
9437 forKeys:(const NSString * [])keys | 9388 forKeys:(const NSString * [])keys |
9438 count:(NSUInteger)count { | 9389 count:(NSUInteger)count { |
9439 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 9390 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
9440 // on to get the type correct. | 9391 // on to get the type correct. |
9441 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithUInt32s:values | 9392 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithValues:values |
9442 forKeys:keys | 9393 forKeys:keys |
9443 count:count] autore
lease]; | 9394 count:count] autore
lease]; |
9444 } | 9395 } |
9445 | 9396 |
9446 + (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary
{ | 9397 + (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary
{ |
9447 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 9398 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
9448 // on to get the type correct. | 9399 // on to get the type correct. |
9449 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 9400 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
9450 } | 9401 } |
9451 | 9402 |
9452 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 9403 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
9453 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 9404 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
9454 } | 9405 } |
9455 | 9406 |
9456 - (instancetype)init { | 9407 - (instancetype)init { |
9457 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 9408 return [self initWithValues:NULL forKeys:NULL count:0]; |
9458 } | 9409 } |
9459 | 9410 |
9460 - (instancetype)initWithUInt32s:(const uint32_t [])values | 9411 - (instancetype)initWithValues:(const uint32_t [])values |
9461 forKeys:(const NSString * [])keys | 9412 forKeys:(const NSString * [])keys |
9462 count:(NSUInteger)count { | 9413 count:(NSUInteger)count { |
9463 self = [super init]; | 9414 self = [super init]; |
9464 if (self) { | 9415 if (self) { |
9465 _dictionary = [[NSMutableDictionary alloc] init]; | 9416 _dictionary = [[NSMutableDictionary alloc] init]; |
9466 if (count && values && keys) { | 9417 if (count && values && keys) { |
9467 for (NSUInteger i = 0; i < count; ++i) { | 9418 for (NSUInteger i = 0; i < count; ++i) { |
9468 if (!keys[i]) { | 9419 if (!keys[i]) { |
9469 [NSException raise:NSInvalidArgumentException | 9420 [NSException raise:NSInvalidArgumentException |
9470 format:@"Attempting to add nil key to a Dictionary"]; | 9421 format:@"Attempting to add nil key to a Dictionary"]; |
9471 } | 9422 } |
9472 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 9423 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
9473 } | 9424 } |
9474 } | 9425 } |
9475 } | 9426 } |
9476 return self; | 9427 return self; |
9477 } | 9428 } |
9478 | 9429 |
9479 - (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary { | 9430 - (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary { |
9480 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; | 9431 self = [self initWithValues:NULL forKeys:NULL count:0]; |
9481 if (self) { | 9432 if (self) { |
9482 if (dictionary) { | 9433 if (dictionary) { |
9483 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 9434 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
9484 } | 9435 } |
9485 } | 9436 } |
9486 return self; | 9437 return self; |
9487 } | 9438 } |
9488 | 9439 |
9489 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 9440 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
9490 #pragma unused(numItems) | 9441 #pragma unused(numItems) |
9491 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 9442 return [self initWithValues:NULL forKeys:NULL count:0]; |
9492 } | 9443 } |
9493 | 9444 |
9494 - (void)dealloc { | 9445 - (void)dealloc { |
9495 NSAssert(!_autocreator, | 9446 NSAssert(!_autocreator, |
9496 @"%@: Autocreator must be cleared before release, autocreator: %@", | 9447 @"%@: Autocreator must be cleared before release, autocreator: %@", |
9497 [self class], _autocreator); | 9448 [self class], _autocreator); |
9498 [_dictionary release]; | 9449 [_dictionary release]; |
9499 [super dealloc]; | 9450 [super dealloc]; |
9500 } | 9451 } |
9501 | 9452 |
9502 - (instancetype)copyWithZone:(NSZone *)zone { | 9453 - (instancetype)copyWithZone:(NSZone *)zone { |
9503 return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; | 9454 return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; |
9504 } | 9455 } |
9505 | 9456 |
9506 - (BOOL)isEqual:(id)other { | 9457 - (BOOL)isEqual:(GPBStringUInt32Dictionary *)other { |
9507 if (self == other) { | 9458 if (self == other) { |
9508 return YES; | 9459 return YES; |
9509 } | 9460 } |
9510 if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) { | 9461 if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) { |
9511 return NO; | 9462 return NO; |
9512 } | 9463 } |
9513 GPBStringUInt32Dictionary *otherDictionary = other; | 9464 return [_dictionary isEqual:other->_dictionary]; |
9514 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
9515 } | 9465 } |
9516 | 9466 |
9517 - (NSUInteger)hash { | 9467 - (NSUInteger)hash { |
9518 return _dictionary.count; | 9468 return _dictionary.count; |
9519 } | 9469 } |
9520 | 9470 |
9521 - (NSString *)description { | 9471 - (NSString *)description { |
9522 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 9472 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
9523 } | 9473 } |
9524 | 9474 |
9525 - (NSUInteger)count { | 9475 - (NSUInteger)count { |
9526 return _dictionary.count; | 9476 return _dictionary.count; |
9527 } | 9477 } |
9528 | 9478 |
9529 - (void)enumerateKeysAndUInt32sUsingBlock: | 9479 - (void)enumerateKeysAndValuesUsingBlock: |
9530 (void (^)(NSString *key, uint32_t value, BOOL *stop))block { | 9480 (void (^)(NSString *key, uint32_t value, BOOL *stop))block { |
9531 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 9481 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
9532 NSNumber *aValue, | 9482 NSNumber *aValue, |
9533 BOOL *stop) { | 9483 BOOL *stop) { |
9534 block(aKey, [aValue unsignedIntValue], stop); | 9484 block(aKey, [aValue unsignedIntValue], stop); |
9535 }]; | 9485 }]; |
9536 } | 9486 } |
9537 | 9487 |
9538 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 9488 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
9539 NSUInteger count = _dictionary.count; | 9489 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9577 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | 9527 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); |
9578 }]; | 9528 }]; |
9579 } | 9529 } |
9580 | 9530 |
9581 - (void)setGPBGenericValue:(GPBGenericValue *)value | 9531 - (void)setGPBGenericValue:(GPBGenericValue *)value |
9582 forGPBGenericValueKey:(GPBGenericValue *)key { | 9532 forGPBGenericValueKey:(GPBGenericValue *)key { |
9583 [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString]; | 9533 [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString]; |
9584 } | 9534 } |
9585 | 9535 |
9586 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 9536 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
9587 [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, BOOL
*stop) { | 9537 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, uint32_t value, BOOL *
stop) { |
9588 #pragma unused(stop) | 9538 #pragma unused(stop) |
9589 block(key, [NSString stringWithFormat:@"%u", value]); | 9539 block(key, [NSString stringWithFormat:@"%u", value]); |
9590 }]; | 9540 }]; |
9591 } | 9541 } |
9592 | 9542 |
9593 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key { | 9543 - (BOOL)valueForKey:(NSString *)key value:(uint32_t *)value { |
9594 NSNumber *wrapped = [_dictionary objectForKey:key]; | 9544 NSNumber *wrapped = [_dictionary objectForKey:key]; |
9595 if (wrapped && value) { | 9545 if (wrapped && value) { |
9596 *value = [wrapped unsignedIntValue]; | 9546 *value = [wrapped unsignedIntValue]; |
9597 } | 9547 } |
9598 return (wrapped != NULL); | 9548 return (wrapped != NULL); |
9599 } | 9549 } |
9600 | 9550 |
9601 - (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary { | 9551 - (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary { |
9602 if (otherDictionary) { | 9552 if (otherDictionary) { |
9603 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 9553 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
9604 if (_autocreator) { | 9554 if (_autocreator) { |
9605 GPBAutocreatedDictionaryModified(_autocreator, self); | 9555 GPBAutocreatedDictionaryModified(_autocreator, self); |
9606 } | 9556 } |
9607 } | 9557 } |
9608 } | 9558 } |
9609 | 9559 |
9610 - (void)setUInt32:(uint32_t)value forKey:(NSString *)key { | 9560 - (void)setValue:(uint32_t)value forKey:(NSString *)key { |
9611 if (!key) { | 9561 if (!key) { |
9612 [NSException raise:NSInvalidArgumentException | 9562 [NSException raise:NSInvalidArgumentException |
9613 format:@"Attempting to add nil key to a Dictionary"]; | 9563 format:@"Attempting to add nil key to a Dictionary"]; |
9614 } | 9564 } |
9615 [_dictionary setObject:@(value) forKey:key]; | 9565 [_dictionary setObject:@(value) forKey:key]; |
9616 if (_autocreator) { | 9566 if (_autocreator) { |
9617 GPBAutocreatedDictionaryModified(_autocreator, self); | 9567 GPBAutocreatedDictionaryModified(_autocreator, self); |
9618 } | 9568 } |
9619 } | 9569 } |
9620 | 9570 |
9621 - (void)removeUInt32ForKey:(NSString *)aKey { | 9571 - (void)removeValueForKey:(NSString *)aKey { |
9622 [_dictionary removeObjectForKey:aKey]; | 9572 [_dictionary removeObjectForKey:aKey]; |
9623 } | 9573 } |
9624 | 9574 |
9625 - (void)removeAll { | 9575 - (void)removeAll { |
9626 [_dictionary removeAllObjects]; | 9576 [_dictionary removeAllObjects]; |
9627 } | 9577 } |
9628 | 9578 |
9629 @end | 9579 @end |
9630 | 9580 |
9631 #pragma mark - String -> Int32 | 9581 #pragma mark - String -> Int32 |
9632 | 9582 |
9633 @implementation GPBStringInt32Dictionary { | 9583 @implementation GPBStringInt32Dictionary { |
9634 @package | 9584 @package |
9635 NSMutableDictionary *_dictionary; | 9585 NSMutableDictionary *_dictionary; |
9636 } | 9586 } |
9637 | 9587 |
9638 + (instancetype)dictionary { | 9588 + (instancetype)dictionary { |
9639 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; | 9589 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
9640 } | 9590 } |
9641 | 9591 |
9642 + (instancetype)dictionaryWithInt32:(int32_t)value | 9592 + (instancetype)dictionaryWithValue:(int32_t)value |
9643 forKey:(NSString *)key { | 9593 forKey:(NSString *)key { |
9644 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 9594 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
9645 // on to get the type correct. | 9595 // on to get the type correct. |
9646 return [[(GPBStringInt32Dictionary*)[self alloc] initWithInt32s:&value | 9596 return [[(GPBStringInt32Dictionary*)[self alloc] initWithValues:&value |
9647 forKeys:&key | 9597 forKeys:&key |
9648 count:1] autorelease
]; | 9598 count:1] autorelease
]; |
9649 } | 9599 } |
9650 | 9600 |
9651 + (instancetype)dictionaryWithInt32s:(const int32_t [])values | 9601 + (instancetype)dictionaryWithValues:(const int32_t [])values |
9652 forKeys:(const NSString * [])keys | 9602 forKeys:(const NSString * [])keys |
9653 count:(NSUInteger)count { | 9603 count:(NSUInteger)count { |
9654 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 9604 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
9655 // on to get the type correct. | 9605 // on to get the type correct. |
9656 return [[(GPBStringInt32Dictionary*)[self alloc] initWithInt32s:values | 9606 return [[(GPBStringInt32Dictionary*)[self alloc] initWithValues:values |
9657 forKeys:keys | 9607 forKeys:keys |
9658 count:count] autorel
ease]; | 9608 count:count] autorel
ease]; |
9659 } | 9609 } |
9660 | 9610 |
9661 + (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary
{ | 9611 + (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary
{ |
9662 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 9612 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
9663 // on to get the type correct. | 9613 // on to get the type correct. |
9664 return [[(GPBStringInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 9614 return [[(GPBStringInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
9665 } | 9615 } |
9666 | 9616 |
9667 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 9617 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
9668 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 9618 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
9669 } | 9619 } |
9670 | 9620 |
9671 - (instancetype)init { | 9621 - (instancetype)init { |
9672 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 9622 return [self initWithValues:NULL forKeys:NULL count:0]; |
9673 } | 9623 } |
9674 | 9624 |
9675 - (instancetype)initWithInt32s:(const int32_t [])values | 9625 - (instancetype)initWithValues:(const int32_t [])values |
9676 forKeys:(const NSString * [])keys | 9626 forKeys:(const NSString * [])keys |
9677 count:(NSUInteger)count { | 9627 count:(NSUInteger)count { |
9678 self = [super init]; | 9628 self = [super init]; |
9679 if (self) { | 9629 if (self) { |
9680 _dictionary = [[NSMutableDictionary alloc] init]; | 9630 _dictionary = [[NSMutableDictionary alloc] init]; |
9681 if (count && values && keys) { | 9631 if (count && values && keys) { |
9682 for (NSUInteger i = 0; i < count; ++i) { | 9632 for (NSUInteger i = 0; i < count; ++i) { |
9683 if (!keys[i]) { | 9633 if (!keys[i]) { |
9684 [NSException raise:NSInvalidArgumentException | 9634 [NSException raise:NSInvalidArgumentException |
9685 format:@"Attempting to add nil key to a Dictionary"]; | 9635 format:@"Attempting to add nil key to a Dictionary"]; |
9686 } | 9636 } |
9687 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 9637 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
9688 } | 9638 } |
9689 } | 9639 } |
9690 } | 9640 } |
9691 return self; | 9641 return self; |
9692 } | 9642 } |
9693 | 9643 |
9694 - (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary { | 9644 - (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary { |
9695 self = [self initWithInt32s:NULL forKeys:NULL count:0]; | 9645 self = [self initWithValues:NULL forKeys:NULL count:0]; |
9696 if (self) { | 9646 if (self) { |
9697 if (dictionary) { | 9647 if (dictionary) { |
9698 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 9648 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
9699 } | 9649 } |
9700 } | 9650 } |
9701 return self; | 9651 return self; |
9702 } | 9652 } |
9703 | 9653 |
9704 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 9654 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
9705 #pragma unused(numItems) | 9655 #pragma unused(numItems) |
9706 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 9656 return [self initWithValues:NULL forKeys:NULL count:0]; |
9707 } | 9657 } |
9708 | 9658 |
9709 - (void)dealloc { | 9659 - (void)dealloc { |
9710 NSAssert(!_autocreator, | 9660 NSAssert(!_autocreator, |
9711 @"%@: Autocreator must be cleared before release, autocreator: %@", | 9661 @"%@: Autocreator must be cleared before release, autocreator: %@", |
9712 [self class], _autocreator); | 9662 [self class], _autocreator); |
9713 [_dictionary release]; | 9663 [_dictionary release]; |
9714 [super dealloc]; | 9664 [super dealloc]; |
9715 } | 9665 } |
9716 | 9666 |
9717 - (instancetype)copyWithZone:(NSZone *)zone { | 9667 - (instancetype)copyWithZone:(NSZone *)zone { |
9718 return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; | 9668 return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; |
9719 } | 9669 } |
9720 | 9670 |
9721 - (BOOL)isEqual:(id)other { | 9671 - (BOOL)isEqual:(GPBStringInt32Dictionary *)other { |
9722 if (self == other) { | 9672 if (self == other) { |
9723 return YES; | 9673 return YES; |
9724 } | 9674 } |
9725 if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) { | 9675 if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) { |
9726 return NO; | 9676 return NO; |
9727 } | 9677 } |
9728 GPBStringInt32Dictionary *otherDictionary = other; | 9678 return [_dictionary isEqual:other->_dictionary]; |
9729 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
9730 } | 9679 } |
9731 | 9680 |
9732 - (NSUInteger)hash { | 9681 - (NSUInteger)hash { |
9733 return _dictionary.count; | 9682 return _dictionary.count; |
9734 } | 9683 } |
9735 | 9684 |
9736 - (NSString *)description { | 9685 - (NSString *)description { |
9737 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 9686 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
9738 } | 9687 } |
9739 | 9688 |
9740 - (NSUInteger)count { | 9689 - (NSUInteger)count { |
9741 return _dictionary.count; | 9690 return _dictionary.count; |
9742 } | 9691 } |
9743 | 9692 |
9744 - (void)enumerateKeysAndInt32sUsingBlock: | 9693 - (void)enumerateKeysAndValuesUsingBlock: |
9745 (void (^)(NSString *key, int32_t value, BOOL *stop))block { | 9694 (void (^)(NSString *key, int32_t value, BOOL *stop))block { |
9746 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 9695 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
9747 NSNumber *aValue, | 9696 NSNumber *aValue, |
9748 BOOL *stop) { | 9697 BOOL *stop) { |
9749 block(aKey, [aValue intValue], stop); | 9698 block(aKey, [aValue intValue], stop); |
9750 }]; | 9699 }]; |
9751 } | 9700 } |
9752 | 9701 |
9753 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 9702 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
9754 NSUInteger count = _dictionary.count; | 9703 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9792 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | 9741 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); |
9793 }]; | 9742 }]; |
9794 } | 9743 } |
9795 | 9744 |
9796 - (void)setGPBGenericValue:(GPBGenericValue *)value | 9745 - (void)setGPBGenericValue:(GPBGenericValue *)value |
9797 forGPBGenericValueKey:(GPBGenericValue *)key { | 9746 forGPBGenericValueKey:(GPBGenericValue *)key { |
9798 [_dictionary setObject:@(value->valueInt32) forKey:key->valueString]; | 9747 [_dictionary setObject:@(value->valueInt32) forKey:key->valueString]; |
9799 } | 9748 } |
9800 | 9749 |
9801 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 9750 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
9802 [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, BOOL *s
top) { | 9751 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, int32_t value, BOOL *s
top) { |
9803 #pragma unused(stop) | 9752 #pragma unused(stop) |
9804 block(key, [NSString stringWithFormat:@"%d", value]); | 9753 block(key, [NSString stringWithFormat:@"%d", value]); |
9805 }]; | 9754 }]; |
9806 } | 9755 } |
9807 | 9756 |
9808 - (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key { | 9757 - (BOOL)valueForKey:(NSString *)key value:(int32_t *)value { |
9809 NSNumber *wrapped = [_dictionary objectForKey:key]; | 9758 NSNumber *wrapped = [_dictionary objectForKey:key]; |
9810 if (wrapped && value) { | 9759 if (wrapped && value) { |
9811 *value = [wrapped intValue]; | 9760 *value = [wrapped intValue]; |
9812 } | 9761 } |
9813 return (wrapped != NULL); | 9762 return (wrapped != NULL); |
9814 } | 9763 } |
9815 | 9764 |
9816 - (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary { | 9765 - (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary { |
9817 if (otherDictionary) { | 9766 if (otherDictionary) { |
9818 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 9767 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
9819 if (_autocreator) { | 9768 if (_autocreator) { |
9820 GPBAutocreatedDictionaryModified(_autocreator, self); | 9769 GPBAutocreatedDictionaryModified(_autocreator, self); |
9821 } | 9770 } |
9822 } | 9771 } |
9823 } | 9772 } |
9824 | 9773 |
9825 - (void)setInt32:(int32_t)value forKey:(NSString *)key { | 9774 - (void)setValue:(int32_t)value forKey:(NSString *)key { |
9826 if (!key) { | 9775 if (!key) { |
9827 [NSException raise:NSInvalidArgumentException | 9776 [NSException raise:NSInvalidArgumentException |
9828 format:@"Attempting to add nil key to a Dictionary"]; | 9777 format:@"Attempting to add nil key to a Dictionary"]; |
9829 } | 9778 } |
9830 [_dictionary setObject:@(value) forKey:key]; | 9779 [_dictionary setObject:@(value) forKey:key]; |
9831 if (_autocreator) { | 9780 if (_autocreator) { |
9832 GPBAutocreatedDictionaryModified(_autocreator, self); | 9781 GPBAutocreatedDictionaryModified(_autocreator, self); |
9833 } | 9782 } |
9834 } | 9783 } |
9835 | 9784 |
9836 - (void)removeInt32ForKey:(NSString *)aKey { | 9785 - (void)removeValueForKey:(NSString *)aKey { |
9837 [_dictionary removeObjectForKey:aKey]; | 9786 [_dictionary removeObjectForKey:aKey]; |
9838 } | 9787 } |
9839 | 9788 |
9840 - (void)removeAll { | 9789 - (void)removeAll { |
9841 [_dictionary removeAllObjects]; | 9790 [_dictionary removeAllObjects]; |
9842 } | 9791 } |
9843 | 9792 |
9844 @end | 9793 @end |
9845 | 9794 |
9846 #pragma mark - String -> UInt64 | 9795 #pragma mark - String -> UInt64 |
9847 | 9796 |
9848 @implementation GPBStringUInt64Dictionary { | 9797 @implementation GPBStringUInt64Dictionary { |
9849 @package | 9798 @package |
9850 NSMutableDictionary *_dictionary; | 9799 NSMutableDictionary *_dictionary; |
9851 } | 9800 } |
9852 | 9801 |
9853 + (instancetype)dictionary { | 9802 + (instancetype)dictionary { |
9854 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; | 9803 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
9855 } | 9804 } |
9856 | 9805 |
9857 + (instancetype)dictionaryWithUInt64:(uint64_t)value | 9806 + (instancetype)dictionaryWithValue:(uint64_t)value |
9858 forKey:(NSString *)key { | 9807 forKey:(NSString *)key { |
9859 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 9808 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
9860 // on to get the type correct. | 9809 // on to get the type correct. |
9861 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithUInt64s:&value | 9810 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithValues:&value |
9862 forKeys:&key | 9811 forKeys:&key |
9863 count:1] autorelea
se]; | 9812 count:1] autoreleas
e]; |
9864 } | 9813 } |
9865 | 9814 |
9866 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values | 9815 + (instancetype)dictionaryWithValues:(const uint64_t [])values |
9867 forKeys:(const NSString * [])keys | 9816 forKeys:(const NSString * [])keys |
9868 count:(NSUInteger)count { | 9817 count:(NSUInteger)count { |
9869 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 9818 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
9870 // on to get the type correct. | 9819 // on to get the type correct. |
9871 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithUInt64s:values | 9820 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithValues:values |
9872 forKeys:keys | 9821 forKeys:keys |
9873 count:count] autore
lease]; | 9822 count:count] autore
lease]; |
9874 } | 9823 } |
9875 | 9824 |
9876 + (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary
{ | 9825 + (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary
{ |
9877 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 9826 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
9878 // on to get the type correct. | 9827 // on to get the type correct. |
9879 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 9828 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
9880 } | 9829 } |
9881 | 9830 |
9882 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 9831 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
9883 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 9832 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
9884 } | 9833 } |
9885 | 9834 |
9886 - (instancetype)init { | 9835 - (instancetype)init { |
9887 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 9836 return [self initWithValues:NULL forKeys:NULL count:0]; |
9888 } | 9837 } |
9889 | 9838 |
9890 - (instancetype)initWithUInt64s:(const uint64_t [])values | 9839 - (instancetype)initWithValues:(const uint64_t [])values |
9891 forKeys:(const NSString * [])keys | 9840 forKeys:(const NSString * [])keys |
9892 count:(NSUInteger)count { | 9841 count:(NSUInteger)count { |
9893 self = [super init]; | 9842 self = [super init]; |
9894 if (self) { | 9843 if (self) { |
9895 _dictionary = [[NSMutableDictionary alloc] init]; | 9844 _dictionary = [[NSMutableDictionary alloc] init]; |
9896 if (count && values && keys) { | 9845 if (count && values && keys) { |
9897 for (NSUInteger i = 0; i < count; ++i) { | 9846 for (NSUInteger i = 0; i < count; ++i) { |
9898 if (!keys[i]) { | 9847 if (!keys[i]) { |
9899 [NSException raise:NSInvalidArgumentException | 9848 [NSException raise:NSInvalidArgumentException |
9900 format:@"Attempting to add nil key to a Dictionary"]; | 9849 format:@"Attempting to add nil key to a Dictionary"]; |
9901 } | 9850 } |
9902 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 9851 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
9903 } | 9852 } |
9904 } | 9853 } |
9905 } | 9854 } |
9906 return self; | 9855 return self; |
9907 } | 9856 } |
9908 | 9857 |
9909 - (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary { | 9858 - (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary { |
9910 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; | 9859 self = [self initWithValues:NULL forKeys:NULL count:0]; |
9911 if (self) { | 9860 if (self) { |
9912 if (dictionary) { | 9861 if (dictionary) { |
9913 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 9862 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
9914 } | 9863 } |
9915 } | 9864 } |
9916 return self; | 9865 return self; |
9917 } | 9866 } |
9918 | 9867 |
9919 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 9868 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
9920 #pragma unused(numItems) | 9869 #pragma unused(numItems) |
9921 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 9870 return [self initWithValues:NULL forKeys:NULL count:0]; |
9922 } | 9871 } |
9923 | 9872 |
9924 - (void)dealloc { | 9873 - (void)dealloc { |
9925 NSAssert(!_autocreator, | 9874 NSAssert(!_autocreator, |
9926 @"%@: Autocreator must be cleared before release, autocreator: %@", | 9875 @"%@: Autocreator must be cleared before release, autocreator: %@", |
9927 [self class], _autocreator); | 9876 [self class], _autocreator); |
9928 [_dictionary release]; | 9877 [_dictionary release]; |
9929 [super dealloc]; | 9878 [super dealloc]; |
9930 } | 9879 } |
9931 | 9880 |
9932 - (instancetype)copyWithZone:(NSZone *)zone { | 9881 - (instancetype)copyWithZone:(NSZone *)zone { |
9933 return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; | 9882 return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; |
9934 } | 9883 } |
9935 | 9884 |
9936 - (BOOL)isEqual:(id)other { | 9885 - (BOOL)isEqual:(GPBStringUInt64Dictionary *)other { |
9937 if (self == other) { | 9886 if (self == other) { |
9938 return YES; | 9887 return YES; |
9939 } | 9888 } |
9940 if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) { | 9889 if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) { |
9941 return NO; | 9890 return NO; |
9942 } | 9891 } |
9943 GPBStringUInt64Dictionary *otherDictionary = other; | 9892 return [_dictionary isEqual:other->_dictionary]; |
9944 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
9945 } | 9893 } |
9946 | 9894 |
9947 - (NSUInteger)hash { | 9895 - (NSUInteger)hash { |
9948 return _dictionary.count; | 9896 return _dictionary.count; |
9949 } | 9897 } |
9950 | 9898 |
9951 - (NSString *)description { | 9899 - (NSString *)description { |
9952 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 9900 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
9953 } | 9901 } |
9954 | 9902 |
9955 - (NSUInteger)count { | 9903 - (NSUInteger)count { |
9956 return _dictionary.count; | 9904 return _dictionary.count; |
9957 } | 9905 } |
9958 | 9906 |
9959 - (void)enumerateKeysAndUInt64sUsingBlock: | 9907 - (void)enumerateKeysAndValuesUsingBlock: |
9960 (void (^)(NSString *key, uint64_t value, BOOL *stop))block { | 9908 (void (^)(NSString *key, uint64_t value, BOOL *stop))block { |
9961 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 9909 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
9962 NSNumber *aValue, | 9910 NSNumber *aValue, |
9963 BOOL *stop) { | 9911 BOOL *stop) { |
9964 block(aKey, [aValue unsignedLongLongValue], stop); | 9912 block(aKey, [aValue unsignedLongLongValue], stop); |
9965 }]; | 9913 }]; |
9966 } | 9914 } |
9967 | 9915 |
9968 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 9916 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
9969 NSUInteger count = _dictionary.count; | 9917 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10007 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | 9955 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); |
10008 }]; | 9956 }]; |
10009 } | 9957 } |
10010 | 9958 |
10011 - (void)setGPBGenericValue:(GPBGenericValue *)value | 9959 - (void)setGPBGenericValue:(GPBGenericValue *)value |
10012 forGPBGenericValueKey:(GPBGenericValue *)key { | 9960 forGPBGenericValueKey:(GPBGenericValue *)key { |
10013 [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString]; | 9961 [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString]; |
10014 } | 9962 } |
10015 | 9963 |
10016 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 9964 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
10017 [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, BOOL
*stop) { | 9965 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, uint64_t value, BOOL *
stop) { |
10018 #pragma unused(stop) | 9966 #pragma unused(stop) |
10019 block(key, [NSString stringWithFormat:@"%llu", value]); | 9967 block(key, [NSString stringWithFormat:@"%llu", value]); |
10020 }]; | 9968 }]; |
10021 } | 9969 } |
10022 | 9970 |
10023 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key { | 9971 - (BOOL)valueForKey:(NSString *)key value:(uint64_t *)value { |
10024 NSNumber *wrapped = [_dictionary objectForKey:key]; | 9972 NSNumber *wrapped = [_dictionary objectForKey:key]; |
10025 if (wrapped && value) { | 9973 if (wrapped && value) { |
10026 *value = [wrapped unsignedLongLongValue]; | 9974 *value = [wrapped unsignedLongLongValue]; |
10027 } | 9975 } |
10028 return (wrapped != NULL); | 9976 return (wrapped != NULL); |
10029 } | 9977 } |
10030 | 9978 |
10031 - (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary { | 9979 - (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary { |
10032 if (otherDictionary) { | 9980 if (otherDictionary) { |
10033 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 9981 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
10034 if (_autocreator) { | 9982 if (_autocreator) { |
10035 GPBAutocreatedDictionaryModified(_autocreator, self); | 9983 GPBAutocreatedDictionaryModified(_autocreator, self); |
10036 } | 9984 } |
10037 } | 9985 } |
10038 } | 9986 } |
10039 | 9987 |
10040 - (void)setUInt64:(uint64_t)value forKey:(NSString *)key { | 9988 - (void)setValue:(uint64_t)value forKey:(NSString *)key { |
10041 if (!key) { | 9989 if (!key) { |
10042 [NSException raise:NSInvalidArgumentException | 9990 [NSException raise:NSInvalidArgumentException |
10043 format:@"Attempting to add nil key to a Dictionary"]; | 9991 format:@"Attempting to add nil key to a Dictionary"]; |
10044 } | 9992 } |
10045 [_dictionary setObject:@(value) forKey:key]; | 9993 [_dictionary setObject:@(value) forKey:key]; |
10046 if (_autocreator) { | 9994 if (_autocreator) { |
10047 GPBAutocreatedDictionaryModified(_autocreator, self); | 9995 GPBAutocreatedDictionaryModified(_autocreator, self); |
10048 } | 9996 } |
10049 } | 9997 } |
10050 | 9998 |
10051 - (void)removeUInt64ForKey:(NSString *)aKey { | 9999 - (void)removeValueForKey:(NSString *)aKey { |
10052 [_dictionary removeObjectForKey:aKey]; | 10000 [_dictionary removeObjectForKey:aKey]; |
10053 } | 10001 } |
10054 | 10002 |
10055 - (void)removeAll { | 10003 - (void)removeAll { |
10056 [_dictionary removeAllObjects]; | 10004 [_dictionary removeAllObjects]; |
10057 } | 10005 } |
10058 | 10006 |
10059 @end | 10007 @end |
10060 | 10008 |
10061 #pragma mark - String -> Int64 | 10009 #pragma mark - String -> Int64 |
10062 | 10010 |
10063 @implementation GPBStringInt64Dictionary { | 10011 @implementation GPBStringInt64Dictionary { |
10064 @package | 10012 @package |
10065 NSMutableDictionary *_dictionary; | 10013 NSMutableDictionary *_dictionary; |
10066 } | 10014 } |
10067 | 10015 |
10068 + (instancetype)dictionary { | 10016 + (instancetype)dictionary { |
10069 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; | 10017 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
10070 } | 10018 } |
10071 | 10019 |
10072 + (instancetype)dictionaryWithInt64:(int64_t)value | 10020 + (instancetype)dictionaryWithValue:(int64_t)value |
10073 forKey:(NSString *)key { | 10021 forKey:(NSString *)key { |
10074 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 10022 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
10075 // on to get the type correct. | 10023 // on to get the type correct. |
10076 return [[(GPBStringInt64Dictionary*)[self alloc] initWithInt64s:&value | 10024 return [[(GPBStringInt64Dictionary*)[self alloc] initWithValues:&value |
10077 forKeys:&key | 10025 forKeys:&key |
10078 count:1] autorelease
]; | 10026 count:1] autorelease
]; |
10079 } | 10027 } |
10080 | 10028 |
10081 + (instancetype)dictionaryWithInt64s:(const int64_t [])values | 10029 + (instancetype)dictionaryWithValues:(const int64_t [])values |
10082 forKeys:(const NSString * [])keys | 10030 forKeys:(const NSString * [])keys |
10083 count:(NSUInteger)count { | 10031 count:(NSUInteger)count { |
10084 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 10032 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
10085 // on to get the type correct. | 10033 // on to get the type correct. |
10086 return [[(GPBStringInt64Dictionary*)[self alloc] initWithInt64s:values | 10034 return [[(GPBStringInt64Dictionary*)[self alloc] initWithValues:values |
10087 forKeys:keys | 10035 forKeys:keys |
10088 count:count] autorel
ease]; | 10036 count:count] autorel
ease]; |
10089 } | 10037 } |
10090 | 10038 |
10091 + (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary
{ | 10039 + (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary
{ |
10092 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 10040 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
10093 // on to get the type correct. | 10041 // on to get the type correct. |
10094 return [[(GPBStringInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 10042 return [[(GPBStringInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
10095 } | 10043 } |
10096 | 10044 |
10097 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 10045 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
10098 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 10046 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
10099 } | 10047 } |
10100 | 10048 |
10101 - (instancetype)init { | 10049 - (instancetype)init { |
10102 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 10050 return [self initWithValues:NULL forKeys:NULL count:0]; |
10103 } | 10051 } |
10104 | 10052 |
10105 - (instancetype)initWithInt64s:(const int64_t [])values | 10053 - (instancetype)initWithValues:(const int64_t [])values |
10106 forKeys:(const NSString * [])keys | 10054 forKeys:(const NSString * [])keys |
10107 count:(NSUInteger)count { | 10055 count:(NSUInteger)count { |
10108 self = [super init]; | 10056 self = [super init]; |
10109 if (self) { | 10057 if (self) { |
10110 _dictionary = [[NSMutableDictionary alloc] init]; | 10058 _dictionary = [[NSMutableDictionary alloc] init]; |
10111 if (count && values && keys) { | 10059 if (count && values && keys) { |
10112 for (NSUInteger i = 0; i < count; ++i) { | 10060 for (NSUInteger i = 0; i < count; ++i) { |
10113 if (!keys[i]) { | 10061 if (!keys[i]) { |
10114 [NSException raise:NSInvalidArgumentException | 10062 [NSException raise:NSInvalidArgumentException |
10115 format:@"Attempting to add nil key to a Dictionary"]; | 10063 format:@"Attempting to add nil key to a Dictionary"]; |
10116 } | 10064 } |
10117 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 10065 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
10118 } | 10066 } |
10119 } | 10067 } |
10120 } | 10068 } |
10121 return self; | 10069 return self; |
10122 } | 10070 } |
10123 | 10071 |
10124 - (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary { | 10072 - (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary { |
10125 self = [self initWithInt64s:NULL forKeys:NULL count:0]; | 10073 self = [self initWithValues:NULL forKeys:NULL count:0]; |
10126 if (self) { | 10074 if (self) { |
10127 if (dictionary) { | 10075 if (dictionary) { |
10128 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 10076 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
10129 } | 10077 } |
10130 } | 10078 } |
10131 return self; | 10079 return self; |
10132 } | 10080 } |
10133 | 10081 |
10134 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 10082 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
10135 #pragma unused(numItems) | 10083 #pragma unused(numItems) |
10136 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 10084 return [self initWithValues:NULL forKeys:NULL count:0]; |
10137 } | 10085 } |
10138 | 10086 |
10139 - (void)dealloc { | 10087 - (void)dealloc { |
10140 NSAssert(!_autocreator, | 10088 NSAssert(!_autocreator, |
10141 @"%@: Autocreator must be cleared before release, autocreator: %@", | 10089 @"%@: Autocreator must be cleared before release, autocreator: %@", |
10142 [self class], _autocreator); | 10090 [self class], _autocreator); |
10143 [_dictionary release]; | 10091 [_dictionary release]; |
10144 [super dealloc]; | 10092 [super dealloc]; |
10145 } | 10093 } |
10146 | 10094 |
10147 - (instancetype)copyWithZone:(NSZone *)zone { | 10095 - (instancetype)copyWithZone:(NSZone *)zone { |
10148 return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; | 10096 return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; |
10149 } | 10097 } |
10150 | 10098 |
10151 - (BOOL)isEqual:(id)other { | 10099 - (BOOL)isEqual:(GPBStringInt64Dictionary *)other { |
10152 if (self == other) { | 10100 if (self == other) { |
10153 return YES; | 10101 return YES; |
10154 } | 10102 } |
10155 if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) { | 10103 if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) { |
10156 return NO; | 10104 return NO; |
10157 } | 10105 } |
10158 GPBStringInt64Dictionary *otherDictionary = other; | 10106 return [_dictionary isEqual:other->_dictionary]; |
10159 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
10160 } | 10107 } |
10161 | 10108 |
10162 - (NSUInteger)hash { | 10109 - (NSUInteger)hash { |
10163 return _dictionary.count; | 10110 return _dictionary.count; |
10164 } | 10111 } |
10165 | 10112 |
10166 - (NSString *)description { | 10113 - (NSString *)description { |
10167 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 10114 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
10168 } | 10115 } |
10169 | 10116 |
10170 - (NSUInteger)count { | 10117 - (NSUInteger)count { |
10171 return _dictionary.count; | 10118 return _dictionary.count; |
10172 } | 10119 } |
10173 | 10120 |
10174 - (void)enumerateKeysAndInt64sUsingBlock: | 10121 - (void)enumerateKeysAndValuesUsingBlock: |
10175 (void (^)(NSString *key, int64_t value, BOOL *stop))block { | 10122 (void (^)(NSString *key, int64_t value, BOOL *stop))block { |
10176 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 10123 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
10177 NSNumber *aValue, | 10124 NSNumber *aValue, |
10178 BOOL *stop) { | 10125 BOOL *stop) { |
10179 block(aKey, [aValue longLongValue], stop); | 10126 block(aKey, [aValue longLongValue], stop); |
10180 }]; | 10127 }]; |
10181 } | 10128 } |
10182 | 10129 |
10183 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 10130 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
10184 NSUInteger count = _dictionary.count; | 10131 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10222 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | 10169 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); |
10223 }]; | 10170 }]; |
10224 } | 10171 } |
10225 | 10172 |
10226 - (void)setGPBGenericValue:(GPBGenericValue *)value | 10173 - (void)setGPBGenericValue:(GPBGenericValue *)value |
10227 forGPBGenericValueKey:(GPBGenericValue *)key { | 10174 forGPBGenericValueKey:(GPBGenericValue *)key { |
10228 [_dictionary setObject:@(value->valueInt64) forKey:key->valueString]; | 10175 [_dictionary setObject:@(value->valueInt64) forKey:key->valueString]; |
10229 } | 10176 } |
10230 | 10177 |
10231 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 10178 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
10232 [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, BOOL *s
top) { | 10179 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, int64_t value, BOOL *s
top) { |
10233 #pragma unused(stop) | 10180 #pragma unused(stop) |
10234 block(key, [NSString stringWithFormat:@"%lld", value]); | 10181 block(key, [NSString stringWithFormat:@"%lld", value]); |
10235 }]; | 10182 }]; |
10236 } | 10183 } |
10237 | 10184 |
10238 - (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key { | 10185 - (BOOL)valueForKey:(NSString *)key value:(int64_t *)value { |
10239 NSNumber *wrapped = [_dictionary objectForKey:key]; | 10186 NSNumber *wrapped = [_dictionary objectForKey:key]; |
10240 if (wrapped && value) { | 10187 if (wrapped && value) { |
10241 *value = [wrapped longLongValue]; | 10188 *value = [wrapped longLongValue]; |
10242 } | 10189 } |
10243 return (wrapped != NULL); | 10190 return (wrapped != NULL); |
10244 } | 10191 } |
10245 | 10192 |
10246 - (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary { | 10193 - (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary { |
10247 if (otherDictionary) { | 10194 if (otherDictionary) { |
10248 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 10195 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
10249 if (_autocreator) { | 10196 if (_autocreator) { |
10250 GPBAutocreatedDictionaryModified(_autocreator, self); | 10197 GPBAutocreatedDictionaryModified(_autocreator, self); |
10251 } | 10198 } |
10252 } | 10199 } |
10253 } | 10200 } |
10254 | 10201 |
10255 - (void)setInt64:(int64_t)value forKey:(NSString *)key { | 10202 - (void)setValue:(int64_t)value forKey:(NSString *)key { |
10256 if (!key) { | 10203 if (!key) { |
10257 [NSException raise:NSInvalidArgumentException | 10204 [NSException raise:NSInvalidArgumentException |
10258 format:@"Attempting to add nil key to a Dictionary"]; | 10205 format:@"Attempting to add nil key to a Dictionary"]; |
10259 } | 10206 } |
10260 [_dictionary setObject:@(value) forKey:key]; | 10207 [_dictionary setObject:@(value) forKey:key]; |
10261 if (_autocreator) { | 10208 if (_autocreator) { |
10262 GPBAutocreatedDictionaryModified(_autocreator, self); | 10209 GPBAutocreatedDictionaryModified(_autocreator, self); |
10263 } | 10210 } |
10264 } | 10211 } |
10265 | 10212 |
10266 - (void)removeInt64ForKey:(NSString *)aKey { | 10213 - (void)removeValueForKey:(NSString *)aKey { |
10267 [_dictionary removeObjectForKey:aKey]; | 10214 [_dictionary removeObjectForKey:aKey]; |
10268 } | 10215 } |
10269 | 10216 |
10270 - (void)removeAll { | 10217 - (void)removeAll { |
10271 [_dictionary removeAllObjects]; | 10218 [_dictionary removeAllObjects]; |
10272 } | 10219 } |
10273 | 10220 |
10274 @end | 10221 @end |
10275 | 10222 |
10276 #pragma mark - String -> Bool | 10223 #pragma mark - String -> Bool |
10277 | 10224 |
10278 @implementation GPBStringBoolDictionary { | 10225 @implementation GPBStringBoolDictionary { |
10279 @package | 10226 @package |
10280 NSMutableDictionary *_dictionary; | 10227 NSMutableDictionary *_dictionary; |
10281 } | 10228 } |
10282 | 10229 |
10283 + (instancetype)dictionary { | 10230 + (instancetype)dictionary { |
10284 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; | 10231 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
10285 } | 10232 } |
10286 | 10233 |
10287 + (instancetype)dictionaryWithBool:(BOOL)value | 10234 + (instancetype)dictionaryWithValue:(BOOL)value |
10288 forKey:(NSString *)key { | 10235 forKey:(NSString *)key { |
10289 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 10236 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
10290 // on to get the type correct. | 10237 // on to get the type correct. |
10291 return [[(GPBStringBoolDictionary*)[self alloc] initWithBools:&value | 10238 return [[(GPBStringBoolDictionary*)[self alloc] initWithValues:&value |
10292 forKeys:&key | 10239 forKeys:&key |
10293 count:1] autorelease]; | 10240 count:1] autorelease]
; |
10294 } | 10241 } |
10295 | 10242 |
10296 + (instancetype)dictionaryWithBools:(const BOOL [])values | 10243 + (instancetype)dictionaryWithValues:(const BOOL [])values |
10297 forKeys:(const NSString * [])keys | 10244 forKeys:(const NSString * [])keys |
10298 count:(NSUInteger)count { | 10245 count:(NSUInteger)count { |
10299 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 10246 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
10300 // on to get the type correct. | 10247 // on to get the type correct. |
10301 return [[(GPBStringBoolDictionary*)[self alloc] initWithBools:values | 10248 return [[(GPBStringBoolDictionary*)[self alloc] initWithValues:values |
10302 forKeys:keys | 10249 forKeys:keys |
10303 count:count] autorele
ase]; | 10250 count:count] autorele
ase]; |
10304 } | 10251 } |
10305 | 10252 |
10306 + (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary { | 10253 + (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary { |
10307 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 10254 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
10308 // on to get the type correct. | 10255 // on to get the type correct. |
10309 return [[(GPBStringBoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 10256 return [[(GPBStringBoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
10310 } | 10257 } |
10311 | 10258 |
10312 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 10259 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
10313 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 10260 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
10314 } | 10261 } |
10315 | 10262 |
10316 - (instancetype)init { | 10263 - (instancetype)init { |
10317 return [self initWithBools:NULL forKeys:NULL count:0]; | 10264 return [self initWithValues:NULL forKeys:NULL count:0]; |
10318 } | 10265 } |
10319 | 10266 |
10320 - (instancetype)initWithBools:(const BOOL [])values | 10267 - (instancetype)initWithValues:(const BOOL [])values |
10321 forKeys:(const NSString * [])keys | 10268 forKeys:(const NSString * [])keys |
10322 count:(NSUInteger)count { | 10269 count:(NSUInteger)count { |
10323 self = [super init]; | 10270 self = [super init]; |
10324 if (self) { | 10271 if (self) { |
10325 _dictionary = [[NSMutableDictionary alloc] init]; | 10272 _dictionary = [[NSMutableDictionary alloc] init]; |
10326 if (count && values && keys) { | 10273 if (count && values && keys) { |
10327 for (NSUInteger i = 0; i < count; ++i) { | 10274 for (NSUInteger i = 0; i < count; ++i) { |
10328 if (!keys[i]) { | 10275 if (!keys[i]) { |
10329 [NSException raise:NSInvalidArgumentException | 10276 [NSException raise:NSInvalidArgumentException |
10330 format:@"Attempting to add nil key to a Dictionary"]; | 10277 format:@"Attempting to add nil key to a Dictionary"]; |
10331 } | 10278 } |
10332 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 10279 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
10333 } | 10280 } |
10334 } | 10281 } |
10335 } | 10282 } |
10336 return self; | 10283 return self; |
10337 } | 10284 } |
10338 | 10285 |
10339 - (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary { | 10286 - (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary { |
10340 self = [self initWithBools:NULL forKeys:NULL count:0]; | 10287 self = [self initWithValues:NULL forKeys:NULL count:0]; |
10341 if (self) { | 10288 if (self) { |
10342 if (dictionary) { | 10289 if (dictionary) { |
10343 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 10290 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
10344 } | 10291 } |
10345 } | 10292 } |
10346 return self; | 10293 return self; |
10347 } | 10294 } |
10348 | 10295 |
10349 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 10296 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
10350 #pragma unused(numItems) | 10297 #pragma unused(numItems) |
10351 return [self initWithBools:NULL forKeys:NULL count:0]; | 10298 return [self initWithValues:NULL forKeys:NULL count:0]; |
10352 } | 10299 } |
10353 | 10300 |
10354 - (void)dealloc { | 10301 - (void)dealloc { |
10355 NSAssert(!_autocreator, | 10302 NSAssert(!_autocreator, |
10356 @"%@: Autocreator must be cleared before release, autocreator: %@", | 10303 @"%@: Autocreator must be cleared before release, autocreator: %@", |
10357 [self class], _autocreator); | 10304 [self class], _autocreator); |
10358 [_dictionary release]; | 10305 [_dictionary release]; |
10359 [super dealloc]; | 10306 [super dealloc]; |
10360 } | 10307 } |
10361 | 10308 |
10362 - (instancetype)copyWithZone:(NSZone *)zone { | 10309 - (instancetype)copyWithZone:(NSZone *)zone { |
10363 return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self]; | 10310 return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self]; |
10364 } | 10311 } |
10365 | 10312 |
10366 - (BOOL)isEqual:(id)other { | 10313 - (BOOL)isEqual:(GPBStringBoolDictionary *)other { |
10367 if (self == other) { | 10314 if (self == other) { |
10368 return YES; | 10315 return YES; |
10369 } | 10316 } |
10370 if (![other isKindOfClass:[GPBStringBoolDictionary class]]) { | 10317 if (![other isKindOfClass:[GPBStringBoolDictionary class]]) { |
10371 return NO; | 10318 return NO; |
10372 } | 10319 } |
10373 GPBStringBoolDictionary *otherDictionary = other; | 10320 return [_dictionary isEqual:other->_dictionary]; |
10374 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
10375 } | 10321 } |
10376 | 10322 |
10377 - (NSUInteger)hash { | 10323 - (NSUInteger)hash { |
10378 return _dictionary.count; | 10324 return _dictionary.count; |
10379 } | 10325 } |
10380 | 10326 |
10381 - (NSString *)description { | 10327 - (NSString *)description { |
10382 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 10328 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
10383 } | 10329 } |
10384 | 10330 |
10385 - (NSUInteger)count { | 10331 - (NSUInteger)count { |
10386 return _dictionary.count; | 10332 return _dictionary.count; |
10387 } | 10333 } |
10388 | 10334 |
10389 - (void)enumerateKeysAndBoolsUsingBlock: | 10335 - (void)enumerateKeysAndValuesUsingBlock: |
10390 (void (^)(NSString *key, BOOL value, BOOL *stop))block { | 10336 (void (^)(NSString *key, BOOL value, BOOL *stop))block { |
10391 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 10337 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
10392 NSNumber *aValue, | 10338 NSNumber *aValue, |
10393 BOOL *stop) { | 10339 BOOL *stop) { |
10394 block(aKey, [aValue boolValue], stop); | 10340 block(aKey, [aValue boolValue], stop); |
10395 }]; | 10341 }]; |
10396 } | 10342 } |
10397 | 10343 |
10398 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 10344 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
10399 NSUInteger count = _dictionary.count; | 10345 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10437 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | 10383 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); |
10438 }]; | 10384 }]; |
10439 } | 10385 } |
10440 | 10386 |
10441 - (void)setGPBGenericValue:(GPBGenericValue *)value | 10387 - (void)setGPBGenericValue:(GPBGenericValue *)value |
10442 forGPBGenericValueKey:(GPBGenericValue *)key { | 10388 forGPBGenericValueKey:(GPBGenericValue *)key { |
10443 [_dictionary setObject:@(value->valueBool) forKey:key->valueString]; | 10389 [_dictionary setObject:@(value->valueBool) forKey:key->valueString]; |
10444 } | 10390 } |
10445 | 10391 |
10446 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 10392 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
10447 [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, BOOL *stop)
{ | 10393 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, BOOL value, BOOL *stop
) { |
10448 #pragma unused(stop) | 10394 #pragma unused(stop) |
10449 block(key, (value ? @"true" : @"false")); | 10395 block(key, (value ? @"true" : @"false")); |
10450 }]; | 10396 }]; |
10451 } | 10397 } |
10452 | 10398 |
10453 - (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key { | 10399 - (BOOL)valueForKey:(NSString *)key value:(BOOL *)value { |
10454 NSNumber *wrapped = [_dictionary objectForKey:key]; | 10400 NSNumber *wrapped = [_dictionary objectForKey:key]; |
10455 if (wrapped && value) { | 10401 if (wrapped && value) { |
10456 *value = [wrapped boolValue]; | 10402 *value = [wrapped boolValue]; |
10457 } | 10403 } |
10458 return (wrapped != NULL); | 10404 return (wrapped != NULL); |
10459 } | 10405 } |
10460 | 10406 |
10461 - (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary { | 10407 - (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary { |
10462 if (otherDictionary) { | 10408 if (otherDictionary) { |
10463 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 10409 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
10464 if (_autocreator) { | 10410 if (_autocreator) { |
10465 GPBAutocreatedDictionaryModified(_autocreator, self); | 10411 GPBAutocreatedDictionaryModified(_autocreator, self); |
10466 } | 10412 } |
10467 } | 10413 } |
10468 } | 10414 } |
10469 | 10415 |
10470 - (void)setBool:(BOOL)value forKey:(NSString *)key { | 10416 - (void)setValue:(BOOL)value forKey:(NSString *)key { |
10471 if (!key) { | 10417 if (!key) { |
10472 [NSException raise:NSInvalidArgumentException | 10418 [NSException raise:NSInvalidArgumentException |
10473 format:@"Attempting to add nil key to a Dictionary"]; | 10419 format:@"Attempting to add nil key to a Dictionary"]; |
10474 } | 10420 } |
10475 [_dictionary setObject:@(value) forKey:key]; | 10421 [_dictionary setObject:@(value) forKey:key]; |
10476 if (_autocreator) { | 10422 if (_autocreator) { |
10477 GPBAutocreatedDictionaryModified(_autocreator, self); | 10423 GPBAutocreatedDictionaryModified(_autocreator, self); |
10478 } | 10424 } |
10479 } | 10425 } |
10480 | 10426 |
10481 - (void)removeBoolForKey:(NSString *)aKey { | 10427 - (void)removeValueForKey:(NSString *)aKey { |
10482 [_dictionary removeObjectForKey:aKey]; | 10428 [_dictionary removeObjectForKey:aKey]; |
10483 } | 10429 } |
10484 | 10430 |
10485 - (void)removeAll { | 10431 - (void)removeAll { |
10486 [_dictionary removeAllObjects]; | 10432 [_dictionary removeAllObjects]; |
10487 } | 10433 } |
10488 | 10434 |
10489 @end | 10435 @end |
10490 | 10436 |
10491 #pragma mark - String -> Float | 10437 #pragma mark - String -> Float |
10492 | 10438 |
10493 @implementation GPBStringFloatDictionary { | 10439 @implementation GPBStringFloatDictionary { |
10494 @package | 10440 @package |
10495 NSMutableDictionary *_dictionary; | 10441 NSMutableDictionary *_dictionary; |
10496 } | 10442 } |
10497 | 10443 |
10498 + (instancetype)dictionary { | 10444 + (instancetype)dictionary { |
10499 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; | 10445 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
10500 } | 10446 } |
10501 | 10447 |
10502 + (instancetype)dictionaryWithFloat:(float)value | 10448 + (instancetype)dictionaryWithValue:(float)value |
10503 forKey:(NSString *)key { | 10449 forKey:(NSString *)key { |
10504 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 10450 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
10505 // on to get the type correct. | 10451 // on to get the type correct. |
10506 return [[(GPBStringFloatDictionary*)[self alloc] initWithFloats:&value | 10452 return [[(GPBStringFloatDictionary*)[self alloc] initWithValues:&value |
10507 forKeys:&key | 10453 forKeys:&key |
10508 count:1] autorelease
]; | 10454 count:1] autorelease
]; |
10509 } | 10455 } |
10510 | 10456 |
10511 + (instancetype)dictionaryWithFloats:(const float [])values | 10457 + (instancetype)dictionaryWithValues:(const float [])values |
10512 forKeys:(const NSString * [])keys | 10458 forKeys:(const NSString * [])keys |
10513 count:(NSUInteger)count { | 10459 count:(NSUInteger)count { |
10514 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 10460 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
10515 // on to get the type correct. | 10461 // on to get the type correct. |
10516 return [[(GPBStringFloatDictionary*)[self alloc] initWithFloats:values | 10462 return [[(GPBStringFloatDictionary*)[self alloc] initWithValues:values |
10517 forKeys:keys | 10463 forKeys:keys |
10518 count:count] autorel
ease]; | 10464 count:count] autorel
ease]; |
10519 } | 10465 } |
10520 | 10466 |
10521 + (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary
{ | 10467 + (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary
{ |
10522 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 10468 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
10523 // on to get the type correct. | 10469 // on to get the type correct. |
10524 return [[(GPBStringFloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 10470 return [[(GPBStringFloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
10525 } | 10471 } |
10526 | 10472 |
10527 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 10473 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
10528 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 10474 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
10529 } | 10475 } |
10530 | 10476 |
10531 - (instancetype)init { | 10477 - (instancetype)init { |
10532 return [self initWithFloats:NULL forKeys:NULL count:0]; | 10478 return [self initWithValues:NULL forKeys:NULL count:0]; |
10533 } | 10479 } |
10534 | 10480 |
10535 - (instancetype)initWithFloats:(const float [])values | 10481 - (instancetype)initWithValues:(const float [])values |
10536 forKeys:(const NSString * [])keys | 10482 forKeys:(const NSString * [])keys |
10537 count:(NSUInteger)count { | 10483 count:(NSUInteger)count { |
10538 self = [super init]; | 10484 self = [super init]; |
10539 if (self) { | 10485 if (self) { |
10540 _dictionary = [[NSMutableDictionary alloc] init]; | 10486 _dictionary = [[NSMutableDictionary alloc] init]; |
10541 if (count && values && keys) { | 10487 if (count && values && keys) { |
10542 for (NSUInteger i = 0; i < count; ++i) { | 10488 for (NSUInteger i = 0; i < count; ++i) { |
10543 if (!keys[i]) { | 10489 if (!keys[i]) { |
10544 [NSException raise:NSInvalidArgumentException | 10490 [NSException raise:NSInvalidArgumentException |
10545 format:@"Attempting to add nil key to a Dictionary"]; | 10491 format:@"Attempting to add nil key to a Dictionary"]; |
10546 } | 10492 } |
10547 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 10493 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
10548 } | 10494 } |
10549 } | 10495 } |
10550 } | 10496 } |
10551 return self; | 10497 return self; |
10552 } | 10498 } |
10553 | 10499 |
10554 - (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary { | 10500 - (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary { |
10555 self = [self initWithFloats:NULL forKeys:NULL count:0]; | 10501 self = [self initWithValues:NULL forKeys:NULL count:0]; |
10556 if (self) { | 10502 if (self) { |
10557 if (dictionary) { | 10503 if (dictionary) { |
10558 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 10504 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
10559 } | 10505 } |
10560 } | 10506 } |
10561 return self; | 10507 return self; |
10562 } | 10508 } |
10563 | 10509 |
10564 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 10510 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
10565 #pragma unused(numItems) | 10511 #pragma unused(numItems) |
10566 return [self initWithFloats:NULL forKeys:NULL count:0]; | 10512 return [self initWithValues:NULL forKeys:NULL count:0]; |
10567 } | 10513 } |
10568 | 10514 |
10569 - (void)dealloc { | 10515 - (void)dealloc { |
10570 NSAssert(!_autocreator, | 10516 NSAssert(!_autocreator, |
10571 @"%@: Autocreator must be cleared before release, autocreator: %@", | 10517 @"%@: Autocreator must be cleared before release, autocreator: %@", |
10572 [self class], _autocreator); | 10518 [self class], _autocreator); |
10573 [_dictionary release]; | 10519 [_dictionary release]; |
10574 [super dealloc]; | 10520 [super dealloc]; |
10575 } | 10521 } |
10576 | 10522 |
10577 - (instancetype)copyWithZone:(NSZone *)zone { | 10523 - (instancetype)copyWithZone:(NSZone *)zone { |
10578 return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self]
; | 10524 return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self]
; |
10579 } | 10525 } |
10580 | 10526 |
10581 - (BOOL)isEqual:(id)other { | 10527 - (BOOL)isEqual:(GPBStringFloatDictionary *)other { |
10582 if (self == other) { | 10528 if (self == other) { |
10583 return YES; | 10529 return YES; |
10584 } | 10530 } |
10585 if (![other isKindOfClass:[GPBStringFloatDictionary class]]) { | 10531 if (![other isKindOfClass:[GPBStringFloatDictionary class]]) { |
10586 return NO; | 10532 return NO; |
10587 } | 10533 } |
10588 GPBStringFloatDictionary *otherDictionary = other; | 10534 return [_dictionary isEqual:other->_dictionary]; |
10589 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
10590 } | 10535 } |
10591 | 10536 |
10592 - (NSUInteger)hash { | 10537 - (NSUInteger)hash { |
10593 return _dictionary.count; | 10538 return _dictionary.count; |
10594 } | 10539 } |
10595 | 10540 |
10596 - (NSString *)description { | 10541 - (NSString *)description { |
10597 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 10542 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
10598 } | 10543 } |
10599 | 10544 |
10600 - (NSUInteger)count { | 10545 - (NSUInteger)count { |
10601 return _dictionary.count; | 10546 return _dictionary.count; |
10602 } | 10547 } |
10603 | 10548 |
10604 - (void)enumerateKeysAndFloatsUsingBlock: | 10549 - (void)enumerateKeysAndValuesUsingBlock: |
10605 (void (^)(NSString *key, float value, BOOL *stop))block { | 10550 (void (^)(NSString *key, float value, BOOL *stop))block { |
10606 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 10551 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
10607 NSNumber *aValue, | 10552 NSNumber *aValue, |
10608 BOOL *stop) { | 10553 BOOL *stop) { |
10609 block(aKey, [aValue floatValue], stop); | 10554 block(aKey, [aValue floatValue], stop); |
10610 }]; | 10555 }]; |
10611 } | 10556 } |
10612 | 10557 |
10613 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 10558 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
10614 NSUInteger count = _dictionary.count; | 10559 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10652 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | 10597 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); |
10653 }]; | 10598 }]; |
10654 } | 10599 } |
10655 | 10600 |
10656 - (void)setGPBGenericValue:(GPBGenericValue *)value | 10601 - (void)setGPBGenericValue:(GPBGenericValue *)value |
10657 forGPBGenericValueKey:(GPBGenericValue *)key { | 10602 forGPBGenericValueKey:(GPBGenericValue *)key { |
10658 [_dictionary setObject:@(value->valueFloat) forKey:key->valueString]; | 10603 [_dictionary setObject:@(value->valueFloat) forKey:key->valueString]; |
10659 } | 10604 } |
10660 | 10605 |
10661 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 10606 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
10662 [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, BOOL *sto
p) { | 10607 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, float value, BOOL *sto
p) { |
10663 #pragma unused(stop) | 10608 #pragma unused(stop) |
10664 block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); | 10609 block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); |
10665 }]; | 10610 }]; |
10666 } | 10611 } |
10667 | 10612 |
10668 - (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key { | 10613 - (BOOL)valueForKey:(NSString *)key value:(float *)value { |
10669 NSNumber *wrapped = [_dictionary objectForKey:key]; | 10614 NSNumber *wrapped = [_dictionary objectForKey:key]; |
10670 if (wrapped && value) { | 10615 if (wrapped && value) { |
10671 *value = [wrapped floatValue]; | 10616 *value = [wrapped floatValue]; |
10672 } | 10617 } |
10673 return (wrapped != NULL); | 10618 return (wrapped != NULL); |
10674 } | 10619 } |
10675 | 10620 |
10676 - (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary { | 10621 - (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary { |
10677 if (otherDictionary) { | 10622 if (otherDictionary) { |
10678 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 10623 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
10679 if (_autocreator) { | 10624 if (_autocreator) { |
10680 GPBAutocreatedDictionaryModified(_autocreator, self); | 10625 GPBAutocreatedDictionaryModified(_autocreator, self); |
10681 } | 10626 } |
10682 } | 10627 } |
10683 } | 10628 } |
10684 | 10629 |
10685 - (void)setFloat:(float)value forKey:(NSString *)key { | 10630 - (void)setValue:(float)value forKey:(NSString *)key { |
10686 if (!key) { | 10631 if (!key) { |
10687 [NSException raise:NSInvalidArgumentException | 10632 [NSException raise:NSInvalidArgumentException |
10688 format:@"Attempting to add nil key to a Dictionary"]; | 10633 format:@"Attempting to add nil key to a Dictionary"]; |
10689 } | 10634 } |
10690 [_dictionary setObject:@(value) forKey:key]; | 10635 [_dictionary setObject:@(value) forKey:key]; |
10691 if (_autocreator) { | 10636 if (_autocreator) { |
10692 GPBAutocreatedDictionaryModified(_autocreator, self); | 10637 GPBAutocreatedDictionaryModified(_autocreator, self); |
10693 } | 10638 } |
10694 } | 10639 } |
10695 | 10640 |
10696 - (void)removeFloatForKey:(NSString *)aKey { | 10641 - (void)removeValueForKey:(NSString *)aKey { |
10697 [_dictionary removeObjectForKey:aKey]; | 10642 [_dictionary removeObjectForKey:aKey]; |
10698 } | 10643 } |
10699 | 10644 |
10700 - (void)removeAll { | 10645 - (void)removeAll { |
10701 [_dictionary removeAllObjects]; | 10646 [_dictionary removeAllObjects]; |
10702 } | 10647 } |
10703 | 10648 |
10704 @end | 10649 @end |
10705 | 10650 |
10706 #pragma mark - String -> Double | 10651 #pragma mark - String -> Double |
10707 | 10652 |
10708 @implementation GPBStringDoubleDictionary { | 10653 @implementation GPBStringDoubleDictionary { |
10709 @package | 10654 @package |
10710 NSMutableDictionary *_dictionary; | 10655 NSMutableDictionary *_dictionary; |
10711 } | 10656 } |
10712 | 10657 |
10713 + (instancetype)dictionary { | 10658 + (instancetype)dictionary { |
10714 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; | 10659 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
10715 } | 10660 } |
10716 | 10661 |
10717 + (instancetype)dictionaryWithDouble:(double)value | 10662 + (instancetype)dictionaryWithValue:(double)value |
10718 forKey:(NSString *)key { | 10663 forKey:(NSString *)key { |
10719 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 10664 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
10720 // on to get the type correct. | 10665 // on to get the type correct. |
10721 return [[(GPBStringDoubleDictionary*)[self alloc] initWithDoubles:&value | 10666 return [[(GPBStringDoubleDictionary*)[self alloc] initWithValues:&value |
10722 forKeys:&key | 10667 forKeys:&key |
10723 count:1] autorelea
se]; | 10668 count:1] autoreleas
e]; |
10724 } | 10669 } |
10725 | 10670 |
10726 + (instancetype)dictionaryWithDoubles:(const double [])values | 10671 + (instancetype)dictionaryWithValues:(const double [])values |
10727 forKeys:(const NSString * [])keys | 10672 forKeys:(const NSString * [])keys |
10728 count:(NSUInteger)count { | 10673 count:(NSUInteger)count { |
10729 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 10674 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
10730 // on to get the type correct. | 10675 // on to get the type correct. |
10731 return [[(GPBStringDoubleDictionary*)[self alloc] initWithDoubles:values | 10676 return [[(GPBStringDoubleDictionary*)[self alloc] initWithValues:values |
10732 forKeys:keys | 10677 forKeys:keys |
10733 count:count] autore
lease]; | 10678 count:count] autore
lease]; |
10734 } | 10679 } |
10735 | 10680 |
10736 + (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary
{ | 10681 + (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary
{ |
10737 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 10682 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
10738 // on to get the type correct. | 10683 // on to get the type correct. |
10739 return [[(GPBStringDoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 10684 return [[(GPBStringDoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
10740 } | 10685 } |
10741 | 10686 |
10742 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 10687 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
10743 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 10688 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
10744 } | 10689 } |
10745 | 10690 |
10746 - (instancetype)init { | 10691 - (instancetype)init { |
10747 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 10692 return [self initWithValues:NULL forKeys:NULL count:0]; |
10748 } | 10693 } |
10749 | 10694 |
10750 - (instancetype)initWithDoubles:(const double [])values | 10695 - (instancetype)initWithValues:(const double [])values |
10751 forKeys:(const NSString * [])keys | 10696 forKeys:(const NSString * [])keys |
10752 count:(NSUInteger)count { | 10697 count:(NSUInteger)count { |
10753 self = [super init]; | 10698 self = [super init]; |
10754 if (self) { | 10699 if (self) { |
10755 _dictionary = [[NSMutableDictionary alloc] init]; | 10700 _dictionary = [[NSMutableDictionary alloc] init]; |
10756 if (count && values && keys) { | 10701 if (count && values && keys) { |
10757 for (NSUInteger i = 0; i < count; ++i) { | 10702 for (NSUInteger i = 0; i < count; ++i) { |
10758 if (!keys[i]) { | 10703 if (!keys[i]) { |
10759 [NSException raise:NSInvalidArgumentException | 10704 [NSException raise:NSInvalidArgumentException |
10760 format:@"Attempting to add nil key to a Dictionary"]; | 10705 format:@"Attempting to add nil key to a Dictionary"]; |
10761 } | 10706 } |
10762 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 10707 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
10763 } | 10708 } |
10764 } | 10709 } |
10765 } | 10710 } |
10766 return self; | 10711 return self; |
10767 } | 10712 } |
10768 | 10713 |
10769 - (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary { | 10714 - (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary { |
10770 self = [self initWithDoubles:NULL forKeys:NULL count:0]; | 10715 self = [self initWithValues:NULL forKeys:NULL count:0]; |
10771 if (self) { | 10716 if (self) { |
10772 if (dictionary) { | 10717 if (dictionary) { |
10773 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 10718 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
10774 } | 10719 } |
10775 } | 10720 } |
10776 return self; | 10721 return self; |
10777 } | 10722 } |
10778 | 10723 |
10779 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 10724 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
10780 #pragma unused(numItems) | 10725 #pragma unused(numItems) |
10781 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 10726 return [self initWithValues:NULL forKeys:NULL count:0]; |
10782 } | 10727 } |
10783 | 10728 |
10784 - (void)dealloc { | 10729 - (void)dealloc { |
10785 NSAssert(!_autocreator, | 10730 NSAssert(!_autocreator, |
10786 @"%@: Autocreator must be cleared before release, autocreator: %@", | 10731 @"%@: Autocreator must be cleared before release, autocreator: %@", |
10787 [self class], _autocreator); | 10732 [self class], _autocreator); |
10788 [_dictionary release]; | 10733 [_dictionary release]; |
10789 [super dealloc]; | 10734 [super dealloc]; |
10790 } | 10735 } |
10791 | 10736 |
10792 - (instancetype)copyWithZone:(NSZone *)zone { | 10737 - (instancetype)copyWithZone:(NSZone *)zone { |
10793 return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self
]; | 10738 return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self
]; |
10794 } | 10739 } |
10795 | 10740 |
10796 - (BOOL)isEqual:(id)other { | 10741 - (BOOL)isEqual:(GPBStringDoubleDictionary *)other { |
10797 if (self == other) { | 10742 if (self == other) { |
10798 return YES; | 10743 return YES; |
10799 } | 10744 } |
10800 if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) { | 10745 if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) { |
10801 return NO; | 10746 return NO; |
10802 } | 10747 } |
10803 GPBStringDoubleDictionary *otherDictionary = other; | 10748 return [_dictionary isEqual:other->_dictionary]; |
10804 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
10805 } | 10749 } |
10806 | 10750 |
10807 - (NSUInteger)hash { | 10751 - (NSUInteger)hash { |
10808 return _dictionary.count; | 10752 return _dictionary.count; |
10809 } | 10753 } |
10810 | 10754 |
10811 - (NSString *)description { | 10755 - (NSString *)description { |
10812 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 10756 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
10813 } | 10757 } |
10814 | 10758 |
10815 - (NSUInteger)count { | 10759 - (NSUInteger)count { |
10816 return _dictionary.count; | 10760 return _dictionary.count; |
10817 } | 10761 } |
10818 | 10762 |
10819 - (void)enumerateKeysAndDoublesUsingBlock: | 10763 - (void)enumerateKeysAndValuesUsingBlock: |
10820 (void (^)(NSString *key, double value, BOOL *stop))block { | 10764 (void (^)(NSString *key, double value, BOOL *stop))block { |
10821 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 10765 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
10822 NSNumber *aValue, | 10766 NSNumber *aValue, |
10823 BOOL *stop) { | 10767 BOOL *stop) { |
10824 block(aKey, [aValue doubleValue], stop); | 10768 block(aKey, [aValue doubleValue], stop); |
10825 }]; | 10769 }]; |
10826 } | 10770 } |
10827 | 10771 |
10828 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 10772 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
10829 NSUInteger count = _dictionary.count; | 10773 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10867 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | 10811 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); |
10868 }]; | 10812 }]; |
10869 } | 10813 } |
10870 | 10814 |
10871 - (void)setGPBGenericValue:(GPBGenericValue *)value | 10815 - (void)setGPBGenericValue:(GPBGenericValue *)value |
10872 forGPBGenericValueKey:(GPBGenericValue *)key { | 10816 forGPBGenericValueKey:(GPBGenericValue *)key { |
10873 [_dictionary setObject:@(value->valueDouble) forKey:key->valueString]; | 10817 [_dictionary setObject:@(value->valueDouble) forKey:key->valueString]; |
10874 } | 10818 } |
10875 | 10819 |
10876 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 10820 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
10877 [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, BOOL *s
top) { | 10821 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, double value, BOOL *st
op) { |
10878 #pragma unused(stop) | 10822 #pragma unused(stop) |
10879 block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); | 10823 block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); |
10880 }]; | 10824 }]; |
10881 } | 10825 } |
10882 | 10826 |
10883 - (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key { | 10827 - (BOOL)valueForKey:(NSString *)key value:(double *)value { |
10884 NSNumber *wrapped = [_dictionary objectForKey:key]; | 10828 NSNumber *wrapped = [_dictionary objectForKey:key]; |
10885 if (wrapped && value) { | 10829 if (wrapped && value) { |
10886 *value = [wrapped doubleValue]; | 10830 *value = [wrapped doubleValue]; |
10887 } | 10831 } |
10888 return (wrapped != NULL); | 10832 return (wrapped != NULL); |
10889 } | 10833 } |
10890 | 10834 |
10891 - (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary { | 10835 - (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary { |
10892 if (otherDictionary) { | 10836 if (otherDictionary) { |
10893 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 10837 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
10894 if (_autocreator) { | 10838 if (_autocreator) { |
10895 GPBAutocreatedDictionaryModified(_autocreator, self); | 10839 GPBAutocreatedDictionaryModified(_autocreator, self); |
10896 } | 10840 } |
10897 } | 10841 } |
10898 } | 10842 } |
10899 | 10843 |
10900 - (void)setDouble:(double)value forKey:(NSString *)key { | 10844 - (void)setValue:(double)value forKey:(NSString *)key { |
10901 if (!key) { | 10845 if (!key) { |
10902 [NSException raise:NSInvalidArgumentException | 10846 [NSException raise:NSInvalidArgumentException |
10903 format:@"Attempting to add nil key to a Dictionary"]; | 10847 format:@"Attempting to add nil key to a Dictionary"]; |
10904 } | 10848 } |
10905 [_dictionary setObject:@(value) forKey:key]; | 10849 [_dictionary setObject:@(value) forKey:key]; |
10906 if (_autocreator) { | 10850 if (_autocreator) { |
10907 GPBAutocreatedDictionaryModified(_autocreator, self); | 10851 GPBAutocreatedDictionaryModified(_autocreator, self); |
10908 } | 10852 } |
10909 } | 10853 } |
10910 | 10854 |
10911 - (void)removeDoubleForKey:(NSString *)aKey { | 10855 - (void)removeValueForKey:(NSString *)aKey { |
10912 [_dictionary removeObjectForKey:aKey]; | 10856 [_dictionary removeObjectForKey:aKey]; |
10913 } | 10857 } |
10914 | 10858 |
10915 - (void)removeAll { | 10859 - (void)removeAll { |
10916 [_dictionary removeAllObjects]; | 10860 [_dictionary removeAllObjects]; |
10917 } | 10861 } |
10918 | 10862 |
10919 @end | 10863 @end |
10920 | 10864 |
10921 #pragma mark - String -> Enum | 10865 #pragma mark - String -> Enum |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11029 @"%@: Autocreator must be cleared before release, autocreator: %@", | 10973 @"%@: Autocreator must be cleared before release, autocreator: %@", |
11030 [self class], _autocreator); | 10974 [self class], _autocreator); |
11031 [_dictionary release]; | 10975 [_dictionary release]; |
11032 [super dealloc]; | 10976 [super dealloc]; |
11033 } | 10977 } |
11034 | 10978 |
11035 - (instancetype)copyWithZone:(NSZone *)zone { | 10979 - (instancetype)copyWithZone:(NSZone *)zone { |
11036 return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self]; | 10980 return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self]; |
11037 } | 10981 } |
11038 | 10982 |
11039 - (BOOL)isEqual:(id)other { | 10983 - (BOOL)isEqual:(GPBStringEnumDictionary *)other { |
11040 if (self == other) { | 10984 if (self == other) { |
11041 return YES; | 10985 return YES; |
11042 } | 10986 } |
11043 if (![other isKindOfClass:[GPBStringEnumDictionary class]]) { | 10987 if (![other isKindOfClass:[GPBStringEnumDictionary class]]) { |
11044 return NO; | 10988 return NO; |
11045 } | 10989 } |
11046 GPBStringEnumDictionary *otherDictionary = other; | 10990 return [_dictionary isEqual:other->_dictionary]; |
11047 return [_dictionary isEqual:otherDictionary->_dictionary]; | |
11048 } | 10991 } |
11049 | 10992 |
11050 - (NSUInteger)hash { | 10993 - (NSUInteger)hash { |
11051 return _dictionary.count; | 10994 return _dictionary.count; |
11052 } | 10995 } |
11053 | 10996 |
11054 - (NSString *)description { | 10997 - (NSString *)description { |
11055 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 10998 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
11056 } | 10999 } |
11057 | 11000 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11128 [_dictionary setObject:@(value->valueEnum) forKey:key->valueString]; | 11071 [_dictionary setObject:@(value->valueEnum) forKey:key->valueString]; |
11129 } | 11072 } |
11130 | 11073 |
11131 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 11074 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
11132 [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL
*stop) { | 11075 [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL
*stop) { |
11133 #pragma unused(stop) | 11076 #pragma unused(stop) |
11134 block(key, @(value)); | 11077 block(key, @(value)); |
11135 }]; | 11078 }]; |
11136 } | 11079 } |
11137 | 11080 |
11138 - (BOOL)getEnum:(int32_t *)value forKey:(NSString *)key { | 11081 - (BOOL)valueForKey:(NSString *)key value:(int32_t *)value { |
11139 NSNumber *wrapped = [_dictionary objectForKey:key]; | 11082 NSNumber *wrapped = [_dictionary objectForKey:key]; |
11140 if (wrapped && value) { | 11083 if (wrapped && value) { |
11141 int32_t result = [wrapped intValue]; | 11084 int32_t result = [wrapped intValue]; |
11142 if (!_validationFunc(result)) { | 11085 if (!_validationFunc(result)) { |
11143 result = kGPBUnrecognizedEnumeratorValue; | 11086 result = kGPBUnrecognizedEnumeratorValue; |
11144 } | 11087 } |
11145 *value = result; | 11088 *value = result; |
11146 } | 11089 } |
11147 return (wrapped != NULL); | 11090 return (wrapped != NULL); |
11148 } | 11091 } |
11149 | 11092 |
11150 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(NSString *)key { | 11093 - (BOOL)valueForKey:(NSString *)key rawValue:(int32_t *)rawValue { |
11151 NSNumber *wrapped = [_dictionary objectForKey:key]; | 11094 NSNumber *wrapped = [_dictionary objectForKey:key]; |
11152 if (wrapped && rawValue) { | 11095 if (wrapped && rawValue) { |
11153 *rawValue = [wrapped intValue]; | 11096 *rawValue = [wrapped intValue]; |
11154 } | 11097 } |
11155 return (wrapped != NULL); | 11098 return (wrapped != NULL); |
11156 } | 11099 } |
11157 | 11100 |
11158 - (void)enumerateKeysAndEnumsUsingBlock: | 11101 - (void)enumerateKeysAndValuesUsingBlock: |
11159 (void (^)(NSString *key, int32_t value, BOOL *stop))block { | 11102 (void (^)(NSString *key, int32_t value, BOOL *stop))block { |
11160 GPBEnumValidationFunc func = _validationFunc; | 11103 GPBEnumValidationFunc func = _validationFunc; |
11161 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 11104 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
11162 NSNumber *aValue, | 11105 NSNumber *aValue, |
11163 BOOL *stop) { | 11106 BOOL *stop) { |
11164 int32_t unwrapped = [aValue intValue]; | 11107 int32_t unwrapped = [aValue intValue]; |
11165 if (!func(unwrapped)) { | 11108 if (!func(unwrapped)) { |
11166 unwrapped = kGPBUnrecognizedEnumeratorValue; | 11109 unwrapped = kGPBUnrecognizedEnumeratorValue; |
11167 } | 11110 } |
11168 block(aKey, unwrapped, stop); | 11111 block(aKey, unwrapped, stop); |
(...skipping 13 matching lines...) Expand all Loading... |
11182 if (!key) { | 11125 if (!key) { |
11183 [NSException raise:NSInvalidArgumentException | 11126 [NSException raise:NSInvalidArgumentException |
11184 format:@"Attempting to add nil key to a Dictionary"]; | 11127 format:@"Attempting to add nil key to a Dictionary"]; |
11185 } | 11128 } |
11186 [_dictionary setObject:@(value) forKey:key]; | 11129 [_dictionary setObject:@(value) forKey:key]; |
11187 if (_autocreator) { | 11130 if (_autocreator) { |
11188 GPBAutocreatedDictionaryModified(_autocreator, self); | 11131 GPBAutocreatedDictionaryModified(_autocreator, self); |
11189 } | 11132 } |
11190 } | 11133 } |
11191 | 11134 |
11192 - (void)removeEnumForKey:(NSString *)aKey { | 11135 - (void)removeValueForKey:(NSString *)aKey { |
11193 [_dictionary removeObjectForKey:aKey]; | 11136 [_dictionary removeObjectForKey:aKey]; |
11194 } | 11137 } |
11195 | 11138 |
11196 - (void)removeAll { | 11139 - (void)removeAll { |
11197 [_dictionary removeAllObjects]; | 11140 [_dictionary removeAllObjects]; |
11198 } | 11141 } |
11199 | 11142 |
11200 - (void)setEnum:(int32_t)value forKey:(NSString *)key { | 11143 - (void)setValue:(int32_t)value forKey:(NSString *)key { |
11201 if (!key) { | 11144 if (!key) { |
11202 [NSException raise:NSInvalidArgumentException | 11145 [NSException raise:NSInvalidArgumentException |
11203 format:@"Attempting to add nil key to a Dictionary"]; | 11146 format:@"Attempting to add nil key to a Dictionary"]; |
11204 } | 11147 } |
11205 if (!_validationFunc(value)) { | 11148 if (!_validationFunc(value)) { |
11206 [NSException raise:NSInvalidArgumentException | 11149 [NSException raise:NSInvalidArgumentException |
11207 format:@"GPBStringEnumDictionary: Attempt to set an unknown enum
value (%d)", | 11150 format:@"GPBStringEnumDictionary: Attempt to set an unknown enum
value (%d)", |
11208 value]; | 11151 value]; |
11209 } | 11152 } |
11210 | 11153 |
(...skipping 13 matching lines...) Expand all Loading... |
11224 | 11167 |
11225 #pragma mark - Bool -> UInt32 | 11168 #pragma mark - Bool -> UInt32 |
11226 | 11169 |
11227 @implementation GPBBoolUInt32Dictionary { | 11170 @implementation GPBBoolUInt32Dictionary { |
11228 @package | 11171 @package |
11229 uint32_t _values[2]; | 11172 uint32_t _values[2]; |
11230 BOOL _valueSet[2]; | 11173 BOOL _valueSet[2]; |
11231 } | 11174 } |
11232 | 11175 |
11233 + (instancetype)dictionary { | 11176 + (instancetype)dictionary { |
11234 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; | 11177 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
11235 } | 11178 } |
11236 | 11179 |
11237 + (instancetype)dictionaryWithUInt32:(uint32_t)value | 11180 + (instancetype)dictionaryWithValue:(uint32_t)value |
11238 forKey:(BOOL)key { | 11181 forKey:(BOOL)key { |
11239 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 11182 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
11240 // on to get the type correct. | 11183 // on to get the type correct. |
11241 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithUInt32s:&value | 11184 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithValues:&value |
11242 forKeys:&key | 11185 forKeys:&key |
11243 count:1] autorelease
]; | 11186 count:1] autorelease]
; |
11244 } | 11187 } |
11245 | 11188 |
11246 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values | 11189 + (instancetype)dictionaryWithValues:(const uint32_t [])values |
11247 forKeys:(const BOOL [])keys | 11190 forKeys:(const BOOL [])keys |
11248 count:(NSUInteger)count { | 11191 count:(NSUInteger)count { |
11249 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: | 11192 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
11250 // on to get the type correct. | 11193 // on to get the type correct. |
11251 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithUInt32s:values | 11194 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithValues:values |
11252 forKeys:keys | 11195 forKeys:keys |
11253 count:count] autorel
ease]; | 11196 count:count] autorele
ase]; |
11254 } | 11197 } |
11255 | 11198 |
11256 + (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { | 11199 + (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { |
11257 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 11200 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
11258 // on to get the type correct. | 11201 // on to get the type correct. |
11259 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 11202 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
11260 } | 11203 } |
11261 | 11204 |
11262 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 11205 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
11263 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 11206 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
11264 } | 11207 } |
11265 | 11208 |
11266 - (instancetype)init { | 11209 - (instancetype)init { |
11267 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 11210 return [self initWithValues:NULL forKeys:NULL count:0]; |
11268 } | 11211 } |
11269 | 11212 |
11270 - (instancetype)initWithUInt32s:(const uint32_t [])values | 11213 - (instancetype)initWithValues:(const uint32_t [])values |
11271 forKeys:(const BOOL [])keys | 11214 forKeys:(const BOOL [])keys |
11272 count:(NSUInteger)count { | 11215 count:(NSUInteger)count { |
11273 self = [super init]; | 11216 self = [super init]; |
11274 if (self) { | 11217 if (self) { |
11275 for (NSUInteger i = 0; i < count; ++i) { | 11218 for (NSUInteger i = 0; i < count; ++i) { |
11276 int idx = keys[i] ? 1 : 0; | 11219 int idx = keys[i] ? 1 : 0; |
11277 _values[idx] = values[i]; | 11220 _values[idx] = values[i]; |
11278 _valueSet[idx] = YES; | 11221 _valueSet[idx] = YES; |
11279 } | 11222 } |
11280 } | 11223 } |
11281 return self; | 11224 return self; |
11282 } | 11225 } |
11283 | 11226 |
11284 - (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { | 11227 - (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { |
11285 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; | 11228 self = [self initWithValues:NULL forKeys:NULL count:0]; |
11286 if (self) { | 11229 if (self) { |
11287 if (dictionary) { | 11230 if (dictionary) { |
11288 for (int i = 0; i < 2; ++i) { | 11231 for (int i = 0; i < 2; ++i) { |
11289 if (dictionary->_valueSet[i]) { | 11232 if (dictionary->_valueSet[i]) { |
11290 _values[i] = dictionary->_values[i]; | 11233 _values[i] = dictionary->_values[i]; |
11291 _valueSet[i] = YES; | 11234 _valueSet[i] = YES; |
11292 } | 11235 } |
11293 } | 11236 } |
11294 } | 11237 } |
11295 } | 11238 } |
11296 return self; | 11239 return self; |
11297 } | 11240 } |
11298 | 11241 |
11299 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 11242 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
11300 #pragma unused(numItems) | 11243 #pragma unused(numItems) |
11301 return [self initWithUInt32s:NULL forKeys:NULL count:0]; | 11244 return [self initWithValues:NULL forKeys:NULL count:0]; |
11302 } | 11245 } |
11303 | 11246 |
11304 #if !defined(NS_BLOCK_ASSERTIONS) | 11247 #if !defined(NS_BLOCK_ASSERTIONS) |
11305 - (void)dealloc { | 11248 - (void)dealloc { |
11306 NSAssert(!_autocreator, | 11249 NSAssert(!_autocreator, |
11307 @"%@: Autocreator must be cleared before release, autocreator: %@", | 11250 @"%@: Autocreator must be cleared before release, autocreator: %@", |
11308 [self class], _autocreator); | 11251 [self class], _autocreator); |
11309 [super dealloc]; | 11252 [super dealloc]; |
11310 } | 11253 } |
11311 #endif // !defined(NS_BLOCK_ASSERTIONS) | 11254 #endif // !defined(NS_BLOCK_ASSERTIONS) |
11312 | 11255 |
11313 - (instancetype)copyWithZone:(NSZone *)zone { | 11256 - (instancetype)copyWithZone:(NSZone *)zone { |
11314 return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self]; | 11257 return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self]; |
11315 } | 11258 } |
11316 | 11259 |
11317 - (BOOL)isEqual:(id)other { | 11260 - (BOOL)isEqual:(GPBBoolUInt32Dictionary *)other { |
11318 if (self == other) { | 11261 if (self == other) { |
11319 return YES; | 11262 return YES; |
11320 } | 11263 } |
11321 if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) { | 11264 if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) { |
11322 return NO; | 11265 return NO; |
11323 } | 11266 } |
11324 GPBBoolUInt32Dictionary *otherDictionary = other; | 11267 if ((_valueSet[0] != other->_valueSet[0]) || |
11325 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || | 11268 (_valueSet[1] != other->_valueSet[1])) { |
11326 (_valueSet[1] != otherDictionary->_valueSet[1])) { | |
11327 return NO; | 11269 return NO; |
11328 } | 11270 } |
11329 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || | 11271 if ((_valueSet[0] && (_values[0] != other->_values[0])) || |
11330 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { | 11272 (_valueSet[1] && (_values[1] != other->_values[1]))) { |
11331 return NO; | 11273 return NO; |
11332 } | 11274 } |
11333 return YES; | 11275 return YES; |
11334 } | 11276 } |
11335 | 11277 |
11336 - (NSUInteger)hash { | 11278 - (NSUInteger)hash { |
11337 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11279 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11338 } | 11280 } |
11339 | 11281 |
11340 - (NSString *)description { | 11282 - (NSString *)description { |
11341 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 11283 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
11342 if (_valueSet[0]) { | 11284 if (_valueSet[0]) { |
11343 [result appendFormat:@"NO: %u", _values[0]]; | 11285 [result appendFormat:@"NO: %u", _values[0]]; |
11344 } | 11286 } |
11345 if (_valueSet[1]) { | 11287 if (_valueSet[1]) { |
11346 [result appendFormat:@"YES: %u", _values[1]]; | 11288 [result appendFormat:@"YES: %u", _values[1]]; |
11347 } | 11289 } |
11348 [result appendString:@" }"]; | 11290 [result appendString:@" }"]; |
11349 return result; | 11291 return result; |
11350 } | 11292 } |
11351 | 11293 |
11352 - (NSUInteger)count { | 11294 - (NSUInteger)count { |
11353 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11295 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11354 } | 11296 } |
11355 | 11297 |
11356 - (BOOL)getUInt32:(uint32_t *)value forKey:(BOOL)key { | 11298 - (BOOL)valueForKey:(BOOL)key value:(uint32_t *)value { |
11357 int idx = (key ? 1 : 0); | 11299 int idx = (key ? 1 : 0); |
11358 if (_valueSet[idx]) { | 11300 if (_valueSet[idx]) { |
11359 if (value) { | 11301 if (value) { |
11360 *value = _values[idx]; | 11302 *value = _values[idx]; |
11361 } | 11303 } |
11362 return YES; | 11304 return YES; |
11363 } | 11305 } |
11364 return NO; | 11306 return NO; |
11365 } | 11307 } |
11366 | 11308 |
11367 - (void)setGPBGenericValue:(GPBGenericValue *)value | 11309 - (void)setGPBGenericValue:(GPBGenericValue *)value |
11368 forGPBGenericValueKey:(GPBGenericValue *)key { | 11310 forGPBGenericValueKey:(GPBGenericValue *)key { |
11369 int idx = (key->valueBool ? 1 : 0); | 11311 int idx = (key->valueBool ? 1 : 0); |
11370 _values[idx] = value->valueUInt32; | 11312 _values[idx] = value->valueUInt32; |
11371 _valueSet[idx] = YES; | 11313 _valueSet[idx] = YES; |
11372 } | 11314 } |
11373 | 11315 |
11374 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 11316 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
11375 if (_valueSet[0]) { | 11317 if (_valueSet[0]) { |
11376 block(@"false", [NSString stringWithFormat:@"%u", _values[0]]); | 11318 block(@"false", [NSString stringWithFormat:@"%u", _values[0]]); |
11377 } | 11319 } |
11378 if (_valueSet[1]) { | 11320 if (_valueSet[1]) { |
11379 block(@"true", [NSString stringWithFormat:@"%u", _values[1]]); | 11321 block(@"true", [NSString stringWithFormat:@"%u", _values[1]]); |
11380 } | 11322 } |
11381 } | 11323 } |
11382 | 11324 |
11383 - (void)enumerateKeysAndUInt32sUsingBlock: | 11325 - (void)enumerateKeysAndValuesUsingBlock: |
11384 (void (^)(BOOL key, uint32_t value, BOOL *stop))block { | 11326 (void (^)(BOOL key, uint32_t value, BOOL *stop))block { |
11385 BOOL stop = NO; | 11327 BOOL stop = NO; |
11386 if (_valueSet[0]) { | 11328 if (_valueSet[0]) { |
11387 block(NO, _values[0], &stop); | 11329 block(NO, _values[0], &stop); |
11388 } | 11330 } |
11389 if (!stop && _valueSet[1]) { | 11331 if (!stop && _valueSet[1]) { |
11390 block(YES, _values[1], &stop); | 11332 block(YES, _values[1], &stop); |
11391 } | 11333 } |
11392 } | 11334 } |
11393 | 11335 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11434 _valueSet[i] = YES; | 11376 _valueSet[i] = YES; |
11435 _values[i] = otherDictionary->_values[i]; | 11377 _values[i] = otherDictionary->_values[i]; |
11436 } | 11378 } |
11437 } | 11379 } |
11438 if (_autocreator) { | 11380 if (_autocreator) { |
11439 GPBAutocreatedDictionaryModified(_autocreator, self); | 11381 GPBAutocreatedDictionaryModified(_autocreator, self); |
11440 } | 11382 } |
11441 } | 11383 } |
11442 } | 11384 } |
11443 | 11385 |
11444 - (void)setUInt32:(uint32_t)value forKey:(BOOL)key { | 11386 - (void)setValue:(uint32_t)value forKey:(BOOL)key { |
11445 int idx = (key ? 1 : 0); | 11387 int idx = (key ? 1 : 0); |
11446 _values[idx] = value; | 11388 _values[idx] = value; |
11447 _valueSet[idx] = YES; | 11389 _valueSet[idx] = YES; |
11448 if (_autocreator) { | 11390 if (_autocreator) { |
11449 GPBAutocreatedDictionaryModified(_autocreator, self); | 11391 GPBAutocreatedDictionaryModified(_autocreator, self); |
11450 } | 11392 } |
11451 } | 11393 } |
11452 | 11394 |
11453 - (void)removeUInt32ForKey:(BOOL)aKey { | 11395 - (void)removeValueForKey:(BOOL)aKey { |
11454 _valueSet[aKey ? 1 : 0] = NO; | 11396 _valueSet[aKey ? 1 : 0] = NO; |
11455 } | 11397 } |
11456 | 11398 |
11457 - (void)removeAll { | 11399 - (void)removeAll { |
11458 _valueSet[0] = NO; | 11400 _valueSet[0] = NO; |
11459 _valueSet[1] = NO; | 11401 _valueSet[1] = NO; |
11460 } | 11402 } |
11461 | 11403 |
11462 @end | 11404 @end |
11463 | 11405 |
11464 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t) | 11406 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t) |
11465 // This block of code is generated, do not edit it directly. | 11407 // This block of code is generated, do not edit it directly. |
11466 | 11408 |
11467 #pragma mark - Bool -> Int32 | 11409 #pragma mark - Bool -> Int32 |
11468 | 11410 |
11469 @implementation GPBBoolInt32Dictionary { | 11411 @implementation GPBBoolInt32Dictionary { |
11470 @package | 11412 @package |
11471 int32_t _values[2]; | 11413 int32_t _values[2]; |
11472 BOOL _valueSet[2]; | 11414 BOOL _valueSet[2]; |
11473 } | 11415 } |
11474 | 11416 |
11475 + (instancetype)dictionary { | 11417 + (instancetype)dictionary { |
11476 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; | 11418 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
11477 } | 11419 } |
11478 | 11420 |
11479 + (instancetype)dictionaryWithInt32:(int32_t)value | 11421 + (instancetype)dictionaryWithValue:(int32_t)value |
11480 forKey:(BOOL)key { | 11422 forKey:(BOOL)key { |
11481 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 11423 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
11482 // on to get the type correct. | 11424 // on to get the type correct. |
11483 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithInt32s:&value | 11425 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithValues:&value |
11484 forKeys:&key | 11426 forKeys:&key |
11485 count:1] autorelease]; | 11427 count:1] autorelease]; |
11486 } | 11428 } |
11487 | 11429 |
11488 + (instancetype)dictionaryWithInt32s:(const int32_t [])values | 11430 + (instancetype)dictionaryWithValues:(const int32_t [])values |
11489 forKeys:(const BOOL [])keys | 11431 forKeys:(const BOOL [])keys |
11490 count:(NSUInteger)count { | 11432 count:(NSUInteger)count { |
11491 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: | 11433 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
11492 // on to get the type correct. | 11434 // on to get the type correct. |
11493 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithInt32s:values | 11435 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithValues:values |
11494 forKeys:keys | 11436 forKeys:keys |
11495 count:count] autorelea
se]; | 11437 count:count] autorelea
se]; |
11496 } | 11438 } |
11497 | 11439 |
11498 + (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary { | 11440 + (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary { |
11499 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 11441 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
11500 // on to get the type correct. | 11442 // on to get the type correct. |
11501 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 11443 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
11502 } | 11444 } |
11503 | 11445 |
11504 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 11446 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
11505 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 11447 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
11506 } | 11448 } |
11507 | 11449 |
11508 - (instancetype)init { | 11450 - (instancetype)init { |
11509 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 11451 return [self initWithValues:NULL forKeys:NULL count:0]; |
11510 } | 11452 } |
11511 | 11453 |
11512 - (instancetype)initWithInt32s:(const int32_t [])values | 11454 - (instancetype)initWithValues:(const int32_t [])values |
11513 forKeys:(const BOOL [])keys | 11455 forKeys:(const BOOL [])keys |
11514 count:(NSUInteger)count { | 11456 count:(NSUInteger)count { |
11515 self = [super init]; | 11457 self = [super init]; |
11516 if (self) { | 11458 if (self) { |
11517 for (NSUInteger i = 0; i < count; ++i) { | 11459 for (NSUInteger i = 0; i < count; ++i) { |
11518 int idx = keys[i] ? 1 : 0; | 11460 int idx = keys[i] ? 1 : 0; |
11519 _values[idx] = values[i]; | 11461 _values[idx] = values[i]; |
11520 _valueSet[idx] = YES; | 11462 _valueSet[idx] = YES; |
11521 } | 11463 } |
11522 } | 11464 } |
11523 return self; | 11465 return self; |
11524 } | 11466 } |
11525 | 11467 |
11526 - (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary { | 11468 - (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary { |
11527 self = [self initWithInt32s:NULL forKeys:NULL count:0]; | 11469 self = [self initWithValues:NULL forKeys:NULL count:0]; |
11528 if (self) { | 11470 if (self) { |
11529 if (dictionary) { | 11471 if (dictionary) { |
11530 for (int i = 0; i < 2; ++i) { | 11472 for (int i = 0; i < 2; ++i) { |
11531 if (dictionary->_valueSet[i]) { | 11473 if (dictionary->_valueSet[i]) { |
11532 _values[i] = dictionary->_values[i]; | 11474 _values[i] = dictionary->_values[i]; |
11533 _valueSet[i] = YES; | 11475 _valueSet[i] = YES; |
11534 } | 11476 } |
11535 } | 11477 } |
11536 } | 11478 } |
11537 } | 11479 } |
11538 return self; | 11480 return self; |
11539 } | 11481 } |
11540 | 11482 |
11541 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 11483 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
11542 #pragma unused(numItems) | 11484 #pragma unused(numItems) |
11543 return [self initWithInt32s:NULL forKeys:NULL count:0]; | 11485 return [self initWithValues:NULL forKeys:NULL count:0]; |
11544 } | 11486 } |
11545 | 11487 |
11546 #if !defined(NS_BLOCK_ASSERTIONS) | 11488 #if !defined(NS_BLOCK_ASSERTIONS) |
11547 - (void)dealloc { | 11489 - (void)dealloc { |
11548 NSAssert(!_autocreator, | 11490 NSAssert(!_autocreator, |
11549 @"%@: Autocreator must be cleared before release, autocreator: %@", | 11491 @"%@: Autocreator must be cleared before release, autocreator: %@", |
11550 [self class], _autocreator); | 11492 [self class], _autocreator); |
11551 [super dealloc]; | 11493 [super dealloc]; |
11552 } | 11494 } |
11553 #endif // !defined(NS_BLOCK_ASSERTIONS) | 11495 #endif // !defined(NS_BLOCK_ASSERTIONS) |
11554 | 11496 |
11555 - (instancetype)copyWithZone:(NSZone *)zone { | 11497 - (instancetype)copyWithZone:(NSZone *)zone { |
11556 return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self]; | 11498 return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self]; |
11557 } | 11499 } |
11558 | 11500 |
11559 - (BOOL)isEqual:(id)other { | 11501 - (BOOL)isEqual:(GPBBoolInt32Dictionary *)other { |
11560 if (self == other) { | 11502 if (self == other) { |
11561 return YES; | 11503 return YES; |
11562 } | 11504 } |
11563 if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) { | 11505 if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) { |
11564 return NO; | 11506 return NO; |
11565 } | 11507 } |
11566 GPBBoolInt32Dictionary *otherDictionary = other; | 11508 if ((_valueSet[0] != other->_valueSet[0]) || |
11567 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || | 11509 (_valueSet[1] != other->_valueSet[1])) { |
11568 (_valueSet[1] != otherDictionary->_valueSet[1])) { | |
11569 return NO; | 11510 return NO; |
11570 } | 11511 } |
11571 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || | 11512 if ((_valueSet[0] && (_values[0] != other->_values[0])) || |
11572 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { | 11513 (_valueSet[1] && (_values[1] != other->_values[1]))) { |
11573 return NO; | 11514 return NO; |
11574 } | 11515 } |
11575 return YES; | 11516 return YES; |
11576 } | 11517 } |
11577 | 11518 |
11578 - (NSUInteger)hash { | 11519 - (NSUInteger)hash { |
11579 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11520 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11580 } | 11521 } |
11581 | 11522 |
11582 - (NSString *)description { | 11523 - (NSString *)description { |
11583 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 11524 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
11584 if (_valueSet[0]) { | 11525 if (_valueSet[0]) { |
11585 [result appendFormat:@"NO: %d", _values[0]]; | 11526 [result appendFormat:@"NO: %d", _values[0]]; |
11586 } | 11527 } |
11587 if (_valueSet[1]) { | 11528 if (_valueSet[1]) { |
11588 [result appendFormat:@"YES: %d", _values[1]]; | 11529 [result appendFormat:@"YES: %d", _values[1]]; |
11589 } | 11530 } |
11590 [result appendString:@" }"]; | 11531 [result appendString:@" }"]; |
11591 return result; | 11532 return result; |
11592 } | 11533 } |
11593 | 11534 |
11594 - (NSUInteger)count { | 11535 - (NSUInteger)count { |
11595 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11536 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11596 } | 11537 } |
11597 | 11538 |
11598 - (BOOL)getInt32:(int32_t *)value forKey:(BOOL)key { | 11539 - (BOOL)valueForKey:(BOOL)key value:(int32_t *)value { |
11599 int idx = (key ? 1 : 0); | 11540 int idx = (key ? 1 : 0); |
11600 if (_valueSet[idx]) { | 11541 if (_valueSet[idx]) { |
11601 if (value) { | 11542 if (value) { |
11602 *value = _values[idx]; | 11543 *value = _values[idx]; |
11603 } | 11544 } |
11604 return YES; | 11545 return YES; |
11605 } | 11546 } |
11606 return NO; | 11547 return NO; |
11607 } | 11548 } |
11608 | 11549 |
11609 - (void)setGPBGenericValue:(GPBGenericValue *)value | 11550 - (void)setGPBGenericValue:(GPBGenericValue *)value |
11610 forGPBGenericValueKey:(GPBGenericValue *)key { | 11551 forGPBGenericValueKey:(GPBGenericValue *)key { |
11611 int idx = (key->valueBool ? 1 : 0); | 11552 int idx = (key->valueBool ? 1 : 0); |
11612 _values[idx] = value->valueInt32; | 11553 _values[idx] = value->valueInt32; |
11613 _valueSet[idx] = YES; | 11554 _valueSet[idx] = YES; |
11614 } | 11555 } |
11615 | 11556 |
11616 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 11557 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
11617 if (_valueSet[0]) { | 11558 if (_valueSet[0]) { |
11618 block(@"false", [NSString stringWithFormat:@"%d", _values[0]]); | 11559 block(@"false", [NSString stringWithFormat:@"%d", _values[0]]); |
11619 } | 11560 } |
11620 if (_valueSet[1]) { | 11561 if (_valueSet[1]) { |
11621 block(@"true", [NSString stringWithFormat:@"%d", _values[1]]); | 11562 block(@"true", [NSString stringWithFormat:@"%d", _values[1]]); |
11622 } | 11563 } |
11623 } | 11564 } |
11624 | 11565 |
11625 - (void)enumerateKeysAndInt32sUsingBlock: | 11566 - (void)enumerateKeysAndValuesUsingBlock: |
11626 (void (^)(BOOL key, int32_t value, BOOL *stop))block { | 11567 (void (^)(BOOL key, int32_t value, BOOL *stop))block { |
11627 BOOL stop = NO; | 11568 BOOL stop = NO; |
11628 if (_valueSet[0]) { | 11569 if (_valueSet[0]) { |
11629 block(NO, _values[0], &stop); | 11570 block(NO, _values[0], &stop); |
11630 } | 11571 } |
11631 if (!stop && _valueSet[1]) { | 11572 if (!stop && _valueSet[1]) { |
11632 block(YES, _values[1], &stop); | 11573 block(YES, _values[1], &stop); |
11633 } | 11574 } |
11634 } | 11575 } |
11635 | 11576 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11676 _valueSet[i] = YES; | 11617 _valueSet[i] = YES; |
11677 _values[i] = otherDictionary->_values[i]; | 11618 _values[i] = otherDictionary->_values[i]; |
11678 } | 11619 } |
11679 } | 11620 } |
11680 if (_autocreator) { | 11621 if (_autocreator) { |
11681 GPBAutocreatedDictionaryModified(_autocreator, self); | 11622 GPBAutocreatedDictionaryModified(_autocreator, self); |
11682 } | 11623 } |
11683 } | 11624 } |
11684 } | 11625 } |
11685 | 11626 |
11686 - (void)setInt32:(int32_t)value forKey:(BOOL)key { | 11627 - (void)setValue:(int32_t)value forKey:(BOOL)key { |
11687 int idx = (key ? 1 : 0); | 11628 int idx = (key ? 1 : 0); |
11688 _values[idx] = value; | 11629 _values[idx] = value; |
11689 _valueSet[idx] = YES; | 11630 _valueSet[idx] = YES; |
11690 if (_autocreator) { | 11631 if (_autocreator) { |
11691 GPBAutocreatedDictionaryModified(_autocreator, self); | 11632 GPBAutocreatedDictionaryModified(_autocreator, self); |
11692 } | 11633 } |
11693 } | 11634 } |
11694 | 11635 |
11695 - (void)removeInt32ForKey:(BOOL)aKey { | 11636 - (void)removeValueForKey:(BOOL)aKey { |
11696 _valueSet[aKey ? 1 : 0] = NO; | 11637 _valueSet[aKey ? 1 : 0] = NO; |
11697 } | 11638 } |
11698 | 11639 |
11699 - (void)removeAll { | 11640 - (void)removeAll { |
11700 _valueSet[0] = NO; | 11641 _valueSet[0] = NO; |
11701 _valueSet[1] = NO; | 11642 _valueSet[1] = NO; |
11702 } | 11643 } |
11703 | 11644 |
11704 @end | 11645 @end |
11705 | 11646 |
11706 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t) | 11647 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t) |
11707 // This block of code is generated, do not edit it directly. | 11648 // This block of code is generated, do not edit it directly. |
11708 | 11649 |
11709 #pragma mark - Bool -> UInt64 | 11650 #pragma mark - Bool -> UInt64 |
11710 | 11651 |
11711 @implementation GPBBoolUInt64Dictionary { | 11652 @implementation GPBBoolUInt64Dictionary { |
11712 @package | 11653 @package |
11713 uint64_t _values[2]; | 11654 uint64_t _values[2]; |
11714 BOOL _valueSet[2]; | 11655 BOOL _valueSet[2]; |
11715 } | 11656 } |
11716 | 11657 |
11717 + (instancetype)dictionary { | 11658 + (instancetype)dictionary { |
11718 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; | 11659 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
11719 } | 11660 } |
11720 | 11661 |
11721 + (instancetype)dictionaryWithUInt64:(uint64_t)value | 11662 + (instancetype)dictionaryWithValue:(uint64_t)value |
11722 forKey:(BOOL)key { | 11663 forKey:(BOOL)key { |
11723 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 11664 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
11724 // on to get the type correct. | 11665 // on to get the type correct. |
11725 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithUInt64s:&value | 11666 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithValues:&value |
11726 forKeys:&key | 11667 forKeys:&key |
11727 count:1] autorelease
]; | 11668 count:1] autorelease]
; |
11728 } | 11669 } |
11729 | 11670 |
11730 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values | 11671 + (instancetype)dictionaryWithValues:(const uint64_t [])values |
11731 forKeys:(const BOOL [])keys | 11672 forKeys:(const BOOL [])keys |
11732 count:(NSUInteger)count { | 11673 count:(NSUInteger)count { |
11733 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: | 11674 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
11734 // on to get the type correct. | 11675 // on to get the type correct. |
11735 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithUInt64s:values | 11676 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithValues:values |
11736 forKeys:keys | 11677 forKeys:keys |
11737 count:count] autorel
ease]; | 11678 count:count] autorele
ase]; |
11738 } | 11679 } |
11739 | 11680 |
11740 + (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { | 11681 + (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { |
11741 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 11682 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
11742 // on to get the type correct. | 11683 // on to get the type correct. |
11743 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 11684 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
11744 } | 11685 } |
11745 | 11686 |
11746 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 11687 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
11747 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 11688 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
11748 } | 11689 } |
11749 | 11690 |
11750 - (instancetype)init { | 11691 - (instancetype)init { |
11751 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 11692 return [self initWithValues:NULL forKeys:NULL count:0]; |
11752 } | 11693 } |
11753 | 11694 |
11754 - (instancetype)initWithUInt64s:(const uint64_t [])values | 11695 - (instancetype)initWithValues:(const uint64_t [])values |
11755 forKeys:(const BOOL [])keys | 11696 forKeys:(const BOOL [])keys |
11756 count:(NSUInteger)count { | 11697 count:(NSUInteger)count { |
11757 self = [super init]; | 11698 self = [super init]; |
11758 if (self) { | 11699 if (self) { |
11759 for (NSUInteger i = 0; i < count; ++i) { | 11700 for (NSUInteger i = 0; i < count; ++i) { |
11760 int idx = keys[i] ? 1 : 0; | 11701 int idx = keys[i] ? 1 : 0; |
11761 _values[idx] = values[i]; | 11702 _values[idx] = values[i]; |
11762 _valueSet[idx] = YES; | 11703 _valueSet[idx] = YES; |
11763 } | 11704 } |
11764 } | 11705 } |
11765 return self; | 11706 return self; |
11766 } | 11707 } |
11767 | 11708 |
11768 - (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { | 11709 - (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { |
11769 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; | 11710 self = [self initWithValues:NULL forKeys:NULL count:0]; |
11770 if (self) { | 11711 if (self) { |
11771 if (dictionary) { | 11712 if (dictionary) { |
11772 for (int i = 0; i < 2; ++i) { | 11713 for (int i = 0; i < 2; ++i) { |
11773 if (dictionary->_valueSet[i]) { | 11714 if (dictionary->_valueSet[i]) { |
11774 _values[i] = dictionary->_values[i]; | 11715 _values[i] = dictionary->_values[i]; |
11775 _valueSet[i] = YES; | 11716 _valueSet[i] = YES; |
11776 } | 11717 } |
11777 } | 11718 } |
11778 } | 11719 } |
11779 } | 11720 } |
11780 return self; | 11721 return self; |
11781 } | 11722 } |
11782 | 11723 |
11783 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 11724 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
11784 #pragma unused(numItems) | 11725 #pragma unused(numItems) |
11785 return [self initWithUInt64s:NULL forKeys:NULL count:0]; | 11726 return [self initWithValues:NULL forKeys:NULL count:0]; |
11786 } | 11727 } |
11787 | 11728 |
11788 #if !defined(NS_BLOCK_ASSERTIONS) | 11729 #if !defined(NS_BLOCK_ASSERTIONS) |
11789 - (void)dealloc { | 11730 - (void)dealloc { |
11790 NSAssert(!_autocreator, | 11731 NSAssert(!_autocreator, |
11791 @"%@: Autocreator must be cleared before release, autocreator: %@", | 11732 @"%@: Autocreator must be cleared before release, autocreator: %@", |
11792 [self class], _autocreator); | 11733 [self class], _autocreator); |
11793 [super dealloc]; | 11734 [super dealloc]; |
11794 } | 11735 } |
11795 #endif // !defined(NS_BLOCK_ASSERTIONS) | 11736 #endif // !defined(NS_BLOCK_ASSERTIONS) |
11796 | 11737 |
11797 - (instancetype)copyWithZone:(NSZone *)zone { | 11738 - (instancetype)copyWithZone:(NSZone *)zone { |
11798 return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self]; | 11739 return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self]; |
11799 } | 11740 } |
11800 | 11741 |
11801 - (BOOL)isEqual:(id)other { | 11742 - (BOOL)isEqual:(GPBBoolUInt64Dictionary *)other { |
11802 if (self == other) { | 11743 if (self == other) { |
11803 return YES; | 11744 return YES; |
11804 } | 11745 } |
11805 if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) { | 11746 if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) { |
11806 return NO; | 11747 return NO; |
11807 } | 11748 } |
11808 GPBBoolUInt64Dictionary *otherDictionary = other; | 11749 if ((_valueSet[0] != other->_valueSet[0]) || |
11809 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || | 11750 (_valueSet[1] != other->_valueSet[1])) { |
11810 (_valueSet[1] != otherDictionary->_valueSet[1])) { | |
11811 return NO; | 11751 return NO; |
11812 } | 11752 } |
11813 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || | 11753 if ((_valueSet[0] && (_values[0] != other->_values[0])) || |
11814 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { | 11754 (_valueSet[1] && (_values[1] != other->_values[1]))) { |
11815 return NO; | 11755 return NO; |
11816 } | 11756 } |
11817 return YES; | 11757 return YES; |
11818 } | 11758 } |
11819 | 11759 |
11820 - (NSUInteger)hash { | 11760 - (NSUInteger)hash { |
11821 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11761 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11822 } | 11762 } |
11823 | 11763 |
11824 - (NSString *)description { | 11764 - (NSString *)description { |
11825 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 11765 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
11826 if (_valueSet[0]) { | 11766 if (_valueSet[0]) { |
11827 [result appendFormat:@"NO: %llu", _values[0]]; | 11767 [result appendFormat:@"NO: %llu", _values[0]]; |
11828 } | 11768 } |
11829 if (_valueSet[1]) { | 11769 if (_valueSet[1]) { |
11830 [result appendFormat:@"YES: %llu", _values[1]]; | 11770 [result appendFormat:@"YES: %llu", _values[1]]; |
11831 } | 11771 } |
11832 [result appendString:@" }"]; | 11772 [result appendString:@" }"]; |
11833 return result; | 11773 return result; |
11834 } | 11774 } |
11835 | 11775 |
11836 - (NSUInteger)count { | 11776 - (NSUInteger)count { |
11837 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11777 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11838 } | 11778 } |
11839 | 11779 |
11840 - (BOOL)getUInt64:(uint64_t *)value forKey:(BOOL)key { | 11780 - (BOOL)valueForKey:(BOOL)key value:(uint64_t *)value { |
11841 int idx = (key ? 1 : 0); | 11781 int idx = (key ? 1 : 0); |
11842 if (_valueSet[idx]) { | 11782 if (_valueSet[idx]) { |
11843 if (value) { | 11783 if (value) { |
11844 *value = _values[idx]; | 11784 *value = _values[idx]; |
11845 } | 11785 } |
11846 return YES; | 11786 return YES; |
11847 } | 11787 } |
11848 return NO; | 11788 return NO; |
11849 } | 11789 } |
11850 | 11790 |
11851 - (void)setGPBGenericValue:(GPBGenericValue *)value | 11791 - (void)setGPBGenericValue:(GPBGenericValue *)value |
11852 forGPBGenericValueKey:(GPBGenericValue *)key { | 11792 forGPBGenericValueKey:(GPBGenericValue *)key { |
11853 int idx = (key->valueBool ? 1 : 0); | 11793 int idx = (key->valueBool ? 1 : 0); |
11854 _values[idx] = value->valueUInt64; | 11794 _values[idx] = value->valueUInt64; |
11855 _valueSet[idx] = YES; | 11795 _valueSet[idx] = YES; |
11856 } | 11796 } |
11857 | 11797 |
11858 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 11798 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
11859 if (_valueSet[0]) { | 11799 if (_valueSet[0]) { |
11860 block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]); | 11800 block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]); |
11861 } | 11801 } |
11862 if (_valueSet[1]) { | 11802 if (_valueSet[1]) { |
11863 block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]); | 11803 block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]); |
11864 } | 11804 } |
11865 } | 11805 } |
11866 | 11806 |
11867 - (void)enumerateKeysAndUInt64sUsingBlock: | 11807 - (void)enumerateKeysAndValuesUsingBlock: |
11868 (void (^)(BOOL key, uint64_t value, BOOL *stop))block { | 11808 (void (^)(BOOL key, uint64_t value, BOOL *stop))block { |
11869 BOOL stop = NO; | 11809 BOOL stop = NO; |
11870 if (_valueSet[0]) { | 11810 if (_valueSet[0]) { |
11871 block(NO, _values[0], &stop); | 11811 block(NO, _values[0], &stop); |
11872 } | 11812 } |
11873 if (!stop && _valueSet[1]) { | 11813 if (!stop && _valueSet[1]) { |
11874 block(YES, _values[1], &stop); | 11814 block(YES, _values[1], &stop); |
11875 } | 11815 } |
11876 } | 11816 } |
11877 | 11817 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11918 _valueSet[i] = YES; | 11858 _valueSet[i] = YES; |
11919 _values[i] = otherDictionary->_values[i]; | 11859 _values[i] = otherDictionary->_values[i]; |
11920 } | 11860 } |
11921 } | 11861 } |
11922 if (_autocreator) { | 11862 if (_autocreator) { |
11923 GPBAutocreatedDictionaryModified(_autocreator, self); | 11863 GPBAutocreatedDictionaryModified(_autocreator, self); |
11924 } | 11864 } |
11925 } | 11865 } |
11926 } | 11866 } |
11927 | 11867 |
11928 - (void)setUInt64:(uint64_t)value forKey:(BOOL)key { | 11868 - (void)setValue:(uint64_t)value forKey:(BOOL)key { |
11929 int idx = (key ? 1 : 0); | 11869 int idx = (key ? 1 : 0); |
11930 _values[idx] = value; | 11870 _values[idx] = value; |
11931 _valueSet[idx] = YES; | 11871 _valueSet[idx] = YES; |
11932 if (_autocreator) { | 11872 if (_autocreator) { |
11933 GPBAutocreatedDictionaryModified(_autocreator, self); | 11873 GPBAutocreatedDictionaryModified(_autocreator, self); |
11934 } | 11874 } |
11935 } | 11875 } |
11936 | 11876 |
11937 - (void)removeUInt64ForKey:(BOOL)aKey { | 11877 - (void)removeValueForKey:(BOOL)aKey { |
11938 _valueSet[aKey ? 1 : 0] = NO; | 11878 _valueSet[aKey ? 1 : 0] = NO; |
11939 } | 11879 } |
11940 | 11880 |
11941 - (void)removeAll { | 11881 - (void)removeAll { |
11942 _valueSet[0] = NO; | 11882 _valueSet[0] = NO; |
11943 _valueSet[1] = NO; | 11883 _valueSet[1] = NO; |
11944 } | 11884 } |
11945 | 11885 |
11946 @end | 11886 @end |
11947 | 11887 |
11948 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t) | 11888 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t) |
11949 // This block of code is generated, do not edit it directly. | 11889 // This block of code is generated, do not edit it directly. |
11950 | 11890 |
11951 #pragma mark - Bool -> Int64 | 11891 #pragma mark - Bool -> Int64 |
11952 | 11892 |
11953 @implementation GPBBoolInt64Dictionary { | 11893 @implementation GPBBoolInt64Dictionary { |
11954 @package | 11894 @package |
11955 int64_t _values[2]; | 11895 int64_t _values[2]; |
11956 BOOL _valueSet[2]; | 11896 BOOL _valueSet[2]; |
11957 } | 11897 } |
11958 | 11898 |
11959 + (instancetype)dictionary { | 11899 + (instancetype)dictionary { |
11960 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; | 11900 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
11961 } | 11901 } |
11962 | 11902 |
11963 + (instancetype)dictionaryWithInt64:(int64_t)value | 11903 + (instancetype)dictionaryWithValue:(int64_t)value |
11964 forKey:(BOOL)key { | 11904 forKey:(BOOL)key { |
11965 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 11905 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
11966 // on to get the type correct. | 11906 // on to get the type correct. |
11967 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithInt64s:&value | 11907 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithValues:&value |
11968 forKeys:&key | 11908 forKeys:&key |
11969 count:1] autorelease]; | 11909 count:1] autorelease]; |
11970 } | 11910 } |
11971 | 11911 |
11972 + (instancetype)dictionaryWithInt64s:(const int64_t [])values | 11912 + (instancetype)dictionaryWithValues:(const int64_t [])values |
11973 forKeys:(const BOOL [])keys | 11913 forKeys:(const BOOL [])keys |
11974 count:(NSUInteger)count { | 11914 count:(NSUInteger)count { |
11975 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: | 11915 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
11976 // on to get the type correct. | 11916 // on to get the type correct. |
11977 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithInt64s:values | 11917 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithValues:values |
11978 forKeys:keys | 11918 forKeys:keys |
11979 count:count] autorelea
se]; | 11919 count:count] autorelea
se]; |
11980 } | 11920 } |
11981 | 11921 |
11982 + (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary { | 11922 + (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary { |
11983 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 11923 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
11984 // on to get the type correct. | 11924 // on to get the type correct. |
11985 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 11925 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
11986 } | 11926 } |
11987 | 11927 |
11988 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 11928 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
11989 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 11929 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
11990 } | 11930 } |
11991 | 11931 |
11992 - (instancetype)init { | 11932 - (instancetype)init { |
11993 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 11933 return [self initWithValues:NULL forKeys:NULL count:0]; |
11994 } | 11934 } |
11995 | 11935 |
11996 - (instancetype)initWithInt64s:(const int64_t [])values | 11936 - (instancetype)initWithValues:(const int64_t [])values |
11997 forKeys:(const BOOL [])keys | 11937 forKeys:(const BOOL [])keys |
11998 count:(NSUInteger)count { | 11938 count:(NSUInteger)count { |
11999 self = [super init]; | 11939 self = [super init]; |
12000 if (self) { | 11940 if (self) { |
12001 for (NSUInteger i = 0; i < count; ++i) { | 11941 for (NSUInteger i = 0; i < count; ++i) { |
12002 int idx = keys[i] ? 1 : 0; | 11942 int idx = keys[i] ? 1 : 0; |
12003 _values[idx] = values[i]; | 11943 _values[idx] = values[i]; |
12004 _valueSet[idx] = YES; | 11944 _valueSet[idx] = YES; |
12005 } | 11945 } |
12006 } | 11946 } |
12007 return self; | 11947 return self; |
12008 } | 11948 } |
12009 | 11949 |
12010 - (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary { | 11950 - (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary { |
12011 self = [self initWithInt64s:NULL forKeys:NULL count:0]; | 11951 self = [self initWithValues:NULL forKeys:NULL count:0]; |
12012 if (self) { | 11952 if (self) { |
12013 if (dictionary) { | 11953 if (dictionary) { |
12014 for (int i = 0; i < 2; ++i) { | 11954 for (int i = 0; i < 2; ++i) { |
12015 if (dictionary->_valueSet[i]) { | 11955 if (dictionary->_valueSet[i]) { |
12016 _values[i] = dictionary->_values[i]; | 11956 _values[i] = dictionary->_values[i]; |
12017 _valueSet[i] = YES; | 11957 _valueSet[i] = YES; |
12018 } | 11958 } |
12019 } | 11959 } |
12020 } | 11960 } |
12021 } | 11961 } |
12022 return self; | 11962 return self; |
12023 } | 11963 } |
12024 | 11964 |
12025 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 11965 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
12026 #pragma unused(numItems) | 11966 #pragma unused(numItems) |
12027 return [self initWithInt64s:NULL forKeys:NULL count:0]; | 11967 return [self initWithValues:NULL forKeys:NULL count:0]; |
12028 } | 11968 } |
12029 | 11969 |
12030 #if !defined(NS_BLOCK_ASSERTIONS) | 11970 #if !defined(NS_BLOCK_ASSERTIONS) |
12031 - (void)dealloc { | 11971 - (void)dealloc { |
12032 NSAssert(!_autocreator, | 11972 NSAssert(!_autocreator, |
12033 @"%@: Autocreator must be cleared before release, autocreator: %@", | 11973 @"%@: Autocreator must be cleared before release, autocreator: %@", |
12034 [self class], _autocreator); | 11974 [self class], _autocreator); |
12035 [super dealloc]; | 11975 [super dealloc]; |
12036 } | 11976 } |
12037 #endif // !defined(NS_BLOCK_ASSERTIONS) | 11977 #endif // !defined(NS_BLOCK_ASSERTIONS) |
12038 | 11978 |
12039 - (instancetype)copyWithZone:(NSZone *)zone { | 11979 - (instancetype)copyWithZone:(NSZone *)zone { |
12040 return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self]; | 11980 return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self]; |
12041 } | 11981 } |
12042 | 11982 |
12043 - (BOOL)isEqual:(id)other { | 11983 - (BOOL)isEqual:(GPBBoolInt64Dictionary *)other { |
12044 if (self == other) { | 11984 if (self == other) { |
12045 return YES; | 11985 return YES; |
12046 } | 11986 } |
12047 if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) { | 11987 if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) { |
12048 return NO; | 11988 return NO; |
12049 } | 11989 } |
12050 GPBBoolInt64Dictionary *otherDictionary = other; | 11990 if ((_valueSet[0] != other->_valueSet[0]) || |
12051 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || | 11991 (_valueSet[1] != other->_valueSet[1])) { |
12052 (_valueSet[1] != otherDictionary->_valueSet[1])) { | |
12053 return NO; | 11992 return NO; |
12054 } | 11993 } |
12055 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || | 11994 if ((_valueSet[0] && (_values[0] != other->_values[0])) || |
12056 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { | 11995 (_valueSet[1] && (_values[1] != other->_values[1]))) { |
12057 return NO; | 11996 return NO; |
12058 } | 11997 } |
12059 return YES; | 11998 return YES; |
12060 } | 11999 } |
12061 | 12000 |
12062 - (NSUInteger)hash { | 12001 - (NSUInteger)hash { |
12063 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12002 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12064 } | 12003 } |
12065 | 12004 |
12066 - (NSString *)description { | 12005 - (NSString *)description { |
12067 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 12006 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
12068 if (_valueSet[0]) { | 12007 if (_valueSet[0]) { |
12069 [result appendFormat:@"NO: %lld", _values[0]]; | 12008 [result appendFormat:@"NO: %lld", _values[0]]; |
12070 } | 12009 } |
12071 if (_valueSet[1]) { | 12010 if (_valueSet[1]) { |
12072 [result appendFormat:@"YES: %lld", _values[1]]; | 12011 [result appendFormat:@"YES: %lld", _values[1]]; |
12073 } | 12012 } |
12074 [result appendString:@" }"]; | 12013 [result appendString:@" }"]; |
12075 return result; | 12014 return result; |
12076 } | 12015 } |
12077 | 12016 |
12078 - (NSUInteger)count { | 12017 - (NSUInteger)count { |
12079 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12018 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12080 } | 12019 } |
12081 | 12020 |
12082 - (BOOL)getInt64:(int64_t *)value forKey:(BOOL)key { | 12021 - (BOOL)valueForKey:(BOOL)key value:(int64_t *)value { |
12083 int idx = (key ? 1 : 0); | 12022 int idx = (key ? 1 : 0); |
12084 if (_valueSet[idx]) { | 12023 if (_valueSet[idx]) { |
12085 if (value) { | 12024 if (value) { |
12086 *value = _values[idx]; | 12025 *value = _values[idx]; |
12087 } | 12026 } |
12088 return YES; | 12027 return YES; |
12089 } | 12028 } |
12090 return NO; | 12029 return NO; |
12091 } | 12030 } |
12092 | 12031 |
12093 - (void)setGPBGenericValue:(GPBGenericValue *)value | 12032 - (void)setGPBGenericValue:(GPBGenericValue *)value |
12094 forGPBGenericValueKey:(GPBGenericValue *)key { | 12033 forGPBGenericValueKey:(GPBGenericValue *)key { |
12095 int idx = (key->valueBool ? 1 : 0); | 12034 int idx = (key->valueBool ? 1 : 0); |
12096 _values[idx] = value->valueInt64; | 12035 _values[idx] = value->valueInt64; |
12097 _valueSet[idx] = YES; | 12036 _valueSet[idx] = YES; |
12098 } | 12037 } |
12099 | 12038 |
12100 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 12039 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
12101 if (_valueSet[0]) { | 12040 if (_valueSet[0]) { |
12102 block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]); | 12041 block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]); |
12103 } | 12042 } |
12104 if (_valueSet[1]) { | 12043 if (_valueSet[1]) { |
12105 block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]); | 12044 block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]); |
12106 } | 12045 } |
12107 } | 12046 } |
12108 | 12047 |
12109 - (void)enumerateKeysAndInt64sUsingBlock: | 12048 - (void)enumerateKeysAndValuesUsingBlock: |
12110 (void (^)(BOOL key, int64_t value, BOOL *stop))block { | 12049 (void (^)(BOOL key, int64_t value, BOOL *stop))block { |
12111 BOOL stop = NO; | 12050 BOOL stop = NO; |
12112 if (_valueSet[0]) { | 12051 if (_valueSet[0]) { |
12113 block(NO, _values[0], &stop); | 12052 block(NO, _values[0], &stop); |
12114 } | 12053 } |
12115 if (!stop && _valueSet[1]) { | 12054 if (!stop && _valueSet[1]) { |
12116 block(YES, _values[1], &stop); | 12055 block(YES, _values[1], &stop); |
12117 } | 12056 } |
12118 } | 12057 } |
12119 | 12058 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12160 _valueSet[i] = YES; | 12099 _valueSet[i] = YES; |
12161 _values[i] = otherDictionary->_values[i]; | 12100 _values[i] = otherDictionary->_values[i]; |
12162 } | 12101 } |
12163 } | 12102 } |
12164 if (_autocreator) { | 12103 if (_autocreator) { |
12165 GPBAutocreatedDictionaryModified(_autocreator, self); | 12104 GPBAutocreatedDictionaryModified(_autocreator, self); |
12166 } | 12105 } |
12167 } | 12106 } |
12168 } | 12107 } |
12169 | 12108 |
12170 - (void)setInt64:(int64_t)value forKey:(BOOL)key { | 12109 - (void)setValue:(int64_t)value forKey:(BOOL)key { |
12171 int idx = (key ? 1 : 0); | 12110 int idx = (key ? 1 : 0); |
12172 _values[idx] = value; | 12111 _values[idx] = value; |
12173 _valueSet[idx] = YES; | 12112 _valueSet[idx] = YES; |
12174 if (_autocreator) { | 12113 if (_autocreator) { |
12175 GPBAutocreatedDictionaryModified(_autocreator, self); | 12114 GPBAutocreatedDictionaryModified(_autocreator, self); |
12176 } | 12115 } |
12177 } | 12116 } |
12178 | 12117 |
12179 - (void)removeInt64ForKey:(BOOL)aKey { | 12118 - (void)removeValueForKey:(BOOL)aKey { |
12180 _valueSet[aKey ? 1 : 0] = NO; | 12119 _valueSet[aKey ? 1 : 0] = NO; |
12181 } | 12120 } |
12182 | 12121 |
12183 - (void)removeAll { | 12122 - (void)removeAll { |
12184 _valueSet[0] = NO; | 12123 _valueSet[0] = NO; |
12185 _valueSet[1] = NO; | 12124 _valueSet[1] = NO; |
12186 } | 12125 } |
12187 | 12126 |
12188 @end | 12127 @end |
12189 | 12128 |
12190 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL) | 12129 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL) |
12191 // This block of code is generated, do not edit it directly. | 12130 // This block of code is generated, do not edit it directly. |
12192 | 12131 |
12193 #pragma mark - Bool -> Bool | 12132 #pragma mark - Bool -> Bool |
12194 | 12133 |
12195 @implementation GPBBoolBoolDictionary { | 12134 @implementation GPBBoolBoolDictionary { |
12196 @package | 12135 @package |
12197 BOOL _values[2]; | 12136 BOOL _values[2]; |
12198 BOOL _valueSet[2]; | 12137 BOOL _valueSet[2]; |
12199 } | 12138 } |
12200 | 12139 |
12201 + (instancetype)dictionary { | 12140 + (instancetype)dictionary { |
12202 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; | 12141 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
12203 } | 12142 } |
12204 | 12143 |
12205 + (instancetype)dictionaryWithBool:(BOOL)value | 12144 + (instancetype)dictionaryWithValue:(BOOL)value |
12206 forKey:(BOOL)key { | 12145 forKey:(BOOL)key { |
12207 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 12146 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
12208 // on to get the type correct. | 12147 // on to get the type correct. |
12209 return [[(GPBBoolBoolDictionary*)[self alloc] initWithBools:&value | 12148 return [[(GPBBoolBoolDictionary*)[self alloc] initWithValues:&value |
12210 forKeys:&key | 12149 forKeys:&key |
12211 count:1] autorelease]; | 12150 count:1] autorelease]; |
12212 } | 12151 } |
12213 | 12152 |
12214 + (instancetype)dictionaryWithBools:(const BOOL [])values | 12153 + (instancetype)dictionaryWithValues:(const BOOL [])values |
12215 forKeys:(const BOOL [])keys | 12154 forKeys:(const BOOL [])keys |
12216 count:(NSUInteger)count { | 12155 count:(NSUInteger)count { |
12217 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: | 12156 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
12218 // on to get the type correct. | 12157 // on to get the type correct. |
12219 return [[(GPBBoolBoolDictionary*)[self alloc] initWithBools:values | 12158 return [[(GPBBoolBoolDictionary*)[self alloc] initWithValues:values |
12220 forKeys:keys | 12159 forKeys:keys |
12221 count:count] autorelease
]; | 12160 count:count] autoreleas
e]; |
12222 } | 12161 } |
12223 | 12162 |
12224 + (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary { | 12163 + (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary { |
12225 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 12164 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
12226 // on to get the type correct. | 12165 // on to get the type correct. |
12227 return [[(GPBBoolBoolDictionary*)[self alloc] initWithDictionary:dictionary] a
utorelease]; | 12166 return [[(GPBBoolBoolDictionary*)[self alloc] initWithDictionary:dictionary] a
utorelease]; |
12228 } | 12167 } |
12229 | 12168 |
12230 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 12169 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
12231 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 12170 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
12232 } | 12171 } |
12233 | 12172 |
12234 - (instancetype)init { | 12173 - (instancetype)init { |
12235 return [self initWithBools:NULL forKeys:NULL count:0]; | 12174 return [self initWithValues:NULL forKeys:NULL count:0]; |
12236 } | 12175 } |
12237 | 12176 |
12238 - (instancetype)initWithBools:(const BOOL [])values | 12177 - (instancetype)initWithValues:(const BOOL [])values |
12239 forKeys:(const BOOL [])keys | 12178 forKeys:(const BOOL [])keys |
12240 count:(NSUInteger)count { | 12179 count:(NSUInteger)count { |
12241 self = [super init]; | 12180 self = [super init]; |
12242 if (self) { | 12181 if (self) { |
12243 for (NSUInteger i = 0; i < count; ++i) { | 12182 for (NSUInteger i = 0; i < count; ++i) { |
12244 int idx = keys[i] ? 1 : 0; | 12183 int idx = keys[i] ? 1 : 0; |
12245 _values[idx] = values[i]; | 12184 _values[idx] = values[i]; |
12246 _valueSet[idx] = YES; | 12185 _valueSet[idx] = YES; |
12247 } | 12186 } |
12248 } | 12187 } |
12249 return self; | 12188 return self; |
12250 } | 12189 } |
12251 | 12190 |
12252 - (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary { | 12191 - (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary { |
12253 self = [self initWithBools:NULL forKeys:NULL count:0]; | 12192 self = [self initWithValues:NULL forKeys:NULL count:0]; |
12254 if (self) { | 12193 if (self) { |
12255 if (dictionary) { | 12194 if (dictionary) { |
12256 for (int i = 0; i < 2; ++i) { | 12195 for (int i = 0; i < 2; ++i) { |
12257 if (dictionary->_valueSet[i]) { | 12196 if (dictionary->_valueSet[i]) { |
12258 _values[i] = dictionary->_values[i]; | 12197 _values[i] = dictionary->_values[i]; |
12259 _valueSet[i] = YES; | 12198 _valueSet[i] = YES; |
12260 } | 12199 } |
12261 } | 12200 } |
12262 } | 12201 } |
12263 } | 12202 } |
12264 return self; | 12203 return self; |
12265 } | 12204 } |
12266 | 12205 |
12267 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 12206 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
12268 #pragma unused(numItems) | 12207 #pragma unused(numItems) |
12269 return [self initWithBools:NULL forKeys:NULL count:0]; | 12208 return [self initWithValues:NULL forKeys:NULL count:0]; |
12270 } | 12209 } |
12271 | 12210 |
12272 #if !defined(NS_BLOCK_ASSERTIONS) | 12211 #if !defined(NS_BLOCK_ASSERTIONS) |
12273 - (void)dealloc { | 12212 - (void)dealloc { |
12274 NSAssert(!_autocreator, | 12213 NSAssert(!_autocreator, |
12275 @"%@: Autocreator must be cleared before release, autocreator: %@", | 12214 @"%@: Autocreator must be cleared before release, autocreator: %@", |
12276 [self class], _autocreator); | 12215 [self class], _autocreator); |
12277 [super dealloc]; | 12216 [super dealloc]; |
12278 } | 12217 } |
12279 #endif // !defined(NS_BLOCK_ASSERTIONS) | 12218 #endif // !defined(NS_BLOCK_ASSERTIONS) |
12280 | 12219 |
12281 - (instancetype)copyWithZone:(NSZone *)zone { | 12220 - (instancetype)copyWithZone:(NSZone *)zone { |
12282 return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self]; | 12221 return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self]; |
12283 } | 12222 } |
12284 | 12223 |
12285 - (BOOL)isEqual:(id)other { | 12224 - (BOOL)isEqual:(GPBBoolBoolDictionary *)other { |
12286 if (self == other) { | 12225 if (self == other) { |
12287 return YES; | 12226 return YES; |
12288 } | 12227 } |
12289 if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) { | 12228 if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) { |
12290 return NO; | 12229 return NO; |
12291 } | 12230 } |
12292 GPBBoolBoolDictionary *otherDictionary = other; | 12231 if ((_valueSet[0] != other->_valueSet[0]) || |
12293 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || | 12232 (_valueSet[1] != other->_valueSet[1])) { |
12294 (_valueSet[1] != otherDictionary->_valueSet[1])) { | |
12295 return NO; | 12233 return NO; |
12296 } | 12234 } |
12297 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || | 12235 if ((_valueSet[0] && (_values[0] != other->_values[0])) || |
12298 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { | 12236 (_valueSet[1] && (_values[1] != other->_values[1]))) { |
12299 return NO; | 12237 return NO; |
12300 } | 12238 } |
12301 return YES; | 12239 return YES; |
12302 } | 12240 } |
12303 | 12241 |
12304 - (NSUInteger)hash { | 12242 - (NSUInteger)hash { |
12305 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12243 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12306 } | 12244 } |
12307 | 12245 |
12308 - (NSString *)description { | 12246 - (NSString *)description { |
12309 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 12247 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
12310 if (_valueSet[0]) { | 12248 if (_valueSet[0]) { |
12311 [result appendFormat:@"NO: %d", _values[0]]; | 12249 [result appendFormat:@"NO: %d", _values[0]]; |
12312 } | 12250 } |
12313 if (_valueSet[1]) { | 12251 if (_valueSet[1]) { |
12314 [result appendFormat:@"YES: %d", _values[1]]; | 12252 [result appendFormat:@"YES: %d", _values[1]]; |
12315 } | 12253 } |
12316 [result appendString:@" }"]; | 12254 [result appendString:@" }"]; |
12317 return result; | 12255 return result; |
12318 } | 12256 } |
12319 | 12257 |
12320 - (NSUInteger)count { | 12258 - (NSUInteger)count { |
12321 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12259 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12322 } | 12260 } |
12323 | 12261 |
12324 - (BOOL)getBool:(BOOL *)value forKey:(BOOL)key { | 12262 - (BOOL)valueForKey:(BOOL)key value:(BOOL *)value { |
12325 int idx = (key ? 1 : 0); | 12263 int idx = (key ? 1 : 0); |
12326 if (_valueSet[idx]) { | 12264 if (_valueSet[idx]) { |
12327 if (value) { | 12265 if (value) { |
12328 *value = _values[idx]; | 12266 *value = _values[idx]; |
12329 } | 12267 } |
12330 return YES; | 12268 return YES; |
12331 } | 12269 } |
12332 return NO; | 12270 return NO; |
12333 } | 12271 } |
12334 | 12272 |
12335 - (void)setGPBGenericValue:(GPBGenericValue *)value | 12273 - (void)setGPBGenericValue:(GPBGenericValue *)value |
12336 forGPBGenericValueKey:(GPBGenericValue *)key { | 12274 forGPBGenericValueKey:(GPBGenericValue *)key { |
12337 int idx = (key->valueBool ? 1 : 0); | 12275 int idx = (key->valueBool ? 1 : 0); |
12338 _values[idx] = value->valueBool; | 12276 _values[idx] = value->valueBool; |
12339 _valueSet[idx] = YES; | 12277 _valueSet[idx] = YES; |
12340 } | 12278 } |
12341 | 12279 |
12342 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 12280 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
12343 if (_valueSet[0]) { | 12281 if (_valueSet[0]) { |
12344 block(@"false", (_values[0] ? @"true" : @"false")); | 12282 block(@"false", (_values[0] ? @"true" : @"false")); |
12345 } | 12283 } |
12346 if (_valueSet[1]) { | 12284 if (_valueSet[1]) { |
12347 block(@"true", (_values[1] ? @"true" : @"false")); | 12285 block(@"true", (_values[1] ? @"true" : @"false")); |
12348 } | 12286 } |
12349 } | 12287 } |
12350 | 12288 |
12351 - (void)enumerateKeysAndBoolsUsingBlock: | 12289 - (void)enumerateKeysAndValuesUsingBlock: |
12352 (void (^)(BOOL key, BOOL value, BOOL *stop))block { | 12290 (void (^)(BOOL key, BOOL value, BOOL *stop))block { |
12353 BOOL stop = NO; | 12291 BOOL stop = NO; |
12354 if (_valueSet[0]) { | 12292 if (_valueSet[0]) { |
12355 block(NO, _values[0], &stop); | 12293 block(NO, _values[0], &stop); |
12356 } | 12294 } |
12357 if (!stop && _valueSet[1]) { | 12295 if (!stop && _valueSet[1]) { |
12358 block(YES, _values[1], &stop); | 12296 block(YES, _values[1], &stop); |
12359 } | 12297 } |
12360 } | 12298 } |
12361 | 12299 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12402 _valueSet[i] = YES; | 12340 _valueSet[i] = YES; |
12403 _values[i] = otherDictionary->_values[i]; | 12341 _values[i] = otherDictionary->_values[i]; |
12404 } | 12342 } |
12405 } | 12343 } |
12406 if (_autocreator) { | 12344 if (_autocreator) { |
12407 GPBAutocreatedDictionaryModified(_autocreator, self); | 12345 GPBAutocreatedDictionaryModified(_autocreator, self); |
12408 } | 12346 } |
12409 } | 12347 } |
12410 } | 12348 } |
12411 | 12349 |
12412 - (void)setBool:(BOOL)value forKey:(BOOL)key { | 12350 - (void)setValue:(BOOL)value forKey:(BOOL)key { |
12413 int idx = (key ? 1 : 0); | 12351 int idx = (key ? 1 : 0); |
12414 _values[idx] = value; | 12352 _values[idx] = value; |
12415 _valueSet[idx] = YES; | 12353 _valueSet[idx] = YES; |
12416 if (_autocreator) { | 12354 if (_autocreator) { |
12417 GPBAutocreatedDictionaryModified(_autocreator, self); | 12355 GPBAutocreatedDictionaryModified(_autocreator, self); |
12418 } | 12356 } |
12419 } | 12357 } |
12420 | 12358 |
12421 - (void)removeBoolForKey:(BOOL)aKey { | 12359 - (void)removeValueForKey:(BOOL)aKey { |
12422 _valueSet[aKey ? 1 : 0] = NO; | 12360 _valueSet[aKey ? 1 : 0] = NO; |
12423 } | 12361 } |
12424 | 12362 |
12425 - (void)removeAll { | 12363 - (void)removeAll { |
12426 _valueSet[0] = NO; | 12364 _valueSet[0] = NO; |
12427 _valueSet[1] = NO; | 12365 _valueSet[1] = NO; |
12428 } | 12366 } |
12429 | 12367 |
12430 @end | 12368 @end |
12431 | 12369 |
12432 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float) | 12370 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float) |
12433 // This block of code is generated, do not edit it directly. | 12371 // This block of code is generated, do not edit it directly. |
12434 | 12372 |
12435 #pragma mark - Bool -> Float | 12373 #pragma mark - Bool -> Float |
12436 | 12374 |
12437 @implementation GPBBoolFloatDictionary { | 12375 @implementation GPBBoolFloatDictionary { |
12438 @package | 12376 @package |
12439 float _values[2]; | 12377 float _values[2]; |
12440 BOOL _valueSet[2]; | 12378 BOOL _valueSet[2]; |
12441 } | 12379 } |
12442 | 12380 |
12443 + (instancetype)dictionary { | 12381 + (instancetype)dictionary { |
12444 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; | 12382 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
12445 } | 12383 } |
12446 | 12384 |
12447 + (instancetype)dictionaryWithFloat:(float)value | 12385 + (instancetype)dictionaryWithValue:(float)value |
12448 forKey:(BOOL)key { | 12386 forKey:(BOOL)key { |
12449 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 12387 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
12450 // on to get the type correct. | 12388 // on to get the type correct. |
12451 return [[(GPBBoolFloatDictionary*)[self alloc] initWithFloats:&value | 12389 return [[(GPBBoolFloatDictionary*)[self alloc] initWithValues:&value |
12452 forKeys:&key | 12390 forKeys:&key |
12453 count:1] autorelease]; | 12391 count:1] autorelease]; |
12454 } | 12392 } |
12455 | 12393 |
12456 + (instancetype)dictionaryWithFloats:(const float [])values | 12394 + (instancetype)dictionaryWithValues:(const float [])values |
12457 forKeys:(const BOOL [])keys | 12395 forKeys:(const BOOL [])keys |
12458 count:(NSUInteger)count { | 12396 count:(NSUInteger)count { |
12459 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: | 12397 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
12460 // on to get the type correct. | 12398 // on to get the type correct. |
12461 return [[(GPBBoolFloatDictionary*)[self alloc] initWithFloats:values | 12399 return [[(GPBBoolFloatDictionary*)[self alloc] initWithValues:values |
12462 forKeys:keys | 12400 forKeys:keys |
12463 count:count] autorelea
se]; | 12401 count:count] autorelea
se]; |
12464 } | 12402 } |
12465 | 12403 |
12466 + (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary { | 12404 + (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary { |
12467 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 12405 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
12468 // on to get the type correct. | 12406 // on to get the type correct. |
12469 return [[(GPBBoolFloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 12407 return [[(GPBBoolFloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
12470 } | 12408 } |
12471 | 12409 |
12472 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 12410 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
12473 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 12411 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
12474 } | 12412 } |
12475 | 12413 |
12476 - (instancetype)init { | 12414 - (instancetype)init { |
12477 return [self initWithFloats:NULL forKeys:NULL count:0]; | 12415 return [self initWithValues:NULL forKeys:NULL count:0]; |
12478 } | 12416 } |
12479 | 12417 |
12480 - (instancetype)initWithFloats:(const float [])values | 12418 - (instancetype)initWithValues:(const float [])values |
12481 forKeys:(const BOOL [])keys | 12419 forKeys:(const BOOL [])keys |
12482 count:(NSUInteger)count { | 12420 count:(NSUInteger)count { |
12483 self = [super init]; | 12421 self = [super init]; |
12484 if (self) { | 12422 if (self) { |
12485 for (NSUInteger i = 0; i < count; ++i) { | 12423 for (NSUInteger i = 0; i < count; ++i) { |
12486 int idx = keys[i] ? 1 : 0; | 12424 int idx = keys[i] ? 1 : 0; |
12487 _values[idx] = values[i]; | 12425 _values[idx] = values[i]; |
12488 _valueSet[idx] = YES; | 12426 _valueSet[idx] = YES; |
12489 } | 12427 } |
12490 } | 12428 } |
12491 return self; | 12429 return self; |
12492 } | 12430 } |
12493 | 12431 |
12494 - (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary { | 12432 - (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary { |
12495 self = [self initWithFloats:NULL forKeys:NULL count:0]; | 12433 self = [self initWithValues:NULL forKeys:NULL count:0]; |
12496 if (self) { | 12434 if (self) { |
12497 if (dictionary) { | 12435 if (dictionary) { |
12498 for (int i = 0; i < 2; ++i) { | 12436 for (int i = 0; i < 2; ++i) { |
12499 if (dictionary->_valueSet[i]) { | 12437 if (dictionary->_valueSet[i]) { |
12500 _values[i] = dictionary->_values[i]; | 12438 _values[i] = dictionary->_values[i]; |
12501 _valueSet[i] = YES; | 12439 _valueSet[i] = YES; |
12502 } | 12440 } |
12503 } | 12441 } |
12504 } | 12442 } |
12505 } | 12443 } |
12506 return self; | 12444 return self; |
12507 } | 12445 } |
12508 | 12446 |
12509 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 12447 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
12510 #pragma unused(numItems) | 12448 #pragma unused(numItems) |
12511 return [self initWithFloats:NULL forKeys:NULL count:0]; | 12449 return [self initWithValues:NULL forKeys:NULL count:0]; |
12512 } | 12450 } |
12513 | 12451 |
12514 #if !defined(NS_BLOCK_ASSERTIONS) | 12452 #if !defined(NS_BLOCK_ASSERTIONS) |
12515 - (void)dealloc { | 12453 - (void)dealloc { |
12516 NSAssert(!_autocreator, | 12454 NSAssert(!_autocreator, |
12517 @"%@: Autocreator must be cleared before release, autocreator: %@", | 12455 @"%@: Autocreator must be cleared before release, autocreator: %@", |
12518 [self class], _autocreator); | 12456 [self class], _autocreator); |
12519 [super dealloc]; | 12457 [super dealloc]; |
12520 } | 12458 } |
12521 #endif // !defined(NS_BLOCK_ASSERTIONS) | 12459 #endif // !defined(NS_BLOCK_ASSERTIONS) |
12522 | 12460 |
12523 - (instancetype)copyWithZone:(NSZone *)zone { | 12461 - (instancetype)copyWithZone:(NSZone *)zone { |
12524 return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self]; | 12462 return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self]; |
12525 } | 12463 } |
12526 | 12464 |
12527 - (BOOL)isEqual:(id)other { | 12465 - (BOOL)isEqual:(GPBBoolFloatDictionary *)other { |
12528 if (self == other) { | 12466 if (self == other) { |
12529 return YES; | 12467 return YES; |
12530 } | 12468 } |
12531 if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) { | 12469 if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) { |
12532 return NO; | 12470 return NO; |
12533 } | 12471 } |
12534 GPBBoolFloatDictionary *otherDictionary = other; | 12472 if ((_valueSet[0] != other->_valueSet[0]) || |
12535 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || | 12473 (_valueSet[1] != other->_valueSet[1])) { |
12536 (_valueSet[1] != otherDictionary->_valueSet[1])) { | |
12537 return NO; | 12474 return NO; |
12538 } | 12475 } |
12539 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || | 12476 if ((_valueSet[0] && (_values[0] != other->_values[0])) || |
12540 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { | 12477 (_valueSet[1] && (_values[1] != other->_values[1]))) { |
12541 return NO; | 12478 return NO; |
12542 } | 12479 } |
12543 return YES; | 12480 return YES; |
12544 } | 12481 } |
12545 | 12482 |
12546 - (NSUInteger)hash { | 12483 - (NSUInteger)hash { |
12547 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12484 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12548 } | 12485 } |
12549 | 12486 |
12550 - (NSString *)description { | 12487 - (NSString *)description { |
12551 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 12488 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
12552 if (_valueSet[0]) { | 12489 if (_valueSet[0]) { |
12553 [result appendFormat:@"NO: %f", _values[0]]; | 12490 [result appendFormat:@"NO: %f", _values[0]]; |
12554 } | 12491 } |
12555 if (_valueSet[1]) { | 12492 if (_valueSet[1]) { |
12556 [result appendFormat:@"YES: %f", _values[1]]; | 12493 [result appendFormat:@"YES: %f", _values[1]]; |
12557 } | 12494 } |
12558 [result appendString:@" }"]; | 12495 [result appendString:@" }"]; |
12559 return result; | 12496 return result; |
12560 } | 12497 } |
12561 | 12498 |
12562 - (NSUInteger)count { | 12499 - (NSUInteger)count { |
12563 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12500 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12564 } | 12501 } |
12565 | 12502 |
12566 - (BOOL)getFloat:(float *)value forKey:(BOOL)key { | 12503 - (BOOL)valueForKey:(BOOL)key value:(float *)value { |
12567 int idx = (key ? 1 : 0); | 12504 int idx = (key ? 1 : 0); |
12568 if (_valueSet[idx]) { | 12505 if (_valueSet[idx]) { |
12569 if (value) { | 12506 if (value) { |
12570 *value = _values[idx]; | 12507 *value = _values[idx]; |
12571 } | 12508 } |
12572 return YES; | 12509 return YES; |
12573 } | 12510 } |
12574 return NO; | 12511 return NO; |
12575 } | 12512 } |
12576 | 12513 |
12577 - (void)setGPBGenericValue:(GPBGenericValue *)value | 12514 - (void)setGPBGenericValue:(GPBGenericValue *)value |
12578 forGPBGenericValueKey:(GPBGenericValue *)key { | 12515 forGPBGenericValueKey:(GPBGenericValue *)key { |
12579 int idx = (key->valueBool ? 1 : 0); | 12516 int idx = (key->valueBool ? 1 : 0); |
12580 _values[idx] = value->valueFloat; | 12517 _values[idx] = value->valueFloat; |
12581 _valueSet[idx] = YES; | 12518 _valueSet[idx] = YES; |
12582 } | 12519 } |
12583 | 12520 |
12584 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 12521 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
12585 if (_valueSet[0]) { | 12522 if (_valueSet[0]) { |
12586 block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]); | 12523 block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]); |
12587 } | 12524 } |
12588 if (_valueSet[1]) { | 12525 if (_valueSet[1]) { |
12589 block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]); | 12526 block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]); |
12590 } | 12527 } |
12591 } | 12528 } |
12592 | 12529 |
12593 - (void)enumerateKeysAndFloatsUsingBlock: | 12530 - (void)enumerateKeysAndValuesUsingBlock: |
12594 (void (^)(BOOL key, float value, BOOL *stop))block { | 12531 (void (^)(BOOL key, float value, BOOL *stop))block { |
12595 BOOL stop = NO; | 12532 BOOL stop = NO; |
12596 if (_valueSet[0]) { | 12533 if (_valueSet[0]) { |
12597 block(NO, _values[0], &stop); | 12534 block(NO, _values[0], &stop); |
12598 } | 12535 } |
12599 if (!stop && _valueSet[1]) { | 12536 if (!stop && _valueSet[1]) { |
12600 block(YES, _values[1], &stop); | 12537 block(YES, _values[1], &stop); |
12601 } | 12538 } |
12602 } | 12539 } |
12603 | 12540 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12644 _valueSet[i] = YES; | 12581 _valueSet[i] = YES; |
12645 _values[i] = otherDictionary->_values[i]; | 12582 _values[i] = otherDictionary->_values[i]; |
12646 } | 12583 } |
12647 } | 12584 } |
12648 if (_autocreator) { | 12585 if (_autocreator) { |
12649 GPBAutocreatedDictionaryModified(_autocreator, self); | 12586 GPBAutocreatedDictionaryModified(_autocreator, self); |
12650 } | 12587 } |
12651 } | 12588 } |
12652 } | 12589 } |
12653 | 12590 |
12654 - (void)setFloat:(float)value forKey:(BOOL)key { | 12591 - (void)setValue:(float)value forKey:(BOOL)key { |
12655 int idx = (key ? 1 : 0); | 12592 int idx = (key ? 1 : 0); |
12656 _values[idx] = value; | 12593 _values[idx] = value; |
12657 _valueSet[idx] = YES; | 12594 _valueSet[idx] = YES; |
12658 if (_autocreator) { | 12595 if (_autocreator) { |
12659 GPBAutocreatedDictionaryModified(_autocreator, self); | 12596 GPBAutocreatedDictionaryModified(_autocreator, self); |
12660 } | 12597 } |
12661 } | 12598 } |
12662 | 12599 |
12663 - (void)removeFloatForKey:(BOOL)aKey { | 12600 - (void)removeValueForKey:(BOOL)aKey { |
12664 _valueSet[aKey ? 1 : 0] = NO; | 12601 _valueSet[aKey ? 1 : 0] = NO; |
12665 } | 12602 } |
12666 | 12603 |
12667 - (void)removeAll { | 12604 - (void)removeAll { |
12668 _valueSet[0] = NO; | 12605 _valueSet[0] = NO; |
12669 _valueSet[1] = NO; | 12606 _valueSet[1] = NO; |
12670 } | 12607 } |
12671 | 12608 |
12672 @end | 12609 @end |
12673 | 12610 |
12674 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double) | 12611 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double) |
12675 // This block of code is generated, do not edit it directly. | 12612 // This block of code is generated, do not edit it directly. |
12676 | 12613 |
12677 #pragma mark - Bool -> Double | 12614 #pragma mark - Bool -> Double |
12678 | 12615 |
12679 @implementation GPBBoolDoubleDictionary { | 12616 @implementation GPBBoolDoubleDictionary { |
12680 @package | 12617 @package |
12681 double _values[2]; | 12618 double _values[2]; |
12682 BOOL _valueSet[2]; | 12619 BOOL _valueSet[2]; |
12683 } | 12620 } |
12684 | 12621 |
12685 + (instancetype)dictionary { | 12622 + (instancetype)dictionary { |
12686 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; | 12623 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; |
12687 } | 12624 } |
12688 | 12625 |
12689 + (instancetype)dictionaryWithDouble:(double)value | 12626 + (instancetype)dictionaryWithValue:(double)value |
12690 forKey:(BOOL)key { | 12627 forKey:(BOOL)key { |
12691 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 12628 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
12692 // on to get the type correct. | 12629 // on to get the type correct. |
12693 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDoubles:&value | 12630 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithValues:&value |
12694 forKeys:&key | 12631 forKeys:&key |
12695 count:1] autorelease
]; | 12632 count:1] autorelease]
; |
12696 } | 12633 } |
12697 | 12634 |
12698 + (instancetype)dictionaryWithDoubles:(const double [])values | 12635 + (instancetype)dictionaryWithValues:(const double [])values |
12699 forKeys:(const BOOL [])keys | 12636 forKeys:(const BOOL [])keys |
12700 count:(NSUInteger)count { | 12637 count:(NSUInteger)count { |
12701 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: | 12638 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: |
12702 // on to get the type correct. | 12639 // on to get the type correct. |
12703 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDoubles:values | 12640 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithValues:values |
12704 forKeys:keys | 12641 forKeys:keys |
12705 count:count] autorel
ease]; | 12642 count:count] autorele
ase]; |
12706 } | 12643 } |
12707 | 12644 |
12708 + (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary { | 12645 + (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary { |
12709 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 12646 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
12710 // on to get the type correct. | 12647 // on to get the type correct. |
12711 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 12648 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
12712 } | 12649 } |
12713 | 12650 |
12714 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 12651 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
12715 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 12652 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
12716 } | 12653 } |
12717 | 12654 |
12718 - (instancetype)init { | 12655 - (instancetype)init { |
12719 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 12656 return [self initWithValues:NULL forKeys:NULL count:0]; |
12720 } | 12657 } |
12721 | 12658 |
12722 - (instancetype)initWithDoubles:(const double [])values | 12659 - (instancetype)initWithValues:(const double [])values |
12723 forKeys:(const BOOL [])keys | 12660 forKeys:(const BOOL [])keys |
12724 count:(NSUInteger)count { | 12661 count:(NSUInteger)count { |
12725 self = [super init]; | 12662 self = [super init]; |
12726 if (self) { | 12663 if (self) { |
12727 for (NSUInteger i = 0; i < count; ++i) { | 12664 for (NSUInteger i = 0; i < count; ++i) { |
12728 int idx = keys[i] ? 1 : 0; | 12665 int idx = keys[i] ? 1 : 0; |
12729 _values[idx] = values[i]; | 12666 _values[idx] = values[i]; |
12730 _valueSet[idx] = YES; | 12667 _valueSet[idx] = YES; |
12731 } | 12668 } |
12732 } | 12669 } |
12733 return self; | 12670 return self; |
12734 } | 12671 } |
12735 | 12672 |
12736 - (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary { | 12673 - (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary { |
12737 self = [self initWithDoubles:NULL forKeys:NULL count:0]; | 12674 self = [self initWithValues:NULL forKeys:NULL count:0]; |
12738 if (self) { | 12675 if (self) { |
12739 if (dictionary) { | 12676 if (dictionary) { |
12740 for (int i = 0; i < 2; ++i) { | 12677 for (int i = 0; i < 2; ++i) { |
12741 if (dictionary->_valueSet[i]) { | 12678 if (dictionary->_valueSet[i]) { |
12742 _values[i] = dictionary->_values[i]; | 12679 _values[i] = dictionary->_values[i]; |
12743 _valueSet[i] = YES; | 12680 _valueSet[i] = YES; |
12744 } | 12681 } |
12745 } | 12682 } |
12746 } | 12683 } |
12747 } | 12684 } |
12748 return self; | 12685 return self; |
12749 } | 12686 } |
12750 | 12687 |
12751 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 12688 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
12752 #pragma unused(numItems) | 12689 #pragma unused(numItems) |
12753 return [self initWithDoubles:NULL forKeys:NULL count:0]; | 12690 return [self initWithValues:NULL forKeys:NULL count:0]; |
12754 } | 12691 } |
12755 | 12692 |
12756 #if !defined(NS_BLOCK_ASSERTIONS) | 12693 #if !defined(NS_BLOCK_ASSERTIONS) |
12757 - (void)dealloc { | 12694 - (void)dealloc { |
12758 NSAssert(!_autocreator, | 12695 NSAssert(!_autocreator, |
12759 @"%@: Autocreator must be cleared before release, autocreator: %@", | 12696 @"%@: Autocreator must be cleared before release, autocreator: %@", |
12760 [self class], _autocreator); | 12697 [self class], _autocreator); |
12761 [super dealloc]; | 12698 [super dealloc]; |
12762 } | 12699 } |
12763 #endif // !defined(NS_BLOCK_ASSERTIONS) | 12700 #endif // !defined(NS_BLOCK_ASSERTIONS) |
12764 | 12701 |
12765 - (instancetype)copyWithZone:(NSZone *)zone { | 12702 - (instancetype)copyWithZone:(NSZone *)zone { |
12766 return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self]; | 12703 return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self]; |
12767 } | 12704 } |
12768 | 12705 |
12769 - (BOOL)isEqual:(id)other { | 12706 - (BOOL)isEqual:(GPBBoolDoubleDictionary *)other { |
12770 if (self == other) { | 12707 if (self == other) { |
12771 return YES; | 12708 return YES; |
12772 } | 12709 } |
12773 if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) { | 12710 if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) { |
12774 return NO; | 12711 return NO; |
12775 } | 12712 } |
12776 GPBBoolDoubleDictionary *otherDictionary = other; | 12713 if ((_valueSet[0] != other->_valueSet[0]) || |
12777 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || | 12714 (_valueSet[1] != other->_valueSet[1])) { |
12778 (_valueSet[1] != otherDictionary->_valueSet[1])) { | |
12779 return NO; | 12715 return NO; |
12780 } | 12716 } |
12781 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || | 12717 if ((_valueSet[0] && (_values[0] != other->_values[0])) || |
12782 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { | 12718 (_valueSet[1] && (_values[1] != other->_values[1]))) { |
12783 return NO; | 12719 return NO; |
12784 } | 12720 } |
12785 return YES; | 12721 return YES; |
12786 } | 12722 } |
12787 | 12723 |
12788 - (NSUInteger)hash { | 12724 - (NSUInteger)hash { |
12789 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12725 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12790 } | 12726 } |
12791 | 12727 |
12792 - (NSString *)description { | 12728 - (NSString *)description { |
12793 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 12729 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
12794 if (_valueSet[0]) { | 12730 if (_valueSet[0]) { |
12795 [result appendFormat:@"NO: %lf", _values[0]]; | 12731 [result appendFormat:@"NO: %lf", _values[0]]; |
12796 } | 12732 } |
12797 if (_valueSet[1]) { | 12733 if (_valueSet[1]) { |
12798 [result appendFormat:@"YES: %lf", _values[1]]; | 12734 [result appendFormat:@"YES: %lf", _values[1]]; |
12799 } | 12735 } |
12800 [result appendString:@" }"]; | 12736 [result appendString:@" }"]; |
12801 return result; | 12737 return result; |
12802 } | 12738 } |
12803 | 12739 |
12804 - (NSUInteger)count { | 12740 - (NSUInteger)count { |
12805 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12741 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12806 } | 12742 } |
12807 | 12743 |
12808 - (BOOL)getDouble:(double *)value forKey:(BOOL)key { | 12744 - (BOOL)valueForKey:(BOOL)key value:(double *)value { |
12809 int idx = (key ? 1 : 0); | 12745 int idx = (key ? 1 : 0); |
12810 if (_valueSet[idx]) { | 12746 if (_valueSet[idx]) { |
12811 if (value) { | 12747 if (value) { |
12812 *value = _values[idx]; | 12748 *value = _values[idx]; |
12813 } | 12749 } |
12814 return YES; | 12750 return YES; |
12815 } | 12751 } |
12816 return NO; | 12752 return NO; |
12817 } | 12753 } |
12818 | 12754 |
12819 - (void)setGPBGenericValue:(GPBGenericValue *)value | 12755 - (void)setGPBGenericValue:(GPBGenericValue *)value |
12820 forGPBGenericValueKey:(GPBGenericValue *)key { | 12756 forGPBGenericValueKey:(GPBGenericValue *)key { |
12821 int idx = (key->valueBool ? 1 : 0); | 12757 int idx = (key->valueBool ? 1 : 0); |
12822 _values[idx] = value->valueDouble; | 12758 _values[idx] = value->valueDouble; |
12823 _valueSet[idx] = YES; | 12759 _valueSet[idx] = YES; |
12824 } | 12760 } |
12825 | 12761 |
12826 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 12762 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
12827 if (_valueSet[0]) { | 12763 if (_valueSet[0]) { |
12828 block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]); | 12764 block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]); |
12829 } | 12765 } |
12830 if (_valueSet[1]) { | 12766 if (_valueSet[1]) { |
12831 block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]); | 12767 block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]); |
12832 } | 12768 } |
12833 } | 12769 } |
12834 | 12770 |
12835 - (void)enumerateKeysAndDoublesUsingBlock: | 12771 - (void)enumerateKeysAndValuesUsingBlock: |
12836 (void (^)(BOOL key, double value, BOOL *stop))block { | 12772 (void (^)(BOOL key, double value, BOOL *stop))block { |
12837 BOOL stop = NO; | 12773 BOOL stop = NO; |
12838 if (_valueSet[0]) { | 12774 if (_valueSet[0]) { |
12839 block(NO, _values[0], &stop); | 12775 block(NO, _values[0], &stop); |
12840 } | 12776 } |
12841 if (!stop && _valueSet[1]) { | 12777 if (!stop && _valueSet[1]) { |
12842 block(YES, _values[1], &stop); | 12778 block(YES, _values[1], &stop); |
12843 } | 12779 } |
12844 } | 12780 } |
12845 | 12781 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12886 _valueSet[i] = YES; | 12822 _valueSet[i] = YES; |
12887 _values[i] = otherDictionary->_values[i]; | 12823 _values[i] = otherDictionary->_values[i]; |
12888 } | 12824 } |
12889 } | 12825 } |
12890 if (_autocreator) { | 12826 if (_autocreator) { |
12891 GPBAutocreatedDictionaryModified(_autocreator, self); | 12827 GPBAutocreatedDictionaryModified(_autocreator, self); |
12892 } | 12828 } |
12893 } | 12829 } |
12894 } | 12830 } |
12895 | 12831 |
12896 - (void)setDouble:(double)value forKey:(BOOL)key { | 12832 - (void)setValue:(double)value forKey:(BOOL)key { |
12897 int idx = (key ? 1 : 0); | 12833 int idx = (key ? 1 : 0); |
12898 _values[idx] = value; | 12834 _values[idx] = value; |
12899 _valueSet[idx] = YES; | 12835 _valueSet[idx] = YES; |
12900 if (_autocreator) { | 12836 if (_autocreator) { |
12901 GPBAutocreatedDictionaryModified(_autocreator, self); | 12837 GPBAutocreatedDictionaryModified(_autocreator, self); |
12902 } | 12838 } |
12903 } | 12839 } |
12904 | 12840 |
12905 - (void)removeDoubleForKey:(BOOL)aKey { | 12841 - (void)removeValueForKey:(BOOL)aKey { |
12906 _valueSet[aKey ? 1 : 0] = NO; | 12842 _valueSet[aKey ? 1 : 0] = NO; |
12907 } | 12843 } |
12908 | 12844 |
12909 - (void)removeAll { | 12845 - (void)removeAll { |
12910 _valueSet[0] = NO; | 12846 _valueSet[0] = NO; |
12911 _valueSet[1] = NO; | 12847 _valueSet[1] = NO; |
12912 } | 12848 } |
12913 | 12849 |
12914 @end | 12850 @end |
12915 | 12851 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13000 [self class], _autocreator); | 12936 [self class], _autocreator); |
13001 [_values[0] release]; | 12937 [_values[0] release]; |
13002 [_values[1] release]; | 12938 [_values[1] release]; |
13003 [super dealloc]; | 12939 [super dealloc]; |
13004 } | 12940 } |
13005 | 12941 |
13006 - (instancetype)copyWithZone:(NSZone *)zone { | 12942 - (instancetype)copyWithZone:(NSZone *)zone { |
13007 return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self]; | 12943 return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self]; |
13008 } | 12944 } |
13009 | 12945 |
13010 - (BOOL)isEqual:(id)other { | 12946 - (BOOL)isEqual:(GPBBoolObjectDictionary *)other { |
13011 if (self == other) { | 12947 if (self == other) { |
13012 return YES; | 12948 return YES; |
13013 } | 12949 } |
13014 if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) { | 12950 if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) { |
13015 return NO; | 12951 return NO; |
13016 } | 12952 } |
13017 GPBBoolObjectDictionary *otherDictionary = other; | 12953 if (((_values[0] != nil) != (other->_values[0] != nil)) || |
13018 if (((_values[0] != nil) != (otherDictionary->_values[0] != nil)) || | 12954 ((_values[1] != nil) != (other->_values[1] != nil))) { |
13019 ((_values[1] != nil) != (otherDictionary->_values[1] != nil))) { | |
13020 return NO; | 12955 return NO; |
13021 } | 12956 } |
13022 if (((_values[0] != nil) && (![_values[0] isEqual:otherDictionary->_values[0]]
)) || | 12957 if (((_values[0] != nil) && (![_values[0] isEqual:other->_values[0]])) || |
13023 ((_values[1] != nil) && (![_values[1] isEqual:otherDictionary->_values[1]]
))) { | 12958 ((_values[1] != nil) && (![_values[1] isEqual:other->_values[1]]))) { |
13024 return NO; | 12959 return NO; |
13025 } | 12960 } |
13026 return YES; | 12961 return YES; |
13027 } | 12962 } |
13028 | 12963 |
13029 - (NSUInteger)hash { | 12964 - (NSUInteger)hash { |
13030 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0); | 12965 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0); |
13031 } | 12966 } |
13032 | 12967 |
13033 - (NSString *)description { | 12968 - (NSString *)description { |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13291 @"%@: Autocreator must be cleared before release, autocreator: %@", | 13226 @"%@: Autocreator must be cleared before release, autocreator: %@", |
13292 [self class], _autocreator); | 13227 [self class], _autocreator); |
13293 [super dealloc]; | 13228 [super dealloc]; |
13294 } | 13229 } |
13295 #endif // !defined(NS_BLOCK_ASSERTIONS) | 13230 #endif // !defined(NS_BLOCK_ASSERTIONS) |
13296 | 13231 |
13297 - (instancetype)copyWithZone:(NSZone *)zone { | 13232 - (instancetype)copyWithZone:(NSZone *)zone { |
13298 return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self]; | 13233 return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self]; |
13299 } | 13234 } |
13300 | 13235 |
13301 - (BOOL)isEqual:(id)other { | 13236 - (BOOL)isEqual:(GPBBoolEnumDictionary *)other { |
13302 if (self == other) { | 13237 if (self == other) { |
13303 return YES; | 13238 return YES; |
13304 } | 13239 } |
13305 if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) { | 13240 if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) { |
13306 return NO; | 13241 return NO; |
13307 } | 13242 } |
13308 GPBBoolEnumDictionary *otherDictionary = other; | 13243 if ((_valueSet[0] != other->_valueSet[0]) || |
13309 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || | 13244 (_valueSet[1] != other->_valueSet[1])) { |
13310 (_valueSet[1] != otherDictionary->_valueSet[1])) { | |
13311 return NO; | 13245 return NO; |
13312 } | 13246 } |
13313 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || | 13247 if ((_valueSet[0] && (_values[0] != other->_values[0])) || |
13314 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { | 13248 (_valueSet[1] && (_values[1] != other->_values[1]))) { |
13315 return NO; | 13249 return NO; |
13316 } | 13250 } |
13317 return YES; | 13251 return YES; |
13318 } | 13252 } |
13319 | 13253 |
13320 - (NSUInteger)hash { | 13254 - (NSUInteger)hash { |
13321 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 13255 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
13322 } | 13256 } |
13323 | 13257 |
13324 - (NSString *)description { | 13258 - (NSString *)description { |
13325 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 13259 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
13326 if (_valueSet[0]) { | 13260 if (_valueSet[0]) { |
13327 [result appendFormat:@"NO: %d", _values[0]]; | 13261 [result appendFormat:@"NO: %d", _values[0]]; |
13328 } | 13262 } |
13329 if (_valueSet[1]) { | 13263 if (_valueSet[1]) { |
13330 [result appendFormat:@"YES: %d", _values[1]]; | 13264 [result appendFormat:@"YES: %d", _values[1]]; |
13331 } | 13265 } |
13332 [result appendString:@" }"]; | 13266 [result appendString:@" }"]; |
13333 return result; | 13267 return result; |
13334 } | 13268 } |
13335 | 13269 |
13336 - (NSUInteger)count { | 13270 - (NSUInteger)count { |
13337 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 13271 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
13338 } | 13272 } |
13339 | 13273 |
13340 - (BOOL)getEnum:(int32_t*)value forKey:(BOOL)key { | 13274 - (BOOL)valueForKey:(BOOL)key value:(int32_t*)value { |
13341 int idx = (key ? 1 : 0); | 13275 int idx = (key ? 1 : 0); |
13342 if (_valueSet[idx]) { | 13276 if (_valueSet[idx]) { |
13343 if (value) { | 13277 if (value) { |
13344 int32_t result = _values[idx]; | 13278 int32_t result = _values[idx]; |
13345 if (!_validationFunc(result)) { | 13279 if (!_validationFunc(result)) { |
13346 result = kGPBUnrecognizedEnumeratorValue; | 13280 result = kGPBUnrecognizedEnumeratorValue; |
13347 } | 13281 } |
13348 *value = result; | 13282 *value = result; |
13349 } | 13283 } |
13350 return YES; | 13284 return YES; |
13351 } | 13285 } |
13352 return NO; | 13286 return NO; |
13353 } | 13287 } |
13354 | 13288 |
13355 - (BOOL)getRawValue:(int32_t*)rawValue forKey:(BOOL)key { | 13289 - (BOOL)valueForKey:(BOOL)key rawValue:(int32_t*)rawValue { |
13356 int idx = (key ? 1 : 0); | 13290 int idx = (key ? 1 : 0); |
13357 if (_valueSet[idx]) { | 13291 if (_valueSet[idx]) { |
13358 if (rawValue) { | 13292 if (rawValue) { |
13359 *rawValue = _values[idx]; | 13293 *rawValue = _values[idx]; |
13360 } | 13294 } |
13361 return YES; | 13295 return YES; |
13362 } | 13296 } |
13363 return NO; | 13297 return NO; |
13364 } | 13298 } |
13365 | 13299 |
13366 - (void)enumerateKeysAndRawValuesUsingBlock: | 13300 - (void)enumerateKeysAndValuesUsingBlock: |
13367 (void (^)(BOOL key, int32_t value, BOOL *stop))block { | 13301 (void (^)(BOOL key, int32_t value, BOOL *stop))block { |
13368 BOOL stop = NO; | 13302 BOOL stop = NO; |
13369 if (_valueSet[0]) { | 13303 if (_valueSet[0]) { |
13370 block(NO, _values[0], &stop); | 13304 block(NO, _values[0], &stop); |
13371 } | 13305 } |
13372 if (!stop && _valueSet[1]) { | 13306 if (!stop && _valueSet[1]) { |
13373 block(YES, _values[1], &stop); | 13307 block(YES, _values[1], &stop); |
13374 } | 13308 } |
13375 } | 13309 } |
13376 | 13310 |
13377 - (void)enumerateKeysAndEnumsUsingBlock: | 13311 - (void)enumerateKeysAndRawValuesUsingBlock: |
13378 (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block { | 13312 (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block { |
13379 BOOL stop = NO; | 13313 BOOL stop = NO; |
13380 GPBEnumValidationFunc func = _validationFunc; | 13314 GPBEnumValidationFunc func = _validationFunc; |
13381 int32_t validatedValue; | 13315 int32_t validatedValue; |
13382 if (_valueSet[0]) { | 13316 if (_valueSet[0]) { |
13383 validatedValue = _values[0]; | 13317 validatedValue = _values[0]; |
13384 if (!func(validatedValue)) { | 13318 if (!func(validatedValue)) { |
13385 validatedValue = kGPBUnrecognizedEnumeratorValue; | 13319 validatedValue = kGPBUnrecognizedEnumeratorValue; |
13386 } | 13320 } |
13387 block(NO, validatedValue, &stop); | 13321 block(NO, validatedValue, &stop); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13472 _valueSet[i] = YES; | 13406 _valueSet[i] = YES; |
13473 _values[i] = otherDictionary->_values[i]; | 13407 _values[i] = otherDictionary->_values[i]; |
13474 } | 13408 } |
13475 } | 13409 } |
13476 if (_autocreator) { | 13410 if (_autocreator) { |
13477 GPBAutocreatedDictionaryModified(_autocreator, self); | 13411 GPBAutocreatedDictionaryModified(_autocreator, self); |
13478 } | 13412 } |
13479 } | 13413 } |
13480 } | 13414 } |
13481 | 13415 |
13482 - (void)setEnum:(int32_t)value forKey:(BOOL)key { | 13416 - (void)setValue:(int32_t)value forKey:(BOOL)key { |
13483 if (!_validationFunc(value)) { | 13417 if (!_validationFunc(value)) { |
13484 [NSException raise:NSInvalidArgumentException | 13418 [NSException raise:NSInvalidArgumentException |
13485 format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum v
alue (%d)", | 13419 format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum v
alue (%d)", |
13486 value]; | 13420 value]; |
13487 } | 13421 } |
13488 int idx = (key ? 1 : 0); | 13422 int idx = (key ? 1 : 0); |
13489 _values[idx] = value; | 13423 _values[idx] = value; |
13490 _valueSet[idx] = YES; | 13424 _valueSet[idx] = YES; |
13491 if (_autocreator) { | 13425 if (_autocreator) { |
13492 GPBAutocreatedDictionaryModified(_autocreator, self); | 13426 GPBAutocreatedDictionaryModified(_autocreator, self); |
13493 } | 13427 } |
13494 } | 13428 } |
13495 | 13429 |
13496 - (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key { | 13430 - (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key { |
13497 int idx = (key ? 1 : 0); | 13431 int idx = (key ? 1 : 0); |
13498 _values[idx] = rawValue; | 13432 _values[idx] = rawValue; |
13499 _valueSet[idx] = YES; | 13433 _valueSet[idx] = YES; |
13500 if (_autocreator) { | 13434 if (_autocreator) { |
13501 GPBAutocreatedDictionaryModified(_autocreator, self); | 13435 GPBAutocreatedDictionaryModified(_autocreator, self); |
13502 } | 13436 } |
13503 } | 13437 } |
13504 | 13438 |
13505 - (void)removeEnumForKey:(BOOL)aKey { | 13439 - (void)removeValueForKey:(BOOL)aKey { |
13506 _valueSet[aKey ? 1 : 0] = NO; | 13440 _valueSet[aKey ? 1 : 0] = NO; |
13507 } | 13441 } |
13508 | 13442 |
13509 - (void)removeAll { | 13443 - (void)removeAll { |
13510 _valueSet[0] = NO; | 13444 _valueSet[0] = NO; |
13511 _valueSet[1] = NO; | 13445 _valueSet[1] = NO; |
13512 } | 13446 } |
13513 | 13447 |
13514 @end | 13448 @end |
13515 | 13449 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13612 } | 13546 } |
13613 | 13547 |
13614 - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts | 13548 - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts |
13615 usingBlock:(void (^)(id key, | 13549 usingBlock:(void (^)(id key, |
13616 id obj, | 13550 id obj, |
13617 BOOL *stop))block { | 13551 BOOL *stop))block { |
13618 [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block]; | 13552 [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block]; |
13619 } | 13553 } |
13620 | 13554 |
13621 @end | 13555 @end |
13622 | |
13623 #pragma clang diagnostic pop | |
OLD | NEW |