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 |
48 // Used to include code only visible to specific versions of the static | 54 // Used to include code only visible to specific versions of the static |
49 // analyzer. Useful for wrapping code that only exists to silence the analyzer. | 55 // analyzer. Useful for wrapping code that only exists to silence the analyzer. |
50 // Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION, | 56 // Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION, |
51 // END_APPLE_BUILD_VERSION using: | 57 // END_APPLE_BUILD_VERSION using: |
52 // xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__ | 58 // xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__ |
53 // Example usage: | 59 // Example usage: |
54 // #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif | 60 // #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif |
55 #define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERS
ION) \ | 61 #define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERS
ION) \ |
56 (defined(__clang_analyzer__) && \ | 62 (defined(__clang_analyzer__) && \ |
57 (__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \ | 63 (__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \ |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 } | 483 } |
478 } | 484 } |
479 } | 485 } |
480 | 486 |
481 if (!hitError) { | 487 if (!hitError) { |
482 // Handle the special defaults and/or missing key/value. | 488 // Handle the special defaults and/or missing key/value. |
483 if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) { | 489 if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) { |
484 key.valueString = [@"" retain]; | 490 key.valueString = [@"" retain]; |
485 } | 491 } |
486 if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) { | 492 if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) { |
| 493 #pragma clang diagnostic push |
| 494 #pragma clang diagnostic ignored "-Wswitch-enum" |
487 switch (valueDataType) { | 495 switch (valueDataType) { |
488 case GPBDataTypeString: | 496 case GPBDataTypeString: |
489 value.valueString = [@"" retain]; | 497 value.valueString = [@"" retain]; |
490 break; | 498 break; |
491 case GPBDataTypeBytes: | 499 case GPBDataTypeBytes: |
492 value.valueData = [GPBEmptyNSData() retain]; | 500 value.valueData = [GPBEmptyNSData() retain]; |
493 break; | 501 break; |
494 #if defined(__clang_analyzer__) | 502 #if defined(__clang_analyzer__) |
495 case GPBDataTypeGroup: | 503 case GPBDataTypeGroup: |
496 // Maps can't really have Groups as the value type, but this case is n
eeded | 504 // Maps can't really have Groups as the value type, but this case is n
eeded |
497 // so the analyzer won't report the posibility of send nil in for the
value | 505 // so the analyzer won't report the posibility of send nil in for the
value |
498 // in the NSMutableDictionary case below. | 506 // in the NSMutableDictionary case below. |
499 #endif | 507 #endif |
500 case GPBDataTypeMessage: { | 508 case GPBDataTypeMessage: { |
501 value.valueMessage = [[field.msgClass alloc] init]; | 509 value.valueMessage = [[field.msgClass alloc] init]; |
502 break; | 510 break; |
503 } | 511 } |
504 default: | 512 default: |
505 // Nothing | 513 // Nothing |
506 break; | 514 break; |
507 } | 515 } |
| 516 #pragma clang diagnostic pop |
508 } | 517 } |
509 | 518 |
510 if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)
) { | 519 if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)
) { |
511 #if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181) | 520 #if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181) |
512 // Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can | 521 // Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can |
513 // be raised as needed for new Xcodes. | 522 // be raised as needed for new Xcodes. |
514 // | 523 // |
515 // This is only needed on a "shallow" analyze; on a "deep" analyze, the | 524 // This is only needed on a "shallow" analyze; on a "deep" analyze, the |
516 // existing code path gets this correct. In shallow, the analyzer decides | 525 // existing code path gets this correct. In shallow, the analyzer decides |
517 // GPBDataTypeIsObject(valueDataType) is both false and true on a single | 526 // GPBDataTypeIsObject(valueDataType) is both false and true on a single |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPE
R) | 570 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPE
R) |
562 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER) | 571 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER) |
563 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPE
R) | 572 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPE
R) |
564 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER) | 573 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER) |
565 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER) | 574 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER) |
566 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER) | 575 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER) |
567 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER) | 576 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER) |
568 //%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER) | 577 //%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER) |
569 | 578 |
570 //%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME,
VALUE_TYPE, KHELPER) | 579 //%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME,
VALUE_TYPE, KHELPER) |
571 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHEL
PER, POD, value) | 580 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHEL
PER, POD, VALUE_NAME, value) |
572 | 581 |
573 //%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME,
VALUE_TYPE) | 582 //%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME,
VALUE_TYPE) |
574 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJ
ECT, object) | 583 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJ
ECT, Object, object) |
575 | 584 |
576 //%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALU
E_TYPE, KHELPER, VHELPER, VNAME) | 585 //%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALU
E_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR) |
577 //%#pragma mark - KEY_NAME -> VALUE_NAME | 586 //%#pragma mark - KEY_NAME -> VALUE_NAME |
578 //% | 587 //% |
579 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { | 588 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { |
580 //% @package | 589 //% @package |
581 //% NSMutableDictionary *_dictionary; | 590 //% NSMutableDictionary *_dictionary; |
582 //%} | 591 //%} |
583 //% | 592 //% |
584 //%+ (instancetype)dictionary { | 593 //%+ (instancetype)dictionary { |
585 //% return [[[self alloc] initWith##VNAME$u##s:NULL forKeys:NULL count:0] autor
elease]; | 594 //% return [[[self alloc] initWith##VNAME##s:NULL forKeys:NULL count:0] autorel
ease]; |
586 //%} | 595 //%} |
587 //% | 596 //% |
588 //%+ (instancetype)dictionaryWith##VNAME$u##:(VALUE_TYPE)##VNAME | 597 //%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)##VNAME_VAR |
589 //% ##VNAME$S## forKey:(KEY_TYPE##KisP$S##KisP)key { | 598 //% ##VNAME$S## forKey:(KEY_TYPE##KisP$S##KisP)key { |
590 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME$u##s:forKeys:count: | 599 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME##s:forKeys:count: |
591 //% // on to get the type correct. | 600 //% // on to get the type correct. |
592 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNA
ME$u##s:&##VNAME | 601 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNA
ME##s:&##VNAME_VAR |
593 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## fo
rKeys:&key | 602 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## fo
rKeys:&key |
594 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S##
count:1] autorelease]; | 603 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S##
count:1] autorelease]; |
595 //%} | 604 //%} |
596 //% | 605 //% |
597 //%+ (instancetype)dictionaryWith##VNAME$u##s:(const VALUE_TYPE [])##VNAME##s | 606 //%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s |
598 //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])k
eys | 607 //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])k
eys |
599 //% ##VNAME$S## count:(NSUInteger)count { | 608 //% ##VNAME$S## count:(NSUInteger)count { |
600 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME$u##s:forKeys:count: | 609 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME##s:forKeys:count: |
601 //% // on to get the type correct. | 610 //% // on to get the type correct. |
602 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNA
ME$u##s:##VNAME##s | 611 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNA
ME##s:##VNAME_VAR##s |
603 //% KEY_NAME$S VALUE_NAME$S forKeys:
keys | 612 //% KEY_NAME$S VALUE_NAME$S forKeys:
keys |
604 //% KEY_NAME$S VALUE_NAME$S count:
count] autorelease]; | 613 //% KEY_NAME$S VALUE_NAME$S count:
count] autorelease]; |
605 //%} | 614 //%} |
606 //% | 615 //% |
607 //%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictiona
ry *)dictionary { | 616 //%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictiona
ry *)dictionary { |
608 //% // Cast is needed so the compiler knows what class we are invoking initWith
Dictionary: | 617 //% // Cast is needed so the compiler knows what class we are invoking initWith
Dictionary: |
609 //% // on to get the type correct. | 618 //% // on to get the type correct. |
610 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDicti
onary:dictionary] autorelease]; | 619 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDicti
onary:dictionary] autorelease]; |
611 //%} | 620 //%} |
612 //% | 621 //% |
613 //%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 622 //%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
614 //% return [[[self alloc] initWithCapacity:numItems] autorelease]; | 623 //% return [[[self alloc] initWithCapacity:numItems] autorelease]; |
615 //%} | 624 //%} |
616 //% | 625 //% |
617 //%- (instancetype)init { | 626 //%- (instancetype)init { |
618 //% return [self initWith##VNAME$u##s:NULL forKeys:NULL count:0]; | 627 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; |
619 //%} | 628 //%} |
620 //% | 629 //% |
621 //%- (instancetype)initWith##VNAME$u##s:(const VALUE_TYPE [])##VNAME##s | 630 //%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s |
622 //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys | 631 //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys |
623 //% ##VNAME$S## count:(NSUInteger)count { | 632 //% ##VNAME$S## count:(NSUInteger)count { |
624 //% self = [super init]; | 633 //% self = [super init]; |
625 //% if (self) { | 634 //% if (self) { |
626 //% _dictionary = [[NSMutableDictionary alloc] init]; | 635 //% _dictionary = [[NSMutableDictionary alloc] init]; |
627 //% if (count && VNAME##s && keys) { | 636 //% if (count && VNAME_VAR##s && keys) { |
628 //% for (NSUInteger i = 0; i < count; ++i) { | 637 //% for (NSUInteger i = 0; i < count; ++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])]; | 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])]; |
630 //% } | 639 //% } |
631 //% } | 640 //% } |
632 //% } | 641 //% } |
633 //% return self; | 642 //% return self; |
634 //%} | 643 //%} |
635 //% | 644 //% |
636 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)d
ictionary { | 645 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)d
ictionary { |
637 //% self = [self initWith##VNAME$u##s:NULL forKeys:NULL count:0]; | 646 //% self = [self initWith##VNAME##s:NULL forKeys:NULL count:0]; |
638 //% if (self) { | 647 //% if (self) { |
639 //% if (dictionary) { | 648 //% if (dictionary) { |
640 //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 649 //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
641 //% } | 650 //% } |
642 //% } | 651 //% } |
643 //% return self; | 652 //% return self; |
644 //%} | 653 //%} |
645 //% | 654 //% |
646 //%- (instancetype)initWithCapacity:(NSUInteger)numItems { | 655 //%- (instancetype)initWithCapacity:(NSUInteger)numItems { |
647 //% #pragma unused(numItems) | 656 //% #pragma unused(numItems) |
648 //% return [self initWith##VNAME$u##s:NULL forKeys:NULL count:0]; | 657 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; |
649 //%} | 658 //%} |
650 //% | 659 //% |
651 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, K
HELPER, VHELPER, VNAME, ) | 660 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, K
HELPER, VHELPER, VNAME, VNAME_VAR, ) |
652 //% | 661 //% |
653 //%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELP
ER) | 662 //%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELP
ER) |
654 //% | 663 //% |
655 //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHE
LPER, VHELPER, VNAME, ) | 664 //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHE
LPER, VHELPER, VNAME, VNAME_VAR, ) |
656 //% | 665 //% |
657 //%@end | 666 //%@end |
658 //% | 667 //% |
659 | 668 |
660 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME,
VALUE_TYPE, KHELPER) | 669 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME,
VALUE_TYPE, KHELPER) |
661 //%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE
, KHELPER, POD) | 670 //%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE
, KHELPER, POD) |
662 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME
, VALUE_TYPE, KHELPER, VHELPER) | 671 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME
, VALUE_TYPE, KHELPER, VHELPER) |
663 //%#pragma mark - KEY_NAME -> VALUE_NAME | 672 //%#pragma mark - KEY_NAME -> VALUE_NAME |
664 //% | 673 //% |
665 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { | 674 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 //% } | 764 //% } |
756 //% return self; | 765 //% return self; |
757 //%} | 766 //%} |
758 //% | 767 //% |
759 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | 768 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func |
760 //% capacity:(NSUInteger)numItems { | 769 //% capacity:(NSUInteger)numItems { |
761 //% #pragma unused(numItems) | 770 //% #pragma unused(numItems) |
762 //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL co
unt:0]; | 771 //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL co
unt:0]; |
763 //%} | 772 //%} |
764 //% | 773 //% |
765 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, K
HELPER, VHELPER, value, Raw) | 774 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, K
HELPER, VHELPER, Value, value, Raw) |
766 //% | 775 //% |
767 //%- (BOOL)valueForKey:(KEY_TYPE##KisP$S##KisP)key value:(VALUE_TYPE *)value { | 776 //%- (BOOL)getEnum:(VALUE_TYPE *)value forKey:(KEY_TYPE##KisP$S##KisP)key { |
768 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; | 777 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; |
769 //% if (wrapped && value) { | 778 //% if (wrapped && value) { |
770 //% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped); | 779 //% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped); |
771 //% if (!_validationFunc(result)) { | 780 //% if (!_validationFunc(result)) { |
772 //% result = kGPBUnrecognizedEnumeratorValue; | 781 //% result = kGPBUnrecognizedEnumeratorValue; |
773 //% } | 782 //% } |
774 //% *value = result; | 783 //% *value = result; |
775 //% } | 784 //% } |
776 //% return (wrapped != NULL); | 785 //% return (wrapped != NULL); |
777 //%} | 786 //%} |
778 //% | 787 //% |
779 //%- (BOOL)valueForKey:(KEY_TYPE##KisP$S##KisP)key rawValue:(VALUE_TYPE *)rawVal
ue { | 788 //%- (BOOL)getRawValue:(VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key
{ |
780 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; | 789 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; |
781 //% if (wrapped && rawValue) { | 790 //% if (wrapped && rawValue) { |
782 //% *rawValue = UNWRAP##VALUE_NAME(wrapped); | 791 //% *rawValue = UNWRAP##VALUE_NAME(wrapped); |
783 //% } | 792 //% } |
784 //% return (wrapped != NULL); | 793 //% return (wrapped != NULL); |
785 //%} | 794 //%} |
786 //% | 795 //% |
787 //%- (void)enumerateKeysAndValuesUsingBlock: | 796 //%- (void)enumerateKeysAndEnumsUsingBlock: |
788 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block { | 797 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block { |
789 //% GPBEnumValidationFunc func = _validationFunc; | 798 //% GPBEnumValidationFunc func = _validationFunc; |
790 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | 799 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, |
791 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##aValue, | 800 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##aValue, |
792 //% BOOL *stop) { | 801 //% BOOL *stop) { |
793 //% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue); | 802 //% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue); |
794 //% if (!func(unwrapped)) { | 803 //% if (!func(unwrapped)) { |
795 //% unwrapped = kGPBUnrecognizedEnumeratorValue; | 804 //% unwrapped = kGPBUnrecognizedEnumeratorValue; |
796 //% } | 805 //% } |
797 //% block(UNWRAP##KEY_NAME(aKey), unwrapped, stop); | 806 //% block(UNWRAP##KEY_NAME(aKey), unwrapped, stop); |
798 //% }]; | 807 //% }]; |
799 //%} | 808 //%} |
800 //% | 809 //% |
801 //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHE
LPER, VHELPER, value, Raw) | 810 //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KH
ELPER, VHELPER, Value, Enum, value, Raw) |
802 //% | 811 //% |
803 //%- (void)setValue:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key { | 812 //%- (void)setEnum:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key { |
804 //%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) { | 813 //%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) { |
805 //% [NSException raise:NSInvalidArgumentException | 814 //% [NSException raise:NSInvalidArgumentException |
806 //% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to se
t an unknown enum value (%d)", | 815 //% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to se
t an unknown enum value (%d)", |
807 //% value]; | 816 //% value]; |
808 //% } | 817 //% } |
809 //% | 818 //% |
810 //% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)
]; | 819 //% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)
]; |
811 //% if (_autocreator) { | 820 //% if (_autocreator) { |
812 //% GPBAutocreatedDictionaryModified(_autocreator, self); | 821 //% GPBAutocreatedDictionaryModified(_autocreator, self); |
813 //% } | 822 //% } |
814 //%} | 823 //%} |
815 //% | 824 //% |
816 //%@end | 825 //%@end |
817 //% | 826 //% |
818 | 827 |
819 //%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, V
ALUE_TYPE, KHELPER, VHELPER, VNAME, ACCESSOR_NAME) | 828 //%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, V
ALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME) |
820 //%- (void)dealloc { | 829 //%- (void)dealloc { |
821 //% NSAssert(!_autocreator, | 830 //% NSAssert(!_autocreator, |
822 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, | 831 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, |
823 //% [self class], _autocreator); | 832 //% [self class], _autocreator); |
824 //% [_dictionary release]; | 833 //% [_dictionary release]; |
825 //% [super dealloc]; | 834 //% [super dealloc]; |
826 //%} | 835 //%} |
827 //% | 836 //% |
828 //%- (instancetype)copyWithZone:(NSZone *)zone { | 837 //%- (instancetype)copyWithZone:(NSZone *)zone { |
829 //% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWith
Dictionary:self]; | 838 //% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWith
Dictionary:self]; |
830 //%} | 839 //%} |
831 //% | 840 //% |
832 //%- (BOOL)isEqual:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)other { | 841 //%- (BOOL)isEqual:(id)other { |
833 //% if (self == other) { | 842 //% if (self == other) { |
834 //% return YES; | 843 //% return YES; |
835 //% } | 844 //% } |
836 //% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) { | 845 //% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) { |
837 //% return NO; | 846 //% return NO; |
838 //% } | 847 //% } |
839 //% return [_dictionary isEqual:other->_dictionary]; | 848 //% GPB##KEY_NAME##VALUE_NAME##Dictionary *otherDictionary = other; |
| 849 //% return [_dictionary isEqual:otherDictionary->_dictionary]; |
840 //%} | 850 //%} |
841 //% | 851 //% |
842 //%- (NSUInteger)hash { | 852 //%- (NSUInteger)hash { |
843 //% return _dictionary.count; | 853 //% return _dictionary.count; |
844 //%} | 854 //%} |
845 //% | 855 //% |
846 //%- (NSString *)description { | 856 //%- (NSString *)description { |
847 //% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _d
ictionary]; | 857 //% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _d
ictionary]; |
848 //%} | 858 //%} |
849 //% | 859 //% |
850 //%- (NSUInteger)count { | 860 //%- (NSUInteger)count { |
851 //% return _dictionary.count; | 861 //% return _dictionary.count; |
852 //%} | 862 //%} |
853 //% | 863 //% |
854 //%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME$u##sUsingBlock: | 864 //%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock: |
855 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME, BOOL *stop))block { | 865 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block { |
856 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | 866 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, |
857 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME$u, | 867 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME_VAR$u, |
858 //% BOOL *stop) { | 868 //% BOOL *stop) { |
859 //% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME$u), stop); | 869 //% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), stop)
; |
860 //% }]; | 870 //% }]; |
861 //%} | 871 //%} |
862 //% | 872 //% |
863 //%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeA
sField:(GPBFieldDescriptor *)field { | 873 //%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeA
sField:(GPBFieldDescriptor *)field { |
864 //% NSUInteger count = _dictionary.count; | 874 //% NSUInteger count = _dictionary.count; |
865 //% if (count == 0) { | 875 //% if (count == 0) { |
866 //% return 0; | 876 //% return 0; |
867 //% } | 877 //% } |
868 //% | 878 //% |
869 //% GPBDataType valueDataType = GPBGetFieldDataType(field); | 879 //% GPBDataType valueDataType = GPBGetFieldDataType(field); |
870 //% GPBDataType keyDataType = field.mapKeyDataType; | 880 //% GPBDataType keyDataType = field.mapKeyDataType; |
871 //% __block size_t result = 0; | 881 //% __block size_t result = 0; |
872 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | 882 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, |
873 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME$u##, | 883 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME_VAR$u##, |
874 //% BOOL *stop) { | 884 //% BOOL *stop) { |
875 //% #pragma unused(stop) | 885 //% #pragma unused(stop) |
876 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey),
kMapKeyFieldNumber, keyDataType); | 886 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey),
kMapKeyFieldNumber, keyDataType); |
877 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME
$u), kMapValueFieldNumber, valueDataType); | 887 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME
_VAR$u), kMapValueFieldNumber, valueDataType); |
878 //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | 888 //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; |
879 //% }]; | 889 //% }]; |
880 //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBData
TypeMessage); | 890 //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBData
TypeMessage); |
881 //% result += tagSize * count; | 891 //% result += tagSize * count; |
882 //% return result; | 892 //% return result; |
883 //%} | 893 //%} |
884 //% | 894 //% |
885 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | 895 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream |
886 //% asField:(GPBFieldDescriptor *)field { | 896 //% asField:(GPBFieldDescriptor *)field { |
887 //% GPBDataType valueDataType = GPBGetFieldDataType(field); | 897 //% GPBDataType valueDataType = GPBGetFieldDataType(field); |
888 //% GPBDataType keyDataType = field.mapKeyDataType; | 898 //% GPBDataType keyDataType = field.mapKeyDataType; |
889 //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLen
gthDelimited); | 899 //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLen
gthDelimited); |
890 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | 900 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, |
891 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME$u, | 901 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##a##VNAME_VAR$u, |
892 //% BOOL *stop) { | 902 //% BOOL *stop) { |
893 //% #pragma unused(stop) | 903 //% #pragma unused(stop) |
894 //% // Write the tag. | 904 //% // Write the tag. |
895 //% [outputStream writeInt32NoTag:tag]; | 905 //% [outputStream writeInt32NoTag:tag]; |
896 //% // Write the size of the message. | 906 //% // Write the size of the message. |
897 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey),
kMapKeyFieldNumber, keyDataType); | 907 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey),
kMapKeyFieldNumber, keyDataType); |
898 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME
$u), kMapValueFieldNumber, valueDataType); | 908 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME
_VAR$u), kMapValueFieldNumber, valueDataType); |
899 //% [outputStream writeInt32NoTag:(int32_t)msgSize]; | 909 //% [outputStream writeInt32NoTag:(int32_t)msgSize]; |
900 //% // Write the fields. | 910 //% // Write the fields. |
901 //% WriteDict##KEY_NAME##Field(outputStream, UNWRAP##KEY_NAME(aKey), kMapKeyF
ieldNumber, keyDataType); | 911 //% WriteDict##KEY_NAME##Field(outputStream, UNWRAP##KEY_NAME(aKey), kMapKeyF
ieldNumber, keyDataType); |
902 //% WriteDict##VALUE_NAME##Field(outputStream, UNWRAP##VALUE_NAME(a##VNAME$u)
, kMapValueFieldNumber, valueDataType); | 912 //% WriteDict##VALUE_NAME##Field(outputStream, UNWRAP##VALUE_NAME(a##VNAME_VA
R$u), kMapValueFieldNumber, valueDataType); |
903 //% }]; | 913 //% }]; |
904 //%} | 914 //%} |
905 //% | 915 //% |
906 //%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericVal
ue:(GPBGenericValue *)value | 916 //%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericVal
ue:(GPBGenericValue *)value |
907 //% forGPBGenericValueKey:(GPBGenericValue *)key { | 917 //% forGPBGenericValueKey:(GPBGenericValue *)key { |
908 //% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_N
AME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)]; | 918 //% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_N
AME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)]; |
909 //%} | 919 //%} |
910 //% | 920 //% |
911 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 921 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
912 //% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME$u##sUsingBlock:^(KEY_TYPE KisP
##key, VALUE_TYPE VNAME, BOOL *stop) { | 922 //% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##
key, VALUE_TYPE VNAME_VAR, BOOL *stop) { |
913 //% #pragma unused(stop) | 923 //% #pragma unused(stop) |
914 //% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME
)); | 924 //% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME
_VAR)); |
915 //% }]; | 925 //% }]; |
916 //%} | 926 //%} |
917 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VAL
UE_TYPE, KHELPER, VHELPER, VNAME, ACCESSOR_NAME) | 927 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VAL
UE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, 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) |
918 //%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME#
#Dictionary *)otherDictionary { | 930 //%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME#
#Dictionary *)otherDictionary { |
919 //% if (otherDictionary) { | 931 //% if (otherDictionary) { |
920 //% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 932 //% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
921 //% if (_autocreator) { | 933 //% if (_autocreator) { |
922 //% GPBAutocreatedDictionaryModified(_autocreator, self); | 934 //% GPBAutocreatedDictionaryModified(_autocreator, self); |
923 //% } | 935 //% } |
924 //% } | 936 //% } |
925 //%} | 937 //%} |
926 //% | 938 //% |
927 //%- (void)set##ACCESSOR_NAME##VNAME$u##:(VALUE_TYPE)VNAME forKey:(KEY_TYPE##Kis
P$S##KisP)key { | 939 //%- (void)set##ACCESSOR_NAME##VNAME##:(VALUE_TYPE)VNAME_VAR forKey:(KEY_TYPE##K
isP$S##KisP)key { |
928 //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME, )##DICTIONARY_VALIDATE_KEY_##KHELP
ER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME) forKey:WRAPPED##KHELPE
R(key)]; | 940 //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR, )##DICTIONARY_VALIDATE_KEY_##K
HELPER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR) forKey:WRAPPED
##KHELPER(key)]; |
929 //% if (_autocreator) { | 941 //% if (_autocreator) { |
930 //% GPBAutocreatedDictionaryModified(_autocreator, self); | 942 //% GPBAutocreatedDictionaryModified(_autocreator, self); |
931 //% } | 943 //% } |
932 //%} | 944 //%} |
933 //% | 945 //% |
934 //%- (void)remove##VNAME$u##ForKey:(KEY_TYPE##KisP$S##KisP)aKey { | 946 //%- (void)remove##VNAME_REMOVE##ForKey:(KEY_TYPE##KisP$S##KisP)aKey { |
935 //% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)]; | 947 //% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)]; |
936 //%} | 948 //%} |
937 //% | 949 //% |
938 //%- (void)removeAll { | 950 //%- (void)removeAll { |
939 //% [_dictionary removeAllObjects]; | 951 //% [_dictionary removeAllObjects]; |
940 //%} | 952 //%} |
941 | 953 |
942 // | 954 // |
943 // Custom Generation for Bool keys | 955 // Custom Generation for Bool keys |
944 // | 956 // |
945 | 957 |
946 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE) | 958 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE) |
947 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, value) | 959 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, va
lue) |
948 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE) | 960 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE) |
949 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, object) | 961 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, Object, obj
ect) |
950 | 962 |
951 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER,
VNAME) | 963 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER,
VNAME, VNAME_VAR) |
952 //%#pragma mark - Bool -> VALUE_NAME | 964 //%#pragma mark - Bool -> VALUE_NAME |
953 //% | 965 //% |
954 //%@implementation GPBBool##VALUE_NAME##Dictionary { | 966 //%@implementation GPBBool##VALUE_NAME##Dictionary { |
955 //% @package | 967 //% @package |
956 //% VALUE_TYPE _values[2]; | 968 //% VALUE_TYPE _values[2]; |
957 //%BOOL_DICT_HAS_STORAGE_##HELPER()} | 969 //%BOOL_DICT_HAS_STORAGE_##HELPER()} |
958 //% | 970 //% |
959 //%+ (instancetype)dictionary { | 971 //%+ (instancetype)dictionary { |
960 //% return [[[self alloc] initWith##VNAME$u##s:NULL forKeys:NULL count:0] autor
elease]; | 972 //% return [[[self alloc] initWith##VNAME##s:NULL forKeys:NULL count:0] autorel
ease]; |
961 //%} | 973 //%} |
962 //% | 974 //% |
963 //%+ (instancetype)dictionaryWith##VNAME$u##:(VALUE_TYPE)VNAME | 975 //%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)VNAME_VAR |
964 //% ##VNAME$S## forKey:(BOOL)key { | 976 //% ##VNAME$S## forKey:(BOOL)key { |
965 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME$u##s:forKeys:count: | 977 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME##s:forKeys:count: |
966 //% // on to get the type correct. | 978 //% // on to get the type correct. |
967 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME$u##
s:&##VNAME | 979 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:
&##VNAME_VAR |
968 //% VALUE_NAME$S ##VNAME$S## forKeys:
&key | 980 //% VALUE_NAME$S ##VNAME$S## forKeys:
&key |
969 //% VALUE_NAME$S ##VNAME$S## count:
1] autorelease]; | 981 //% VALUE_NAME$S ##VNAME$S## count:
1] autorelease]; |
970 //%} | 982 //%} |
971 //% | 983 //% |
972 //%+ (instancetype)dictionaryWith##VNAME$u##s:(const VALUE_TYPE [])##VNAME##s | 984 //%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s |
973 //% ##VNAME$S## forKeys:(const BOOL [])keys | 985 //% ##VNAME$S## forKeys:(const BOOL [])keys |
974 //% ##VNAME$S## count:(NSUInteger)count { | 986 //% ##VNAME$S## count:(NSUInteger)count { |
975 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME$u##s:forKeys:count: | 987 //% // Cast is needed so the compiler knows what class we are invoking initWith
##VNAME##s:forKeys:count: |
976 //% // on to get the type correct. | 988 //% // on to get the type correct. |
977 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME$u##
s:##VNAME##s | 989 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:
##VNAME_VAR##s |
978 //% VALUE_NAME$S ##VNAME$S## forKeys:
keys | 990 //% VALUE_NAME$S ##VNAME$S## forKeys:
keys |
979 //% VALUE_NAME$S ##VNAME$S## count:
count] autorelease]; | 991 //% VALUE_NAME$S ##VNAME$S## count:
count] autorelease]; |
980 //%} | 992 //%} |
981 //% | 993 //% |
982 //%+ (instancetype)dictionaryWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)d
ictionary { | 994 //%+ (instancetype)dictionaryWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)d
ictionary { |
983 //% // Cast is needed so the compiler knows what class we are invoking initWith
Dictionary: | 995 //% // Cast is needed so the compiler knows what class we are invoking initWith
Dictionary: |
984 //% // on to get the type correct. | 996 //% // on to get the type correct. |
985 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:
dictionary] autorelease]; | 997 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:
dictionary] autorelease]; |
986 //%} | 998 //%} |
987 //% | 999 //% |
988 //%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 1000 //%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
989 //% return [[[self alloc] initWithCapacity:numItems] autorelease]; | 1001 //% return [[[self alloc] initWithCapacity:numItems] autorelease]; |
990 //%} | 1002 //%} |
991 //% | 1003 //% |
992 //%- (instancetype)init { | 1004 //%- (instancetype)init { |
993 //% return [self initWith##VNAME$u##s:NULL forKeys:NULL count:0]; | 1005 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; |
994 //%} | 1006 //%} |
995 //% | 1007 //% |
996 //%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE) | 1008 //%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE) |
997 //% | 1009 //% |
998 //%- (instancetype)initWithCapacity:(NSUInteger)numItems { | 1010 //%- (instancetype)initWithCapacity:(NSUInteger)numItems { |
999 //% #pragma unused(numItems) | 1011 //% #pragma unused(numItems) |
1000 //% return [self initWith##VNAME$u##s:NULL forKeys:NULL count:0]; | 1012 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; |
1001 //%} | 1013 //%} |
1002 //% | 1014 //% |
1003 //%BOOL_DICT_DEALLOC##HELPER() | 1015 //%BOOL_DICT_DEALLOC##HELPER() |
1004 //% | 1016 //% |
1005 //%- (instancetype)copyWithZone:(NSZone *)zone { | 1017 //%- (instancetype)copyWithZone:(NSZone *)zone { |
1006 //% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictio
nary:self]; | 1018 //% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictio
nary:self]; |
1007 //%} | 1019 //%} |
1008 //% | 1020 //% |
1009 //%- (BOOL)isEqual:(GPBBool##VALUE_NAME##Dictionary *)other { | 1021 //%- (BOOL)isEqual:(id)other { |
1010 //% if (self == other) { | 1022 //% if (self == other) { |
1011 //% return YES; | 1023 //% return YES; |
1012 //% } | 1024 //% } |
1013 //% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) { | 1025 //% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) { |
1014 //% return NO; | 1026 //% return NO; |
1015 //% } | 1027 //% } |
1016 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, other->)) |
| | 1028 //% GPBBool##VALUE_NAME##Dictionary *otherDictionary = other; |
1017 //% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, other->)))
{ | 1029 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, otherDictio
nary->)) || |
| 1030 //% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, otherDictio
nary->))) { |
1018 //% return NO; | 1031 //% return NO; |
1019 //% } | 1032 //% } |
1020 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], other->_valu
es[0]))) || | 1033 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], otherDiction
ary->_values[0]))) || |
1021 //% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], other->_valu
es[1])))) { | 1034 //% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], otherDiction
ary->_values[1])))) { |
1022 //% return NO; | 1035 //% return NO; |
1023 //% } | 1036 //% } |
1024 //% return YES; | 1037 //% return YES; |
1025 //%} | 1038 //%} |
1026 //% | 1039 //% |
1027 //%- (NSUInteger)hash { | 1040 //%- (NSUInteger)hash { |
1028 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1,
) ? 1 : 0); | 1041 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1,
) ? 1 : 0); |
1029 //%} | 1042 //%} |
1030 //% | 1043 //% |
1031 //%- (NSString *)description { | 1044 //%- (NSString *)description { |
1032 //% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [
self class], self]; | 1045 //% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [
self class], self]; |
1033 //% if (BOOL_DICT_W_HAS##HELPER(0, )) { | 1046 //% if (BOOL_DICT_W_HAS##HELPER(0, )) { |
1034 //% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]]; | 1047 //% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]]; |
1035 //% } | 1048 //% } |
1036 //% if (BOOL_DICT_W_HAS##HELPER(1, )) { | 1049 //% if (BOOL_DICT_W_HAS##HELPER(1, )) { |
1037 //% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]]
; | 1050 //% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]]
; |
1038 //% } | 1051 //% } |
1039 //% [result appendString:@" }"]; | 1052 //% [result appendString:@" }"]; |
1040 //% return result; | 1053 //% return result; |
1041 //%} | 1054 //%} |
1042 //% | 1055 //% |
1043 //%- (NSUInteger)count { | 1056 //%- (NSUInteger)count { |
1044 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1,
) ? 1 : 0); | 1057 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1,
) ? 1 : 0); |
1045 //%} | 1058 //%} |
1046 //% | 1059 //% |
1047 //%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_TYPE) | 1060 //%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE) |
1048 //% | 1061 //% |
1049 //%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP) | 1062 //%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP) |
1050 //% | 1063 //% |
1051 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 1064 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
1052 //% if (BOOL_DICT_HAS##HELPER(0, )) { | 1065 //% if (BOOL_DICT_HAS##HELPER(0, )) { |
1053 //% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0])); | 1066 //% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0])); |
1054 //% } | 1067 //% } |
1055 //% if (BOOL_DICT_W_HAS##HELPER(1, )) { | 1068 //% if (BOOL_DICT_W_HAS##HELPER(1, )) { |
1056 //% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1])); | 1069 //% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1])); |
1057 //% } | 1070 //% } |
1058 //%} | 1071 //%} |
1059 //% | 1072 //% |
1060 //%- (void)enumerateKeysAnd##VNAME$u##sUsingBlock: | 1073 //%- (void)enumerateKeysAnd##VNAME##sUsingBlock: |
1061 //% (void (^)(BOOL key, VALUE_TYPE VNAME, BOOL *stop))block { | 1074 //% (void (^)(BOOL key, VALUE_TYPE VNAME_VAR, BOOL *stop))block { |
1062 //% BOOL stop = NO; | 1075 //% BOOL stop = NO; |
1063 //% if (BOOL_DICT_HAS##HELPER(0, )) { | 1076 //% if (BOOL_DICT_HAS##HELPER(0, )) { |
1064 //% block(NO, _values[0], &stop); | 1077 //% block(NO, _values[0], &stop); |
1065 //% } | 1078 //% } |
1066 //% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) { | 1079 //% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) { |
1067 //% block(YES, _values[1], &stop); | 1080 //% block(YES, _values[1], &stop); |
1068 //% } | 1081 //% } |
1069 //%} | 1082 //%} |
1070 //% | 1083 //% |
1071 //%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeA
sField:(GPBFieldDescriptor *)field { | 1084 //%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... |
1108 //% | 1121 //% |
1109 //%@end | 1122 //%@end |
1110 //% | 1123 //% |
1111 | 1124 |
1112 | 1125 |
1113 // | 1126 // |
1114 // Helpers for PODs | 1127 // Helpers for PODs |
1115 // | 1128 // |
1116 | 1129 |
1117 //%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER) | 1130 //%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER) |
1118 //%- (BOOL)valueForKey:(KEY_TYPE)key value:(VALUE_TYPE *)value { | 1131 //%- (BOOL)get##VALUE_NAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key { |
1119 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; | 1132 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; |
1120 //% if (wrapped && value) { | 1133 //% if (wrapped && value) { |
1121 //% *value = UNWRAP##VALUE_NAME(wrapped); | 1134 //% *value = UNWRAP##VALUE_NAME(wrapped); |
1122 //% } | 1135 //% } |
1123 //% return (wrapped != NULL); | 1136 //% return (wrapped != NULL); |
1124 //%} | 1137 //%} |
1125 //%PDDM-DEFINE WRAPPEDPOD(VALUE) | 1138 //%PDDM-DEFINE WRAPPEDPOD(VALUE) |
1126 //%@(VALUE) | 1139 //%@(VALUE) |
1127 //%PDDM-DEFINE UNWRAPUInt32(VALUE) | 1140 //%PDDM-DEFINE UNWRAPUInt32(VALUE) |
1128 //%[VALUE unsignedIntValue] | 1141 //%[VALUE unsignedIntValue] |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 //%value##VALUE_NAME | 1211 //%value##VALUE_NAME |
1199 //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT) | 1212 //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT) |
1200 // Empty | 1213 // Empty |
1201 //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT) | 1214 //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT) |
1202 // Empty | 1215 // Empty |
1203 | 1216 |
1204 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD() | 1217 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD() |
1205 //% BOOL _valueSet[2]; | 1218 //% BOOL _valueSet[2]; |
1206 //% | 1219 //% |
1207 //%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE) | 1220 //%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE) |
1208 //%- (instancetype)initWithValues:(const VALUE_TYPE [])values | 1221 //%- (instancetype)initWith##VALUE_NAME##s:(const VALUE_TYPE [])values |
1209 //% forKeys:(const BOOL [])keys | 1222 //% ##VALUE_NAME$S## forKeys:(const BOOL [])keys |
1210 //% count:(NSUInteger)count { | 1223 //% ##VALUE_NAME$S## count:(NSUInteger)count { |
1211 //% self = [super init]; | 1224 //% self = [super init]; |
1212 //% if (self) { | 1225 //% if (self) { |
1213 //% for (NSUInteger i = 0; i < count; ++i) { | 1226 //% for (NSUInteger i = 0; i < count; ++i) { |
1214 //% int idx = keys[i] ? 1 : 0; | 1227 //% int idx = keys[i] ? 1 : 0; |
1215 //% _values[idx] = values[i]; | 1228 //% _values[idx] = values[i]; |
1216 //% _valueSet[idx] = YES; | 1229 //% _valueSet[idx] = YES; |
1217 //% } | 1230 //% } |
1218 //% } | 1231 //% } |
1219 //% return self; | 1232 //% return self; |
1220 //%} | 1233 //%} |
1221 //% | 1234 //% |
1222 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)diction
ary { | 1235 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)diction
ary { |
1223 //% self = [self initWithValues:NULL forKeys:NULL count:0]; | 1236 //% self = [self initWith##VALUE_NAME##s:NULL forKeys:NULL count:0]; |
1224 //% if (self) { | 1237 //% if (self) { |
1225 //% if (dictionary) { | 1238 //% if (dictionary) { |
1226 //% for (int i = 0; i < 2; ++i) { | 1239 //% for (int i = 0; i < 2; ++i) { |
1227 //% if (dictionary->_valueSet[i]) { | 1240 //% if (dictionary->_valueSet[i]) { |
1228 //% _values[i] = dictionary->_values[i]; | 1241 //% _values[i] = dictionary->_values[i]; |
1229 //% _valueSet[i] = YES; | 1242 //% _valueSet[i] = YES; |
1230 //% } | 1243 //% } |
1231 //% } | 1244 //% } |
1232 //% } | 1245 //% } |
1233 //% } | 1246 //% } |
1234 //% return self; | 1247 //% return self; |
1235 //%} | 1248 //%} |
1236 //%PDDM-DEFINE BOOL_DICT_DEALLOCPOD() | 1249 //%PDDM-DEFINE BOOL_DICT_DEALLOCPOD() |
1237 //%#if !defined(NS_BLOCK_ASSERTIONS) | 1250 //%#if !defined(NS_BLOCK_ASSERTIONS) |
1238 //%- (void)dealloc { | 1251 //%- (void)dealloc { |
1239 //% NSAssert(!_autocreator, | 1252 //% NSAssert(!_autocreator, |
1240 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, | 1253 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, |
1241 //% [self class], _autocreator); | 1254 //% [self class], _autocreator); |
1242 //% [super dealloc]; | 1255 //% [super dealloc]; |
1243 //%} | 1256 //%} |
1244 //%#endif // !defined(NS_BLOCK_ASSERTIONS) | 1257 //%#endif // !defined(NS_BLOCK_ASSERTIONS) |
1245 //%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF) | 1258 //%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF) |
1246 //%BOOL_DICT_HASPOD(IDX, REF) | 1259 //%BOOL_DICT_HASPOD(IDX, REF) |
1247 //%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF) | 1260 //%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF) |
1248 //%REF##_valueSet[IDX] | 1261 //%REF##_valueSet[IDX] |
1249 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_TYPE) | 1262 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE) |
1250 //%- (BOOL)valueForKey:(BOOL)key value:(VALUE_TYPE *)value { | 1263 //%- (BOOL)get##VALUE_NAME##:(VALUE_TYPE *)value forKey:(BOOL)key { |
1251 //% int idx = (key ? 1 : 0); | 1264 //% int idx = (key ? 1 : 0); |
1252 //% if (_valueSet[idx]) { | 1265 //% if (_valueSet[idx]) { |
1253 //% if (value) { | 1266 //% if (value) { |
1254 //% *value = _values[idx]; | 1267 //% *value = _values[idx]; |
1255 //% } | 1268 //% } |
1256 //% return YES; | 1269 //% return YES; |
1257 //% } | 1270 //% } |
1258 //% return NO; | 1271 //% return NO; |
1259 //%} | 1272 //%} |
1260 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP) | 1273 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP) |
(...skipping 11 matching lines...) Expand all Loading... |
1272 //% _valueSet[i] = YES; | 1285 //% _valueSet[i] = YES; |
1273 //% _values[i] = otherDictionary->_values[i]; | 1286 //% _values[i] = otherDictionary->_values[i]; |
1274 //% } | 1287 //% } |
1275 //% } | 1288 //% } |
1276 //% if (_autocreator) { | 1289 //% if (_autocreator) { |
1277 //% GPBAutocreatedDictionaryModified(_autocreator, self); | 1290 //% GPBAutocreatedDictionaryModified(_autocreator, self); |
1278 //% } | 1291 //% } |
1279 //% } | 1292 //% } |
1280 //%} | 1293 //%} |
1281 //% | 1294 //% |
1282 //%- (void)setValue:(VALUE_TYPE)value forKey:(BOOL)key { | 1295 //%- (void)set##VALUE_NAME:(VALUE_TYPE)value forKey:(BOOL)key { |
1283 //% int idx = (key ? 1 : 0); | 1296 //% int idx = (key ? 1 : 0); |
1284 //% _values[idx] = value; | 1297 //% _values[idx] = value; |
1285 //% _valueSet[idx] = YES; | 1298 //% _valueSet[idx] = YES; |
1286 //% if (_autocreator) { | 1299 //% if (_autocreator) { |
1287 //% GPBAutocreatedDictionaryModified(_autocreator, self); | 1300 //% GPBAutocreatedDictionaryModified(_autocreator, self); |
1288 //% } | 1301 //% } |
1289 //%} | 1302 //%} |
1290 //% | 1303 //% |
1291 //%- (void)removeValueForKey:(BOOL)aKey { | 1304 //%- (void)remove##VALUE_NAME##ForKey:(BOOL)aKey { |
1292 //% _valueSet[aKey ? 1 : 0] = NO; | 1305 //% _valueSet[aKey ? 1 : 0] = NO; |
1293 //%} | 1306 //%} |
1294 //% | 1307 //% |
1295 //%- (void)removeAll { | 1308 //%- (void)removeAll { |
1296 //% _valueSet[0] = NO; | 1309 //% _valueSet[0] = NO; |
1297 //% _valueSet[1] = NO; | 1310 //% _valueSet[1] = NO; |
1298 //%} | 1311 //%} |
1299 //%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME) | 1312 //%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME) |
1300 //%STR_FORMAT_##VALUE_NAME() | 1313 //%STR_FORMAT_##VALUE_NAME() |
1301 //%PDDM-DEFINE STR_FORMAT_UInt32() | 1314 //%PDDM-DEFINE STR_FORMAT_UInt32() |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, | 1455 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, |
1443 //% [self class], _autocreator); | 1456 //% [self class], _autocreator); |
1444 //% [_values[0] release]; | 1457 //% [_values[0] release]; |
1445 //% [_values[1] release]; | 1458 //% [_values[1] release]; |
1446 //% [super dealloc]; | 1459 //% [super dealloc]; |
1447 //%} | 1460 //%} |
1448 //%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF) | 1461 //%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF) |
1449 //%(BOOL_DICT_HASOBJECT(IDX, REF)) | 1462 //%(BOOL_DICT_HASOBJECT(IDX, REF)) |
1450 //%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF) | 1463 //%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF) |
1451 //%REF##_values[IDX] != nil | 1464 //%REF##_values[IDX] != nil |
1452 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_TYPE) | 1465 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE) |
1453 //%- (VALUE_TYPE)objectForKey:(BOOL)key { | 1466 //%- (VALUE_TYPE)objectForKey:(BOOL)key { |
1454 //% return _values[key ? 1 : 0]; | 1467 //% return _values[key ? 1 : 0]; |
1455 //%} | 1468 //%} |
1456 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP) | 1469 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP) |
1457 //%- (void)setGPBGenericValue:(GPBGenericValue *)value | 1470 //%- (void)setGPBGenericValue:(GPBGenericValue *)value |
1458 //% forGPBGenericValueKey:(GPBGenericValue *)key { | 1471 //% forGPBGenericValueKey:(GPBGenericValue *)key { |
1459 //% int idx = (key->valueBool ? 1 : 0); | 1472 //% int idx = (key->valueBool ? 1 : 0); |
1460 //% [_values[idx] release]; | 1473 //% [_values[idx] release]; |
1461 //% _values[idx] = [value->valueString retain]; | 1474 //% _values[idx] = [value->valueString retain]; |
1462 //%} | 1475 //%} |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 // This block of code is generated, do not edit it directly. | 1522 // This block of code is generated, do not edit it directly. |
1510 | 1523 |
1511 #pragma mark - UInt32 -> UInt32 | 1524 #pragma mark - UInt32 -> UInt32 |
1512 | 1525 |
1513 @implementation GPBUInt32UInt32Dictionary { | 1526 @implementation GPBUInt32UInt32Dictionary { |
1514 @package | 1527 @package |
1515 NSMutableDictionary *_dictionary; | 1528 NSMutableDictionary *_dictionary; |
1516 } | 1529 } |
1517 | 1530 |
1518 + (instancetype)dictionary { | 1531 + (instancetype)dictionary { |
1519 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 1532 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; |
1520 } | 1533 } |
1521 | 1534 |
1522 + (instancetype)dictionaryWithValue:(uint32_t)value | 1535 + (instancetype)dictionaryWithUInt32:(uint32_t)value |
1523 forKey:(uint32_t)key { | 1536 forKey:(uint32_t)key { |
1524 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 1537 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
1525 // on to get the type correct. | 1538 // on to get the type correct. |
1526 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithValues:&value | 1539 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithUInt32s:&value |
1527 forKeys:&key | 1540 forKeys:&key |
1528 count:1] autoreleas
e]; | 1541 count:1] autorelea
se]; |
1529 } | 1542 } |
1530 | 1543 |
1531 + (instancetype)dictionaryWithValues:(const uint32_t [])values | 1544 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values |
1532 forKeys:(const uint32_t [])keys | 1545 forKeys:(const uint32_t [])keys |
1533 count:(NSUInteger)count { | 1546 count:(NSUInteger)count { |
1534 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 1547 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
1535 // on to get the type correct. | 1548 // on to get the type correct. |
1536 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithValues:values | 1549 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithUInt32s:values |
1537 forKeys:keys | 1550 forKeys:keys |
1538 count:count] autore
lease]; | 1551 count:count] autore
lease]; |
1539 } | 1552 } |
1540 | 1553 |
1541 + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary
{ | 1554 + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary
{ |
1542 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 1555 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
1543 // on to get the type correct. | 1556 // on to get the type correct. |
1544 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 1557 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
1545 } | 1558 } |
1546 | 1559 |
1547 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 1560 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
1548 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 1561 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
1549 } | 1562 } |
1550 | 1563 |
1551 - (instancetype)init { | 1564 - (instancetype)init { |
1552 return [self initWithValues:NULL forKeys:NULL count:0]; | 1565 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
1553 } | 1566 } |
1554 | 1567 |
1555 - (instancetype)initWithValues:(const uint32_t [])values | 1568 - (instancetype)initWithUInt32s:(const uint32_t [])values |
1556 forKeys:(const uint32_t [])keys | 1569 forKeys:(const uint32_t [])keys |
1557 count:(NSUInteger)count { | 1570 count:(NSUInteger)count { |
1558 self = [super init]; | 1571 self = [super init]; |
1559 if (self) { | 1572 if (self) { |
1560 _dictionary = [[NSMutableDictionary alloc] init]; | 1573 _dictionary = [[NSMutableDictionary alloc] init]; |
1561 if (count && values && keys) { | 1574 if (count && values && keys) { |
1562 for (NSUInteger i = 0; i < count; ++i) { | 1575 for (NSUInteger i = 0; i < count; ++i) { |
1563 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 1576 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
1564 } | 1577 } |
1565 } | 1578 } |
1566 } | 1579 } |
1567 return self; | 1580 return self; |
1568 } | 1581 } |
1569 | 1582 |
1570 - (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary { | 1583 - (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary { |
1571 self = [self initWithValues:NULL forKeys:NULL count:0]; | 1584 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; |
1572 if (self) { | 1585 if (self) { |
1573 if (dictionary) { | 1586 if (dictionary) { |
1574 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 1587 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
1575 } | 1588 } |
1576 } | 1589 } |
1577 return self; | 1590 return self; |
1578 } | 1591 } |
1579 | 1592 |
1580 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 1593 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
1581 #pragma unused(numItems) | 1594 #pragma unused(numItems) |
1582 return [self initWithValues:NULL forKeys:NULL count:0]; | 1595 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
1583 } | 1596 } |
1584 | 1597 |
1585 - (void)dealloc { | 1598 - (void)dealloc { |
1586 NSAssert(!_autocreator, | 1599 NSAssert(!_autocreator, |
1587 @"%@: Autocreator must be cleared before release, autocreator: %@", | 1600 @"%@: Autocreator must be cleared before release, autocreator: %@", |
1588 [self class], _autocreator); | 1601 [self class], _autocreator); |
1589 [_dictionary release]; | 1602 [_dictionary release]; |
1590 [super dealloc]; | 1603 [super dealloc]; |
1591 } | 1604 } |
1592 | 1605 |
1593 - (instancetype)copyWithZone:(NSZone *)zone { | 1606 - (instancetype)copyWithZone:(NSZone *)zone { |
1594 return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; | 1607 return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; |
1595 } | 1608 } |
1596 | 1609 |
1597 - (BOOL)isEqual:(GPBUInt32UInt32Dictionary *)other { | 1610 - (BOOL)isEqual:(id)other { |
1598 if (self == other) { | 1611 if (self == other) { |
1599 return YES; | 1612 return YES; |
1600 } | 1613 } |
1601 if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) { | 1614 if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) { |
1602 return NO; | 1615 return NO; |
1603 } | 1616 } |
1604 return [_dictionary isEqual:other->_dictionary]; | 1617 GPBUInt32UInt32Dictionary *otherDictionary = other; |
| 1618 return [_dictionary isEqual:otherDictionary->_dictionary]; |
1605 } | 1619 } |
1606 | 1620 |
1607 - (NSUInteger)hash { | 1621 - (NSUInteger)hash { |
1608 return _dictionary.count; | 1622 return _dictionary.count; |
1609 } | 1623 } |
1610 | 1624 |
1611 - (NSString *)description { | 1625 - (NSString *)description { |
1612 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 1626 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
1613 } | 1627 } |
1614 | 1628 |
1615 - (NSUInteger)count { | 1629 - (NSUInteger)count { |
1616 return _dictionary.count; | 1630 return _dictionary.count; |
1617 } | 1631 } |
1618 | 1632 |
1619 - (void)enumerateKeysAndValuesUsingBlock: | 1633 - (void)enumerateKeysAndUInt32sUsingBlock: |
1620 (void (^)(uint32_t key, uint32_t value, BOOL *stop))block { | 1634 (void (^)(uint32_t key, uint32_t value, BOOL *stop))block { |
1621 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 1635 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
1622 NSNumber *aValue, | 1636 NSNumber *aValue, |
1623 BOOL *stop) { | 1637 BOOL *stop) { |
1624 block([aKey unsignedIntValue], [aValue unsignedIntValue], stop); | 1638 block([aKey unsignedIntValue], [aValue unsignedIntValue], stop); |
1625 }]; | 1639 }]; |
1626 } | 1640 } |
1627 | 1641 |
1628 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 1642 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
1629 NSUInteger count = _dictionary.count; | 1643 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1667 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | 1681 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); |
1668 }]; | 1682 }]; |
1669 } | 1683 } |
1670 | 1684 |
1671 - (void)setGPBGenericValue:(GPBGenericValue *)value | 1685 - (void)setGPBGenericValue:(GPBGenericValue *)value |
1672 forGPBGenericValueKey:(GPBGenericValue *)key { | 1686 forGPBGenericValueKey:(GPBGenericValue *)key { |
1673 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)]; | 1687 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)]; |
1674 } | 1688 } |
1675 | 1689 |
1676 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 1690 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
1677 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, uint32_t value, BOOL *s
top) { | 1691 [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, BOOL *
stop) { |
1678 #pragma unused(stop) | 1692 #pragma unused(stop) |
1679 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%u", value]); | 1693 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%u", value]); |
1680 }]; | 1694 }]; |
1681 } | 1695 } |
1682 | 1696 |
1683 - (BOOL)valueForKey:(uint32_t)key value:(uint32_t *)value { | 1697 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key { |
1684 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 1698 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
1685 if (wrapped && value) { | 1699 if (wrapped && value) { |
1686 *value = [wrapped unsignedIntValue]; | 1700 *value = [wrapped unsignedIntValue]; |
1687 } | 1701 } |
1688 return (wrapped != NULL); | 1702 return (wrapped != NULL); |
1689 } | 1703 } |
1690 | 1704 |
1691 - (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary { | 1705 - (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary { |
1692 if (otherDictionary) { | 1706 if (otherDictionary) { |
1693 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 1707 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
1694 if (_autocreator) { | 1708 if (_autocreator) { |
1695 GPBAutocreatedDictionaryModified(_autocreator, self); | 1709 GPBAutocreatedDictionaryModified(_autocreator, self); |
1696 } | 1710 } |
1697 } | 1711 } |
1698 } | 1712 } |
1699 | 1713 |
1700 - (void)setValue:(uint32_t)value forKey:(uint32_t)key { | 1714 - (void)setUInt32:(uint32_t)value forKey:(uint32_t)key { |
1701 [_dictionary setObject:@(value) forKey:@(key)]; | 1715 [_dictionary setObject:@(value) forKey:@(key)]; |
1702 if (_autocreator) { | 1716 if (_autocreator) { |
1703 GPBAutocreatedDictionaryModified(_autocreator, self); | 1717 GPBAutocreatedDictionaryModified(_autocreator, self); |
1704 } | 1718 } |
1705 } | 1719 } |
1706 | 1720 |
1707 - (void)removeValueForKey:(uint32_t)aKey { | 1721 - (void)removeUInt32ForKey:(uint32_t)aKey { |
1708 [_dictionary removeObjectForKey:@(aKey)]; | 1722 [_dictionary removeObjectForKey:@(aKey)]; |
1709 } | 1723 } |
1710 | 1724 |
1711 - (void)removeAll { | 1725 - (void)removeAll { |
1712 [_dictionary removeAllObjects]; | 1726 [_dictionary removeAllObjects]; |
1713 } | 1727 } |
1714 | 1728 |
1715 @end | 1729 @end |
1716 | 1730 |
1717 #pragma mark - UInt32 -> Int32 | 1731 #pragma mark - UInt32 -> Int32 |
1718 | 1732 |
1719 @implementation GPBUInt32Int32Dictionary { | 1733 @implementation GPBUInt32Int32Dictionary { |
1720 @package | 1734 @package |
1721 NSMutableDictionary *_dictionary; | 1735 NSMutableDictionary *_dictionary; |
1722 } | 1736 } |
1723 | 1737 |
1724 + (instancetype)dictionary { | 1738 + (instancetype)dictionary { |
1725 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 1739 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; |
1726 } | 1740 } |
1727 | 1741 |
1728 + (instancetype)dictionaryWithValue:(int32_t)value | 1742 + (instancetype)dictionaryWithInt32:(int32_t)value |
1729 forKey:(uint32_t)key { | 1743 forKey:(uint32_t)key { |
1730 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 1744 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
1731 // on to get the type correct. | 1745 // on to get the type correct. |
1732 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithValues:&value | 1746 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithInt32s:&value |
1733 forKeys:&key | 1747 forKeys:&key |
1734 count:1] autorelease
]; | 1748 count:1] autorelease
]; |
1735 } | 1749 } |
1736 | 1750 |
1737 + (instancetype)dictionaryWithValues:(const int32_t [])values | 1751 + (instancetype)dictionaryWithInt32s:(const int32_t [])values |
1738 forKeys:(const uint32_t [])keys | 1752 forKeys:(const uint32_t [])keys |
1739 count:(NSUInteger)count { | 1753 count:(NSUInteger)count { |
1740 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 1754 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
1741 // on to get the type correct. | 1755 // on to get the type correct. |
1742 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithValues:values | 1756 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithInt32s:values |
1743 forKeys:keys | 1757 forKeys:keys |
1744 count:count] autorel
ease]; | 1758 count:count] autorel
ease]; |
1745 } | 1759 } |
1746 | 1760 |
1747 + (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary
{ | 1761 + (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary
{ |
1748 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 1762 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
1749 // on to get the type correct. | 1763 // on to get the type correct. |
1750 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 1764 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
1751 } | 1765 } |
1752 | 1766 |
1753 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 1767 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
1754 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 1768 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
1755 } | 1769 } |
1756 | 1770 |
1757 - (instancetype)init { | 1771 - (instancetype)init { |
1758 return [self initWithValues:NULL forKeys:NULL count:0]; | 1772 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
1759 } | 1773 } |
1760 | 1774 |
1761 - (instancetype)initWithValues:(const int32_t [])values | 1775 - (instancetype)initWithInt32s:(const int32_t [])values |
1762 forKeys:(const uint32_t [])keys | 1776 forKeys:(const uint32_t [])keys |
1763 count:(NSUInteger)count { | 1777 count:(NSUInteger)count { |
1764 self = [super init]; | 1778 self = [super init]; |
1765 if (self) { | 1779 if (self) { |
1766 _dictionary = [[NSMutableDictionary alloc] init]; | 1780 _dictionary = [[NSMutableDictionary alloc] init]; |
1767 if (count && values && keys) { | 1781 if (count && values && keys) { |
1768 for (NSUInteger i = 0; i < count; ++i) { | 1782 for (NSUInteger i = 0; i < count; ++i) { |
1769 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 1783 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
1770 } | 1784 } |
1771 } | 1785 } |
1772 } | 1786 } |
1773 return self; | 1787 return self; |
1774 } | 1788 } |
1775 | 1789 |
1776 - (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary { | 1790 - (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary { |
1777 self = [self initWithValues:NULL forKeys:NULL count:0]; | 1791 self = [self initWithInt32s:NULL forKeys:NULL count:0]; |
1778 if (self) { | 1792 if (self) { |
1779 if (dictionary) { | 1793 if (dictionary) { |
1780 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 1794 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
1781 } | 1795 } |
1782 } | 1796 } |
1783 return self; | 1797 return self; |
1784 } | 1798 } |
1785 | 1799 |
1786 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 1800 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
1787 #pragma unused(numItems) | 1801 #pragma unused(numItems) |
1788 return [self initWithValues:NULL forKeys:NULL count:0]; | 1802 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
1789 } | 1803 } |
1790 | 1804 |
1791 - (void)dealloc { | 1805 - (void)dealloc { |
1792 NSAssert(!_autocreator, | 1806 NSAssert(!_autocreator, |
1793 @"%@: Autocreator must be cleared before release, autocreator: %@", | 1807 @"%@: Autocreator must be cleared before release, autocreator: %@", |
1794 [self class], _autocreator); | 1808 [self class], _autocreator); |
1795 [_dictionary release]; | 1809 [_dictionary release]; |
1796 [super dealloc]; | 1810 [super dealloc]; |
1797 } | 1811 } |
1798 | 1812 |
1799 - (instancetype)copyWithZone:(NSZone *)zone { | 1813 - (instancetype)copyWithZone:(NSZone *)zone { |
1800 return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]
; | 1814 return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]
; |
1801 } | 1815 } |
1802 | 1816 |
1803 - (BOOL)isEqual:(GPBUInt32Int32Dictionary *)other { | 1817 - (BOOL)isEqual:(id)other { |
1804 if (self == other) { | 1818 if (self == other) { |
1805 return YES; | 1819 return YES; |
1806 } | 1820 } |
1807 if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) { | 1821 if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) { |
1808 return NO; | 1822 return NO; |
1809 } | 1823 } |
1810 return [_dictionary isEqual:other->_dictionary]; | 1824 GPBUInt32Int32Dictionary *otherDictionary = other; |
| 1825 return [_dictionary isEqual:otherDictionary->_dictionary]; |
1811 } | 1826 } |
1812 | 1827 |
1813 - (NSUInteger)hash { | 1828 - (NSUInteger)hash { |
1814 return _dictionary.count; | 1829 return _dictionary.count; |
1815 } | 1830 } |
1816 | 1831 |
1817 - (NSString *)description { | 1832 - (NSString *)description { |
1818 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 1833 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
1819 } | 1834 } |
1820 | 1835 |
1821 - (NSUInteger)count { | 1836 - (NSUInteger)count { |
1822 return _dictionary.count; | 1837 return _dictionary.count; |
1823 } | 1838 } |
1824 | 1839 |
1825 - (void)enumerateKeysAndValuesUsingBlock: | 1840 - (void)enumerateKeysAndInt32sUsingBlock: |
1826 (void (^)(uint32_t key, int32_t value, BOOL *stop))block { | 1841 (void (^)(uint32_t key, int32_t value, BOOL *stop))block { |
1827 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 1842 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
1828 NSNumber *aValue, | 1843 NSNumber *aValue, |
1829 BOOL *stop) { | 1844 BOOL *stop) { |
1830 block([aKey unsignedIntValue], [aValue intValue], stop); | 1845 block([aKey unsignedIntValue], [aValue intValue], stop); |
1831 }]; | 1846 }]; |
1832 } | 1847 } |
1833 | 1848 |
1834 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 1849 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
1835 NSUInteger count = _dictionary.count; | 1850 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1873 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | 1888 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); |
1874 }]; | 1889 }]; |
1875 } | 1890 } |
1876 | 1891 |
1877 - (void)setGPBGenericValue:(GPBGenericValue *)value | 1892 - (void)setGPBGenericValue:(GPBGenericValue *)value |
1878 forGPBGenericValueKey:(GPBGenericValue *)key { | 1893 forGPBGenericValueKey:(GPBGenericValue *)key { |
1879 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)]; | 1894 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)]; |
1880 } | 1895 } |
1881 | 1896 |
1882 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 1897 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
1883 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, int32_t value, BOOL *st
op) { | 1898 [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, BOOL *st
op) { |
1884 #pragma unused(stop) | 1899 #pragma unused(stop) |
1885 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%d", value]); | 1900 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%d", value]); |
1886 }]; | 1901 }]; |
1887 } | 1902 } |
1888 | 1903 |
1889 - (BOOL)valueForKey:(uint32_t)key value:(int32_t *)value { | 1904 - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key { |
1890 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 1905 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
1891 if (wrapped && value) { | 1906 if (wrapped && value) { |
1892 *value = [wrapped intValue]; | 1907 *value = [wrapped intValue]; |
1893 } | 1908 } |
1894 return (wrapped != NULL); | 1909 return (wrapped != NULL); |
1895 } | 1910 } |
1896 | 1911 |
1897 - (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary { | 1912 - (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary { |
1898 if (otherDictionary) { | 1913 if (otherDictionary) { |
1899 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 1914 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
1900 if (_autocreator) { | 1915 if (_autocreator) { |
1901 GPBAutocreatedDictionaryModified(_autocreator, self); | 1916 GPBAutocreatedDictionaryModified(_autocreator, self); |
1902 } | 1917 } |
1903 } | 1918 } |
1904 } | 1919 } |
1905 | 1920 |
1906 - (void)setValue:(int32_t)value forKey:(uint32_t)key { | 1921 - (void)setInt32:(int32_t)value forKey:(uint32_t)key { |
1907 [_dictionary setObject:@(value) forKey:@(key)]; | 1922 [_dictionary setObject:@(value) forKey:@(key)]; |
1908 if (_autocreator) { | 1923 if (_autocreator) { |
1909 GPBAutocreatedDictionaryModified(_autocreator, self); | 1924 GPBAutocreatedDictionaryModified(_autocreator, self); |
1910 } | 1925 } |
1911 } | 1926 } |
1912 | 1927 |
1913 - (void)removeValueForKey:(uint32_t)aKey { | 1928 - (void)removeInt32ForKey:(uint32_t)aKey { |
1914 [_dictionary removeObjectForKey:@(aKey)]; | 1929 [_dictionary removeObjectForKey:@(aKey)]; |
1915 } | 1930 } |
1916 | 1931 |
1917 - (void)removeAll { | 1932 - (void)removeAll { |
1918 [_dictionary removeAllObjects]; | 1933 [_dictionary removeAllObjects]; |
1919 } | 1934 } |
1920 | 1935 |
1921 @end | 1936 @end |
1922 | 1937 |
1923 #pragma mark - UInt32 -> UInt64 | 1938 #pragma mark - UInt32 -> UInt64 |
1924 | 1939 |
1925 @implementation GPBUInt32UInt64Dictionary { | 1940 @implementation GPBUInt32UInt64Dictionary { |
1926 @package | 1941 @package |
1927 NSMutableDictionary *_dictionary; | 1942 NSMutableDictionary *_dictionary; |
1928 } | 1943 } |
1929 | 1944 |
1930 + (instancetype)dictionary { | 1945 + (instancetype)dictionary { |
1931 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 1946 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; |
1932 } | 1947 } |
1933 | 1948 |
1934 + (instancetype)dictionaryWithValue:(uint64_t)value | 1949 + (instancetype)dictionaryWithUInt64:(uint64_t)value |
1935 forKey:(uint32_t)key { | 1950 forKey:(uint32_t)key { |
1936 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 1951 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
1937 // on to get the type correct. | 1952 // on to get the type correct. |
1938 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithValues:&value | 1953 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithUInt64s:&value |
1939 forKeys:&key | 1954 forKeys:&key |
1940 count:1] autoreleas
e]; | 1955 count:1] autorelea
se]; |
1941 } | 1956 } |
1942 | 1957 |
1943 + (instancetype)dictionaryWithValues:(const uint64_t [])values | 1958 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values |
1944 forKeys:(const uint32_t [])keys | 1959 forKeys:(const uint32_t [])keys |
1945 count:(NSUInteger)count { | 1960 count:(NSUInteger)count { |
1946 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 1961 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
1947 // on to get the type correct. | 1962 // on to get the type correct. |
1948 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithValues:values | 1963 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithUInt64s:values |
1949 forKeys:keys | 1964 forKeys:keys |
1950 count:count] autore
lease]; | 1965 count:count] autore
lease]; |
1951 } | 1966 } |
1952 | 1967 |
1953 + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary
{ | 1968 + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary
{ |
1954 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 1969 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
1955 // on to get the type correct. | 1970 // on to get the type correct. |
1956 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 1971 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
1957 } | 1972 } |
1958 | 1973 |
1959 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 1974 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
1960 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 1975 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
1961 } | 1976 } |
1962 | 1977 |
1963 - (instancetype)init { | 1978 - (instancetype)init { |
1964 return [self initWithValues:NULL forKeys:NULL count:0]; | 1979 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
1965 } | 1980 } |
1966 | 1981 |
1967 - (instancetype)initWithValues:(const uint64_t [])values | 1982 - (instancetype)initWithUInt64s:(const uint64_t [])values |
1968 forKeys:(const uint32_t [])keys | 1983 forKeys:(const uint32_t [])keys |
1969 count:(NSUInteger)count { | 1984 count:(NSUInteger)count { |
1970 self = [super init]; | 1985 self = [super init]; |
1971 if (self) { | 1986 if (self) { |
1972 _dictionary = [[NSMutableDictionary alloc] init]; | 1987 _dictionary = [[NSMutableDictionary alloc] init]; |
1973 if (count && values && keys) { | 1988 if (count && values && keys) { |
1974 for (NSUInteger i = 0; i < count; ++i) { | 1989 for (NSUInteger i = 0; i < count; ++i) { |
1975 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 1990 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
1976 } | 1991 } |
1977 } | 1992 } |
1978 } | 1993 } |
1979 return self; | 1994 return self; |
1980 } | 1995 } |
1981 | 1996 |
1982 - (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary { | 1997 - (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary { |
1983 self = [self initWithValues:NULL forKeys:NULL count:0]; | 1998 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; |
1984 if (self) { | 1999 if (self) { |
1985 if (dictionary) { | 2000 if (dictionary) { |
1986 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 2001 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
1987 } | 2002 } |
1988 } | 2003 } |
1989 return self; | 2004 return self; |
1990 } | 2005 } |
1991 | 2006 |
1992 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 2007 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
1993 #pragma unused(numItems) | 2008 #pragma unused(numItems) |
1994 return [self initWithValues:NULL forKeys:NULL count:0]; | 2009 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
1995 } | 2010 } |
1996 | 2011 |
1997 - (void)dealloc { | 2012 - (void)dealloc { |
1998 NSAssert(!_autocreator, | 2013 NSAssert(!_autocreator, |
1999 @"%@: Autocreator must be cleared before release, autocreator: %@", | 2014 @"%@: Autocreator must be cleared before release, autocreator: %@", |
2000 [self class], _autocreator); | 2015 [self class], _autocreator); |
2001 [_dictionary release]; | 2016 [_dictionary release]; |
2002 [super dealloc]; | 2017 [super dealloc]; |
2003 } | 2018 } |
2004 | 2019 |
2005 - (instancetype)copyWithZone:(NSZone *)zone { | 2020 - (instancetype)copyWithZone:(NSZone *)zone { |
2006 return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; | 2021 return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; |
2007 } | 2022 } |
2008 | 2023 |
2009 - (BOOL)isEqual:(GPBUInt32UInt64Dictionary *)other { | 2024 - (BOOL)isEqual:(id)other { |
2010 if (self == other) { | 2025 if (self == other) { |
2011 return YES; | 2026 return YES; |
2012 } | 2027 } |
2013 if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) { | 2028 if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) { |
2014 return NO; | 2029 return NO; |
2015 } | 2030 } |
2016 return [_dictionary isEqual:other->_dictionary]; | 2031 GPBUInt32UInt64Dictionary *otherDictionary = other; |
| 2032 return [_dictionary isEqual:otherDictionary->_dictionary]; |
2017 } | 2033 } |
2018 | 2034 |
2019 - (NSUInteger)hash { | 2035 - (NSUInteger)hash { |
2020 return _dictionary.count; | 2036 return _dictionary.count; |
2021 } | 2037 } |
2022 | 2038 |
2023 - (NSString *)description { | 2039 - (NSString *)description { |
2024 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 2040 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
2025 } | 2041 } |
2026 | 2042 |
2027 - (NSUInteger)count { | 2043 - (NSUInteger)count { |
2028 return _dictionary.count; | 2044 return _dictionary.count; |
2029 } | 2045 } |
2030 | 2046 |
2031 - (void)enumerateKeysAndValuesUsingBlock: | 2047 - (void)enumerateKeysAndUInt64sUsingBlock: |
2032 (void (^)(uint32_t key, uint64_t value, BOOL *stop))block { | 2048 (void (^)(uint32_t key, uint64_t value, BOOL *stop))block { |
2033 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 2049 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
2034 NSNumber *aValue, | 2050 NSNumber *aValue, |
2035 BOOL *stop) { | 2051 BOOL *stop) { |
2036 block([aKey unsignedIntValue], [aValue unsignedLongLongValue], stop); | 2052 block([aKey unsignedIntValue], [aValue unsignedLongLongValue], stop); |
2037 }]; | 2053 }]; |
2038 } | 2054 } |
2039 | 2055 |
2040 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 2056 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
2041 NSUInteger count = _dictionary.count; | 2057 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2079 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | 2095 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); |
2080 }]; | 2096 }]; |
2081 } | 2097 } |
2082 | 2098 |
2083 - (void)setGPBGenericValue:(GPBGenericValue *)value | 2099 - (void)setGPBGenericValue:(GPBGenericValue *)value |
2084 forGPBGenericValueKey:(GPBGenericValue *)key { | 2100 forGPBGenericValueKey:(GPBGenericValue *)key { |
2085 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)]; | 2101 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)]; |
2086 } | 2102 } |
2087 | 2103 |
2088 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 2104 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
2089 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, uint64_t value, BOOL *s
top) { | 2105 [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, BOOL *
stop) { |
2090 #pragma unused(stop) | 2106 #pragma unused(stop) |
2091 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%llu", value]); | 2107 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%llu", value]); |
2092 }]; | 2108 }]; |
2093 } | 2109 } |
2094 | 2110 |
2095 - (BOOL)valueForKey:(uint32_t)key value:(uint64_t *)value { | 2111 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key { |
2096 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 2112 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
2097 if (wrapped && value) { | 2113 if (wrapped && value) { |
2098 *value = [wrapped unsignedLongLongValue]; | 2114 *value = [wrapped unsignedLongLongValue]; |
2099 } | 2115 } |
2100 return (wrapped != NULL); | 2116 return (wrapped != NULL); |
2101 } | 2117 } |
2102 | 2118 |
2103 - (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary { | 2119 - (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary { |
2104 if (otherDictionary) { | 2120 if (otherDictionary) { |
2105 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 2121 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
2106 if (_autocreator) { | 2122 if (_autocreator) { |
2107 GPBAutocreatedDictionaryModified(_autocreator, self); | 2123 GPBAutocreatedDictionaryModified(_autocreator, self); |
2108 } | 2124 } |
2109 } | 2125 } |
2110 } | 2126 } |
2111 | 2127 |
2112 - (void)setValue:(uint64_t)value forKey:(uint32_t)key { | 2128 - (void)setUInt64:(uint64_t)value forKey:(uint32_t)key { |
2113 [_dictionary setObject:@(value) forKey:@(key)]; | 2129 [_dictionary setObject:@(value) forKey:@(key)]; |
2114 if (_autocreator) { | 2130 if (_autocreator) { |
2115 GPBAutocreatedDictionaryModified(_autocreator, self); | 2131 GPBAutocreatedDictionaryModified(_autocreator, self); |
2116 } | 2132 } |
2117 } | 2133 } |
2118 | 2134 |
2119 - (void)removeValueForKey:(uint32_t)aKey { | 2135 - (void)removeUInt64ForKey:(uint32_t)aKey { |
2120 [_dictionary removeObjectForKey:@(aKey)]; | 2136 [_dictionary removeObjectForKey:@(aKey)]; |
2121 } | 2137 } |
2122 | 2138 |
2123 - (void)removeAll { | 2139 - (void)removeAll { |
2124 [_dictionary removeAllObjects]; | 2140 [_dictionary removeAllObjects]; |
2125 } | 2141 } |
2126 | 2142 |
2127 @end | 2143 @end |
2128 | 2144 |
2129 #pragma mark - UInt32 -> Int64 | 2145 #pragma mark - UInt32 -> Int64 |
2130 | 2146 |
2131 @implementation GPBUInt32Int64Dictionary { | 2147 @implementation GPBUInt32Int64Dictionary { |
2132 @package | 2148 @package |
2133 NSMutableDictionary *_dictionary; | 2149 NSMutableDictionary *_dictionary; |
2134 } | 2150 } |
2135 | 2151 |
2136 + (instancetype)dictionary { | 2152 + (instancetype)dictionary { |
2137 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 2153 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; |
2138 } | 2154 } |
2139 | 2155 |
2140 + (instancetype)dictionaryWithValue:(int64_t)value | 2156 + (instancetype)dictionaryWithInt64:(int64_t)value |
2141 forKey:(uint32_t)key { | 2157 forKey:(uint32_t)key { |
2142 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 2158 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
2143 // on to get the type correct. | 2159 // on to get the type correct. |
2144 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithValues:&value | 2160 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithInt64s:&value |
2145 forKeys:&key | 2161 forKeys:&key |
2146 count:1] autorelease
]; | 2162 count:1] autorelease
]; |
2147 } | 2163 } |
2148 | 2164 |
2149 + (instancetype)dictionaryWithValues:(const int64_t [])values | 2165 + (instancetype)dictionaryWithInt64s:(const int64_t [])values |
2150 forKeys:(const uint32_t [])keys | 2166 forKeys:(const uint32_t [])keys |
2151 count:(NSUInteger)count { | 2167 count:(NSUInteger)count { |
2152 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 2168 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
2153 // on to get the type correct. | 2169 // on to get the type correct. |
2154 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithValues:values | 2170 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithInt64s:values |
2155 forKeys:keys | 2171 forKeys:keys |
2156 count:count] autorel
ease]; | 2172 count:count] autorel
ease]; |
2157 } | 2173 } |
2158 | 2174 |
2159 + (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary
{ | 2175 + (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary
{ |
2160 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 2176 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
2161 // on to get the type correct. | 2177 // on to get the type correct. |
2162 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 2178 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
2163 } | 2179 } |
2164 | 2180 |
2165 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 2181 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
2166 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 2182 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
2167 } | 2183 } |
2168 | 2184 |
2169 - (instancetype)init { | 2185 - (instancetype)init { |
2170 return [self initWithValues:NULL forKeys:NULL count:0]; | 2186 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
2171 } | 2187 } |
2172 | 2188 |
2173 - (instancetype)initWithValues:(const int64_t [])values | 2189 - (instancetype)initWithInt64s:(const int64_t [])values |
2174 forKeys:(const uint32_t [])keys | 2190 forKeys:(const uint32_t [])keys |
2175 count:(NSUInteger)count { | 2191 count:(NSUInteger)count { |
2176 self = [super init]; | 2192 self = [super init]; |
2177 if (self) { | 2193 if (self) { |
2178 _dictionary = [[NSMutableDictionary alloc] init]; | 2194 _dictionary = [[NSMutableDictionary alloc] init]; |
2179 if (count && values && keys) { | 2195 if (count && values && keys) { |
2180 for (NSUInteger i = 0; i < count; ++i) { | 2196 for (NSUInteger i = 0; i < count; ++i) { |
2181 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 2197 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
2182 } | 2198 } |
2183 } | 2199 } |
2184 } | 2200 } |
2185 return self; | 2201 return self; |
2186 } | 2202 } |
2187 | 2203 |
2188 - (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary { | 2204 - (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary { |
2189 self = [self initWithValues:NULL forKeys:NULL count:0]; | 2205 self = [self initWithInt64s:NULL forKeys:NULL count:0]; |
2190 if (self) { | 2206 if (self) { |
2191 if (dictionary) { | 2207 if (dictionary) { |
2192 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 2208 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
2193 } | 2209 } |
2194 } | 2210 } |
2195 return self; | 2211 return self; |
2196 } | 2212 } |
2197 | 2213 |
2198 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 2214 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
2199 #pragma unused(numItems) | 2215 #pragma unused(numItems) |
2200 return [self initWithValues:NULL forKeys:NULL count:0]; | 2216 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
2201 } | 2217 } |
2202 | 2218 |
2203 - (void)dealloc { | 2219 - (void)dealloc { |
2204 NSAssert(!_autocreator, | 2220 NSAssert(!_autocreator, |
2205 @"%@: Autocreator must be cleared before release, autocreator: %@", | 2221 @"%@: Autocreator must be cleared before release, autocreator: %@", |
2206 [self class], _autocreator); | 2222 [self class], _autocreator); |
2207 [_dictionary release]; | 2223 [_dictionary release]; |
2208 [super dealloc]; | 2224 [super dealloc]; |
2209 } | 2225 } |
2210 | 2226 |
2211 - (instancetype)copyWithZone:(NSZone *)zone { | 2227 - (instancetype)copyWithZone:(NSZone *)zone { |
2212 return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]
; | 2228 return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]
; |
2213 } | 2229 } |
2214 | 2230 |
2215 - (BOOL)isEqual:(GPBUInt32Int64Dictionary *)other { | 2231 - (BOOL)isEqual:(id)other { |
2216 if (self == other) { | 2232 if (self == other) { |
2217 return YES; | 2233 return YES; |
2218 } | 2234 } |
2219 if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) { | 2235 if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) { |
2220 return NO; | 2236 return NO; |
2221 } | 2237 } |
2222 return [_dictionary isEqual:other->_dictionary]; | 2238 GPBUInt32Int64Dictionary *otherDictionary = other; |
| 2239 return [_dictionary isEqual:otherDictionary->_dictionary]; |
2223 } | 2240 } |
2224 | 2241 |
2225 - (NSUInteger)hash { | 2242 - (NSUInteger)hash { |
2226 return _dictionary.count; | 2243 return _dictionary.count; |
2227 } | 2244 } |
2228 | 2245 |
2229 - (NSString *)description { | 2246 - (NSString *)description { |
2230 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 2247 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
2231 } | 2248 } |
2232 | 2249 |
2233 - (NSUInteger)count { | 2250 - (NSUInteger)count { |
2234 return _dictionary.count; | 2251 return _dictionary.count; |
2235 } | 2252 } |
2236 | 2253 |
2237 - (void)enumerateKeysAndValuesUsingBlock: | 2254 - (void)enumerateKeysAndInt64sUsingBlock: |
2238 (void (^)(uint32_t key, int64_t value, BOOL *stop))block { | 2255 (void (^)(uint32_t key, int64_t value, BOOL *stop))block { |
2239 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 2256 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
2240 NSNumber *aValue, | 2257 NSNumber *aValue, |
2241 BOOL *stop) { | 2258 BOOL *stop) { |
2242 block([aKey unsignedIntValue], [aValue longLongValue], stop); | 2259 block([aKey unsignedIntValue], [aValue longLongValue], stop); |
2243 }]; | 2260 }]; |
2244 } | 2261 } |
2245 | 2262 |
2246 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 2263 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
2247 NSUInteger count = _dictionary.count; | 2264 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2285 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | 2302 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); |
2286 }]; | 2303 }]; |
2287 } | 2304 } |
2288 | 2305 |
2289 - (void)setGPBGenericValue:(GPBGenericValue *)value | 2306 - (void)setGPBGenericValue:(GPBGenericValue *)value |
2290 forGPBGenericValueKey:(GPBGenericValue *)key { | 2307 forGPBGenericValueKey:(GPBGenericValue *)key { |
2291 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)]; | 2308 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)]; |
2292 } | 2309 } |
2293 | 2310 |
2294 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 2311 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
2295 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, int64_t value, BOOL *st
op) { | 2312 [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, BOOL *st
op) { |
2296 #pragma unused(stop) | 2313 #pragma unused(stop) |
2297 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%lld", value]); | 2314 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%lld", value]); |
2298 }]; | 2315 }]; |
2299 } | 2316 } |
2300 | 2317 |
2301 - (BOOL)valueForKey:(uint32_t)key value:(int64_t *)value { | 2318 - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key { |
2302 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 2319 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
2303 if (wrapped && value) { | 2320 if (wrapped && value) { |
2304 *value = [wrapped longLongValue]; | 2321 *value = [wrapped longLongValue]; |
2305 } | 2322 } |
2306 return (wrapped != NULL); | 2323 return (wrapped != NULL); |
2307 } | 2324 } |
2308 | 2325 |
2309 - (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary { | 2326 - (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary { |
2310 if (otherDictionary) { | 2327 if (otherDictionary) { |
2311 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 2328 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
2312 if (_autocreator) { | 2329 if (_autocreator) { |
2313 GPBAutocreatedDictionaryModified(_autocreator, self); | 2330 GPBAutocreatedDictionaryModified(_autocreator, self); |
2314 } | 2331 } |
2315 } | 2332 } |
2316 } | 2333 } |
2317 | 2334 |
2318 - (void)setValue:(int64_t)value forKey:(uint32_t)key { | 2335 - (void)setInt64:(int64_t)value forKey:(uint32_t)key { |
2319 [_dictionary setObject:@(value) forKey:@(key)]; | 2336 [_dictionary setObject:@(value) forKey:@(key)]; |
2320 if (_autocreator) { | 2337 if (_autocreator) { |
2321 GPBAutocreatedDictionaryModified(_autocreator, self); | 2338 GPBAutocreatedDictionaryModified(_autocreator, self); |
2322 } | 2339 } |
2323 } | 2340 } |
2324 | 2341 |
2325 - (void)removeValueForKey:(uint32_t)aKey { | 2342 - (void)removeInt64ForKey:(uint32_t)aKey { |
2326 [_dictionary removeObjectForKey:@(aKey)]; | 2343 [_dictionary removeObjectForKey:@(aKey)]; |
2327 } | 2344 } |
2328 | 2345 |
2329 - (void)removeAll { | 2346 - (void)removeAll { |
2330 [_dictionary removeAllObjects]; | 2347 [_dictionary removeAllObjects]; |
2331 } | 2348 } |
2332 | 2349 |
2333 @end | 2350 @end |
2334 | 2351 |
2335 #pragma mark - UInt32 -> Bool | 2352 #pragma mark - UInt32 -> Bool |
2336 | 2353 |
2337 @implementation GPBUInt32BoolDictionary { | 2354 @implementation GPBUInt32BoolDictionary { |
2338 @package | 2355 @package |
2339 NSMutableDictionary *_dictionary; | 2356 NSMutableDictionary *_dictionary; |
2340 } | 2357 } |
2341 | 2358 |
2342 + (instancetype)dictionary { | 2359 + (instancetype)dictionary { |
2343 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 2360 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; |
2344 } | 2361 } |
2345 | 2362 |
2346 + (instancetype)dictionaryWithValue:(BOOL)value | 2363 + (instancetype)dictionaryWithBool:(BOOL)value |
2347 forKey:(uint32_t)key { | 2364 forKey:(uint32_t)key { |
2348 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 2365 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
2349 // on to get the type correct. | 2366 // on to get the type correct. |
2350 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithValues:&value | 2367 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithBools:&value |
2351 forKeys:&key | 2368 forKeys:&key |
2352 count:1] autorelease]
; | 2369 count:1] autorelease]; |
2353 } | 2370 } |
2354 | 2371 |
2355 + (instancetype)dictionaryWithValues:(const BOOL [])values | 2372 + (instancetype)dictionaryWithBools:(const BOOL [])values |
2356 forKeys:(const uint32_t [])keys | 2373 forKeys:(const uint32_t [])keys |
2357 count:(NSUInteger)count { | 2374 count:(NSUInteger)count { |
2358 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 2375 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
2359 // on to get the type correct. | 2376 // on to get the type correct. |
2360 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithValues:values | 2377 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithBools:values |
2361 forKeys:keys | 2378 forKeys:keys |
2362 count:count] autorele
ase]; | 2379 count:count] autorele
ase]; |
2363 } | 2380 } |
2364 | 2381 |
2365 + (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary { | 2382 + (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary { |
2366 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 2383 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
2367 // on to get the type correct. | 2384 // on to get the type correct. |
2368 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 2385 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
2369 } | 2386 } |
2370 | 2387 |
2371 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 2388 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
2372 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 2389 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
2373 } | 2390 } |
2374 | 2391 |
2375 - (instancetype)init { | 2392 - (instancetype)init { |
2376 return [self initWithValues:NULL forKeys:NULL count:0]; | 2393 return [self initWithBools:NULL forKeys:NULL count:0]; |
2377 } | 2394 } |
2378 | 2395 |
2379 - (instancetype)initWithValues:(const BOOL [])values | 2396 - (instancetype)initWithBools:(const BOOL [])values |
2380 forKeys:(const uint32_t [])keys | 2397 forKeys:(const uint32_t [])keys |
2381 count:(NSUInteger)count { | 2398 count:(NSUInteger)count { |
2382 self = [super init]; | 2399 self = [super init]; |
2383 if (self) { | 2400 if (self) { |
2384 _dictionary = [[NSMutableDictionary alloc] init]; | 2401 _dictionary = [[NSMutableDictionary alloc] init]; |
2385 if (count && values && keys) { | 2402 if (count && values && keys) { |
2386 for (NSUInteger i = 0; i < count; ++i) { | 2403 for (NSUInteger i = 0; i < count; ++i) { |
2387 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 2404 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
2388 } | 2405 } |
2389 } | 2406 } |
2390 } | 2407 } |
2391 return self; | 2408 return self; |
2392 } | 2409 } |
2393 | 2410 |
2394 - (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary { | 2411 - (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary { |
2395 self = [self initWithValues:NULL forKeys:NULL count:0]; | 2412 self = [self initWithBools:NULL forKeys:NULL count:0]; |
2396 if (self) { | 2413 if (self) { |
2397 if (dictionary) { | 2414 if (dictionary) { |
2398 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 2415 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
2399 } | 2416 } |
2400 } | 2417 } |
2401 return self; | 2418 return self; |
2402 } | 2419 } |
2403 | 2420 |
2404 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 2421 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
2405 #pragma unused(numItems) | 2422 #pragma unused(numItems) |
2406 return [self initWithValues:NULL forKeys:NULL count:0]; | 2423 return [self initWithBools:NULL forKeys:NULL count:0]; |
2407 } | 2424 } |
2408 | 2425 |
2409 - (void)dealloc { | 2426 - (void)dealloc { |
2410 NSAssert(!_autocreator, | 2427 NSAssert(!_autocreator, |
2411 @"%@: Autocreator must be cleared before release, autocreator: %@", | 2428 @"%@: Autocreator must be cleared before release, autocreator: %@", |
2412 [self class], _autocreator); | 2429 [self class], _autocreator); |
2413 [_dictionary release]; | 2430 [_dictionary release]; |
2414 [super dealloc]; | 2431 [super dealloc]; |
2415 } | 2432 } |
2416 | 2433 |
2417 - (instancetype)copyWithZone:(NSZone *)zone { | 2434 - (instancetype)copyWithZone:(NSZone *)zone { |
2418 return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; | 2435 return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; |
2419 } | 2436 } |
2420 | 2437 |
2421 - (BOOL)isEqual:(GPBUInt32BoolDictionary *)other { | 2438 - (BOOL)isEqual:(id)other { |
2422 if (self == other) { | 2439 if (self == other) { |
2423 return YES; | 2440 return YES; |
2424 } | 2441 } |
2425 if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) { | 2442 if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) { |
2426 return NO; | 2443 return NO; |
2427 } | 2444 } |
2428 return [_dictionary isEqual:other->_dictionary]; | 2445 GPBUInt32BoolDictionary *otherDictionary = other; |
| 2446 return [_dictionary isEqual:otherDictionary->_dictionary]; |
2429 } | 2447 } |
2430 | 2448 |
2431 - (NSUInteger)hash { | 2449 - (NSUInteger)hash { |
2432 return _dictionary.count; | 2450 return _dictionary.count; |
2433 } | 2451 } |
2434 | 2452 |
2435 - (NSString *)description { | 2453 - (NSString *)description { |
2436 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 2454 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
2437 } | 2455 } |
2438 | 2456 |
2439 - (NSUInteger)count { | 2457 - (NSUInteger)count { |
2440 return _dictionary.count; | 2458 return _dictionary.count; |
2441 } | 2459 } |
2442 | 2460 |
2443 - (void)enumerateKeysAndValuesUsingBlock: | 2461 - (void)enumerateKeysAndBoolsUsingBlock: |
2444 (void (^)(uint32_t key, BOOL value, BOOL *stop))block { | 2462 (void (^)(uint32_t key, BOOL value, BOOL *stop))block { |
2445 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 2463 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
2446 NSNumber *aValue, | 2464 NSNumber *aValue, |
2447 BOOL *stop) { | 2465 BOOL *stop) { |
2448 block([aKey unsignedIntValue], [aValue boolValue], stop); | 2466 block([aKey unsignedIntValue], [aValue boolValue], stop); |
2449 }]; | 2467 }]; |
2450 } | 2468 } |
2451 | 2469 |
2452 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 2470 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
2453 NSUInteger count = _dictionary.count; | 2471 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2491 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | 2509 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); |
2492 }]; | 2510 }]; |
2493 } | 2511 } |
2494 | 2512 |
2495 - (void)setGPBGenericValue:(GPBGenericValue *)value | 2513 - (void)setGPBGenericValue:(GPBGenericValue *)value |
2496 forGPBGenericValueKey:(GPBGenericValue *)key { | 2514 forGPBGenericValueKey:(GPBGenericValue *)key { |
2497 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)]; | 2515 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)]; |
2498 } | 2516 } |
2499 | 2517 |
2500 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 2518 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
2501 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, BOOL value, BOOL *stop)
{ | 2519 [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, BOOL *stop)
{ |
2502 #pragma unused(stop) | 2520 #pragma unused(stop) |
2503 block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false")
); | 2521 block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false")
); |
2504 }]; | 2522 }]; |
2505 } | 2523 } |
2506 | 2524 |
2507 - (BOOL)valueForKey:(uint32_t)key value:(BOOL *)value { | 2525 - (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key { |
2508 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 2526 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
2509 if (wrapped && value) { | 2527 if (wrapped && value) { |
2510 *value = [wrapped boolValue]; | 2528 *value = [wrapped boolValue]; |
2511 } | 2529 } |
2512 return (wrapped != NULL); | 2530 return (wrapped != NULL); |
2513 } | 2531 } |
2514 | 2532 |
2515 - (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary { | 2533 - (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary { |
2516 if (otherDictionary) { | 2534 if (otherDictionary) { |
2517 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 2535 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
2518 if (_autocreator) { | 2536 if (_autocreator) { |
2519 GPBAutocreatedDictionaryModified(_autocreator, self); | 2537 GPBAutocreatedDictionaryModified(_autocreator, self); |
2520 } | 2538 } |
2521 } | 2539 } |
2522 } | 2540 } |
2523 | 2541 |
2524 - (void)setValue:(BOOL)value forKey:(uint32_t)key { | 2542 - (void)setBool:(BOOL)value forKey:(uint32_t)key { |
2525 [_dictionary setObject:@(value) forKey:@(key)]; | 2543 [_dictionary setObject:@(value) forKey:@(key)]; |
2526 if (_autocreator) { | 2544 if (_autocreator) { |
2527 GPBAutocreatedDictionaryModified(_autocreator, self); | 2545 GPBAutocreatedDictionaryModified(_autocreator, self); |
2528 } | 2546 } |
2529 } | 2547 } |
2530 | 2548 |
2531 - (void)removeValueForKey:(uint32_t)aKey { | 2549 - (void)removeBoolForKey:(uint32_t)aKey { |
2532 [_dictionary removeObjectForKey:@(aKey)]; | 2550 [_dictionary removeObjectForKey:@(aKey)]; |
2533 } | 2551 } |
2534 | 2552 |
2535 - (void)removeAll { | 2553 - (void)removeAll { |
2536 [_dictionary removeAllObjects]; | 2554 [_dictionary removeAllObjects]; |
2537 } | 2555 } |
2538 | 2556 |
2539 @end | 2557 @end |
2540 | 2558 |
2541 #pragma mark - UInt32 -> Float | 2559 #pragma mark - UInt32 -> Float |
2542 | 2560 |
2543 @implementation GPBUInt32FloatDictionary { | 2561 @implementation GPBUInt32FloatDictionary { |
2544 @package | 2562 @package |
2545 NSMutableDictionary *_dictionary; | 2563 NSMutableDictionary *_dictionary; |
2546 } | 2564 } |
2547 | 2565 |
2548 + (instancetype)dictionary { | 2566 + (instancetype)dictionary { |
2549 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 2567 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; |
2550 } | 2568 } |
2551 | 2569 |
2552 + (instancetype)dictionaryWithValue:(float)value | 2570 + (instancetype)dictionaryWithFloat:(float)value |
2553 forKey:(uint32_t)key { | 2571 forKey:(uint32_t)key { |
2554 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 2572 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
2555 // on to get the type correct. | 2573 // on to get the type correct. |
2556 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithValues:&value | 2574 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithFloats:&value |
2557 forKeys:&key | 2575 forKeys:&key |
2558 count:1] autorelease
]; | 2576 count:1] autorelease
]; |
2559 } | 2577 } |
2560 | 2578 |
2561 + (instancetype)dictionaryWithValues:(const float [])values | 2579 + (instancetype)dictionaryWithFloats:(const float [])values |
2562 forKeys:(const uint32_t [])keys | 2580 forKeys:(const uint32_t [])keys |
2563 count:(NSUInteger)count { | 2581 count:(NSUInteger)count { |
2564 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 2582 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
2565 // on to get the type correct. | 2583 // on to get the type correct. |
2566 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithValues:values | 2584 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithFloats:values |
2567 forKeys:keys | 2585 forKeys:keys |
2568 count:count] autorel
ease]; | 2586 count:count] autorel
ease]; |
2569 } | 2587 } |
2570 | 2588 |
2571 + (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary
{ | 2589 + (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary
{ |
2572 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 2590 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
2573 // on to get the type correct. | 2591 // on to get the type correct. |
2574 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 2592 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
2575 } | 2593 } |
2576 | 2594 |
2577 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 2595 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
2578 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 2596 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
2579 } | 2597 } |
2580 | 2598 |
2581 - (instancetype)init { | 2599 - (instancetype)init { |
2582 return [self initWithValues:NULL forKeys:NULL count:0]; | 2600 return [self initWithFloats:NULL forKeys:NULL count:0]; |
2583 } | 2601 } |
2584 | 2602 |
2585 - (instancetype)initWithValues:(const float [])values | 2603 - (instancetype)initWithFloats:(const float [])values |
2586 forKeys:(const uint32_t [])keys | 2604 forKeys:(const uint32_t [])keys |
2587 count:(NSUInteger)count { | 2605 count:(NSUInteger)count { |
2588 self = [super init]; | 2606 self = [super init]; |
2589 if (self) { | 2607 if (self) { |
2590 _dictionary = [[NSMutableDictionary alloc] init]; | 2608 _dictionary = [[NSMutableDictionary alloc] init]; |
2591 if (count && values && keys) { | 2609 if (count && values && keys) { |
2592 for (NSUInteger i = 0; i < count; ++i) { | 2610 for (NSUInteger i = 0; i < count; ++i) { |
2593 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 2611 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
2594 } | 2612 } |
2595 } | 2613 } |
2596 } | 2614 } |
2597 return self; | 2615 return self; |
2598 } | 2616 } |
2599 | 2617 |
2600 - (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary { | 2618 - (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary { |
2601 self = [self initWithValues:NULL forKeys:NULL count:0]; | 2619 self = [self initWithFloats:NULL forKeys:NULL count:0]; |
2602 if (self) { | 2620 if (self) { |
2603 if (dictionary) { | 2621 if (dictionary) { |
2604 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 2622 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
2605 } | 2623 } |
2606 } | 2624 } |
2607 return self; | 2625 return self; |
2608 } | 2626 } |
2609 | 2627 |
2610 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 2628 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
2611 #pragma unused(numItems) | 2629 #pragma unused(numItems) |
2612 return [self initWithValues:NULL forKeys:NULL count:0]; | 2630 return [self initWithFloats:NULL forKeys:NULL count:0]; |
2613 } | 2631 } |
2614 | 2632 |
2615 - (void)dealloc { | 2633 - (void)dealloc { |
2616 NSAssert(!_autocreator, | 2634 NSAssert(!_autocreator, |
2617 @"%@: Autocreator must be cleared before release, autocreator: %@", | 2635 @"%@: Autocreator must be cleared before release, autocreator: %@", |
2618 [self class], _autocreator); | 2636 [self class], _autocreator); |
2619 [_dictionary release]; | 2637 [_dictionary release]; |
2620 [super dealloc]; | 2638 [super dealloc]; |
2621 } | 2639 } |
2622 | 2640 |
2623 - (instancetype)copyWithZone:(NSZone *)zone { | 2641 - (instancetype)copyWithZone:(NSZone *)zone { |
2624 return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]
; | 2642 return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]
; |
2625 } | 2643 } |
2626 | 2644 |
2627 - (BOOL)isEqual:(GPBUInt32FloatDictionary *)other { | 2645 - (BOOL)isEqual:(id)other { |
2628 if (self == other) { | 2646 if (self == other) { |
2629 return YES; | 2647 return YES; |
2630 } | 2648 } |
2631 if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) { | 2649 if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) { |
2632 return NO; | 2650 return NO; |
2633 } | 2651 } |
2634 return [_dictionary isEqual:other->_dictionary]; | 2652 GPBUInt32FloatDictionary *otherDictionary = other; |
| 2653 return [_dictionary isEqual:otherDictionary->_dictionary]; |
2635 } | 2654 } |
2636 | 2655 |
2637 - (NSUInteger)hash { | 2656 - (NSUInteger)hash { |
2638 return _dictionary.count; | 2657 return _dictionary.count; |
2639 } | 2658 } |
2640 | 2659 |
2641 - (NSString *)description { | 2660 - (NSString *)description { |
2642 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 2661 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
2643 } | 2662 } |
2644 | 2663 |
2645 - (NSUInteger)count { | 2664 - (NSUInteger)count { |
2646 return _dictionary.count; | 2665 return _dictionary.count; |
2647 } | 2666 } |
2648 | 2667 |
2649 - (void)enumerateKeysAndValuesUsingBlock: | 2668 - (void)enumerateKeysAndFloatsUsingBlock: |
2650 (void (^)(uint32_t key, float value, BOOL *stop))block { | 2669 (void (^)(uint32_t key, float value, BOOL *stop))block { |
2651 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 2670 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
2652 NSNumber *aValue, | 2671 NSNumber *aValue, |
2653 BOOL *stop) { | 2672 BOOL *stop) { |
2654 block([aKey unsignedIntValue], [aValue floatValue], stop); | 2673 block([aKey unsignedIntValue], [aValue floatValue], stop); |
2655 }]; | 2674 }]; |
2656 } | 2675 } |
2657 | 2676 |
2658 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 2677 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
2659 NSUInteger count = _dictionary.count; | 2678 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2697 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | 2716 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); |
2698 }]; | 2717 }]; |
2699 } | 2718 } |
2700 | 2719 |
2701 - (void)setGPBGenericValue:(GPBGenericValue *)value | 2720 - (void)setGPBGenericValue:(GPBGenericValue *)value |
2702 forGPBGenericValueKey:(GPBGenericValue *)key { | 2721 forGPBGenericValueKey:(GPBGenericValue *)key { |
2703 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)]; | 2722 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)]; |
2704 } | 2723 } |
2705 | 2724 |
2706 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 2725 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
2707 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, float value, BOOL *stop
) { | 2726 [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, BOOL *stop
) { |
2708 #pragma unused(stop) | 2727 #pragma unused(stop) |
2709 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%.*g", FLT_DIG, value]); | 2728 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%.*g", FLT_DIG, value]); |
2710 }]; | 2729 }]; |
2711 } | 2730 } |
2712 | 2731 |
2713 - (BOOL)valueForKey:(uint32_t)key value:(float *)value { | 2732 - (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key { |
2714 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 2733 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
2715 if (wrapped && value) { | 2734 if (wrapped && value) { |
2716 *value = [wrapped floatValue]; | 2735 *value = [wrapped floatValue]; |
2717 } | 2736 } |
2718 return (wrapped != NULL); | 2737 return (wrapped != NULL); |
2719 } | 2738 } |
2720 | 2739 |
2721 - (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary { | 2740 - (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary { |
2722 if (otherDictionary) { | 2741 if (otherDictionary) { |
2723 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 2742 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
2724 if (_autocreator) { | 2743 if (_autocreator) { |
2725 GPBAutocreatedDictionaryModified(_autocreator, self); | 2744 GPBAutocreatedDictionaryModified(_autocreator, self); |
2726 } | 2745 } |
2727 } | 2746 } |
2728 } | 2747 } |
2729 | 2748 |
2730 - (void)setValue:(float)value forKey:(uint32_t)key { | 2749 - (void)setFloat:(float)value forKey:(uint32_t)key { |
2731 [_dictionary setObject:@(value) forKey:@(key)]; | 2750 [_dictionary setObject:@(value) forKey:@(key)]; |
2732 if (_autocreator) { | 2751 if (_autocreator) { |
2733 GPBAutocreatedDictionaryModified(_autocreator, self); | 2752 GPBAutocreatedDictionaryModified(_autocreator, self); |
2734 } | 2753 } |
2735 } | 2754 } |
2736 | 2755 |
2737 - (void)removeValueForKey:(uint32_t)aKey { | 2756 - (void)removeFloatForKey:(uint32_t)aKey { |
2738 [_dictionary removeObjectForKey:@(aKey)]; | 2757 [_dictionary removeObjectForKey:@(aKey)]; |
2739 } | 2758 } |
2740 | 2759 |
2741 - (void)removeAll { | 2760 - (void)removeAll { |
2742 [_dictionary removeAllObjects]; | 2761 [_dictionary removeAllObjects]; |
2743 } | 2762 } |
2744 | 2763 |
2745 @end | 2764 @end |
2746 | 2765 |
2747 #pragma mark - UInt32 -> Double | 2766 #pragma mark - UInt32 -> Double |
2748 | 2767 |
2749 @implementation GPBUInt32DoubleDictionary { | 2768 @implementation GPBUInt32DoubleDictionary { |
2750 @package | 2769 @package |
2751 NSMutableDictionary *_dictionary; | 2770 NSMutableDictionary *_dictionary; |
2752 } | 2771 } |
2753 | 2772 |
2754 + (instancetype)dictionary { | 2773 + (instancetype)dictionary { |
2755 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 2774 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; |
2756 } | 2775 } |
2757 | 2776 |
2758 + (instancetype)dictionaryWithValue:(double)value | 2777 + (instancetype)dictionaryWithDouble:(double)value |
2759 forKey:(uint32_t)key { | 2778 forKey:(uint32_t)key { |
2760 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 2779 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
2761 // on to get the type correct. | 2780 // on to get the type correct. |
2762 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithValues:&value | 2781 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDoubles:&value |
2763 forKeys:&key | 2782 forKeys:&key |
2764 count:1] autoreleas
e]; | 2783 count:1] autorelea
se]; |
2765 } | 2784 } |
2766 | 2785 |
2767 + (instancetype)dictionaryWithValues:(const double [])values | 2786 + (instancetype)dictionaryWithDoubles:(const double [])values |
2768 forKeys:(const uint32_t [])keys | 2787 forKeys:(const uint32_t [])keys |
2769 count:(NSUInteger)count { | 2788 count:(NSUInteger)count { |
2770 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 2789 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
2771 // on to get the type correct. | 2790 // on to get the type correct. |
2772 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithValues:values | 2791 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDoubles:values |
2773 forKeys:keys | 2792 forKeys:keys |
2774 count:count] autore
lease]; | 2793 count:count] autore
lease]; |
2775 } | 2794 } |
2776 | 2795 |
2777 + (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary
{ | 2796 + (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary
{ |
2778 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 2797 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
2779 // on to get the type correct. | 2798 // on to get the type correct. |
2780 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 2799 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
2781 } | 2800 } |
2782 | 2801 |
2783 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 2802 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
2784 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 2803 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
2785 } | 2804 } |
2786 | 2805 |
2787 - (instancetype)init { | 2806 - (instancetype)init { |
2788 return [self initWithValues:NULL forKeys:NULL count:0]; | 2807 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
2789 } | 2808 } |
2790 | 2809 |
2791 - (instancetype)initWithValues:(const double [])values | 2810 - (instancetype)initWithDoubles:(const double [])values |
2792 forKeys:(const uint32_t [])keys | 2811 forKeys:(const uint32_t [])keys |
2793 count:(NSUInteger)count { | 2812 count:(NSUInteger)count { |
2794 self = [super init]; | 2813 self = [super init]; |
2795 if (self) { | 2814 if (self) { |
2796 _dictionary = [[NSMutableDictionary alloc] init]; | 2815 _dictionary = [[NSMutableDictionary alloc] init]; |
2797 if (count && values && keys) { | 2816 if (count && values && keys) { |
2798 for (NSUInteger i = 0; i < count; ++i) { | 2817 for (NSUInteger i = 0; i < count; ++i) { |
2799 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 2818 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
2800 } | 2819 } |
2801 } | 2820 } |
2802 } | 2821 } |
2803 return self; | 2822 return self; |
2804 } | 2823 } |
2805 | 2824 |
2806 - (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary { | 2825 - (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary { |
2807 self = [self initWithValues:NULL forKeys:NULL count:0]; | 2826 self = [self initWithDoubles:NULL forKeys:NULL count:0]; |
2808 if (self) { | 2827 if (self) { |
2809 if (dictionary) { | 2828 if (dictionary) { |
2810 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 2829 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
2811 } | 2830 } |
2812 } | 2831 } |
2813 return self; | 2832 return self; |
2814 } | 2833 } |
2815 | 2834 |
2816 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 2835 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
2817 #pragma unused(numItems) | 2836 #pragma unused(numItems) |
2818 return [self initWithValues:NULL forKeys:NULL count:0]; | 2837 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
2819 } | 2838 } |
2820 | 2839 |
2821 - (void)dealloc { | 2840 - (void)dealloc { |
2822 NSAssert(!_autocreator, | 2841 NSAssert(!_autocreator, |
2823 @"%@: Autocreator must be cleared before release, autocreator: %@", | 2842 @"%@: Autocreator must be cleared before release, autocreator: %@", |
2824 [self class], _autocreator); | 2843 [self class], _autocreator); |
2825 [_dictionary release]; | 2844 [_dictionary release]; |
2826 [super dealloc]; | 2845 [super dealloc]; |
2827 } | 2846 } |
2828 | 2847 |
2829 - (instancetype)copyWithZone:(NSZone *)zone { | 2848 - (instancetype)copyWithZone:(NSZone *)zone { |
2830 return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self
]; | 2849 return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self
]; |
2831 } | 2850 } |
2832 | 2851 |
2833 - (BOOL)isEqual:(GPBUInt32DoubleDictionary *)other { | 2852 - (BOOL)isEqual:(id)other { |
2834 if (self == other) { | 2853 if (self == other) { |
2835 return YES; | 2854 return YES; |
2836 } | 2855 } |
2837 if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) { | 2856 if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) { |
2838 return NO; | 2857 return NO; |
2839 } | 2858 } |
2840 return [_dictionary isEqual:other->_dictionary]; | 2859 GPBUInt32DoubleDictionary *otherDictionary = other; |
| 2860 return [_dictionary isEqual:otherDictionary->_dictionary]; |
2841 } | 2861 } |
2842 | 2862 |
2843 - (NSUInteger)hash { | 2863 - (NSUInteger)hash { |
2844 return _dictionary.count; | 2864 return _dictionary.count; |
2845 } | 2865 } |
2846 | 2866 |
2847 - (NSString *)description { | 2867 - (NSString *)description { |
2848 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 2868 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
2849 } | 2869 } |
2850 | 2870 |
2851 - (NSUInteger)count { | 2871 - (NSUInteger)count { |
2852 return _dictionary.count; | 2872 return _dictionary.count; |
2853 } | 2873 } |
2854 | 2874 |
2855 - (void)enumerateKeysAndValuesUsingBlock: | 2875 - (void)enumerateKeysAndDoublesUsingBlock: |
2856 (void (^)(uint32_t key, double value, BOOL *stop))block { | 2876 (void (^)(uint32_t key, double value, BOOL *stop))block { |
2857 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 2877 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
2858 NSNumber *aValue, | 2878 NSNumber *aValue, |
2859 BOOL *stop) { | 2879 BOOL *stop) { |
2860 block([aKey unsignedIntValue], [aValue doubleValue], stop); | 2880 block([aKey unsignedIntValue], [aValue doubleValue], stop); |
2861 }]; | 2881 }]; |
2862 } | 2882 } |
2863 | 2883 |
2864 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 2884 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
2865 NSUInteger count = _dictionary.count; | 2885 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2903 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | 2923 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); |
2904 }]; | 2924 }]; |
2905 } | 2925 } |
2906 | 2926 |
2907 - (void)setGPBGenericValue:(GPBGenericValue *)value | 2927 - (void)setGPBGenericValue:(GPBGenericValue *)value |
2908 forGPBGenericValueKey:(GPBGenericValue *)key { | 2928 forGPBGenericValueKey:(GPBGenericValue *)key { |
2909 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)]; | 2929 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)]; |
2910 } | 2930 } |
2911 | 2931 |
2912 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 2932 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
2913 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, double value, BOOL *sto
p) { | 2933 [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, BOOL *st
op) { |
2914 #pragma unused(stop) | 2934 #pragma unused(stop) |
2915 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%.*lg", DBL_DIG, value]); | 2935 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%.*lg", DBL_DIG, value]); |
2916 }]; | 2936 }]; |
2917 } | 2937 } |
2918 | 2938 |
2919 - (BOOL)valueForKey:(uint32_t)key value:(double *)value { | 2939 - (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key { |
2920 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 2940 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
2921 if (wrapped && value) { | 2941 if (wrapped && value) { |
2922 *value = [wrapped doubleValue]; | 2942 *value = [wrapped doubleValue]; |
2923 } | 2943 } |
2924 return (wrapped != NULL); | 2944 return (wrapped != NULL); |
2925 } | 2945 } |
2926 | 2946 |
2927 - (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary { | 2947 - (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary { |
2928 if (otherDictionary) { | 2948 if (otherDictionary) { |
2929 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 2949 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
2930 if (_autocreator) { | 2950 if (_autocreator) { |
2931 GPBAutocreatedDictionaryModified(_autocreator, self); | 2951 GPBAutocreatedDictionaryModified(_autocreator, self); |
2932 } | 2952 } |
2933 } | 2953 } |
2934 } | 2954 } |
2935 | 2955 |
2936 - (void)setValue:(double)value forKey:(uint32_t)key { | 2956 - (void)setDouble:(double)value forKey:(uint32_t)key { |
2937 [_dictionary setObject:@(value) forKey:@(key)]; | 2957 [_dictionary setObject:@(value) forKey:@(key)]; |
2938 if (_autocreator) { | 2958 if (_autocreator) { |
2939 GPBAutocreatedDictionaryModified(_autocreator, self); | 2959 GPBAutocreatedDictionaryModified(_autocreator, self); |
2940 } | 2960 } |
2941 } | 2961 } |
2942 | 2962 |
2943 - (void)removeValueForKey:(uint32_t)aKey { | 2963 - (void)removeDoubleForKey:(uint32_t)aKey { |
2944 [_dictionary removeObjectForKey:@(aKey)]; | 2964 [_dictionary removeObjectForKey:@(aKey)]; |
2945 } | 2965 } |
2946 | 2966 |
2947 - (void)removeAll { | 2967 - (void)removeAll { |
2948 [_dictionary removeAllObjects]; | 2968 [_dictionary removeAllObjects]; |
2949 } | 2969 } |
2950 | 2970 |
2951 @end | 2971 @end |
2952 | 2972 |
2953 #pragma mark - UInt32 -> Enum | 2973 #pragma mark - UInt32 -> Enum |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3057 @"%@: Autocreator must be cleared before release, autocreator: %@", | 3077 @"%@: Autocreator must be cleared before release, autocreator: %@", |
3058 [self class], _autocreator); | 3078 [self class], _autocreator); |
3059 [_dictionary release]; | 3079 [_dictionary release]; |
3060 [super dealloc]; | 3080 [super dealloc]; |
3061 } | 3081 } |
3062 | 3082 |
3063 - (instancetype)copyWithZone:(NSZone *)zone { | 3083 - (instancetype)copyWithZone:(NSZone *)zone { |
3064 return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; | 3084 return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; |
3065 } | 3085 } |
3066 | 3086 |
3067 - (BOOL)isEqual:(GPBUInt32EnumDictionary *)other { | 3087 - (BOOL)isEqual:(id)other { |
3068 if (self == other) { | 3088 if (self == other) { |
3069 return YES; | 3089 return YES; |
3070 } | 3090 } |
3071 if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) { | 3091 if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) { |
3072 return NO; | 3092 return NO; |
3073 } | 3093 } |
3074 return [_dictionary isEqual:other->_dictionary]; | 3094 GPBUInt32EnumDictionary *otherDictionary = other; |
| 3095 return [_dictionary isEqual:otherDictionary->_dictionary]; |
3075 } | 3096 } |
3076 | 3097 |
3077 - (NSUInteger)hash { | 3098 - (NSUInteger)hash { |
3078 return _dictionary.count; | 3099 return _dictionary.count; |
3079 } | 3100 } |
3080 | 3101 |
3081 - (NSString *)description { | 3102 - (NSString *)description { |
3082 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 3103 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
3083 } | 3104 } |
3084 | 3105 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3155 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)]; | 3176 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)]; |
3156 } | 3177 } |
3157 | 3178 |
3158 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 3179 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
3159 [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL
*stop) { | 3180 [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL
*stop) { |
3160 #pragma unused(stop) | 3181 #pragma unused(stop) |
3161 block([NSString stringWithFormat:@"%u", key], @(value)); | 3182 block([NSString stringWithFormat:@"%u", key], @(value)); |
3162 }]; | 3183 }]; |
3163 } | 3184 } |
3164 | 3185 |
3165 - (BOOL)valueForKey:(uint32_t)key value:(int32_t *)value { | 3186 - (BOOL)getEnum:(int32_t *)value forKey:(uint32_t)key { |
3166 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 3187 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
3167 if (wrapped && value) { | 3188 if (wrapped && value) { |
3168 int32_t result = [wrapped intValue]; | 3189 int32_t result = [wrapped intValue]; |
3169 if (!_validationFunc(result)) { | 3190 if (!_validationFunc(result)) { |
3170 result = kGPBUnrecognizedEnumeratorValue; | 3191 result = kGPBUnrecognizedEnumeratorValue; |
3171 } | 3192 } |
3172 *value = result; | 3193 *value = result; |
3173 } | 3194 } |
3174 return (wrapped != NULL); | 3195 return (wrapped != NULL); |
3175 } | 3196 } |
3176 | 3197 |
3177 - (BOOL)valueForKey:(uint32_t)key rawValue:(int32_t *)rawValue { | 3198 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint32_t)key { |
3178 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 3199 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
3179 if (wrapped && rawValue) { | 3200 if (wrapped && rawValue) { |
3180 *rawValue = [wrapped intValue]; | 3201 *rawValue = [wrapped intValue]; |
3181 } | 3202 } |
3182 return (wrapped != NULL); | 3203 return (wrapped != NULL); |
3183 } | 3204 } |
3184 | 3205 |
3185 - (void)enumerateKeysAndValuesUsingBlock: | 3206 - (void)enumerateKeysAndEnumsUsingBlock: |
3186 (void (^)(uint32_t key, int32_t value, BOOL *stop))block { | 3207 (void (^)(uint32_t key, int32_t value, BOOL *stop))block { |
3187 GPBEnumValidationFunc func = _validationFunc; | 3208 GPBEnumValidationFunc func = _validationFunc; |
3188 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 3209 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
3189 NSNumber *aValue, | 3210 NSNumber *aValue, |
3190 BOOL *stop) { | 3211 BOOL *stop) { |
3191 int32_t unwrapped = [aValue intValue]; | 3212 int32_t unwrapped = [aValue intValue]; |
3192 if (!func(unwrapped)) { | 3213 if (!func(unwrapped)) { |
3193 unwrapped = kGPBUnrecognizedEnumeratorValue; | 3214 unwrapped = kGPBUnrecognizedEnumeratorValue; |
3194 } | 3215 } |
3195 block([aKey unsignedIntValue], unwrapped, stop); | 3216 block([aKey unsignedIntValue], unwrapped, stop); |
3196 }]; | 3217 }]; |
3197 } | 3218 } |
3198 | 3219 |
3199 - (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary { | 3220 - (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary { |
3200 if (otherDictionary) { | 3221 if (otherDictionary) { |
3201 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 3222 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
3202 if (_autocreator) { | 3223 if (_autocreator) { |
3203 GPBAutocreatedDictionaryModified(_autocreator, self); | 3224 GPBAutocreatedDictionaryModified(_autocreator, self); |
3204 } | 3225 } |
3205 } | 3226 } |
3206 } | 3227 } |
3207 | 3228 |
3208 - (void)setRawValue:(int32_t)value forKey:(uint32_t)key { | 3229 - (void)setRawValue:(int32_t)value forKey:(uint32_t)key { |
3209 [_dictionary setObject:@(value) forKey:@(key)]; | 3230 [_dictionary setObject:@(value) forKey:@(key)]; |
3210 if (_autocreator) { | 3231 if (_autocreator) { |
3211 GPBAutocreatedDictionaryModified(_autocreator, self); | 3232 GPBAutocreatedDictionaryModified(_autocreator, self); |
3212 } | 3233 } |
3213 } | 3234 } |
3214 | 3235 |
3215 - (void)removeValueForKey:(uint32_t)aKey { | 3236 - (void)removeEnumForKey:(uint32_t)aKey { |
3216 [_dictionary removeObjectForKey:@(aKey)]; | 3237 [_dictionary removeObjectForKey:@(aKey)]; |
3217 } | 3238 } |
3218 | 3239 |
3219 - (void)removeAll { | 3240 - (void)removeAll { |
3220 [_dictionary removeAllObjects]; | 3241 [_dictionary removeAllObjects]; |
3221 } | 3242 } |
3222 | 3243 |
3223 - (void)setValue:(int32_t)value forKey:(uint32_t)key { | 3244 - (void)setEnum:(int32_t)value forKey:(uint32_t)key { |
3224 if (!_validationFunc(value)) { | 3245 if (!_validationFunc(value)) { |
3225 [NSException raise:NSInvalidArgumentException | 3246 [NSException raise:NSInvalidArgumentException |
3226 format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum
value (%d)", | 3247 format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum
value (%d)", |
3227 value]; | 3248 value]; |
3228 } | 3249 } |
3229 | 3250 |
3230 [_dictionary setObject:@(value) forKey:@(key)]; | 3251 [_dictionary setObject:@(value) forKey:@(key)]; |
3231 if (_autocreator) { | 3252 if (_autocreator) { |
3232 GPBAutocreatedDictionaryModified(_autocreator, self); | 3253 GPBAutocreatedDictionaryModified(_autocreator, self); |
3233 } | 3254 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3318 @"%@: Autocreator must be cleared before release, autocreator: %@", | 3339 @"%@: Autocreator must be cleared before release, autocreator: %@", |
3319 [self class], _autocreator); | 3340 [self class], _autocreator); |
3320 [_dictionary release]; | 3341 [_dictionary release]; |
3321 [super dealloc]; | 3342 [super dealloc]; |
3322 } | 3343 } |
3323 | 3344 |
3324 - (instancetype)copyWithZone:(NSZone *)zone { | 3345 - (instancetype)copyWithZone:(NSZone *)zone { |
3325 return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self
]; | 3346 return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self
]; |
3326 } | 3347 } |
3327 | 3348 |
3328 - (BOOL)isEqual:(GPBUInt32ObjectDictionary *)other { | 3349 - (BOOL)isEqual:(id)other { |
3329 if (self == other) { | 3350 if (self == other) { |
3330 return YES; | 3351 return YES; |
3331 } | 3352 } |
3332 if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) { | 3353 if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) { |
3333 return NO; | 3354 return NO; |
3334 } | 3355 } |
3335 return [_dictionary isEqual:other->_dictionary]; | 3356 GPBUInt32ObjectDictionary *otherDictionary = other; |
| 3357 return [_dictionary isEqual:otherDictionary->_dictionary]; |
3336 } | 3358 } |
3337 | 3359 |
3338 - (NSUInteger)hash { | 3360 - (NSUInteger)hash { |
3339 return _dictionary.count; | 3361 return _dictionary.count; |
3340 } | 3362 } |
3341 | 3363 |
3342 - (NSString *)description { | 3364 - (NSString *)description { |
3343 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 3365 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
3344 } | 3366 } |
3345 | 3367 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3473 // This block of code is generated, do not edit it directly. | 3495 // This block of code is generated, do not edit it directly. |
3474 | 3496 |
3475 #pragma mark - Int32 -> UInt32 | 3497 #pragma mark - Int32 -> UInt32 |
3476 | 3498 |
3477 @implementation GPBInt32UInt32Dictionary { | 3499 @implementation GPBInt32UInt32Dictionary { |
3478 @package | 3500 @package |
3479 NSMutableDictionary *_dictionary; | 3501 NSMutableDictionary *_dictionary; |
3480 } | 3502 } |
3481 | 3503 |
3482 + (instancetype)dictionary { | 3504 + (instancetype)dictionary { |
3483 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 3505 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; |
3484 } | 3506 } |
3485 | 3507 |
3486 + (instancetype)dictionaryWithValue:(uint32_t)value | 3508 + (instancetype)dictionaryWithUInt32:(uint32_t)value |
3487 forKey:(int32_t)key { | 3509 forKey:(int32_t)key { |
3488 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 3510 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
3489 // on to get the type correct. | 3511 // on to get the type correct. |
3490 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithValues:&value | 3512 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithUInt32s:&value |
3491 forKeys:&key | 3513 forKeys:&key |
3492 count:1] autorelease
]; | 3514 count:1] autoreleas
e]; |
3493 } | 3515 } |
3494 | 3516 |
3495 + (instancetype)dictionaryWithValues:(const uint32_t [])values | 3517 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values |
3496 forKeys:(const int32_t [])keys | 3518 forKeys:(const int32_t [])keys |
3497 count:(NSUInteger)count { | 3519 count:(NSUInteger)count { |
3498 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 3520 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
3499 // on to get the type correct. | 3521 // on to get the type correct. |
3500 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithValues:values | 3522 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithUInt32s:values |
3501 forKeys:keys | 3523 forKeys:keys |
3502 count:count] autorel
ease]; | 3524 count:count] autorel
ease]; |
3503 } | 3525 } |
3504 | 3526 |
3505 + (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary
{ | 3527 + (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary
{ |
3506 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 3528 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
3507 // on to get the type correct. | 3529 // on to get the type correct. |
3508 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 3530 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
3509 } | 3531 } |
3510 | 3532 |
3511 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 3533 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
3512 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 3534 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
3513 } | 3535 } |
3514 | 3536 |
3515 - (instancetype)init { | 3537 - (instancetype)init { |
3516 return [self initWithValues:NULL forKeys:NULL count:0]; | 3538 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
3517 } | 3539 } |
3518 | 3540 |
3519 - (instancetype)initWithValues:(const uint32_t [])values | 3541 - (instancetype)initWithUInt32s:(const uint32_t [])values |
3520 forKeys:(const int32_t [])keys | 3542 forKeys:(const int32_t [])keys |
3521 count:(NSUInteger)count { | 3543 count:(NSUInteger)count { |
3522 self = [super init]; | 3544 self = [super init]; |
3523 if (self) { | 3545 if (self) { |
3524 _dictionary = [[NSMutableDictionary alloc] init]; | 3546 _dictionary = [[NSMutableDictionary alloc] init]; |
3525 if (count && values && keys) { | 3547 if (count && values && keys) { |
3526 for (NSUInteger i = 0; i < count; ++i) { | 3548 for (NSUInteger i = 0; i < count; ++i) { |
3527 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 3549 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
3528 } | 3550 } |
3529 } | 3551 } |
3530 } | 3552 } |
3531 return self; | 3553 return self; |
3532 } | 3554 } |
3533 | 3555 |
3534 - (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary { | 3556 - (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary { |
3535 self = [self initWithValues:NULL forKeys:NULL count:0]; | 3557 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; |
3536 if (self) { | 3558 if (self) { |
3537 if (dictionary) { | 3559 if (dictionary) { |
3538 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 3560 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
3539 } | 3561 } |
3540 } | 3562 } |
3541 return self; | 3563 return self; |
3542 } | 3564 } |
3543 | 3565 |
3544 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 3566 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
3545 #pragma unused(numItems) | 3567 #pragma unused(numItems) |
3546 return [self initWithValues:NULL forKeys:NULL count:0]; | 3568 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
3547 } | 3569 } |
3548 | 3570 |
3549 - (void)dealloc { | 3571 - (void)dealloc { |
3550 NSAssert(!_autocreator, | 3572 NSAssert(!_autocreator, |
3551 @"%@: Autocreator must be cleared before release, autocreator: %@", | 3573 @"%@: Autocreator must be cleared before release, autocreator: %@", |
3552 [self class], _autocreator); | 3574 [self class], _autocreator); |
3553 [_dictionary release]; | 3575 [_dictionary release]; |
3554 [super dealloc]; | 3576 [super dealloc]; |
3555 } | 3577 } |
3556 | 3578 |
3557 - (instancetype)copyWithZone:(NSZone *)zone { | 3579 - (instancetype)copyWithZone:(NSZone *)zone { |
3558 return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; | 3580 return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; |
3559 } | 3581 } |
3560 | 3582 |
3561 - (BOOL)isEqual:(GPBInt32UInt32Dictionary *)other { | 3583 - (BOOL)isEqual:(id)other { |
3562 if (self == other) { | 3584 if (self == other) { |
3563 return YES; | 3585 return YES; |
3564 } | 3586 } |
3565 if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) { | 3587 if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) { |
3566 return NO; | 3588 return NO; |
3567 } | 3589 } |
3568 return [_dictionary isEqual:other->_dictionary]; | 3590 GPBInt32UInt32Dictionary *otherDictionary = other; |
| 3591 return [_dictionary isEqual:otherDictionary->_dictionary]; |
3569 } | 3592 } |
3570 | 3593 |
3571 - (NSUInteger)hash { | 3594 - (NSUInteger)hash { |
3572 return _dictionary.count; | 3595 return _dictionary.count; |
3573 } | 3596 } |
3574 | 3597 |
3575 - (NSString *)description { | 3598 - (NSString *)description { |
3576 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 3599 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
3577 } | 3600 } |
3578 | 3601 |
3579 - (NSUInteger)count { | 3602 - (NSUInteger)count { |
3580 return _dictionary.count; | 3603 return _dictionary.count; |
3581 } | 3604 } |
3582 | 3605 |
3583 - (void)enumerateKeysAndValuesUsingBlock: | 3606 - (void)enumerateKeysAndUInt32sUsingBlock: |
3584 (void (^)(int32_t key, uint32_t value, BOOL *stop))block { | 3607 (void (^)(int32_t key, uint32_t value, BOOL *stop))block { |
3585 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 3608 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
3586 NSNumber *aValue, | 3609 NSNumber *aValue, |
3587 BOOL *stop) { | 3610 BOOL *stop) { |
3588 block([aKey intValue], [aValue unsignedIntValue], stop); | 3611 block([aKey intValue], [aValue unsignedIntValue], stop); |
3589 }]; | 3612 }]; |
3590 } | 3613 } |
3591 | 3614 |
3592 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 3615 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
3593 NSUInteger count = _dictionary.count; | 3616 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3631 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | 3654 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); |
3632 }]; | 3655 }]; |
3633 } | 3656 } |
3634 | 3657 |
3635 - (void)setGPBGenericValue:(GPBGenericValue *)value | 3658 - (void)setGPBGenericValue:(GPBGenericValue *)value |
3636 forGPBGenericValueKey:(GPBGenericValue *)key { | 3659 forGPBGenericValueKey:(GPBGenericValue *)key { |
3637 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)]; | 3660 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)]; |
3638 } | 3661 } |
3639 | 3662 |
3640 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 3663 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
3641 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, uint32_t value, BOOL *st
op) { | 3664 [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, BOOL *s
top) { |
3642 #pragma unused(stop) | 3665 #pragma unused(stop) |
3643 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%u", value]); | 3666 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%u", value]); |
3644 }]; | 3667 }]; |
3645 } | 3668 } |
3646 | 3669 |
3647 - (BOOL)valueForKey:(int32_t)key value:(uint32_t *)value { | 3670 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key { |
3648 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 3671 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
3649 if (wrapped && value) { | 3672 if (wrapped && value) { |
3650 *value = [wrapped unsignedIntValue]; | 3673 *value = [wrapped unsignedIntValue]; |
3651 } | 3674 } |
3652 return (wrapped != NULL); | 3675 return (wrapped != NULL); |
3653 } | 3676 } |
3654 | 3677 |
3655 - (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary { | 3678 - (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary { |
3656 if (otherDictionary) { | 3679 if (otherDictionary) { |
3657 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 3680 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
3658 if (_autocreator) { | 3681 if (_autocreator) { |
3659 GPBAutocreatedDictionaryModified(_autocreator, self); | 3682 GPBAutocreatedDictionaryModified(_autocreator, self); |
3660 } | 3683 } |
3661 } | 3684 } |
3662 } | 3685 } |
3663 | 3686 |
3664 - (void)setValue:(uint32_t)value forKey:(int32_t)key { | 3687 - (void)setUInt32:(uint32_t)value forKey:(int32_t)key { |
3665 [_dictionary setObject:@(value) forKey:@(key)]; | 3688 [_dictionary setObject:@(value) forKey:@(key)]; |
3666 if (_autocreator) { | 3689 if (_autocreator) { |
3667 GPBAutocreatedDictionaryModified(_autocreator, self); | 3690 GPBAutocreatedDictionaryModified(_autocreator, self); |
3668 } | 3691 } |
3669 } | 3692 } |
3670 | 3693 |
3671 - (void)removeValueForKey:(int32_t)aKey { | 3694 - (void)removeUInt32ForKey:(int32_t)aKey { |
3672 [_dictionary removeObjectForKey:@(aKey)]; | 3695 [_dictionary removeObjectForKey:@(aKey)]; |
3673 } | 3696 } |
3674 | 3697 |
3675 - (void)removeAll { | 3698 - (void)removeAll { |
3676 [_dictionary removeAllObjects]; | 3699 [_dictionary removeAllObjects]; |
3677 } | 3700 } |
3678 | 3701 |
3679 @end | 3702 @end |
3680 | 3703 |
3681 #pragma mark - Int32 -> Int32 | 3704 #pragma mark - Int32 -> Int32 |
3682 | 3705 |
3683 @implementation GPBInt32Int32Dictionary { | 3706 @implementation GPBInt32Int32Dictionary { |
3684 @package | 3707 @package |
3685 NSMutableDictionary *_dictionary; | 3708 NSMutableDictionary *_dictionary; |
3686 } | 3709 } |
3687 | 3710 |
3688 + (instancetype)dictionary { | 3711 + (instancetype)dictionary { |
3689 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 3712 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; |
3690 } | 3713 } |
3691 | 3714 |
3692 + (instancetype)dictionaryWithValue:(int32_t)value | 3715 + (instancetype)dictionaryWithInt32:(int32_t)value |
3693 forKey:(int32_t)key { | 3716 forKey:(int32_t)key { |
3694 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 3717 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
3695 // on to get the type correct. | 3718 // on to get the type correct. |
3696 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithValues:&value | 3719 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithInt32s:&value |
3697 forKeys:&key | 3720 forKeys:&key |
3698 count:1] autorelease]
; | 3721 count:1] autorelease]
; |
3699 } | 3722 } |
3700 | 3723 |
3701 + (instancetype)dictionaryWithValues:(const int32_t [])values | 3724 + (instancetype)dictionaryWithInt32s:(const int32_t [])values |
3702 forKeys:(const int32_t [])keys | 3725 forKeys:(const int32_t [])keys |
3703 count:(NSUInteger)count { | 3726 count:(NSUInteger)count { |
3704 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 3727 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
3705 // on to get the type correct. | 3728 // on to get the type correct. |
3706 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithValues:values | 3729 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithInt32s:values |
3707 forKeys:keys | 3730 forKeys:keys |
3708 count:count] autorele
ase]; | 3731 count:count] autorele
ase]; |
3709 } | 3732 } |
3710 | 3733 |
3711 + (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary { | 3734 + (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary { |
3712 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 3735 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
3713 // on to get the type correct. | 3736 // on to get the type correct. |
3714 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 3737 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
3715 } | 3738 } |
3716 | 3739 |
3717 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 3740 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
3718 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 3741 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
3719 } | 3742 } |
3720 | 3743 |
3721 - (instancetype)init { | 3744 - (instancetype)init { |
3722 return [self initWithValues:NULL forKeys:NULL count:0]; | 3745 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
3723 } | 3746 } |
3724 | 3747 |
3725 - (instancetype)initWithValues:(const int32_t [])values | 3748 - (instancetype)initWithInt32s:(const int32_t [])values |
3726 forKeys:(const int32_t [])keys | 3749 forKeys:(const int32_t [])keys |
3727 count:(NSUInteger)count { | 3750 count:(NSUInteger)count { |
3728 self = [super init]; | 3751 self = [super init]; |
3729 if (self) { | 3752 if (self) { |
3730 _dictionary = [[NSMutableDictionary alloc] init]; | 3753 _dictionary = [[NSMutableDictionary alloc] init]; |
3731 if (count && values && keys) { | 3754 if (count && values && keys) { |
3732 for (NSUInteger i = 0; i < count; ++i) { | 3755 for (NSUInteger i = 0; i < count; ++i) { |
3733 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 3756 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
3734 } | 3757 } |
3735 } | 3758 } |
3736 } | 3759 } |
3737 return self; | 3760 return self; |
3738 } | 3761 } |
3739 | 3762 |
3740 - (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary { | 3763 - (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary { |
3741 self = [self initWithValues:NULL forKeys:NULL count:0]; | 3764 self = [self initWithInt32s:NULL forKeys:NULL count:0]; |
3742 if (self) { | 3765 if (self) { |
3743 if (dictionary) { | 3766 if (dictionary) { |
3744 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 3767 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
3745 } | 3768 } |
3746 } | 3769 } |
3747 return self; | 3770 return self; |
3748 } | 3771 } |
3749 | 3772 |
3750 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 3773 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
3751 #pragma unused(numItems) | 3774 #pragma unused(numItems) |
3752 return [self initWithValues:NULL forKeys:NULL count:0]; | 3775 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
3753 } | 3776 } |
3754 | 3777 |
3755 - (void)dealloc { | 3778 - (void)dealloc { |
3756 NSAssert(!_autocreator, | 3779 NSAssert(!_autocreator, |
3757 @"%@: Autocreator must be cleared before release, autocreator: %@", | 3780 @"%@: Autocreator must be cleared before release, autocreator: %@", |
3758 [self class], _autocreator); | 3781 [self class], _autocreator); |
3759 [_dictionary release]; | 3782 [_dictionary release]; |
3760 [super dealloc]; | 3783 [super dealloc]; |
3761 } | 3784 } |
3762 | 3785 |
3763 - (instancetype)copyWithZone:(NSZone *)zone { | 3786 - (instancetype)copyWithZone:(NSZone *)zone { |
3764 return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]; | 3787 return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]; |
3765 } | 3788 } |
3766 | 3789 |
3767 - (BOOL)isEqual:(GPBInt32Int32Dictionary *)other { | 3790 - (BOOL)isEqual:(id)other { |
3768 if (self == other) { | 3791 if (self == other) { |
3769 return YES; | 3792 return YES; |
3770 } | 3793 } |
3771 if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) { | 3794 if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) { |
3772 return NO; | 3795 return NO; |
3773 } | 3796 } |
3774 return [_dictionary isEqual:other->_dictionary]; | 3797 GPBInt32Int32Dictionary *otherDictionary = other; |
| 3798 return [_dictionary isEqual:otherDictionary->_dictionary]; |
3775 } | 3799 } |
3776 | 3800 |
3777 - (NSUInteger)hash { | 3801 - (NSUInteger)hash { |
3778 return _dictionary.count; | 3802 return _dictionary.count; |
3779 } | 3803 } |
3780 | 3804 |
3781 - (NSString *)description { | 3805 - (NSString *)description { |
3782 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 3806 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
3783 } | 3807 } |
3784 | 3808 |
3785 - (NSUInteger)count { | 3809 - (NSUInteger)count { |
3786 return _dictionary.count; | 3810 return _dictionary.count; |
3787 } | 3811 } |
3788 | 3812 |
3789 - (void)enumerateKeysAndValuesUsingBlock: | 3813 - (void)enumerateKeysAndInt32sUsingBlock: |
3790 (void (^)(int32_t key, int32_t value, BOOL *stop))block { | 3814 (void (^)(int32_t key, int32_t value, BOOL *stop))block { |
3791 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 3815 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
3792 NSNumber *aValue, | 3816 NSNumber *aValue, |
3793 BOOL *stop) { | 3817 BOOL *stop) { |
3794 block([aKey intValue], [aValue intValue], stop); | 3818 block([aKey intValue], [aValue intValue], stop); |
3795 }]; | 3819 }]; |
3796 } | 3820 } |
3797 | 3821 |
3798 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 3822 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
3799 NSUInteger count = _dictionary.count; | 3823 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3837 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | 3861 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); |
3838 }]; | 3862 }]; |
3839 } | 3863 } |
3840 | 3864 |
3841 - (void)setGPBGenericValue:(GPBGenericValue *)value | 3865 - (void)setGPBGenericValue:(GPBGenericValue *)value |
3842 forGPBGenericValueKey:(GPBGenericValue *)key { | 3866 forGPBGenericValueKey:(GPBGenericValue *)key { |
3843 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)]; | 3867 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)]; |
3844 } | 3868 } |
3845 | 3869 |
3846 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 3870 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
3847 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, int32_t value, BOOL *sto
p) { | 3871 [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, BOOL *sto
p) { |
3848 #pragma unused(stop) | 3872 #pragma unused(stop) |
3849 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%d", value]); | 3873 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%d", value]); |
3850 }]; | 3874 }]; |
3851 } | 3875 } |
3852 | 3876 |
3853 - (BOOL)valueForKey:(int32_t)key value:(int32_t *)value { | 3877 - (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key { |
3854 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 3878 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
3855 if (wrapped && value) { | 3879 if (wrapped && value) { |
3856 *value = [wrapped intValue]; | 3880 *value = [wrapped intValue]; |
3857 } | 3881 } |
3858 return (wrapped != NULL); | 3882 return (wrapped != NULL); |
3859 } | 3883 } |
3860 | 3884 |
3861 - (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary { | 3885 - (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary { |
3862 if (otherDictionary) { | 3886 if (otherDictionary) { |
3863 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 3887 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
3864 if (_autocreator) { | 3888 if (_autocreator) { |
3865 GPBAutocreatedDictionaryModified(_autocreator, self); | 3889 GPBAutocreatedDictionaryModified(_autocreator, self); |
3866 } | 3890 } |
3867 } | 3891 } |
3868 } | 3892 } |
3869 | 3893 |
3870 - (void)setValue:(int32_t)value forKey:(int32_t)key { | 3894 - (void)setInt32:(int32_t)value forKey:(int32_t)key { |
3871 [_dictionary setObject:@(value) forKey:@(key)]; | 3895 [_dictionary setObject:@(value) forKey:@(key)]; |
3872 if (_autocreator) { | 3896 if (_autocreator) { |
3873 GPBAutocreatedDictionaryModified(_autocreator, self); | 3897 GPBAutocreatedDictionaryModified(_autocreator, self); |
3874 } | 3898 } |
3875 } | 3899 } |
3876 | 3900 |
3877 - (void)removeValueForKey:(int32_t)aKey { | 3901 - (void)removeInt32ForKey:(int32_t)aKey { |
3878 [_dictionary removeObjectForKey:@(aKey)]; | 3902 [_dictionary removeObjectForKey:@(aKey)]; |
3879 } | 3903 } |
3880 | 3904 |
3881 - (void)removeAll { | 3905 - (void)removeAll { |
3882 [_dictionary removeAllObjects]; | 3906 [_dictionary removeAllObjects]; |
3883 } | 3907 } |
3884 | 3908 |
3885 @end | 3909 @end |
3886 | 3910 |
3887 #pragma mark - Int32 -> UInt64 | 3911 #pragma mark - Int32 -> UInt64 |
3888 | 3912 |
3889 @implementation GPBInt32UInt64Dictionary { | 3913 @implementation GPBInt32UInt64Dictionary { |
3890 @package | 3914 @package |
3891 NSMutableDictionary *_dictionary; | 3915 NSMutableDictionary *_dictionary; |
3892 } | 3916 } |
3893 | 3917 |
3894 + (instancetype)dictionary { | 3918 + (instancetype)dictionary { |
3895 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 3919 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; |
3896 } | 3920 } |
3897 | 3921 |
3898 + (instancetype)dictionaryWithValue:(uint64_t)value | 3922 + (instancetype)dictionaryWithUInt64:(uint64_t)value |
3899 forKey:(int32_t)key { | 3923 forKey:(int32_t)key { |
3900 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 3924 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
3901 // on to get the type correct. | 3925 // on to get the type correct. |
3902 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithValues:&value | 3926 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithUInt64s:&value |
3903 forKeys:&key | 3927 forKeys:&key |
3904 count:1] autorelease
]; | 3928 count:1] autoreleas
e]; |
3905 } | 3929 } |
3906 | 3930 |
3907 + (instancetype)dictionaryWithValues:(const uint64_t [])values | 3931 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values |
3908 forKeys:(const int32_t [])keys | 3932 forKeys:(const int32_t [])keys |
3909 count:(NSUInteger)count { | 3933 count:(NSUInteger)count { |
3910 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 3934 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
3911 // on to get the type correct. | 3935 // on to get the type correct. |
3912 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithValues:values | 3936 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithUInt64s:values |
3913 forKeys:keys | 3937 forKeys:keys |
3914 count:count] autorel
ease]; | 3938 count:count] autorel
ease]; |
3915 } | 3939 } |
3916 | 3940 |
3917 + (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary
{ | 3941 + (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary
{ |
3918 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 3942 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
3919 // on to get the type correct. | 3943 // on to get the type correct. |
3920 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 3944 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
3921 } | 3945 } |
3922 | 3946 |
3923 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 3947 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
3924 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 3948 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
3925 } | 3949 } |
3926 | 3950 |
3927 - (instancetype)init { | 3951 - (instancetype)init { |
3928 return [self initWithValues:NULL forKeys:NULL count:0]; | 3952 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
3929 } | 3953 } |
3930 | 3954 |
3931 - (instancetype)initWithValues:(const uint64_t [])values | 3955 - (instancetype)initWithUInt64s:(const uint64_t [])values |
3932 forKeys:(const int32_t [])keys | 3956 forKeys:(const int32_t [])keys |
3933 count:(NSUInteger)count { | 3957 count:(NSUInteger)count { |
3934 self = [super init]; | 3958 self = [super init]; |
3935 if (self) { | 3959 if (self) { |
3936 _dictionary = [[NSMutableDictionary alloc] init]; | 3960 _dictionary = [[NSMutableDictionary alloc] init]; |
3937 if (count && values && keys) { | 3961 if (count && values && keys) { |
3938 for (NSUInteger i = 0; i < count; ++i) { | 3962 for (NSUInteger i = 0; i < count; ++i) { |
3939 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 3963 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
3940 } | 3964 } |
3941 } | 3965 } |
3942 } | 3966 } |
3943 return self; | 3967 return self; |
3944 } | 3968 } |
3945 | 3969 |
3946 - (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary { | 3970 - (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary { |
3947 self = [self initWithValues:NULL forKeys:NULL count:0]; | 3971 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; |
3948 if (self) { | 3972 if (self) { |
3949 if (dictionary) { | 3973 if (dictionary) { |
3950 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 3974 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
3951 } | 3975 } |
3952 } | 3976 } |
3953 return self; | 3977 return self; |
3954 } | 3978 } |
3955 | 3979 |
3956 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 3980 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
3957 #pragma unused(numItems) | 3981 #pragma unused(numItems) |
3958 return [self initWithValues:NULL forKeys:NULL count:0]; | 3982 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
3959 } | 3983 } |
3960 | 3984 |
3961 - (void)dealloc { | 3985 - (void)dealloc { |
3962 NSAssert(!_autocreator, | 3986 NSAssert(!_autocreator, |
3963 @"%@: Autocreator must be cleared before release, autocreator: %@", | 3987 @"%@: Autocreator must be cleared before release, autocreator: %@", |
3964 [self class], _autocreator); | 3988 [self class], _autocreator); |
3965 [_dictionary release]; | 3989 [_dictionary release]; |
3966 [super dealloc]; | 3990 [super dealloc]; |
3967 } | 3991 } |
3968 | 3992 |
3969 - (instancetype)copyWithZone:(NSZone *)zone { | 3993 - (instancetype)copyWithZone:(NSZone *)zone { |
3970 return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; | 3994 return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; |
3971 } | 3995 } |
3972 | 3996 |
3973 - (BOOL)isEqual:(GPBInt32UInt64Dictionary *)other { | 3997 - (BOOL)isEqual:(id)other { |
3974 if (self == other) { | 3998 if (self == other) { |
3975 return YES; | 3999 return YES; |
3976 } | 4000 } |
3977 if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) { | 4001 if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) { |
3978 return NO; | 4002 return NO; |
3979 } | 4003 } |
3980 return [_dictionary isEqual:other->_dictionary]; | 4004 GPBInt32UInt64Dictionary *otherDictionary = other; |
| 4005 return [_dictionary isEqual:otherDictionary->_dictionary]; |
3981 } | 4006 } |
3982 | 4007 |
3983 - (NSUInteger)hash { | 4008 - (NSUInteger)hash { |
3984 return _dictionary.count; | 4009 return _dictionary.count; |
3985 } | 4010 } |
3986 | 4011 |
3987 - (NSString *)description { | 4012 - (NSString *)description { |
3988 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 4013 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
3989 } | 4014 } |
3990 | 4015 |
3991 - (NSUInteger)count { | 4016 - (NSUInteger)count { |
3992 return _dictionary.count; | 4017 return _dictionary.count; |
3993 } | 4018 } |
3994 | 4019 |
3995 - (void)enumerateKeysAndValuesUsingBlock: | 4020 - (void)enumerateKeysAndUInt64sUsingBlock: |
3996 (void (^)(int32_t key, uint64_t value, BOOL *stop))block { | 4021 (void (^)(int32_t key, uint64_t value, BOOL *stop))block { |
3997 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 4022 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
3998 NSNumber *aValue, | 4023 NSNumber *aValue, |
3999 BOOL *stop) { | 4024 BOOL *stop) { |
4000 block([aKey intValue], [aValue unsignedLongLongValue], stop); | 4025 block([aKey intValue], [aValue unsignedLongLongValue], stop); |
4001 }]; | 4026 }]; |
4002 } | 4027 } |
4003 | 4028 |
4004 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 4029 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
4005 NSUInteger count = _dictionary.count; | 4030 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4043 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | 4068 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); |
4044 }]; | 4069 }]; |
4045 } | 4070 } |
4046 | 4071 |
4047 - (void)setGPBGenericValue:(GPBGenericValue *)value | 4072 - (void)setGPBGenericValue:(GPBGenericValue *)value |
4048 forGPBGenericValueKey:(GPBGenericValue *)key { | 4073 forGPBGenericValueKey:(GPBGenericValue *)key { |
4049 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)]; | 4074 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)]; |
4050 } | 4075 } |
4051 | 4076 |
4052 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 4077 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
4053 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, uint64_t value, BOOL *st
op) { | 4078 [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, BOOL *s
top) { |
4054 #pragma unused(stop) | 4079 #pragma unused(stop) |
4055 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%llu", value]); | 4080 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%llu", value]); |
4056 }]; | 4081 }]; |
4057 } | 4082 } |
4058 | 4083 |
4059 - (BOOL)valueForKey:(int32_t)key value:(uint64_t *)value { | 4084 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key { |
4060 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 4085 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
4061 if (wrapped && value) { | 4086 if (wrapped && value) { |
4062 *value = [wrapped unsignedLongLongValue]; | 4087 *value = [wrapped unsignedLongLongValue]; |
4063 } | 4088 } |
4064 return (wrapped != NULL); | 4089 return (wrapped != NULL); |
4065 } | 4090 } |
4066 | 4091 |
4067 - (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary { | 4092 - (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary { |
4068 if (otherDictionary) { | 4093 if (otherDictionary) { |
4069 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 4094 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
4070 if (_autocreator) { | 4095 if (_autocreator) { |
4071 GPBAutocreatedDictionaryModified(_autocreator, self); | 4096 GPBAutocreatedDictionaryModified(_autocreator, self); |
4072 } | 4097 } |
4073 } | 4098 } |
4074 } | 4099 } |
4075 | 4100 |
4076 - (void)setValue:(uint64_t)value forKey:(int32_t)key { | 4101 - (void)setUInt64:(uint64_t)value forKey:(int32_t)key { |
4077 [_dictionary setObject:@(value) forKey:@(key)]; | 4102 [_dictionary setObject:@(value) forKey:@(key)]; |
4078 if (_autocreator) { | 4103 if (_autocreator) { |
4079 GPBAutocreatedDictionaryModified(_autocreator, self); | 4104 GPBAutocreatedDictionaryModified(_autocreator, self); |
4080 } | 4105 } |
4081 } | 4106 } |
4082 | 4107 |
4083 - (void)removeValueForKey:(int32_t)aKey { | 4108 - (void)removeUInt64ForKey:(int32_t)aKey { |
4084 [_dictionary removeObjectForKey:@(aKey)]; | 4109 [_dictionary removeObjectForKey:@(aKey)]; |
4085 } | 4110 } |
4086 | 4111 |
4087 - (void)removeAll { | 4112 - (void)removeAll { |
4088 [_dictionary removeAllObjects]; | 4113 [_dictionary removeAllObjects]; |
4089 } | 4114 } |
4090 | 4115 |
4091 @end | 4116 @end |
4092 | 4117 |
4093 #pragma mark - Int32 -> Int64 | 4118 #pragma mark - Int32 -> Int64 |
4094 | 4119 |
4095 @implementation GPBInt32Int64Dictionary { | 4120 @implementation GPBInt32Int64Dictionary { |
4096 @package | 4121 @package |
4097 NSMutableDictionary *_dictionary; | 4122 NSMutableDictionary *_dictionary; |
4098 } | 4123 } |
4099 | 4124 |
4100 + (instancetype)dictionary { | 4125 + (instancetype)dictionary { |
4101 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 4126 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; |
4102 } | 4127 } |
4103 | 4128 |
4104 + (instancetype)dictionaryWithValue:(int64_t)value | 4129 + (instancetype)dictionaryWithInt64:(int64_t)value |
4105 forKey:(int32_t)key { | 4130 forKey:(int32_t)key { |
4106 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 4131 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
4107 // on to get the type correct. | 4132 // on to get the type correct. |
4108 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithValues:&value | 4133 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithInt64s:&value |
4109 forKeys:&key | 4134 forKeys:&key |
4110 count:1] autorelease]
; | 4135 count:1] autorelease]
; |
4111 } | 4136 } |
4112 | 4137 |
4113 + (instancetype)dictionaryWithValues:(const int64_t [])values | 4138 + (instancetype)dictionaryWithInt64s:(const int64_t [])values |
4114 forKeys:(const int32_t [])keys | 4139 forKeys:(const int32_t [])keys |
4115 count:(NSUInteger)count { | 4140 count:(NSUInteger)count { |
4116 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 4141 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
4117 // on to get the type correct. | 4142 // on to get the type correct. |
4118 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithValues:values | 4143 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithInt64s:values |
4119 forKeys:keys | 4144 forKeys:keys |
4120 count:count] autorele
ase]; | 4145 count:count] autorele
ase]; |
4121 } | 4146 } |
4122 | 4147 |
4123 + (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary { | 4148 + (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary { |
4124 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 4149 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
4125 // on to get the type correct. | 4150 // on to get the type correct. |
4126 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 4151 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
4127 } | 4152 } |
4128 | 4153 |
4129 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 4154 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
4130 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 4155 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
4131 } | 4156 } |
4132 | 4157 |
4133 - (instancetype)init { | 4158 - (instancetype)init { |
4134 return [self initWithValues:NULL forKeys:NULL count:0]; | 4159 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
4135 } | 4160 } |
4136 | 4161 |
4137 - (instancetype)initWithValues:(const int64_t [])values | 4162 - (instancetype)initWithInt64s:(const int64_t [])values |
4138 forKeys:(const int32_t [])keys | 4163 forKeys:(const int32_t [])keys |
4139 count:(NSUInteger)count { | 4164 count:(NSUInteger)count { |
4140 self = [super init]; | 4165 self = [super init]; |
4141 if (self) { | 4166 if (self) { |
4142 _dictionary = [[NSMutableDictionary alloc] init]; | 4167 _dictionary = [[NSMutableDictionary alloc] init]; |
4143 if (count && values && keys) { | 4168 if (count && values && keys) { |
4144 for (NSUInteger i = 0; i < count; ++i) { | 4169 for (NSUInteger i = 0; i < count; ++i) { |
4145 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 4170 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
4146 } | 4171 } |
4147 } | 4172 } |
4148 } | 4173 } |
4149 return self; | 4174 return self; |
4150 } | 4175 } |
4151 | 4176 |
4152 - (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary { | 4177 - (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary { |
4153 self = [self initWithValues:NULL forKeys:NULL count:0]; | 4178 self = [self initWithInt64s:NULL forKeys:NULL count:0]; |
4154 if (self) { | 4179 if (self) { |
4155 if (dictionary) { | 4180 if (dictionary) { |
4156 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 4181 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
4157 } | 4182 } |
4158 } | 4183 } |
4159 return self; | 4184 return self; |
4160 } | 4185 } |
4161 | 4186 |
4162 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 4187 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
4163 #pragma unused(numItems) | 4188 #pragma unused(numItems) |
4164 return [self initWithValues:NULL forKeys:NULL count:0]; | 4189 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
4165 } | 4190 } |
4166 | 4191 |
4167 - (void)dealloc { | 4192 - (void)dealloc { |
4168 NSAssert(!_autocreator, | 4193 NSAssert(!_autocreator, |
4169 @"%@: Autocreator must be cleared before release, autocreator: %@", | 4194 @"%@: Autocreator must be cleared before release, autocreator: %@", |
4170 [self class], _autocreator); | 4195 [self class], _autocreator); |
4171 [_dictionary release]; | 4196 [_dictionary release]; |
4172 [super dealloc]; | 4197 [super dealloc]; |
4173 } | 4198 } |
4174 | 4199 |
4175 - (instancetype)copyWithZone:(NSZone *)zone { | 4200 - (instancetype)copyWithZone:(NSZone *)zone { |
4176 return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]; | 4201 return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]; |
4177 } | 4202 } |
4178 | 4203 |
4179 - (BOOL)isEqual:(GPBInt32Int64Dictionary *)other { | 4204 - (BOOL)isEqual:(id)other { |
4180 if (self == other) { | 4205 if (self == other) { |
4181 return YES; | 4206 return YES; |
4182 } | 4207 } |
4183 if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) { | 4208 if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) { |
4184 return NO; | 4209 return NO; |
4185 } | 4210 } |
4186 return [_dictionary isEqual:other->_dictionary]; | 4211 GPBInt32Int64Dictionary *otherDictionary = other; |
| 4212 return [_dictionary isEqual:otherDictionary->_dictionary]; |
4187 } | 4213 } |
4188 | 4214 |
4189 - (NSUInteger)hash { | 4215 - (NSUInteger)hash { |
4190 return _dictionary.count; | 4216 return _dictionary.count; |
4191 } | 4217 } |
4192 | 4218 |
4193 - (NSString *)description { | 4219 - (NSString *)description { |
4194 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 4220 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
4195 } | 4221 } |
4196 | 4222 |
4197 - (NSUInteger)count { | 4223 - (NSUInteger)count { |
4198 return _dictionary.count; | 4224 return _dictionary.count; |
4199 } | 4225 } |
4200 | 4226 |
4201 - (void)enumerateKeysAndValuesUsingBlock: | 4227 - (void)enumerateKeysAndInt64sUsingBlock: |
4202 (void (^)(int32_t key, int64_t value, BOOL *stop))block { | 4228 (void (^)(int32_t key, int64_t value, BOOL *stop))block { |
4203 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 4229 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
4204 NSNumber *aValue, | 4230 NSNumber *aValue, |
4205 BOOL *stop) { | 4231 BOOL *stop) { |
4206 block([aKey intValue], [aValue longLongValue], stop); | 4232 block([aKey intValue], [aValue longLongValue], stop); |
4207 }]; | 4233 }]; |
4208 } | 4234 } |
4209 | 4235 |
4210 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 4236 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
4211 NSUInteger count = _dictionary.count; | 4237 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4249 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | 4275 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); |
4250 }]; | 4276 }]; |
4251 } | 4277 } |
4252 | 4278 |
4253 - (void)setGPBGenericValue:(GPBGenericValue *)value | 4279 - (void)setGPBGenericValue:(GPBGenericValue *)value |
4254 forGPBGenericValueKey:(GPBGenericValue *)key { | 4280 forGPBGenericValueKey:(GPBGenericValue *)key { |
4255 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)]; | 4281 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)]; |
4256 } | 4282 } |
4257 | 4283 |
4258 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 4284 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
4259 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, int64_t value, BOOL *sto
p) { | 4285 [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, BOOL *sto
p) { |
4260 #pragma unused(stop) | 4286 #pragma unused(stop) |
4261 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%lld", value]); | 4287 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%lld", value]); |
4262 }]; | 4288 }]; |
4263 } | 4289 } |
4264 | 4290 |
4265 - (BOOL)valueForKey:(int32_t)key value:(int64_t *)value { | 4291 - (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key { |
4266 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 4292 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
4267 if (wrapped && value) { | 4293 if (wrapped && value) { |
4268 *value = [wrapped longLongValue]; | 4294 *value = [wrapped longLongValue]; |
4269 } | 4295 } |
4270 return (wrapped != NULL); | 4296 return (wrapped != NULL); |
4271 } | 4297 } |
4272 | 4298 |
4273 - (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary { | 4299 - (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary { |
4274 if (otherDictionary) { | 4300 if (otherDictionary) { |
4275 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 4301 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
4276 if (_autocreator) { | 4302 if (_autocreator) { |
4277 GPBAutocreatedDictionaryModified(_autocreator, self); | 4303 GPBAutocreatedDictionaryModified(_autocreator, self); |
4278 } | 4304 } |
4279 } | 4305 } |
4280 } | 4306 } |
4281 | 4307 |
4282 - (void)setValue:(int64_t)value forKey:(int32_t)key { | 4308 - (void)setInt64:(int64_t)value forKey:(int32_t)key { |
4283 [_dictionary setObject:@(value) forKey:@(key)]; | 4309 [_dictionary setObject:@(value) forKey:@(key)]; |
4284 if (_autocreator) { | 4310 if (_autocreator) { |
4285 GPBAutocreatedDictionaryModified(_autocreator, self); | 4311 GPBAutocreatedDictionaryModified(_autocreator, self); |
4286 } | 4312 } |
4287 } | 4313 } |
4288 | 4314 |
4289 - (void)removeValueForKey:(int32_t)aKey { | 4315 - (void)removeInt64ForKey:(int32_t)aKey { |
4290 [_dictionary removeObjectForKey:@(aKey)]; | 4316 [_dictionary removeObjectForKey:@(aKey)]; |
4291 } | 4317 } |
4292 | 4318 |
4293 - (void)removeAll { | 4319 - (void)removeAll { |
4294 [_dictionary removeAllObjects]; | 4320 [_dictionary removeAllObjects]; |
4295 } | 4321 } |
4296 | 4322 |
4297 @end | 4323 @end |
4298 | 4324 |
4299 #pragma mark - Int32 -> Bool | 4325 #pragma mark - Int32 -> Bool |
4300 | 4326 |
4301 @implementation GPBInt32BoolDictionary { | 4327 @implementation GPBInt32BoolDictionary { |
4302 @package | 4328 @package |
4303 NSMutableDictionary *_dictionary; | 4329 NSMutableDictionary *_dictionary; |
4304 } | 4330 } |
4305 | 4331 |
4306 + (instancetype)dictionary { | 4332 + (instancetype)dictionary { |
4307 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 4333 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; |
4308 } | 4334 } |
4309 | 4335 |
4310 + (instancetype)dictionaryWithValue:(BOOL)value | 4336 + (instancetype)dictionaryWithBool:(BOOL)value |
4311 forKey:(int32_t)key { | 4337 forKey:(int32_t)key { |
4312 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 4338 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
4313 // on to get the type correct. | 4339 // on to get the type correct. |
4314 return [[(GPBInt32BoolDictionary*)[self alloc] initWithValues:&value | 4340 return [[(GPBInt32BoolDictionary*)[self alloc] initWithBools:&value |
4315 forKeys:&key | 4341 forKeys:&key |
4316 count:1] autorelease]; | 4342 count:1] autorelease]; |
4317 } | 4343 } |
4318 | 4344 |
4319 + (instancetype)dictionaryWithValues:(const BOOL [])values | 4345 + (instancetype)dictionaryWithBools:(const BOOL [])values |
4320 forKeys:(const int32_t [])keys | 4346 forKeys:(const int32_t [])keys |
4321 count:(NSUInteger)count { | 4347 count:(NSUInteger)count { |
4322 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 4348 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
4323 // on to get the type correct. | 4349 // on to get the type correct. |
4324 return [[(GPBInt32BoolDictionary*)[self alloc] initWithValues:values | 4350 return [[(GPBInt32BoolDictionary*)[self alloc] initWithBools:values |
4325 forKeys:keys | 4351 forKeys:keys |
4326 count:count] autorelea
se]; | 4352 count:count] autorelea
se]; |
4327 } | 4353 } |
4328 | 4354 |
4329 + (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary { | 4355 + (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary { |
4330 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 4356 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
4331 // on to get the type correct. | 4357 // on to get the type correct. |
4332 return [[(GPBInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 4358 return [[(GPBInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
4333 } | 4359 } |
4334 | 4360 |
4335 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 4361 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
4336 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 4362 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
4337 } | 4363 } |
4338 | 4364 |
4339 - (instancetype)init { | 4365 - (instancetype)init { |
4340 return [self initWithValues:NULL forKeys:NULL count:0]; | 4366 return [self initWithBools:NULL forKeys:NULL count:0]; |
4341 } | 4367 } |
4342 | 4368 |
4343 - (instancetype)initWithValues:(const BOOL [])values | 4369 - (instancetype)initWithBools:(const BOOL [])values |
4344 forKeys:(const int32_t [])keys | 4370 forKeys:(const int32_t [])keys |
4345 count:(NSUInteger)count { | 4371 count:(NSUInteger)count { |
4346 self = [super init]; | 4372 self = [super init]; |
4347 if (self) { | 4373 if (self) { |
4348 _dictionary = [[NSMutableDictionary alloc] init]; | 4374 _dictionary = [[NSMutableDictionary alloc] init]; |
4349 if (count && values && keys) { | 4375 if (count && values && keys) { |
4350 for (NSUInteger i = 0; i < count; ++i) { | 4376 for (NSUInteger i = 0; i < count; ++i) { |
4351 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 4377 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
4352 } | 4378 } |
4353 } | 4379 } |
4354 } | 4380 } |
4355 return self; | 4381 return self; |
4356 } | 4382 } |
4357 | 4383 |
4358 - (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary { | 4384 - (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary { |
4359 self = [self initWithValues:NULL forKeys:NULL count:0]; | 4385 self = [self initWithBools:NULL forKeys:NULL count:0]; |
4360 if (self) { | 4386 if (self) { |
4361 if (dictionary) { | 4387 if (dictionary) { |
4362 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 4388 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
4363 } | 4389 } |
4364 } | 4390 } |
4365 return self; | 4391 return self; |
4366 } | 4392 } |
4367 | 4393 |
4368 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 4394 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
4369 #pragma unused(numItems) | 4395 #pragma unused(numItems) |
4370 return [self initWithValues:NULL forKeys:NULL count:0]; | 4396 return [self initWithBools:NULL forKeys:NULL count:0]; |
4371 } | 4397 } |
4372 | 4398 |
4373 - (void)dealloc { | 4399 - (void)dealloc { |
4374 NSAssert(!_autocreator, | 4400 NSAssert(!_autocreator, |
4375 @"%@: Autocreator must be cleared before release, autocreator: %@", | 4401 @"%@: Autocreator must be cleared before release, autocreator: %@", |
4376 [self class], _autocreator); | 4402 [self class], _autocreator); |
4377 [_dictionary release]; | 4403 [_dictionary release]; |
4378 [super dealloc]; | 4404 [super dealloc]; |
4379 } | 4405 } |
4380 | 4406 |
4381 - (instancetype)copyWithZone:(NSZone *)zone { | 4407 - (instancetype)copyWithZone:(NSZone *)zone { |
4382 return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; | 4408 return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; |
4383 } | 4409 } |
4384 | 4410 |
4385 - (BOOL)isEqual:(GPBInt32BoolDictionary *)other { | 4411 - (BOOL)isEqual:(id)other { |
4386 if (self == other) { | 4412 if (self == other) { |
4387 return YES; | 4413 return YES; |
4388 } | 4414 } |
4389 if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) { | 4415 if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) { |
4390 return NO; | 4416 return NO; |
4391 } | 4417 } |
4392 return [_dictionary isEqual:other->_dictionary]; | 4418 GPBInt32BoolDictionary *otherDictionary = other; |
| 4419 return [_dictionary isEqual:otherDictionary->_dictionary]; |
4393 } | 4420 } |
4394 | 4421 |
4395 - (NSUInteger)hash { | 4422 - (NSUInteger)hash { |
4396 return _dictionary.count; | 4423 return _dictionary.count; |
4397 } | 4424 } |
4398 | 4425 |
4399 - (NSString *)description { | 4426 - (NSString *)description { |
4400 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 4427 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
4401 } | 4428 } |
4402 | 4429 |
4403 - (NSUInteger)count { | 4430 - (NSUInteger)count { |
4404 return _dictionary.count; | 4431 return _dictionary.count; |
4405 } | 4432 } |
4406 | 4433 |
4407 - (void)enumerateKeysAndValuesUsingBlock: | 4434 - (void)enumerateKeysAndBoolsUsingBlock: |
4408 (void (^)(int32_t key, BOOL value, BOOL *stop))block { | 4435 (void (^)(int32_t key, BOOL value, BOOL *stop))block { |
4409 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 4436 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
4410 NSNumber *aValue, | 4437 NSNumber *aValue, |
4411 BOOL *stop) { | 4438 BOOL *stop) { |
4412 block([aKey intValue], [aValue boolValue], stop); | 4439 block([aKey intValue], [aValue boolValue], stop); |
4413 }]; | 4440 }]; |
4414 } | 4441 } |
4415 | 4442 |
4416 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 4443 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
4417 NSUInteger count = _dictionary.count; | 4444 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4455 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | 4482 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); |
4456 }]; | 4483 }]; |
4457 } | 4484 } |
4458 | 4485 |
4459 - (void)setGPBGenericValue:(GPBGenericValue *)value | 4486 - (void)setGPBGenericValue:(GPBGenericValue *)value |
4460 forGPBGenericValueKey:(GPBGenericValue *)key { | 4487 forGPBGenericValueKey:(GPBGenericValue *)key { |
4461 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)]; | 4488 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)]; |
4462 } | 4489 } |
4463 | 4490 |
4464 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 4491 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
4465 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, BOOL value, BOOL *stop)
{ | 4492 [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, BOOL *stop) { |
4466 #pragma unused(stop) | 4493 #pragma unused(stop) |
4467 block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false")
); | 4494 block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false")
); |
4468 }]; | 4495 }]; |
4469 } | 4496 } |
4470 | 4497 |
4471 - (BOOL)valueForKey:(int32_t)key value:(BOOL *)value { | 4498 - (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key { |
4472 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 4499 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
4473 if (wrapped && value) { | 4500 if (wrapped && value) { |
4474 *value = [wrapped boolValue]; | 4501 *value = [wrapped boolValue]; |
4475 } | 4502 } |
4476 return (wrapped != NULL); | 4503 return (wrapped != NULL); |
4477 } | 4504 } |
4478 | 4505 |
4479 - (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary { | 4506 - (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary { |
4480 if (otherDictionary) { | 4507 if (otherDictionary) { |
4481 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 4508 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
4482 if (_autocreator) { | 4509 if (_autocreator) { |
4483 GPBAutocreatedDictionaryModified(_autocreator, self); | 4510 GPBAutocreatedDictionaryModified(_autocreator, self); |
4484 } | 4511 } |
4485 } | 4512 } |
4486 } | 4513 } |
4487 | 4514 |
4488 - (void)setValue:(BOOL)value forKey:(int32_t)key { | 4515 - (void)setBool:(BOOL)value forKey:(int32_t)key { |
4489 [_dictionary setObject:@(value) forKey:@(key)]; | 4516 [_dictionary setObject:@(value) forKey:@(key)]; |
4490 if (_autocreator) { | 4517 if (_autocreator) { |
4491 GPBAutocreatedDictionaryModified(_autocreator, self); | 4518 GPBAutocreatedDictionaryModified(_autocreator, self); |
4492 } | 4519 } |
4493 } | 4520 } |
4494 | 4521 |
4495 - (void)removeValueForKey:(int32_t)aKey { | 4522 - (void)removeBoolForKey:(int32_t)aKey { |
4496 [_dictionary removeObjectForKey:@(aKey)]; | 4523 [_dictionary removeObjectForKey:@(aKey)]; |
4497 } | 4524 } |
4498 | 4525 |
4499 - (void)removeAll { | 4526 - (void)removeAll { |
4500 [_dictionary removeAllObjects]; | 4527 [_dictionary removeAllObjects]; |
4501 } | 4528 } |
4502 | 4529 |
4503 @end | 4530 @end |
4504 | 4531 |
4505 #pragma mark - Int32 -> Float | 4532 #pragma mark - Int32 -> Float |
4506 | 4533 |
4507 @implementation GPBInt32FloatDictionary { | 4534 @implementation GPBInt32FloatDictionary { |
4508 @package | 4535 @package |
4509 NSMutableDictionary *_dictionary; | 4536 NSMutableDictionary *_dictionary; |
4510 } | 4537 } |
4511 | 4538 |
4512 + (instancetype)dictionary { | 4539 + (instancetype)dictionary { |
4513 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 4540 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; |
4514 } | 4541 } |
4515 | 4542 |
4516 + (instancetype)dictionaryWithValue:(float)value | 4543 + (instancetype)dictionaryWithFloat:(float)value |
4517 forKey:(int32_t)key { | 4544 forKey:(int32_t)key { |
4518 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 4545 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
4519 // on to get the type correct. | 4546 // on to get the type correct. |
4520 return [[(GPBInt32FloatDictionary*)[self alloc] initWithValues:&value | 4547 return [[(GPBInt32FloatDictionary*)[self alloc] initWithFloats:&value |
4521 forKeys:&key | 4548 forKeys:&key |
4522 count:1] autorelease]
; | 4549 count:1] autorelease]
; |
4523 } | 4550 } |
4524 | 4551 |
4525 + (instancetype)dictionaryWithValues:(const float [])values | 4552 + (instancetype)dictionaryWithFloats:(const float [])values |
4526 forKeys:(const int32_t [])keys | 4553 forKeys:(const int32_t [])keys |
4527 count:(NSUInteger)count { | 4554 count:(NSUInteger)count { |
4528 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 4555 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
4529 // on to get the type correct. | 4556 // on to get the type correct. |
4530 return [[(GPBInt32FloatDictionary*)[self alloc] initWithValues:values | 4557 return [[(GPBInt32FloatDictionary*)[self alloc] initWithFloats:values |
4531 forKeys:keys | 4558 forKeys:keys |
4532 count:count] autorele
ase]; | 4559 count:count] autorele
ase]; |
4533 } | 4560 } |
4534 | 4561 |
4535 + (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary { | 4562 + (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary { |
4536 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 4563 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
4537 // on to get the type correct. | 4564 // on to get the type correct. |
4538 return [[(GPBInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 4565 return [[(GPBInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
4539 } | 4566 } |
4540 | 4567 |
4541 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 4568 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
4542 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 4569 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
4543 } | 4570 } |
4544 | 4571 |
4545 - (instancetype)init { | 4572 - (instancetype)init { |
4546 return [self initWithValues:NULL forKeys:NULL count:0]; | 4573 return [self initWithFloats:NULL forKeys:NULL count:0]; |
4547 } | 4574 } |
4548 | 4575 |
4549 - (instancetype)initWithValues:(const float [])values | 4576 - (instancetype)initWithFloats:(const float [])values |
4550 forKeys:(const int32_t [])keys | 4577 forKeys:(const int32_t [])keys |
4551 count:(NSUInteger)count { | 4578 count:(NSUInteger)count { |
4552 self = [super init]; | 4579 self = [super init]; |
4553 if (self) { | 4580 if (self) { |
4554 _dictionary = [[NSMutableDictionary alloc] init]; | 4581 _dictionary = [[NSMutableDictionary alloc] init]; |
4555 if (count && values && keys) { | 4582 if (count && values && keys) { |
4556 for (NSUInteger i = 0; i < count; ++i) { | 4583 for (NSUInteger i = 0; i < count; ++i) { |
4557 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 4584 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
4558 } | 4585 } |
4559 } | 4586 } |
4560 } | 4587 } |
4561 return self; | 4588 return self; |
4562 } | 4589 } |
4563 | 4590 |
4564 - (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary { | 4591 - (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary { |
4565 self = [self initWithValues:NULL forKeys:NULL count:0]; | 4592 self = [self initWithFloats:NULL forKeys:NULL count:0]; |
4566 if (self) { | 4593 if (self) { |
4567 if (dictionary) { | 4594 if (dictionary) { |
4568 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 4595 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
4569 } | 4596 } |
4570 } | 4597 } |
4571 return self; | 4598 return self; |
4572 } | 4599 } |
4573 | 4600 |
4574 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 4601 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
4575 #pragma unused(numItems) | 4602 #pragma unused(numItems) |
4576 return [self initWithValues:NULL forKeys:NULL count:0]; | 4603 return [self initWithFloats:NULL forKeys:NULL count:0]; |
4577 } | 4604 } |
4578 | 4605 |
4579 - (void)dealloc { | 4606 - (void)dealloc { |
4580 NSAssert(!_autocreator, | 4607 NSAssert(!_autocreator, |
4581 @"%@: Autocreator must be cleared before release, autocreator: %@", | 4608 @"%@: Autocreator must be cleared before release, autocreator: %@", |
4582 [self class], _autocreator); | 4609 [self class], _autocreator); |
4583 [_dictionary release]; | 4610 [_dictionary release]; |
4584 [super dealloc]; | 4611 [super dealloc]; |
4585 } | 4612 } |
4586 | 4613 |
4587 - (instancetype)copyWithZone:(NSZone *)zone { | 4614 - (instancetype)copyWithZone:(NSZone *)zone { |
4588 return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]; | 4615 return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]; |
4589 } | 4616 } |
4590 | 4617 |
4591 - (BOOL)isEqual:(GPBInt32FloatDictionary *)other { | 4618 - (BOOL)isEqual:(id)other { |
4592 if (self == other) { | 4619 if (self == other) { |
4593 return YES; | 4620 return YES; |
4594 } | 4621 } |
4595 if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) { | 4622 if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) { |
4596 return NO; | 4623 return NO; |
4597 } | 4624 } |
4598 return [_dictionary isEqual:other->_dictionary]; | 4625 GPBInt32FloatDictionary *otherDictionary = other; |
| 4626 return [_dictionary isEqual:otherDictionary->_dictionary]; |
4599 } | 4627 } |
4600 | 4628 |
4601 - (NSUInteger)hash { | 4629 - (NSUInteger)hash { |
4602 return _dictionary.count; | 4630 return _dictionary.count; |
4603 } | 4631 } |
4604 | 4632 |
4605 - (NSString *)description { | 4633 - (NSString *)description { |
4606 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 4634 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
4607 } | 4635 } |
4608 | 4636 |
4609 - (NSUInteger)count { | 4637 - (NSUInteger)count { |
4610 return _dictionary.count; | 4638 return _dictionary.count; |
4611 } | 4639 } |
4612 | 4640 |
4613 - (void)enumerateKeysAndValuesUsingBlock: | 4641 - (void)enumerateKeysAndFloatsUsingBlock: |
4614 (void (^)(int32_t key, float value, BOOL *stop))block { | 4642 (void (^)(int32_t key, float value, BOOL *stop))block { |
4615 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 4643 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
4616 NSNumber *aValue, | 4644 NSNumber *aValue, |
4617 BOOL *stop) { | 4645 BOOL *stop) { |
4618 block([aKey intValue], [aValue floatValue], stop); | 4646 block([aKey intValue], [aValue floatValue], stop); |
4619 }]; | 4647 }]; |
4620 } | 4648 } |
4621 | 4649 |
4622 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 4650 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
4623 NSUInteger count = _dictionary.count; | 4651 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4661 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | 4689 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); |
4662 }]; | 4690 }]; |
4663 } | 4691 } |
4664 | 4692 |
4665 - (void)setGPBGenericValue:(GPBGenericValue *)value | 4693 - (void)setGPBGenericValue:(GPBGenericValue *)value |
4666 forGPBGenericValueKey:(GPBGenericValue *)key { | 4694 forGPBGenericValueKey:(GPBGenericValue *)key { |
4667 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)]; | 4695 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)]; |
4668 } | 4696 } |
4669 | 4697 |
4670 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 4698 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
4671 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, float value, BOOL *stop)
{ | 4699 [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, BOOL *stop)
{ |
4672 #pragma unused(stop) | 4700 #pragma unused(stop) |
4673 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%.*g", FLT_DIG, value]); | 4701 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%.*g", FLT_DIG, value]); |
4674 }]; | 4702 }]; |
4675 } | 4703 } |
4676 | 4704 |
4677 - (BOOL)valueForKey:(int32_t)key value:(float *)value { | 4705 - (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key { |
4678 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 4706 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
4679 if (wrapped && value) { | 4707 if (wrapped && value) { |
4680 *value = [wrapped floatValue]; | 4708 *value = [wrapped floatValue]; |
4681 } | 4709 } |
4682 return (wrapped != NULL); | 4710 return (wrapped != NULL); |
4683 } | 4711 } |
4684 | 4712 |
4685 - (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary { | 4713 - (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary { |
4686 if (otherDictionary) { | 4714 if (otherDictionary) { |
4687 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 4715 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
4688 if (_autocreator) { | 4716 if (_autocreator) { |
4689 GPBAutocreatedDictionaryModified(_autocreator, self); | 4717 GPBAutocreatedDictionaryModified(_autocreator, self); |
4690 } | 4718 } |
4691 } | 4719 } |
4692 } | 4720 } |
4693 | 4721 |
4694 - (void)setValue:(float)value forKey:(int32_t)key { | 4722 - (void)setFloat:(float)value forKey:(int32_t)key { |
4695 [_dictionary setObject:@(value) forKey:@(key)]; | 4723 [_dictionary setObject:@(value) forKey:@(key)]; |
4696 if (_autocreator) { | 4724 if (_autocreator) { |
4697 GPBAutocreatedDictionaryModified(_autocreator, self); | 4725 GPBAutocreatedDictionaryModified(_autocreator, self); |
4698 } | 4726 } |
4699 } | 4727 } |
4700 | 4728 |
4701 - (void)removeValueForKey:(int32_t)aKey { | 4729 - (void)removeFloatForKey:(int32_t)aKey { |
4702 [_dictionary removeObjectForKey:@(aKey)]; | 4730 [_dictionary removeObjectForKey:@(aKey)]; |
4703 } | 4731 } |
4704 | 4732 |
4705 - (void)removeAll { | 4733 - (void)removeAll { |
4706 [_dictionary removeAllObjects]; | 4734 [_dictionary removeAllObjects]; |
4707 } | 4735 } |
4708 | 4736 |
4709 @end | 4737 @end |
4710 | 4738 |
4711 #pragma mark - Int32 -> Double | 4739 #pragma mark - Int32 -> Double |
4712 | 4740 |
4713 @implementation GPBInt32DoubleDictionary { | 4741 @implementation GPBInt32DoubleDictionary { |
4714 @package | 4742 @package |
4715 NSMutableDictionary *_dictionary; | 4743 NSMutableDictionary *_dictionary; |
4716 } | 4744 } |
4717 | 4745 |
4718 + (instancetype)dictionary { | 4746 + (instancetype)dictionary { |
4719 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 4747 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; |
4720 } | 4748 } |
4721 | 4749 |
4722 + (instancetype)dictionaryWithValue:(double)value | 4750 + (instancetype)dictionaryWithDouble:(double)value |
4723 forKey:(int32_t)key { | 4751 forKey:(int32_t)key { |
4724 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 4752 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
4725 // on to get the type correct. | 4753 // on to get the type correct. |
4726 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithValues:&value | 4754 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDoubles:&value |
4727 forKeys:&key | 4755 forKeys:&key |
4728 count:1] autorelease
]; | 4756 count:1] autoreleas
e]; |
4729 } | 4757 } |
4730 | 4758 |
4731 + (instancetype)dictionaryWithValues:(const double [])values | 4759 + (instancetype)dictionaryWithDoubles:(const double [])values |
4732 forKeys:(const int32_t [])keys | 4760 forKeys:(const int32_t [])keys |
4733 count:(NSUInteger)count { | 4761 count:(NSUInteger)count { |
4734 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 4762 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
4735 // on to get the type correct. | 4763 // on to get the type correct. |
4736 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithValues:values | 4764 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDoubles:values |
4737 forKeys:keys | 4765 forKeys:keys |
4738 count:count] autorel
ease]; | 4766 count:count] autorel
ease]; |
4739 } | 4767 } |
4740 | 4768 |
4741 + (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary
{ | 4769 + (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary
{ |
4742 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 4770 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
4743 // on to get the type correct. | 4771 // on to get the type correct. |
4744 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 4772 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
4745 } | 4773 } |
4746 | 4774 |
4747 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 4775 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
4748 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 4776 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
4749 } | 4777 } |
4750 | 4778 |
4751 - (instancetype)init { | 4779 - (instancetype)init { |
4752 return [self initWithValues:NULL forKeys:NULL count:0]; | 4780 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
4753 } | 4781 } |
4754 | 4782 |
4755 - (instancetype)initWithValues:(const double [])values | 4783 - (instancetype)initWithDoubles:(const double [])values |
4756 forKeys:(const int32_t [])keys | 4784 forKeys:(const int32_t [])keys |
4757 count:(NSUInteger)count { | 4785 count:(NSUInteger)count { |
4758 self = [super init]; | 4786 self = [super init]; |
4759 if (self) { | 4787 if (self) { |
4760 _dictionary = [[NSMutableDictionary alloc] init]; | 4788 _dictionary = [[NSMutableDictionary alloc] init]; |
4761 if (count && values && keys) { | 4789 if (count && values && keys) { |
4762 for (NSUInteger i = 0; i < count; ++i) { | 4790 for (NSUInteger i = 0; i < count; ++i) { |
4763 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 4791 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
4764 } | 4792 } |
4765 } | 4793 } |
4766 } | 4794 } |
4767 return self; | 4795 return self; |
4768 } | 4796 } |
4769 | 4797 |
4770 - (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary { | 4798 - (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary { |
4771 self = [self initWithValues:NULL forKeys:NULL count:0]; | 4799 self = [self initWithDoubles:NULL forKeys:NULL count:0]; |
4772 if (self) { | 4800 if (self) { |
4773 if (dictionary) { | 4801 if (dictionary) { |
4774 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 4802 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
4775 } | 4803 } |
4776 } | 4804 } |
4777 return self; | 4805 return self; |
4778 } | 4806 } |
4779 | 4807 |
4780 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 4808 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
4781 #pragma unused(numItems) | 4809 #pragma unused(numItems) |
4782 return [self initWithValues:NULL forKeys:NULL count:0]; | 4810 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
4783 } | 4811 } |
4784 | 4812 |
4785 - (void)dealloc { | 4813 - (void)dealloc { |
4786 NSAssert(!_autocreator, | 4814 NSAssert(!_autocreator, |
4787 @"%@: Autocreator must be cleared before release, autocreator: %@", | 4815 @"%@: Autocreator must be cleared before release, autocreator: %@", |
4788 [self class], _autocreator); | 4816 [self class], _autocreator); |
4789 [_dictionary release]; | 4817 [_dictionary release]; |
4790 [super dealloc]; | 4818 [super dealloc]; |
4791 } | 4819 } |
4792 | 4820 |
4793 - (instancetype)copyWithZone:(NSZone *)zone { | 4821 - (instancetype)copyWithZone:(NSZone *)zone { |
4794 return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self]
; | 4822 return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self]
; |
4795 } | 4823 } |
4796 | 4824 |
4797 - (BOOL)isEqual:(GPBInt32DoubleDictionary *)other { | 4825 - (BOOL)isEqual:(id)other { |
4798 if (self == other) { | 4826 if (self == other) { |
4799 return YES; | 4827 return YES; |
4800 } | 4828 } |
4801 if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) { | 4829 if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) { |
4802 return NO; | 4830 return NO; |
4803 } | 4831 } |
4804 return [_dictionary isEqual:other->_dictionary]; | 4832 GPBInt32DoubleDictionary *otherDictionary = other; |
| 4833 return [_dictionary isEqual:otherDictionary->_dictionary]; |
4805 } | 4834 } |
4806 | 4835 |
4807 - (NSUInteger)hash { | 4836 - (NSUInteger)hash { |
4808 return _dictionary.count; | 4837 return _dictionary.count; |
4809 } | 4838 } |
4810 | 4839 |
4811 - (NSString *)description { | 4840 - (NSString *)description { |
4812 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 4841 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
4813 } | 4842 } |
4814 | 4843 |
4815 - (NSUInteger)count { | 4844 - (NSUInteger)count { |
4816 return _dictionary.count; | 4845 return _dictionary.count; |
4817 } | 4846 } |
4818 | 4847 |
4819 - (void)enumerateKeysAndValuesUsingBlock: | 4848 - (void)enumerateKeysAndDoublesUsingBlock: |
4820 (void (^)(int32_t key, double value, BOOL *stop))block { | 4849 (void (^)(int32_t key, double value, BOOL *stop))block { |
4821 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 4850 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
4822 NSNumber *aValue, | 4851 NSNumber *aValue, |
4823 BOOL *stop) { | 4852 BOOL *stop) { |
4824 block([aKey intValue], [aValue doubleValue], stop); | 4853 block([aKey intValue], [aValue doubleValue], stop); |
4825 }]; | 4854 }]; |
4826 } | 4855 } |
4827 | 4856 |
4828 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 4857 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
4829 NSUInteger count = _dictionary.count; | 4858 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4867 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | 4896 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); |
4868 }]; | 4897 }]; |
4869 } | 4898 } |
4870 | 4899 |
4871 - (void)setGPBGenericValue:(GPBGenericValue *)value | 4900 - (void)setGPBGenericValue:(GPBGenericValue *)value |
4872 forGPBGenericValueKey:(GPBGenericValue *)key { | 4901 forGPBGenericValueKey:(GPBGenericValue *)key { |
4873 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)]; | 4902 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)]; |
4874 } | 4903 } |
4875 | 4904 |
4876 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 4905 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
4877 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, double value, BOOL *stop
) { | 4906 [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, BOOL *sto
p) { |
4878 #pragma unused(stop) | 4907 #pragma unused(stop) |
4879 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%.*lg", DBL_DIG, value]); | 4908 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%.*lg", DBL_DIG, value]); |
4880 }]; | 4909 }]; |
4881 } | 4910 } |
4882 | 4911 |
4883 - (BOOL)valueForKey:(int32_t)key value:(double *)value { | 4912 - (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key { |
4884 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 4913 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
4885 if (wrapped && value) { | 4914 if (wrapped && value) { |
4886 *value = [wrapped doubleValue]; | 4915 *value = [wrapped doubleValue]; |
4887 } | 4916 } |
4888 return (wrapped != NULL); | 4917 return (wrapped != NULL); |
4889 } | 4918 } |
4890 | 4919 |
4891 - (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary { | 4920 - (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary { |
4892 if (otherDictionary) { | 4921 if (otherDictionary) { |
4893 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 4922 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
4894 if (_autocreator) { | 4923 if (_autocreator) { |
4895 GPBAutocreatedDictionaryModified(_autocreator, self); | 4924 GPBAutocreatedDictionaryModified(_autocreator, self); |
4896 } | 4925 } |
4897 } | 4926 } |
4898 } | 4927 } |
4899 | 4928 |
4900 - (void)setValue:(double)value forKey:(int32_t)key { | 4929 - (void)setDouble:(double)value forKey:(int32_t)key { |
4901 [_dictionary setObject:@(value) forKey:@(key)]; | 4930 [_dictionary setObject:@(value) forKey:@(key)]; |
4902 if (_autocreator) { | 4931 if (_autocreator) { |
4903 GPBAutocreatedDictionaryModified(_autocreator, self); | 4932 GPBAutocreatedDictionaryModified(_autocreator, self); |
4904 } | 4933 } |
4905 } | 4934 } |
4906 | 4935 |
4907 - (void)removeValueForKey:(int32_t)aKey { | 4936 - (void)removeDoubleForKey:(int32_t)aKey { |
4908 [_dictionary removeObjectForKey:@(aKey)]; | 4937 [_dictionary removeObjectForKey:@(aKey)]; |
4909 } | 4938 } |
4910 | 4939 |
4911 - (void)removeAll { | 4940 - (void)removeAll { |
4912 [_dictionary removeAllObjects]; | 4941 [_dictionary removeAllObjects]; |
4913 } | 4942 } |
4914 | 4943 |
4915 @end | 4944 @end |
4916 | 4945 |
4917 #pragma mark - Int32 -> Enum | 4946 #pragma mark - Int32 -> Enum |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5021 @"%@: Autocreator must be cleared before release, autocreator: %@", | 5050 @"%@: Autocreator must be cleared before release, autocreator: %@", |
5022 [self class], _autocreator); | 5051 [self class], _autocreator); |
5023 [_dictionary release]; | 5052 [_dictionary release]; |
5024 [super dealloc]; | 5053 [super dealloc]; |
5025 } | 5054 } |
5026 | 5055 |
5027 - (instancetype)copyWithZone:(NSZone *)zone { | 5056 - (instancetype)copyWithZone:(NSZone *)zone { |
5028 return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; | 5057 return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; |
5029 } | 5058 } |
5030 | 5059 |
5031 - (BOOL)isEqual:(GPBInt32EnumDictionary *)other { | 5060 - (BOOL)isEqual:(id)other { |
5032 if (self == other) { | 5061 if (self == other) { |
5033 return YES; | 5062 return YES; |
5034 } | 5063 } |
5035 if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) { | 5064 if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) { |
5036 return NO; | 5065 return NO; |
5037 } | 5066 } |
5038 return [_dictionary isEqual:other->_dictionary]; | 5067 GPBInt32EnumDictionary *otherDictionary = other; |
| 5068 return [_dictionary isEqual:otherDictionary->_dictionary]; |
5039 } | 5069 } |
5040 | 5070 |
5041 - (NSUInteger)hash { | 5071 - (NSUInteger)hash { |
5042 return _dictionary.count; | 5072 return _dictionary.count; |
5043 } | 5073 } |
5044 | 5074 |
5045 - (NSString *)description { | 5075 - (NSString *)description { |
5046 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 5076 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
5047 } | 5077 } |
5048 | 5078 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5119 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)]; | 5149 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)]; |
5120 } | 5150 } |
5121 | 5151 |
5122 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 5152 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
5123 [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *
stop) { | 5153 [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *
stop) { |
5124 #pragma unused(stop) | 5154 #pragma unused(stop) |
5125 block([NSString stringWithFormat:@"%d", key], @(value)); | 5155 block([NSString stringWithFormat:@"%d", key], @(value)); |
5126 }]; | 5156 }]; |
5127 } | 5157 } |
5128 | 5158 |
5129 - (BOOL)valueForKey:(int32_t)key value:(int32_t *)value { | 5159 - (BOOL)getEnum:(int32_t *)value forKey:(int32_t)key { |
5130 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 5160 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
5131 if (wrapped && value) { | 5161 if (wrapped && value) { |
5132 int32_t result = [wrapped intValue]; | 5162 int32_t result = [wrapped intValue]; |
5133 if (!_validationFunc(result)) { | 5163 if (!_validationFunc(result)) { |
5134 result = kGPBUnrecognizedEnumeratorValue; | 5164 result = kGPBUnrecognizedEnumeratorValue; |
5135 } | 5165 } |
5136 *value = result; | 5166 *value = result; |
5137 } | 5167 } |
5138 return (wrapped != NULL); | 5168 return (wrapped != NULL); |
5139 } | 5169 } |
5140 | 5170 |
5141 - (BOOL)valueForKey:(int32_t)key rawValue:(int32_t *)rawValue { | 5171 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int32_t)key { |
5142 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 5172 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
5143 if (wrapped && rawValue) { | 5173 if (wrapped && rawValue) { |
5144 *rawValue = [wrapped intValue]; | 5174 *rawValue = [wrapped intValue]; |
5145 } | 5175 } |
5146 return (wrapped != NULL); | 5176 return (wrapped != NULL); |
5147 } | 5177 } |
5148 | 5178 |
5149 - (void)enumerateKeysAndValuesUsingBlock: | 5179 - (void)enumerateKeysAndEnumsUsingBlock: |
5150 (void (^)(int32_t key, int32_t value, BOOL *stop))block { | 5180 (void (^)(int32_t key, int32_t value, BOOL *stop))block { |
5151 GPBEnumValidationFunc func = _validationFunc; | 5181 GPBEnumValidationFunc func = _validationFunc; |
5152 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 5182 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
5153 NSNumber *aValue, | 5183 NSNumber *aValue, |
5154 BOOL *stop) { | 5184 BOOL *stop) { |
5155 int32_t unwrapped = [aValue intValue]; | 5185 int32_t unwrapped = [aValue intValue]; |
5156 if (!func(unwrapped)) { | 5186 if (!func(unwrapped)) { |
5157 unwrapped = kGPBUnrecognizedEnumeratorValue; | 5187 unwrapped = kGPBUnrecognizedEnumeratorValue; |
5158 } | 5188 } |
5159 block([aKey intValue], unwrapped, stop); | 5189 block([aKey intValue], unwrapped, stop); |
5160 }]; | 5190 }]; |
5161 } | 5191 } |
5162 | 5192 |
5163 - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary { | 5193 - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary { |
5164 if (otherDictionary) { | 5194 if (otherDictionary) { |
5165 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 5195 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
5166 if (_autocreator) { | 5196 if (_autocreator) { |
5167 GPBAutocreatedDictionaryModified(_autocreator, self); | 5197 GPBAutocreatedDictionaryModified(_autocreator, self); |
5168 } | 5198 } |
5169 } | 5199 } |
5170 } | 5200 } |
5171 | 5201 |
5172 - (void)setRawValue:(int32_t)value forKey:(int32_t)key { | 5202 - (void)setRawValue:(int32_t)value forKey:(int32_t)key { |
5173 [_dictionary setObject:@(value) forKey:@(key)]; | 5203 [_dictionary setObject:@(value) forKey:@(key)]; |
5174 if (_autocreator) { | 5204 if (_autocreator) { |
5175 GPBAutocreatedDictionaryModified(_autocreator, self); | 5205 GPBAutocreatedDictionaryModified(_autocreator, self); |
5176 } | 5206 } |
5177 } | 5207 } |
5178 | 5208 |
5179 - (void)removeValueForKey:(int32_t)aKey { | 5209 - (void)removeEnumForKey:(int32_t)aKey { |
5180 [_dictionary removeObjectForKey:@(aKey)]; | 5210 [_dictionary removeObjectForKey:@(aKey)]; |
5181 } | 5211 } |
5182 | 5212 |
5183 - (void)removeAll { | 5213 - (void)removeAll { |
5184 [_dictionary removeAllObjects]; | 5214 [_dictionary removeAllObjects]; |
5185 } | 5215 } |
5186 | 5216 |
5187 - (void)setValue:(int32_t)value forKey:(int32_t)key { | 5217 - (void)setEnum:(int32_t)value forKey:(int32_t)key { |
5188 if (!_validationFunc(value)) { | 5218 if (!_validationFunc(value)) { |
5189 [NSException raise:NSInvalidArgumentException | 5219 [NSException raise:NSInvalidArgumentException |
5190 format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum
value (%d)", | 5220 format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum
value (%d)", |
5191 value]; | 5221 value]; |
5192 } | 5222 } |
5193 | 5223 |
5194 [_dictionary setObject:@(value) forKey:@(key)]; | 5224 [_dictionary setObject:@(value) forKey:@(key)]; |
5195 if (_autocreator) { | 5225 if (_autocreator) { |
5196 GPBAutocreatedDictionaryModified(_autocreator, self); | 5226 GPBAutocreatedDictionaryModified(_autocreator, self); |
5197 } | 5227 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5282 @"%@: Autocreator must be cleared before release, autocreator: %@", | 5312 @"%@: Autocreator must be cleared before release, autocreator: %@", |
5283 [self class], _autocreator); | 5313 [self class], _autocreator); |
5284 [_dictionary release]; | 5314 [_dictionary release]; |
5285 [super dealloc]; | 5315 [super dealloc]; |
5286 } | 5316 } |
5287 | 5317 |
5288 - (instancetype)copyWithZone:(NSZone *)zone { | 5318 - (instancetype)copyWithZone:(NSZone *)zone { |
5289 return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self]
; | 5319 return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self]
; |
5290 } | 5320 } |
5291 | 5321 |
5292 - (BOOL)isEqual:(GPBInt32ObjectDictionary *)other { | 5322 - (BOOL)isEqual:(id)other { |
5293 if (self == other) { | 5323 if (self == other) { |
5294 return YES; | 5324 return YES; |
5295 } | 5325 } |
5296 if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) { | 5326 if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) { |
5297 return NO; | 5327 return NO; |
5298 } | 5328 } |
5299 return [_dictionary isEqual:other->_dictionary]; | 5329 GPBInt32ObjectDictionary *otherDictionary = other; |
| 5330 return [_dictionary isEqual:otherDictionary->_dictionary]; |
5300 } | 5331 } |
5301 | 5332 |
5302 - (NSUInteger)hash { | 5333 - (NSUInteger)hash { |
5303 return _dictionary.count; | 5334 return _dictionary.count; |
5304 } | 5335 } |
5305 | 5336 |
5306 - (NSString *)description { | 5337 - (NSString *)description { |
5307 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 5338 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
5308 } | 5339 } |
5309 | 5340 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5437 // This block of code is generated, do not edit it directly. | 5468 // This block of code is generated, do not edit it directly. |
5438 | 5469 |
5439 #pragma mark - UInt64 -> UInt32 | 5470 #pragma mark - UInt64 -> UInt32 |
5440 | 5471 |
5441 @implementation GPBUInt64UInt32Dictionary { | 5472 @implementation GPBUInt64UInt32Dictionary { |
5442 @package | 5473 @package |
5443 NSMutableDictionary *_dictionary; | 5474 NSMutableDictionary *_dictionary; |
5444 } | 5475 } |
5445 | 5476 |
5446 + (instancetype)dictionary { | 5477 + (instancetype)dictionary { |
5447 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 5478 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; |
5448 } | 5479 } |
5449 | 5480 |
5450 + (instancetype)dictionaryWithValue:(uint32_t)value | 5481 + (instancetype)dictionaryWithUInt32:(uint32_t)value |
5451 forKey:(uint64_t)key { | 5482 forKey:(uint64_t)key { |
5452 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 5483 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
5453 // on to get the type correct. | 5484 // on to get the type correct. |
5454 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithValues:&value | 5485 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithUInt32s:&value |
5455 forKeys:&key | 5486 forKeys:&key |
5456 count:1] autoreleas
e]; | 5487 count:1] autorelea
se]; |
5457 } | 5488 } |
5458 | 5489 |
5459 + (instancetype)dictionaryWithValues:(const uint32_t [])values | 5490 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values |
5460 forKeys:(const uint64_t [])keys | 5491 forKeys:(const uint64_t [])keys |
5461 count:(NSUInteger)count { | 5492 count:(NSUInteger)count { |
5462 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 5493 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
5463 // on to get the type correct. | 5494 // on to get the type correct. |
5464 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithValues:values | 5495 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithUInt32s:values |
5465 forKeys:keys | 5496 forKeys:keys |
5466 count:count] autore
lease]; | 5497 count:count] autore
lease]; |
5467 } | 5498 } |
5468 | 5499 |
5469 + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary
{ | 5500 + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary
{ |
5470 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 5501 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
5471 // on to get the type correct. | 5502 // on to get the type correct. |
5472 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 5503 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
5473 } | 5504 } |
5474 | 5505 |
5475 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 5506 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
5476 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 5507 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
5477 } | 5508 } |
5478 | 5509 |
5479 - (instancetype)init { | 5510 - (instancetype)init { |
5480 return [self initWithValues:NULL forKeys:NULL count:0]; | 5511 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
5481 } | 5512 } |
5482 | 5513 |
5483 - (instancetype)initWithValues:(const uint32_t [])values | 5514 - (instancetype)initWithUInt32s:(const uint32_t [])values |
5484 forKeys:(const uint64_t [])keys | 5515 forKeys:(const uint64_t [])keys |
5485 count:(NSUInteger)count { | 5516 count:(NSUInteger)count { |
5486 self = [super init]; | 5517 self = [super init]; |
5487 if (self) { | 5518 if (self) { |
5488 _dictionary = [[NSMutableDictionary alloc] init]; | 5519 _dictionary = [[NSMutableDictionary alloc] init]; |
5489 if (count && values && keys) { | 5520 if (count && values && keys) { |
5490 for (NSUInteger i = 0; i < count; ++i) { | 5521 for (NSUInteger i = 0; i < count; ++i) { |
5491 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 5522 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
5492 } | 5523 } |
5493 } | 5524 } |
5494 } | 5525 } |
5495 return self; | 5526 return self; |
5496 } | 5527 } |
5497 | 5528 |
5498 - (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary { | 5529 - (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary { |
5499 self = [self initWithValues:NULL forKeys:NULL count:0]; | 5530 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; |
5500 if (self) { | 5531 if (self) { |
5501 if (dictionary) { | 5532 if (dictionary) { |
5502 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 5533 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
5503 } | 5534 } |
5504 } | 5535 } |
5505 return self; | 5536 return self; |
5506 } | 5537 } |
5507 | 5538 |
5508 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 5539 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
5509 #pragma unused(numItems) | 5540 #pragma unused(numItems) |
5510 return [self initWithValues:NULL forKeys:NULL count:0]; | 5541 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
5511 } | 5542 } |
5512 | 5543 |
5513 - (void)dealloc { | 5544 - (void)dealloc { |
5514 NSAssert(!_autocreator, | 5545 NSAssert(!_autocreator, |
5515 @"%@: Autocreator must be cleared before release, autocreator: %@", | 5546 @"%@: Autocreator must be cleared before release, autocreator: %@", |
5516 [self class], _autocreator); | 5547 [self class], _autocreator); |
5517 [_dictionary release]; | 5548 [_dictionary release]; |
5518 [super dealloc]; | 5549 [super dealloc]; |
5519 } | 5550 } |
5520 | 5551 |
5521 - (instancetype)copyWithZone:(NSZone *)zone { | 5552 - (instancetype)copyWithZone:(NSZone *)zone { |
5522 return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; | 5553 return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; |
5523 } | 5554 } |
5524 | 5555 |
5525 - (BOOL)isEqual:(GPBUInt64UInt32Dictionary *)other { | 5556 - (BOOL)isEqual:(id)other { |
5526 if (self == other) { | 5557 if (self == other) { |
5527 return YES; | 5558 return YES; |
5528 } | 5559 } |
5529 if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) { | 5560 if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) { |
5530 return NO; | 5561 return NO; |
5531 } | 5562 } |
5532 return [_dictionary isEqual:other->_dictionary]; | 5563 GPBUInt64UInt32Dictionary *otherDictionary = other; |
| 5564 return [_dictionary isEqual:otherDictionary->_dictionary]; |
5533 } | 5565 } |
5534 | 5566 |
5535 - (NSUInteger)hash { | 5567 - (NSUInteger)hash { |
5536 return _dictionary.count; | 5568 return _dictionary.count; |
5537 } | 5569 } |
5538 | 5570 |
5539 - (NSString *)description { | 5571 - (NSString *)description { |
5540 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 5572 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
5541 } | 5573 } |
5542 | 5574 |
5543 - (NSUInteger)count { | 5575 - (NSUInteger)count { |
5544 return _dictionary.count; | 5576 return _dictionary.count; |
5545 } | 5577 } |
5546 | 5578 |
5547 - (void)enumerateKeysAndValuesUsingBlock: | 5579 - (void)enumerateKeysAndUInt32sUsingBlock: |
5548 (void (^)(uint64_t key, uint32_t value, BOOL *stop))block { | 5580 (void (^)(uint64_t key, uint32_t value, BOOL *stop))block { |
5549 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 5581 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
5550 NSNumber *aValue, | 5582 NSNumber *aValue, |
5551 BOOL *stop) { | 5583 BOOL *stop) { |
5552 block([aKey unsignedLongLongValue], [aValue unsignedIntValue], stop); | 5584 block([aKey unsignedLongLongValue], [aValue unsignedIntValue], stop); |
5553 }]; | 5585 }]; |
5554 } | 5586 } |
5555 | 5587 |
5556 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 5588 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
5557 NSUInteger count = _dictionary.count; | 5589 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5595 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | 5627 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); |
5596 }]; | 5628 }]; |
5597 } | 5629 } |
5598 | 5630 |
5599 - (void)setGPBGenericValue:(GPBGenericValue *)value | 5631 - (void)setGPBGenericValue:(GPBGenericValue *)value |
5600 forGPBGenericValueKey:(GPBGenericValue *)key { | 5632 forGPBGenericValueKey:(GPBGenericValue *)key { |
5601 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)]; | 5633 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)]; |
5602 } | 5634 } |
5603 | 5635 |
5604 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 5636 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
5605 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, uint32_t value, BOOL *s
top) { | 5637 [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, BOOL *
stop) { |
5606 #pragma unused(stop) | 5638 #pragma unused(stop) |
5607 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%u", value]); | 5639 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%u", value]); |
5608 }]; | 5640 }]; |
5609 } | 5641 } |
5610 | 5642 |
5611 - (BOOL)valueForKey:(uint64_t)key value:(uint32_t *)value { | 5643 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key { |
5612 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 5644 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
5613 if (wrapped && value) { | 5645 if (wrapped && value) { |
5614 *value = [wrapped unsignedIntValue]; | 5646 *value = [wrapped unsignedIntValue]; |
5615 } | 5647 } |
5616 return (wrapped != NULL); | 5648 return (wrapped != NULL); |
5617 } | 5649 } |
5618 | 5650 |
5619 - (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary { | 5651 - (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary { |
5620 if (otherDictionary) { | 5652 if (otherDictionary) { |
5621 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 5653 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
5622 if (_autocreator) { | 5654 if (_autocreator) { |
5623 GPBAutocreatedDictionaryModified(_autocreator, self); | 5655 GPBAutocreatedDictionaryModified(_autocreator, self); |
5624 } | 5656 } |
5625 } | 5657 } |
5626 } | 5658 } |
5627 | 5659 |
5628 - (void)setValue:(uint32_t)value forKey:(uint64_t)key { | 5660 - (void)setUInt32:(uint32_t)value forKey:(uint64_t)key { |
5629 [_dictionary setObject:@(value) forKey:@(key)]; | 5661 [_dictionary setObject:@(value) forKey:@(key)]; |
5630 if (_autocreator) { | 5662 if (_autocreator) { |
5631 GPBAutocreatedDictionaryModified(_autocreator, self); | 5663 GPBAutocreatedDictionaryModified(_autocreator, self); |
5632 } | 5664 } |
5633 } | 5665 } |
5634 | 5666 |
5635 - (void)removeValueForKey:(uint64_t)aKey { | 5667 - (void)removeUInt32ForKey:(uint64_t)aKey { |
5636 [_dictionary removeObjectForKey:@(aKey)]; | 5668 [_dictionary removeObjectForKey:@(aKey)]; |
5637 } | 5669 } |
5638 | 5670 |
5639 - (void)removeAll { | 5671 - (void)removeAll { |
5640 [_dictionary removeAllObjects]; | 5672 [_dictionary removeAllObjects]; |
5641 } | 5673 } |
5642 | 5674 |
5643 @end | 5675 @end |
5644 | 5676 |
5645 #pragma mark - UInt64 -> Int32 | 5677 #pragma mark - UInt64 -> Int32 |
5646 | 5678 |
5647 @implementation GPBUInt64Int32Dictionary { | 5679 @implementation GPBUInt64Int32Dictionary { |
5648 @package | 5680 @package |
5649 NSMutableDictionary *_dictionary; | 5681 NSMutableDictionary *_dictionary; |
5650 } | 5682 } |
5651 | 5683 |
5652 + (instancetype)dictionary { | 5684 + (instancetype)dictionary { |
5653 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 5685 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; |
5654 } | 5686 } |
5655 | 5687 |
5656 + (instancetype)dictionaryWithValue:(int32_t)value | 5688 + (instancetype)dictionaryWithInt32:(int32_t)value |
5657 forKey:(uint64_t)key { | 5689 forKey:(uint64_t)key { |
5658 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 5690 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
5659 // on to get the type correct. | 5691 // on to get the type correct. |
5660 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithValues:&value | 5692 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithInt32s:&value |
5661 forKeys:&key | 5693 forKeys:&key |
5662 count:1] autorelease
]; | 5694 count:1] autorelease
]; |
5663 } | 5695 } |
5664 | 5696 |
5665 + (instancetype)dictionaryWithValues:(const int32_t [])values | 5697 + (instancetype)dictionaryWithInt32s:(const int32_t [])values |
5666 forKeys:(const uint64_t [])keys | 5698 forKeys:(const uint64_t [])keys |
5667 count:(NSUInteger)count { | 5699 count:(NSUInteger)count { |
5668 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 5700 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
5669 // on to get the type correct. | 5701 // on to get the type correct. |
5670 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithValues:values | 5702 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithInt32s:values |
5671 forKeys:keys | 5703 forKeys:keys |
5672 count:count] autorel
ease]; | 5704 count:count] autorel
ease]; |
5673 } | 5705 } |
5674 | 5706 |
5675 + (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary
{ | 5707 + (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary
{ |
5676 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 5708 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
5677 // on to get the type correct. | 5709 // on to get the type correct. |
5678 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 5710 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
5679 } | 5711 } |
5680 | 5712 |
5681 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 5713 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
5682 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 5714 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
5683 } | 5715 } |
5684 | 5716 |
5685 - (instancetype)init { | 5717 - (instancetype)init { |
5686 return [self initWithValues:NULL forKeys:NULL count:0]; | 5718 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
5687 } | 5719 } |
5688 | 5720 |
5689 - (instancetype)initWithValues:(const int32_t [])values | 5721 - (instancetype)initWithInt32s:(const int32_t [])values |
5690 forKeys:(const uint64_t [])keys | 5722 forKeys:(const uint64_t [])keys |
5691 count:(NSUInteger)count { | 5723 count:(NSUInteger)count { |
5692 self = [super init]; | 5724 self = [super init]; |
5693 if (self) { | 5725 if (self) { |
5694 _dictionary = [[NSMutableDictionary alloc] init]; | 5726 _dictionary = [[NSMutableDictionary alloc] init]; |
5695 if (count && values && keys) { | 5727 if (count && values && keys) { |
5696 for (NSUInteger i = 0; i < count; ++i) { | 5728 for (NSUInteger i = 0; i < count; ++i) { |
5697 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 5729 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
5698 } | 5730 } |
5699 } | 5731 } |
5700 } | 5732 } |
5701 return self; | 5733 return self; |
5702 } | 5734 } |
5703 | 5735 |
5704 - (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary { | 5736 - (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary { |
5705 self = [self initWithValues:NULL forKeys:NULL count:0]; | 5737 self = [self initWithInt32s:NULL forKeys:NULL count:0]; |
5706 if (self) { | 5738 if (self) { |
5707 if (dictionary) { | 5739 if (dictionary) { |
5708 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 5740 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
5709 } | 5741 } |
5710 } | 5742 } |
5711 return self; | 5743 return self; |
5712 } | 5744 } |
5713 | 5745 |
5714 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 5746 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
5715 #pragma unused(numItems) | 5747 #pragma unused(numItems) |
5716 return [self initWithValues:NULL forKeys:NULL count:0]; | 5748 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
5717 } | 5749 } |
5718 | 5750 |
5719 - (void)dealloc { | 5751 - (void)dealloc { |
5720 NSAssert(!_autocreator, | 5752 NSAssert(!_autocreator, |
5721 @"%@: Autocreator must be cleared before release, autocreator: %@", | 5753 @"%@: Autocreator must be cleared before release, autocreator: %@", |
5722 [self class], _autocreator); | 5754 [self class], _autocreator); |
5723 [_dictionary release]; | 5755 [_dictionary release]; |
5724 [super dealloc]; | 5756 [super dealloc]; |
5725 } | 5757 } |
5726 | 5758 |
5727 - (instancetype)copyWithZone:(NSZone *)zone { | 5759 - (instancetype)copyWithZone:(NSZone *)zone { |
5728 return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]
; | 5760 return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]
; |
5729 } | 5761 } |
5730 | 5762 |
5731 - (BOOL)isEqual:(GPBUInt64Int32Dictionary *)other { | 5763 - (BOOL)isEqual:(id)other { |
5732 if (self == other) { | 5764 if (self == other) { |
5733 return YES; | 5765 return YES; |
5734 } | 5766 } |
5735 if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) { | 5767 if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) { |
5736 return NO; | 5768 return NO; |
5737 } | 5769 } |
5738 return [_dictionary isEqual:other->_dictionary]; | 5770 GPBUInt64Int32Dictionary *otherDictionary = other; |
| 5771 return [_dictionary isEqual:otherDictionary->_dictionary]; |
5739 } | 5772 } |
5740 | 5773 |
5741 - (NSUInteger)hash { | 5774 - (NSUInteger)hash { |
5742 return _dictionary.count; | 5775 return _dictionary.count; |
5743 } | 5776 } |
5744 | 5777 |
5745 - (NSString *)description { | 5778 - (NSString *)description { |
5746 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 5779 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
5747 } | 5780 } |
5748 | 5781 |
5749 - (NSUInteger)count { | 5782 - (NSUInteger)count { |
5750 return _dictionary.count; | 5783 return _dictionary.count; |
5751 } | 5784 } |
5752 | 5785 |
5753 - (void)enumerateKeysAndValuesUsingBlock: | 5786 - (void)enumerateKeysAndInt32sUsingBlock: |
5754 (void (^)(uint64_t key, int32_t value, BOOL *stop))block { | 5787 (void (^)(uint64_t key, int32_t value, BOOL *stop))block { |
5755 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 5788 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
5756 NSNumber *aValue, | 5789 NSNumber *aValue, |
5757 BOOL *stop) { | 5790 BOOL *stop) { |
5758 block([aKey unsignedLongLongValue], [aValue intValue], stop); | 5791 block([aKey unsignedLongLongValue], [aValue intValue], stop); |
5759 }]; | 5792 }]; |
5760 } | 5793 } |
5761 | 5794 |
5762 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 5795 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
5763 NSUInteger count = _dictionary.count; | 5796 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5801 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | 5834 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); |
5802 }]; | 5835 }]; |
5803 } | 5836 } |
5804 | 5837 |
5805 - (void)setGPBGenericValue:(GPBGenericValue *)value | 5838 - (void)setGPBGenericValue:(GPBGenericValue *)value |
5806 forGPBGenericValueKey:(GPBGenericValue *)key { | 5839 forGPBGenericValueKey:(GPBGenericValue *)key { |
5807 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)]; | 5840 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)]; |
5808 } | 5841 } |
5809 | 5842 |
5810 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 5843 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
5811 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, int32_t value, BOOL *st
op) { | 5844 [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, BOOL *st
op) { |
5812 #pragma unused(stop) | 5845 #pragma unused(stop) |
5813 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%d", value]); | 5846 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%d", value]); |
5814 }]; | 5847 }]; |
5815 } | 5848 } |
5816 | 5849 |
5817 - (BOOL)valueForKey:(uint64_t)key value:(int32_t *)value { | 5850 - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key { |
5818 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 5851 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
5819 if (wrapped && value) { | 5852 if (wrapped && value) { |
5820 *value = [wrapped intValue]; | 5853 *value = [wrapped intValue]; |
5821 } | 5854 } |
5822 return (wrapped != NULL); | 5855 return (wrapped != NULL); |
5823 } | 5856 } |
5824 | 5857 |
5825 - (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary { | 5858 - (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary { |
5826 if (otherDictionary) { | 5859 if (otherDictionary) { |
5827 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 5860 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
5828 if (_autocreator) { | 5861 if (_autocreator) { |
5829 GPBAutocreatedDictionaryModified(_autocreator, self); | 5862 GPBAutocreatedDictionaryModified(_autocreator, self); |
5830 } | 5863 } |
5831 } | 5864 } |
5832 } | 5865 } |
5833 | 5866 |
5834 - (void)setValue:(int32_t)value forKey:(uint64_t)key { | 5867 - (void)setInt32:(int32_t)value forKey:(uint64_t)key { |
5835 [_dictionary setObject:@(value) forKey:@(key)]; | 5868 [_dictionary setObject:@(value) forKey:@(key)]; |
5836 if (_autocreator) { | 5869 if (_autocreator) { |
5837 GPBAutocreatedDictionaryModified(_autocreator, self); | 5870 GPBAutocreatedDictionaryModified(_autocreator, self); |
5838 } | 5871 } |
5839 } | 5872 } |
5840 | 5873 |
5841 - (void)removeValueForKey:(uint64_t)aKey { | 5874 - (void)removeInt32ForKey:(uint64_t)aKey { |
5842 [_dictionary removeObjectForKey:@(aKey)]; | 5875 [_dictionary removeObjectForKey:@(aKey)]; |
5843 } | 5876 } |
5844 | 5877 |
5845 - (void)removeAll { | 5878 - (void)removeAll { |
5846 [_dictionary removeAllObjects]; | 5879 [_dictionary removeAllObjects]; |
5847 } | 5880 } |
5848 | 5881 |
5849 @end | 5882 @end |
5850 | 5883 |
5851 #pragma mark - UInt64 -> UInt64 | 5884 #pragma mark - UInt64 -> UInt64 |
5852 | 5885 |
5853 @implementation GPBUInt64UInt64Dictionary { | 5886 @implementation GPBUInt64UInt64Dictionary { |
5854 @package | 5887 @package |
5855 NSMutableDictionary *_dictionary; | 5888 NSMutableDictionary *_dictionary; |
5856 } | 5889 } |
5857 | 5890 |
5858 + (instancetype)dictionary { | 5891 + (instancetype)dictionary { |
5859 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 5892 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; |
5860 } | 5893 } |
5861 | 5894 |
5862 + (instancetype)dictionaryWithValue:(uint64_t)value | 5895 + (instancetype)dictionaryWithUInt64:(uint64_t)value |
5863 forKey:(uint64_t)key { | 5896 forKey:(uint64_t)key { |
5864 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 5897 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
5865 // on to get the type correct. | 5898 // on to get the type correct. |
5866 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithValues:&value | 5899 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithUInt64s:&value |
5867 forKeys:&key | 5900 forKeys:&key |
5868 count:1] autoreleas
e]; | 5901 count:1] autorelea
se]; |
5869 } | 5902 } |
5870 | 5903 |
5871 + (instancetype)dictionaryWithValues:(const uint64_t [])values | 5904 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values |
5872 forKeys:(const uint64_t [])keys | 5905 forKeys:(const uint64_t [])keys |
5873 count:(NSUInteger)count { | 5906 count:(NSUInteger)count { |
5874 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 5907 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
5875 // on to get the type correct. | 5908 // on to get the type correct. |
5876 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithValues:values | 5909 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithUInt64s:values |
5877 forKeys:keys | 5910 forKeys:keys |
5878 count:count] autore
lease]; | 5911 count:count] autore
lease]; |
5879 } | 5912 } |
5880 | 5913 |
5881 + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary
{ | 5914 + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary
{ |
5882 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 5915 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
5883 // on to get the type correct. | 5916 // on to get the type correct. |
5884 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 5917 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
5885 } | 5918 } |
5886 | 5919 |
5887 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 5920 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
5888 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 5921 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
5889 } | 5922 } |
5890 | 5923 |
5891 - (instancetype)init { | 5924 - (instancetype)init { |
5892 return [self initWithValues:NULL forKeys:NULL count:0]; | 5925 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
5893 } | 5926 } |
5894 | 5927 |
5895 - (instancetype)initWithValues:(const uint64_t [])values | 5928 - (instancetype)initWithUInt64s:(const uint64_t [])values |
5896 forKeys:(const uint64_t [])keys | 5929 forKeys:(const uint64_t [])keys |
5897 count:(NSUInteger)count { | 5930 count:(NSUInteger)count { |
5898 self = [super init]; | 5931 self = [super init]; |
5899 if (self) { | 5932 if (self) { |
5900 _dictionary = [[NSMutableDictionary alloc] init]; | 5933 _dictionary = [[NSMutableDictionary alloc] init]; |
5901 if (count && values && keys) { | 5934 if (count && values && keys) { |
5902 for (NSUInteger i = 0; i < count; ++i) { | 5935 for (NSUInteger i = 0; i < count; ++i) { |
5903 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 5936 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
5904 } | 5937 } |
5905 } | 5938 } |
5906 } | 5939 } |
5907 return self; | 5940 return self; |
5908 } | 5941 } |
5909 | 5942 |
5910 - (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary { | 5943 - (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary { |
5911 self = [self initWithValues:NULL forKeys:NULL count:0]; | 5944 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; |
5912 if (self) { | 5945 if (self) { |
5913 if (dictionary) { | 5946 if (dictionary) { |
5914 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 5947 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
5915 } | 5948 } |
5916 } | 5949 } |
5917 return self; | 5950 return self; |
5918 } | 5951 } |
5919 | 5952 |
5920 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 5953 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
5921 #pragma unused(numItems) | 5954 #pragma unused(numItems) |
5922 return [self initWithValues:NULL forKeys:NULL count:0]; | 5955 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
5923 } | 5956 } |
5924 | 5957 |
5925 - (void)dealloc { | 5958 - (void)dealloc { |
5926 NSAssert(!_autocreator, | 5959 NSAssert(!_autocreator, |
5927 @"%@: Autocreator must be cleared before release, autocreator: %@", | 5960 @"%@: Autocreator must be cleared before release, autocreator: %@", |
5928 [self class], _autocreator); | 5961 [self class], _autocreator); |
5929 [_dictionary release]; | 5962 [_dictionary release]; |
5930 [super dealloc]; | 5963 [super dealloc]; |
5931 } | 5964 } |
5932 | 5965 |
5933 - (instancetype)copyWithZone:(NSZone *)zone { | 5966 - (instancetype)copyWithZone:(NSZone *)zone { |
5934 return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; | 5967 return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; |
5935 } | 5968 } |
5936 | 5969 |
5937 - (BOOL)isEqual:(GPBUInt64UInt64Dictionary *)other { | 5970 - (BOOL)isEqual:(id)other { |
5938 if (self == other) { | 5971 if (self == other) { |
5939 return YES; | 5972 return YES; |
5940 } | 5973 } |
5941 if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) { | 5974 if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) { |
5942 return NO; | 5975 return NO; |
5943 } | 5976 } |
5944 return [_dictionary isEqual:other->_dictionary]; | 5977 GPBUInt64UInt64Dictionary *otherDictionary = other; |
| 5978 return [_dictionary isEqual:otherDictionary->_dictionary]; |
5945 } | 5979 } |
5946 | 5980 |
5947 - (NSUInteger)hash { | 5981 - (NSUInteger)hash { |
5948 return _dictionary.count; | 5982 return _dictionary.count; |
5949 } | 5983 } |
5950 | 5984 |
5951 - (NSString *)description { | 5985 - (NSString *)description { |
5952 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 5986 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
5953 } | 5987 } |
5954 | 5988 |
5955 - (NSUInteger)count { | 5989 - (NSUInteger)count { |
5956 return _dictionary.count; | 5990 return _dictionary.count; |
5957 } | 5991 } |
5958 | 5992 |
5959 - (void)enumerateKeysAndValuesUsingBlock: | 5993 - (void)enumerateKeysAndUInt64sUsingBlock: |
5960 (void (^)(uint64_t key, uint64_t value, BOOL *stop))block { | 5994 (void (^)(uint64_t key, uint64_t value, BOOL *stop))block { |
5961 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 5995 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
5962 NSNumber *aValue, | 5996 NSNumber *aValue, |
5963 BOOL *stop) { | 5997 BOOL *stop) { |
5964 block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], stop); | 5998 block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], stop); |
5965 }]; | 5999 }]; |
5966 } | 6000 } |
5967 | 6001 |
5968 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 6002 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
5969 NSUInteger count = _dictionary.count; | 6003 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6007 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | 6041 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); |
6008 }]; | 6042 }]; |
6009 } | 6043 } |
6010 | 6044 |
6011 - (void)setGPBGenericValue:(GPBGenericValue *)value | 6045 - (void)setGPBGenericValue:(GPBGenericValue *)value |
6012 forGPBGenericValueKey:(GPBGenericValue *)key { | 6046 forGPBGenericValueKey:(GPBGenericValue *)key { |
6013 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)]; | 6047 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)]; |
6014 } | 6048 } |
6015 | 6049 |
6016 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 6050 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
6017 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, uint64_t value, BOOL *s
top) { | 6051 [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, BOOL *
stop) { |
6018 #pragma unused(stop) | 6052 #pragma unused(stop) |
6019 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%llu", value]); | 6053 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%llu", value]); |
6020 }]; | 6054 }]; |
6021 } | 6055 } |
6022 | 6056 |
6023 - (BOOL)valueForKey:(uint64_t)key value:(uint64_t *)value { | 6057 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key { |
6024 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 6058 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
6025 if (wrapped && value) { | 6059 if (wrapped && value) { |
6026 *value = [wrapped unsignedLongLongValue]; | 6060 *value = [wrapped unsignedLongLongValue]; |
6027 } | 6061 } |
6028 return (wrapped != NULL); | 6062 return (wrapped != NULL); |
6029 } | 6063 } |
6030 | 6064 |
6031 - (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary { | 6065 - (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary { |
6032 if (otherDictionary) { | 6066 if (otherDictionary) { |
6033 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 6067 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
6034 if (_autocreator) { | 6068 if (_autocreator) { |
6035 GPBAutocreatedDictionaryModified(_autocreator, self); | 6069 GPBAutocreatedDictionaryModified(_autocreator, self); |
6036 } | 6070 } |
6037 } | 6071 } |
6038 } | 6072 } |
6039 | 6073 |
6040 - (void)setValue:(uint64_t)value forKey:(uint64_t)key { | 6074 - (void)setUInt64:(uint64_t)value forKey:(uint64_t)key { |
6041 [_dictionary setObject:@(value) forKey:@(key)]; | 6075 [_dictionary setObject:@(value) forKey:@(key)]; |
6042 if (_autocreator) { | 6076 if (_autocreator) { |
6043 GPBAutocreatedDictionaryModified(_autocreator, self); | 6077 GPBAutocreatedDictionaryModified(_autocreator, self); |
6044 } | 6078 } |
6045 } | 6079 } |
6046 | 6080 |
6047 - (void)removeValueForKey:(uint64_t)aKey { | 6081 - (void)removeUInt64ForKey:(uint64_t)aKey { |
6048 [_dictionary removeObjectForKey:@(aKey)]; | 6082 [_dictionary removeObjectForKey:@(aKey)]; |
6049 } | 6083 } |
6050 | 6084 |
6051 - (void)removeAll { | 6085 - (void)removeAll { |
6052 [_dictionary removeAllObjects]; | 6086 [_dictionary removeAllObjects]; |
6053 } | 6087 } |
6054 | 6088 |
6055 @end | 6089 @end |
6056 | 6090 |
6057 #pragma mark - UInt64 -> Int64 | 6091 #pragma mark - UInt64 -> Int64 |
6058 | 6092 |
6059 @implementation GPBUInt64Int64Dictionary { | 6093 @implementation GPBUInt64Int64Dictionary { |
6060 @package | 6094 @package |
6061 NSMutableDictionary *_dictionary; | 6095 NSMutableDictionary *_dictionary; |
6062 } | 6096 } |
6063 | 6097 |
6064 + (instancetype)dictionary { | 6098 + (instancetype)dictionary { |
6065 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 6099 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; |
6066 } | 6100 } |
6067 | 6101 |
6068 + (instancetype)dictionaryWithValue:(int64_t)value | 6102 + (instancetype)dictionaryWithInt64:(int64_t)value |
6069 forKey:(uint64_t)key { | 6103 forKey:(uint64_t)key { |
6070 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 6104 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
6071 // on to get the type correct. | 6105 // on to get the type correct. |
6072 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithValues:&value | 6106 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithInt64s:&value |
6073 forKeys:&key | 6107 forKeys:&key |
6074 count:1] autorelease
]; | 6108 count:1] autorelease
]; |
6075 } | 6109 } |
6076 | 6110 |
6077 + (instancetype)dictionaryWithValues:(const int64_t [])values | 6111 + (instancetype)dictionaryWithInt64s:(const int64_t [])values |
6078 forKeys:(const uint64_t [])keys | 6112 forKeys:(const uint64_t [])keys |
6079 count:(NSUInteger)count { | 6113 count:(NSUInteger)count { |
6080 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 6114 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
6081 // on to get the type correct. | 6115 // on to get the type correct. |
6082 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithValues:values | 6116 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithInt64s:values |
6083 forKeys:keys | 6117 forKeys:keys |
6084 count:count] autorel
ease]; | 6118 count:count] autorel
ease]; |
6085 } | 6119 } |
6086 | 6120 |
6087 + (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary
{ | 6121 + (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary
{ |
6088 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 6122 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
6089 // on to get the type correct. | 6123 // on to get the type correct. |
6090 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 6124 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
6091 } | 6125 } |
6092 | 6126 |
6093 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 6127 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
6094 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 6128 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
6095 } | 6129 } |
6096 | 6130 |
6097 - (instancetype)init { | 6131 - (instancetype)init { |
6098 return [self initWithValues:NULL forKeys:NULL count:0]; | 6132 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
6099 } | 6133 } |
6100 | 6134 |
6101 - (instancetype)initWithValues:(const int64_t [])values | 6135 - (instancetype)initWithInt64s:(const int64_t [])values |
6102 forKeys:(const uint64_t [])keys | 6136 forKeys:(const uint64_t [])keys |
6103 count:(NSUInteger)count { | 6137 count:(NSUInteger)count { |
6104 self = [super init]; | 6138 self = [super init]; |
6105 if (self) { | 6139 if (self) { |
6106 _dictionary = [[NSMutableDictionary alloc] init]; | 6140 _dictionary = [[NSMutableDictionary alloc] init]; |
6107 if (count && values && keys) { | 6141 if (count && values && keys) { |
6108 for (NSUInteger i = 0; i < count; ++i) { | 6142 for (NSUInteger i = 0; i < count; ++i) { |
6109 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 6143 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
6110 } | 6144 } |
6111 } | 6145 } |
6112 } | 6146 } |
6113 return self; | 6147 return self; |
6114 } | 6148 } |
6115 | 6149 |
6116 - (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary { | 6150 - (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary { |
6117 self = [self initWithValues:NULL forKeys:NULL count:0]; | 6151 self = [self initWithInt64s:NULL forKeys:NULL count:0]; |
6118 if (self) { | 6152 if (self) { |
6119 if (dictionary) { | 6153 if (dictionary) { |
6120 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 6154 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
6121 } | 6155 } |
6122 } | 6156 } |
6123 return self; | 6157 return self; |
6124 } | 6158 } |
6125 | 6159 |
6126 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 6160 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
6127 #pragma unused(numItems) | 6161 #pragma unused(numItems) |
6128 return [self initWithValues:NULL forKeys:NULL count:0]; | 6162 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
6129 } | 6163 } |
6130 | 6164 |
6131 - (void)dealloc { | 6165 - (void)dealloc { |
6132 NSAssert(!_autocreator, | 6166 NSAssert(!_autocreator, |
6133 @"%@: Autocreator must be cleared before release, autocreator: %@", | 6167 @"%@: Autocreator must be cleared before release, autocreator: %@", |
6134 [self class], _autocreator); | 6168 [self class], _autocreator); |
6135 [_dictionary release]; | 6169 [_dictionary release]; |
6136 [super dealloc]; | 6170 [super dealloc]; |
6137 } | 6171 } |
6138 | 6172 |
6139 - (instancetype)copyWithZone:(NSZone *)zone { | 6173 - (instancetype)copyWithZone:(NSZone *)zone { |
6140 return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]
; | 6174 return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]
; |
6141 } | 6175 } |
6142 | 6176 |
6143 - (BOOL)isEqual:(GPBUInt64Int64Dictionary *)other { | 6177 - (BOOL)isEqual:(id)other { |
6144 if (self == other) { | 6178 if (self == other) { |
6145 return YES; | 6179 return YES; |
6146 } | 6180 } |
6147 if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) { | 6181 if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) { |
6148 return NO; | 6182 return NO; |
6149 } | 6183 } |
6150 return [_dictionary isEqual:other->_dictionary]; | 6184 GPBUInt64Int64Dictionary *otherDictionary = other; |
| 6185 return [_dictionary isEqual:otherDictionary->_dictionary]; |
6151 } | 6186 } |
6152 | 6187 |
6153 - (NSUInteger)hash { | 6188 - (NSUInteger)hash { |
6154 return _dictionary.count; | 6189 return _dictionary.count; |
6155 } | 6190 } |
6156 | 6191 |
6157 - (NSString *)description { | 6192 - (NSString *)description { |
6158 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 6193 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
6159 } | 6194 } |
6160 | 6195 |
6161 - (NSUInteger)count { | 6196 - (NSUInteger)count { |
6162 return _dictionary.count; | 6197 return _dictionary.count; |
6163 } | 6198 } |
6164 | 6199 |
6165 - (void)enumerateKeysAndValuesUsingBlock: | 6200 - (void)enumerateKeysAndInt64sUsingBlock: |
6166 (void (^)(uint64_t key, int64_t value, BOOL *stop))block { | 6201 (void (^)(uint64_t key, int64_t value, BOOL *stop))block { |
6167 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 6202 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
6168 NSNumber *aValue, | 6203 NSNumber *aValue, |
6169 BOOL *stop) { | 6204 BOOL *stop) { |
6170 block([aKey unsignedLongLongValue], [aValue longLongValue], stop); | 6205 block([aKey unsignedLongLongValue], [aValue longLongValue], stop); |
6171 }]; | 6206 }]; |
6172 } | 6207 } |
6173 | 6208 |
6174 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 6209 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
6175 NSUInteger count = _dictionary.count; | 6210 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6213 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | 6248 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); |
6214 }]; | 6249 }]; |
6215 } | 6250 } |
6216 | 6251 |
6217 - (void)setGPBGenericValue:(GPBGenericValue *)value | 6252 - (void)setGPBGenericValue:(GPBGenericValue *)value |
6218 forGPBGenericValueKey:(GPBGenericValue *)key { | 6253 forGPBGenericValueKey:(GPBGenericValue *)key { |
6219 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)]; | 6254 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)]; |
6220 } | 6255 } |
6221 | 6256 |
6222 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 6257 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
6223 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, int64_t value, BOOL *st
op) { | 6258 [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, BOOL *st
op) { |
6224 #pragma unused(stop) | 6259 #pragma unused(stop) |
6225 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%lld", value]); | 6260 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%lld", value]); |
6226 }]; | 6261 }]; |
6227 } | 6262 } |
6228 | 6263 |
6229 - (BOOL)valueForKey:(uint64_t)key value:(int64_t *)value { | 6264 - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key { |
6230 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 6265 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
6231 if (wrapped && value) { | 6266 if (wrapped && value) { |
6232 *value = [wrapped longLongValue]; | 6267 *value = [wrapped longLongValue]; |
6233 } | 6268 } |
6234 return (wrapped != NULL); | 6269 return (wrapped != NULL); |
6235 } | 6270 } |
6236 | 6271 |
6237 - (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary { | 6272 - (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary { |
6238 if (otherDictionary) { | 6273 if (otherDictionary) { |
6239 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 6274 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
6240 if (_autocreator) { | 6275 if (_autocreator) { |
6241 GPBAutocreatedDictionaryModified(_autocreator, self); | 6276 GPBAutocreatedDictionaryModified(_autocreator, self); |
6242 } | 6277 } |
6243 } | 6278 } |
6244 } | 6279 } |
6245 | 6280 |
6246 - (void)setValue:(int64_t)value forKey:(uint64_t)key { | 6281 - (void)setInt64:(int64_t)value forKey:(uint64_t)key { |
6247 [_dictionary setObject:@(value) forKey:@(key)]; | 6282 [_dictionary setObject:@(value) forKey:@(key)]; |
6248 if (_autocreator) { | 6283 if (_autocreator) { |
6249 GPBAutocreatedDictionaryModified(_autocreator, self); | 6284 GPBAutocreatedDictionaryModified(_autocreator, self); |
6250 } | 6285 } |
6251 } | 6286 } |
6252 | 6287 |
6253 - (void)removeValueForKey:(uint64_t)aKey { | 6288 - (void)removeInt64ForKey:(uint64_t)aKey { |
6254 [_dictionary removeObjectForKey:@(aKey)]; | 6289 [_dictionary removeObjectForKey:@(aKey)]; |
6255 } | 6290 } |
6256 | 6291 |
6257 - (void)removeAll { | 6292 - (void)removeAll { |
6258 [_dictionary removeAllObjects]; | 6293 [_dictionary removeAllObjects]; |
6259 } | 6294 } |
6260 | 6295 |
6261 @end | 6296 @end |
6262 | 6297 |
6263 #pragma mark - UInt64 -> Bool | 6298 #pragma mark - UInt64 -> Bool |
6264 | 6299 |
6265 @implementation GPBUInt64BoolDictionary { | 6300 @implementation GPBUInt64BoolDictionary { |
6266 @package | 6301 @package |
6267 NSMutableDictionary *_dictionary; | 6302 NSMutableDictionary *_dictionary; |
6268 } | 6303 } |
6269 | 6304 |
6270 + (instancetype)dictionary { | 6305 + (instancetype)dictionary { |
6271 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 6306 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; |
6272 } | 6307 } |
6273 | 6308 |
6274 + (instancetype)dictionaryWithValue:(BOOL)value | 6309 + (instancetype)dictionaryWithBool:(BOOL)value |
6275 forKey:(uint64_t)key { | 6310 forKey:(uint64_t)key { |
6276 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 6311 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
6277 // on to get the type correct. | 6312 // on to get the type correct. |
6278 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithValues:&value | 6313 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithBools:&value |
6279 forKeys:&key | 6314 forKeys:&key |
6280 count:1] autorelease]
; | 6315 count:1] autorelease]; |
6281 } | 6316 } |
6282 | 6317 |
6283 + (instancetype)dictionaryWithValues:(const BOOL [])values | 6318 + (instancetype)dictionaryWithBools:(const BOOL [])values |
6284 forKeys:(const uint64_t [])keys | 6319 forKeys:(const uint64_t [])keys |
6285 count:(NSUInteger)count { | 6320 count:(NSUInteger)count { |
6286 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 6321 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
6287 // on to get the type correct. | 6322 // on to get the type correct. |
6288 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithValues:values | 6323 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithBools:values |
6289 forKeys:keys | 6324 forKeys:keys |
6290 count:count] autorele
ase]; | 6325 count:count] autorele
ase]; |
6291 } | 6326 } |
6292 | 6327 |
6293 + (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary { | 6328 + (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary { |
6294 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 6329 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
6295 // on to get the type correct. | 6330 // on to get the type correct. |
6296 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 6331 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
6297 } | 6332 } |
6298 | 6333 |
6299 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 6334 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
6300 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 6335 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
6301 } | 6336 } |
6302 | 6337 |
6303 - (instancetype)init { | 6338 - (instancetype)init { |
6304 return [self initWithValues:NULL forKeys:NULL count:0]; | 6339 return [self initWithBools:NULL forKeys:NULL count:0]; |
6305 } | 6340 } |
6306 | 6341 |
6307 - (instancetype)initWithValues:(const BOOL [])values | 6342 - (instancetype)initWithBools:(const BOOL [])values |
6308 forKeys:(const uint64_t [])keys | 6343 forKeys:(const uint64_t [])keys |
6309 count:(NSUInteger)count { | 6344 count:(NSUInteger)count { |
6310 self = [super init]; | 6345 self = [super init]; |
6311 if (self) { | 6346 if (self) { |
6312 _dictionary = [[NSMutableDictionary alloc] init]; | 6347 _dictionary = [[NSMutableDictionary alloc] init]; |
6313 if (count && values && keys) { | 6348 if (count && values && keys) { |
6314 for (NSUInteger i = 0; i < count; ++i) { | 6349 for (NSUInteger i = 0; i < count; ++i) { |
6315 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 6350 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
6316 } | 6351 } |
6317 } | 6352 } |
6318 } | 6353 } |
6319 return self; | 6354 return self; |
6320 } | 6355 } |
6321 | 6356 |
6322 - (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary { | 6357 - (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary { |
6323 self = [self initWithValues:NULL forKeys:NULL count:0]; | 6358 self = [self initWithBools:NULL forKeys:NULL count:0]; |
6324 if (self) { | 6359 if (self) { |
6325 if (dictionary) { | 6360 if (dictionary) { |
6326 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 6361 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
6327 } | 6362 } |
6328 } | 6363 } |
6329 return self; | 6364 return self; |
6330 } | 6365 } |
6331 | 6366 |
6332 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 6367 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
6333 #pragma unused(numItems) | 6368 #pragma unused(numItems) |
6334 return [self initWithValues:NULL forKeys:NULL count:0]; | 6369 return [self initWithBools:NULL forKeys:NULL count:0]; |
6335 } | 6370 } |
6336 | 6371 |
6337 - (void)dealloc { | 6372 - (void)dealloc { |
6338 NSAssert(!_autocreator, | 6373 NSAssert(!_autocreator, |
6339 @"%@: Autocreator must be cleared before release, autocreator: %@", | 6374 @"%@: Autocreator must be cleared before release, autocreator: %@", |
6340 [self class], _autocreator); | 6375 [self class], _autocreator); |
6341 [_dictionary release]; | 6376 [_dictionary release]; |
6342 [super dealloc]; | 6377 [super dealloc]; |
6343 } | 6378 } |
6344 | 6379 |
6345 - (instancetype)copyWithZone:(NSZone *)zone { | 6380 - (instancetype)copyWithZone:(NSZone *)zone { |
6346 return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; | 6381 return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; |
6347 } | 6382 } |
6348 | 6383 |
6349 - (BOOL)isEqual:(GPBUInt64BoolDictionary *)other { | 6384 - (BOOL)isEqual:(id)other { |
6350 if (self == other) { | 6385 if (self == other) { |
6351 return YES; | 6386 return YES; |
6352 } | 6387 } |
6353 if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) { | 6388 if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) { |
6354 return NO; | 6389 return NO; |
6355 } | 6390 } |
6356 return [_dictionary isEqual:other->_dictionary]; | 6391 GPBUInt64BoolDictionary *otherDictionary = other; |
| 6392 return [_dictionary isEqual:otherDictionary->_dictionary]; |
6357 } | 6393 } |
6358 | 6394 |
6359 - (NSUInteger)hash { | 6395 - (NSUInteger)hash { |
6360 return _dictionary.count; | 6396 return _dictionary.count; |
6361 } | 6397 } |
6362 | 6398 |
6363 - (NSString *)description { | 6399 - (NSString *)description { |
6364 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 6400 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
6365 } | 6401 } |
6366 | 6402 |
6367 - (NSUInteger)count { | 6403 - (NSUInteger)count { |
6368 return _dictionary.count; | 6404 return _dictionary.count; |
6369 } | 6405 } |
6370 | 6406 |
6371 - (void)enumerateKeysAndValuesUsingBlock: | 6407 - (void)enumerateKeysAndBoolsUsingBlock: |
6372 (void (^)(uint64_t key, BOOL value, BOOL *stop))block { | 6408 (void (^)(uint64_t key, BOOL value, BOOL *stop))block { |
6373 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 6409 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
6374 NSNumber *aValue, | 6410 NSNumber *aValue, |
6375 BOOL *stop) { | 6411 BOOL *stop) { |
6376 block([aKey unsignedLongLongValue], [aValue boolValue], stop); | 6412 block([aKey unsignedLongLongValue], [aValue boolValue], stop); |
6377 }]; | 6413 }]; |
6378 } | 6414 } |
6379 | 6415 |
6380 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 6416 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
6381 NSUInteger count = _dictionary.count; | 6417 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6419 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | 6455 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); |
6420 }]; | 6456 }]; |
6421 } | 6457 } |
6422 | 6458 |
6423 - (void)setGPBGenericValue:(GPBGenericValue *)value | 6459 - (void)setGPBGenericValue:(GPBGenericValue *)value |
6424 forGPBGenericValueKey:(GPBGenericValue *)key { | 6460 forGPBGenericValueKey:(GPBGenericValue *)key { |
6425 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)]; | 6461 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)]; |
6426 } | 6462 } |
6427 | 6463 |
6428 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 6464 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
6429 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, BOOL value, BOOL *stop)
{ | 6465 [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, BOOL *stop)
{ |
6430 #pragma unused(stop) | 6466 #pragma unused(stop) |
6431 block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false
")); | 6467 block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false
")); |
6432 }]; | 6468 }]; |
6433 } | 6469 } |
6434 | 6470 |
6435 - (BOOL)valueForKey:(uint64_t)key value:(BOOL *)value { | 6471 - (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key { |
6436 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 6472 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
6437 if (wrapped && value) { | 6473 if (wrapped && value) { |
6438 *value = [wrapped boolValue]; | 6474 *value = [wrapped boolValue]; |
6439 } | 6475 } |
6440 return (wrapped != NULL); | 6476 return (wrapped != NULL); |
6441 } | 6477 } |
6442 | 6478 |
6443 - (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary { | 6479 - (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary { |
6444 if (otherDictionary) { | 6480 if (otherDictionary) { |
6445 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 6481 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
6446 if (_autocreator) { | 6482 if (_autocreator) { |
6447 GPBAutocreatedDictionaryModified(_autocreator, self); | 6483 GPBAutocreatedDictionaryModified(_autocreator, self); |
6448 } | 6484 } |
6449 } | 6485 } |
6450 } | 6486 } |
6451 | 6487 |
6452 - (void)setValue:(BOOL)value forKey:(uint64_t)key { | 6488 - (void)setBool:(BOOL)value forKey:(uint64_t)key { |
6453 [_dictionary setObject:@(value) forKey:@(key)]; | 6489 [_dictionary setObject:@(value) forKey:@(key)]; |
6454 if (_autocreator) { | 6490 if (_autocreator) { |
6455 GPBAutocreatedDictionaryModified(_autocreator, self); | 6491 GPBAutocreatedDictionaryModified(_autocreator, self); |
6456 } | 6492 } |
6457 } | 6493 } |
6458 | 6494 |
6459 - (void)removeValueForKey:(uint64_t)aKey { | 6495 - (void)removeBoolForKey:(uint64_t)aKey { |
6460 [_dictionary removeObjectForKey:@(aKey)]; | 6496 [_dictionary removeObjectForKey:@(aKey)]; |
6461 } | 6497 } |
6462 | 6498 |
6463 - (void)removeAll { | 6499 - (void)removeAll { |
6464 [_dictionary removeAllObjects]; | 6500 [_dictionary removeAllObjects]; |
6465 } | 6501 } |
6466 | 6502 |
6467 @end | 6503 @end |
6468 | 6504 |
6469 #pragma mark - UInt64 -> Float | 6505 #pragma mark - UInt64 -> Float |
6470 | 6506 |
6471 @implementation GPBUInt64FloatDictionary { | 6507 @implementation GPBUInt64FloatDictionary { |
6472 @package | 6508 @package |
6473 NSMutableDictionary *_dictionary; | 6509 NSMutableDictionary *_dictionary; |
6474 } | 6510 } |
6475 | 6511 |
6476 + (instancetype)dictionary { | 6512 + (instancetype)dictionary { |
6477 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 6513 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; |
6478 } | 6514 } |
6479 | 6515 |
6480 + (instancetype)dictionaryWithValue:(float)value | 6516 + (instancetype)dictionaryWithFloat:(float)value |
6481 forKey:(uint64_t)key { | 6517 forKey:(uint64_t)key { |
6482 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 6518 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
6483 // on to get the type correct. | 6519 // on to get the type correct. |
6484 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithValues:&value | 6520 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithFloats:&value |
6485 forKeys:&key | 6521 forKeys:&key |
6486 count:1] autorelease
]; | 6522 count:1] autorelease
]; |
6487 } | 6523 } |
6488 | 6524 |
6489 + (instancetype)dictionaryWithValues:(const float [])values | 6525 + (instancetype)dictionaryWithFloats:(const float [])values |
6490 forKeys:(const uint64_t [])keys | 6526 forKeys:(const uint64_t [])keys |
6491 count:(NSUInteger)count { | 6527 count:(NSUInteger)count { |
6492 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 6528 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
6493 // on to get the type correct. | 6529 // on to get the type correct. |
6494 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithValues:values | 6530 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithFloats:values |
6495 forKeys:keys | 6531 forKeys:keys |
6496 count:count] autorel
ease]; | 6532 count:count] autorel
ease]; |
6497 } | 6533 } |
6498 | 6534 |
6499 + (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary
{ | 6535 + (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary
{ |
6500 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 6536 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
6501 // on to get the type correct. | 6537 // on to get the type correct. |
6502 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 6538 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
6503 } | 6539 } |
6504 | 6540 |
6505 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 6541 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
6506 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 6542 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
6507 } | 6543 } |
6508 | 6544 |
6509 - (instancetype)init { | 6545 - (instancetype)init { |
6510 return [self initWithValues:NULL forKeys:NULL count:0]; | 6546 return [self initWithFloats:NULL forKeys:NULL count:0]; |
6511 } | 6547 } |
6512 | 6548 |
6513 - (instancetype)initWithValues:(const float [])values | 6549 - (instancetype)initWithFloats:(const float [])values |
6514 forKeys:(const uint64_t [])keys | 6550 forKeys:(const uint64_t [])keys |
6515 count:(NSUInteger)count { | 6551 count:(NSUInteger)count { |
6516 self = [super init]; | 6552 self = [super init]; |
6517 if (self) { | 6553 if (self) { |
6518 _dictionary = [[NSMutableDictionary alloc] init]; | 6554 _dictionary = [[NSMutableDictionary alloc] init]; |
6519 if (count && values && keys) { | 6555 if (count && values && keys) { |
6520 for (NSUInteger i = 0; i < count; ++i) { | 6556 for (NSUInteger i = 0; i < count; ++i) { |
6521 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 6557 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
6522 } | 6558 } |
6523 } | 6559 } |
6524 } | 6560 } |
6525 return self; | 6561 return self; |
6526 } | 6562 } |
6527 | 6563 |
6528 - (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary { | 6564 - (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary { |
6529 self = [self initWithValues:NULL forKeys:NULL count:0]; | 6565 self = [self initWithFloats:NULL forKeys:NULL count:0]; |
6530 if (self) { | 6566 if (self) { |
6531 if (dictionary) { | 6567 if (dictionary) { |
6532 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 6568 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
6533 } | 6569 } |
6534 } | 6570 } |
6535 return self; | 6571 return self; |
6536 } | 6572 } |
6537 | 6573 |
6538 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 6574 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
6539 #pragma unused(numItems) | 6575 #pragma unused(numItems) |
6540 return [self initWithValues:NULL forKeys:NULL count:0]; | 6576 return [self initWithFloats:NULL forKeys:NULL count:0]; |
6541 } | 6577 } |
6542 | 6578 |
6543 - (void)dealloc { | 6579 - (void)dealloc { |
6544 NSAssert(!_autocreator, | 6580 NSAssert(!_autocreator, |
6545 @"%@: Autocreator must be cleared before release, autocreator: %@", | 6581 @"%@: Autocreator must be cleared before release, autocreator: %@", |
6546 [self class], _autocreator); | 6582 [self class], _autocreator); |
6547 [_dictionary release]; | 6583 [_dictionary release]; |
6548 [super dealloc]; | 6584 [super dealloc]; |
6549 } | 6585 } |
6550 | 6586 |
6551 - (instancetype)copyWithZone:(NSZone *)zone { | 6587 - (instancetype)copyWithZone:(NSZone *)zone { |
6552 return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]
; | 6588 return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]
; |
6553 } | 6589 } |
6554 | 6590 |
6555 - (BOOL)isEqual:(GPBUInt64FloatDictionary *)other { | 6591 - (BOOL)isEqual:(id)other { |
6556 if (self == other) { | 6592 if (self == other) { |
6557 return YES; | 6593 return YES; |
6558 } | 6594 } |
6559 if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) { | 6595 if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) { |
6560 return NO; | 6596 return NO; |
6561 } | 6597 } |
6562 return [_dictionary isEqual:other->_dictionary]; | 6598 GPBUInt64FloatDictionary *otherDictionary = other; |
| 6599 return [_dictionary isEqual:otherDictionary->_dictionary]; |
6563 } | 6600 } |
6564 | 6601 |
6565 - (NSUInteger)hash { | 6602 - (NSUInteger)hash { |
6566 return _dictionary.count; | 6603 return _dictionary.count; |
6567 } | 6604 } |
6568 | 6605 |
6569 - (NSString *)description { | 6606 - (NSString *)description { |
6570 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 6607 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
6571 } | 6608 } |
6572 | 6609 |
6573 - (NSUInteger)count { | 6610 - (NSUInteger)count { |
6574 return _dictionary.count; | 6611 return _dictionary.count; |
6575 } | 6612 } |
6576 | 6613 |
6577 - (void)enumerateKeysAndValuesUsingBlock: | 6614 - (void)enumerateKeysAndFloatsUsingBlock: |
6578 (void (^)(uint64_t key, float value, BOOL *stop))block { | 6615 (void (^)(uint64_t key, float value, BOOL *stop))block { |
6579 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 6616 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
6580 NSNumber *aValue, | 6617 NSNumber *aValue, |
6581 BOOL *stop) { | 6618 BOOL *stop) { |
6582 block([aKey unsignedLongLongValue], [aValue floatValue], stop); | 6619 block([aKey unsignedLongLongValue], [aValue floatValue], stop); |
6583 }]; | 6620 }]; |
6584 } | 6621 } |
6585 | 6622 |
6586 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 6623 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
6587 NSUInteger count = _dictionary.count; | 6624 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6625 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | 6662 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); |
6626 }]; | 6663 }]; |
6627 } | 6664 } |
6628 | 6665 |
6629 - (void)setGPBGenericValue:(GPBGenericValue *)value | 6666 - (void)setGPBGenericValue:(GPBGenericValue *)value |
6630 forGPBGenericValueKey:(GPBGenericValue *)key { | 6667 forGPBGenericValueKey:(GPBGenericValue *)key { |
6631 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)]; | 6668 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)]; |
6632 } | 6669 } |
6633 | 6670 |
6634 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 6671 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
6635 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, float value, BOOL *stop
) { | 6672 [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, BOOL *stop
) { |
6636 #pragma unused(stop) | 6673 #pragma unused(stop) |
6637 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%.*g", FLT_DIG, value]); | 6674 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%.*g", FLT_DIG, value]); |
6638 }]; | 6675 }]; |
6639 } | 6676 } |
6640 | 6677 |
6641 - (BOOL)valueForKey:(uint64_t)key value:(float *)value { | 6678 - (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key { |
6642 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 6679 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
6643 if (wrapped && value) { | 6680 if (wrapped && value) { |
6644 *value = [wrapped floatValue]; | 6681 *value = [wrapped floatValue]; |
6645 } | 6682 } |
6646 return (wrapped != NULL); | 6683 return (wrapped != NULL); |
6647 } | 6684 } |
6648 | 6685 |
6649 - (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary { | 6686 - (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary { |
6650 if (otherDictionary) { | 6687 if (otherDictionary) { |
6651 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 6688 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
6652 if (_autocreator) { | 6689 if (_autocreator) { |
6653 GPBAutocreatedDictionaryModified(_autocreator, self); | 6690 GPBAutocreatedDictionaryModified(_autocreator, self); |
6654 } | 6691 } |
6655 } | 6692 } |
6656 } | 6693 } |
6657 | 6694 |
6658 - (void)setValue:(float)value forKey:(uint64_t)key { | 6695 - (void)setFloat:(float)value forKey:(uint64_t)key { |
6659 [_dictionary setObject:@(value) forKey:@(key)]; | 6696 [_dictionary setObject:@(value) forKey:@(key)]; |
6660 if (_autocreator) { | 6697 if (_autocreator) { |
6661 GPBAutocreatedDictionaryModified(_autocreator, self); | 6698 GPBAutocreatedDictionaryModified(_autocreator, self); |
6662 } | 6699 } |
6663 } | 6700 } |
6664 | 6701 |
6665 - (void)removeValueForKey:(uint64_t)aKey { | 6702 - (void)removeFloatForKey:(uint64_t)aKey { |
6666 [_dictionary removeObjectForKey:@(aKey)]; | 6703 [_dictionary removeObjectForKey:@(aKey)]; |
6667 } | 6704 } |
6668 | 6705 |
6669 - (void)removeAll { | 6706 - (void)removeAll { |
6670 [_dictionary removeAllObjects]; | 6707 [_dictionary removeAllObjects]; |
6671 } | 6708 } |
6672 | 6709 |
6673 @end | 6710 @end |
6674 | 6711 |
6675 #pragma mark - UInt64 -> Double | 6712 #pragma mark - UInt64 -> Double |
6676 | 6713 |
6677 @implementation GPBUInt64DoubleDictionary { | 6714 @implementation GPBUInt64DoubleDictionary { |
6678 @package | 6715 @package |
6679 NSMutableDictionary *_dictionary; | 6716 NSMutableDictionary *_dictionary; |
6680 } | 6717 } |
6681 | 6718 |
6682 + (instancetype)dictionary { | 6719 + (instancetype)dictionary { |
6683 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 6720 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; |
6684 } | 6721 } |
6685 | 6722 |
6686 + (instancetype)dictionaryWithValue:(double)value | 6723 + (instancetype)dictionaryWithDouble:(double)value |
6687 forKey:(uint64_t)key { | 6724 forKey:(uint64_t)key { |
6688 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 6725 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
6689 // on to get the type correct. | 6726 // on to get the type correct. |
6690 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithValues:&value | 6727 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDoubles:&value |
6691 forKeys:&key | 6728 forKeys:&key |
6692 count:1] autoreleas
e]; | 6729 count:1] autorelea
se]; |
6693 } | 6730 } |
6694 | 6731 |
6695 + (instancetype)dictionaryWithValues:(const double [])values | 6732 + (instancetype)dictionaryWithDoubles:(const double [])values |
6696 forKeys:(const uint64_t [])keys | 6733 forKeys:(const uint64_t [])keys |
6697 count:(NSUInteger)count { | 6734 count:(NSUInteger)count { |
6698 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 6735 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
6699 // on to get the type correct. | 6736 // on to get the type correct. |
6700 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithValues:values | 6737 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDoubles:values |
6701 forKeys:keys | 6738 forKeys:keys |
6702 count:count] autore
lease]; | 6739 count:count] autore
lease]; |
6703 } | 6740 } |
6704 | 6741 |
6705 + (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary
{ | 6742 + (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary
{ |
6706 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 6743 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
6707 // on to get the type correct. | 6744 // on to get the type correct. |
6708 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 6745 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
6709 } | 6746 } |
6710 | 6747 |
6711 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 6748 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
6712 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 6749 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
6713 } | 6750 } |
6714 | 6751 |
6715 - (instancetype)init { | 6752 - (instancetype)init { |
6716 return [self initWithValues:NULL forKeys:NULL count:0]; | 6753 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
6717 } | 6754 } |
6718 | 6755 |
6719 - (instancetype)initWithValues:(const double [])values | 6756 - (instancetype)initWithDoubles:(const double [])values |
6720 forKeys:(const uint64_t [])keys | 6757 forKeys:(const uint64_t [])keys |
6721 count:(NSUInteger)count { | 6758 count:(NSUInteger)count { |
6722 self = [super init]; | 6759 self = [super init]; |
6723 if (self) { | 6760 if (self) { |
6724 _dictionary = [[NSMutableDictionary alloc] init]; | 6761 _dictionary = [[NSMutableDictionary alloc] init]; |
6725 if (count && values && keys) { | 6762 if (count && values && keys) { |
6726 for (NSUInteger i = 0; i < count; ++i) { | 6763 for (NSUInteger i = 0; i < count; ++i) { |
6727 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 6764 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
6728 } | 6765 } |
6729 } | 6766 } |
6730 } | 6767 } |
6731 return self; | 6768 return self; |
6732 } | 6769 } |
6733 | 6770 |
6734 - (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary { | 6771 - (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary { |
6735 self = [self initWithValues:NULL forKeys:NULL count:0]; | 6772 self = [self initWithDoubles:NULL forKeys:NULL count:0]; |
6736 if (self) { | 6773 if (self) { |
6737 if (dictionary) { | 6774 if (dictionary) { |
6738 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 6775 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
6739 } | 6776 } |
6740 } | 6777 } |
6741 return self; | 6778 return self; |
6742 } | 6779 } |
6743 | 6780 |
6744 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 6781 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
6745 #pragma unused(numItems) | 6782 #pragma unused(numItems) |
6746 return [self initWithValues:NULL forKeys:NULL count:0]; | 6783 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
6747 } | 6784 } |
6748 | 6785 |
6749 - (void)dealloc { | 6786 - (void)dealloc { |
6750 NSAssert(!_autocreator, | 6787 NSAssert(!_autocreator, |
6751 @"%@: Autocreator must be cleared before release, autocreator: %@", | 6788 @"%@: Autocreator must be cleared before release, autocreator: %@", |
6752 [self class], _autocreator); | 6789 [self class], _autocreator); |
6753 [_dictionary release]; | 6790 [_dictionary release]; |
6754 [super dealloc]; | 6791 [super dealloc]; |
6755 } | 6792 } |
6756 | 6793 |
6757 - (instancetype)copyWithZone:(NSZone *)zone { | 6794 - (instancetype)copyWithZone:(NSZone *)zone { |
6758 return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self
]; | 6795 return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self
]; |
6759 } | 6796 } |
6760 | 6797 |
6761 - (BOOL)isEqual:(GPBUInt64DoubleDictionary *)other { | 6798 - (BOOL)isEqual:(id)other { |
6762 if (self == other) { | 6799 if (self == other) { |
6763 return YES; | 6800 return YES; |
6764 } | 6801 } |
6765 if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) { | 6802 if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) { |
6766 return NO; | 6803 return NO; |
6767 } | 6804 } |
6768 return [_dictionary isEqual:other->_dictionary]; | 6805 GPBUInt64DoubleDictionary *otherDictionary = other; |
| 6806 return [_dictionary isEqual:otherDictionary->_dictionary]; |
6769 } | 6807 } |
6770 | 6808 |
6771 - (NSUInteger)hash { | 6809 - (NSUInteger)hash { |
6772 return _dictionary.count; | 6810 return _dictionary.count; |
6773 } | 6811 } |
6774 | 6812 |
6775 - (NSString *)description { | 6813 - (NSString *)description { |
6776 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 6814 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
6777 } | 6815 } |
6778 | 6816 |
6779 - (NSUInteger)count { | 6817 - (NSUInteger)count { |
6780 return _dictionary.count; | 6818 return _dictionary.count; |
6781 } | 6819 } |
6782 | 6820 |
6783 - (void)enumerateKeysAndValuesUsingBlock: | 6821 - (void)enumerateKeysAndDoublesUsingBlock: |
6784 (void (^)(uint64_t key, double value, BOOL *stop))block { | 6822 (void (^)(uint64_t key, double value, BOOL *stop))block { |
6785 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 6823 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
6786 NSNumber *aValue, | 6824 NSNumber *aValue, |
6787 BOOL *stop) { | 6825 BOOL *stop) { |
6788 block([aKey unsignedLongLongValue], [aValue doubleValue], stop); | 6826 block([aKey unsignedLongLongValue], [aValue doubleValue], stop); |
6789 }]; | 6827 }]; |
6790 } | 6828 } |
6791 | 6829 |
6792 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 6830 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
6793 NSUInteger count = _dictionary.count; | 6831 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6831 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | 6869 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); |
6832 }]; | 6870 }]; |
6833 } | 6871 } |
6834 | 6872 |
6835 - (void)setGPBGenericValue:(GPBGenericValue *)value | 6873 - (void)setGPBGenericValue:(GPBGenericValue *)value |
6836 forGPBGenericValueKey:(GPBGenericValue *)key { | 6874 forGPBGenericValueKey:(GPBGenericValue *)key { |
6837 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)]; | 6875 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)]; |
6838 } | 6876 } |
6839 | 6877 |
6840 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 6878 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
6841 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, double value, BOOL *sto
p) { | 6879 [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, BOOL *st
op) { |
6842 #pragma unused(stop) | 6880 #pragma unused(stop) |
6843 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%.*lg", DBL_DIG, value]); | 6881 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%.*lg", DBL_DIG, value]); |
6844 }]; | 6882 }]; |
6845 } | 6883 } |
6846 | 6884 |
6847 - (BOOL)valueForKey:(uint64_t)key value:(double *)value { | 6885 - (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key { |
6848 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 6886 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
6849 if (wrapped && value) { | 6887 if (wrapped && value) { |
6850 *value = [wrapped doubleValue]; | 6888 *value = [wrapped doubleValue]; |
6851 } | 6889 } |
6852 return (wrapped != NULL); | 6890 return (wrapped != NULL); |
6853 } | 6891 } |
6854 | 6892 |
6855 - (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary { | 6893 - (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary { |
6856 if (otherDictionary) { | 6894 if (otherDictionary) { |
6857 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 6895 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
6858 if (_autocreator) { | 6896 if (_autocreator) { |
6859 GPBAutocreatedDictionaryModified(_autocreator, self); | 6897 GPBAutocreatedDictionaryModified(_autocreator, self); |
6860 } | 6898 } |
6861 } | 6899 } |
6862 } | 6900 } |
6863 | 6901 |
6864 - (void)setValue:(double)value forKey:(uint64_t)key { | 6902 - (void)setDouble:(double)value forKey:(uint64_t)key { |
6865 [_dictionary setObject:@(value) forKey:@(key)]; | 6903 [_dictionary setObject:@(value) forKey:@(key)]; |
6866 if (_autocreator) { | 6904 if (_autocreator) { |
6867 GPBAutocreatedDictionaryModified(_autocreator, self); | 6905 GPBAutocreatedDictionaryModified(_autocreator, self); |
6868 } | 6906 } |
6869 } | 6907 } |
6870 | 6908 |
6871 - (void)removeValueForKey:(uint64_t)aKey { | 6909 - (void)removeDoubleForKey:(uint64_t)aKey { |
6872 [_dictionary removeObjectForKey:@(aKey)]; | 6910 [_dictionary removeObjectForKey:@(aKey)]; |
6873 } | 6911 } |
6874 | 6912 |
6875 - (void)removeAll { | 6913 - (void)removeAll { |
6876 [_dictionary removeAllObjects]; | 6914 [_dictionary removeAllObjects]; |
6877 } | 6915 } |
6878 | 6916 |
6879 @end | 6917 @end |
6880 | 6918 |
6881 #pragma mark - UInt64 -> Enum | 6919 #pragma mark - UInt64 -> Enum |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6985 @"%@: Autocreator must be cleared before release, autocreator: %@", | 7023 @"%@: Autocreator must be cleared before release, autocreator: %@", |
6986 [self class], _autocreator); | 7024 [self class], _autocreator); |
6987 [_dictionary release]; | 7025 [_dictionary release]; |
6988 [super dealloc]; | 7026 [super dealloc]; |
6989 } | 7027 } |
6990 | 7028 |
6991 - (instancetype)copyWithZone:(NSZone *)zone { | 7029 - (instancetype)copyWithZone:(NSZone *)zone { |
6992 return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; | 7030 return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; |
6993 } | 7031 } |
6994 | 7032 |
6995 - (BOOL)isEqual:(GPBUInt64EnumDictionary *)other { | 7033 - (BOOL)isEqual:(id)other { |
6996 if (self == other) { | 7034 if (self == other) { |
6997 return YES; | 7035 return YES; |
6998 } | 7036 } |
6999 if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) { | 7037 if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) { |
7000 return NO; | 7038 return NO; |
7001 } | 7039 } |
7002 return [_dictionary isEqual:other->_dictionary]; | 7040 GPBUInt64EnumDictionary *otherDictionary = other; |
| 7041 return [_dictionary isEqual:otherDictionary->_dictionary]; |
7003 } | 7042 } |
7004 | 7043 |
7005 - (NSUInteger)hash { | 7044 - (NSUInteger)hash { |
7006 return _dictionary.count; | 7045 return _dictionary.count; |
7007 } | 7046 } |
7008 | 7047 |
7009 - (NSString *)description { | 7048 - (NSString *)description { |
7010 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 7049 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
7011 } | 7050 } |
7012 | 7051 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7083 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)]; | 7122 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)]; |
7084 } | 7123 } |
7085 | 7124 |
7086 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 7125 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
7087 [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL
*stop) { | 7126 [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL
*stop) { |
7088 #pragma unused(stop) | 7127 #pragma unused(stop) |
7089 block([NSString stringWithFormat:@"%llu", key], @(value)); | 7128 block([NSString stringWithFormat:@"%llu", key], @(value)); |
7090 }]; | 7129 }]; |
7091 } | 7130 } |
7092 | 7131 |
7093 - (BOOL)valueForKey:(uint64_t)key value:(int32_t *)value { | 7132 - (BOOL)getEnum:(int32_t *)value forKey:(uint64_t)key { |
7094 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 7133 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
7095 if (wrapped && value) { | 7134 if (wrapped && value) { |
7096 int32_t result = [wrapped intValue]; | 7135 int32_t result = [wrapped intValue]; |
7097 if (!_validationFunc(result)) { | 7136 if (!_validationFunc(result)) { |
7098 result = kGPBUnrecognizedEnumeratorValue; | 7137 result = kGPBUnrecognizedEnumeratorValue; |
7099 } | 7138 } |
7100 *value = result; | 7139 *value = result; |
7101 } | 7140 } |
7102 return (wrapped != NULL); | 7141 return (wrapped != NULL); |
7103 } | 7142 } |
7104 | 7143 |
7105 - (BOOL)valueForKey:(uint64_t)key rawValue:(int32_t *)rawValue { | 7144 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint64_t)key { |
7106 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 7145 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
7107 if (wrapped && rawValue) { | 7146 if (wrapped && rawValue) { |
7108 *rawValue = [wrapped intValue]; | 7147 *rawValue = [wrapped intValue]; |
7109 } | 7148 } |
7110 return (wrapped != NULL); | 7149 return (wrapped != NULL); |
7111 } | 7150 } |
7112 | 7151 |
7113 - (void)enumerateKeysAndValuesUsingBlock: | 7152 - (void)enumerateKeysAndEnumsUsingBlock: |
7114 (void (^)(uint64_t key, int32_t value, BOOL *stop))block { | 7153 (void (^)(uint64_t key, int32_t value, BOOL *stop))block { |
7115 GPBEnumValidationFunc func = _validationFunc; | 7154 GPBEnumValidationFunc func = _validationFunc; |
7116 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 7155 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
7117 NSNumber *aValue, | 7156 NSNumber *aValue, |
7118 BOOL *stop) { | 7157 BOOL *stop) { |
7119 int32_t unwrapped = [aValue intValue]; | 7158 int32_t unwrapped = [aValue intValue]; |
7120 if (!func(unwrapped)) { | 7159 if (!func(unwrapped)) { |
7121 unwrapped = kGPBUnrecognizedEnumeratorValue; | 7160 unwrapped = kGPBUnrecognizedEnumeratorValue; |
7122 } | 7161 } |
7123 block([aKey unsignedLongLongValue], unwrapped, stop); | 7162 block([aKey unsignedLongLongValue], unwrapped, stop); |
7124 }]; | 7163 }]; |
7125 } | 7164 } |
7126 | 7165 |
7127 - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary { | 7166 - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary { |
7128 if (otherDictionary) { | 7167 if (otherDictionary) { |
7129 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 7168 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
7130 if (_autocreator) { | 7169 if (_autocreator) { |
7131 GPBAutocreatedDictionaryModified(_autocreator, self); | 7170 GPBAutocreatedDictionaryModified(_autocreator, self); |
7132 } | 7171 } |
7133 } | 7172 } |
7134 } | 7173 } |
7135 | 7174 |
7136 - (void)setRawValue:(int32_t)value forKey:(uint64_t)key { | 7175 - (void)setRawValue:(int32_t)value forKey:(uint64_t)key { |
7137 [_dictionary setObject:@(value) forKey:@(key)]; | 7176 [_dictionary setObject:@(value) forKey:@(key)]; |
7138 if (_autocreator) { | 7177 if (_autocreator) { |
7139 GPBAutocreatedDictionaryModified(_autocreator, self); | 7178 GPBAutocreatedDictionaryModified(_autocreator, self); |
7140 } | 7179 } |
7141 } | 7180 } |
7142 | 7181 |
7143 - (void)removeValueForKey:(uint64_t)aKey { | 7182 - (void)removeEnumForKey:(uint64_t)aKey { |
7144 [_dictionary removeObjectForKey:@(aKey)]; | 7183 [_dictionary removeObjectForKey:@(aKey)]; |
7145 } | 7184 } |
7146 | 7185 |
7147 - (void)removeAll { | 7186 - (void)removeAll { |
7148 [_dictionary removeAllObjects]; | 7187 [_dictionary removeAllObjects]; |
7149 } | 7188 } |
7150 | 7189 |
7151 - (void)setValue:(int32_t)value forKey:(uint64_t)key { | 7190 - (void)setEnum:(int32_t)value forKey:(uint64_t)key { |
7152 if (!_validationFunc(value)) { | 7191 if (!_validationFunc(value)) { |
7153 [NSException raise:NSInvalidArgumentException | 7192 [NSException raise:NSInvalidArgumentException |
7154 format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum
value (%d)", | 7193 format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum
value (%d)", |
7155 value]; | 7194 value]; |
7156 } | 7195 } |
7157 | 7196 |
7158 [_dictionary setObject:@(value) forKey:@(key)]; | 7197 [_dictionary setObject:@(value) forKey:@(key)]; |
7159 if (_autocreator) { | 7198 if (_autocreator) { |
7160 GPBAutocreatedDictionaryModified(_autocreator, self); | 7199 GPBAutocreatedDictionaryModified(_autocreator, self); |
7161 } | 7200 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7246 @"%@: Autocreator must be cleared before release, autocreator: %@", | 7285 @"%@: Autocreator must be cleared before release, autocreator: %@", |
7247 [self class], _autocreator); | 7286 [self class], _autocreator); |
7248 [_dictionary release]; | 7287 [_dictionary release]; |
7249 [super dealloc]; | 7288 [super dealloc]; |
7250 } | 7289 } |
7251 | 7290 |
7252 - (instancetype)copyWithZone:(NSZone *)zone { | 7291 - (instancetype)copyWithZone:(NSZone *)zone { |
7253 return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self
]; | 7292 return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self
]; |
7254 } | 7293 } |
7255 | 7294 |
7256 - (BOOL)isEqual:(GPBUInt64ObjectDictionary *)other { | 7295 - (BOOL)isEqual:(id)other { |
7257 if (self == other) { | 7296 if (self == other) { |
7258 return YES; | 7297 return YES; |
7259 } | 7298 } |
7260 if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) { | 7299 if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) { |
7261 return NO; | 7300 return NO; |
7262 } | 7301 } |
7263 return [_dictionary isEqual:other->_dictionary]; | 7302 GPBUInt64ObjectDictionary *otherDictionary = other; |
| 7303 return [_dictionary isEqual:otherDictionary->_dictionary]; |
7264 } | 7304 } |
7265 | 7305 |
7266 - (NSUInteger)hash { | 7306 - (NSUInteger)hash { |
7267 return _dictionary.count; | 7307 return _dictionary.count; |
7268 } | 7308 } |
7269 | 7309 |
7270 - (NSString *)description { | 7310 - (NSString *)description { |
7271 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 7311 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
7272 } | 7312 } |
7273 | 7313 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7401 // This block of code is generated, do not edit it directly. | 7441 // This block of code is generated, do not edit it directly. |
7402 | 7442 |
7403 #pragma mark - Int64 -> UInt32 | 7443 #pragma mark - Int64 -> UInt32 |
7404 | 7444 |
7405 @implementation GPBInt64UInt32Dictionary { | 7445 @implementation GPBInt64UInt32Dictionary { |
7406 @package | 7446 @package |
7407 NSMutableDictionary *_dictionary; | 7447 NSMutableDictionary *_dictionary; |
7408 } | 7448 } |
7409 | 7449 |
7410 + (instancetype)dictionary { | 7450 + (instancetype)dictionary { |
7411 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 7451 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; |
7412 } | 7452 } |
7413 | 7453 |
7414 + (instancetype)dictionaryWithValue:(uint32_t)value | 7454 + (instancetype)dictionaryWithUInt32:(uint32_t)value |
7415 forKey:(int64_t)key { | 7455 forKey:(int64_t)key { |
7416 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 7456 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
7417 // on to get the type correct. | 7457 // on to get the type correct. |
7418 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithValues:&value | 7458 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithUInt32s:&value |
7419 forKeys:&key | 7459 forKeys:&key |
7420 count:1] autorelease
]; | 7460 count:1] autoreleas
e]; |
7421 } | 7461 } |
7422 | 7462 |
7423 + (instancetype)dictionaryWithValues:(const uint32_t [])values | 7463 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values |
7424 forKeys:(const int64_t [])keys | 7464 forKeys:(const int64_t [])keys |
7425 count:(NSUInteger)count { | 7465 count:(NSUInteger)count { |
7426 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 7466 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
7427 // on to get the type correct. | 7467 // on to get the type correct. |
7428 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithValues:values | 7468 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithUInt32s:values |
7429 forKeys:keys | 7469 forKeys:keys |
7430 count:count] autorel
ease]; | 7470 count:count] autorel
ease]; |
7431 } | 7471 } |
7432 | 7472 |
7433 + (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary
{ | 7473 + (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary
{ |
7434 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 7474 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
7435 // on to get the type correct. | 7475 // on to get the type correct. |
7436 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 7476 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
7437 } | 7477 } |
7438 | 7478 |
7439 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 7479 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
7440 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 7480 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
7441 } | 7481 } |
7442 | 7482 |
7443 - (instancetype)init { | 7483 - (instancetype)init { |
7444 return [self initWithValues:NULL forKeys:NULL count:0]; | 7484 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
7445 } | 7485 } |
7446 | 7486 |
7447 - (instancetype)initWithValues:(const uint32_t [])values | 7487 - (instancetype)initWithUInt32s:(const uint32_t [])values |
7448 forKeys:(const int64_t [])keys | 7488 forKeys:(const int64_t [])keys |
7449 count:(NSUInteger)count { | 7489 count:(NSUInteger)count { |
7450 self = [super init]; | 7490 self = [super init]; |
7451 if (self) { | 7491 if (self) { |
7452 _dictionary = [[NSMutableDictionary alloc] init]; | 7492 _dictionary = [[NSMutableDictionary alloc] init]; |
7453 if (count && values && keys) { | 7493 if (count && values && keys) { |
7454 for (NSUInteger i = 0; i < count; ++i) { | 7494 for (NSUInteger i = 0; i < count; ++i) { |
7455 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 7495 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
7456 } | 7496 } |
7457 } | 7497 } |
7458 } | 7498 } |
7459 return self; | 7499 return self; |
7460 } | 7500 } |
7461 | 7501 |
7462 - (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary { | 7502 - (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary { |
7463 self = [self initWithValues:NULL forKeys:NULL count:0]; | 7503 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; |
7464 if (self) { | 7504 if (self) { |
7465 if (dictionary) { | 7505 if (dictionary) { |
7466 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 7506 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
7467 } | 7507 } |
7468 } | 7508 } |
7469 return self; | 7509 return self; |
7470 } | 7510 } |
7471 | 7511 |
7472 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 7512 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
7473 #pragma unused(numItems) | 7513 #pragma unused(numItems) |
7474 return [self initWithValues:NULL forKeys:NULL count:0]; | 7514 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
7475 } | 7515 } |
7476 | 7516 |
7477 - (void)dealloc { | 7517 - (void)dealloc { |
7478 NSAssert(!_autocreator, | 7518 NSAssert(!_autocreator, |
7479 @"%@: Autocreator must be cleared before release, autocreator: %@", | 7519 @"%@: Autocreator must be cleared before release, autocreator: %@", |
7480 [self class], _autocreator); | 7520 [self class], _autocreator); |
7481 [_dictionary release]; | 7521 [_dictionary release]; |
7482 [super dealloc]; | 7522 [super dealloc]; |
7483 } | 7523 } |
7484 | 7524 |
7485 - (instancetype)copyWithZone:(NSZone *)zone { | 7525 - (instancetype)copyWithZone:(NSZone *)zone { |
7486 return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; | 7526 return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; |
7487 } | 7527 } |
7488 | 7528 |
7489 - (BOOL)isEqual:(GPBInt64UInt32Dictionary *)other { | 7529 - (BOOL)isEqual:(id)other { |
7490 if (self == other) { | 7530 if (self == other) { |
7491 return YES; | 7531 return YES; |
7492 } | 7532 } |
7493 if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) { | 7533 if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) { |
7494 return NO; | 7534 return NO; |
7495 } | 7535 } |
7496 return [_dictionary isEqual:other->_dictionary]; | 7536 GPBInt64UInt32Dictionary *otherDictionary = other; |
| 7537 return [_dictionary isEqual:otherDictionary->_dictionary]; |
7497 } | 7538 } |
7498 | 7539 |
7499 - (NSUInteger)hash { | 7540 - (NSUInteger)hash { |
7500 return _dictionary.count; | 7541 return _dictionary.count; |
7501 } | 7542 } |
7502 | 7543 |
7503 - (NSString *)description { | 7544 - (NSString *)description { |
7504 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 7545 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
7505 } | 7546 } |
7506 | 7547 |
7507 - (NSUInteger)count { | 7548 - (NSUInteger)count { |
7508 return _dictionary.count; | 7549 return _dictionary.count; |
7509 } | 7550 } |
7510 | 7551 |
7511 - (void)enumerateKeysAndValuesUsingBlock: | 7552 - (void)enumerateKeysAndUInt32sUsingBlock: |
7512 (void (^)(int64_t key, uint32_t value, BOOL *stop))block { | 7553 (void (^)(int64_t key, uint32_t value, BOOL *stop))block { |
7513 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 7554 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
7514 NSNumber *aValue, | 7555 NSNumber *aValue, |
7515 BOOL *stop) { | 7556 BOOL *stop) { |
7516 block([aKey longLongValue], [aValue unsignedIntValue], stop); | 7557 block([aKey longLongValue], [aValue unsignedIntValue], stop); |
7517 }]; | 7558 }]; |
7518 } | 7559 } |
7519 | 7560 |
7520 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 7561 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
7521 NSUInteger count = _dictionary.count; | 7562 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7559 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | 7600 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); |
7560 }]; | 7601 }]; |
7561 } | 7602 } |
7562 | 7603 |
7563 - (void)setGPBGenericValue:(GPBGenericValue *)value | 7604 - (void)setGPBGenericValue:(GPBGenericValue *)value |
7564 forGPBGenericValueKey:(GPBGenericValue *)key { | 7605 forGPBGenericValueKey:(GPBGenericValue *)key { |
7565 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)]; | 7606 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)]; |
7566 } | 7607 } |
7567 | 7608 |
7568 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 7609 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
7569 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, uint32_t value, BOOL *st
op) { | 7610 [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, BOOL *s
top) { |
7570 #pragma unused(stop) | 7611 #pragma unused(stop) |
7571 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%u", value]); | 7612 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%u", value]); |
7572 }]; | 7613 }]; |
7573 } | 7614 } |
7574 | 7615 |
7575 - (BOOL)valueForKey:(int64_t)key value:(uint32_t *)value { | 7616 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key { |
7576 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 7617 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
7577 if (wrapped && value) { | 7618 if (wrapped && value) { |
7578 *value = [wrapped unsignedIntValue]; | 7619 *value = [wrapped unsignedIntValue]; |
7579 } | 7620 } |
7580 return (wrapped != NULL); | 7621 return (wrapped != NULL); |
7581 } | 7622 } |
7582 | 7623 |
7583 - (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary { | 7624 - (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary { |
7584 if (otherDictionary) { | 7625 if (otherDictionary) { |
7585 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 7626 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
7586 if (_autocreator) { | 7627 if (_autocreator) { |
7587 GPBAutocreatedDictionaryModified(_autocreator, self); | 7628 GPBAutocreatedDictionaryModified(_autocreator, self); |
7588 } | 7629 } |
7589 } | 7630 } |
7590 } | 7631 } |
7591 | 7632 |
7592 - (void)setValue:(uint32_t)value forKey:(int64_t)key { | 7633 - (void)setUInt32:(uint32_t)value forKey:(int64_t)key { |
7593 [_dictionary setObject:@(value) forKey:@(key)]; | 7634 [_dictionary setObject:@(value) forKey:@(key)]; |
7594 if (_autocreator) { | 7635 if (_autocreator) { |
7595 GPBAutocreatedDictionaryModified(_autocreator, self); | 7636 GPBAutocreatedDictionaryModified(_autocreator, self); |
7596 } | 7637 } |
7597 } | 7638 } |
7598 | 7639 |
7599 - (void)removeValueForKey:(int64_t)aKey { | 7640 - (void)removeUInt32ForKey:(int64_t)aKey { |
7600 [_dictionary removeObjectForKey:@(aKey)]; | 7641 [_dictionary removeObjectForKey:@(aKey)]; |
7601 } | 7642 } |
7602 | 7643 |
7603 - (void)removeAll { | 7644 - (void)removeAll { |
7604 [_dictionary removeAllObjects]; | 7645 [_dictionary removeAllObjects]; |
7605 } | 7646 } |
7606 | 7647 |
7607 @end | 7648 @end |
7608 | 7649 |
7609 #pragma mark - Int64 -> Int32 | 7650 #pragma mark - Int64 -> Int32 |
7610 | 7651 |
7611 @implementation GPBInt64Int32Dictionary { | 7652 @implementation GPBInt64Int32Dictionary { |
7612 @package | 7653 @package |
7613 NSMutableDictionary *_dictionary; | 7654 NSMutableDictionary *_dictionary; |
7614 } | 7655 } |
7615 | 7656 |
7616 + (instancetype)dictionary { | 7657 + (instancetype)dictionary { |
7617 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 7658 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; |
7618 } | 7659 } |
7619 | 7660 |
7620 + (instancetype)dictionaryWithValue:(int32_t)value | 7661 + (instancetype)dictionaryWithInt32:(int32_t)value |
7621 forKey:(int64_t)key { | 7662 forKey:(int64_t)key { |
7622 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 7663 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
7623 // on to get the type correct. | 7664 // on to get the type correct. |
7624 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithValues:&value | 7665 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithInt32s:&value |
7625 forKeys:&key | 7666 forKeys:&key |
7626 count:1] autorelease]
; | 7667 count:1] autorelease]
; |
7627 } | 7668 } |
7628 | 7669 |
7629 + (instancetype)dictionaryWithValues:(const int32_t [])values | 7670 + (instancetype)dictionaryWithInt32s:(const int32_t [])values |
7630 forKeys:(const int64_t [])keys | 7671 forKeys:(const int64_t [])keys |
7631 count:(NSUInteger)count { | 7672 count:(NSUInteger)count { |
7632 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 7673 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
7633 // on to get the type correct. | 7674 // on to get the type correct. |
7634 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithValues:values | 7675 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithInt32s:values |
7635 forKeys:keys | 7676 forKeys:keys |
7636 count:count] autorele
ase]; | 7677 count:count] autorele
ase]; |
7637 } | 7678 } |
7638 | 7679 |
7639 + (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary { | 7680 + (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary { |
7640 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 7681 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
7641 // on to get the type correct. | 7682 // on to get the type correct. |
7642 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 7683 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
7643 } | 7684 } |
7644 | 7685 |
7645 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 7686 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
7646 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 7687 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
7647 } | 7688 } |
7648 | 7689 |
7649 - (instancetype)init { | 7690 - (instancetype)init { |
7650 return [self initWithValues:NULL forKeys:NULL count:0]; | 7691 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
7651 } | 7692 } |
7652 | 7693 |
7653 - (instancetype)initWithValues:(const int32_t [])values | 7694 - (instancetype)initWithInt32s:(const int32_t [])values |
7654 forKeys:(const int64_t [])keys | 7695 forKeys:(const int64_t [])keys |
7655 count:(NSUInteger)count { | 7696 count:(NSUInteger)count { |
7656 self = [super init]; | 7697 self = [super init]; |
7657 if (self) { | 7698 if (self) { |
7658 _dictionary = [[NSMutableDictionary alloc] init]; | 7699 _dictionary = [[NSMutableDictionary alloc] init]; |
7659 if (count && values && keys) { | 7700 if (count && values && keys) { |
7660 for (NSUInteger i = 0; i < count; ++i) { | 7701 for (NSUInteger i = 0; i < count; ++i) { |
7661 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 7702 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
7662 } | 7703 } |
7663 } | 7704 } |
7664 } | 7705 } |
7665 return self; | 7706 return self; |
7666 } | 7707 } |
7667 | 7708 |
7668 - (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary { | 7709 - (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary { |
7669 self = [self initWithValues:NULL forKeys:NULL count:0]; | 7710 self = [self initWithInt32s:NULL forKeys:NULL count:0]; |
7670 if (self) { | 7711 if (self) { |
7671 if (dictionary) { | 7712 if (dictionary) { |
7672 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 7713 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
7673 } | 7714 } |
7674 } | 7715 } |
7675 return self; | 7716 return self; |
7676 } | 7717 } |
7677 | 7718 |
7678 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 7719 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
7679 #pragma unused(numItems) | 7720 #pragma unused(numItems) |
7680 return [self initWithValues:NULL forKeys:NULL count:0]; | 7721 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
7681 } | 7722 } |
7682 | 7723 |
7683 - (void)dealloc { | 7724 - (void)dealloc { |
7684 NSAssert(!_autocreator, | 7725 NSAssert(!_autocreator, |
7685 @"%@: Autocreator must be cleared before release, autocreator: %@", | 7726 @"%@: Autocreator must be cleared before release, autocreator: %@", |
7686 [self class], _autocreator); | 7727 [self class], _autocreator); |
7687 [_dictionary release]; | 7728 [_dictionary release]; |
7688 [super dealloc]; | 7729 [super dealloc]; |
7689 } | 7730 } |
7690 | 7731 |
7691 - (instancetype)copyWithZone:(NSZone *)zone { | 7732 - (instancetype)copyWithZone:(NSZone *)zone { |
7692 return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]; | 7733 return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]; |
7693 } | 7734 } |
7694 | 7735 |
7695 - (BOOL)isEqual:(GPBInt64Int32Dictionary *)other { | 7736 - (BOOL)isEqual:(id)other { |
7696 if (self == other) { | 7737 if (self == other) { |
7697 return YES; | 7738 return YES; |
7698 } | 7739 } |
7699 if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) { | 7740 if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) { |
7700 return NO; | 7741 return NO; |
7701 } | 7742 } |
7702 return [_dictionary isEqual:other->_dictionary]; | 7743 GPBInt64Int32Dictionary *otherDictionary = other; |
| 7744 return [_dictionary isEqual:otherDictionary->_dictionary]; |
7703 } | 7745 } |
7704 | 7746 |
7705 - (NSUInteger)hash { | 7747 - (NSUInteger)hash { |
7706 return _dictionary.count; | 7748 return _dictionary.count; |
7707 } | 7749 } |
7708 | 7750 |
7709 - (NSString *)description { | 7751 - (NSString *)description { |
7710 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 7752 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
7711 } | 7753 } |
7712 | 7754 |
7713 - (NSUInteger)count { | 7755 - (NSUInteger)count { |
7714 return _dictionary.count; | 7756 return _dictionary.count; |
7715 } | 7757 } |
7716 | 7758 |
7717 - (void)enumerateKeysAndValuesUsingBlock: | 7759 - (void)enumerateKeysAndInt32sUsingBlock: |
7718 (void (^)(int64_t key, int32_t value, BOOL *stop))block { | 7760 (void (^)(int64_t key, int32_t value, BOOL *stop))block { |
7719 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 7761 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
7720 NSNumber *aValue, | 7762 NSNumber *aValue, |
7721 BOOL *stop) { | 7763 BOOL *stop) { |
7722 block([aKey longLongValue], [aValue intValue], stop); | 7764 block([aKey longLongValue], [aValue intValue], stop); |
7723 }]; | 7765 }]; |
7724 } | 7766 } |
7725 | 7767 |
7726 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 7768 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
7727 NSUInteger count = _dictionary.count; | 7769 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7765 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | 7807 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); |
7766 }]; | 7808 }]; |
7767 } | 7809 } |
7768 | 7810 |
7769 - (void)setGPBGenericValue:(GPBGenericValue *)value | 7811 - (void)setGPBGenericValue:(GPBGenericValue *)value |
7770 forGPBGenericValueKey:(GPBGenericValue *)key { | 7812 forGPBGenericValueKey:(GPBGenericValue *)key { |
7771 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)]; | 7813 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)]; |
7772 } | 7814 } |
7773 | 7815 |
7774 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 7816 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
7775 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, int32_t value, BOOL *sto
p) { | 7817 [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, BOOL *sto
p) { |
7776 #pragma unused(stop) | 7818 #pragma unused(stop) |
7777 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%d", value]); | 7819 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%d", value]); |
7778 }]; | 7820 }]; |
7779 } | 7821 } |
7780 | 7822 |
7781 - (BOOL)valueForKey:(int64_t)key value:(int32_t *)value { | 7823 - (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key { |
7782 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 7824 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
7783 if (wrapped && value) { | 7825 if (wrapped && value) { |
7784 *value = [wrapped intValue]; | 7826 *value = [wrapped intValue]; |
7785 } | 7827 } |
7786 return (wrapped != NULL); | 7828 return (wrapped != NULL); |
7787 } | 7829 } |
7788 | 7830 |
7789 - (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary { | 7831 - (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary { |
7790 if (otherDictionary) { | 7832 if (otherDictionary) { |
7791 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 7833 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
7792 if (_autocreator) { | 7834 if (_autocreator) { |
7793 GPBAutocreatedDictionaryModified(_autocreator, self); | 7835 GPBAutocreatedDictionaryModified(_autocreator, self); |
7794 } | 7836 } |
7795 } | 7837 } |
7796 } | 7838 } |
7797 | 7839 |
7798 - (void)setValue:(int32_t)value forKey:(int64_t)key { | 7840 - (void)setInt32:(int32_t)value forKey:(int64_t)key { |
7799 [_dictionary setObject:@(value) forKey:@(key)]; | 7841 [_dictionary setObject:@(value) forKey:@(key)]; |
7800 if (_autocreator) { | 7842 if (_autocreator) { |
7801 GPBAutocreatedDictionaryModified(_autocreator, self); | 7843 GPBAutocreatedDictionaryModified(_autocreator, self); |
7802 } | 7844 } |
7803 } | 7845 } |
7804 | 7846 |
7805 - (void)removeValueForKey:(int64_t)aKey { | 7847 - (void)removeInt32ForKey:(int64_t)aKey { |
7806 [_dictionary removeObjectForKey:@(aKey)]; | 7848 [_dictionary removeObjectForKey:@(aKey)]; |
7807 } | 7849 } |
7808 | 7850 |
7809 - (void)removeAll { | 7851 - (void)removeAll { |
7810 [_dictionary removeAllObjects]; | 7852 [_dictionary removeAllObjects]; |
7811 } | 7853 } |
7812 | 7854 |
7813 @end | 7855 @end |
7814 | 7856 |
7815 #pragma mark - Int64 -> UInt64 | 7857 #pragma mark - Int64 -> UInt64 |
7816 | 7858 |
7817 @implementation GPBInt64UInt64Dictionary { | 7859 @implementation GPBInt64UInt64Dictionary { |
7818 @package | 7860 @package |
7819 NSMutableDictionary *_dictionary; | 7861 NSMutableDictionary *_dictionary; |
7820 } | 7862 } |
7821 | 7863 |
7822 + (instancetype)dictionary { | 7864 + (instancetype)dictionary { |
7823 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 7865 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; |
7824 } | 7866 } |
7825 | 7867 |
7826 + (instancetype)dictionaryWithValue:(uint64_t)value | 7868 + (instancetype)dictionaryWithUInt64:(uint64_t)value |
7827 forKey:(int64_t)key { | 7869 forKey:(int64_t)key { |
7828 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 7870 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
7829 // on to get the type correct. | 7871 // on to get the type correct. |
7830 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithValues:&value | 7872 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithUInt64s:&value |
7831 forKeys:&key | 7873 forKeys:&key |
7832 count:1] autorelease
]; | 7874 count:1] autoreleas
e]; |
7833 } | 7875 } |
7834 | 7876 |
7835 + (instancetype)dictionaryWithValues:(const uint64_t [])values | 7877 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values |
7836 forKeys:(const int64_t [])keys | 7878 forKeys:(const int64_t [])keys |
7837 count:(NSUInteger)count { | 7879 count:(NSUInteger)count { |
7838 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 7880 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
7839 // on to get the type correct. | 7881 // on to get the type correct. |
7840 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithValues:values | 7882 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithUInt64s:values |
7841 forKeys:keys | 7883 forKeys:keys |
7842 count:count] autorel
ease]; | 7884 count:count] autorel
ease]; |
7843 } | 7885 } |
7844 | 7886 |
7845 + (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary
{ | 7887 + (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary
{ |
7846 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 7888 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
7847 // on to get the type correct. | 7889 // on to get the type correct. |
7848 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 7890 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
7849 } | 7891 } |
7850 | 7892 |
7851 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 7893 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
7852 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 7894 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
7853 } | 7895 } |
7854 | 7896 |
7855 - (instancetype)init { | 7897 - (instancetype)init { |
7856 return [self initWithValues:NULL forKeys:NULL count:0]; | 7898 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
7857 } | 7899 } |
7858 | 7900 |
7859 - (instancetype)initWithValues:(const uint64_t [])values | 7901 - (instancetype)initWithUInt64s:(const uint64_t [])values |
7860 forKeys:(const int64_t [])keys | 7902 forKeys:(const int64_t [])keys |
7861 count:(NSUInteger)count { | 7903 count:(NSUInteger)count { |
7862 self = [super init]; | 7904 self = [super init]; |
7863 if (self) { | 7905 if (self) { |
7864 _dictionary = [[NSMutableDictionary alloc] init]; | 7906 _dictionary = [[NSMutableDictionary alloc] init]; |
7865 if (count && values && keys) { | 7907 if (count && values && keys) { |
7866 for (NSUInteger i = 0; i < count; ++i) { | 7908 for (NSUInteger i = 0; i < count; ++i) { |
7867 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 7909 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
7868 } | 7910 } |
7869 } | 7911 } |
7870 } | 7912 } |
7871 return self; | 7913 return self; |
7872 } | 7914 } |
7873 | 7915 |
7874 - (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary { | 7916 - (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary { |
7875 self = [self initWithValues:NULL forKeys:NULL count:0]; | 7917 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; |
7876 if (self) { | 7918 if (self) { |
7877 if (dictionary) { | 7919 if (dictionary) { |
7878 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 7920 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
7879 } | 7921 } |
7880 } | 7922 } |
7881 return self; | 7923 return self; |
7882 } | 7924 } |
7883 | 7925 |
7884 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 7926 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
7885 #pragma unused(numItems) | 7927 #pragma unused(numItems) |
7886 return [self initWithValues:NULL forKeys:NULL count:0]; | 7928 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
7887 } | 7929 } |
7888 | 7930 |
7889 - (void)dealloc { | 7931 - (void)dealloc { |
7890 NSAssert(!_autocreator, | 7932 NSAssert(!_autocreator, |
7891 @"%@: Autocreator must be cleared before release, autocreator: %@", | 7933 @"%@: Autocreator must be cleared before release, autocreator: %@", |
7892 [self class], _autocreator); | 7934 [self class], _autocreator); |
7893 [_dictionary release]; | 7935 [_dictionary release]; |
7894 [super dealloc]; | 7936 [super dealloc]; |
7895 } | 7937 } |
7896 | 7938 |
7897 - (instancetype)copyWithZone:(NSZone *)zone { | 7939 - (instancetype)copyWithZone:(NSZone *)zone { |
7898 return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; | 7940 return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; |
7899 } | 7941 } |
7900 | 7942 |
7901 - (BOOL)isEqual:(GPBInt64UInt64Dictionary *)other { | 7943 - (BOOL)isEqual:(id)other { |
7902 if (self == other) { | 7944 if (self == other) { |
7903 return YES; | 7945 return YES; |
7904 } | 7946 } |
7905 if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) { | 7947 if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) { |
7906 return NO; | 7948 return NO; |
7907 } | 7949 } |
7908 return [_dictionary isEqual:other->_dictionary]; | 7950 GPBInt64UInt64Dictionary *otherDictionary = other; |
| 7951 return [_dictionary isEqual:otherDictionary->_dictionary]; |
7909 } | 7952 } |
7910 | 7953 |
7911 - (NSUInteger)hash { | 7954 - (NSUInteger)hash { |
7912 return _dictionary.count; | 7955 return _dictionary.count; |
7913 } | 7956 } |
7914 | 7957 |
7915 - (NSString *)description { | 7958 - (NSString *)description { |
7916 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 7959 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
7917 } | 7960 } |
7918 | 7961 |
7919 - (NSUInteger)count { | 7962 - (NSUInteger)count { |
7920 return _dictionary.count; | 7963 return _dictionary.count; |
7921 } | 7964 } |
7922 | 7965 |
7923 - (void)enumerateKeysAndValuesUsingBlock: | 7966 - (void)enumerateKeysAndUInt64sUsingBlock: |
7924 (void (^)(int64_t key, uint64_t value, BOOL *stop))block { | 7967 (void (^)(int64_t key, uint64_t value, BOOL *stop))block { |
7925 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 7968 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
7926 NSNumber *aValue, | 7969 NSNumber *aValue, |
7927 BOOL *stop) { | 7970 BOOL *stop) { |
7928 block([aKey longLongValue], [aValue unsignedLongLongValue], stop); | 7971 block([aKey longLongValue], [aValue unsignedLongLongValue], stop); |
7929 }]; | 7972 }]; |
7930 } | 7973 } |
7931 | 7974 |
7932 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 7975 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
7933 NSUInteger count = _dictionary.count; | 7976 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7971 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | 8014 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); |
7972 }]; | 8015 }]; |
7973 } | 8016 } |
7974 | 8017 |
7975 - (void)setGPBGenericValue:(GPBGenericValue *)value | 8018 - (void)setGPBGenericValue:(GPBGenericValue *)value |
7976 forGPBGenericValueKey:(GPBGenericValue *)key { | 8019 forGPBGenericValueKey:(GPBGenericValue *)key { |
7977 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)]; | 8020 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)]; |
7978 } | 8021 } |
7979 | 8022 |
7980 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 8023 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
7981 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, uint64_t value, BOOL *st
op) { | 8024 [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, BOOL *s
top) { |
7982 #pragma unused(stop) | 8025 #pragma unused(stop) |
7983 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%llu", value]); | 8026 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%llu", value]); |
7984 }]; | 8027 }]; |
7985 } | 8028 } |
7986 | 8029 |
7987 - (BOOL)valueForKey:(int64_t)key value:(uint64_t *)value { | 8030 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key { |
7988 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 8031 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
7989 if (wrapped && value) { | 8032 if (wrapped && value) { |
7990 *value = [wrapped unsignedLongLongValue]; | 8033 *value = [wrapped unsignedLongLongValue]; |
7991 } | 8034 } |
7992 return (wrapped != NULL); | 8035 return (wrapped != NULL); |
7993 } | 8036 } |
7994 | 8037 |
7995 - (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary { | 8038 - (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary { |
7996 if (otherDictionary) { | 8039 if (otherDictionary) { |
7997 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 8040 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
7998 if (_autocreator) { | 8041 if (_autocreator) { |
7999 GPBAutocreatedDictionaryModified(_autocreator, self); | 8042 GPBAutocreatedDictionaryModified(_autocreator, self); |
8000 } | 8043 } |
8001 } | 8044 } |
8002 } | 8045 } |
8003 | 8046 |
8004 - (void)setValue:(uint64_t)value forKey:(int64_t)key { | 8047 - (void)setUInt64:(uint64_t)value forKey:(int64_t)key { |
8005 [_dictionary setObject:@(value) forKey:@(key)]; | 8048 [_dictionary setObject:@(value) forKey:@(key)]; |
8006 if (_autocreator) { | 8049 if (_autocreator) { |
8007 GPBAutocreatedDictionaryModified(_autocreator, self); | 8050 GPBAutocreatedDictionaryModified(_autocreator, self); |
8008 } | 8051 } |
8009 } | 8052 } |
8010 | 8053 |
8011 - (void)removeValueForKey:(int64_t)aKey { | 8054 - (void)removeUInt64ForKey:(int64_t)aKey { |
8012 [_dictionary removeObjectForKey:@(aKey)]; | 8055 [_dictionary removeObjectForKey:@(aKey)]; |
8013 } | 8056 } |
8014 | 8057 |
8015 - (void)removeAll { | 8058 - (void)removeAll { |
8016 [_dictionary removeAllObjects]; | 8059 [_dictionary removeAllObjects]; |
8017 } | 8060 } |
8018 | 8061 |
8019 @end | 8062 @end |
8020 | 8063 |
8021 #pragma mark - Int64 -> Int64 | 8064 #pragma mark - Int64 -> Int64 |
8022 | 8065 |
8023 @implementation GPBInt64Int64Dictionary { | 8066 @implementation GPBInt64Int64Dictionary { |
8024 @package | 8067 @package |
8025 NSMutableDictionary *_dictionary; | 8068 NSMutableDictionary *_dictionary; |
8026 } | 8069 } |
8027 | 8070 |
8028 + (instancetype)dictionary { | 8071 + (instancetype)dictionary { |
8029 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 8072 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; |
8030 } | 8073 } |
8031 | 8074 |
8032 + (instancetype)dictionaryWithValue:(int64_t)value | 8075 + (instancetype)dictionaryWithInt64:(int64_t)value |
8033 forKey:(int64_t)key { | 8076 forKey:(int64_t)key { |
8034 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 8077 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
8035 // on to get the type correct. | 8078 // on to get the type correct. |
8036 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithValues:&value | 8079 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithInt64s:&value |
8037 forKeys:&key | 8080 forKeys:&key |
8038 count:1] autorelease]
; | 8081 count:1] autorelease]
; |
8039 } | 8082 } |
8040 | 8083 |
8041 + (instancetype)dictionaryWithValues:(const int64_t [])values | 8084 + (instancetype)dictionaryWithInt64s:(const int64_t [])values |
8042 forKeys:(const int64_t [])keys | 8085 forKeys:(const int64_t [])keys |
8043 count:(NSUInteger)count { | 8086 count:(NSUInteger)count { |
8044 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 8087 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
8045 // on to get the type correct. | 8088 // on to get the type correct. |
8046 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithValues:values | 8089 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithInt64s:values |
8047 forKeys:keys | 8090 forKeys:keys |
8048 count:count] autorele
ase]; | 8091 count:count] autorele
ase]; |
8049 } | 8092 } |
8050 | 8093 |
8051 + (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary { | 8094 + (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary { |
8052 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 8095 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
8053 // on to get the type correct. | 8096 // on to get the type correct. |
8054 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 8097 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
8055 } | 8098 } |
8056 | 8099 |
8057 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 8100 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
8058 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 8101 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
8059 } | 8102 } |
8060 | 8103 |
8061 - (instancetype)init { | 8104 - (instancetype)init { |
8062 return [self initWithValues:NULL forKeys:NULL count:0]; | 8105 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
8063 } | 8106 } |
8064 | 8107 |
8065 - (instancetype)initWithValues:(const int64_t [])values | 8108 - (instancetype)initWithInt64s:(const int64_t [])values |
8066 forKeys:(const int64_t [])keys | 8109 forKeys:(const int64_t [])keys |
8067 count:(NSUInteger)count { | 8110 count:(NSUInteger)count { |
8068 self = [super init]; | 8111 self = [super init]; |
8069 if (self) { | 8112 if (self) { |
8070 _dictionary = [[NSMutableDictionary alloc] init]; | 8113 _dictionary = [[NSMutableDictionary alloc] init]; |
8071 if (count && values && keys) { | 8114 if (count && values && keys) { |
8072 for (NSUInteger i = 0; i < count; ++i) { | 8115 for (NSUInteger i = 0; i < count; ++i) { |
8073 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 8116 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
8074 } | 8117 } |
8075 } | 8118 } |
8076 } | 8119 } |
8077 return self; | 8120 return self; |
8078 } | 8121 } |
8079 | 8122 |
8080 - (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary { | 8123 - (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary { |
8081 self = [self initWithValues:NULL forKeys:NULL count:0]; | 8124 self = [self initWithInt64s:NULL forKeys:NULL count:0]; |
8082 if (self) { | 8125 if (self) { |
8083 if (dictionary) { | 8126 if (dictionary) { |
8084 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 8127 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
8085 } | 8128 } |
8086 } | 8129 } |
8087 return self; | 8130 return self; |
8088 } | 8131 } |
8089 | 8132 |
8090 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 8133 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
8091 #pragma unused(numItems) | 8134 #pragma unused(numItems) |
8092 return [self initWithValues:NULL forKeys:NULL count:0]; | 8135 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
8093 } | 8136 } |
8094 | 8137 |
8095 - (void)dealloc { | 8138 - (void)dealloc { |
8096 NSAssert(!_autocreator, | 8139 NSAssert(!_autocreator, |
8097 @"%@: Autocreator must be cleared before release, autocreator: %@", | 8140 @"%@: Autocreator must be cleared before release, autocreator: %@", |
8098 [self class], _autocreator); | 8141 [self class], _autocreator); |
8099 [_dictionary release]; | 8142 [_dictionary release]; |
8100 [super dealloc]; | 8143 [super dealloc]; |
8101 } | 8144 } |
8102 | 8145 |
8103 - (instancetype)copyWithZone:(NSZone *)zone { | 8146 - (instancetype)copyWithZone:(NSZone *)zone { |
8104 return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]; | 8147 return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]; |
8105 } | 8148 } |
8106 | 8149 |
8107 - (BOOL)isEqual:(GPBInt64Int64Dictionary *)other { | 8150 - (BOOL)isEqual:(id)other { |
8108 if (self == other) { | 8151 if (self == other) { |
8109 return YES; | 8152 return YES; |
8110 } | 8153 } |
8111 if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) { | 8154 if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) { |
8112 return NO; | 8155 return NO; |
8113 } | 8156 } |
8114 return [_dictionary isEqual:other->_dictionary]; | 8157 GPBInt64Int64Dictionary *otherDictionary = other; |
| 8158 return [_dictionary isEqual:otherDictionary->_dictionary]; |
8115 } | 8159 } |
8116 | 8160 |
8117 - (NSUInteger)hash { | 8161 - (NSUInteger)hash { |
8118 return _dictionary.count; | 8162 return _dictionary.count; |
8119 } | 8163 } |
8120 | 8164 |
8121 - (NSString *)description { | 8165 - (NSString *)description { |
8122 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 8166 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
8123 } | 8167 } |
8124 | 8168 |
8125 - (NSUInteger)count { | 8169 - (NSUInteger)count { |
8126 return _dictionary.count; | 8170 return _dictionary.count; |
8127 } | 8171 } |
8128 | 8172 |
8129 - (void)enumerateKeysAndValuesUsingBlock: | 8173 - (void)enumerateKeysAndInt64sUsingBlock: |
8130 (void (^)(int64_t key, int64_t value, BOOL *stop))block { | 8174 (void (^)(int64_t key, int64_t value, BOOL *stop))block { |
8131 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 8175 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
8132 NSNumber *aValue, | 8176 NSNumber *aValue, |
8133 BOOL *stop) { | 8177 BOOL *stop) { |
8134 block([aKey longLongValue], [aValue longLongValue], stop); | 8178 block([aKey longLongValue], [aValue longLongValue], stop); |
8135 }]; | 8179 }]; |
8136 } | 8180 } |
8137 | 8181 |
8138 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 8182 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
8139 NSUInteger count = _dictionary.count; | 8183 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8177 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | 8221 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); |
8178 }]; | 8222 }]; |
8179 } | 8223 } |
8180 | 8224 |
8181 - (void)setGPBGenericValue:(GPBGenericValue *)value | 8225 - (void)setGPBGenericValue:(GPBGenericValue *)value |
8182 forGPBGenericValueKey:(GPBGenericValue *)key { | 8226 forGPBGenericValueKey:(GPBGenericValue *)key { |
8183 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)]; | 8227 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)]; |
8184 } | 8228 } |
8185 | 8229 |
8186 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 8230 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
8187 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, int64_t value, BOOL *sto
p) { | 8231 [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, BOOL *sto
p) { |
8188 #pragma unused(stop) | 8232 #pragma unused(stop) |
8189 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%lld", value]); | 8233 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%lld", value]); |
8190 }]; | 8234 }]; |
8191 } | 8235 } |
8192 | 8236 |
8193 - (BOOL)valueForKey:(int64_t)key value:(int64_t *)value { | 8237 - (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key { |
8194 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 8238 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
8195 if (wrapped && value) { | 8239 if (wrapped && value) { |
8196 *value = [wrapped longLongValue]; | 8240 *value = [wrapped longLongValue]; |
8197 } | 8241 } |
8198 return (wrapped != NULL); | 8242 return (wrapped != NULL); |
8199 } | 8243 } |
8200 | 8244 |
8201 - (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary { | 8245 - (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary { |
8202 if (otherDictionary) { | 8246 if (otherDictionary) { |
8203 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 8247 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
8204 if (_autocreator) { | 8248 if (_autocreator) { |
8205 GPBAutocreatedDictionaryModified(_autocreator, self); | 8249 GPBAutocreatedDictionaryModified(_autocreator, self); |
8206 } | 8250 } |
8207 } | 8251 } |
8208 } | 8252 } |
8209 | 8253 |
8210 - (void)setValue:(int64_t)value forKey:(int64_t)key { | 8254 - (void)setInt64:(int64_t)value forKey:(int64_t)key { |
8211 [_dictionary setObject:@(value) forKey:@(key)]; | 8255 [_dictionary setObject:@(value) forKey:@(key)]; |
8212 if (_autocreator) { | 8256 if (_autocreator) { |
8213 GPBAutocreatedDictionaryModified(_autocreator, self); | 8257 GPBAutocreatedDictionaryModified(_autocreator, self); |
8214 } | 8258 } |
8215 } | 8259 } |
8216 | 8260 |
8217 - (void)removeValueForKey:(int64_t)aKey { | 8261 - (void)removeInt64ForKey:(int64_t)aKey { |
8218 [_dictionary removeObjectForKey:@(aKey)]; | 8262 [_dictionary removeObjectForKey:@(aKey)]; |
8219 } | 8263 } |
8220 | 8264 |
8221 - (void)removeAll { | 8265 - (void)removeAll { |
8222 [_dictionary removeAllObjects]; | 8266 [_dictionary removeAllObjects]; |
8223 } | 8267 } |
8224 | 8268 |
8225 @end | 8269 @end |
8226 | 8270 |
8227 #pragma mark - Int64 -> Bool | 8271 #pragma mark - Int64 -> Bool |
8228 | 8272 |
8229 @implementation GPBInt64BoolDictionary { | 8273 @implementation GPBInt64BoolDictionary { |
8230 @package | 8274 @package |
8231 NSMutableDictionary *_dictionary; | 8275 NSMutableDictionary *_dictionary; |
8232 } | 8276 } |
8233 | 8277 |
8234 + (instancetype)dictionary { | 8278 + (instancetype)dictionary { |
8235 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 8279 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; |
8236 } | 8280 } |
8237 | 8281 |
8238 + (instancetype)dictionaryWithValue:(BOOL)value | 8282 + (instancetype)dictionaryWithBool:(BOOL)value |
8239 forKey:(int64_t)key { | 8283 forKey:(int64_t)key { |
8240 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 8284 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
8241 // on to get the type correct. | 8285 // on to get the type correct. |
8242 return [[(GPBInt64BoolDictionary*)[self alloc] initWithValues:&value | 8286 return [[(GPBInt64BoolDictionary*)[self alloc] initWithBools:&value |
8243 forKeys:&key | 8287 forKeys:&key |
8244 count:1] autorelease]; | 8288 count:1] autorelease]; |
8245 } | 8289 } |
8246 | 8290 |
8247 + (instancetype)dictionaryWithValues:(const BOOL [])values | 8291 + (instancetype)dictionaryWithBools:(const BOOL [])values |
8248 forKeys:(const int64_t [])keys | 8292 forKeys:(const int64_t [])keys |
8249 count:(NSUInteger)count { | 8293 count:(NSUInteger)count { |
8250 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 8294 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
8251 // on to get the type correct. | 8295 // on to get the type correct. |
8252 return [[(GPBInt64BoolDictionary*)[self alloc] initWithValues:values | 8296 return [[(GPBInt64BoolDictionary*)[self alloc] initWithBools:values |
8253 forKeys:keys | 8297 forKeys:keys |
8254 count:count] autorelea
se]; | 8298 count:count] autorelea
se]; |
8255 } | 8299 } |
8256 | 8300 |
8257 + (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary { | 8301 + (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary { |
8258 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 8302 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
8259 // on to get the type correct. | 8303 // on to get the type correct. |
8260 return [[(GPBInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 8304 return [[(GPBInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
8261 } | 8305 } |
8262 | 8306 |
8263 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 8307 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
8264 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 8308 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
8265 } | 8309 } |
8266 | 8310 |
8267 - (instancetype)init { | 8311 - (instancetype)init { |
8268 return [self initWithValues:NULL forKeys:NULL count:0]; | 8312 return [self initWithBools:NULL forKeys:NULL count:0]; |
8269 } | 8313 } |
8270 | 8314 |
8271 - (instancetype)initWithValues:(const BOOL [])values | 8315 - (instancetype)initWithBools:(const BOOL [])values |
8272 forKeys:(const int64_t [])keys | 8316 forKeys:(const int64_t [])keys |
8273 count:(NSUInteger)count { | 8317 count:(NSUInteger)count { |
8274 self = [super init]; | 8318 self = [super init]; |
8275 if (self) { | 8319 if (self) { |
8276 _dictionary = [[NSMutableDictionary alloc] init]; | 8320 _dictionary = [[NSMutableDictionary alloc] init]; |
8277 if (count && values && keys) { | 8321 if (count && values && keys) { |
8278 for (NSUInteger i = 0; i < count; ++i) { | 8322 for (NSUInteger i = 0; i < count; ++i) { |
8279 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 8323 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
8280 } | 8324 } |
8281 } | 8325 } |
8282 } | 8326 } |
8283 return self; | 8327 return self; |
8284 } | 8328 } |
8285 | 8329 |
8286 - (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary { | 8330 - (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary { |
8287 self = [self initWithValues:NULL forKeys:NULL count:0]; | 8331 self = [self initWithBools:NULL forKeys:NULL count:0]; |
8288 if (self) { | 8332 if (self) { |
8289 if (dictionary) { | 8333 if (dictionary) { |
8290 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 8334 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
8291 } | 8335 } |
8292 } | 8336 } |
8293 return self; | 8337 return self; |
8294 } | 8338 } |
8295 | 8339 |
8296 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 8340 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
8297 #pragma unused(numItems) | 8341 #pragma unused(numItems) |
8298 return [self initWithValues:NULL forKeys:NULL count:0]; | 8342 return [self initWithBools:NULL forKeys:NULL count:0]; |
8299 } | 8343 } |
8300 | 8344 |
8301 - (void)dealloc { | 8345 - (void)dealloc { |
8302 NSAssert(!_autocreator, | 8346 NSAssert(!_autocreator, |
8303 @"%@: Autocreator must be cleared before release, autocreator: %@", | 8347 @"%@: Autocreator must be cleared before release, autocreator: %@", |
8304 [self class], _autocreator); | 8348 [self class], _autocreator); |
8305 [_dictionary release]; | 8349 [_dictionary release]; |
8306 [super dealloc]; | 8350 [super dealloc]; |
8307 } | 8351 } |
8308 | 8352 |
8309 - (instancetype)copyWithZone:(NSZone *)zone { | 8353 - (instancetype)copyWithZone:(NSZone *)zone { |
8310 return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; | 8354 return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; |
8311 } | 8355 } |
8312 | 8356 |
8313 - (BOOL)isEqual:(GPBInt64BoolDictionary *)other { | 8357 - (BOOL)isEqual:(id)other { |
8314 if (self == other) { | 8358 if (self == other) { |
8315 return YES; | 8359 return YES; |
8316 } | 8360 } |
8317 if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) { | 8361 if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) { |
8318 return NO; | 8362 return NO; |
8319 } | 8363 } |
8320 return [_dictionary isEqual:other->_dictionary]; | 8364 GPBInt64BoolDictionary *otherDictionary = other; |
| 8365 return [_dictionary isEqual:otherDictionary->_dictionary]; |
8321 } | 8366 } |
8322 | 8367 |
8323 - (NSUInteger)hash { | 8368 - (NSUInteger)hash { |
8324 return _dictionary.count; | 8369 return _dictionary.count; |
8325 } | 8370 } |
8326 | 8371 |
8327 - (NSString *)description { | 8372 - (NSString *)description { |
8328 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 8373 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
8329 } | 8374 } |
8330 | 8375 |
8331 - (NSUInteger)count { | 8376 - (NSUInteger)count { |
8332 return _dictionary.count; | 8377 return _dictionary.count; |
8333 } | 8378 } |
8334 | 8379 |
8335 - (void)enumerateKeysAndValuesUsingBlock: | 8380 - (void)enumerateKeysAndBoolsUsingBlock: |
8336 (void (^)(int64_t key, BOOL value, BOOL *stop))block { | 8381 (void (^)(int64_t key, BOOL value, BOOL *stop))block { |
8337 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 8382 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
8338 NSNumber *aValue, | 8383 NSNumber *aValue, |
8339 BOOL *stop) { | 8384 BOOL *stop) { |
8340 block([aKey longLongValue], [aValue boolValue], stop); | 8385 block([aKey longLongValue], [aValue boolValue], stop); |
8341 }]; | 8386 }]; |
8342 } | 8387 } |
8343 | 8388 |
8344 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 8389 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
8345 NSUInteger count = _dictionary.count; | 8390 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8383 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | 8428 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); |
8384 }]; | 8429 }]; |
8385 } | 8430 } |
8386 | 8431 |
8387 - (void)setGPBGenericValue:(GPBGenericValue *)value | 8432 - (void)setGPBGenericValue:(GPBGenericValue *)value |
8388 forGPBGenericValueKey:(GPBGenericValue *)key { | 8433 forGPBGenericValueKey:(GPBGenericValue *)key { |
8389 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)]; | 8434 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)]; |
8390 } | 8435 } |
8391 | 8436 |
8392 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 8437 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
8393 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, BOOL value, BOOL *stop)
{ | 8438 [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, BOOL *stop) { |
8394 #pragma unused(stop) | 8439 #pragma unused(stop) |
8395 block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false
")); | 8440 block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false
")); |
8396 }]; | 8441 }]; |
8397 } | 8442 } |
8398 | 8443 |
8399 - (BOOL)valueForKey:(int64_t)key value:(BOOL *)value { | 8444 - (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key { |
8400 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 8445 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
8401 if (wrapped && value) { | 8446 if (wrapped && value) { |
8402 *value = [wrapped boolValue]; | 8447 *value = [wrapped boolValue]; |
8403 } | 8448 } |
8404 return (wrapped != NULL); | 8449 return (wrapped != NULL); |
8405 } | 8450 } |
8406 | 8451 |
8407 - (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary { | 8452 - (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary { |
8408 if (otherDictionary) { | 8453 if (otherDictionary) { |
8409 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 8454 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
8410 if (_autocreator) { | 8455 if (_autocreator) { |
8411 GPBAutocreatedDictionaryModified(_autocreator, self); | 8456 GPBAutocreatedDictionaryModified(_autocreator, self); |
8412 } | 8457 } |
8413 } | 8458 } |
8414 } | 8459 } |
8415 | 8460 |
8416 - (void)setValue:(BOOL)value forKey:(int64_t)key { | 8461 - (void)setBool:(BOOL)value forKey:(int64_t)key { |
8417 [_dictionary setObject:@(value) forKey:@(key)]; | 8462 [_dictionary setObject:@(value) forKey:@(key)]; |
8418 if (_autocreator) { | 8463 if (_autocreator) { |
8419 GPBAutocreatedDictionaryModified(_autocreator, self); | 8464 GPBAutocreatedDictionaryModified(_autocreator, self); |
8420 } | 8465 } |
8421 } | 8466 } |
8422 | 8467 |
8423 - (void)removeValueForKey:(int64_t)aKey { | 8468 - (void)removeBoolForKey:(int64_t)aKey { |
8424 [_dictionary removeObjectForKey:@(aKey)]; | 8469 [_dictionary removeObjectForKey:@(aKey)]; |
8425 } | 8470 } |
8426 | 8471 |
8427 - (void)removeAll { | 8472 - (void)removeAll { |
8428 [_dictionary removeAllObjects]; | 8473 [_dictionary removeAllObjects]; |
8429 } | 8474 } |
8430 | 8475 |
8431 @end | 8476 @end |
8432 | 8477 |
8433 #pragma mark - Int64 -> Float | 8478 #pragma mark - Int64 -> Float |
8434 | 8479 |
8435 @implementation GPBInt64FloatDictionary { | 8480 @implementation GPBInt64FloatDictionary { |
8436 @package | 8481 @package |
8437 NSMutableDictionary *_dictionary; | 8482 NSMutableDictionary *_dictionary; |
8438 } | 8483 } |
8439 | 8484 |
8440 + (instancetype)dictionary { | 8485 + (instancetype)dictionary { |
8441 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 8486 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; |
8442 } | 8487 } |
8443 | 8488 |
8444 + (instancetype)dictionaryWithValue:(float)value | 8489 + (instancetype)dictionaryWithFloat:(float)value |
8445 forKey:(int64_t)key { | 8490 forKey:(int64_t)key { |
8446 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 8491 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
8447 // on to get the type correct. | 8492 // on to get the type correct. |
8448 return [[(GPBInt64FloatDictionary*)[self alloc] initWithValues:&value | 8493 return [[(GPBInt64FloatDictionary*)[self alloc] initWithFloats:&value |
8449 forKeys:&key | 8494 forKeys:&key |
8450 count:1] autorelease]
; | 8495 count:1] autorelease]
; |
8451 } | 8496 } |
8452 | 8497 |
8453 + (instancetype)dictionaryWithValues:(const float [])values | 8498 + (instancetype)dictionaryWithFloats:(const float [])values |
8454 forKeys:(const int64_t [])keys | 8499 forKeys:(const int64_t [])keys |
8455 count:(NSUInteger)count { | 8500 count:(NSUInteger)count { |
8456 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 8501 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
8457 // on to get the type correct. | 8502 // on to get the type correct. |
8458 return [[(GPBInt64FloatDictionary*)[self alloc] initWithValues:values | 8503 return [[(GPBInt64FloatDictionary*)[self alloc] initWithFloats:values |
8459 forKeys:keys | 8504 forKeys:keys |
8460 count:count] autorele
ase]; | 8505 count:count] autorele
ase]; |
8461 } | 8506 } |
8462 | 8507 |
8463 + (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary { | 8508 + (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary { |
8464 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 8509 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
8465 // on to get the type correct. | 8510 // on to get the type correct. |
8466 return [[(GPBInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 8511 return [[(GPBInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
8467 } | 8512 } |
8468 | 8513 |
8469 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 8514 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
8470 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 8515 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
8471 } | 8516 } |
8472 | 8517 |
8473 - (instancetype)init { | 8518 - (instancetype)init { |
8474 return [self initWithValues:NULL forKeys:NULL count:0]; | 8519 return [self initWithFloats:NULL forKeys:NULL count:0]; |
8475 } | 8520 } |
8476 | 8521 |
8477 - (instancetype)initWithValues:(const float [])values | 8522 - (instancetype)initWithFloats:(const float [])values |
8478 forKeys:(const int64_t [])keys | 8523 forKeys:(const int64_t [])keys |
8479 count:(NSUInteger)count { | 8524 count:(NSUInteger)count { |
8480 self = [super init]; | 8525 self = [super init]; |
8481 if (self) { | 8526 if (self) { |
8482 _dictionary = [[NSMutableDictionary alloc] init]; | 8527 _dictionary = [[NSMutableDictionary alloc] init]; |
8483 if (count && values && keys) { | 8528 if (count && values && keys) { |
8484 for (NSUInteger i = 0; i < count; ++i) { | 8529 for (NSUInteger i = 0; i < count; ++i) { |
8485 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 8530 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
8486 } | 8531 } |
8487 } | 8532 } |
8488 } | 8533 } |
8489 return self; | 8534 return self; |
8490 } | 8535 } |
8491 | 8536 |
8492 - (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary { | 8537 - (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary { |
8493 self = [self initWithValues:NULL forKeys:NULL count:0]; | 8538 self = [self initWithFloats:NULL forKeys:NULL count:0]; |
8494 if (self) { | 8539 if (self) { |
8495 if (dictionary) { | 8540 if (dictionary) { |
8496 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 8541 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
8497 } | 8542 } |
8498 } | 8543 } |
8499 return self; | 8544 return self; |
8500 } | 8545 } |
8501 | 8546 |
8502 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 8547 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
8503 #pragma unused(numItems) | 8548 #pragma unused(numItems) |
8504 return [self initWithValues:NULL forKeys:NULL count:0]; | 8549 return [self initWithFloats:NULL forKeys:NULL count:0]; |
8505 } | 8550 } |
8506 | 8551 |
8507 - (void)dealloc { | 8552 - (void)dealloc { |
8508 NSAssert(!_autocreator, | 8553 NSAssert(!_autocreator, |
8509 @"%@: Autocreator must be cleared before release, autocreator: %@", | 8554 @"%@: Autocreator must be cleared before release, autocreator: %@", |
8510 [self class], _autocreator); | 8555 [self class], _autocreator); |
8511 [_dictionary release]; | 8556 [_dictionary release]; |
8512 [super dealloc]; | 8557 [super dealloc]; |
8513 } | 8558 } |
8514 | 8559 |
8515 - (instancetype)copyWithZone:(NSZone *)zone { | 8560 - (instancetype)copyWithZone:(NSZone *)zone { |
8516 return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]; | 8561 return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]; |
8517 } | 8562 } |
8518 | 8563 |
8519 - (BOOL)isEqual:(GPBInt64FloatDictionary *)other { | 8564 - (BOOL)isEqual:(id)other { |
8520 if (self == other) { | 8565 if (self == other) { |
8521 return YES; | 8566 return YES; |
8522 } | 8567 } |
8523 if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) { | 8568 if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) { |
8524 return NO; | 8569 return NO; |
8525 } | 8570 } |
8526 return [_dictionary isEqual:other->_dictionary]; | 8571 GPBInt64FloatDictionary *otherDictionary = other; |
| 8572 return [_dictionary isEqual:otherDictionary->_dictionary]; |
8527 } | 8573 } |
8528 | 8574 |
8529 - (NSUInteger)hash { | 8575 - (NSUInteger)hash { |
8530 return _dictionary.count; | 8576 return _dictionary.count; |
8531 } | 8577 } |
8532 | 8578 |
8533 - (NSString *)description { | 8579 - (NSString *)description { |
8534 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 8580 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
8535 } | 8581 } |
8536 | 8582 |
8537 - (NSUInteger)count { | 8583 - (NSUInteger)count { |
8538 return _dictionary.count; | 8584 return _dictionary.count; |
8539 } | 8585 } |
8540 | 8586 |
8541 - (void)enumerateKeysAndValuesUsingBlock: | 8587 - (void)enumerateKeysAndFloatsUsingBlock: |
8542 (void (^)(int64_t key, float value, BOOL *stop))block { | 8588 (void (^)(int64_t key, float value, BOOL *stop))block { |
8543 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 8589 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
8544 NSNumber *aValue, | 8590 NSNumber *aValue, |
8545 BOOL *stop) { | 8591 BOOL *stop) { |
8546 block([aKey longLongValue], [aValue floatValue], stop); | 8592 block([aKey longLongValue], [aValue floatValue], stop); |
8547 }]; | 8593 }]; |
8548 } | 8594 } |
8549 | 8595 |
8550 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 8596 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
8551 NSUInteger count = _dictionary.count; | 8597 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8589 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | 8635 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); |
8590 }]; | 8636 }]; |
8591 } | 8637 } |
8592 | 8638 |
8593 - (void)setGPBGenericValue:(GPBGenericValue *)value | 8639 - (void)setGPBGenericValue:(GPBGenericValue *)value |
8594 forGPBGenericValueKey:(GPBGenericValue *)key { | 8640 forGPBGenericValueKey:(GPBGenericValue *)key { |
8595 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)]; | 8641 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)]; |
8596 } | 8642 } |
8597 | 8643 |
8598 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 8644 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
8599 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, float value, BOOL *stop)
{ | 8645 [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, BOOL *stop)
{ |
8600 #pragma unused(stop) | 8646 #pragma unused(stop) |
8601 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%.*g", FLT_DIG, value]); | 8647 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%.*g", FLT_DIG, value]); |
8602 }]; | 8648 }]; |
8603 } | 8649 } |
8604 | 8650 |
8605 - (BOOL)valueForKey:(int64_t)key value:(float *)value { | 8651 - (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key { |
8606 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 8652 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
8607 if (wrapped && value) { | 8653 if (wrapped && value) { |
8608 *value = [wrapped floatValue]; | 8654 *value = [wrapped floatValue]; |
8609 } | 8655 } |
8610 return (wrapped != NULL); | 8656 return (wrapped != NULL); |
8611 } | 8657 } |
8612 | 8658 |
8613 - (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary { | 8659 - (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary { |
8614 if (otherDictionary) { | 8660 if (otherDictionary) { |
8615 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 8661 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
8616 if (_autocreator) { | 8662 if (_autocreator) { |
8617 GPBAutocreatedDictionaryModified(_autocreator, self); | 8663 GPBAutocreatedDictionaryModified(_autocreator, self); |
8618 } | 8664 } |
8619 } | 8665 } |
8620 } | 8666 } |
8621 | 8667 |
8622 - (void)setValue:(float)value forKey:(int64_t)key { | 8668 - (void)setFloat:(float)value forKey:(int64_t)key { |
8623 [_dictionary setObject:@(value) forKey:@(key)]; | 8669 [_dictionary setObject:@(value) forKey:@(key)]; |
8624 if (_autocreator) { | 8670 if (_autocreator) { |
8625 GPBAutocreatedDictionaryModified(_autocreator, self); | 8671 GPBAutocreatedDictionaryModified(_autocreator, self); |
8626 } | 8672 } |
8627 } | 8673 } |
8628 | 8674 |
8629 - (void)removeValueForKey:(int64_t)aKey { | 8675 - (void)removeFloatForKey:(int64_t)aKey { |
8630 [_dictionary removeObjectForKey:@(aKey)]; | 8676 [_dictionary removeObjectForKey:@(aKey)]; |
8631 } | 8677 } |
8632 | 8678 |
8633 - (void)removeAll { | 8679 - (void)removeAll { |
8634 [_dictionary removeAllObjects]; | 8680 [_dictionary removeAllObjects]; |
8635 } | 8681 } |
8636 | 8682 |
8637 @end | 8683 @end |
8638 | 8684 |
8639 #pragma mark - Int64 -> Double | 8685 #pragma mark - Int64 -> Double |
8640 | 8686 |
8641 @implementation GPBInt64DoubleDictionary { | 8687 @implementation GPBInt64DoubleDictionary { |
8642 @package | 8688 @package |
8643 NSMutableDictionary *_dictionary; | 8689 NSMutableDictionary *_dictionary; |
8644 } | 8690 } |
8645 | 8691 |
8646 + (instancetype)dictionary { | 8692 + (instancetype)dictionary { |
8647 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 8693 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; |
8648 } | 8694 } |
8649 | 8695 |
8650 + (instancetype)dictionaryWithValue:(double)value | 8696 + (instancetype)dictionaryWithDouble:(double)value |
8651 forKey:(int64_t)key { | 8697 forKey:(int64_t)key { |
8652 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 8698 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
8653 // on to get the type correct. | 8699 // on to get the type correct. |
8654 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithValues:&value | 8700 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDoubles:&value |
8655 forKeys:&key | 8701 forKeys:&key |
8656 count:1] autorelease
]; | 8702 count:1] autoreleas
e]; |
8657 } | 8703 } |
8658 | 8704 |
8659 + (instancetype)dictionaryWithValues:(const double [])values | 8705 + (instancetype)dictionaryWithDoubles:(const double [])values |
8660 forKeys:(const int64_t [])keys | 8706 forKeys:(const int64_t [])keys |
8661 count:(NSUInteger)count { | 8707 count:(NSUInteger)count { |
8662 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 8708 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
8663 // on to get the type correct. | 8709 // on to get the type correct. |
8664 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithValues:values | 8710 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDoubles:values |
8665 forKeys:keys | 8711 forKeys:keys |
8666 count:count] autorel
ease]; | 8712 count:count] autorel
ease]; |
8667 } | 8713 } |
8668 | 8714 |
8669 + (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary
{ | 8715 + (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary
{ |
8670 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 8716 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
8671 // on to get the type correct. | 8717 // on to get the type correct. |
8672 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 8718 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
8673 } | 8719 } |
8674 | 8720 |
8675 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 8721 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
8676 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 8722 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
8677 } | 8723 } |
8678 | 8724 |
8679 - (instancetype)init { | 8725 - (instancetype)init { |
8680 return [self initWithValues:NULL forKeys:NULL count:0]; | 8726 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
8681 } | 8727 } |
8682 | 8728 |
8683 - (instancetype)initWithValues:(const double [])values | 8729 - (instancetype)initWithDoubles:(const double [])values |
8684 forKeys:(const int64_t [])keys | 8730 forKeys:(const int64_t [])keys |
8685 count:(NSUInteger)count { | 8731 count:(NSUInteger)count { |
8686 self = [super init]; | 8732 self = [super init]; |
8687 if (self) { | 8733 if (self) { |
8688 _dictionary = [[NSMutableDictionary alloc] init]; | 8734 _dictionary = [[NSMutableDictionary alloc] init]; |
8689 if (count && values && keys) { | 8735 if (count && values && keys) { |
8690 for (NSUInteger i = 0; i < count; ++i) { | 8736 for (NSUInteger i = 0; i < count; ++i) { |
8691 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | 8737 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; |
8692 } | 8738 } |
8693 } | 8739 } |
8694 } | 8740 } |
8695 return self; | 8741 return self; |
8696 } | 8742 } |
8697 | 8743 |
8698 - (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary { | 8744 - (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary { |
8699 self = [self initWithValues:NULL forKeys:NULL count:0]; | 8745 self = [self initWithDoubles:NULL forKeys:NULL count:0]; |
8700 if (self) { | 8746 if (self) { |
8701 if (dictionary) { | 8747 if (dictionary) { |
8702 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 8748 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
8703 } | 8749 } |
8704 } | 8750 } |
8705 return self; | 8751 return self; |
8706 } | 8752 } |
8707 | 8753 |
8708 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 8754 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
8709 #pragma unused(numItems) | 8755 #pragma unused(numItems) |
8710 return [self initWithValues:NULL forKeys:NULL count:0]; | 8756 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
8711 } | 8757 } |
8712 | 8758 |
8713 - (void)dealloc { | 8759 - (void)dealloc { |
8714 NSAssert(!_autocreator, | 8760 NSAssert(!_autocreator, |
8715 @"%@: Autocreator must be cleared before release, autocreator: %@", | 8761 @"%@: Autocreator must be cleared before release, autocreator: %@", |
8716 [self class], _autocreator); | 8762 [self class], _autocreator); |
8717 [_dictionary release]; | 8763 [_dictionary release]; |
8718 [super dealloc]; | 8764 [super dealloc]; |
8719 } | 8765 } |
8720 | 8766 |
8721 - (instancetype)copyWithZone:(NSZone *)zone { | 8767 - (instancetype)copyWithZone:(NSZone *)zone { |
8722 return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self]
; | 8768 return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self]
; |
8723 } | 8769 } |
8724 | 8770 |
8725 - (BOOL)isEqual:(GPBInt64DoubleDictionary *)other { | 8771 - (BOOL)isEqual:(id)other { |
8726 if (self == other) { | 8772 if (self == other) { |
8727 return YES; | 8773 return YES; |
8728 } | 8774 } |
8729 if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) { | 8775 if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) { |
8730 return NO; | 8776 return NO; |
8731 } | 8777 } |
8732 return [_dictionary isEqual:other->_dictionary]; | 8778 GPBInt64DoubleDictionary *otherDictionary = other; |
| 8779 return [_dictionary isEqual:otherDictionary->_dictionary]; |
8733 } | 8780 } |
8734 | 8781 |
8735 - (NSUInteger)hash { | 8782 - (NSUInteger)hash { |
8736 return _dictionary.count; | 8783 return _dictionary.count; |
8737 } | 8784 } |
8738 | 8785 |
8739 - (NSString *)description { | 8786 - (NSString *)description { |
8740 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 8787 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
8741 } | 8788 } |
8742 | 8789 |
8743 - (NSUInteger)count { | 8790 - (NSUInteger)count { |
8744 return _dictionary.count; | 8791 return _dictionary.count; |
8745 } | 8792 } |
8746 | 8793 |
8747 - (void)enumerateKeysAndValuesUsingBlock: | 8794 - (void)enumerateKeysAndDoublesUsingBlock: |
8748 (void (^)(int64_t key, double value, BOOL *stop))block { | 8795 (void (^)(int64_t key, double value, BOOL *stop))block { |
8749 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 8796 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
8750 NSNumber *aValue, | 8797 NSNumber *aValue, |
8751 BOOL *stop) { | 8798 BOOL *stop) { |
8752 block([aKey longLongValue], [aValue doubleValue], stop); | 8799 block([aKey longLongValue], [aValue doubleValue], stop); |
8753 }]; | 8800 }]; |
8754 } | 8801 } |
8755 | 8802 |
8756 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 8803 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
8757 NSUInteger count = _dictionary.count; | 8804 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8795 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | 8842 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); |
8796 }]; | 8843 }]; |
8797 } | 8844 } |
8798 | 8845 |
8799 - (void)setGPBGenericValue:(GPBGenericValue *)value | 8846 - (void)setGPBGenericValue:(GPBGenericValue *)value |
8800 forGPBGenericValueKey:(GPBGenericValue *)key { | 8847 forGPBGenericValueKey:(GPBGenericValue *)key { |
8801 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)]; | 8848 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)]; |
8802 } | 8849 } |
8803 | 8850 |
8804 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 8851 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
8805 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, double value, BOOL *stop
) { | 8852 [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, BOOL *sto
p) { |
8806 #pragma unused(stop) | 8853 #pragma unused(stop) |
8807 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%.*lg", DBL_DIG, value]); | 8854 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%.*lg", DBL_DIG, value]); |
8808 }]; | 8855 }]; |
8809 } | 8856 } |
8810 | 8857 |
8811 - (BOOL)valueForKey:(int64_t)key value:(double *)value { | 8858 - (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key { |
8812 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 8859 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
8813 if (wrapped && value) { | 8860 if (wrapped && value) { |
8814 *value = [wrapped doubleValue]; | 8861 *value = [wrapped doubleValue]; |
8815 } | 8862 } |
8816 return (wrapped != NULL); | 8863 return (wrapped != NULL); |
8817 } | 8864 } |
8818 | 8865 |
8819 - (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary { | 8866 - (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary { |
8820 if (otherDictionary) { | 8867 if (otherDictionary) { |
8821 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 8868 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
8822 if (_autocreator) { | 8869 if (_autocreator) { |
8823 GPBAutocreatedDictionaryModified(_autocreator, self); | 8870 GPBAutocreatedDictionaryModified(_autocreator, self); |
8824 } | 8871 } |
8825 } | 8872 } |
8826 } | 8873 } |
8827 | 8874 |
8828 - (void)setValue:(double)value forKey:(int64_t)key { | 8875 - (void)setDouble:(double)value forKey:(int64_t)key { |
8829 [_dictionary setObject:@(value) forKey:@(key)]; | 8876 [_dictionary setObject:@(value) forKey:@(key)]; |
8830 if (_autocreator) { | 8877 if (_autocreator) { |
8831 GPBAutocreatedDictionaryModified(_autocreator, self); | 8878 GPBAutocreatedDictionaryModified(_autocreator, self); |
8832 } | 8879 } |
8833 } | 8880 } |
8834 | 8881 |
8835 - (void)removeValueForKey:(int64_t)aKey { | 8882 - (void)removeDoubleForKey:(int64_t)aKey { |
8836 [_dictionary removeObjectForKey:@(aKey)]; | 8883 [_dictionary removeObjectForKey:@(aKey)]; |
8837 } | 8884 } |
8838 | 8885 |
8839 - (void)removeAll { | 8886 - (void)removeAll { |
8840 [_dictionary removeAllObjects]; | 8887 [_dictionary removeAllObjects]; |
8841 } | 8888 } |
8842 | 8889 |
8843 @end | 8890 @end |
8844 | 8891 |
8845 #pragma mark - Int64 -> Enum | 8892 #pragma mark - Int64 -> Enum |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8949 @"%@: Autocreator must be cleared before release, autocreator: %@", | 8996 @"%@: Autocreator must be cleared before release, autocreator: %@", |
8950 [self class], _autocreator); | 8997 [self class], _autocreator); |
8951 [_dictionary release]; | 8998 [_dictionary release]; |
8952 [super dealloc]; | 8999 [super dealloc]; |
8953 } | 9000 } |
8954 | 9001 |
8955 - (instancetype)copyWithZone:(NSZone *)zone { | 9002 - (instancetype)copyWithZone:(NSZone *)zone { |
8956 return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; | 9003 return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; |
8957 } | 9004 } |
8958 | 9005 |
8959 - (BOOL)isEqual:(GPBInt64EnumDictionary *)other { | 9006 - (BOOL)isEqual:(id)other { |
8960 if (self == other) { | 9007 if (self == other) { |
8961 return YES; | 9008 return YES; |
8962 } | 9009 } |
8963 if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) { | 9010 if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) { |
8964 return NO; | 9011 return NO; |
8965 } | 9012 } |
8966 return [_dictionary isEqual:other->_dictionary]; | 9013 GPBInt64EnumDictionary *otherDictionary = other; |
| 9014 return [_dictionary isEqual:otherDictionary->_dictionary]; |
8967 } | 9015 } |
8968 | 9016 |
8969 - (NSUInteger)hash { | 9017 - (NSUInteger)hash { |
8970 return _dictionary.count; | 9018 return _dictionary.count; |
8971 } | 9019 } |
8972 | 9020 |
8973 - (NSString *)description { | 9021 - (NSString *)description { |
8974 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 9022 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
8975 } | 9023 } |
8976 | 9024 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9047 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)]; | 9095 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)]; |
9048 } | 9096 } |
9049 | 9097 |
9050 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 9098 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
9051 [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *
stop) { | 9099 [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *
stop) { |
9052 #pragma unused(stop) | 9100 #pragma unused(stop) |
9053 block([NSString stringWithFormat:@"%lld", key], @(value)); | 9101 block([NSString stringWithFormat:@"%lld", key], @(value)); |
9054 }]; | 9102 }]; |
9055 } | 9103 } |
9056 | 9104 |
9057 - (BOOL)valueForKey:(int64_t)key value:(int32_t *)value { | 9105 - (BOOL)getEnum:(int32_t *)value forKey:(int64_t)key { |
9058 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 9106 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
9059 if (wrapped && value) { | 9107 if (wrapped && value) { |
9060 int32_t result = [wrapped intValue]; | 9108 int32_t result = [wrapped intValue]; |
9061 if (!_validationFunc(result)) { | 9109 if (!_validationFunc(result)) { |
9062 result = kGPBUnrecognizedEnumeratorValue; | 9110 result = kGPBUnrecognizedEnumeratorValue; |
9063 } | 9111 } |
9064 *value = result; | 9112 *value = result; |
9065 } | 9113 } |
9066 return (wrapped != NULL); | 9114 return (wrapped != NULL); |
9067 } | 9115 } |
9068 | 9116 |
9069 - (BOOL)valueForKey:(int64_t)key rawValue:(int32_t *)rawValue { | 9117 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int64_t)key { |
9070 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | 9118 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; |
9071 if (wrapped && rawValue) { | 9119 if (wrapped && rawValue) { |
9072 *rawValue = [wrapped intValue]; | 9120 *rawValue = [wrapped intValue]; |
9073 } | 9121 } |
9074 return (wrapped != NULL); | 9122 return (wrapped != NULL); |
9075 } | 9123 } |
9076 | 9124 |
9077 - (void)enumerateKeysAndValuesUsingBlock: | 9125 - (void)enumerateKeysAndEnumsUsingBlock: |
9078 (void (^)(int64_t key, int32_t value, BOOL *stop))block { | 9126 (void (^)(int64_t key, int32_t value, BOOL *stop))block { |
9079 GPBEnumValidationFunc func = _validationFunc; | 9127 GPBEnumValidationFunc func = _validationFunc; |
9080 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | 9128 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, |
9081 NSNumber *aValue, | 9129 NSNumber *aValue, |
9082 BOOL *stop) { | 9130 BOOL *stop) { |
9083 int32_t unwrapped = [aValue intValue]; | 9131 int32_t unwrapped = [aValue intValue]; |
9084 if (!func(unwrapped)) { | 9132 if (!func(unwrapped)) { |
9085 unwrapped = kGPBUnrecognizedEnumeratorValue; | 9133 unwrapped = kGPBUnrecognizedEnumeratorValue; |
9086 } | 9134 } |
9087 block([aKey longLongValue], unwrapped, stop); | 9135 block([aKey longLongValue], unwrapped, stop); |
9088 }]; | 9136 }]; |
9089 } | 9137 } |
9090 | 9138 |
9091 - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary { | 9139 - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary { |
9092 if (otherDictionary) { | 9140 if (otherDictionary) { |
9093 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 9141 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
9094 if (_autocreator) { | 9142 if (_autocreator) { |
9095 GPBAutocreatedDictionaryModified(_autocreator, self); | 9143 GPBAutocreatedDictionaryModified(_autocreator, self); |
9096 } | 9144 } |
9097 } | 9145 } |
9098 } | 9146 } |
9099 | 9147 |
9100 - (void)setRawValue:(int32_t)value forKey:(int64_t)key { | 9148 - (void)setRawValue:(int32_t)value forKey:(int64_t)key { |
9101 [_dictionary setObject:@(value) forKey:@(key)]; | 9149 [_dictionary setObject:@(value) forKey:@(key)]; |
9102 if (_autocreator) { | 9150 if (_autocreator) { |
9103 GPBAutocreatedDictionaryModified(_autocreator, self); | 9151 GPBAutocreatedDictionaryModified(_autocreator, self); |
9104 } | 9152 } |
9105 } | 9153 } |
9106 | 9154 |
9107 - (void)removeValueForKey:(int64_t)aKey { | 9155 - (void)removeEnumForKey:(int64_t)aKey { |
9108 [_dictionary removeObjectForKey:@(aKey)]; | 9156 [_dictionary removeObjectForKey:@(aKey)]; |
9109 } | 9157 } |
9110 | 9158 |
9111 - (void)removeAll { | 9159 - (void)removeAll { |
9112 [_dictionary removeAllObjects]; | 9160 [_dictionary removeAllObjects]; |
9113 } | 9161 } |
9114 | 9162 |
9115 - (void)setValue:(int32_t)value forKey:(int64_t)key { | 9163 - (void)setEnum:(int32_t)value forKey:(int64_t)key { |
9116 if (!_validationFunc(value)) { | 9164 if (!_validationFunc(value)) { |
9117 [NSException raise:NSInvalidArgumentException | 9165 [NSException raise:NSInvalidArgumentException |
9118 format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum
value (%d)", | 9166 format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum
value (%d)", |
9119 value]; | 9167 value]; |
9120 } | 9168 } |
9121 | 9169 |
9122 [_dictionary setObject:@(value) forKey:@(key)]; | 9170 [_dictionary setObject:@(value) forKey:@(key)]; |
9123 if (_autocreator) { | 9171 if (_autocreator) { |
9124 GPBAutocreatedDictionaryModified(_autocreator, self); | 9172 GPBAutocreatedDictionaryModified(_autocreator, self); |
9125 } | 9173 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9210 @"%@: Autocreator must be cleared before release, autocreator: %@", | 9258 @"%@: Autocreator must be cleared before release, autocreator: %@", |
9211 [self class], _autocreator); | 9259 [self class], _autocreator); |
9212 [_dictionary release]; | 9260 [_dictionary release]; |
9213 [super dealloc]; | 9261 [super dealloc]; |
9214 } | 9262 } |
9215 | 9263 |
9216 - (instancetype)copyWithZone:(NSZone *)zone { | 9264 - (instancetype)copyWithZone:(NSZone *)zone { |
9217 return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self]
; | 9265 return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self]
; |
9218 } | 9266 } |
9219 | 9267 |
9220 - (BOOL)isEqual:(GPBInt64ObjectDictionary *)other { | 9268 - (BOOL)isEqual:(id)other { |
9221 if (self == other) { | 9269 if (self == other) { |
9222 return YES; | 9270 return YES; |
9223 } | 9271 } |
9224 if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) { | 9272 if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) { |
9225 return NO; | 9273 return NO; |
9226 } | 9274 } |
9227 return [_dictionary isEqual:other->_dictionary]; | 9275 GPBInt64ObjectDictionary *otherDictionary = other; |
| 9276 return [_dictionary isEqual:otherDictionary->_dictionary]; |
9228 } | 9277 } |
9229 | 9278 |
9230 - (NSUInteger)hash { | 9279 - (NSUInteger)hash { |
9231 return _dictionary.count; | 9280 return _dictionary.count; |
9232 } | 9281 } |
9233 | 9282 |
9234 - (NSString *)description { | 9283 - (NSString *)description { |
9235 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 9284 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
9236 } | 9285 } |
9237 | 9286 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9365 // This block of code is generated, do not edit it directly. | 9414 // This block of code is generated, do not edit it directly. |
9366 | 9415 |
9367 #pragma mark - String -> UInt32 | 9416 #pragma mark - String -> UInt32 |
9368 | 9417 |
9369 @implementation GPBStringUInt32Dictionary { | 9418 @implementation GPBStringUInt32Dictionary { |
9370 @package | 9419 @package |
9371 NSMutableDictionary *_dictionary; | 9420 NSMutableDictionary *_dictionary; |
9372 } | 9421 } |
9373 | 9422 |
9374 + (instancetype)dictionary { | 9423 + (instancetype)dictionary { |
9375 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 9424 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; |
9376 } | 9425 } |
9377 | 9426 |
9378 + (instancetype)dictionaryWithValue:(uint32_t)value | 9427 + (instancetype)dictionaryWithUInt32:(uint32_t)value |
9379 forKey:(NSString *)key { | 9428 forKey:(NSString *)key { |
9380 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 9429 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
9381 // on to get the type correct. | 9430 // on to get the type correct. |
9382 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithValues:&value | 9431 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithUInt32s:&value |
9383 forKeys:&key | 9432 forKeys:&key |
9384 count:1] autoreleas
e]; | 9433 count:1] autorelea
se]; |
9385 } | 9434 } |
9386 | 9435 |
9387 + (instancetype)dictionaryWithValues:(const uint32_t [])values | 9436 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values |
9388 forKeys:(const NSString * [])keys | 9437 forKeys:(const NSString * [])keys |
9389 count:(NSUInteger)count { | 9438 count:(NSUInteger)count { |
9390 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 9439 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
9391 // on to get the type correct. | 9440 // on to get the type correct. |
9392 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithValues:values | 9441 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithUInt32s:values |
9393 forKeys:keys | 9442 forKeys:keys |
9394 count:count] autore
lease]; | 9443 count:count] autore
lease]; |
9395 } | 9444 } |
9396 | 9445 |
9397 + (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary
{ | 9446 + (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary
{ |
9398 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 9447 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
9399 // on to get the type correct. | 9448 // on to get the type correct. |
9400 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 9449 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
9401 } | 9450 } |
9402 | 9451 |
9403 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 9452 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
9404 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 9453 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
9405 } | 9454 } |
9406 | 9455 |
9407 - (instancetype)init { | 9456 - (instancetype)init { |
9408 return [self initWithValues:NULL forKeys:NULL count:0]; | 9457 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
9409 } | 9458 } |
9410 | 9459 |
9411 - (instancetype)initWithValues:(const uint32_t [])values | 9460 - (instancetype)initWithUInt32s:(const uint32_t [])values |
9412 forKeys:(const NSString * [])keys | 9461 forKeys:(const NSString * [])keys |
9413 count:(NSUInteger)count { | 9462 count:(NSUInteger)count { |
9414 self = [super init]; | 9463 self = [super init]; |
9415 if (self) { | 9464 if (self) { |
9416 _dictionary = [[NSMutableDictionary alloc] init]; | 9465 _dictionary = [[NSMutableDictionary alloc] init]; |
9417 if (count && values && keys) { | 9466 if (count && values && keys) { |
9418 for (NSUInteger i = 0; i < count; ++i) { | 9467 for (NSUInteger i = 0; i < count; ++i) { |
9419 if (!keys[i]) { | 9468 if (!keys[i]) { |
9420 [NSException raise:NSInvalidArgumentException | 9469 [NSException raise:NSInvalidArgumentException |
9421 format:@"Attempting to add nil key to a Dictionary"]; | 9470 format:@"Attempting to add nil key to a Dictionary"]; |
9422 } | 9471 } |
9423 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 9472 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
9424 } | 9473 } |
9425 } | 9474 } |
9426 } | 9475 } |
9427 return self; | 9476 return self; |
9428 } | 9477 } |
9429 | 9478 |
9430 - (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary { | 9479 - (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary { |
9431 self = [self initWithValues:NULL forKeys:NULL count:0]; | 9480 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; |
9432 if (self) { | 9481 if (self) { |
9433 if (dictionary) { | 9482 if (dictionary) { |
9434 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 9483 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
9435 } | 9484 } |
9436 } | 9485 } |
9437 return self; | 9486 return self; |
9438 } | 9487 } |
9439 | 9488 |
9440 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 9489 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
9441 #pragma unused(numItems) | 9490 #pragma unused(numItems) |
9442 return [self initWithValues:NULL forKeys:NULL count:0]; | 9491 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
9443 } | 9492 } |
9444 | 9493 |
9445 - (void)dealloc { | 9494 - (void)dealloc { |
9446 NSAssert(!_autocreator, | 9495 NSAssert(!_autocreator, |
9447 @"%@: Autocreator must be cleared before release, autocreator: %@", | 9496 @"%@: Autocreator must be cleared before release, autocreator: %@", |
9448 [self class], _autocreator); | 9497 [self class], _autocreator); |
9449 [_dictionary release]; | 9498 [_dictionary release]; |
9450 [super dealloc]; | 9499 [super dealloc]; |
9451 } | 9500 } |
9452 | 9501 |
9453 - (instancetype)copyWithZone:(NSZone *)zone { | 9502 - (instancetype)copyWithZone:(NSZone *)zone { |
9454 return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; | 9503 return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; |
9455 } | 9504 } |
9456 | 9505 |
9457 - (BOOL)isEqual:(GPBStringUInt32Dictionary *)other { | 9506 - (BOOL)isEqual:(id)other { |
9458 if (self == other) { | 9507 if (self == other) { |
9459 return YES; | 9508 return YES; |
9460 } | 9509 } |
9461 if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) { | 9510 if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) { |
9462 return NO; | 9511 return NO; |
9463 } | 9512 } |
9464 return [_dictionary isEqual:other->_dictionary]; | 9513 GPBStringUInt32Dictionary *otherDictionary = other; |
| 9514 return [_dictionary isEqual:otherDictionary->_dictionary]; |
9465 } | 9515 } |
9466 | 9516 |
9467 - (NSUInteger)hash { | 9517 - (NSUInteger)hash { |
9468 return _dictionary.count; | 9518 return _dictionary.count; |
9469 } | 9519 } |
9470 | 9520 |
9471 - (NSString *)description { | 9521 - (NSString *)description { |
9472 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 9522 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
9473 } | 9523 } |
9474 | 9524 |
9475 - (NSUInteger)count { | 9525 - (NSUInteger)count { |
9476 return _dictionary.count; | 9526 return _dictionary.count; |
9477 } | 9527 } |
9478 | 9528 |
9479 - (void)enumerateKeysAndValuesUsingBlock: | 9529 - (void)enumerateKeysAndUInt32sUsingBlock: |
9480 (void (^)(NSString *key, uint32_t value, BOOL *stop))block { | 9530 (void (^)(NSString *key, uint32_t value, BOOL *stop))block { |
9481 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 9531 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
9482 NSNumber *aValue, | 9532 NSNumber *aValue, |
9483 BOOL *stop) { | 9533 BOOL *stop) { |
9484 block(aKey, [aValue unsignedIntValue], stop); | 9534 block(aKey, [aValue unsignedIntValue], stop); |
9485 }]; | 9535 }]; |
9486 } | 9536 } |
9487 | 9537 |
9488 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 9538 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
9489 NSUInteger count = _dictionary.count; | 9539 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9527 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | 9577 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); |
9528 }]; | 9578 }]; |
9529 } | 9579 } |
9530 | 9580 |
9531 - (void)setGPBGenericValue:(GPBGenericValue *)value | 9581 - (void)setGPBGenericValue:(GPBGenericValue *)value |
9532 forGPBGenericValueKey:(GPBGenericValue *)key { | 9582 forGPBGenericValueKey:(GPBGenericValue *)key { |
9533 [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString]; | 9583 [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString]; |
9534 } | 9584 } |
9535 | 9585 |
9536 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 9586 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
9537 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, uint32_t value, BOOL *
stop) { | 9587 [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, BOOL
*stop) { |
9538 #pragma unused(stop) | 9588 #pragma unused(stop) |
9539 block(key, [NSString stringWithFormat:@"%u", value]); | 9589 block(key, [NSString stringWithFormat:@"%u", value]); |
9540 }]; | 9590 }]; |
9541 } | 9591 } |
9542 | 9592 |
9543 - (BOOL)valueForKey:(NSString *)key value:(uint32_t *)value { | 9593 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key { |
9544 NSNumber *wrapped = [_dictionary objectForKey:key]; | 9594 NSNumber *wrapped = [_dictionary objectForKey:key]; |
9545 if (wrapped && value) { | 9595 if (wrapped && value) { |
9546 *value = [wrapped unsignedIntValue]; | 9596 *value = [wrapped unsignedIntValue]; |
9547 } | 9597 } |
9548 return (wrapped != NULL); | 9598 return (wrapped != NULL); |
9549 } | 9599 } |
9550 | 9600 |
9551 - (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary { | 9601 - (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary { |
9552 if (otherDictionary) { | 9602 if (otherDictionary) { |
9553 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 9603 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
9554 if (_autocreator) { | 9604 if (_autocreator) { |
9555 GPBAutocreatedDictionaryModified(_autocreator, self); | 9605 GPBAutocreatedDictionaryModified(_autocreator, self); |
9556 } | 9606 } |
9557 } | 9607 } |
9558 } | 9608 } |
9559 | 9609 |
9560 - (void)setValue:(uint32_t)value forKey:(NSString *)key { | 9610 - (void)setUInt32:(uint32_t)value forKey:(NSString *)key { |
9561 if (!key) { | 9611 if (!key) { |
9562 [NSException raise:NSInvalidArgumentException | 9612 [NSException raise:NSInvalidArgumentException |
9563 format:@"Attempting to add nil key to a Dictionary"]; | 9613 format:@"Attempting to add nil key to a Dictionary"]; |
9564 } | 9614 } |
9565 [_dictionary setObject:@(value) forKey:key]; | 9615 [_dictionary setObject:@(value) forKey:key]; |
9566 if (_autocreator) { | 9616 if (_autocreator) { |
9567 GPBAutocreatedDictionaryModified(_autocreator, self); | 9617 GPBAutocreatedDictionaryModified(_autocreator, self); |
9568 } | 9618 } |
9569 } | 9619 } |
9570 | 9620 |
9571 - (void)removeValueForKey:(NSString *)aKey { | 9621 - (void)removeUInt32ForKey:(NSString *)aKey { |
9572 [_dictionary removeObjectForKey:aKey]; | 9622 [_dictionary removeObjectForKey:aKey]; |
9573 } | 9623 } |
9574 | 9624 |
9575 - (void)removeAll { | 9625 - (void)removeAll { |
9576 [_dictionary removeAllObjects]; | 9626 [_dictionary removeAllObjects]; |
9577 } | 9627 } |
9578 | 9628 |
9579 @end | 9629 @end |
9580 | 9630 |
9581 #pragma mark - String -> Int32 | 9631 #pragma mark - String -> Int32 |
9582 | 9632 |
9583 @implementation GPBStringInt32Dictionary { | 9633 @implementation GPBStringInt32Dictionary { |
9584 @package | 9634 @package |
9585 NSMutableDictionary *_dictionary; | 9635 NSMutableDictionary *_dictionary; |
9586 } | 9636 } |
9587 | 9637 |
9588 + (instancetype)dictionary { | 9638 + (instancetype)dictionary { |
9589 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 9639 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; |
9590 } | 9640 } |
9591 | 9641 |
9592 + (instancetype)dictionaryWithValue:(int32_t)value | 9642 + (instancetype)dictionaryWithInt32:(int32_t)value |
9593 forKey:(NSString *)key { | 9643 forKey:(NSString *)key { |
9594 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 9644 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
9595 // on to get the type correct. | 9645 // on to get the type correct. |
9596 return [[(GPBStringInt32Dictionary*)[self alloc] initWithValues:&value | 9646 return [[(GPBStringInt32Dictionary*)[self alloc] initWithInt32s:&value |
9597 forKeys:&key | 9647 forKeys:&key |
9598 count:1] autorelease
]; | 9648 count:1] autorelease
]; |
9599 } | 9649 } |
9600 | 9650 |
9601 + (instancetype)dictionaryWithValues:(const int32_t [])values | 9651 + (instancetype)dictionaryWithInt32s:(const int32_t [])values |
9602 forKeys:(const NSString * [])keys | 9652 forKeys:(const NSString * [])keys |
9603 count:(NSUInteger)count { | 9653 count:(NSUInteger)count { |
9604 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 9654 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
9605 // on to get the type correct. | 9655 // on to get the type correct. |
9606 return [[(GPBStringInt32Dictionary*)[self alloc] initWithValues:values | 9656 return [[(GPBStringInt32Dictionary*)[self alloc] initWithInt32s:values |
9607 forKeys:keys | 9657 forKeys:keys |
9608 count:count] autorel
ease]; | 9658 count:count] autorel
ease]; |
9609 } | 9659 } |
9610 | 9660 |
9611 + (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary
{ | 9661 + (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary
{ |
9612 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 9662 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
9613 // on to get the type correct. | 9663 // on to get the type correct. |
9614 return [[(GPBStringInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 9664 return [[(GPBStringInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
9615 } | 9665 } |
9616 | 9666 |
9617 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 9667 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
9618 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 9668 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
9619 } | 9669 } |
9620 | 9670 |
9621 - (instancetype)init { | 9671 - (instancetype)init { |
9622 return [self initWithValues:NULL forKeys:NULL count:0]; | 9672 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
9623 } | 9673 } |
9624 | 9674 |
9625 - (instancetype)initWithValues:(const int32_t [])values | 9675 - (instancetype)initWithInt32s:(const int32_t [])values |
9626 forKeys:(const NSString * [])keys | 9676 forKeys:(const NSString * [])keys |
9627 count:(NSUInteger)count { | 9677 count:(NSUInteger)count { |
9628 self = [super init]; | 9678 self = [super init]; |
9629 if (self) { | 9679 if (self) { |
9630 _dictionary = [[NSMutableDictionary alloc] init]; | 9680 _dictionary = [[NSMutableDictionary alloc] init]; |
9631 if (count && values && keys) { | 9681 if (count && values && keys) { |
9632 for (NSUInteger i = 0; i < count; ++i) { | 9682 for (NSUInteger i = 0; i < count; ++i) { |
9633 if (!keys[i]) { | 9683 if (!keys[i]) { |
9634 [NSException raise:NSInvalidArgumentException | 9684 [NSException raise:NSInvalidArgumentException |
9635 format:@"Attempting to add nil key to a Dictionary"]; | 9685 format:@"Attempting to add nil key to a Dictionary"]; |
9636 } | 9686 } |
9637 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 9687 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
9638 } | 9688 } |
9639 } | 9689 } |
9640 } | 9690 } |
9641 return self; | 9691 return self; |
9642 } | 9692 } |
9643 | 9693 |
9644 - (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary { | 9694 - (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary { |
9645 self = [self initWithValues:NULL forKeys:NULL count:0]; | 9695 self = [self initWithInt32s:NULL forKeys:NULL count:0]; |
9646 if (self) { | 9696 if (self) { |
9647 if (dictionary) { | 9697 if (dictionary) { |
9648 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 9698 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
9649 } | 9699 } |
9650 } | 9700 } |
9651 return self; | 9701 return self; |
9652 } | 9702 } |
9653 | 9703 |
9654 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 9704 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
9655 #pragma unused(numItems) | 9705 #pragma unused(numItems) |
9656 return [self initWithValues:NULL forKeys:NULL count:0]; | 9706 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
9657 } | 9707 } |
9658 | 9708 |
9659 - (void)dealloc { | 9709 - (void)dealloc { |
9660 NSAssert(!_autocreator, | 9710 NSAssert(!_autocreator, |
9661 @"%@: Autocreator must be cleared before release, autocreator: %@", | 9711 @"%@: Autocreator must be cleared before release, autocreator: %@", |
9662 [self class], _autocreator); | 9712 [self class], _autocreator); |
9663 [_dictionary release]; | 9713 [_dictionary release]; |
9664 [super dealloc]; | 9714 [super dealloc]; |
9665 } | 9715 } |
9666 | 9716 |
9667 - (instancetype)copyWithZone:(NSZone *)zone { | 9717 - (instancetype)copyWithZone:(NSZone *)zone { |
9668 return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; | 9718 return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; |
9669 } | 9719 } |
9670 | 9720 |
9671 - (BOOL)isEqual:(GPBStringInt32Dictionary *)other { | 9721 - (BOOL)isEqual:(id)other { |
9672 if (self == other) { | 9722 if (self == other) { |
9673 return YES; | 9723 return YES; |
9674 } | 9724 } |
9675 if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) { | 9725 if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) { |
9676 return NO; | 9726 return NO; |
9677 } | 9727 } |
9678 return [_dictionary isEqual:other->_dictionary]; | 9728 GPBStringInt32Dictionary *otherDictionary = other; |
| 9729 return [_dictionary isEqual:otherDictionary->_dictionary]; |
9679 } | 9730 } |
9680 | 9731 |
9681 - (NSUInteger)hash { | 9732 - (NSUInteger)hash { |
9682 return _dictionary.count; | 9733 return _dictionary.count; |
9683 } | 9734 } |
9684 | 9735 |
9685 - (NSString *)description { | 9736 - (NSString *)description { |
9686 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 9737 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
9687 } | 9738 } |
9688 | 9739 |
9689 - (NSUInteger)count { | 9740 - (NSUInteger)count { |
9690 return _dictionary.count; | 9741 return _dictionary.count; |
9691 } | 9742 } |
9692 | 9743 |
9693 - (void)enumerateKeysAndValuesUsingBlock: | 9744 - (void)enumerateKeysAndInt32sUsingBlock: |
9694 (void (^)(NSString *key, int32_t value, BOOL *stop))block { | 9745 (void (^)(NSString *key, int32_t value, BOOL *stop))block { |
9695 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 9746 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
9696 NSNumber *aValue, | 9747 NSNumber *aValue, |
9697 BOOL *stop) { | 9748 BOOL *stop) { |
9698 block(aKey, [aValue intValue], stop); | 9749 block(aKey, [aValue intValue], stop); |
9699 }]; | 9750 }]; |
9700 } | 9751 } |
9701 | 9752 |
9702 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 9753 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
9703 NSUInteger count = _dictionary.count; | 9754 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9741 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | 9792 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); |
9742 }]; | 9793 }]; |
9743 } | 9794 } |
9744 | 9795 |
9745 - (void)setGPBGenericValue:(GPBGenericValue *)value | 9796 - (void)setGPBGenericValue:(GPBGenericValue *)value |
9746 forGPBGenericValueKey:(GPBGenericValue *)key { | 9797 forGPBGenericValueKey:(GPBGenericValue *)key { |
9747 [_dictionary setObject:@(value->valueInt32) forKey:key->valueString]; | 9798 [_dictionary setObject:@(value->valueInt32) forKey:key->valueString]; |
9748 } | 9799 } |
9749 | 9800 |
9750 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 9801 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
9751 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, int32_t value, BOOL *s
top) { | 9802 [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, BOOL *s
top) { |
9752 #pragma unused(stop) | 9803 #pragma unused(stop) |
9753 block(key, [NSString stringWithFormat:@"%d", value]); | 9804 block(key, [NSString stringWithFormat:@"%d", value]); |
9754 }]; | 9805 }]; |
9755 } | 9806 } |
9756 | 9807 |
9757 - (BOOL)valueForKey:(NSString *)key value:(int32_t *)value { | 9808 - (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key { |
9758 NSNumber *wrapped = [_dictionary objectForKey:key]; | 9809 NSNumber *wrapped = [_dictionary objectForKey:key]; |
9759 if (wrapped && value) { | 9810 if (wrapped && value) { |
9760 *value = [wrapped intValue]; | 9811 *value = [wrapped intValue]; |
9761 } | 9812 } |
9762 return (wrapped != NULL); | 9813 return (wrapped != NULL); |
9763 } | 9814 } |
9764 | 9815 |
9765 - (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary { | 9816 - (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary { |
9766 if (otherDictionary) { | 9817 if (otherDictionary) { |
9767 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 9818 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
9768 if (_autocreator) { | 9819 if (_autocreator) { |
9769 GPBAutocreatedDictionaryModified(_autocreator, self); | 9820 GPBAutocreatedDictionaryModified(_autocreator, self); |
9770 } | 9821 } |
9771 } | 9822 } |
9772 } | 9823 } |
9773 | 9824 |
9774 - (void)setValue:(int32_t)value forKey:(NSString *)key { | 9825 - (void)setInt32:(int32_t)value forKey:(NSString *)key { |
9775 if (!key) { | 9826 if (!key) { |
9776 [NSException raise:NSInvalidArgumentException | 9827 [NSException raise:NSInvalidArgumentException |
9777 format:@"Attempting to add nil key to a Dictionary"]; | 9828 format:@"Attempting to add nil key to a Dictionary"]; |
9778 } | 9829 } |
9779 [_dictionary setObject:@(value) forKey:key]; | 9830 [_dictionary setObject:@(value) forKey:key]; |
9780 if (_autocreator) { | 9831 if (_autocreator) { |
9781 GPBAutocreatedDictionaryModified(_autocreator, self); | 9832 GPBAutocreatedDictionaryModified(_autocreator, self); |
9782 } | 9833 } |
9783 } | 9834 } |
9784 | 9835 |
9785 - (void)removeValueForKey:(NSString *)aKey { | 9836 - (void)removeInt32ForKey:(NSString *)aKey { |
9786 [_dictionary removeObjectForKey:aKey]; | 9837 [_dictionary removeObjectForKey:aKey]; |
9787 } | 9838 } |
9788 | 9839 |
9789 - (void)removeAll { | 9840 - (void)removeAll { |
9790 [_dictionary removeAllObjects]; | 9841 [_dictionary removeAllObjects]; |
9791 } | 9842 } |
9792 | 9843 |
9793 @end | 9844 @end |
9794 | 9845 |
9795 #pragma mark - String -> UInt64 | 9846 #pragma mark - String -> UInt64 |
9796 | 9847 |
9797 @implementation GPBStringUInt64Dictionary { | 9848 @implementation GPBStringUInt64Dictionary { |
9798 @package | 9849 @package |
9799 NSMutableDictionary *_dictionary; | 9850 NSMutableDictionary *_dictionary; |
9800 } | 9851 } |
9801 | 9852 |
9802 + (instancetype)dictionary { | 9853 + (instancetype)dictionary { |
9803 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 9854 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; |
9804 } | 9855 } |
9805 | 9856 |
9806 + (instancetype)dictionaryWithValue:(uint64_t)value | 9857 + (instancetype)dictionaryWithUInt64:(uint64_t)value |
9807 forKey:(NSString *)key { | 9858 forKey:(NSString *)key { |
9808 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 9859 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
9809 // on to get the type correct. | 9860 // on to get the type correct. |
9810 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithValues:&value | 9861 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithUInt64s:&value |
9811 forKeys:&key | 9862 forKeys:&key |
9812 count:1] autoreleas
e]; | 9863 count:1] autorelea
se]; |
9813 } | 9864 } |
9814 | 9865 |
9815 + (instancetype)dictionaryWithValues:(const uint64_t [])values | 9866 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values |
9816 forKeys:(const NSString * [])keys | 9867 forKeys:(const NSString * [])keys |
9817 count:(NSUInteger)count { | 9868 count:(NSUInteger)count { |
9818 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 9869 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
9819 // on to get the type correct. | 9870 // on to get the type correct. |
9820 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithValues:values | 9871 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithUInt64s:values |
9821 forKeys:keys | 9872 forKeys:keys |
9822 count:count] autore
lease]; | 9873 count:count] autore
lease]; |
9823 } | 9874 } |
9824 | 9875 |
9825 + (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary
{ | 9876 + (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary
{ |
9826 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 9877 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
9827 // on to get the type correct. | 9878 // on to get the type correct. |
9828 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 9879 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
9829 } | 9880 } |
9830 | 9881 |
9831 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 9882 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
9832 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 9883 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
9833 } | 9884 } |
9834 | 9885 |
9835 - (instancetype)init { | 9886 - (instancetype)init { |
9836 return [self initWithValues:NULL forKeys:NULL count:0]; | 9887 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
9837 } | 9888 } |
9838 | 9889 |
9839 - (instancetype)initWithValues:(const uint64_t [])values | 9890 - (instancetype)initWithUInt64s:(const uint64_t [])values |
9840 forKeys:(const NSString * [])keys | 9891 forKeys:(const NSString * [])keys |
9841 count:(NSUInteger)count { | 9892 count:(NSUInteger)count { |
9842 self = [super init]; | 9893 self = [super init]; |
9843 if (self) { | 9894 if (self) { |
9844 _dictionary = [[NSMutableDictionary alloc] init]; | 9895 _dictionary = [[NSMutableDictionary alloc] init]; |
9845 if (count && values && keys) { | 9896 if (count && values && keys) { |
9846 for (NSUInteger i = 0; i < count; ++i) { | 9897 for (NSUInteger i = 0; i < count; ++i) { |
9847 if (!keys[i]) { | 9898 if (!keys[i]) { |
9848 [NSException raise:NSInvalidArgumentException | 9899 [NSException raise:NSInvalidArgumentException |
9849 format:@"Attempting to add nil key to a Dictionary"]; | 9900 format:@"Attempting to add nil key to a Dictionary"]; |
9850 } | 9901 } |
9851 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 9902 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
9852 } | 9903 } |
9853 } | 9904 } |
9854 } | 9905 } |
9855 return self; | 9906 return self; |
9856 } | 9907 } |
9857 | 9908 |
9858 - (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary { | 9909 - (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary { |
9859 self = [self initWithValues:NULL forKeys:NULL count:0]; | 9910 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; |
9860 if (self) { | 9911 if (self) { |
9861 if (dictionary) { | 9912 if (dictionary) { |
9862 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 9913 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
9863 } | 9914 } |
9864 } | 9915 } |
9865 return self; | 9916 return self; |
9866 } | 9917 } |
9867 | 9918 |
9868 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 9919 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
9869 #pragma unused(numItems) | 9920 #pragma unused(numItems) |
9870 return [self initWithValues:NULL forKeys:NULL count:0]; | 9921 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
9871 } | 9922 } |
9872 | 9923 |
9873 - (void)dealloc { | 9924 - (void)dealloc { |
9874 NSAssert(!_autocreator, | 9925 NSAssert(!_autocreator, |
9875 @"%@: Autocreator must be cleared before release, autocreator: %@", | 9926 @"%@: Autocreator must be cleared before release, autocreator: %@", |
9876 [self class], _autocreator); | 9927 [self class], _autocreator); |
9877 [_dictionary release]; | 9928 [_dictionary release]; |
9878 [super dealloc]; | 9929 [super dealloc]; |
9879 } | 9930 } |
9880 | 9931 |
9881 - (instancetype)copyWithZone:(NSZone *)zone { | 9932 - (instancetype)copyWithZone:(NSZone *)zone { |
9882 return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; | 9933 return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; |
9883 } | 9934 } |
9884 | 9935 |
9885 - (BOOL)isEqual:(GPBStringUInt64Dictionary *)other { | 9936 - (BOOL)isEqual:(id)other { |
9886 if (self == other) { | 9937 if (self == other) { |
9887 return YES; | 9938 return YES; |
9888 } | 9939 } |
9889 if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) { | 9940 if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) { |
9890 return NO; | 9941 return NO; |
9891 } | 9942 } |
9892 return [_dictionary isEqual:other->_dictionary]; | 9943 GPBStringUInt64Dictionary *otherDictionary = other; |
| 9944 return [_dictionary isEqual:otherDictionary->_dictionary]; |
9893 } | 9945 } |
9894 | 9946 |
9895 - (NSUInteger)hash { | 9947 - (NSUInteger)hash { |
9896 return _dictionary.count; | 9948 return _dictionary.count; |
9897 } | 9949 } |
9898 | 9950 |
9899 - (NSString *)description { | 9951 - (NSString *)description { |
9900 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 9952 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
9901 } | 9953 } |
9902 | 9954 |
9903 - (NSUInteger)count { | 9955 - (NSUInteger)count { |
9904 return _dictionary.count; | 9956 return _dictionary.count; |
9905 } | 9957 } |
9906 | 9958 |
9907 - (void)enumerateKeysAndValuesUsingBlock: | 9959 - (void)enumerateKeysAndUInt64sUsingBlock: |
9908 (void (^)(NSString *key, uint64_t value, BOOL *stop))block { | 9960 (void (^)(NSString *key, uint64_t value, BOOL *stop))block { |
9909 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 9961 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
9910 NSNumber *aValue, | 9962 NSNumber *aValue, |
9911 BOOL *stop) { | 9963 BOOL *stop) { |
9912 block(aKey, [aValue unsignedLongLongValue], stop); | 9964 block(aKey, [aValue unsignedLongLongValue], stop); |
9913 }]; | 9965 }]; |
9914 } | 9966 } |
9915 | 9967 |
9916 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 9968 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
9917 NSUInteger count = _dictionary.count; | 9969 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9955 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | 10007 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); |
9956 }]; | 10008 }]; |
9957 } | 10009 } |
9958 | 10010 |
9959 - (void)setGPBGenericValue:(GPBGenericValue *)value | 10011 - (void)setGPBGenericValue:(GPBGenericValue *)value |
9960 forGPBGenericValueKey:(GPBGenericValue *)key { | 10012 forGPBGenericValueKey:(GPBGenericValue *)key { |
9961 [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString]; | 10013 [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString]; |
9962 } | 10014 } |
9963 | 10015 |
9964 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 10016 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
9965 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, uint64_t value, BOOL *
stop) { | 10017 [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, BOOL
*stop) { |
9966 #pragma unused(stop) | 10018 #pragma unused(stop) |
9967 block(key, [NSString stringWithFormat:@"%llu", value]); | 10019 block(key, [NSString stringWithFormat:@"%llu", value]); |
9968 }]; | 10020 }]; |
9969 } | 10021 } |
9970 | 10022 |
9971 - (BOOL)valueForKey:(NSString *)key value:(uint64_t *)value { | 10023 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key { |
9972 NSNumber *wrapped = [_dictionary objectForKey:key]; | 10024 NSNumber *wrapped = [_dictionary objectForKey:key]; |
9973 if (wrapped && value) { | 10025 if (wrapped && value) { |
9974 *value = [wrapped unsignedLongLongValue]; | 10026 *value = [wrapped unsignedLongLongValue]; |
9975 } | 10027 } |
9976 return (wrapped != NULL); | 10028 return (wrapped != NULL); |
9977 } | 10029 } |
9978 | 10030 |
9979 - (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary { | 10031 - (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary { |
9980 if (otherDictionary) { | 10032 if (otherDictionary) { |
9981 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 10033 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
9982 if (_autocreator) { | 10034 if (_autocreator) { |
9983 GPBAutocreatedDictionaryModified(_autocreator, self); | 10035 GPBAutocreatedDictionaryModified(_autocreator, self); |
9984 } | 10036 } |
9985 } | 10037 } |
9986 } | 10038 } |
9987 | 10039 |
9988 - (void)setValue:(uint64_t)value forKey:(NSString *)key { | 10040 - (void)setUInt64:(uint64_t)value forKey:(NSString *)key { |
9989 if (!key) { | 10041 if (!key) { |
9990 [NSException raise:NSInvalidArgumentException | 10042 [NSException raise:NSInvalidArgumentException |
9991 format:@"Attempting to add nil key to a Dictionary"]; | 10043 format:@"Attempting to add nil key to a Dictionary"]; |
9992 } | 10044 } |
9993 [_dictionary setObject:@(value) forKey:key]; | 10045 [_dictionary setObject:@(value) forKey:key]; |
9994 if (_autocreator) { | 10046 if (_autocreator) { |
9995 GPBAutocreatedDictionaryModified(_autocreator, self); | 10047 GPBAutocreatedDictionaryModified(_autocreator, self); |
9996 } | 10048 } |
9997 } | 10049 } |
9998 | 10050 |
9999 - (void)removeValueForKey:(NSString *)aKey { | 10051 - (void)removeUInt64ForKey:(NSString *)aKey { |
10000 [_dictionary removeObjectForKey:aKey]; | 10052 [_dictionary removeObjectForKey:aKey]; |
10001 } | 10053 } |
10002 | 10054 |
10003 - (void)removeAll { | 10055 - (void)removeAll { |
10004 [_dictionary removeAllObjects]; | 10056 [_dictionary removeAllObjects]; |
10005 } | 10057 } |
10006 | 10058 |
10007 @end | 10059 @end |
10008 | 10060 |
10009 #pragma mark - String -> Int64 | 10061 #pragma mark - String -> Int64 |
10010 | 10062 |
10011 @implementation GPBStringInt64Dictionary { | 10063 @implementation GPBStringInt64Dictionary { |
10012 @package | 10064 @package |
10013 NSMutableDictionary *_dictionary; | 10065 NSMutableDictionary *_dictionary; |
10014 } | 10066 } |
10015 | 10067 |
10016 + (instancetype)dictionary { | 10068 + (instancetype)dictionary { |
10017 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 10069 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; |
10018 } | 10070 } |
10019 | 10071 |
10020 + (instancetype)dictionaryWithValue:(int64_t)value | 10072 + (instancetype)dictionaryWithInt64:(int64_t)value |
10021 forKey:(NSString *)key { | 10073 forKey:(NSString *)key { |
10022 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 10074 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
10023 // on to get the type correct. | 10075 // on to get the type correct. |
10024 return [[(GPBStringInt64Dictionary*)[self alloc] initWithValues:&value | 10076 return [[(GPBStringInt64Dictionary*)[self alloc] initWithInt64s:&value |
10025 forKeys:&key | 10077 forKeys:&key |
10026 count:1] autorelease
]; | 10078 count:1] autorelease
]; |
10027 } | 10079 } |
10028 | 10080 |
10029 + (instancetype)dictionaryWithValues:(const int64_t [])values | 10081 + (instancetype)dictionaryWithInt64s:(const int64_t [])values |
10030 forKeys:(const NSString * [])keys | 10082 forKeys:(const NSString * [])keys |
10031 count:(NSUInteger)count { | 10083 count:(NSUInteger)count { |
10032 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 10084 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
10033 // on to get the type correct. | 10085 // on to get the type correct. |
10034 return [[(GPBStringInt64Dictionary*)[self alloc] initWithValues:values | 10086 return [[(GPBStringInt64Dictionary*)[self alloc] initWithInt64s:values |
10035 forKeys:keys | 10087 forKeys:keys |
10036 count:count] autorel
ease]; | 10088 count:count] autorel
ease]; |
10037 } | 10089 } |
10038 | 10090 |
10039 + (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary
{ | 10091 + (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary
{ |
10040 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 10092 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
10041 // on to get the type correct. | 10093 // on to get the type correct. |
10042 return [[(GPBStringInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 10094 return [[(GPBStringInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
10043 } | 10095 } |
10044 | 10096 |
10045 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 10097 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
10046 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 10098 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
10047 } | 10099 } |
10048 | 10100 |
10049 - (instancetype)init { | 10101 - (instancetype)init { |
10050 return [self initWithValues:NULL forKeys:NULL count:0]; | 10102 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
10051 } | 10103 } |
10052 | 10104 |
10053 - (instancetype)initWithValues:(const int64_t [])values | 10105 - (instancetype)initWithInt64s:(const int64_t [])values |
10054 forKeys:(const NSString * [])keys | 10106 forKeys:(const NSString * [])keys |
10055 count:(NSUInteger)count { | 10107 count:(NSUInteger)count { |
10056 self = [super init]; | 10108 self = [super init]; |
10057 if (self) { | 10109 if (self) { |
10058 _dictionary = [[NSMutableDictionary alloc] init]; | 10110 _dictionary = [[NSMutableDictionary alloc] init]; |
10059 if (count && values && keys) { | 10111 if (count && values && keys) { |
10060 for (NSUInteger i = 0; i < count; ++i) { | 10112 for (NSUInteger i = 0; i < count; ++i) { |
10061 if (!keys[i]) { | 10113 if (!keys[i]) { |
10062 [NSException raise:NSInvalidArgumentException | 10114 [NSException raise:NSInvalidArgumentException |
10063 format:@"Attempting to add nil key to a Dictionary"]; | 10115 format:@"Attempting to add nil key to a Dictionary"]; |
10064 } | 10116 } |
10065 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 10117 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
10066 } | 10118 } |
10067 } | 10119 } |
10068 } | 10120 } |
10069 return self; | 10121 return self; |
10070 } | 10122 } |
10071 | 10123 |
10072 - (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary { | 10124 - (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary { |
10073 self = [self initWithValues:NULL forKeys:NULL count:0]; | 10125 self = [self initWithInt64s:NULL forKeys:NULL count:0]; |
10074 if (self) { | 10126 if (self) { |
10075 if (dictionary) { | 10127 if (dictionary) { |
10076 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 10128 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
10077 } | 10129 } |
10078 } | 10130 } |
10079 return self; | 10131 return self; |
10080 } | 10132 } |
10081 | 10133 |
10082 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 10134 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
10083 #pragma unused(numItems) | 10135 #pragma unused(numItems) |
10084 return [self initWithValues:NULL forKeys:NULL count:0]; | 10136 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
10085 } | 10137 } |
10086 | 10138 |
10087 - (void)dealloc { | 10139 - (void)dealloc { |
10088 NSAssert(!_autocreator, | 10140 NSAssert(!_autocreator, |
10089 @"%@: Autocreator must be cleared before release, autocreator: %@", | 10141 @"%@: Autocreator must be cleared before release, autocreator: %@", |
10090 [self class], _autocreator); | 10142 [self class], _autocreator); |
10091 [_dictionary release]; | 10143 [_dictionary release]; |
10092 [super dealloc]; | 10144 [super dealloc]; |
10093 } | 10145 } |
10094 | 10146 |
10095 - (instancetype)copyWithZone:(NSZone *)zone { | 10147 - (instancetype)copyWithZone:(NSZone *)zone { |
10096 return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; | 10148 return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; |
10097 } | 10149 } |
10098 | 10150 |
10099 - (BOOL)isEqual:(GPBStringInt64Dictionary *)other { | 10151 - (BOOL)isEqual:(id)other { |
10100 if (self == other) { | 10152 if (self == other) { |
10101 return YES; | 10153 return YES; |
10102 } | 10154 } |
10103 if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) { | 10155 if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) { |
10104 return NO; | 10156 return NO; |
10105 } | 10157 } |
10106 return [_dictionary isEqual:other->_dictionary]; | 10158 GPBStringInt64Dictionary *otherDictionary = other; |
| 10159 return [_dictionary isEqual:otherDictionary->_dictionary]; |
10107 } | 10160 } |
10108 | 10161 |
10109 - (NSUInteger)hash { | 10162 - (NSUInteger)hash { |
10110 return _dictionary.count; | 10163 return _dictionary.count; |
10111 } | 10164 } |
10112 | 10165 |
10113 - (NSString *)description { | 10166 - (NSString *)description { |
10114 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 10167 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
10115 } | 10168 } |
10116 | 10169 |
10117 - (NSUInteger)count { | 10170 - (NSUInteger)count { |
10118 return _dictionary.count; | 10171 return _dictionary.count; |
10119 } | 10172 } |
10120 | 10173 |
10121 - (void)enumerateKeysAndValuesUsingBlock: | 10174 - (void)enumerateKeysAndInt64sUsingBlock: |
10122 (void (^)(NSString *key, int64_t value, BOOL *stop))block { | 10175 (void (^)(NSString *key, int64_t value, BOOL *stop))block { |
10123 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 10176 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
10124 NSNumber *aValue, | 10177 NSNumber *aValue, |
10125 BOOL *stop) { | 10178 BOOL *stop) { |
10126 block(aKey, [aValue longLongValue], stop); | 10179 block(aKey, [aValue longLongValue], stop); |
10127 }]; | 10180 }]; |
10128 } | 10181 } |
10129 | 10182 |
10130 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 10183 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
10131 NSUInteger count = _dictionary.count; | 10184 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10169 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | 10222 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); |
10170 }]; | 10223 }]; |
10171 } | 10224 } |
10172 | 10225 |
10173 - (void)setGPBGenericValue:(GPBGenericValue *)value | 10226 - (void)setGPBGenericValue:(GPBGenericValue *)value |
10174 forGPBGenericValueKey:(GPBGenericValue *)key { | 10227 forGPBGenericValueKey:(GPBGenericValue *)key { |
10175 [_dictionary setObject:@(value->valueInt64) forKey:key->valueString]; | 10228 [_dictionary setObject:@(value->valueInt64) forKey:key->valueString]; |
10176 } | 10229 } |
10177 | 10230 |
10178 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 10231 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
10179 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, int64_t value, BOOL *s
top) { | 10232 [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, BOOL *s
top) { |
10180 #pragma unused(stop) | 10233 #pragma unused(stop) |
10181 block(key, [NSString stringWithFormat:@"%lld", value]); | 10234 block(key, [NSString stringWithFormat:@"%lld", value]); |
10182 }]; | 10235 }]; |
10183 } | 10236 } |
10184 | 10237 |
10185 - (BOOL)valueForKey:(NSString *)key value:(int64_t *)value { | 10238 - (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key { |
10186 NSNumber *wrapped = [_dictionary objectForKey:key]; | 10239 NSNumber *wrapped = [_dictionary objectForKey:key]; |
10187 if (wrapped && value) { | 10240 if (wrapped && value) { |
10188 *value = [wrapped longLongValue]; | 10241 *value = [wrapped longLongValue]; |
10189 } | 10242 } |
10190 return (wrapped != NULL); | 10243 return (wrapped != NULL); |
10191 } | 10244 } |
10192 | 10245 |
10193 - (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary { | 10246 - (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary { |
10194 if (otherDictionary) { | 10247 if (otherDictionary) { |
10195 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 10248 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
10196 if (_autocreator) { | 10249 if (_autocreator) { |
10197 GPBAutocreatedDictionaryModified(_autocreator, self); | 10250 GPBAutocreatedDictionaryModified(_autocreator, self); |
10198 } | 10251 } |
10199 } | 10252 } |
10200 } | 10253 } |
10201 | 10254 |
10202 - (void)setValue:(int64_t)value forKey:(NSString *)key { | 10255 - (void)setInt64:(int64_t)value forKey:(NSString *)key { |
10203 if (!key) { | 10256 if (!key) { |
10204 [NSException raise:NSInvalidArgumentException | 10257 [NSException raise:NSInvalidArgumentException |
10205 format:@"Attempting to add nil key to a Dictionary"]; | 10258 format:@"Attempting to add nil key to a Dictionary"]; |
10206 } | 10259 } |
10207 [_dictionary setObject:@(value) forKey:key]; | 10260 [_dictionary setObject:@(value) forKey:key]; |
10208 if (_autocreator) { | 10261 if (_autocreator) { |
10209 GPBAutocreatedDictionaryModified(_autocreator, self); | 10262 GPBAutocreatedDictionaryModified(_autocreator, self); |
10210 } | 10263 } |
10211 } | 10264 } |
10212 | 10265 |
10213 - (void)removeValueForKey:(NSString *)aKey { | 10266 - (void)removeInt64ForKey:(NSString *)aKey { |
10214 [_dictionary removeObjectForKey:aKey]; | 10267 [_dictionary removeObjectForKey:aKey]; |
10215 } | 10268 } |
10216 | 10269 |
10217 - (void)removeAll { | 10270 - (void)removeAll { |
10218 [_dictionary removeAllObjects]; | 10271 [_dictionary removeAllObjects]; |
10219 } | 10272 } |
10220 | 10273 |
10221 @end | 10274 @end |
10222 | 10275 |
10223 #pragma mark - String -> Bool | 10276 #pragma mark - String -> Bool |
10224 | 10277 |
10225 @implementation GPBStringBoolDictionary { | 10278 @implementation GPBStringBoolDictionary { |
10226 @package | 10279 @package |
10227 NSMutableDictionary *_dictionary; | 10280 NSMutableDictionary *_dictionary; |
10228 } | 10281 } |
10229 | 10282 |
10230 + (instancetype)dictionary { | 10283 + (instancetype)dictionary { |
10231 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 10284 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; |
10232 } | 10285 } |
10233 | 10286 |
10234 + (instancetype)dictionaryWithValue:(BOOL)value | 10287 + (instancetype)dictionaryWithBool:(BOOL)value |
10235 forKey:(NSString *)key { | 10288 forKey:(NSString *)key { |
10236 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 10289 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
10237 // on to get the type correct. | 10290 // on to get the type correct. |
10238 return [[(GPBStringBoolDictionary*)[self alloc] initWithValues:&value | 10291 return [[(GPBStringBoolDictionary*)[self alloc] initWithBools:&value |
10239 forKeys:&key | 10292 forKeys:&key |
10240 count:1] autorelease]
; | 10293 count:1] autorelease]; |
10241 } | 10294 } |
10242 | 10295 |
10243 + (instancetype)dictionaryWithValues:(const BOOL [])values | 10296 + (instancetype)dictionaryWithBools:(const BOOL [])values |
10244 forKeys:(const NSString * [])keys | 10297 forKeys:(const NSString * [])keys |
10245 count:(NSUInteger)count { | 10298 count:(NSUInteger)count { |
10246 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 10299 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
10247 // on to get the type correct. | 10300 // on to get the type correct. |
10248 return [[(GPBStringBoolDictionary*)[self alloc] initWithValues:values | 10301 return [[(GPBStringBoolDictionary*)[self alloc] initWithBools:values |
10249 forKeys:keys | 10302 forKeys:keys |
10250 count:count] autorele
ase]; | 10303 count:count] autorele
ase]; |
10251 } | 10304 } |
10252 | 10305 |
10253 + (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary { | 10306 + (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary { |
10254 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 10307 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
10255 // on to get the type correct. | 10308 // on to get the type correct. |
10256 return [[(GPBStringBoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 10309 return [[(GPBStringBoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
10257 } | 10310 } |
10258 | 10311 |
10259 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 10312 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
10260 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 10313 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
10261 } | 10314 } |
10262 | 10315 |
10263 - (instancetype)init { | 10316 - (instancetype)init { |
10264 return [self initWithValues:NULL forKeys:NULL count:0]; | 10317 return [self initWithBools:NULL forKeys:NULL count:0]; |
10265 } | 10318 } |
10266 | 10319 |
10267 - (instancetype)initWithValues:(const BOOL [])values | 10320 - (instancetype)initWithBools:(const BOOL [])values |
10268 forKeys:(const NSString * [])keys | 10321 forKeys:(const NSString * [])keys |
10269 count:(NSUInteger)count { | 10322 count:(NSUInteger)count { |
10270 self = [super init]; | 10323 self = [super init]; |
10271 if (self) { | 10324 if (self) { |
10272 _dictionary = [[NSMutableDictionary alloc] init]; | 10325 _dictionary = [[NSMutableDictionary alloc] init]; |
10273 if (count && values && keys) { | 10326 if (count && values && keys) { |
10274 for (NSUInteger i = 0; i < count; ++i) { | 10327 for (NSUInteger i = 0; i < count; ++i) { |
10275 if (!keys[i]) { | 10328 if (!keys[i]) { |
10276 [NSException raise:NSInvalidArgumentException | 10329 [NSException raise:NSInvalidArgumentException |
10277 format:@"Attempting to add nil key to a Dictionary"]; | 10330 format:@"Attempting to add nil key to a Dictionary"]; |
10278 } | 10331 } |
10279 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 10332 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
10280 } | 10333 } |
10281 } | 10334 } |
10282 } | 10335 } |
10283 return self; | 10336 return self; |
10284 } | 10337 } |
10285 | 10338 |
10286 - (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary { | 10339 - (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary { |
10287 self = [self initWithValues:NULL forKeys:NULL count:0]; | 10340 self = [self initWithBools:NULL forKeys:NULL count:0]; |
10288 if (self) { | 10341 if (self) { |
10289 if (dictionary) { | 10342 if (dictionary) { |
10290 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 10343 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
10291 } | 10344 } |
10292 } | 10345 } |
10293 return self; | 10346 return self; |
10294 } | 10347 } |
10295 | 10348 |
10296 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 10349 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
10297 #pragma unused(numItems) | 10350 #pragma unused(numItems) |
10298 return [self initWithValues:NULL forKeys:NULL count:0]; | 10351 return [self initWithBools:NULL forKeys:NULL count:0]; |
10299 } | 10352 } |
10300 | 10353 |
10301 - (void)dealloc { | 10354 - (void)dealloc { |
10302 NSAssert(!_autocreator, | 10355 NSAssert(!_autocreator, |
10303 @"%@: Autocreator must be cleared before release, autocreator: %@", | 10356 @"%@: Autocreator must be cleared before release, autocreator: %@", |
10304 [self class], _autocreator); | 10357 [self class], _autocreator); |
10305 [_dictionary release]; | 10358 [_dictionary release]; |
10306 [super dealloc]; | 10359 [super dealloc]; |
10307 } | 10360 } |
10308 | 10361 |
10309 - (instancetype)copyWithZone:(NSZone *)zone { | 10362 - (instancetype)copyWithZone:(NSZone *)zone { |
10310 return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self]; | 10363 return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self]; |
10311 } | 10364 } |
10312 | 10365 |
10313 - (BOOL)isEqual:(GPBStringBoolDictionary *)other { | 10366 - (BOOL)isEqual:(id)other { |
10314 if (self == other) { | 10367 if (self == other) { |
10315 return YES; | 10368 return YES; |
10316 } | 10369 } |
10317 if (![other isKindOfClass:[GPBStringBoolDictionary class]]) { | 10370 if (![other isKindOfClass:[GPBStringBoolDictionary class]]) { |
10318 return NO; | 10371 return NO; |
10319 } | 10372 } |
10320 return [_dictionary isEqual:other->_dictionary]; | 10373 GPBStringBoolDictionary *otherDictionary = other; |
| 10374 return [_dictionary isEqual:otherDictionary->_dictionary]; |
10321 } | 10375 } |
10322 | 10376 |
10323 - (NSUInteger)hash { | 10377 - (NSUInteger)hash { |
10324 return _dictionary.count; | 10378 return _dictionary.count; |
10325 } | 10379 } |
10326 | 10380 |
10327 - (NSString *)description { | 10381 - (NSString *)description { |
10328 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 10382 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
10329 } | 10383 } |
10330 | 10384 |
10331 - (NSUInteger)count { | 10385 - (NSUInteger)count { |
10332 return _dictionary.count; | 10386 return _dictionary.count; |
10333 } | 10387 } |
10334 | 10388 |
10335 - (void)enumerateKeysAndValuesUsingBlock: | 10389 - (void)enumerateKeysAndBoolsUsingBlock: |
10336 (void (^)(NSString *key, BOOL value, BOOL *stop))block { | 10390 (void (^)(NSString *key, BOOL value, BOOL *stop))block { |
10337 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 10391 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
10338 NSNumber *aValue, | 10392 NSNumber *aValue, |
10339 BOOL *stop) { | 10393 BOOL *stop) { |
10340 block(aKey, [aValue boolValue], stop); | 10394 block(aKey, [aValue boolValue], stop); |
10341 }]; | 10395 }]; |
10342 } | 10396 } |
10343 | 10397 |
10344 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 10398 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
10345 NSUInteger count = _dictionary.count; | 10399 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10383 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | 10437 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); |
10384 }]; | 10438 }]; |
10385 } | 10439 } |
10386 | 10440 |
10387 - (void)setGPBGenericValue:(GPBGenericValue *)value | 10441 - (void)setGPBGenericValue:(GPBGenericValue *)value |
10388 forGPBGenericValueKey:(GPBGenericValue *)key { | 10442 forGPBGenericValueKey:(GPBGenericValue *)key { |
10389 [_dictionary setObject:@(value->valueBool) forKey:key->valueString]; | 10443 [_dictionary setObject:@(value->valueBool) forKey:key->valueString]; |
10390 } | 10444 } |
10391 | 10445 |
10392 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 10446 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
10393 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, BOOL value, BOOL *stop
) { | 10447 [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, BOOL *stop)
{ |
10394 #pragma unused(stop) | 10448 #pragma unused(stop) |
10395 block(key, (value ? @"true" : @"false")); | 10449 block(key, (value ? @"true" : @"false")); |
10396 }]; | 10450 }]; |
10397 } | 10451 } |
10398 | 10452 |
10399 - (BOOL)valueForKey:(NSString *)key value:(BOOL *)value { | 10453 - (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key { |
10400 NSNumber *wrapped = [_dictionary objectForKey:key]; | 10454 NSNumber *wrapped = [_dictionary objectForKey:key]; |
10401 if (wrapped && value) { | 10455 if (wrapped && value) { |
10402 *value = [wrapped boolValue]; | 10456 *value = [wrapped boolValue]; |
10403 } | 10457 } |
10404 return (wrapped != NULL); | 10458 return (wrapped != NULL); |
10405 } | 10459 } |
10406 | 10460 |
10407 - (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary { | 10461 - (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary { |
10408 if (otherDictionary) { | 10462 if (otherDictionary) { |
10409 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 10463 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
10410 if (_autocreator) { | 10464 if (_autocreator) { |
10411 GPBAutocreatedDictionaryModified(_autocreator, self); | 10465 GPBAutocreatedDictionaryModified(_autocreator, self); |
10412 } | 10466 } |
10413 } | 10467 } |
10414 } | 10468 } |
10415 | 10469 |
10416 - (void)setValue:(BOOL)value forKey:(NSString *)key { | 10470 - (void)setBool:(BOOL)value forKey:(NSString *)key { |
10417 if (!key) { | 10471 if (!key) { |
10418 [NSException raise:NSInvalidArgumentException | 10472 [NSException raise:NSInvalidArgumentException |
10419 format:@"Attempting to add nil key to a Dictionary"]; | 10473 format:@"Attempting to add nil key to a Dictionary"]; |
10420 } | 10474 } |
10421 [_dictionary setObject:@(value) forKey:key]; | 10475 [_dictionary setObject:@(value) forKey:key]; |
10422 if (_autocreator) { | 10476 if (_autocreator) { |
10423 GPBAutocreatedDictionaryModified(_autocreator, self); | 10477 GPBAutocreatedDictionaryModified(_autocreator, self); |
10424 } | 10478 } |
10425 } | 10479 } |
10426 | 10480 |
10427 - (void)removeValueForKey:(NSString *)aKey { | 10481 - (void)removeBoolForKey:(NSString *)aKey { |
10428 [_dictionary removeObjectForKey:aKey]; | 10482 [_dictionary removeObjectForKey:aKey]; |
10429 } | 10483 } |
10430 | 10484 |
10431 - (void)removeAll { | 10485 - (void)removeAll { |
10432 [_dictionary removeAllObjects]; | 10486 [_dictionary removeAllObjects]; |
10433 } | 10487 } |
10434 | 10488 |
10435 @end | 10489 @end |
10436 | 10490 |
10437 #pragma mark - String -> Float | 10491 #pragma mark - String -> Float |
10438 | 10492 |
10439 @implementation GPBStringFloatDictionary { | 10493 @implementation GPBStringFloatDictionary { |
10440 @package | 10494 @package |
10441 NSMutableDictionary *_dictionary; | 10495 NSMutableDictionary *_dictionary; |
10442 } | 10496 } |
10443 | 10497 |
10444 + (instancetype)dictionary { | 10498 + (instancetype)dictionary { |
10445 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 10499 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; |
10446 } | 10500 } |
10447 | 10501 |
10448 + (instancetype)dictionaryWithValue:(float)value | 10502 + (instancetype)dictionaryWithFloat:(float)value |
10449 forKey:(NSString *)key { | 10503 forKey:(NSString *)key { |
10450 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 10504 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
10451 // on to get the type correct. | 10505 // on to get the type correct. |
10452 return [[(GPBStringFloatDictionary*)[self alloc] initWithValues:&value | 10506 return [[(GPBStringFloatDictionary*)[self alloc] initWithFloats:&value |
10453 forKeys:&key | 10507 forKeys:&key |
10454 count:1] autorelease
]; | 10508 count:1] autorelease
]; |
10455 } | 10509 } |
10456 | 10510 |
10457 + (instancetype)dictionaryWithValues:(const float [])values | 10511 + (instancetype)dictionaryWithFloats:(const float [])values |
10458 forKeys:(const NSString * [])keys | 10512 forKeys:(const NSString * [])keys |
10459 count:(NSUInteger)count { | 10513 count:(NSUInteger)count { |
10460 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 10514 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
10461 // on to get the type correct. | 10515 // on to get the type correct. |
10462 return [[(GPBStringFloatDictionary*)[self alloc] initWithValues:values | 10516 return [[(GPBStringFloatDictionary*)[self alloc] initWithFloats:values |
10463 forKeys:keys | 10517 forKeys:keys |
10464 count:count] autorel
ease]; | 10518 count:count] autorel
ease]; |
10465 } | 10519 } |
10466 | 10520 |
10467 + (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary
{ | 10521 + (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary
{ |
10468 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 10522 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
10469 // on to get the type correct. | 10523 // on to get the type correct. |
10470 return [[(GPBStringFloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | 10524 return [[(GPBStringFloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; |
10471 } | 10525 } |
10472 | 10526 |
10473 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 10527 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
10474 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 10528 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
10475 } | 10529 } |
10476 | 10530 |
10477 - (instancetype)init { | 10531 - (instancetype)init { |
10478 return [self initWithValues:NULL forKeys:NULL count:0]; | 10532 return [self initWithFloats:NULL forKeys:NULL count:0]; |
10479 } | 10533 } |
10480 | 10534 |
10481 - (instancetype)initWithValues:(const float [])values | 10535 - (instancetype)initWithFloats:(const float [])values |
10482 forKeys:(const NSString * [])keys | 10536 forKeys:(const NSString * [])keys |
10483 count:(NSUInteger)count { | 10537 count:(NSUInteger)count { |
10484 self = [super init]; | 10538 self = [super init]; |
10485 if (self) { | 10539 if (self) { |
10486 _dictionary = [[NSMutableDictionary alloc] init]; | 10540 _dictionary = [[NSMutableDictionary alloc] init]; |
10487 if (count && values && keys) { | 10541 if (count && values && keys) { |
10488 for (NSUInteger i = 0; i < count; ++i) { | 10542 for (NSUInteger i = 0; i < count; ++i) { |
10489 if (!keys[i]) { | 10543 if (!keys[i]) { |
10490 [NSException raise:NSInvalidArgumentException | 10544 [NSException raise:NSInvalidArgumentException |
10491 format:@"Attempting to add nil key to a Dictionary"]; | 10545 format:@"Attempting to add nil key to a Dictionary"]; |
10492 } | 10546 } |
10493 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 10547 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
10494 } | 10548 } |
10495 } | 10549 } |
10496 } | 10550 } |
10497 return self; | 10551 return self; |
10498 } | 10552 } |
10499 | 10553 |
10500 - (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary { | 10554 - (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary { |
10501 self = [self initWithValues:NULL forKeys:NULL count:0]; | 10555 self = [self initWithFloats:NULL forKeys:NULL count:0]; |
10502 if (self) { | 10556 if (self) { |
10503 if (dictionary) { | 10557 if (dictionary) { |
10504 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 10558 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
10505 } | 10559 } |
10506 } | 10560 } |
10507 return self; | 10561 return self; |
10508 } | 10562 } |
10509 | 10563 |
10510 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 10564 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
10511 #pragma unused(numItems) | 10565 #pragma unused(numItems) |
10512 return [self initWithValues:NULL forKeys:NULL count:0]; | 10566 return [self initWithFloats:NULL forKeys:NULL count:0]; |
10513 } | 10567 } |
10514 | 10568 |
10515 - (void)dealloc { | 10569 - (void)dealloc { |
10516 NSAssert(!_autocreator, | 10570 NSAssert(!_autocreator, |
10517 @"%@: Autocreator must be cleared before release, autocreator: %@", | 10571 @"%@: Autocreator must be cleared before release, autocreator: %@", |
10518 [self class], _autocreator); | 10572 [self class], _autocreator); |
10519 [_dictionary release]; | 10573 [_dictionary release]; |
10520 [super dealloc]; | 10574 [super dealloc]; |
10521 } | 10575 } |
10522 | 10576 |
10523 - (instancetype)copyWithZone:(NSZone *)zone { | 10577 - (instancetype)copyWithZone:(NSZone *)zone { |
10524 return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self]
; | 10578 return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self]
; |
10525 } | 10579 } |
10526 | 10580 |
10527 - (BOOL)isEqual:(GPBStringFloatDictionary *)other { | 10581 - (BOOL)isEqual:(id)other { |
10528 if (self == other) { | 10582 if (self == other) { |
10529 return YES; | 10583 return YES; |
10530 } | 10584 } |
10531 if (![other isKindOfClass:[GPBStringFloatDictionary class]]) { | 10585 if (![other isKindOfClass:[GPBStringFloatDictionary class]]) { |
10532 return NO; | 10586 return NO; |
10533 } | 10587 } |
10534 return [_dictionary isEqual:other->_dictionary]; | 10588 GPBStringFloatDictionary *otherDictionary = other; |
| 10589 return [_dictionary isEqual:otherDictionary->_dictionary]; |
10535 } | 10590 } |
10536 | 10591 |
10537 - (NSUInteger)hash { | 10592 - (NSUInteger)hash { |
10538 return _dictionary.count; | 10593 return _dictionary.count; |
10539 } | 10594 } |
10540 | 10595 |
10541 - (NSString *)description { | 10596 - (NSString *)description { |
10542 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 10597 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
10543 } | 10598 } |
10544 | 10599 |
10545 - (NSUInteger)count { | 10600 - (NSUInteger)count { |
10546 return _dictionary.count; | 10601 return _dictionary.count; |
10547 } | 10602 } |
10548 | 10603 |
10549 - (void)enumerateKeysAndValuesUsingBlock: | 10604 - (void)enumerateKeysAndFloatsUsingBlock: |
10550 (void (^)(NSString *key, float value, BOOL *stop))block { | 10605 (void (^)(NSString *key, float value, BOOL *stop))block { |
10551 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 10606 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
10552 NSNumber *aValue, | 10607 NSNumber *aValue, |
10553 BOOL *stop) { | 10608 BOOL *stop) { |
10554 block(aKey, [aValue floatValue], stop); | 10609 block(aKey, [aValue floatValue], stop); |
10555 }]; | 10610 }]; |
10556 } | 10611 } |
10557 | 10612 |
10558 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 10613 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
10559 NSUInteger count = _dictionary.count; | 10614 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10597 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | 10652 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); |
10598 }]; | 10653 }]; |
10599 } | 10654 } |
10600 | 10655 |
10601 - (void)setGPBGenericValue:(GPBGenericValue *)value | 10656 - (void)setGPBGenericValue:(GPBGenericValue *)value |
10602 forGPBGenericValueKey:(GPBGenericValue *)key { | 10657 forGPBGenericValueKey:(GPBGenericValue *)key { |
10603 [_dictionary setObject:@(value->valueFloat) forKey:key->valueString]; | 10658 [_dictionary setObject:@(value->valueFloat) forKey:key->valueString]; |
10604 } | 10659 } |
10605 | 10660 |
10606 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 10661 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
10607 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, float value, BOOL *sto
p) { | 10662 [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, BOOL *sto
p) { |
10608 #pragma unused(stop) | 10663 #pragma unused(stop) |
10609 block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); | 10664 block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); |
10610 }]; | 10665 }]; |
10611 } | 10666 } |
10612 | 10667 |
10613 - (BOOL)valueForKey:(NSString *)key value:(float *)value { | 10668 - (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key { |
10614 NSNumber *wrapped = [_dictionary objectForKey:key]; | 10669 NSNumber *wrapped = [_dictionary objectForKey:key]; |
10615 if (wrapped && value) { | 10670 if (wrapped && value) { |
10616 *value = [wrapped floatValue]; | 10671 *value = [wrapped floatValue]; |
10617 } | 10672 } |
10618 return (wrapped != NULL); | 10673 return (wrapped != NULL); |
10619 } | 10674 } |
10620 | 10675 |
10621 - (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary { | 10676 - (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary { |
10622 if (otherDictionary) { | 10677 if (otherDictionary) { |
10623 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 10678 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
10624 if (_autocreator) { | 10679 if (_autocreator) { |
10625 GPBAutocreatedDictionaryModified(_autocreator, self); | 10680 GPBAutocreatedDictionaryModified(_autocreator, self); |
10626 } | 10681 } |
10627 } | 10682 } |
10628 } | 10683 } |
10629 | 10684 |
10630 - (void)setValue:(float)value forKey:(NSString *)key { | 10685 - (void)setFloat:(float)value forKey:(NSString *)key { |
10631 if (!key) { | 10686 if (!key) { |
10632 [NSException raise:NSInvalidArgumentException | 10687 [NSException raise:NSInvalidArgumentException |
10633 format:@"Attempting to add nil key to a Dictionary"]; | 10688 format:@"Attempting to add nil key to a Dictionary"]; |
10634 } | 10689 } |
10635 [_dictionary setObject:@(value) forKey:key]; | 10690 [_dictionary setObject:@(value) forKey:key]; |
10636 if (_autocreator) { | 10691 if (_autocreator) { |
10637 GPBAutocreatedDictionaryModified(_autocreator, self); | 10692 GPBAutocreatedDictionaryModified(_autocreator, self); |
10638 } | 10693 } |
10639 } | 10694 } |
10640 | 10695 |
10641 - (void)removeValueForKey:(NSString *)aKey { | 10696 - (void)removeFloatForKey:(NSString *)aKey { |
10642 [_dictionary removeObjectForKey:aKey]; | 10697 [_dictionary removeObjectForKey:aKey]; |
10643 } | 10698 } |
10644 | 10699 |
10645 - (void)removeAll { | 10700 - (void)removeAll { |
10646 [_dictionary removeAllObjects]; | 10701 [_dictionary removeAllObjects]; |
10647 } | 10702 } |
10648 | 10703 |
10649 @end | 10704 @end |
10650 | 10705 |
10651 #pragma mark - String -> Double | 10706 #pragma mark - String -> Double |
10652 | 10707 |
10653 @implementation GPBStringDoubleDictionary { | 10708 @implementation GPBStringDoubleDictionary { |
10654 @package | 10709 @package |
10655 NSMutableDictionary *_dictionary; | 10710 NSMutableDictionary *_dictionary; |
10656 } | 10711 } |
10657 | 10712 |
10658 + (instancetype)dictionary { | 10713 + (instancetype)dictionary { |
10659 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 10714 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; |
10660 } | 10715 } |
10661 | 10716 |
10662 + (instancetype)dictionaryWithValue:(double)value | 10717 + (instancetype)dictionaryWithDouble:(double)value |
10663 forKey:(NSString *)key { | 10718 forKey:(NSString *)key { |
10664 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 10719 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
10665 // on to get the type correct. | 10720 // on to get the type correct. |
10666 return [[(GPBStringDoubleDictionary*)[self alloc] initWithValues:&value | 10721 return [[(GPBStringDoubleDictionary*)[self alloc] initWithDoubles:&value |
10667 forKeys:&key | 10722 forKeys:&key |
10668 count:1] autoreleas
e]; | 10723 count:1] autorelea
se]; |
10669 } | 10724 } |
10670 | 10725 |
10671 + (instancetype)dictionaryWithValues:(const double [])values | 10726 + (instancetype)dictionaryWithDoubles:(const double [])values |
10672 forKeys:(const NSString * [])keys | 10727 forKeys:(const NSString * [])keys |
10673 count:(NSUInteger)count { | 10728 count:(NSUInteger)count { |
10674 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 10729 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
10675 // on to get the type correct. | 10730 // on to get the type correct. |
10676 return [[(GPBStringDoubleDictionary*)[self alloc] initWithValues:values | 10731 return [[(GPBStringDoubleDictionary*)[self alloc] initWithDoubles:values |
10677 forKeys:keys | 10732 forKeys:keys |
10678 count:count] autore
lease]; | 10733 count:count] autore
lease]; |
10679 } | 10734 } |
10680 | 10735 |
10681 + (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary
{ | 10736 + (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary
{ |
10682 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 10737 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
10683 // on to get the type correct. | 10738 // on to get the type correct. |
10684 return [[(GPBStringDoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | 10739 return [[(GPBStringDoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; |
10685 } | 10740 } |
10686 | 10741 |
10687 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 10742 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
10688 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 10743 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
10689 } | 10744 } |
10690 | 10745 |
10691 - (instancetype)init { | 10746 - (instancetype)init { |
10692 return [self initWithValues:NULL forKeys:NULL count:0]; | 10747 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
10693 } | 10748 } |
10694 | 10749 |
10695 - (instancetype)initWithValues:(const double [])values | 10750 - (instancetype)initWithDoubles:(const double [])values |
10696 forKeys:(const NSString * [])keys | 10751 forKeys:(const NSString * [])keys |
10697 count:(NSUInteger)count { | 10752 count:(NSUInteger)count { |
10698 self = [super init]; | 10753 self = [super init]; |
10699 if (self) { | 10754 if (self) { |
10700 _dictionary = [[NSMutableDictionary alloc] init]; | 10755 _dictionary = [[NSMutableDictionary alloc] init]; |
10701 if (count && values && keys) { | 10756 if (count && values && keys) { |
10702 for (NSUInteger i = 0; i < count; ++i) { | 10757 for (NSUInteger i = 0; i < count; ++i) { |
10703 if (!keys[i]) { | 10758 if (!keys[i]) { |
10704 [NSException raise:NSInvalidArgumentException | 10759 [NSException raise:NSInvalidArgumentException |
10705 format:@"Attempting to add nil key to a Dictionary"]; | 10760 format:@"Attempting to add nil key to a Dictionary"]; |
10706 } | 10761 } |
10707 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | 10762 [_dictionary setObject:@(values[i]) forKey:keys[i]]; |
10708 } | 10763 } |
10709 } | 10764 } |
10710 } | 10765 } |
10711 return self; | 10766 return self; |
10712 } | 10767 } |
10713 | 10768 |
10714 - (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary { | 10769 - (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary { |
10715 self = [self initWithValues:NULL forKeys:NULL count:0]; | 10770 self = [self initWithDoubles:NULL forKeys:NULL count:0]; |
10716 if (self) { | 10771 if (self) { |
10717 if (dictionary) { | 10772 if (dictionary) { |
10718 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | 10773 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; |
10719 } | 10774 } |
10720 } | 10775 } |
10721 return self; | 10776 return self; |
10722 } | 10777 } |
10723 | 10778 |
10724 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 10779 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
10725 #pragma unused(numItems) | 10780 #pragma unused(numItems) |
10726 return [self initWithValues:NULL forKeys:NULL count:0]; | 10781 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
10727 } | 10782 } |
10728 | 10783 |
10729 - (void)dealloc { | 10784 - (void)dealloc { |
10730 NSAssert(!_autocreator, | 10785 NSAssert(!_autocreator, |
10731 @"%@: Autocreator must be cleared before release, autocreator: %@", | 10786 @"%@: Autocreator must be cleared before release, autocreator: %@", |
10732 [self class], _autocreator); | 10787 [self class], _autocreator); |
10733 [_dictionary release]; | 10788 [_dictionary release]; |
10734 [super dealloc]; | 10789 [super dealloc]; |
10735 } | 10790 } |
10736 | 10791 |
10737 - (instancetype)copyWithZone:(NSZone *)zone { | 10792 - (instancetype)copyWithZone:(NSZone *)zone { |
10738 return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self
]; | 10793 return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self
]; |
10739 } | 10794 } |
10740 | 10795 |
10741 - (BOOL)isEqual:(GPBStringDoubleDictionary *)other { | 10796 - (BOOL)isEqual:(id)other { |
10742 if (self == other) { | 10797 if (self == other) { |
10743 return YES; | 10798 return YES; |
10744 } | 10799 } |
10745 if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) { | 10800 if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) { |
10746 return NO; | 10801 return NO; |
10747 } | 10802 } |
10748 return [_dictionary isEqual:other->_dictionary]; | 10803 GPBStringDoubleDictionary *otherDictionary = other; |
| 10804 return [_dictionary isEqual:otherDictionary->_dictionary]; |
10749 } | 10805 } |
10750 | 10806 |
10751 - (NSUInteger)hash { | 10807 - (NSUInteger)hash { |
10752 return _dictionary.count; | 10808 return _dictionary.count; |
10753 } | 10809 } |
10754 | 10810 |
10755 - (NSString *)description { | 10811 - (NSString *)description { |
10756 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 10812 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
10757 } | 10813 } |
10758 | 10814 |
10759 - (NSUInteger)count { | 10815 - (NSUInteger)count { |
10760 return _dictionary.count; | 10816 return _dictionary.count; |
10761 } | 10817 } |
10762 | 10818 |
10763 - (void)enumerateKeysAndValuesUsingBlock: | 10819 - (void)enumerateKeysAndDoublesUsingBlock: |
10764 (void (^)(NSString *key, double value, BOOL *stop))block { | 10820 (void (^)(NSString *key, double value, BOOL *stop))block { |
10765 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 10821 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
10766 NSNumber *aValue, | 10822 NSNumber *aValue, |
10767 BOOL *stop) { | 10823 BOOL *stop) { |
10768 block(aKey, [aValue doubleValue], stop); | 10824 block(aKey, [aValue doubleValue], stop); |
10769 }]; | 10825 }]; |
10770 } | 10826 } |
10771 | 10827 |
10772 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | 10828 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { |
10773 NSUInteger count = _dictionary.count; | 10829 NSUInteger count = _dictionary.count; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10811 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | 10867 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); |
10812 }]; | 10868 }]; |
10813 } | 10869 } |
10814 | 10870 |
10815 - (void)setGPBGenericValue:(GPBGenericValue *)value | 10871 - (void)setGPBGenericValue:(GPBGenericValue *)value |
10816 forGPBGenericValueKey:(GPBGenericValue *)key { | 10872 forGPBGenericValueKey:(GPBGenericValue *)key { |
10817 [_dictionary setObject:@(value->valueDouble) forKey:key->valueString]; | 10873 [_dictionary setObject:@(value->valueDouble) forKey:key->valueString]; |
10818 } | 10874 } |
10819 | 10875 |
10820 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 10876 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
10821 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, double value, BOOL *st
op) { | 10877 [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, BOOL *s
top) { |
10822 #pragma unused(stop) | 10878 #pragma unused(stop) |
10823 block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); | 10879 block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); |
10824 }]; | 10880 }]; |
10825 } | 10881 } |
10826 | 10882 |
10827 - (BOOL)valueForKey:(NSString *)key value:(double *)value { | 10883 - (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key { |
10828 NSNumber *wrapped = [_dictionary objectForKey:key]; | 10884 NSNumber *wrapped = [_dictionary objectForKey:key]; |
10829 if (wrapped && value) { | 10885 if (wrapped && value) { |
10830 *value = [wrapped doubleValue]; | 10886 *value = [wrapped doubleValue]; |
10831 } | 10887 } |
10832 return (wrapped != NULL); | 10888 return (wrapped != NULL); |
10833 } | 10889 } |
10834 | 10890 |
10835 - (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary { | 10891 - (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary { |
10836 if (otherDictionary) { | 10892 if (otherDictionary) { |
10837 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | 10893 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; |
10838 if (_autocreator) { | 10894 if (_autocreator) { |
10839 GPBAutocreatedDictionaryModified(_autocreator, self); | 10895 GPBAutocreatedDictionaryModified(_autocreator, self); |
10840 } | 10896 } |
10841 } | 10897 } |
10842 } | 10898 } |
10843 | 10899 |
10844 - (void)setValue:(double)value forKey:(NSString *)key { | 10900 - (void)setDouble:(double)value forKey:(NSString *)key { |
10845 if (!key) { | 10901 if (!key) { |
10846 [NSException raise:NSInvalidArgumentException | 10902 [NSException raise:NSInvalidArgumentException |
10847 format:@"Attempting to add nil key to a Dictionary"]; | 10903 format:@"Attempting to add nil key to a Dictionary"]; |
10848 } | 10904 } |
10849 [_dictionary setObject:@(value) forKey:key]; | 10905 [_dictionary setObject:@(value) forKey:key]; |
10850 if (_autocreator) { | 10906 if (_autocreator) { |
10851 GPBAutocreatedDictionaryModified(_autocreator, self); | 10907 GPBAutocreatedDictionaryModified(_autocreator, self); |
10852 } | 10908 } |
10853 } | 10909 } |
10854 | 10910 |
10855 - (void)removeValueForKey:(NSString *)aKey { | 10911 - (void)removeDoubleForKey:(NSString *)aKey { |
10856 [_dictionary removeObjectForKey:aKey]; | 10912 [_dictionary removeObjectForKey:aKey]; |
10857 } | 10913 } |
10858 | 10914 |
10859 - (void)removeAll { | 10915 - (void)removeAll { |
10860 [_dictionary removeAllObjects]; | 10916 [_dictionary removeAllObjects]; |
10861 } | 10917 } |
10862 | 10918 |
10863 @end | 10919 @end |
10864 | 10920 |
10865 #pragma mark - String -> Enum | 10921 #pragma mark - String -> Enum |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10973 @"%@: Autocreator must be cleared before release, autocreator: %@", | 11029 @"%@: Autocreator must be cleared before release, autocreator: %@", |
10974 [self class], _autocreator); | 11030 [self class], _autocreator); |
10975 [_dictionary release]; | 11031 [_dictionary release]; |
10976 [super dealloc]; | 11032 [super dealloc]; |
10977 } | 11033 } |
10978 | 11034 |
10979 - (instancetype)copyWithZone:(NSZone *)zone { | 11035 - (instancetype)copyWithZone:(NSZone *)zone { |
10980 return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self]; | 11036 return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self]; |
10981 } | 11037 } |
10982 | 11038 |
10983 - (BOOL)isEqual:(GPBStringEnumDictionary *)other { | 11039 - (BOOL)isEqual:(id)other { |
10984 if (self == other) { | 11040 if (self == other) { |
10985 return YES; | 11041 return YES; |
10986 } | 11042 } |
10987 if (![other isKindOfClass:[GPBStringEnumDictionary class]]) { | 11043 if (![other isKindOfClass:[GPBStringEnumDictionary class]]) { |
10988 return NO; | 11044 return NO; |
10989 } | 11045 } |
10990 return [_dictionary isEqual:other->_dictionary]; | 11046 GPBStringEnumDictionary *otherDictionary = other; |
| 11047 return [_dictionary isEqual:otherDictionary->_dictionary]; |
10991 } | 11048 } |
10992 | 11049 |
10993 - (NSUInteger)hash { | 11050 - (NSUInteger)hash { |
10994 return _dictionary.count; | 11051 return _dictionary.count; |
10995 } | 11052 } |
10996 | 11053 |
10997 - (NSString *)description { | 11054 - (NSString *)description { |
10998 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | 11055 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; |
10999 } | 11056 } |
11000 | 11057 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11071 [_dictionary setObject:@(value->valueEnum) forKey:key->valueString]; | 11128 [_dictionary setObject:@(value->valueEnum) forKey:key->valueString]; |
11072 } | 11129 } |
11073 | 11130 |
11074 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 11131 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
11075 [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL
*stop) { | 11132 [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL
*stop) { |
11076 #pragma unused(stop) | 11133 #pragma unused(stop) |
11077 block(key, @(value)); | 11134 block(key, @(value)); |
11078 }]; | 11135 }]; |
11079 } | 11136 } |
11080 | 11137 |
11081 - (BOOL)valueForKey:(NSString *)key value:(int32_t *)value { | 11138 - (BOOL)getEnum:(int32_t *)value forKey:(NSString *)key { |
11082 NSNumber *wrapped = [_dictionary objectForKey:key]; | 11139 NSNumber *wrapped = [_dictionary objectForKey:key]; |
11083 if (wrapped && value) { | 11140 if (wrapped && value) { |
11084 int32_t result = [wrapped intValue]; | 11141 int32_t result = [wrapped intValue]; |
11085 if (!_validationFunc(result)) { | 11142 if (!_validationFunc(result)) { |
11086 result = kGPBUnrecognizedEnumeratorValue; | 11143 result = kGPBUnrecognizedEnumeratorValue; |
11087 } | 11144 } |
11088 *value = result; | 11145 *value = result; |
11089 } | 11146 } |
11090 return (wrapped != NULL); | 11147 return (wrapped != NULL); |
11091 } | 11148 } |
11092 | 11149 |
11093 - (BOOL)valueForKey:(NSString *)key rawValue:(int32_t *)rawValue { | 11150 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(NSString *)key { |
11094 NSNumber *wrapped = [_dictionary objectForKey:key]; | 11151 NSNumber *wrapped = [_dictionary objectForKey:key]; |
11095 if (wrapped && rawValue) { | 11152 if (wrapped && rawValue) { |
11096 *rawValue = [wrapped intValue]; | 11153 *rawValue = [wrapped intValue]; |
11097 } | 11154 } |
11098 return (wrapped != NULL); | 11155 return (wrapped != NULL); |
11099 } | 11156 } |
11100 | 11157 |
11101 - (void)enumerateKeysAndValuesUsingBlock: | 11158 - (void)enumerateKeysAndEnumsUsingBlock: |
11102 (void (^)(NSString *key, int32_t value, BOOL *stop))block { | 11159 (void (^)(NSString *key, int32_t value, BOOL *stop))block { |
11103 GPBEnumValidationFunc func = _validationFunc; | 11160 GPBEnumValidationFunc func = _validationFunc; |
11104 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | 11161 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, |
11105 NSNumber *aValue, | 11162 NSNumber *aValue, |
11106 BOOL *stop) { | 11163 BOOL *stop) { |
11107 int32_t unwrapped = [aValue intValue]; | 11164 int32_t unwrapped = [aValue intValue]; |
11108 if (!func(unwrapped)) { | 11165 if (!func(unwrapped)) { |
11109 unwrapped = kGPBUnrecognizedEnumeratorValue; | 11166 unwrapped = kGPBUnrecognizedEnumeratorValue; |
11110 } | 11167 } |
11111 block(aKey, unwrapped, stop); | 11168 block(aKey, unwrapped, stop); |
(...skipping 13 matching lines...) Expand all Loading... |
11125 if (!key) { | 11182 if (!key) { |
11126 [NSException raise:NSInvalidArgumentException | 11183 [NSException raise:NSInvalidArgumentException |
11127 format:@"Attempting to add nil key to a Dictionary"]; | 11184 format:@"Attempting to add nil key to a Dictionary"]; |
11128 } | 11185 } |
11129 [_dictionary setObject:@(value) forKey:key]; | 11186 [_dictionary setObject:@(value) forKey:key]; |
11130 if (_autocreator) { | 11187 if (_autocreator) { |
11131 GPBAutocreatedDictionaryModified(_autocreator, self); | 11188 GPBAutocreatedDictionaryModified(_autocreator, self); |
11132 } | 11189 } |
11133 } | 11190 } |
11134 | 11191 |
11135 - (void)removeValueForKey:(NSString *)aKey { | 11192 - (void)removeEnumForKey:(NSString *)aKey { |
11136 [_dictionary removeObjectForKey:aKey]; | 11193 [_dictionary removeObjectForKey:aKey]; |
11137 } | 11194 } |
11138 | 11195 |
11139 - (void)removeAll { | 11196 - (void)removeAll { |
11140 [_dictionary removeAllObjects]; | 11197 [_dictionary removeAllObjects]; |
11141 } | 11198 } |
11142 | 11199 |
11143 - (void)setValue:(int32_t)value forKey:(NSString *)key { | 11200 - (void)setEnum:(int32_t)value forKey:(NSString *)key { |
11144 if (!key) { | 11201 if (!key) { |
11145 [NSException raise:NSInvalidArgumentException | 11202 [NSException raise:NSInvalidArgumentException |
11146 format:@"Attempting to add nil key to a Dictionary"]; | 11203 format:@"Attempting to add nil key to a Dictionary"]; |
11147 } | 11204 } |
11148 if (!_validationFunc(value)) { | 11205 if (!_validationFunc(value)) { |
11149 [NSException raise:NSInvalidArgumentException | 11206 [NSException raise:NSInvalidArgumentException |
11150 format:@"GPBStringEnumDictionary: Attempt to set an unknown enum
value (%d)", | 11207 format:@"GPBStringEnumDictionary: Attempt to set an unknown enum
value (%d)", |
11151 value]; | 11208 value]; |
11152 } | 11209 } |
11153 | 11210 |
(...skipping 13 matching lines...) Expand all Loading... |
11167 | 11224 |
11168 #pragma mark - Bool -> UInt32 | 11225 #pragma mark - Bool -> UInt32 |
11169 | 11226 |
11170 @implementation GPBBoolUInt32Dictionary { | 11227 @implementation GPBBoolUInt32Dictionary { |
11171 @package | 11228 @package |
11172 uint32_t _values[2]; | 11229 uint32_t _values[2]; |
11173 BOOL _valueSet[2]; | 11230 BOOL _valueSet[2]; |
11174 } | 11231 } |
11175 | 11232 |
11176 + (instancetype)dictionary { | 11233 + (instancetype)dictionary { |
11177 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 11234 return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; |
11178 } | 11235 } |
11179 | 11236 |
11180 + (instancetype)dictionaryWithValue:(uint32_t)value | 11237 + (instancetype)dictionaryWithUInt32:(uint32_t)value |
11181 forKey:(BOOL)key { | 11238 forKey:(BOOL)key { |
11182 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 11239 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
11183 // on to get the type correct. | 11240 // on to get the type correct. |
11184 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithValues:&value | 11241 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithUInt32s:&value |
11185 forKeys:&key | 11242 forKeys:&key |
11186 count:1] autorelease]
; | 11243 count:1] autorelease
]; |
11187 } | 11244 } |
11188 | 11245 |
11189 + (instancetype)dictionaryWithValues:(const uint32_t [])values | 11246 + (instancetype)dictionaryWithUInt32s:(const uint32_t [])values |
11190 forKeys:(const BOOL [])keys | 11247 forKeys:(const BOOL [])keys |
11191 count:(NSUInteger)count { | 11248 count:(NSUInteger)count { |
11192 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 11249 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t32s:forKeys:count: |
11193 // on to get the type correct. | 11250 // on to get the type correct. |
11194 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithValues:values | 11251 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithUInt32s:values |
11195 forKeys:keys | 11252 forKeys:keys |
11196 count:count] autorele
ase]; | 11253 count:count] autorel
ease]; |
11197 } | 11254 } |
11198 | 11255 |
11199 + (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { | 11256 + (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { |
11200 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 11257 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
11201 // on to get the type correct. | 11258 // on to get the type correct. |
11202 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 11259 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
11203 } | 11260 } |
11204 | 11261 |
11205 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 11262 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
11206 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 11263 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
11207 } | 11264 } |
11208 | 11265 |
11209 - (instancetype)init { | 11266 - (instancetype)init { |
11210 return [self initWithValues:NULL forKeys:NULL count:0]; | 11267 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
11211 } | 11268 } |
11212 | 11269 |
11213 - (instancetype)initWithValues:(const uint32_t [])values | 11270 - (instancetype)initWithUInt32s:(const uint32_t [])values |
11214 forKeys:(const BOOL [])keys | 11271 forKeys:(const BOOL [])keys |
11215 count:(NSUInteger)count { | 11272 count:(NSUInteger)count { |
11216 self = [super init]; | 11273 self = [super init]; |
11217 if (self) { | 11274 if (self) { |
11218 for (NSUInteger i = 0; i < count; ++i) { | 11275 for (NSUInteger i = 0; i < count; ++i) { |
11219 int idx = keys[i] ? 1 : 0; | 11276 int idx = keys[i] ? 1 : 0; |
11220 _values[idx] = values[i]; | 11277 _values[idx] = values[i]; |
11221 _valueSet[idx] = YES; | 11278 _valueSet[idx] = YES; |
11222 } | 11279 } |
11223 } | 11280 } |
11224 return self; | 11281 return self; |
11225 } | 11282 } |
11226 | 11283 |
11227 - (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { | 11284 - (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { |
11228 self = [self initWithValues:NULL forKeys:NULL count:0]; | 11285 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; |
11229 if (self) { | 11286 if (self) { |
11230 if (dictionary) { | 11287 if (dictionary) { |
11231 for (int i = 0; i < 2; ++i) { | 11288 for (int i = 0; i < 2; ++i) { |
11232 if (dictionary->_valueSet[i]) { | 11289 if (dictionary->_valueSet[i]) { |
11233 _values[i] = dictionary->_values[i]; | 11290 _values[i] = dictionary->_values[i]; |
11234 _valueSet[i] = YES; | 11291 _valueSet[i] = YES; |
11235 } | 11292 } |
11236 } | 11293 } |
11237 } | 11294 } |
11238 } | 11295 } |
11239 return self; | 11296 return self; |
11240 } | 11297 } |
11241 | 11298 |
11242 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 11299 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
11243 #pragma unused(numItems) | 11300 #pragma unused(numItems) |
11244 return [self initWithValues:NULL forKeys:NULL count:0]; | 11301 return [self initWithUInt32s:NULL forKeys:NULL count:0]; |
11245 } | 11302 } |
11246 | 11303 |
11247 #if !defined(NS_BLOCK_ASSERTIONS) | 11304 #if !defined(NS_BLOCK_ASSERTIONS) |
11248 - (void)dealloc { | 11305 - (void)dealloc { |
11249 NSAssert(!_autocreator, | 11306 NSAssert(!_autocreator, |
11250 @"%@: Autocreator must be cleared before release, autocreator: %@", | 11307 @"%@: Autocreator must be cleared before release, autocreator: %@", |
11251 [self class], _autocreator); | 11308 [self class], _autocreator); |
11252 [super dealloc]; | 11309 [super dealloc]; |
11253 } | 11310 } |
11254 #endif // !defined(NS_BLOCK_ASSERTIONS) | 11311 #endif // !defined(NS_BLOCK_ASSERTIONS) |
11255 | 11312 |
11256 - (instancetype)copyWithZone:(NSZone *)zone { | 11313 - (instancetype)copyWithZone:(NSZone *)zone { |
11257 return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self]; | 11314 return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self]; |
11258 } | 11315 } |
11259 | 11316 |
11260 - (BOOL)isEqual:(GPBBoolUInt32Dictionary *)other { | 11317 - (BOOL)isEqual:(id)other { |
11261 if (self == other) { | 11318 if (self == other) { |
11262 return YES; | 11319 return YES; |
11263 } | 11320 } |
11264 if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) { | 11321 if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) { |
11265 return NO; | 11322 return NO; |
11266 } | 11323 } |
11267 if ((_valueSet[0] != other->_valueSet[0]) || | 11324 GPBBoolUInt32Dictionary *otherDictionary = other; |
11268 (_valueSet[1] != other->_valueSet[1])) { | 11325 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || |
| 11326 (_valueSet[1] != otherDictionary->_valueSet[1])) { |
11269 return NO; | 11327 return NO; |
11270 } | 11328 } |
11271 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | 11329 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || |
11272 (_valueSet[1] && (_values[1] != other->_values[1]))) { | 11330 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { |
11273 return NO; | 11331 return NO; |
11274 } | 11332 } |
11275 return YES; | 11333 return YES; |
11276 } | 11334 } |
11277 | 11335 |
11278 - (NSUInteger)hash { | 11336 - (NSUInteger)hash { |
11279 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11337 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11280 } | 11338 } |
11281 | 11339 |
11282 - (NSString *)description { | 11340 - (NSString *)description { |
11283 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 11341 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
11284 if (_valueSet[0]) { | 11342 if (_valueSet[0]) { |
11285 [result appendFormat:@"NO: %u", _values[0]]; | 11343 [result appendFormat:@"NO: %u", _values[0]]; |
11286 } | 11344 } |
11287 if (_valueSet[1]) { | 11345 if (_valueSet[1]) { |
11288 [result appendFormat:@"YES: %u", _values[1]]; | 11346 [result appendFormat:@"YES: %u", _values[1]]; |
11289 } | 11347 } |
11290 [result appendString:@" }"]; | 11348 [result appendString:@" }"]; |
11291 return result; | 11349 return result; |
11292 } | 11350 } |
11293 | 11351 |
11294 - (NSUInteger)count { | 11352 - (NSUInteger)count { |
11295 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11353 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11296 } | 11354 } |
11297 | 11355 |
11298 - (BOOL)valueForKey:(BOOL)key value:(uint32_t *)value { | 11356 - (BOOL)getUInt32:(uint32_t *)value forKey:(BOOL)key { |
11299 int idx = (key ? 1 : 0); | 11357 int idx = (key ? 1 : 0); |
11300 if (_valueSet[idx]) { | 11358 if (_valueSet[idx]) { |
11301 if (value) { | 11359 if (value) { |
11302 *value = _values[idx]; | 11360 *value = _values[idx]; |
11303 } | 11361 } |
11304 return YES; | 11362 return YES; |
11305 } | 11363 } |
11306 return NO; | 11364 return NO; |
11307 } | 11365 } |
11308 | 11366 |
11309 - (void)setGPBGenericValue:(GPBGenericValue *)value | 11367 - (void)setGPBGenericValue:(GPBGenericValue *)value |
11310 forGPBGenericValueKey:(GPBGenericValue *)key { | 11368 forGPBGenericValueKey:(GPBGenericValue *)key { |
11311 int idx = (key->valueBool ? 1 : 0); | 11369 int idx = (key->valueBool ? 1 : 0); |
11312 _values[idx] = value->valueUInt32; | 11370 _values[idx] = value->valueUInt32; |
11313 _valueSet[idx] = YES; | 11371 _valueSet[idx] = YES; |
11314 } | 11372 } |
11315 | 11373 |
11316 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 11374 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
11317 if (_valueSet[0]) { | 11375 if (_valueSet[0]) { |
11318 block(@"false", [NSString stringWithFormat:@"%u", _values[0]]); | 11376 block(@"false", [NSString stringWithFormat:@"%u", _values[0]]); |
11319 } | 11377 } |
11320 if (_valueSet[1]) { | 11378 if (_valueSet[1]) { |
11321 block(@"true", [NSString stringWithFormat:@"%u", _values[1]]); | 11379 block(@"true", [NSString stringWithFormat:@"%u", _values[1]]); |
11322 } | 11380 } |
11323 } | 11381 } |
11324 | 11382 |
11325 - (void)enumerateKeysAndValuesUsingBlock: | 11383 - (void)enumerateKeysAndUInt32sUsingBlock: |
11326 (void (^)(BOOL key, uint32_t value, BOOL *stop))block { | 11384 (void (^)(BOOL key, uint32_t value, BOOL *stop))block { |
11327 BOOL stop = NO; | 11385 BOOL stop = NO; |
11328 if (_valueSet[0]) { | 11386 if (_valueSet[0]) { |
11329 block(NO, _values[0], &stop); | 11387 block(NO, _values[0], &stop); |
11330 } | 11388 } |
11331 if (!stop && _valueSet[1]) { | 11389 if (!stop && _valueSet[1]) { |
11332 block(YES, _values[1], &stop); | 11390 block(YES, _values[1], &stop); |
11333 } | 11391 } |
11334 } | 11392 } |
11335 | 11393 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11376 _valueSet[i] = YES; | 11434 _valueSet[i] = YES; |
11377 _values[i] = otherDictionary->_values[i]; | 11435 _values[i] = otherDictionary->_values[i]; |
11378 } | 11436 } |
11379 } | 11437 } |
11380 if (_autocreator) { | 11438 if (_autocreator) { |
11381 GPBAutocreatedDictionaryModified(_autocreator, self); | 11439 GPBAutocreatedDictionaryModified(_autocreator, self); |
11382 } | 11440 } |
11383 } | 11441 } |
11384 } | 11442 } |
11385 | 11443 |
11386 - (void)setValue:(uint32_t)value forKey:(BOOL)key { | 11444 - (void)setUInt32:(uint32_t)value forKey:(BOOL)key { |
11387 int idx = (key ? 1 : 0); | 11445 int idx = (key ? 1 : 0); |
11388 _values[idx] = value; | 11446 _values[idx] = value; |
11389 _valueSet[idx] = YES; | 11447 _valueSet[idx] = YES; |
11390 if (_autocreator) { | 11448 if (_autocreator) { |
11391 GPBAutocreatedDictionaryModified(_autocreator, self); | 11449 GPBAutocreatedDictionaryModified(_autocreator, self); |
11392 } | 11450 } |
11393 } | 11451 } |
11394 | 11452 |
11395 - (void)removeValueForKey:(BOOL)aKey { | 11453 - (void)removeUInt32ForKey:(BOOL)aKey { |
11396 _valueSet[aKey ? 1 : 0] = NO; | 11454 _valueSet[aKey ? 1 : 0] = NO; |
11397 } | 11455 } |
11398 | 11456 |
11399 - (void)removeAll { | 11457 - (void)removeAll { |
11400 _valueSet[0] = NO; | 11458 _valueSet[0] = NO; |
11401 _valueSet[1] = NO; | 11459 _valueSet[1] = NO; |
11402 } | 11460 } |
11403 | 11461 |
11404 @end | 11462 @end |
11405 | 11463 |
11406 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t) | 11464 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t) |
11407 // This block of code is generated, do not edit it directly. | 11465 // This block of code is generated, do not edit it directly. |
11408 | 11466 |
11409 #pragma mark - Bool -> Int32 | 11467 #pragma mark - Bool -> Int32 |
11410 | 11468 |
11411 @implementation GPBBoolInt32Dictionary { | 11469 @implementation GPBBoolInt32Dictionary { |
11412 @package | 11470 @package |
11413 int32_t _values[2]; | 11471 int32_t _values[2]; |
11414 BOOL _valueSet[2]; | 11472 BOOL _valueSet[2]; |
11415 } | 11473 } |
11416 | 11474 |
11417 + (instancetype)dictionary { | 11475 + (instancetype)dictionary { |
11418 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 11476 return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; |
11419 } | 11477 } |
11420 | 11478 |
11421 + (instancetype)dictionaryWithValue:(int32_t)value | 11479 + (instancetype)dictionaryWithInt32:(int32_t)value |
11422 forKey:(BOOL)key { | 11480 forKey:(BOOL)key { |
11423 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 11481 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
11424 // on to get the type correct. | 11482 // on to get the type correct. |
11425 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithValues:&value | 11483 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithInt32s:&value |
11426 forKeys:&key | 11484 forKeys:&key |
11427 count:1] autorelease]; | 11485 count:1] autorelease]; |
11428 } | 11486 } |
11429 | 11487 |
11430 + (instancetype)dictionaryWithValues:(const int32_t [])values | 11488 + (instancetype)dictionaryWithInt32s:(const int32_t [])values |
11431 forKeys:(const BOOL [])keys | 11489 forKeys:(const BOOL [])keys |
11432 count:(NSUInteger)count { | 11490 count:(NSUInteger)count { |
11433 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 11491 // Cast is needed so the compiler knows what class we are invoking initWithInt
32s:forKeys:count: |
11434 // on to get the type correct. | 11492 // on to get the type correct. |
11435 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithValues:values | 11493 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithInt32s:values |
11436 forKeys:keys | 11494 forKeys:keys |
11437 count:count] autorelea
se]; | 11495 count:count] autorelea
se]; |
11438 } | 11496 } |
11439 | 11497 |
11440 + (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary { | 11498 + (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary { |
11441 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 11499 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
11442 // on to get the type correct. | 11500 // on to get the type correct. |
11443 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 11501 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
11444 } | 11502 } |
11445 | 11503 |
11446 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 11504 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
11447 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 11505 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
11448 } | 11506 } |
11449 | 11507 |
11450 - (instancetype)init { | 11508 - (instancetype)init { |
11451 return [self initWithValues:NULL forKeys:NULL count:0]; | 11509 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
11452 } | 11510 } |
11453 | 11511 |
11454 - (instancetype)initWithValues:(const int32_t [])values | 11512 - (instancetype)initWithInt32s:(const int32_t [])values |
11455 forKeys:(const BOOL [])keys | 11513 forKeys:(const BOOL [])keys |
11456 count:(NSUInteger)count { | 11514 count:(NSUInteger)count { |
11457 self = [super init]; | 11515 self = [super init]; |
11458 if (self) { | 11516 if (self) { |
11459 for (NSUInteger i = 0; i < count; ++i) { | 11517 for (NSUInteger i = 0; i < count; ++i) { |
11460 int idx = keys[i] ? 1 : 0; | 11518 int idx = keys[i] ? 1 : 0; |
11461 _values[idx] = values[i]; | 11519 _values[idx] = values[i]; |
11462 _valueSet[idx] = YES; | 11520 _valueSet[idx] = YES; |
11463 } | 11521 } |
11464 } | 11522 } |
11465 return self; | 11523 return self; |
11466 } | 11524 } |
11467 | 11525 |
11468 - (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary { | 11526 - (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary { |
11469 self = [self initWithValues:NULL forKeys:NULL count:0]; | 11527 self = [self initWithInt32s:NULL forKeys:NULL count:0]; |
11470 if (self) { | 11528 if (self) { |
11471 if (dictionary) { | 11529 if (dictionary) { |
11472 for (int i = 0; i < 2; ++i) { | 11530 for (int i = 0; i < 2; ++i) { |
11473 if (dictionary->_valueSet[i]) { | 11531 if (dictionary->_valueSet[i]) { |
11474 _values[i] = dictionary->_values[i]; | 11532 _values[i] = dictionary->_values[i]; |
11475 _valueSet[i] = YES; | 11533 _valueSet[i] = YES; |
11476 } | 11534 } |
11477 } | 11535 } |
11478 } | 11536 } |
11479 } | 11537 } |
11480 return self; | 11538 return self; |
11481 } | 11539 } |
11482 | 11540 |
11483 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 11541 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
11484 #pragma unused(numItems) | 11542 #pragma unused(numItems) |
11485 return [self initWithValues:NULL forKeys:NULL count:0]; | 11543 return [self initWithInt32s:NULL forKeys:NULL count:0]; |
11486 } | 11544 } |
11487 | 11545 |
11488 #if !defined(NS_BLOCK_ASSERTIONS) | 11546 #if !defined(NS_BLOCK_ASSERTIONS) |
11489 - (void)dealloc { | 11547 - (void)dealloc { |
11490 NSAssert(!_autocreator, | 11548 NSAssert(!_autocreator, |
11491 @"%@: Autocreator must be cleared before release, autocreator: %@", | 11549 @"%@: Autocreator must be cleared before release, autocreator: %@", |
11492 [self class], _autocreator); | 11550 [self class], _autocreator); |
11493 [super dealloc]; | 11551 [super dealloc]; |
11494 } | 11552 } |
11495 #endif // !defined(NS_BLOCK_ASSERTIONS) | 11553 #endif // !defined(NS_BLOCK_ASSERTIONS) |
11496 | 11554 |
11497 - (instancetype)copyWithZone:(NSZone *)zone { | 11555 - (instancetype)copyWithZone:(NSZone *)zone { |
11498 return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self]; | 11556 return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self]; |
11499 } | 11557 } |
11500 | 11558 |
11501 - (BOOL)isEqual:(GPBBoolInt32Dictionary *)other { | 11559 - (BOOL)isEqual:(id)other { |
11502 if (self == other) { | 11560 if (self == other) { |
11503 return YES; | 11561 return YES; |
11504 } | 11562 } |
11505 if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) { | 11563 if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) { |
11506 return NO; | 11564 return NO; |
11507 } | 11565 } |
11508 if ((_valueSet[0] != other->_valueSet[0]) || | 11566 GPBBoolInt32Dictionary *otherDictionary = other; |
11509 (_valueSet[1] != other->_valueSet[1])) { | 11567 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || |
| 11568 (_valueSet[1] != otherDictionary->_valueSet[1])) { |
11510 return NO; | 11569 return NO; |
11511 } | 11570 } |
11512 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | 11571 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || |
11513 (_valueSet[1] && (_values[1] != other->_values[1]))) { | 11572 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { |
11514 return NO; | 11573 return NO; |
11515 } | 11574 } |
11516 return YES; | 11575 return YES; |
11517 } | 11576 } |
11518 | 11577 |
11519 - (NSUInteger)hash { | 11578 - (NSUInteger)hash { |
11520 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11579 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11521 } | 11580 } |
11522 | 11581 |
11523 - (NSString *)description { | 11582 - (NSString *)description { |
11524 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 11583 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
11525 if (_valueSet[0]) { | 11584 if (_valueSet[0]) { |
11526 [result appendFormat:@"NO: %d", _values[0]]; | 11585 [result appendFormat:@"NO: %d", _values[0]]; |
11527 } | 11586 } |
11528 if (_valueSet[1]) { | 11587 if (_valueSet[1]) { |
11529 [result appendFormat:@"YES: %d", _values[1]]; | 11588 [result appendFormat:@"YES: %d", _values[1]]; |
11530 } | 11589 } |
11531 [result appendString:@" }"]; | 11590 [result appendString:@" }"]; |
11532 return result; | 11591 return result; |
11533 } | 11592 } |
11534 | 11593 |
11535 - (NSUInteger)count { | 11594 - (NSUInteger)count { |
11536 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11595 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11537 } | 11596 } |
11538 | 11597 |
11539 - (BOOL)valueForKey:(BOOL)key value:(int32_t *)value { | 11598 - (BOOL)getInt32:(int32_t *)value forKey:(BOOL)key { |
11540 int idx = (key ? 1 : 0); | 11599 int idx = (key ? 1 : 0); |
11541 if (_valueSet[idx]) { | 11600 if (_valueSet[idx]) { |
11542 if (value) { | 11601 if (value) { |
11543 *value = _values[idx]; | 11602 *value = _values[idx]; |
11544 } | 11603 } |
11545 return YES; | 11604 return YES; |
11546 } | 11605 } |
11547 return NO; | 11606 return NO; |
11548 } | 11607 } |
11549 | 11608 |
11550 - (void)setGPBGenericValue:(GPBGenericValue *)value | 11609 - (void)setGPBGenericValue:(GPBGenericValue *)value |
11551 forGPBGenericValueKey:(GPBGenericValue *)key { | 11610 forGPBGenericValueKey:(GPBGenericValue *)key { |
11552 int idx = (key->valueBool ? 1 : 0); | 11611 int idx = (key->valueBool ? 1 : 0); |
11553 _values[idx] = value->valueInt32; | 11612 _values[idx] = value->valueInt32; |
11554 _valueSet[idx] = YES; | 11613 _valueSet[idx] = YES; |
11555 } | 11614 } |
11556 | 11615 |
11557 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 11616 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
11558 if (_valueSet[0]) { | 11617 if (_valueSet[0]) { |
11559 block(@"false", [NSString stringWithFormat:@"%d", _values[0]]); | 11618 block(@"false", [NSString stringWithFormat:@"%d", _values[0]]); |
11560 } | 11619 } |
11561 if (_valueSet[1]) { | 11620 if (_valueSet[1]) { |
11562 block(@"true", [NSString stringWithFormat:@"%d", _values[1]]); | 11621 block(@"true", [NSString stringWithFormat:@"%d", _values[1]]); |
11563 } | 11622 } |
11564 } | 11623 } |
11565 | 11624 |
11566 - (void)enumerateKeysAndValuesUsingBlock: | 11625 - (void)enumerateKeysAndInt32sUsingBlock: |
11567 (void (^)(BOOL key, int32_t value, BOOL *stop))block { | 11626 (void (^)(BOOL key, int32_t value, BOOL *stop))block { |
11568 BOOL stop = NO; | 11627 BOOL stop = NO; |
11569 if (_valueSet[0]) { | 11628 if (_valueSet[0]) { |
11570 block(NO, _values[0], &stop); | 11629 block(NO, _values[0], &stop); |
11571 } | 11630 } |
11572 if (!stop && _valueSet[1]) { | 11631 if (!stop && _valueSet[1]) { |
11573 block(YES, _values[1], &stop); | 11632 block(YES, _values[1], &stop); |
11574 } | 11633 } |
11575 } | 11634 } |
11576 | 11635 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11617 _valueSet[i] = YES; | 11676 _valueSet[i] = YES; |
11618 _values[i] = otherDictionary->_values[i]; | 11677 _values[i] = otherDictionary->_values[i]; |
11619 } | 11678 } |
11620 } | 11679 } |
11621 if (_autocreator) { | 11680 if (_autocreator) { |
11622 GPBAutocreatedDictionaryModified(_autocreator, self); | 11681 GPBAutocreatedDictionaryModified(_autocreator, self); |
11623 } | 11682 } |
11624 } | 11683 } |
11625 } | 11684 } |
11626 | 11685 |
11627 - (void)setValue:(int32_t)value forKey:(BOOL)key { | 11686 - (void)setInt32:(int32_t)value forKey:(BOOL)key { |
11628 int idx = (key ? 1 : 0); | 11687 int idx = (key ? 1 : 0); |
11629 _values[idx] = value; | 11688 _values[idx] = value; |
11630 _valueSet[idx] = YES; | 11689 _valueSet[idx] = YES; |
11631 if (_autocreator) { | 11690 if (_autocreator) { |
11632 GPBAutocreatedDictionaryModified(_autocreator, self); | 11691 GPBAutocreatedDictionaryModified(_autocreator, self); |
11633 } | 11692 } |
11634 } | 11693 } |
11635 | 11694 |
11636 - (void)removeValueForKey:(BOOL)aKey { | 11695 - (void)removeInt32ForKey:(BOOL)aKey { |
11637 _valueSet[aKey ? 1 : 0] = NO; | 11696 _valueSet[aKey ? 1 : 0] = NO; |
11638 } | 11697 } |
11639 | 11698 |
11640 - (void)removeAll { | 11699 - (void)removeAll { |
11641 _valueSet[0] = NO; | 11700 _valueSet[0] = NO; |
11642 _valueSet[1] = NO; | 11701 _valueSet[1] = NO; |
11643 } | 11702 } |
11644 | 11703 |
11645 @end | 11704 @end |
11646 | 11705 |
11647 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t) | 11706 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t) |
11648 // This block of code is generated, do not edit it directly. | 11707 // This block of code is generated, do not edit it directly. |
11649 | 11708 |
11650 #pragma mark - Bool -> UInt64 | 11709 #pragma mark - Bool -> UInt64 |
11651 | 11710 |
11652 @implementation GPBBoolUInt64Dictionary { | 11711 @implementation GPBBoolUInt64Dictionary { |
11653 @package | 11712 @package |
11654 uint64_t _values[2]; | 11713 uint64_t _values[2]; |
11655 BOOL _valueSet[2]; | 11714 BOOL _valueSet[2]; |
11656 } | 11715 } |
11657 | 11716 |
11658 + (instancetype)dictionary { | 11717 + (instancetype)dictionary { |
11659 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 11718 return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; |
11660 } | 11719 } |
11661 | 11720 |
11662 + (instancetype)dictionaryWithValue:(uint64_t)value | 11721 + (instancetype)dictionaryWithUInt64:(uint64_t)value |
11663 forKey:(BOOL)key { | 11722 forKey:(BOOL)key { |
11664 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 11723 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
11665 // on to get the type correct. | 11724 // on to get the type correct. |
11666 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithValues:&value | 11725 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithUInt64s:&value |
11667 forKeys:&key | 11726 forKeys:&key |
11668 count:1] autorelease]
; | 11727 count:1] autorelease
]; |
11669 } | 11728 } |
11670 | 11729 |
11671 + (instancetype)dictionaryWithValues:(const uint64_t [])values | 11730 + (instancetype)dictionaryWithUInt64s:(const uint64_t [])values |
11672 forKeys:(const BOOL [])keys | 11731 forKeys:(const BOOL [])keys |
11673 count:(NSUInteger)count { | 11732 count:(NSUInteger)count { |
11674 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 11733 // Cast is needed so the compiler knows what class we are invoking initWithUIn
t64s:forKeys:count: |
11675 // on to get the type correct. | 11734 // on to get the type correct. |
11676 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithValues:values | 11735 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithUInt64s:values |
11677 forKeys:keys | 11736 forKeys:keys |
11678 count:count] autorele
ase]; | 11737 count:count] autorel
ease]; |
11679 } | 11738 } |
11680 | 11739 |
11681 + (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { | 11740 + (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { |
11682 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 11741 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
11683 // on to get the type correct. | 11742 // on to get the type correct. |
11684 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 11743 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
11685 } | 11744 } |
11686 | 11745 |
11687 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 11746 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
11688 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 11747 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
11689 } | 11748 } |
11690 | 11749 |
11691 - (instancetype)init { | 11750 - (instancetype)init { |
11692 return [self initWithValues:NULL forKeys:NULL count:0]; | 11751 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
11693 } | 11752 } |
11694 | 11753 |
11695 - (instancetype)initWithValues:(const uint64_t [])values | 11754 - (instancetype)initWithUInt64s:(const uint64_t [])values |
11696 forKeys:(const BOOL [])keys | 11755 forKeys:(const BOOL [])keys |
11697 count:(NSUInteger)count { | 11756 count:(NSUInteger)count { |
11698 self = [super init]; | 11757 self = [super init]; |
11699 if (self) { | 11758 if (self) { |
11700 for (NSUInteger i = 0; i < count; ++i) { | 11759 for (NSUInteger i = 0; i < count; ++i) { |
11701 int idx = keys[i] ? 1 : 0; | 11760 int idx = keys[i] ? 1 : 0; |
11702 _values[idx] = values[i]; | 11761 _values[idx] = values[i]; |
11703 _valueSet[idx] = YES; | 11762 _valueSet[idx] = YES; |
11704 } | 11763 } |
11705 } | 11764 } |
11706 return self; | 11765 return self; |
11707 } | 11766 } |
11708 | 11767 |
11709 - (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { | 11768 - (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { |
11710 self = [self initWithValues:NULL forKeys:NULL count:0]; | 11769 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; |
11711 if (self) { | 11770 if (self) { |
11712 if (dictionary) { | 11771 if (dictionary) { |
11713 for (int i = 0; i < 2; ++i) { | 11772 for (int i = 0; i < 2; ++i) { |
11714 if (dictionary->_valueSet[i]) { | 11773 if (dictionary->_valueSet[i]) { |
11715 _values[i] = dictionary->_values[i]; | 11774 _values[i] = dictionary->_values[i]; |
11716 _valueSet[i] = YES; | 11775 _valueSet[i] = YES; |
11717 } | 11776 } |
11718 } | 11777 } |
11719 } | 11778 } |
11720 } | 11779 } |
11721 return self; | 11780 return self; |
11722 } | 11781 } |
11723 | 11782 |
11724 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 11783 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
11725 #pragma unused(numItems) | 11784 #pragma unused(numItems) |
11726 return [self initWithValues:NULL forKeys:NULL count:0]; | 11785 return [self initWithUInt64s:NULL forKeys:NULL count:0]; |
11727 } | 11786 } |
11728 | 11787 |
11729 #if !defined(NS_BLOCK_ASSERTIONS) | 11788 #if !defined(NS_BLOCK_ASSERTIONS) |
11730 - (void)dealloc { | 11789 - (void)dealloc { |
11731 NSAssert(!_autocreator, | 11790 NSAssert(!_autocreator, |
11732 @"%@: Autocreator must be cleared before release, autocreator: %@", | 11791 @"%@: Autocreator must be cleared before release, autocreator: %@", |
11733 [self class], _autocreator); | 11792 [self class], _autocreator); |
11734 [super dealloc]; | 11793 [super dealloc]; |
11735 } | 11794 } |
11736 #endif // !defined(NS_BLOCK_ASSERTIONS) | 11795 #endif // !defined(NS_BLOCK_ASSERTIONS) |
11737 | 11796 |
11738 - (instancetype)copyWithZone:(NSZone *)zone { | 11797 - (instancetype)copyWithZone:(NSZone *)zone { |
11739 return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self]; | 11798 return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self]; |
11740 } | 11799 } |
11741 | 11800 |
11742 - (BOOL)isEqual:(GPBBoolUInt64Dictionary *)other { | 11801 - (BOOL)isEqual:(id)other { |
11743 if (self == other) { | 11802 if (self == other) { |
11744 return YES; | 11803 return YES; |
11745 } | 11804 } |
11746 if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) { | 11805 if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) { |
11747 return NO; | 11806 return NO; |
11748 } | 11807 } |
11749 if ((_valueSet[0] != other->_valueSet[0]) || | 11808 GPBBoolUInt64Dictionary *otherDictionary = other; |
11750 (_valueSet[1] != other->_valueSet[1])) { | 11809 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || |
| 11810 (_valueSet[1] != otherDictionary->_valueSet[1])) { |
11751 return NO; | 11811 return NO; |
11752 } | 11812 } |
11753 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | 11813 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || |
11754 (_valueSet[1] && (_values[1] != other->_values[1]))) { | 11814 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { |
11755 return NO; | 11815 return NO; |
11756 } | 11816 } |
11757 return YES; | 11817 return YES; |
11758 } | 11818 } |
11759 | 11819 |
11760 - (NSUInteger)hash { | 11820 - (NSUInteger)hash { |
11761 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11821 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11762 } | 11822 } |
11763 | 11823 |
11764 - (NSString *)description { | 11824 - (NSString *)description { |
11765 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 11825 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
11766 if (_valueSet[0]) { | 11826 if (_valueSet[0]) { |
11767 [result appendFormat:@"NO: %llu", _values[0]]; | 11827 [result appendFormat:@"NO: %llu", _values[0]]; |
11768 } | 11828 } |
11769 if (_valueSet[1]) { | 11829 if (_valueSet[1]) { |
11770 [result appendFormat:@"YES: %llu", _values[1]]; | 11830 [result appendFormat:@"YES: %llu", _values[1]]; |
11771 } | 11831 } |
11772 [result appendString:@" }"]; | 11832 [result appendString:@" }"]; |
11773 return result; | 11833 return result; |
11774 } | 11834 } |
11775 | 11835 |
11776 - (NSUInteger)count { | 11836 - (NSUInteger)count { |
11777 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 11837 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
11778 } | 11838 } |
11779 | 11839 |
11780 - (BOOL)valueForKey:(BOOL)key value:(uint64_t *)value { | 11840 - (BOOL)getUInt64:(uint64_t *)value forKey:(BOOL)key { |
11781 int idx = (key ? 1 : 0); | 11841 int idx = (key ? 1 : 0); |
11782 if (_valueSet[idx]) { | 11842 if (_valueSet[idx]) { |
11783 if (value) { | 11843 if (value) { |
11784 *value = _values[idx]; | 11844 *value = _values[idx]; |
11785 } | 11845 } |
11786 return YES; | 11846 return YES; |
11787 } | 11847 } |
11788 return NO; | 11848 return NO; |
11789 } | 11849 } |
11790 | 11850 |
11791 - (void)setGPBGenericValue:(GPBGenericValue *)value | 11851 - (void)setGPBGenericValue:(GPBGenericValue *)value |
11792 forGPBGenericValueKey:(GPBGenericValue *)key { | 11852 forGPBGenericValueKey:(GPBGenericValue *)key { |
11793 int idx = (key->valueBool ? 1 : 0); | 11853 int idx = (key->valueBool ? 1 : 0); |
11794 _values[idx] = value->valueUInt64; | 11854 _values[idx] = value->valueUInt64; |
11795 _valueSet[idx] = YES; | 11855 _valueSet[idx] = YES; |
11796 } | 11856 } |
11797 | 11857 |
11798 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 11858 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
11799 if (_valueSet[0]) { | 11859 if (_valueSet[0]) { |
11800 block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]); | 11860 block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]); |
11801 } | 11861 } |
11802 if (_valueSet[1]) { | 11862 if (_valueSet[1]) { |
11803 block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]); | 11863 block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]); |
11804 } | 11864 } |
11805 } | 11865 } |
11806 | 11866 |
11807 - (void)enumerateKeysAndValuesUsingBlock: | 11867 - (void)enumerateKeysAndUInt64sUsingBlock: |
11808 (void (^)(BOOL key, uint64_t value, BOOL *stop))block { | 11868 (void (^)(BOOL key, uint64_t value, BOOL *stop))block { |
11809 BOOL stop = NO; | 11869 BOOL stop = NO; |
11810 if (_valueSet[0]) { | 11870 if (_valueSet[0]) { |
11811 block(NO, _values[0], &stop); | 11871 block(NO, _values[0], &stop); |
11812 } | 11872 } |
11813 if (!stop && _valueSet[1]) { | 11873 if (!stop && _valueSet[1]) { |
11814 block(YES, _values[1], &stop); | 11874 block(YES, _values[1], &stop); |
11815 } | 11875 } |
11816 } | 11876 } |
11817 | 11877 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11858 _valueSet[i] = YES; | 11918 _valueSet[i] = YES; |
11859 _values[i] = otherDictionary->_values[i]; | 11919 _values[i] = otherDictionary->_values[i]; |
11860 } | 11920 } |
11861 } | 11921 } |
11862 if (_autocreator) { | 11922 if (_autocreator) { |
11863 GPBAutocreatedDictionaryModified(_autocreator, self); | 11923 GPBAutocreatedDictionaryModified(_autocreator, self); |
11864 } | 11924 } |
11865 } | 11925 } |
11866 } | 11926 } |
11867 | 11927 |
11868 - (void)setValue:(uint64_t)value forKey:(BOOL)key { | 11928 - (void)setUInt64:(uint64_t)value forKey:(BOOL)key { |
11869 int idx = (key ? 1 : 0); | 11929 int idx = (key ? 1 : 0); |
11870 _values[idx] = value; | 11930 _values[idx] = value; |
11871 _valueSet[idx] = YES; | 11931 _valueSet[idx] = YES; |
11872 if (_autocreator) { | 11932 if (_autocreator) { |
11873 GPBAutocreatedDictionaryModified(_autocreator, self); | 11933 GPBAutocreatedDictionaryModified(_autocreator, self); |
11874 } | 11934 } |
11875 } | 11935 } |
11876 | 11936 |
11877 - (void)removeValueForKey:(BOOL)aKey { | 11937 - (void)removeUInt64ForKey:(BOOL)aKey { |
11878 _valueSet[aKey ? 1 : 0] = NO; | 11938 _valueSet[aKey ? 1 : 0] = NO; |
11879 } | 11939 } |
11880 | 11940 |
11881 - (void)removeAll { | 11941 - (void)removeAll { |
11882 _valueSet[0] = NO; | 11942 _valueSet[0] = NO; |
11883 _valueSet[1] = NO; | 11943 _valueSet[1] = NO; |
11884 } | 11944 } |
11885 | 11945 |
11886 @end | 11946 @end |
11887 | 11947 |
11888 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t) | 11948 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t) |
11889 // This block of code is generated, do not edit it directly. | 11949 // This block of code is generated, do not edit it directly. |
11890 | 11950 |
11891 #pragma mark - Bool -> Int64 | 11951 #pragma mark - Bool -> Int64 |
11892 | 11952 |
11893 @implementation GPBBoolInt64Dictionary { | 11953 @implementation GPBBoolInt64Dictionary { |
11894 @package | 11954 @package |
11895 int64_t _values[2]; | 11955 int64_t _values[2]; |
11896 BOOL _valueSet[2]; | 11956 BOOL _valueSet[2]; |
11897 } | 11957 } |
11898 | 11958 |
11899 + (instancetype)dictionary { | 11959 + (instancetype)dictionary { |
11900 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 11960 return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; |
11901 } | 11961 } |
11902 | 11962 |
11903 + (instancetype)dictionaryWithValue:(int64_t)value | 11963 + (instancetype)dictionaryWithInt64:(int64_t)value |
11904 forKey:(BOOL)key { | 11964 forKey:(BOOL)key { |
11905 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 11965 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
11906 // on to get the type correct. | 11966 // on to get the type correct. |
11907 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithValues:&value | 11967 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithInt64s:&value |
11908 forKeys:&key | 11968 forKeys:&key |
11909 count:1] autorelease]; | 11969 count:1] autorelease]; |
11910 } | 11970 } |
11911 | 11971 |
11912 + (instancetype)dictionaryWithValues:(const int64_t [])values | 11972 + (instancetype)dictionaryWithInt64s:(const int64_t [])values |
11913 forKeys:(const BOOL [])keys | 11973 forKeys:(const BOOL [])keys |
11914 count:(NSUInteger)count { | 11974 count:(NSUInteger)count { |
11915 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 11975 // Cast is needed so the compiler knows what class we are invoking initWithInt
64s:forKeys:count: |
11916 // on to get the type correct. | 11976 // on to get the type correct. |
11917 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithValues:values | 11977 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithInt64s:values |
11918 forKeys:keys | 11978 forKeys:keys |
11919 count:count] autorelea
se]; | 11979 count:count] autorelea
se]; |
11920 } | 11980 } |
11921 | 11981 |
11922 + (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary { | 11982 + (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary { |
11923 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 11983 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
11924 // on to get the type correct. | 11984 // on to get the type correct. |
11925 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 11985 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
11926 } | 11986 } |
11927 | 11987 |
11928 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 11988 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
11929 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 11989 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
11930 } | 11990 } |
11931 | 11991 |
11932 - (instancetype)init { | 11992 - (instancetype)init { |
11933 return [self initWithValues:NULL forKeys:NULL count:0]; | 11993 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
11934 } | 11994 } |
11935 | 11995 |
11936 - (instancetype)initWithValues:(const int64_t [])values | 11996 - (instancetype)initWithInt64s:(const int64_t [])values |
11937 forKeys:(const BOOL [])keys | 11997 forKeys:(const BOOL [])keys |
11938 count:(NSUInteger)count { | 11998 count:(NSUInteger)count { |
11939 self = [super init]; | 11999 self = [super init]; |
11940 if (self) { | 12000 if (self) { |
11941 for (NSUInteger i = 0; i < count; ++i) { | 12001 for (NSUInteger i = 0; i < count; ++i) { |
11942 int idx = keys[i] ? 1 : 0; | 12002 int idx = keys[i] ? 1 : 0; |
11943 _values[idx] = values[i]; | 12003 _values[idx] = values[i]; |
11944 _valueSet[idx] = YES; | 12004 _valueSet[idx] = YES; |
11945 } | 12005 } |
11946 } | 12006 } |
11947 return self; | 12007 return self; |
11948 } | 12008 } |
11949 | 12009 |
11950 - (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary { | 12010 - (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary { |
11951 self = [self initWithValues:NULL forKeys:NULL count:0]; | 12011 self = [self initWithInt64s:NULL forKeys:NULL count:0]; |
11952 if (self) { | 12012 if (self) { |
11953 if (dictionary) { | 12013 if (dictionary) { |
11954 for (int i = 0; i < 2; ++i) { | 12014 for (int i = 0; i < 2; ++i) { |
11955 if (dictionary->_valueSet[i]) { | 12015 if (dictionary->_valueSet[i]) { |
11956 _values[i] = dictionary->_values[i]; | 12016 _values[i] = dictionary->_values[i]; |
11957 _valueSet[i] = YES; | 12017 _valueSet[i] = YES; |
11958 } | 12018 } |
11959 } | 12019 } |
11960 } | 12020 } |
11961 } | 12021 } |
11962 return self; | 12022 return self; |
11963 } | 12023 } |
11964 | 12024 |
11965 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 12025 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
11966 #pragma unused(numItems) | 12026 #pragma unused(numItems) |
11967 return [self initWithValues:NULL forKeys:NULL count:0]; | 12027 return [self initWithInt64s:NULL forKeys:NULL count:0]; |
11968 } | 12028 } |
11969 | 12029 |
11970 #if !defined(NS_BLOCK_ASSERTIONS) | 12030 #if !defined(NS_BLOCK_ASSERTIONS) |
11971 - (void)dealloc { | 12031 - (void)dealloc { |
11972 NSAssert(!_autocreator, | 12032 NSAssert(!_autocreator, |
11973 @"%@: Autocreator must be cleared before release, autocreator: %@", | 12033 @"%@: Autocreator must be cleared before release, autocreator: %@", |
11974 [self class], _autocreator); | 12034 [self class], _autocreator); |
11975 [super dealloc]; | 12035 [super dealloc]; |
11976 } | 12036 } |
11977 #endif // !defined(NS_BLOCK_ASSERTIONS) | 12037 #endif // !defined(NS_BLOCK_ASSERTIONS) |
11978 | 12038 |
11979 - (instancetype)copyWithZone:(NSZone *)zone { | 12039 - (instancetype)copyWithZone:(NSZone *)zone { |
11980 return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self]; | 12040 return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self]; |
11981 } | 12041 } |
11982 | 12042 |
11983 - (BOOL)isEqual:(GPBBoolInt64Dictionary *)other { | 12043 - (BOOL)isEqual:(id)other { |
11984 if (self == other) { | 12044 if (self == other) { |
11985 return YES; | 12045 return YES; |
11986 } | 12046 } |
11987 if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) { | 12047 if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) { |
11988 return NO; | 12048 return NO; |
11989 } | 12049 } |
11990 if ((_valueSet[0] != other->_valueSet[0]) || | 12050 GPBBoolInt64Dictionary *otherDictionary = other; |
11991 (_valueSet[1] != other->_valueSet[1])) { | 12051 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || |
| 12052 (_valueSet[1] != otherDictionary->_valueSet[1])) { |
11992 return NO; | 12053 return NO; |
11993 } | 12054 } |
11994 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | 12055 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || |
11995 (_valueSet[1] && (_values[1] != other->_values[1]))) { | 12056 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { |
11996 return NO; | 12057 return NO; |
11997 } | 12058 } |
11998 return YES; | 12059 return YES; |
11999 } | 12060 } |
12000 | 12061 |
12001 - (NSUInteger)hash { | 12062 - (NSUInteger)hash { |
12002 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12063 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12003 } | 12064 } |
12004 | 12065 |
12005 - (NSString *)description { | 12066 - (NSString *)description { |
12006 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 12067 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
12007 if (_valueSet[0]) { | 12068 if (_valueSet[0]) { |
12008 [result appendFormat:@"NO: %lld", _values[0]]; | 12069 [result appendFormat:@"NO: %lld", _values[0]]; |
12009 } | 12070 } |
12010 if (_valueSet[1]) { | 12071 if (_valueSet[1]) { |
12011 [result appendFormat:@"YES: %lld", _values[1]]; | 12072 [result appendFormat:@"YES: %lld", _values[1]]; |
12012 } | 12073 } |
12013 [result appendString:@" }"]; | 12074 [result appendString:@" }"]; |
12014 return result; | 12075 return result; |
12015 } | 12076 } |
12016 | 12077 |
12017 - (NSUInteger)count { | 12078 - (NSUInteger)count { |
12018 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12079 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12019 } | 12080 } |
12020 | 12081 |
12021 - (BOOL)valueForKey:(BOOL)key value:(int64_t *)value { | 12082 - (BOOL)getInt64:(int64_t *)value forKey:(BOOL)key { |
12022 int idx = (key ? 1 : 0); | 12083 int idx = (key ? 1 : 0); |
12023 if (_valueSet[idx]) { | 12084 if (_valueSet[idx]) { |
12024 if (value) { | 12085 if (value) { |
12025 *value = _values[idx]; | 12086 *value = _values[idx]; |
12026 } | 12087 } |
12027 return YES; | 12088 return YES; |
12028 } | 12089 } |
12029 return NO; | 12090 return NO; |
12030 } | 12091 } |
12031 | 12092 |
12032 - (void)setGPBGenericValue:(GPBGenericValue *)value | 12093 - (void)setGPBGenericValue:(GPBGenericValue *)value |
12033 forGPBGenericValueKey:(GPBGenericValue *)key { | 12094 forGPBGenericValueKey:(GPBGenericValue *)key { |
12034 int idx = (key->valueBool ? 1 : 0); | 12095 int idx = (key->valueBool ? 1 : 0); |
12035 _values[idx] = value->valueInt64; | 12096 _values[idx] = value->valueInt64; |
12036 _valueSet[idx] = YES; | 12097 _valueSet[idx] = YES; |
12037 } | 12098 } |
12038 | 12099 |
12039 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 12100 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
12040 if (_valueSet[0]) { | 12101 if (_valueSet[0]) { |
12041 block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]); | 12102 block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]); |
12042 } | 12103 } |
12043 if (_valueSet[1]) { | 12104 if (_valueSet[1]) { |
12044 block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]); | 12105 block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]); |
12045 } | 12106 } |
12046 } | 12107 } |
12047 | 12108 |
12048 - (void)enumerateKeysAndValuesUsingBlock: | 12109 - (void)enumerateKeysAndInt64sUsingBlock: |
12049 (void (^)(BOOL key, int64_t value, BOOL *stop))block { | 12110 (void (^)(BOOL key, int64_t value, BOOL *stop))block { |
12050 BOOL stop = NO; | 12111 BOOL stop = NO; |
12051 if (_valueSet[0]) { | 12112 if (_valueSet[0]) { |
12052 block(NO, _values[0], &stop); | 12113 block(NO, _values[0], &stop); |
12053 } | 12114 } |
12054 if (!stop && _valueSet[1]) { | 12115 if (!stop && _valueSet[1]) { |
12055 block(YES, _values[1], &stop); | 12116 block(YES, _values[1], &stop); |
12056 } | 12117 } |
12057 } | 12118 } |
12058 | 12119 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12099 _valueSet[i] = YES; | 12160 _valueSet[i] = YES; |
12100 _values[i] = otherDictionary->_values[i]; | 12161 _values[i] = otherDictionary->_values[i]; |
12101 } | 12162 } |
12102 } | 12163 } |
12103 if (_autocreator) { | 12164 if (_autocreator) { |
12104 GPBAutocreatedDictionaryModified(_autocreator, self); | 12165 GPBAutocreatedDictionaryModified(_autocreator, self); |
12105 } | 12166 } |
12106 } | 12167 } |
12107 } | 12168 } |
12108 | 12169 |
12109 - (void)setValue:(int64_t)value forKey:(BOOL)key { | 12170 - (void)setInt64:(int64_t)value forKey:(BOOL)key { |
12110 int idx = (key ? 1 : 0); | 12171 int idx = (key ? 1 : 0); |
12111 _values[idx] = value; | 12172 _values[idx] = value; |
12112 _valueSet[idx] = YES; | 12173 _valueSet[idx] = YES; |
12113 if (_autocreator) { | 12174 if (_autocreator) { |
12114 GPBAutocreatedDictionaryModified(_autocreator, self); | 12175 GPBAutocreatedDictionaryModified(_autocreator, self); |
12115 } | 12176 } |
12116 } | 12177 } |
12117 | 12178 |
12118 - (void)removeValueForKey:(BOOL)aKey { | 12179 - (void)removeInt64ForKey:(BOOL)aKey { |
12119 _valueSet[aKey ? 1 : 0] = NO; | 12180 _valueSet[aKey ? 1 : 0] = NO; |
12120 } | 12181 } |
12121 | 12182 |
12122 - (void)removeAll { | 12183 - (void)removeAll { |
12123 _valueSet[0] = NO; | 12184 _valueSet[0] = NO; |
12124 _valueSet[1] = NO; | 12185 _valueSet[1] = NO; |
12125 } | 12186 } |
12126 | 12187 |
12127 @end | 12188 @end |
12128 | 12189 |
12129 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL) | 12190 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL) |
12130 // This block of code is generated, do not edit it directly. | 12191 // This block of code is generated, do not edit it directly. |
12131 | 12192 |
12132 #pragma mark - Bool -> Bool | 12193 #pragma mark - Bool -> Bool |
12133 | 12194 |
12134 @implementation GPBBoolBoolDictionary { | 12195 @implementation GPBBoolBoolDictionary { |
12135 @package | 12196 @package |
12136 BOOL _values[2]; | 12197 BOOL _values[2]; |
12137 BOOL _valueSet[2]; | 12198 BOOL _valueSet[2]; |
12138 } | 12199 } |
12139 | 12200 |
12140 + (instancetype)dictionary { | 12201 + (instancetype)dictionary { |
12141 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 12202 return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; |
12142 } | 12203 } |
12143 | 12204 |
12144 + (instancetype)dictionaryWithValue:(BOOL)value | 12205 + (instancetype)dictionaryWithBool:(BOOL)value |
12145 forKey:(BOOL)key { | 12206 forKey:(BOOL)key { |
12146 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 12207 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
12147 // on to get the type correct. | 12208 // on to get the type correct. |
12148 return [[(GPBBoolBoolDictionary*)[self alloc] initWithValues:&value | 12209 return [[(GPBBoolBoolDictionary*)[self alloc] initWithBools:&value |
12149 forKeys:&key | 12210 forKeys:&key |
12150 count:1] autorelease]; | 12211 count:1] autorelease]; |
12151 } | 12212 } |
12152 | 12213 |
12153 + (instancetype)dictionaryWithValues:(const BOOL [])values | 12214 + (instancetype)dictionaryWithBools:(const BOOL [])values |
12154 forKeys:(const BOOL [])keys | 12215 forKeys:(const BOOL [])keys |
12155 count:(NSUInteger)count { | 12216 count:(NSUInteger)count { |
12156 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 12217 // Cast is needed so the compiler knows what class we are invoking initWithBoo
ls:forKeys:count: |
12157 // on to get the type correct. | 12218 // on to get the type correct. |
12158 return [[(GPBBoolBoolDictionary*)[self alloc] initWithValues:values | 12219 return [[(GPBBoolBoolDictionary*)[self alloc] initWithBools:values |
12159 forKeys:keys | 12220 forKeys:keys |
12160 count:count] autoreleas
e]; | 12221 count:count] autorelease
]; |
12161 } | 12222 } |
12162 | 12223 |
12163 + (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary { | 12224 + (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary { |
12164 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 12225 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
12165 // on to get the type correct. | 12226 // on to get the type correct. |
12166 return [[(GPBBoolBoolDictionary*)[self alloc] initWithDictionary:dictionary] a
utorelease]; | 12227 return [[(GPBBoolBoolDictionary*)[self alloc] initWithDictionary:dictionary] a
utorelease]; |
12167 } | 12228 } |
12168 | 12229 |
12169 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 12230 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
12170 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 12231 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
12171 } | 12232 } |
12172 | 12233 |
12173 - (instancetype)init { | 12234 - (instancetype)init { |
12174 return [self initWithValues:NULL forKeys:NULL count:0]; | 12235 return [self initWithBools:NULL forKeys:NULL count:0]; |
12175 } | 12236 } |
12176 | 12237 |
12177 - (instancetype)initWithValues:(const BOOL [])values | 12238 - (instancetype)initWithBools:(const BOOL [])values |
12178 forKeys:(const BOOL [])keys | 12239 forKeys:(const BOOL [])keys |
12179 count:(NSUInteger)count { | 12240 count:(NSUInteger)count { |
12180 self = [super init]; | 12241 self = [super init]; |
12181 if (self) { | 12242 if (self) { |
12182 for (NSUInteger i = 0; i < count; ++i) { | 12243 for (NSUInteger i = 0; i < count; ++i) { |
12183 int idx = keys[i] ? 1 : 0; | 12244 int idx = keys[i] ? 1 : 0; |
12184 _values[idx] = values[i]; | 12245 _values[idx] = values[i]; |
12185 _valueSet[idx] = YES; | 12246 _valueSet[idx] = YES; |
12186 } | 12247 } |
12187 } | 12248 } |
12188 return self; | 12249 return self; |
12189 } | 12250 } |
12190 | 12251 |
12191 - (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary { | 12252 - (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary { |
12192 self = [self initWithValues:NULL forKeys:NULL count:0]; | 12253 self = [self initWithBools:NULL forKeys:NULL count:0]; |
12193 if (self) { | 12254 if (self) { |
12194 if (dictionary) { | 12255 if (dictionary) { |
12195 for (int i = 0; i < 2; ++i) { | 12256 for (int i = 0; i < 2; ++i) { |
12196 if (dictionary->_valueSet[i]) { | 12257 if (dictionary->_valueSet[i]) { |
12197 _values[i] = dictionary->_values[i]; | 12258 _values[i] = dictionary->_values[i]; |
12198 _valueSet[i] = YES; | 12259 _valueSet[i] = YES; |
12199 } | 12260 } |
12200 } | 12261 } |
12201 } | 12262 } |
12202 } | 12263 } |
12203 return self; | 12264 return self; |
12204 } | 12265 } |
12205 | 12266 |
12206 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 12267 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
12207 #pragma unused(numItems) | 12268 #pragma unused(numItems) |
12208 return [self initWithValues:NULL forKeys:NULL count:0]; | 12269 return [self initWithBools:NULL forKeys:NULL count:0]; |
12209 } | 12270 } |
12210 | 12271 |
12211 #if !defined(NS_BLOCK_ASSERTIONS) | 12272 #if !defined(NS_BLOCK_ASSERTIONS) |
12212 - (void)dealloc { | 12273 - (void)dealloc { |
12213 NSAssert(!_autocreator, | 12274 NSAssert(!_autocreator, |
12214 @"%@: Autocreator must be cleared before release, autocreator: %@", | 12275 @"%@: Autocreator must be cleared before release, autocreator: %@", |
12215 [self class], _autocreator); | 12276 [self class], _autocreator); |
12216 [super dealloc]; | 12277 [super dealloc]; |
12217 } | 12278 } |
12218 #endif // !defined(NS_BLOCK_ASSERTIONS) | 12279 #endif // !defined(NS_BLOCK_ASSERTIONS) |
12219 | 12280 |
12220 - (instancetype)copyWithZone:(NSZone *)zone { | 12281 - (instancetype)copyWithZone:(NSZone *)zone { |
12221 return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self]; | 12282 return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self]; |
12222 } | 12283 } |
12223 | 12284 |
12224 - (BOOL)isEqual:(GPBBoolBoolDictionary *)other { | 12285 - (BOOL)isEqual:(id)other { |
12225 if (self == other) { | 12286 if (self == other) { |
12226 return YES; | 12287 return YES; |
12227 } | 12288 } |
12228 if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) { | 12289 if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) { |
12229 return NO; | 12290 return NO; |
12230 } | 12291 } |
12231 if ((_valueSet[0] != other->_valueSet[0]) || | 12292 GPBBoolBoolDictionary *otherDictionary = other; |
12232 (_valueSet[1] != other->_valueSet[1])) { | 12293 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || |
| 12294 (_valueSet[1] != otherDictionary->_valueSet[1])) { |
12233 return NO; | 12295 return NO; |
12234 } | 12296 } |
12235 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | 12297 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || |
12236 (_valueSet[1] && (_values[1] != other->_values[1]))) { | 12298 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { |
12237 return NO; | 12299 return NO; |
12238 } | 12300 } |
12239 return YES; | 12301 return YES; |
12240 } | 12302 } |
12241 | 12303 |
12242 - (NSUInteger)hash { | 12304 - (NSUInteger)hash { |
12243 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12305 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12244 } | 12306 } |
12245 | 12307 |
12246 - (NSString *)description { | 12308 - (NSString *)description { |
12247 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 12309 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
12248 if (_valueSet[0]) { | 12310 if (_valueSet[0]) { |
12249 [result appendFormat:@"NO: %d", _values[0]]; | 12311 [result appendFormat:@"NO: %d", _values[0]]; |
12250 } | 12312 } |
12251 if (_valueSet[1]) { | 12313 if (_valueSet[1]) { |
12252 [result appendFormat:@"YES: %d", _values[1]]; | 12314 [result appendFormat:@"YES: %d", _values[1]]; |
12253 } | 12315 } |
12254 [result appendString:@" }"]; | 12316 [result appendString:@" }"]; |
12255 return result; | 12317 return result; |
12256 } | 12318 } |
12257 | 12319 |
12258 - (NSUInteger)count { | 12320 - (NSUInteger)count { |
12259 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12321 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12260 } | 12322 } |
12261 | 12323 |
12262 - (BOOL)valueForKey:(BOOL)key value:(BOOL *)value { | 12324 - (BOOL)getBool:(BOOL *)value forKey:(BOOL)key { |
12263 int idx = (key ? 1 : 0); | 12325 int idx = (key ? 1 : 0); |
12264 if (_valueSet[idx]) { | 12326 if (_valueSet[idx]) { |
12265 if (value) { | 12327 if (value) { |
12266 *value = _values[idx]; | 12328 *value = _values[idx]; |
12267 } | 12329 } |
12268 return YES; | 12330 return YES; |
12269 } | 12331 } |
12270 return NO; | 12332 return NO; |
12271 } | 12333 } |
12272 | 12334 |
12273 - (void)setGPBGenericValue:(GPBGenericValue *)value | 12335 - (void)setGPBGenericValue:(GPBGenericValue *)value |
12274 forGPBGenericValueKey:(GPBGenericValue *)key { | 12336 forGPBGenericValueKey:(GPBGenericValue *)key { |
12275 int idx = (key->valueBool ? 1 : 0); | 12337 int idx = (key->valueBool ? 1 : 0); |
12276 _values[idx] = value->valueBool; | 12338 _values[idx] = value->valueBool; |
12277 _valueSet[idx] = YES; | 12339 _valueSet[idx] = YES; |
12278 } | 12340 } |
12279 | 12341 |
12280 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 12342 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
12281 if (_valueSet[0]) { | 12343 if (_valueSet[0]) { |
12282 block(@"false", (_values[0] ? @"true" : @"false")); | 12344 block(@"false", (_values[0] ? @"true" : @"false")); |
12283 } | 12345 } |
12284 if (_valueSet[1]) { | 12346 if (_valueSet[1]) { |
12285 block(@"true", (_values[1] ? @"true" : @"false")); | 12347 block(@"true", (_values[1] ? @"true" : @"false")); |
12286 } | 12348 } |
12287 } | 12349 } |
12288 | 12350 |
12289 - (void)enumerateKeysAndValuesUsingBlock: | 12351 - (void)enumerateKeysAndBoolsUsingBlock: |
12290 (void (^)(BOOL key, BOOL value, BOOL *stop))block { | 12352 (void (^)(BOOL key, BOOL value, BOOL *stop))block { |
12291 BOOL stop = NO; | 12353 BOOL stop = NO; |
12292 if (_valueSet[0]) { | 12354 if (_valueSet[0]) { |
12293 block(NO, _values[0], &stop); | 12355 block(NO, _values[0], &stop); |
12294 } | 12356 } |
12295 if (!stop && _valueSet[1]) { | 12357 if (!stop && _valueSet[1]) { |
12296 block(YES, _values[1], &stop); | 12358 block(YES, _values[1], &stop); |
12297 } | 12359 } |
12298 } | 12360 } |
12299 | 12361 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12340 _valueSet[i] = YES; | 12402 _valueSet[i] = YES; |
12341 _values[i] = otherDictionary->_values[i]; | 12403 _values[i] = otherDictionary->_values[i]; |
12342 } | 12404 } |
12343 } | 12405 } |
12344 if (_autocreator) { | 12406 if (_autocreator) { |
12345 GPBAutocreatedDictionaryModified(_autocreator, self); | 12407 GPBAutocreatedDictionaryModified(_autocreator, self); |
12346 } | 12408 } |
12347 } | 12409 } |
12348 } | 12410 } |
12349 | 12411 |
12350 - (void)setValue:(BOOL)value forKey:(BOOL)key { | 12412 - (void)setBool:(BOOL)value forKey:(BOOL)key { |
12351 int idx = (key ? 1 : 0); | 12413 int idx = (key ? 1 : 0); |
12352 _values[idx] = value; | 12414 _values[idx] = value; |
12353 _valueSet[idx] = YES; | 12415 _valueSet[idx] = YES; |
12354 if (_autocreator) { | 12416 if (_autocreator) { |
12355 GPBAutocreatedDictionaryModified(_autocreator, self); | 12417 GPBAutocreatedDictionaryModified(_autocreator, self); |
12356 } | 12418 } |
12357 } | 12419 } |
12358 | 12420 |
12359 - (void)removeValueForKey:(BOOL)aKey { | 12421 - (void)removeBoolForKey:(BOOL)aKey { |
12360 _valueSet[aKey ? 1 : 0] = NO; | 12422 _valueSet[aKey ? 1 : 0] = NO; |
12361 } | 12423 } |
12362 | 12424 |
12363 - (void)removeAll { | 12425 - (void)removeAll { |
12364 _valueSet[0] = NO; | 12426 _valueSet[0] = NO; |
12365 _valueSet[1] = NO; | 12427 _valueSet[1] = NO; |
12366 } | 12428 } |
12367 | 12429 |
12368 @end | 12430 @end |
12369 | 12431 |
12370 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float) | 12432 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float) |
12371 // This block of code is generated, do not edit it directly. | 12433 // This block of code is generated, do not edit it directly. |
12372 | 12434 |
12373 #pragma mark - Bool -> Float | 12435 #pragma mark - Bool -> Float |
12374 | 12436 |
12375 @implementation GPBBoolFloatDictionary { | 12437 @implementation GPBBoolFloatDictionary { |
12376 @package | 12438 @package |
12377 float _values[2]; | 12439 float _values[2]; |
12378 BOOL _valueSet[2]; | 12440 BOOL _valueSet[2]; |
12379 } | 12441 } |
12380 | 12442 |
12381 + (instancetype)dictionary { | 12443 + (instancetype)dictionary { |
12382 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 12444 return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; |
12383 } | 12445 } |
12384 | 12446 |
12385 + (instancetype)dictionaryWithValue:(float)value | 12447 + (instancetype)dictionaryWithFloat:(float)value |
12386 forKey:(BOOL)key { | 12448 forKey:(BOOL)key { |
12387 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 12449 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
12388 // on to get the type correct. | 12450 // on to get the type correct. |
12389 return [[(GPBBoolFloatDictionary*)[self alloc] initWithValues:&value | 12451 return [[(GPBBoolFloatDictionary*)[self alloc] initWithFloats:&value |
12390 forKeys:&key | 12452 forKeys:&key |
12391 count:1] autorelease]; | 12453 count:1] autorelease]; |
12392 } | 12454 } |
12393 | 12455 |
12394 + (instancetype)dictionaryWithValues:(const float [])values | 12456 + (instancetype)dictionaryWithFloats:(const float [])values |
12395 forKeys:(const BOOL [])keys | 12457 forKeys:(const BOOL [])keys |
12396 count:(NSUInteger)count { | 12458 count:(NSUInteger)count { |
12397 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 12459 // Cast is needed so the compiler knows what class we are invoking initWithFlo
ats:forKeys:count: |
12398 // on to get the type correct. | 12460 // on to get the type correct. |
12399 return [[(GPBBoolFloatDictionary*)[self alloc] initWithValues:values | 12461 return [[(GPBBoolFloatDictionary*)[self alloc] initWithFloats:values |
12400 forKeys:keys | 12462 forKeys:keys |
12401 count:count] autorelea
se]; | 12463 count:count] autorelea
se]; |
12402 } | 12464 } |
12403 | 12465 |
12404 + (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary { | 12466 + (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary { |
12405 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 12467 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
12406 // on to get the type correct. | 12468 // on to get the type correct. |
12407 return [[(GPBBoolFloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 12469 return [[(GPBBoolFloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
12408 } | 12470 } |
12409 | 12471 |
12410 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 12472 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
12411 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 12473 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
12412 } | 12474 } |
12413 | 12475 |
12414 - (instancetype)init { | 12476 - (instancetype)init { |
12415 return [self initWithValues:NULL forKeys:NULL count:0]; | 12477 return [self initWithFloats:NULL forKeys:NULL count:0]; |
12416 } | 12478 } |
12417 | 12479 |
12418 - (instancetype)initWithValues:(const float [])values | 12480 - (instancetype)initWithFloats:(const float [])values |
12419 forKeys:(const BOOL [])keys | 12481 forKeys:(const BOOL [])keys |
12420 count:(NSUInteger)count { | 12482 count:(NSUInteger)count { |
12421 self = [super init]; | 12483 self = [super init]; |
12422 if (self) { | 12484 if (self) { |
12423 for (NSUInteger i = 0; i < count; ++i) { | 12485 for (NSUInteger i = 0; i < count; ++i) { |
12424 int idx = keys[i] ? 1 : 0; | 12486 int idx = keys[i] ? 1 : 0; |
12425 _values[idx] = values[i]; | 12487 _values[idx] = values[i]; |
12426 _valueSet[idx] = YES; | 12488 _valueSet[idx] = YES; |
12427 } | 12489 } |
12428 } | 12490 } |
12429 return self; | 12491 return self; |
12430 } | 12492 } |
12431 | 12493 |
12432 - (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary { | 12494 - (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary { |
12433 self = [self initWithValues:NULL forKeys:NULL count:0]; | 12495 self = [self initWithFloats:NULL forKeys:NULL count:0]; |
12434 if (self) { | 12496 if (self) { |
12435 if (dictionary) { | 12497 if (dictionary) { |
12436 for (int i = 0; i < 2; ++i) { | 12498 for (int i = 0; i < 2; ++i) { |
12437 if (dictionary->_valueSet[i]) { | 12499 if (dictionary->_valueSet[i]) { |
12438 _values[i] = dictionary->_values[i]; | 12500 _values[i] = dictionary->_values[i]; |
12439 _valueSet[i] = YES; | 12501 _valueSet[i] = YES; |
12440 } | 12502 } |
12441 } | 12503 } |
12442 } | 12504 } |
12443 } | 12505 } |
12444 return self; | 12506 return self; |
12445 } | 12507 } |
12446 | 12508 |
12447 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 12509 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
12448 #pragma unused(numItems) | 12510 #pragma unused(numItems) |
12449 return [self initWithValues:NULL forKeys:NULL count:0]; | 12511 return [self initWithFloats:NULL forKeys:NULL count:0]; |
12450 } | 12512 } |
12451 | 12513 |
12452 #if !defined(NS_BLOCK_ASSERTIONS) | 12514 #if !defined(NS_BLOCK_ASSERTIONS) |
12453 - (void)dealloc { | 12515 - (void)dealloc { |
12454 NSAssert(!_autocreator, | 12516 NSAssert(!_autocreator, |
12455 @"%@: Autocreator must be cleared before release, autocreator: %@", | 12517 @"%@: Autocreator must be cleared before release, autocreator: %@", |
12456 [self class], _autocreator); | 12518 [self class], _autocreator); |
12457 [super dealloc]; | 12519 [super dealloc]; |
12458 } | 12520 } |
12459 #endif // !defined(NS_BLOCK_ASSERTIONS) | 12521 #endif // !defined(NS_BLOCK_ASSERTIONS) |
12460 | 12522 |
12461 - (instancetype)copyWithZone:(NSZone *)zone { | 12523 - (instancetype)copyWithZone:(NSZone *)zone { |
12462 return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self]; | 12524 return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self]; |
12463 } | 12525 } |
12464 | 12526 |
12465 - (BOOL)isEqual:(GPBBoolFloatDictionary *)other { | 12527 - (BOOL)isEqual:(id)other { |
12466 if (self == other) { | 12528 if (self == other) { |
12467 return YES; | 12529 return YES; |
12468 } | 12530 } |
12469 if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) { | 12531 if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) { |
12470 return NO; | 12532 return NO; |
12471 } | 12533 } |
12472 if ((_valueSet[0] != other->_valueSet[0]) || | 12534 GPBBoolFloatDictionary *otherDictionary = other; |
12473 (_valueSet[1] != other->_valueSet[1])) { | 12535 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || |
| 12536 (_valueSet[1] != otherDictionary->_valueSet[1])) { |
12474 return NO; | 12537 return NO; |
12475 } | 12538 } |
12476 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | 12539 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || |
12477 (_valueSet[1] && (_values[1] != other->_values[1]))) { | 12540 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { |
12478 return NO; | 12541 return NO; |
12479 } | 12542 } |
12480 return YES; | 12543 return YES; |
12481 } | 12544 } |
12482 | 12545 |
12483 - (NSUInteger)hash { | 12546 - (NSUInteger)hash { |
12484 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12547 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12485 } | 12548 } |
12486 | 12549 |
12487 - (NSString *)description { | 12550 - (NSString *)description { |
12488 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 12551 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
12489 if (_valueSet[0]) { | 12552 if (_valueSet[0]) { |
12490 [result appendFormat:@"NO: %f", _values[0]]; | 12553 [result appendFormat:@"NO: %f", _values[0]]; |
12491 } | 12554 } |
12492 if (_valueSet[1]) { | 12555 if (_valueSet[1]) { |
12493 [result appendFormat:@"YES: %f", _values[1]]; | 12556 [result appendFormat:@"YES: %f", _values[1]]; |
12494 } | 12557 } |
12495 [result appendString:@" }"]; | 12558 [result appendString:@" }"]; |
12496 return result; | 12559 return result; |
12497 } | 12560 } |
12498 | 12561 |
12499 - (NSUInteger)count { | 12562 - (NSUInteger)count { |
12500 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12563 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12501 } | 12564 } |
12502 | 12565 |
12503 - (BOOL)valueForKey:(BOOL)key value:(float *)value { | 12566 - (BOOL)getFloat:(float *)value forKey:(BOOL)key { |
12504 int idx = (key ? 1 : 0); | 12567 int idx = (key ? 1 : 0); |
12505 if (_valueSet[idx]) { | 12568 if (_valueSet[idx]) { |
12506 if (value) { | 12569 if (value) { |
12507 *value = _values[idx]; | 12570 *value = _values[idx]; |
12508 } | 12571 } |
12509 return YES; | 12572 return YES; |
12510 } | 12573 } |
12511 return NO; | 12574 return NO; |
12512 } | 12575 } |
12513 | 12576 |
12514 - (void)setGPBGenericValue:(GPBGenericValue *)value | 12577 - (void)setGPBGenericValue:(GPBGenericValue *)value |
12515 forGPBGenericValueKey:(GPBGenericValue *)key { | 12578 forGPBGenericValueKey:(GPBGenericValue *)key { |
12516 int idx = (key->valueBool ? 1 : 0); | 12579 int idx = (key->valueBool ? 1 : 0); |
12517 _values[idx] = value->valueFloat; | 12580 _values[idx] = value->valueFloat; |
12518 _valueSet[idx] = YES; | 12581 _valueSet[idx] = YES; |
12519 } | 12582 } |
12520 | 12583 |
12521 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 12584 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
12522 if (_valueSet[0]) { | 12585 if (_valueSet[0]) { |
12523 block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]); | 12586 block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]); |
12524 } | 12587 } |
12525 if (_valueSet[1]) { | 12588 if (_valueSet[1]) { |
12526 block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]); | 12589 block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]); |
12527 } | 12590 } |
12528 } | 12591 } |
12529 | 12592 |
12530 - (void)enumerateKeysAndValuesUsingBlock: | 12593 - (void)enumerateKeysAndFloatsUsingBlock: |
12531 (void (^)(BOOL key, float value, BOOL *stop))block { | 12594 (void (^)(BOOL key, float value, BOOL *stop))block { |
12532 BOOL stop = NO; | 12595 BOOL stop = NO; |
12533 if (_valueSet[0]) { | 12596 if (_valueSet[0]) { |
12534 block(NO, _values[0], &stop); | 12597 block(NO, _values[0], &stop); |
12535 } | 12598 } |
12536 if (!stop && _valueSet[1]) { | 12599 if (!stop && _valueSet[1]) { |
12537 block(YES, _values[1], &stop); | 12600 block(YES, _values[1], &stop); |
12538 } | 12601 } |
12539 } | 12602 } |
12540 | 12603 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12581 _valueSet[i] = YES; | 12644 _valueSet[i] = YES; |
12582 _values[i] = otherDictionary->_values[i]; | 12645 _values[i] = otherDictionary->_values[i]; |
12583 } | 12646 } |
12584 } | 12647 } |
12585 if (_autocreator) { | 12648 if (_autocreator) { |
12586 GPBAutocreatedDictionaryModified(_autocreator, self); | 12649 GPBAutocreatedDictionaryModified(_autocreator, self); |
12587 } | 12650 } |
12588 } | 12651 } |
12589 } | 12652 } |
12590 | 12653 |
12591 - (void)setValue:(float)value forKey:(BOOL)key { | 12654 - (void)setFloat:(float)value forKey:(BOOL)key { |
12592 int idx = (key ? 1 : 0); | 12655 int idx = (key ? 1 : 0); |
12593 _values[idx] = value; | 12656 _values[idx] = value; |
12594 _valueSet[idx] = YES; | 12657 _valueSet[idx] = YES; |
12595 if (_autocreator) { | 12658 if (_autocreator) { |
12596 GPBAutocreatedDictionaryModified(_autocreator, self); | 12659 GPBAutocreatedDictionaryModified(_autocreator, self); |
12597 } | 12660 } |
12598 } | 12661 } |
12599 | 12662 |
12600 - (void)removeValueForKey:(BOOL)aKey { | 12663 - (void)removeFloatForKey:(BOOL)aKey { |
12601 _valueSet[aKey ? 1 : 0] = NO; | 12664 _valueSet[aKey ? 1 : 0] = NO; |
12602 } | 12665 } |
12603 | 12666 |
12604 - (void)removeAll { | 12667 - (void)removeAll { |
12605 _valueSet[0] = NO; | 12668 _valueSet[0] = NO; |
12606 _valueSet[1] = NO; | 12669 _valueSet[1] = NO; |
12607 } | 12670 } |
12608 | 12671 |
12609 @end | 12672 @end |
12610 | 12673 |
12611 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double) | 12674 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double) |
12612 // This block of code is generated, do not edit it directly. | 12675 // This block of code is generated, do not edit it directly. |
12613 | 12676 |
12614 #pragma mark - Bool -> Double | 12677 #pragma mark - Bool -> Double |
12615 | 12678 |
12616 @implementation GPBBoolDoubleDictionary { | 12679 @implementation GPBBoolDoubleDictionary { |
12617 @package | 12680 @package |
12618 double _values[2]; | 12681 double _values[2]; |
12619 BOOL _valueSet[2]; | 12682 BOOL _valueSet[2]; |
12620 } | 12683 } |
12621 | 12684 |
12622 + (instancetype)dictionary { | 12685 + (instancetype)dictionary { |
12623 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | 12686 return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; |
12624 } | 12687 } |
12625 | 12688 |
12626 + (instancetype)dictionaryWithValue:(double)value | 12689 + (instancetype)dictionaryWithDouble:(double)value |
12627 forKey:(BOOL)key { | 12690 forKey:(BOOL)key { |
12628 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 12691 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
12629 // on to get the type correct. | 12692 // on to get the type correct. |
12630 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithValues:&value | 12693 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDoubles:&value |
12631 forKeys:&key | 12694 forKeys:&key |
12632 count:1] autorelease]
; | 12695 count:1] autorelease
]; |
12633 } | 12696 } |
12634 | 12697 |
12635 + (instancetype)dictionaryWithValues:(const double [])values | 12698 + (instancetype)dictionaryWithDoubles:(const double [])values |
12636 forKeys:(const BOOL [])keys | 12699 forKeys:(const BOOL [])keys |
12637 count:(NSUInteger)count { | 12700 count:(NSUInteger)count { |
12638 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | 12701 // Cast is needed so the compiler knows what class we are invoking initWithDou
bles:forKeys:count: |
12639 // on to get the type correct. | 12702 // on to get the type correct. |
12640 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithValues:values | 12703 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDoubles:values |
12641 forKeys:keys | 12704 forKeys:keys |
12642 count:count] autorele
ase]; | 12705 count:count] autorel
ease]; |
12643 } | 12706 } |
12644 | 12707 |
12645 + (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary { | 12708 + (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary { |
12646 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: | 12709 // Cast is needed so the compiler knows what class we are invoking initWithDic
tionary: |
12647 // on to get the type correct. | 12710 // on to get the type correct. |
12648 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | 12711 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; |
12649 } | 12712 } |
12650 | 12713 |
12651 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | 12714 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { |
12652 return [[[self alloc] initWithCapacity:numItems] autorelease]; | 12715 return [[[self alloc] initWithCapacity:numItems] autorelease]; |
12653 } | 12716 } |
12654 | 12717 |
12655 - (instancetype)init { | 12718 - (instancetype)init { |
12656 return [self initWithValues:NULL forKeys:NULL count:0]; | 12719 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
12657 } | 12720 } |
12658 | 12721 |
12659 - (instancetype)initWithValues:(const double [])values | 12722 - (instancetype)initWithDoubles:(const double [])values |
12660 forKeys:(const BOOL [])keys | 12723 forKeys:(const BOOL [])keys |
12661 count:(NSUInteger)count { | 12724 count:(NSUInteger)count { |
12662 self = [super init]; | 12725 self = [super init]; |
12663 if (self) { | 12726 if (self) { |
12664 for (NSUInteger i = 0; i < count; ++i) { | 12727 for (NSUInteger i = 0; i < count; ++i) { |
12665 int idx = keys[i] ? 1 : 0; | 12728 int idx = keys[i] ? 1 : 0; |
12666 _values[idx] = values[i]; | 12729 _values[idx] = values[i]; |
12667 _valueSet[idx] = YES; | 12730 _valueSet[idx] = YES; |
12668 } | 12731 } |
12669 } | 12732 } |
12670 return self; | 12733 return self; |
12671 } | 12734 } |
12672 | 12735 |
12673 - (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary { | 12736 - (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary { |
12674 self = [self initWithValues:NULL forKeys:NULL count:0]; | 12737 self = [self initWithDoubles:NULL forKeys:NULL count:0]; |
12675 if (self) { | 12738 if (self) { |
12676 if (dictionary) { | 12739 if (dictionary) { |
12677 for (int i = 0; i < 2; ++i) { | 12740 for (int i = 0; i < 2; ++i) { |
12678 if (dictionary->_valueSet[i]) { | 12741 if (dictionary->_valueSet[i]) { |
12679 _values[i] = dictionary->_values[i]; | 12742 _values[i] = dictionary->_values[i]; |
12680 _valueSet[i] = YES; | 12743 _valueSet[i] = YES; |
12681 } | 12744 } |
12682 } | 12745 } |
12683 } | 12746 } |
12684 } | 12747 } |
12685 return self; | 12748 return self; |
12686 } | 12749 } |
12687 | 12750 |
12688 - (instancetype)initWithCapacity:(NSUInteger)numItems { | 12751 - (instancetype)initWithCapacity:(NSUInteger)numItems { |
12689 #pragma unused(numItems) | 12752 #pragma unused(numItems) |
12690 return [self initWithValues:NULL forKeys:NULL count:0]; | 12753 return [self initWithDoubles:NULL forKeys:NULL count:0]; |
12691 } | 12754 } |
12692 | 12755 |
12693 #if !defined(NS_BLOCK_ASSERTIONS) | 12756 #if !defined(NS_BLOCK_ASSERTIONS) |
12694 - (void)dealloc { | 12757 - (void)dealloc { |
12695 NSAssert(!_autocreator, | 12758 NSAssert(!_autocreator, |
12696 @"%@: Autocreator must be cleared before release, autocreator: %@", | 12759 @"%@: Autocreator must be cleared before release, autocreator: %@", |
12697 [self class], _autocreator); | 12760 [self class], _autocreator); |
12698 [super dealloc]; | 12761 [super dealloc]; |
12699 } | 12762 } |
12700 #endif // !defined(NS_BLOCK_ASSERTIONS) | 12763 #endif // !defined(NS_BLOCK_ASSERTIONS) |
12701 | 12764 |
12702 - (instancetype)copyWithZone:(NSZone *)zone { | 12765 - (instancetype)copyWithZone:(NSZone *)zone { |
12703 return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self]; | 12766 return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self]; |
12704 } | 12767 } |
12705 | 12768 |
12706 - (BOOL)isEqual:(GPBBoolDoubleDictionary *)other { | 12769 - (BOOL)isEqual:(id)other { |
12707 if (self == other) { | 12770 if (self == other) { |
12708 return YES; | 12771 return YES; |
12709 } | 12772 } |
12710 if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) { | 12773 if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) { |
12711 return NO; | 12774 return NO; |
12712 } | 12775 } |
12713 if ((_valueSet[0] != other->_valueSet[0]) || | 12776 GPBBoolDoubleDictionary *otherDictionary = other; |
12714 (_valueSet[1] != other->_valueSet[1])) { | 12777 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || |
| 12778 (_valueSet[1] != otherDictionary->_valueSet[1])) { |
12715 return NO; | 12779 return NO; |
12716 } | 12780 } |
12717 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | 12781 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || |
12718 (_valueSet[1] && (_values[1] != other->_values[1]))) { | 12782 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { |
12719 return NO; | 12783 return NO; |
12720 } | 12784 } |
12721 return YES; | 12785 return YES; |
12722 } | 12786 } |
12723 | 12787 |
12724 - (NSUInteger)hash { | 12788 - (NSUInteger)hash { |
12725 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12789 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12726 } | 12790 } |
12727 | 12791 |
12728 - (NSString *)description { | 12792 - (NSString *)description { |
12729 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 12793 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
12730 if (_valueSet[0]) { | 12794 if (_valueSet[0]) { |
12731 [result appendFormat:@"NO: %lf", _values[0]]; | 12795 [result appendFormat:@"NO: %lf", _values[0]]; |
12732 } | 12796 } |
12733 if (_valueSet[1]) { | 12797 if (_valueSet[1]) { |
12734 [result appendFormat:@"YES: %lf", _values[1]]; | 12798 [result appendFormat:@"YES: %lf", _values[1]]; |
12735 } | 12799 } |
12736 [result appendString:@" }"]; | 12800 [result appendString:@" }"]; |
12737 return result; | 12801 return result; |
12738 } | 12802 } |
12739 | 12803 |
12740 - (NSUInteger)count { | 12804 - (NSUInteger)count { |
12741 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 12805 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
12742 } | 12806 } |
12743 | 12807 |
12744 - (BOOL)valueForKey:(BOOL)key value:(double *)value { | 12808 - (BOOL)getDouble:(double *)value forKey:(BOOL)key { |
12745 int idx = (key ? 1 : 0); | 12809 int idx = (key ? 1 : 0); |
12746 if (_valueSet[idx]) { | 12810 if (_valueSet[idx]) { |
12747 if (value) { | 12811 if (value) { |
12748 *value = _values[idx]; | 12812 *value = _values[idx]; |
12749 } | 12813 } |
12750 return YES; | 12814 return YES; |
12751 } | 12815 } |
12752 return NO; | 12816 return NO; |
12753 } | 12817 } |
12754 | 12818 |
12755 - (void)setGPBGenericValue:(GPBGenericValue *)value | 12819 - (void)setGPBGenericValue:(GPBGenericValue *)value |
12756 forGPBGenericValueKey:(GPBGenericValue *)key { | 12820 forGPBGenericValueKey:(GPBGenericValue *)key { |
12757 int idx = (key->valueBool ? 1 : 0); | 12821 int idx = (key->valueBool ? 1 : 0); |
12758 _values[idx] = value->valueDouble; | 12822 _values[idx] = value->valueDouble; |
12759 _valueSet[idx] = YES; | 12823 _valueSet[idx] = YES; |
12760 } | 12824 } |
12761 | 12825 |
12762 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | 12826 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { |
12763 if (_valueSet[0]) { | 12827 if (_valueSet[0]) { |
12764 block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]); | 12828 block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]); |
12765 } | 12829 } |
12766 if (_valueSet[1]) { | 12830 if (_valueSet[1]) { |
12767 block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]); | 12831 block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]); |
12768 } | 12832 } |
12769 } | 12833 } |
12770 | 12834 |
12771 - (void)enumerateKeysAndValuesUsingBlock: | 12835 - (void)enumerateKeysAndDoublesUsingBlock: |
12772 (void (^)(BOOL key, double value, BOOL *stop))block { | 12836 (void (^)(BOOL key, double value, BOOL *stop))block { |
12773 BOOL stop = NO; | 12837 BOOL stop = NO; |
12774 if (_valueSet[0]) { | 12838 if (_valueSet[0]) { |
12775 block(NO, _values[0], &stop); | 12839 block(NO, _values[0], &stop); |
12776 } | 12840 } |
12777 if (!stop && _valueSet[1]) { | 12841 if (!stop && _valueSet[1]) { |
12778 block(YES, _values[1], &stop); | 12842 block(YES, _values[1], &stop); |
12779 } | 12843 } |
12780 } | 12844 } |
12781 | 12845 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12822 _valueSet[i] = YES; | 12886 _valueSet[i] = YES; |
12823 _values[i] = otherDictionary->_values[i]; | 12887 _values[i] = otherDictionary->_values[i]; |
12824 } | 12888 } |
12825 } | 12889 } |
12826 if (_autocreator) { | 12890 if (_autocreator) { |
12827 GPBAutocreatedDictionaryModified(_autocreator, self); | 12891 GPBAutocreatedDictionaryModified(_autocreator, self); |
12828 } | 12892 } |
12829 } | 12893 } |
12830 } | 12894 } |
12831 | 12895 |
12832 - (void)setValue:(double)value forKey:(BOOL)key { | 12896 - (void)setDouble:(double)value forKey:(BOOL)key { |
12833 int idx = (key ? 1 : 0); | 12897 int idx = (key ? 1 : 0); |
12834 _values[idx] = value; | 12898 _values[idx] = value; |
12835 _valueSet[idx] = YES; | 12899 _valueSet[idx] = YES; |
12836 if (_autocreator) { | 12900 if (_autocreator) { |
12837 GPBAutocreatedDictionaryModified(_autocreator, self); | 12901 GPBAutocreatedDictionaryModified(_autocreator, self); |
12838 } | 12902 } |
12839 } | 12903 } |
12840 | 12904 |
12841 - (void)removeValueForKey:(BOOL)aKey { | 12905 - (void)removeDoubleForKey:(BOOL)aKey { |
12842 _valueSet[aKey ? 1 : 0] = NO; | 12906 _valueSet[aKey ? 1 : 0] = NO; |
12843 } | 12907 } |
12844 | 12908 |
12845 - (void)removeAll { | 12909 - (void)removeAll { |
12846 _valueSet[0] = NO; | 12910 _valueSet[0] = NO; |
12847 _valueSet[1] = NO; | 12911 _valueSet[1] = NO; |
12848 } | 12912 } |
12849 | 12913 |
12850 @end | 12914 @end |
12851 | 12915 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12936 [self class], _autocreator); | 13000 [self class], _autocreator); |
12937 [_values[0] release]; | 13001 [_values[0] release]; |
12938 [_values[1] release]; | 13002 [_values[1] release]; |
12939 [super dealloc]; | 13003 [super dealloc]; |
12940 } | 13004 } |
12941 | 13005 |
12942 - (instancetype)copyWithZone:(NSZone *)zone { | 13006 - (instancetype)copyWithZone:(NSZone *)zone { |
12943 return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self]; | 13007 return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self]; |
12944 } | 13008 } |
12945 | 13009 |
12946 - (BOOL)isEqual:(GPBBoolObjectDictionary *)other { | 13010 - (BOOL)isEqual:(id)other { |
12947 if (self == other) { | 13011 if (self == other) { |
12948 return YES; | 13012 return YES; |
12949 } | 13013 } |
12950 if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) { | 13014 if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) { |
12951 return NO; | 13015 return NO; |
12952 } | 13016 } |
12953 if (((_values[0] != nil) != (other->_values[0] != nil)) || | 13017 GPBBoolObjectDictionary *otherDictionary = other; |
12954 ((_values[1] != nil) != (other->_values[1] != nil))) { | 13018 if (((_values[0] != nil) != (otherDictionary->_values[0] != nil)) || |
| 13019 ((_values[1] != nil) != (otherDictionary->_values[1] != nil))) { |
12955 return NO; | 13020 return NO; |
12956 } | 13021 } |
12957 if (((_values[0] != nil) && (![_values[0] isEqual:other->_values[0]])) || | 13022 if (((_values[0] != nil) && (![_values[0] isEqual:otherDictionary->_values[0]]
)) || |
12958 ((_values[1] != nil) && (![_values[1] isEqual:other->_values[1]]))) { | 13023 ((_values[1] != nil) && (![_values[1] isEqual:otherDictionary->_values[1]]
))) { |
12959 return NO; | 13024 return NO; |
12960 } | 13025 } |
12961 return YES; | 13026 return YES; |
12962 } | 13027 } |
12963 | 13028 |
12964 - (NSUInteger)hash { | 13029 - (NSUInteger)hash { |
12965 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0); | 13030 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0); |
12966 } | 13031 } |
12967 | 13032 |
12968 - (NSString *)description { | 13033 - (NSString *)description { |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13226 @"%@: Autocreator must be cleared before release, autocreator: %@", | 13291 @"%@: Autocreator must be cleared before release, autocreator: %@", |
13227 [self class], _autocreator); | 13292 [self class], _autocreator); |
13228 [super dealloc]; | 13293 [super dealloc]; |
13229 } | 13294 } |
13230 #endif // !defined(NS_BLOCK_ASSERTIONS) | 13295 #endif // !defined(NS_BLOCK_ASSERTIONS) |
13231 | 13296 |
13232 - (instancetype)copyWithZone:(NSZone *)zone { | 13297 - (instancetype)copyWithZone:(NSZone *)zone { |
13233 return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self]; | 13298 return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self]; |
13234 } | 13299 } |
13235 | 13300 |
13236 - (BOOL)isEqual:(GPBBoolEnumDictionary *)other { | 13301 - (BOOL)isEqual:(id)other { |
13237 if (self == other) { | 13302 if (self == other) { |
13238 return YES; | 13303 return YES; |
13239 } | 13304 } |
13240 if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) { | 13305 if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) { |
13241 return NO; | 13306 return NO; |
13242 } | 13307 } |
13243 if ((_valueSet[0] != other->_valueSet[0]) || | 13308 GPBBoolEnumDictionary *otherDictionary = other; |
13244 (_valueSet[1] != other->_valueSet[1])) { | 13309 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || |
| 13310 (_valueSet[1] != otherDictionary->_valueSet[1])) { |
13245 return NO; | 13311 return NO; |
13246 } | 13312 } |
13247 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | 13313 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || |
13248 (_valueSet[1] && (_values[1] != other->_values[1]))) { | 13314 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { |
13249 return NO; | 13315 return NO; |
13250 } | 13316 } |
13251 return YES; | 13317 return YES; |
13252 } | 13318 } |
13253 | 13319 |
13254 - (NSUInteger)hash { | 13320 - (NSUInteger)hash { |
13255 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 13321 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
13256 } | 13322 } |
13257 | 13323 |
13258 - (NSString *)description { | 13324 - (NSString *)description { |
13259 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | 13325 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; |
13260 if (_valueSet[0]) { | 13326 if (_valueSet[0]) { |
13261 [result appendFormat:@"NO: %d", _values[0]]; | 13327 [result appendFormat:@"NO: %d", _values[0]]; |
13262 } | 13328 } |
13263 if (_valueSet[1]) { | 13329 if (_valueSet[1]) { |
13264 [result appendFormat:@"YES: %d", _values[1]]; | 13330 [result appendFormat:@"YES: %d", _values[1]]; |
13265 } | 13331 } |
13266 [result appendString:@" }"]; | 13332 [result appendString:@" }"]; |
13267 return result; | 13333 return result; |
13268 } | 13334 } |
13269 | 13335 |
13270 - (NSUInteger)count { | 13336 - (NSUInteger)count { |
13271 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | 13337 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); |
13272 } | 13338 } |
13273 | 13339 |
13274 - (BOOL)valueForKey:(BOOL)key value:(int32_t*)value { | 13340 - (BOOL)getEnum:(int32_t*)value forKey:(BOOL)key { |
13275 int idx = (key ? 1 : 0); | 13341 int idx = (key ? 1 : 0); |
13276 if (_valueSet[idx]) { | 13342 if (_valueSet[idx]) { |
13277 if (value) { | 13343 if (value) { |
13278 int32_t result = _values[idx]; | 13344 int32_t result = _values[idx]; |
13279 if (!_validationFunc(result)) { | 13345 if (!_validationFunc(result)) { |
13280 result = kGPBUnrecognizedEnumeratorValue; | 13346 result = kGPBUnrecognizedEnumeratorValue; |
13281 } | 13347 } |
13282 *value = result; | 13348 *value = result; |
13283 } | 13349 } |
13284 return YES; | 13350 return YES; |
13285 } | 13351 } |
13286 return NO; | 13352 return NO; |
13287 } | 13353 } |
13288 | 13354 |
13289 - (BOOL)valueForKey:(BOOL)key rawValue:(int32_t*)rawValue { | 13355 - (BOOL)getRawValue:(int32_t*)rawValue forKey:(BOOL)key { |
13290 int idx = (key ? 1 : 0); | 13356 int idx = (key ? 1 : 0); |
13291 if (_valueSet[idx]) { | 13357 if (_valueSet[idx]) { |
13292 if (rawValue) { | 13358 if (rawValue) { |
13293 *rawValue = _values[idx]; | 13359 *rawValue = _values[idx]; |
13294 } | 13360 } |
13295 return YES; | 13361 return YES; |
13296 } | 13362 } |
13297 return NO; | 13363 return NO; |
13298 } | 13364 } |
13299 | 13365 |
13300 - (void)enumerateKeysAndValuesUsingBlock: | 13366 - (void)enumerateKeysAndRawValuesUsingBlock: |
13301 (void (^)(BOOL key, int32_t value, BOOL *stop))block { | 13367 (void (^)(BOOL key, int32_t value, BOOL *stop))block { |
13302 BOOL stop = NO; | 13368 BOOL stop = NO; |
13303 if (_valueSet[0]) { | 13369 if (_valueSet[0]) { |
13304 block(NO, _values[0], &stop); | 13370 block(NO, _values[0], &stop); |
13305 } | 13371 } |
13306 if (!stop && _valueSet[1]) { | 13372 if (!stop && _valueSet[1]) { |
13307 block(YES, _values[1], &stop); | 13373 block(YES, _values[1], &stop); |
13308 } | 13374 } |
13309 } | 13375 } |
13310 | 13376 |
13311 - (void)enumerateKeysAndRawValuesUsingBlock: | 13377 - (void)enumerateKeysAndEnumsUsingBlock: |
13312 (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block { | 13378 (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block { |
13313 BOOL stop = NO; | 13379 BOOL stop = NO; |
13314 GPBEnumValidationFunc func = _validationFunc; | 13380 GPBEnumValidationFunc func = _validationFunc; |
13315 int32_t validatedValue; | 13381 int32_t validatedValue; |
13316 if (_valueSet[0]) { | 13382 if (_valueSet[0]) { |
13317 validatedValue = _values[0]; | 13383 validatedValue = _values[0]; |
13318 if (!func(validatedValue)) { | 13384 if (!func(validatedValue)) { |
13319 validatedValue = kGPBUnrecognizedEnumeratorValue; | 13385 validatedValue = kGPBUnrecognizedEnumeratorValue; |
13320 } | 13386 } |
13321 block(NO, validatedValue, &stop); | 13387 block(NO, validatedValue, &stop); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13406 _valueSet[i] = YES; | 13472 _valueSet[i] = YES; |
13407 _values[i] = otherDictionary->_values[i]; | 13473 _values[i] = otherDictionary->_values[i]; |
13408 } | 13474 } |
13409 } | 13475 } |
13410 if (_autocreator) { | 13476 if (_autocreator) { |
13411 GPBAutocreatedDictionaryModified(_autocreator, self); | 13477 GPBAutocreatedDictionaryModified(_autocreator, self); |
13412 } | 13478 } |
13413 } | 13479 } |
13414 } | 13480 } |
13415 | 13481 |
13416 - (void)setValue:(int32_t)value forKey:(BOOL)key { | 13482 - (void)setEnum:(int32_t)value forKey:(BOOL)key { |
13417 if (!_validationFunc(value)) { | 13483 if (!_validationFunc(value)) { |
13418 [NSException raise:NSInvalidArgumentException | 13484 [NSException raise:NSInvalidArgumentException |
13419 format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum v
alue (%d)", | 13485 format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum v
alue (%d)", |
13420 value]; | 13486 value]; |
13421 } | 13487 } |
13422 int idx = (key ? 1 : 0); | 13488 int idx = (key ? 1 : 0); |
13423 _values[idx] = value; | 13489 _values[idx] = value; |
13424 _valueSet[idx] = YES; | 13490 _valueSet[idx] = YES; |
13425 if (_autocreator) { | 13491 if (_autocreator) { |
13426 GPBAutocreatedDictionaryModified(_autocreator, self); | 13492 GPBAutocreatedDictionaryModified(_autocreator, self); |
13427 } | 13493 } |
13428 } | 13494 } |
13429 | 13495 |
13430 - (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key { | 13496 - (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key { |
13431 int idx = (key ? 1 : 0); | 13497 int idx = (key ? 1 : 0); |
13432 _values[idx] = rawValue; | 13498 _values[idx] = rawValue; |
13433 _valueSet[idx] = YES; | 13499 _valueSet[idx] = YES; |
13434 if (_autocreator) { | 13500 if (_autocreator) { |
13435 GPBAutocreatedDictionaryModified(_autocreator, self); | 13501 GPBAutocreatedDictionaryModified(_autocreator, self); |
13436 } | 13502 } |
13437 } | 13503 } |
13438 | 13504 |
13439 - (void)removeValueForKey:(BOOL)aKey { | 13505 - (void)removeEnumForKey:(BOOL)aKey { |
13440 _valueSet[aKey ? 1 : 0] = NO; | 13506 _valueSet[aKey ? 1 : 0] = NO; |
13441 } | 13507 } |
13442 | 13508 |
13443 - (void)removeAll { | 13509 - (void)removeAll { |
13444 _valueSet[0] = NO; | 13510 _valueSet[0] = NO; |
13445 _valueSet[1] = NO; | 13511 _valueSet[1] = NO; |
13446 } | 13512 } |
13447 | 13513 |
13448 @end | 13514 @end |
13449 | 13515 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13546 } | 13612 } |
13547 | 13613 |
13548 - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts | 13614 - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts |
13549 usingBlock:(void (^)(id key, | 13615 usingBlock:(void (^)(id key, |
13550 id obj, | 13616 id obj, |
13551 BOOL *stop))block { | 13617 BOOL *stop))block { |
13552 [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block]; | 13618 [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block]; |
13553 } | 13619 } |
13554 | 13620 |
13555 @end | 13621 @end |
| 13622 |
| 13623 #pragma clang diagnostic pop |
OLD | NEW |