GPBDictionary.h 279 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc.  All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#import <Foundation/Foundation.h>

33
#import "GPBRuntimeTypes.h"
34

35 36 37 38 39 40 41 42
// Note on naming: for the classes holding numeric values, a more natural
// naming of the method might be things like "-valueForKey:",
// "-setValue:forKey:"; etc. But those selectors are also defined by Key Value
// Coding (KVC) as categories on NSObject. So "overloading" the selectors with
// other meanings can cause warnings (based on compiler settings), but more
// importantly, some of those selector get called as KVC breaks up keypaths.
// So if those selectors are used, using KVC will compile cleanly, but could
// crash as it invokes those selectors with the wrong types of arguments.
43

44
NS_ASSUME_NONNULL_BEGIN
45

46 47 48 49 50
//%PDDM-EXPAND DECLARE_DICTIONARIES()
// This block of code is generated, do not edit it directly.

#pragma mark - UInt32 -> UInt32

51 52 53 54 55 56
/**
 * Class used for map fields of <uint32_t, uint32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
57 58
@interface GPBUInt32UInt32Dictionary : NSObject <NSCopying>

59
/** Number of entries stored in this dictionary. */
60 61
@property(nonatomic, readonly) NSUInteger count;

62 63 64
/**
 * @return A newly instanced and empty dictionary.
 **/
65
+ (instancetype)dictionary;
66 67 68 69 70 71 72 73 74

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
75 76
+ (instancetype)dictionaryWithUInt32:(uint32_t)value
                              forKey:(uint32_t)key;
77 78 79 80 81 82 83 84 85 86

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
87 88 89
+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
                              forKeys:(const uint32_t [])keys
                                count:(NSUInteger)count;
90 91 92 93 94 95 96 97 98 99

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
100
+ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary;
101 102 103 104 105 106 107 108

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
109 110
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

111 112 113 114 115 116 117 118 119
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
120 121 122
- (instancetype)initWithUInt32s:(const uint32_t [])values
                        forKeys:(const uint32_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
123 124 125 126 127 128 129 130

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
131
- (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary;
132 133 134 135 136 137 138 139

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
140 141
- (instancetype)initWithCapacity:(NSUInteger)numItems;

142 143 144 145 146 147 148 149
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
150
- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key;
151

152 153 154 155 156 157 158 159
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
160
- (void)enumerateKeysAndUInt32sUsingBlock:
161 162
    (void (^)(uint32_t key, uint32_t value, BOOL *stop))block;

163 164 165 166 167 168
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
169 170
- (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary;

171 172 173 174 175 176
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
177
- (void)setUInt32:(uint32_t)value forKey:(uint32_t)key;
178

179 180 181 182 183
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
184
- (void)removeUInt32ForKey:(uint32_t)aKey;
185 186 187 188

/**
 * Removes all entries in this dictionary.
 **/
189 190 191 192 193 194
- (void)removeAll;

@end

#pragma mark - UInt32 -> Int32

195 196 197 198 199 200
/**
 * Class used for map fields of <uint32_t, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
201 202
@interface GPBUInt32Int32Dictionary : NSObject <NSCopying>

203
/** Number of entries stored in this dictionary. */
204 205
@property(nonatomic, readonly) NSUInteger count;

206 207 208
/**
 * @return A newly instanced and empty dictionary.
 **/
209
+ (instancetype)dictionary;
210 211 212 213 214 215 216 217 218

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
219
+ (instancetype)dictionaryWithInt32:(int32_t)value
220
                             forKey:(uint32_t)key;
221 222 223 224 225 226 227 228 229 230

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
231
+ (instancetype)dictionaryWithInt32s:(const int32_t [])values
232 233
                             forKeys:(const uint32_t [])keys
                               count:(NSUInteger)count;
234 235 236 237 238 239 240 241 242 243

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
244
+ (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary;
245 246 247 248 249 250 251 252

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
253 254
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

255 256 257 258 259 260 261 262 263
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
264
- (instancetype)initWithInt32s:(const int32_t [])values
265 266
                       forKeys:(const uint32_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
267 268 269 270 271 272 273 274

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
275
- (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary;
276 277 278 279 280 281 282 283

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
284 285
- (instancetype)initWithCapacity:(NSUInteger)numItems;

286 287 288 289 290 291 292 293
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
294
- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key;
295

296 297 298 299 300 301 302 303
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
304
- (void)enumerateKeysAndInt32sUsingBlock:
305 306
    (void (^)(uint32_t key, int32_t value, BOOL *stop))block;

307 308 309 310 311 312
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
313 314
- (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary;

315 316 317 318 319 320
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
321
- (void)setInt32:(int32_t)value forKey:(uint32_t)key;
322

323 324 325 326 327
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
328
- (void)removeInt32ForKey:(uint32_t)aKey;
329 330 331 332

/**
 * Removes all entries in this dictionary.
 **/
333 334 335 336 337 338
- (void)removeAll;

@end

#pragma mark - UInt32 -> UInt64

339 340 341 342 343 344
/**
 * Class used for map fields of <uint32_t, uint64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
345 346
@interface GPBUInt32UInt64Dictionary : NSObject <NSCopying>

347
/** Number of entries stored in this dictionary. */
348 349
@property(nonatomic, readonly) NSUInteger count;

350 351 352
/**
 * @return A newly instanced and empty dictionary.
 **/
353
+ (instancetype)dictionary;
354 355 356 357 358 359 360 361 362

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
363 364
+ (instancetype)dictionaryWithUInt64:(uint64_t)value
                              forKey:(uint32_t)key;
365 366 367 368 369 370 371 372 373 374

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
375 376 377
+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
                              forKeys:(const uint32_t [])keys
                                count:(NSUInteger)count;
378 379 380 381 382 383 384 385 386 387

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
388
+ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary;
389 390 391 392 393 394 395 396

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
397 398
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

399 400 401 402 403 404 405 406 407
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
408 409 410
- (instancetype)initWithUInt64s:(const uint64_t [])values
                        forKeys:(const uint32_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
411 412 413 414 415 416 417 418

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
419
- (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary;
420 421 422 423 424 425 426 427

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
428 429
- (instancetype)initWithCapacity:(NSUInteger)numItems;

430 431 432 433 434 435 436 437
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
438
- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key;
439

440 441 442 443 444 445 446 447
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
448
- (void)enumerateKeysAndUInt64sUsingBlock:
449 450
    (void (^)(uint32_t key, uint64_t value, BOOL *stop))block;

451 452 453 454 455 456
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
457 458
- (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary;

459 460 461 462 463 464
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
465
- (void)setUInt64:(uint64_t)value forKey:(uint32_t)key;
466

467 468 469 470 471
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
472
- (void)removeUInt64ForKey:(uint32_t)aKey;
473 474 475 476

/**
 * Removes all entries in this dictionary.
 **/
477 478 479 480 481 482
- (void)removeAll;

@end

#pragma mark - UInt32 -> Int64

483 484 485 486 487 488
/**
 * Class used for map fields of <uint32_t, int64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
489 490
@interface GPBUInt32Int64Dictionary : NSObject <NSCopying>

491
/** Number of entries stored in this dictionary. */
492 493
@property(nonatomic, readonly) NSUInteger count;

494 495 496
/**
 * @return A newly instanced and empty dictionary.
 **/
497
+ (instancetype)dictionary;
498 499 500 501 502 503 504 505 506

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
507
+ (instancetype)dictionaryWithInt64:(int64_t)value
508
                             forKey:(uint32_t)key;
509 510 511 512 513 514 515 516 517 518

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
519
+ (instancetype)dictionaryWithInt64s:(const int64_t [])values
520 521
                             forKeys:(const uint32_t [])keys
                               count:(NSUInteger)count;
522 523 524 525 526 527 528 529 530 531

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
532
+ (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary;
533 534 535 536 537 538 539 540

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
541 542
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

543 544 545 546 547 548 549 550 551
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
552
- (instancetype)initWithInt64s:(const int64_t [])values
553 554
                       forKeys:(const uint32_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
555 556 557 558 559 560 561 562

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
563
- (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary;
564 565 566 567 568 569 570 571

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
572 573
- (instancetype)initWithCapacity:(NSUInteger)numItems;

574 575 576 577 578 579 580 581
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
582
- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key;
583

584 585 586 587 588 589 590 591
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
592
- (void)enumerateKeysAndInt64sUsingBlock:
593 594
    (void (^)(uint32_t key, int64_t value, BOOL *stop))block;

595 596 597 598 599 600
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
601 602
- (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary;

603 604 605 606 607 608
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
609
- (void)setInt64:(int64_t)value forKey:(uint32_t)key;
610

611 612 613 614 615
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
616
- (void)removeInt64ForKey:(uint32_t)aKey;
617 618 619 620

/**
 * Removes all entries in this dictionary.
 **/
621 622 623 624 625 626
- (void)removeAll;

@end

#pragma mark - UInt32 -> Bool

627 628 629 630 631 632
/**
 * Class used for map fields of <uint32_t, BOOL>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
633 634
@interface GPBUInt32BoolDictionary : NSObject <NSCopying>

635
/** Number of entries stored in this dictionary. */
636 637
@property(nonatomic, readonly) NSUInteger count;

638 639 640
/**
 * @return A newly instanced and empty dictionary.
 **/
641
+ (instancetype)dictionary;
642 643 644 645 646 647 648 649 650

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
651 652
+ (instancetype)dictionaryWithBool:(BOOL)value
                            forKey:(uint32_t)key;
653 654 655 656 657 658 659 660 661 662

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
663 664 665
+ (instancetype)dictionaryWithBools:(const BOOL [])values
                            forKeys:(const uint32_t [])keys
                              count:(NSUInteger)count;
666 667 668 669 670 671 672 673 674 675

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
676
+ (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary;
677 678 679 680 681 682 683 684

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
685 686
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

687 688 689 690 691 692 693 694 695
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
696 697 698
- (instancetype)initWithBools:(const BOOL [])values
                      forKeys:(const uint32_t [])keys
                        count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
699 700 701 702 703 704 705 706

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
707
- (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary;
708 709 710 711 712 713 714 715

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
716 717
- (instancetype)initWithCapacity:(NSUInteger)numItems;

718 719 720 721 722 723 724 725
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
726
- (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key;
727

728 729 730 731 732 733 734 735
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
736
- (void)enumerateKeysAndBoolsUsingBlock:
737 738
    (void (^)(uint32_t key, BOOL value, BOOL *stop))block;

739 740 741 742 743 744
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
745 746
- (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary;

747 748 749 750 751 752
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
753
- (void)setBool:(BOOL)value forKey:(uint32_t)key;
754

755 756 757 758 759
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
760
- (void)removeBoolForKey:(uint32_t)aKey;
761 762 763 764

/**
 * Removes all entries in this dictionary.
 **/
765 766 767 768 769 770
- (void)removeAll;

@end

#pragma mark - UInt32 -> Float

771 772 773 774 775 776
/**
 * Class used for map fields of <uint32_t, float>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
777 778
@interface GPBUInt32FloatDictionary : NSObject <NSCopying>

779
/** Number of entries stored in this dictionary. */
780 781
@property(nonatomic, readonly) NSUInteger count;

782 783 784
/**
 * @return A newly instanced and empty dictionary.
 **/
785
+ (instancetype)dictionary;
786 787 788 789 790 791 792 793 794

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
795
+ (instancetype)dictionaryWithFloat:(float)value
796
                             forKey:(uint32_t)key;
797 798 799 800 801 802 803 804 805 806

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
807
+ (instancetype)dictionaryWithFloats:(const float [])values
808 809
                             forKeys:(const uint32_t [])keys
                               count:(NSUInteger)count;
810 811 812 813 814 815 816 817 818 819

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
820
+ (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary;
821 822 823 824 825 826 827 828

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
829 830
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

831 832 833 834 835 836 837 838 839
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
840
- (instancetype)initWithFloats:(const float [])values
841 842
                       forKeys:(const uint32_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
843 844 845 846 847 848 849 850

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
851
- (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary;
852 853 854 855 856 857 858 859

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
860 861
- (instancetype)initWithCapacity:(NSUInteger)numItems;

862 863 864 865 866 867 868 869
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
870
- (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key;
871

872 873 874 875 876 877 878 879
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
880
- (void)enumerateKeysAndFloatsUsingBlock:
881 882
    (void (^)(uint32_t key, float value, BOOL *stop))block;

883 884 885 886 887 888
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
889 890
- (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary;

891 892 893 894 895 896
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
897
- (void)setFloat:(float)value forKey:(uint32_t)key;
898

899 900 901 902 903
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
904
- (void)removeFloatForKey:(uint32_t)aKey;
905 906 907 908

/**
 * Removes all entries in this dictionary.
 **/
909 910 911 912 913 914
- (void)removeAll;

@end

#pragma mark - UInt32 -> Double

915 916 917 918 919 920
/**
 * Class used for map fields of <uint32_t, double>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
921 922
@interface GPBUInt32DoubleDictionary : NSObject <NSCopying>

923
/** Number of entries stored in this dictionary. */
924 925
@property(nonatomic, readonly) NSUInteger count;

926 927 928
/**
 * @return A newly instanced and empty dictionary.
 **/
929
+ (instancetype)dictionary;
930 931 932 933 934 935 936 937 938

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
939 940
+ (instancetype)dictionaryWithDouble:(double)value
                              forKey:(uint32_t)key;
941 942 943 944 945 946 947 948 949 950

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
951 952 953
+ (instancetype)dictionaryWithDoubles:(const double [])values
                              forKeys:(const uint32_t [])keys
                                count:(NSUInteger)count;
954 955 956 957 958 959 960 961 962 963

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
964
+ (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary;
965 966 967 968 969 970 971 972

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
973 974
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

975 976 977 978 979 980 981 982 983
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
984 985 986
- (instancetype)initWithDoubles:(const double [])values
                        forKeys:(const uint32_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
987 988 989 990 991 992 993 994

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
995
- (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary;
996 997 998 999 1000 1001 1002 1003

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
1004 1005
- (instancetype)initWithCapacity:(NSUInteger)numItems;

1006 1007 1008 1009 1010 1011 1012 1013
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
1014
- (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key;
1015

1016 1017 1018 1019 1020 1021 1022 1023
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
1024
- (void)enumerateKeysAndDoublesUsingBlock:
1025 1026
    (void (^)(uint32_t key, double value, BOOL *stop))block;

1027 1028 1029 1030 1031 1032
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
1033 1034
- (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary;

1035 1036 1037 1038 1039 1040
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
1041
- (void)setDouble:(double)value forKey:(uint32_t)key;
1042

1043 1044 1045 1046 1047
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
1048
- (void)removeDoubleForKey:(uint32_t)aKey;
1049 1050 1051 1052

/**
 * Removes all entries in this dictionary.
 **/
1053 1054 1055 1056 1057 1058
- (void)removeAll;

@end

#pragma mark - UInt32 -> Enum

1059 1060 1061 1062 1063 1064
/**
 * Class used for map fields of <uint32_t, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
1065 1066
@interface GPBUInt32EnumDictionary : NSObject <NSCopying>

1067
/** Number of entries stored in this dictionary. */
1068
@property(nonatomic, readonly) NSUInteger count;
1069
/** The validation function to check if the enums are valid. */
1070 1071
@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;

1072 1073 1074
/**
 * @return A newly instanced and empty dictionary.
 **/
1075
+ (instancetype)dictionary;
1076 1077 1078 1079 1080 1081 1082 1083

/**
 * Creates and initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly instanced dictionary.
 **/
1084
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param func     The enum validation function for the dictionary.
 * @param rawValue The raw enum value to be placed in the dictionary.
 * @param key      The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
1095
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
1096 1097
                                        rawValue:(int32_t)rawValue
                                          forKey:(uint32_t)key;
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
1109
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
1110 1111 1112
                                       rawValues:(const int32_t [])values
                                         forKeys:(const uint32_t [])keys
                                           count:(NSUInteger)count;
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
1123
+ (instancetype)dictionaryWithDictionary:(GPBUInt32EnumDictionary *)dictionary;
1124 1125 1126 1127 1128 1129 1130 1131 1132

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
1133
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
1134 1135
                                        capacity:(NSUInteger)numItems;

1136 1137 1138 1139 1140 1141 1142
/**
 * Initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly initialized dictionary.
 **/
1143
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154

/**
 * Initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly initialized dictionary with the keys and values in it.
 **/
1155
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
1156 1157 1158
                                 rawValues:(const int32_t [])values
                                   forKeys:(const uint32_t [])keys
                                     count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168

/**
 * Initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly initialized dictionary with the entries from the given
 *         dictionary in it.
 **/
1169
- (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary;
1170 1171 1172 1173 1174 1175 1176 1177 1178

/**
 * Initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly initialized dictionary with the given capacity.
 **/
1179
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
1180 1181 1182 1183 1184 1185
                                  capacity:(NSUInteger)numItems;

// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
// is not a valid enumerator as defined by validationFunc. If the actual value is
// desired, use "raw" version of the method.

1186 1187 1188 1189 1190 1191 1192 1193
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
1194
- (BOOL)getEnum:(nullable int32_t *)value forKey:(uint32_t)key;
1195

1196 1197 1198 1199 1200 1201 1202 1203
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
1204
- (void)enumerateKeysAndEnumsUsingBlock:
1205 1206
    (void (^)(uint32_t key, int32_t value, BOOL *stop))block;

1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
/**
 * Gets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue Pointer into which the value will be set, if found.
 * @param key      Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
1218
- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(uint32_t)key;
1219

1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param block The block to enumerate with.
 *   **key**:      The key for the current entry.
 *   **rawValue**: The value for the current entry
 *   **stop**:     A pointer to a boolean that when set stops the enumeration.
 **/
1231 1232 1233
- (void)enumerateKeysAndRawValuesUsingBlock:
    (void (^)(uint32_t key, int32_t rawValue, BOOL *stop))block;

1234 1235 1236 1237 1238 1239 1240 1241 1242
/**
 * Adds the keys and raw enum values from another dictionary.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
1243 1244 1245 1246 1247 1248 1249
- (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary;

// If value is not a valid enumerator as defined by validationFunc, these
// methods will assert in debug, and will log in release and assign the value
// to the default value. Use the rawValue methods below to assign non enumerator
// values.

1250 1251 1252 1253 1254 1255
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
1256
- (void)setEnum:(int32_t)value forKey:(uint32_t)key;
1257

1258 1259 1260 1261 1262 1263 1264 1265 1266
/**
 * Sets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue The raw enum value to set.
 * @param key      The key under which to store the raw enum value.
 **/
1267 1268
- (void)setRawValue:(int32_t)rawValue forKey:(uint32_t)key;

1269 1270 1271 1272 1273
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
1274
- (void)removeEnumForKey:(uint32_t)aKey;
1275 1276 1277 1278

/**
 * Removes all entries in this dictionary.
 **/
1279 1280 1281 1282 1283 1284
- (void)removeAll;

@end

#pragma mark - UInt32 -> Object

1285 1286 1287 1288 1289 1290
/**
 * Class used for map fields of <uint32_t, ObjectType>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
1291
@interface GPBUInt32ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
1292

1293
/** Number of entries stored in this dictionary. */
1294 1295
@property(nonatomic, readonly) NSUInteger count;

1296 1297 1298
/**
 * @return A newly instanced and empty dictionary.
 **/
1299
+ (instancetype)dictionary;
1300 1301 1302 1303 1304 1305 1306 1307 1308

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param object     The value to be placed in the dictionary.
 * @param key        The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
1309
+ (instancetype)dictionaryWithObject:(ObjectType)object
1310
                              forKey:(uint32_t)key;
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param objects      The values to be placed in the dictionary.
 * @param keys         The keys under which to store the values.
 * @param count        The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
1321
+ (instancetype)dictionaryWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects
1322 1323
                              forKeys:(const uint32_t [])keys
                                count:(NSUInteger)count;
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
1334
+ (instancetype)dictionaryWithDictionary:(GPBUInt32ObjectDictionary *)dictionary;
1335 1336 1337 1338 1339 1340 1341 1342

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
1343 1344
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

1345 1346 1347 1348 1349 1350 1351 1352 1353
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param objects      The values to be placed in this dictionary.
 * @param keys         The keys under which to store the values.
 * @param count        The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
1354
- (instancetype)initWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects
1355 1356
                        forKeys:(const uint32_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
1357 1358 1359 1360 1361 1362 1363 1364

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
1365
- (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary;
1366 1367 1368 1369 1370 1371 1372 1373

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
1374 1375
- (instancetype)initWithCapacity:(NSUInteger)numItems;

1376 1377 1378 1379 1380 1381 1382
/**
 * Fetches the object stored under the given key.
 *
 * @param key Key under which the value is stored, if present.
 *
 * @return The object if found, nil otherwise.
 **/
1383
- (ObjectType)objectForKey:(uint32_t)key;
1384

1385 1386 1387 1388 1389 1390 1391 1392
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:         The key for the current entry.
 *   **object**:      The value for the current entry
 *   **stop**:        A pointer to a boolean that when set stops the enumeration.
 **/
1393
- (void)enumerateKeysAndObjectsUsingBlock:
1394
    (void (^)(uint32_t key, ObjectType object, BOOL *stop))block;
1395

1396 1397 1398 1399 1400 1401
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
1402 1403
- (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary;

1404 1405 1406 1407 1408 1409
/**
 * Sets the value for the given key.
 *
 * @param object     The value to set.
 * @param key        The key under which to store the value.
 **/
1410
- (void)setObject:(ObjectType)object forKey:(uint32_t)key;
1411

1412 1413 1414 1415 1416
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
1417
- (void)removeObjectForKey:(uint32_t)aKey;
1418 1419 1420 1421

/**
 * Removes all entries in this dictionary.
 **/
1422 1423 1424 1425 1426 1427
- (void)removeAll;

@end

#pragma mark - Int32 -> UInt32

1428 1429 1430 1431 1432 1433
/**
 * Class used for map fields of <int32_t, uint32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
1434 1435
@interface GPBInt32UInt32Dictionary : NSObject <NSCopying>

1436
/** Number of entries stored in this dictionary. */
1437 1438
@property(nonatomic, readonly) NSUInteger count;

1439 1440 1441
/**
 * @return A newly instanced and empty dictionary.
 **/
1442
+ (instancetype)dictionary;
1443 1444 1445 1446 1447 1448 1449 1450 1451

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
1452 1453
+ (instancetype)dictionaryWithUInt32:(uint32_t)value
                              forKey:(int32_t)key;
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
1464 1465 1466
+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
                              forKeys:(const int32_t [])keys
                                count:(NSUInteger)count;
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
1477
+ (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary;
1478 1479 1480 1481 1482 1483 1484 1485

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
1486 1487
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

1488 1489 1490 1491 1492 1493 1494 1495 1496
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
1497 1498 1499
- (instancetype)initWithUInt32s:(const uint32_t [])values
                        forKeys:(const int32_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
1500 1501 1502 1503 1504 1505 1506 1507

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
1508
- (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary;
1509 1510 1511 1512 1513 1514 1515 1516

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
1517 1518
- (instancetype)initWithCapacity:(NSUInteger)numItems;

1519 1520 1521 1522 1523 1524 1525 1526
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
1527
- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key;
1528

1529 1530 1531 1532 1533 1534 1535 1536
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
1537
- (void)enumerateKeysAndUInt32sUsingBlock:
1538 1539
    (void (^)(int32_t key, uint32_t value, BOOL *stop))block;

1540 1541 1542 1543 1544 1545
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
1546 1547
- (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary;

1548 1549 1550 1551 1552 1553
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
1554
- (void)setUInt32:(uint32_t)value forKey:(int32_t)key;
1555

1556 1557 1558 1559 1560
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
1561
- (void)removeUInt32ForKey:(int32_t)aKey;
1562 1563 1564 1565

/**
 * Removes all entries in this dictionary.
 **/
1566 1567 1568 1569 1570 1571
- (void)removeAll;

@end

#pragma mark - Int32 -> Int32

1572 1573 1574 1575 1576 1577
/**
 * Class used for map fields of <int32_t, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
1578 1579
@interface GPBInt32Int32Dictionary : NSObject <NSCopying>

1580
/** Number of entries stored in this dictionary. */
1581 1582
@property(nonatomic, readonly) NSUInteger count;

1583 1584 1585
/**
 * @return A newly instanced and empty dictionary.
 **/
1586
+ (instancetype)dictionary;
1587 1588 1589 1590 1591 1592 1593 1594 1595

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
1596
+ (instancetype)dictionaryWithInt32:(int32_t)value
1597
                             forKey:(int32_t)key;
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
1608
+ (instancetype)dictionaryWithInt32s:(const int32_t [])values
1609 1610
                             forKeys:(const int32_t [])keys
                               count:(NSUInteger)count;
1611 1612 1613 1614 1615 1616 1617 1618 1619 1620

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
1621
+ (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary;
1622 1623 1624 1625 1626 1627 1628 1629

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
1630 1631
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

1632 1633 1634 1635 1636 1637 1638 1639 1640
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
1641
- (instancetype)initWithInt32s:(const int32_t [])values
1642 1643
                       forKeys:(const int32_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
1644 1645 1646 1647 1648 1649 1650 1651

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
1652
- (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary;
1653 1654 1655 1656 1657 1658 1659 1660

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
1661 1662
- (instancetype)initWithCapacity:(NSUInteger)numItems;

1663 1664 1665 1666 1667 1668 1669 1670
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
1671
- (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key;
1672

1673 1674 1675 1676 1677 1678 1679 1680
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
1681
- (void)enumerateKeysAndInt32sUsingBlock:
1682 1683
    (void (^)(int32_t key, int32_t value, BOOL *stop))block;

1684 1685 1686 1687 1688 1689
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
1690 1691
- (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary;

1692 1693 1694 1695 1696 1697
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
1698
- (void)setInt32:(int32_t)value forKey:(int32_t)key;
1699

1700 1701 1702 1703 1704
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
1705
- (void)removeInt32ForKey:(int32_t)aKey;
1706 1707 1708 1709

/**
 * Removes all entries in this dictionary.
 **/
1710 1711 1712 1713 1714 1715
- (void)removeAll;

@end

#pragma mark - Int32 -> UInt64

1716 1717 1718 1719 1720 1721
/**
 * Class used for map fields of <int32_t, uint64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
1722 1723
@interface GPBInt32UInt64Dictionary : NSObject <NSCopying>

1724
/** Number of entries stored in this dictionary. */
1725 1726
@property(nonatomic, readonly) NSUInteger count;

1727 1728 1729
/**
 * @return A newly instanced and empty dictionary.
 **/
1730
+ (instancetype)dictionary;
1731 1732 1733 1734 1735 1736 1737 1738 1739

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
1740 1741
+ (instancetype)dictionaryWithUInt64:(uint64_t)value
                              forKey:(int32_t)key;
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
1752 1753 1754
+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
                              forKeys:(const int32_t [])keys
                                count:(NSUInteger)count;
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
1765
+ (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary;
1766 1767 1768 1769 1770 1771 1772 1773

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
1774 1775
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

1776 1777 1778 1779 1780 1781 1782 1783 1784
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
1785 1786 1787
- (instancetype)initWithUInt64s:(const uint64_t [])values
                        forKeys:(const int32_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
1788 1789 1790 1791 1792 1793 1794 1795

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
1796
- (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary;
1797 1798 1799 1800 1801 1802 1803 1804

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
1805 1806
- (instancetype)initWithCapacity:(NSUInteger)numItems;

1807 1808 1809 1810 1811 1812 1813 1814
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
1815
- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key;
1816

1817 1818 1819 1820 1821 1822 1823 1824
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
1825
- (void)enumerateKeysAndUInt64sUsingBlock:
1826 1827
    (void (^)(int32_t key, uint64_t value, BOOL *stop))block;

1828 1829 1830 1831 1832 1833
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
1834 1835
- (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary;

1836 1837 1838 1839 1840 1841
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
1842
- (void)setUInt64:(uint64_t)value forKey:(int32_t)key;
1843

1844 1845 1846 1847 1848
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
1849
- (void)removeUInt64ForKey:(int32_t)aKey;
1850 1851 1852 1853

/**
 * Removes all entries in this dictionary.
 **/
1854 1855 1856 1857 1858 1859
- (void)removeAll;

@end

#pragma mark - Int32 -> Int64

1860 1861 1862 1863 1864 1865
/**
 * Class used for map fields of <int32_t, int64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
1866 1867
@interface GPBInt32Int64Dictionary : NSObject <NSCopying>

1868
/** Number of entries stored in this dictionary. */
1869 1870
@property(nonatomic, readonly) NSUInteger count;

1871 1872 1873
/**
 * @return A newly instanced and empty dictionary.
 **/
1874
+ (instancetype)dictionary;
1875 1876 1877 1878 1879 1880 1881 1882 1883

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
1884
+ (instancetype)dictionaryWithInt64:(int64_t)value
1885
                             forKey:(int32_t)key;
1886 1887 1888 1889 1890 1891 1892 1893 1894 1895

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
1896
+ (instancetype)dictionaryWithInt64s:(const int64_t [])values
1897 1898
                             forKeys:(const int32_t [])keys
                               count:(NSUInteger)count;
1899 1900 1901 1902 1903 1904 1905 1906 1907 1908

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
1909
+ (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary;
1910 1911 1912 1913 1914 1915 1916 1917

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
1918 1919
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

1920 1921 1922 1923 1924 1925 1926 1927 1928
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
1929
- (instancetype)initWithInt64s:(const int64_t [])values
1930 1931
                       forKeys:(const int32_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
1932 1933 1934 1935 1936 1937 1938 1939

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
1940
- (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary;
1941 1942 1943 1944 1945 1946 1947 1948

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
1949 1950
- (instancetype)initWithCapacity:(NSUInteger)numItems;

1951 1952 1953 1954 1955 1956 1957 1958
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
1959
- (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key;
1960

1961 1962 1963 1964 1965 1966 1967 1968
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
1969
- (void)enumerateKeysAndInt64sUsingBlock:
1970 1971
    (void (^)(int32_t key, int64_t value, BOOL *stop))block;

1972 1973 1974 1975 1976 1977
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
1978 1979
- (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary;

1980 1981 1982 1983 1984 1985
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
1986
- (void)setInt64:(int64_t)value forKey:(int32_t)key;
1987

1988 1989 1990 1991 1992
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
1993
- (void)removeInt64ForKey:(int32_t)aKey;
1994 1995 1996 1997

/**
 * Removes all entries in this dictionary.
 **/
1998 1999 2000 2001 2002 2003
- (void)removeAll;

@end

#pragma mark - Int32 -> Bool

2004 2005 2006 2007 2008 2009
/**
 * Class used for map fields of <int32_t, BOOL>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
2010 2011
@interface GPBInt32BoolDictionary : NSObject <NSCopying>

2012
/** Number of entries stored in this dictionary. */
2013 2014
@property(nonatomic, readonly) NSUInteger count;

2015 2016 2017
/**
 * @return A newly instanced and empty dictionary.
 **/
2018
+ (instancetype)dictionary;
2019 2020 2021 2022 2023 2024 2025 2026 2027

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
2028 2029
+ (instancetype)dictionaryWithBool:(BOOL)value
                            forKey:(int32_t)key;
2030 2031 2032 2033 2034 2035 2036 2037 2038 2039

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
2040 2041 2042
+ (instancetype)dictionaryWithBools:(const BOOL [])values
                            forKeys:(const int32_t [])keys
                              count:(NSUInteger)count;
2043 2044 2045 2046 2047 2048 2049 2050 2051 2052

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
2053
+ (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary;
2054 2055 2056 2057 2058 2059 2060 2061

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
2062 2063
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

2064 2065 2066 2067 2068 2069 2070 2071 2072
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
2073 2074 2075
- (instancetype)initWithBools:(const BOOL [])values
                      forKeys:(const int32_t [])keys
                        count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
2076 2077 2078 2079 2080 2081 2082 2083

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
2084
- (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary;
2085 2086 2087 2088 2089 2090 2091 2092

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
2093 2094
- (instancetype)initWithCapacity:(NSUInteger)numItems;

2095 2096 2097 2098 2099 2100 2101 2102
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
2103
- (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key;
2104

2105 2106 2107 2108 2109 2110 2111 2112
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
2113
- (void)enumerateKeysAndBoolsUsingBlock:
2114 2115
    (void (^)(int32_t key, BOOL value, BOOL *stop))block;

2116 2117 2118 2119 2120 2121
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
2122 2123
- (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary;

2124 2125 2126 2127 2128 2129
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
2130
- (void)setBool:(BOOL)value forKey:(int32_t)key;
2131

2132 2133 2134 2135 2136
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
2137
- (void)removeBoolForKey:(int32_t)aKey;
2138 2139 2140 2141

/**
 * Removes all entries in this dictionary.
 **/
2142 2143 2144 2145 2146 2147
- (void)removeAll;

@end

#pragma mark - Int32 -> Float

2148 2149 2150 2151 2152 2153
/**
 * Class used for map fields of <int32_t, float>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
2154 2155
@interface GPBInt32FloatDictionary : NSObject <NSCopying>

2156
/** Number of entries stored in this dictionary. */
2157 2158
@property(nonatomic, readonly) NSUInteger count;

2159 2160 2161
/**
 * @return A newly instanced and empty dictionary.
 **/
2162
+ (instancetype)dictionary;
2163 2164 2165 2166 2167 2168 2169 2170 2171

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
2172
+ (instancetype)dictionaryWithFloat:(float)value
2173
                             forKey:(int32_t)key;
2174 2175 2176 2177 2178 2179 2180 2181 2182 2183

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
2184
+ (instancetype)dictionaryWithFloats:(const float [])values
2185 2186
                             forKeys:(const int32_t [])keys
                               count:(NSUInteger)count;
2187 2188 2189 2190 2191 2192 2193 2194 2195 2196

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
2197
+ (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary;
2198 2199 2200 2201 2202 2203 2204 2205

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
2206 2207
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

2208 2209 2210 2211 2212 2213 2214 2215 2216
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
2217
- (instancetype)initWithFloats:(const float [])values
2218 2219
                       forKeys:(const int32_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
2220 2221 2222 2223 2224 2225 2226 2227

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
2228
- (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary;
2229 2230 2231 2232 2233 2234 2235 2236

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
2237 2238
- (instancetype)initWithCapacity:(NSUInteger)numItems;

2239 2240 2241 2242 2243 2244 2245 2246
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
2247
- (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key;
2248

2249 2250 2251 2252 2253 2254 2255 2256
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
2257
- (void)enumerateKeysAndFloatsUsingBlock:
2258 2259
    (void (^)(int32_t key, float value, BOOL *stop))block;

2260 2261 2262 2263 2264 2265
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
2266 2267
- (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary;

2268 2269 2270 2271 2272 2273
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
2274
- (void)setFloat:(float)value forKey:(int32_t)key;
2275

2276 2277 2278 2279 2280
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
2281
- (void)removeFloatForKey:(int32_t)aKey;
2282 2283 2284 2285

/**
 * Removes all entries in this dictionary.
 **/
2286 2287 2288 2289 2290 2291
- (void)removeAll;

@end

#pragma mark - Int32 -> Double

2292 2293 2294 2295 2296 2297
/**
 * Class used for map fields of <int32_t, double>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
2298 2299
@interface GPBInt32DoubleDictionary : NSObject <NSCopying>

2300
/** Number of entries stored in this dictionary. */
2301 2302
@property(nonatomic, readonly) NSUInteger count;

2303 2304 2305
/**
 * @return A newly instanced and empty dictionary.
 **/
2306
+ (instancetype)dictionary;
2307 2308 2309 2310 2311 2312 2313 2314 2315

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
2316 2317
+ (instancetype)dictionaryWithDouble:(double)value
                              forKey:(int32_t)key;
2318 2319 2320 2321 2322 2323 2324 2325 2326 2327

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
2328 2329 2330
+ (instancetype)dictionaryWithDoubles:(const double [])values
                              forKeys:(const int32_t [])keys
                                count:(NSUInteger)count;
2331 2332 2333 2334 2335 2336 2337 2338 2339 2340

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
2341
+ (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary;
2342 2343 2344 2345 2346 2347 2348 2349

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
2350 2351
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

2352 2353 2354 2355 2356 2357 2358 2359 2360
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
2361 2362 2363
- (instancetype)initWithDoubles:(const double [])values
                        forKeys:(const int32_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
2364 2365 2366 2367 2368 2369 2370 2371

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
2372
- (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary;
2373 2374 2375 2376 2377 2378 2379 2380

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
2381 2382
- (instancetype)initWithCapacity:(NSUInteger)numItems;

2383 2384 2385 2386 2387 2388 2389 2390
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
2391
- (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key;
2392

2393 2394 2395 2396 2397 2398 2399 2400
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
2401
- (void)enumerateKeysAndDoublesUsingBlock:
2402 2403
    (void (^)(int32_t key, double value, BOOL *stop))block;

2404 2405 2406 2407 2408 2409
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
2410 2411
- (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary;

2412 2413 2414 2415 2416 2417
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
2418
- (void)setDouble:(double)value forKey:(int32_t)key;
2419

2420 2421 2422 2423 2424
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
2425
- (void)removeDoubleForKey:(int32_t)aKey;
2426 2427 2428 2429

/**
 * Removes all entries in this dictionary.
 **/
2430 2431 2432 2433 2434 2435
- (void)removeAll;

@end

#pragma mark - Int32 -> Enum

2436 2437 2438 2439 2440 2441
/**
 * Class used for map fields of <int32_t, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
2442 2443
@interface GPBInt32EnumDictionary : NSObject <NSCopying>

2444
/** Number of entries stored in this dictionary. */
2445
@property(nonatomic, readonly) NSUInteger count;
2446
/** The validation function to check if the enums are valid. */
2447 2448
@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;

2449 2450 2451
/**
 * @return A newly instanced and empty dictionary.
 **/
2452
+ (instancetype)dictionary;
2453 2454 2455 2456 2457 2458 2459 2460

/**
 * Creates and initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly instanced dictionary.
 **/
2461
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
2462 2463 2464 2465 2466 2467 2468 2469 2470 2471

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param func     The enum validation function for the dictionary.
 * @param rawValue The raw enum value to be placed in the dictionary.
 * @param key      The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
2472
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
2473 2474
                                        rawValue:(int32_t)rawValue
                                          forKey:(int32_t)key;
2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
2486
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
2487 2488 2489
                                       rawValues:(const int32_t [])values
                                         forKeys:(const int32_t [])keys
                                           count:(NSUInteger)count;
2490 2491 2492 2493 2494 2495 2496 2497 2498 2499

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
2500
+ (instancetype)dictionaryWithDictionary:(GPBInt32EnumDictionary *)dictionary;
2501 2502 2503 2504 2505 2506 2507 2508 2509

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
2510
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
2511 2512
                                        capacity:(NSUInteger)numItems;

2513 2514 2515 2516 2517 2518 2519
/**
 * Initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly initialized dictionary.
 **/
2520
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531

/**
 * Initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly initialized dictionary with the keys and values in it.
 **/
2532
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
2533 2534 2535
                                 rawValues:(const int32_t [])values
                                   forKeys:(const int32_t [])keys
                                     count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
2536 2537 2538 2539 2540 2541 2542 2543 2544 2545

/**
 * Initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly initialized dictionary with the entries from the given
 *         dictionary in it.
 **/
2546
- (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary;
2547 2548 2549 2550 2551 2552 2553 2554 2555

/**
 * Initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly initialized dictionary with the given capacity.
 **/
2556
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
2557 2558 2559 2560 2561 2562
                                  capacity:(NSUInteger)numItems;

// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
// is not a valid enumerator as defined by validationFunc. If the actual value is
// desired, use "raw" version of the method.

2563 2564 2565 2566 2567 2568 2569 2570
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
2571
- (BOOL)getEnum:(nullable int32_t *)value forKey:(int32_t)key;
2572

2573 2574 2575 2576 2577 2578 2579 2580
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
2581
- (void)enumerateKeysAndEnumsUsingBlock:
2582 2583
    (void (^)(int32_t key, int32_t value, BOOL *stop))block;

2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594
/**
 * Gets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue Pointer into which the value will be set, if found.
 * @param key      Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
2595
- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(int32_t)key;
2596

2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param block The block to enumerate with.
 *   **key**:      The key for the current entry.
 *   **rawValue**: The value for the current entry
 *   **stop**:     A pointer to a boolean that when set stops the enumeration.
 **/
2608 2609 2610
- (void)enumerateKeysAndRawValuesUsingBlock:
    (void (^)(int32_t key, int32_t rawValue, BOOL *stop))block;

2611 2612 2613 2614 2615 2616 2617 2618 2619
/**
 * Adds the keys and raw enum values from another dictionary.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
2620 2621 2622 2623 2624 2625 2626
- (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary;

// If value is not a valid enumerator as defined by validationFunc, these
// methods will assert in debug, and will log in release and assign the value
// to the default value. Use the rawValue methods below to assign non enumerator
// values.

2627 2628 2629 2630 2631 2632
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
2633
- (void)setEnum:(int32_t)value forKey:(int32_t)key;
2634

2635 2636 2637 2638 2639 2640 2641 2642 2643
/**
 * Sets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue The raw enum value to set.
 * @param key      The key under which to store the raw enum value.
 **/
2644 2645
- (void)setRawValue:(int32_t)rawValue forKey:(int32_t)key;

2646 2647 2648 2649 2650
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
2651
- (void)removeEnumForKey:(int32_t)aKey;
2652 2653 2654 2655

/**
 * Removes all entries in this dictionary.
 **/
2656 2657 2658 2659 2660 2661
- (void)removeAll;

@end

#pragma mark - Int32 -> Object

2662 2663 2664 2665 2666 2667
/**
 * Class used for map fields of <int32_t, ObjectType>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
2668
@interface GPBInt32ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
2669

2670
/** Number of entries stored in this dictionary. */
2671 2672
@property(nonatomic, readonly) NSUInteger count;

2673 2674 2675
/**
 * @return A newly instanced and empty dictionary.
 **/
2676
+ (instancetype)dictionary;
2677 2678 2679 2680 2681 2682 2683 2684 2685

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param object     The value to be placed in the dictionary.
 * @param key        The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
2686
+ (instancetype)dictionaryWithObject:(ObjectType)object
2687
                              forKey:(int32_t)key;
2688 2689 2690 2691 2692 2693 2694 2695 2696 2697

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param objects      The values to be placed in the dictionary.
 * @param keys         The keys under which to store the values.
 * @param count        The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
2698
+ (instancetype)dictionaryWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects
2699 2700
                              forKeys:(const int32_t [])keys
                                count:(NSUInteger)count;
2701 2702 2703 2704 2705 2706 2707 2708 2709 2710

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
2711
+ (instancetype)dictionaryWithDictionary:(GPBInt32ObjectDictionary *)dictionary;
2712 2713 2714 2715 2716 2717 2718 2719

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
2720 2721
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

2722 2723 2724 2725 2726 2727 2728 2729 2730
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param objects      The values to be placed in this dictionary.
 * @param keys         The keys under which to store the values.
 * @param count        The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
2731
- (instancetype)initWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects
2732 2733
                        forKeys:(const int32_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
2734 2735 2736 2737 2738 2739 2740 2741

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
2742
- (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary;
2743 2744 2745 2746 2747 2748 2749 2750

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
2751 2752
- (instancetype)initWithCapacity:(NSUInteger)numItems;

2753 2754 2755 2756 2757 2758 2759
/**
 * Fetches the object stored under the given key.
 *
 * @param key Key under which the value is stored, if present.
 *
 * @return The object if found, nil otherwise.
 **/
2760
- (ObjectType)objectForKey:(int32_t)key;
2761

2762 2763 2764 2765 2766 2767 2768 2769
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:         The key for the current entry.
 *   **object**:      The value for the current entry
 *   **stop**:        A pointer to a boolean that when set stops the enumeration.
 **/
2770
- (void)enumerateKeysAndObjectsUsingBlock:
2771
    (void (^)(int32_t key, ObjectType object, BOOL *stop))block;
2772

2773 2774 2775 2776 2777 2778
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
2779 2780
- (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary;

2781 2782 2783 2784 2785 2786
/**
 * Sets the value for the given key.
 *
 * @param object     The value to set.
 * @param key        The key under which to store the value.
 **/
2787
- (void)setObject:(ObjectType)object forKey:(int32_t)key;
2788

2789 2790 2791 2792 2793
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
2794
- (void)removeObjectForKey:(int32_t)aKey;
2795 2796 2797 2798

/**
 * Removes all entries in this dictionary.
 **/
2799 2800 2801 2802 2803 2804
- (void)removeAll;

@end

#pragma mark - UInt64 -> UInt32

2805 2806 2807 2808 2809 2810
/**
 * Class used for map fields of <uint64_t, uint32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
2811 2812
@interface GPBUInt64UInt32Dictionary : NSObject <NSCopying>

2813
/** Number of entries stored in this dictionary. */
2814 2815
@property(nonatomic, readonly) NSUInteger count;

2816 2817 2818
/**
 * @return A newly instanced and empty dictionary.
 **/
2819
+ (instancetype)dictionary;
2820 2821 2822 2823 2824 2825 2826 2827 2828

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
2829 2830
+ (instancetype)dictionaryWithUInt32:(uint32_t)value
                              forKey:(uint64_t)key;
2831 2832 2833 2834 2835 2836 2837 2838 2839 2840

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
2841 2842 2843
+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
                              forKeys:(const uint64_t [])keys
                                count:(NSUInteger)count;
2844 2845 2846 2847 2848 2849 2850 2851 2852 2853

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
2854
+ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary;
2855 2856 2857 2858 2859 2860 2861 2862

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
2863 2864
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

2865 2866 2867 2868 2869 2870 2871 2872 2873
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
2874 2875 2876
- (instancetype)initWithUInt32s:(const uint32_t [])values
                        forKeys:(const uint64_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
2877 2878 2879 2880 2881 2882 2883 2884

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
2885
- (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary;
2886 2887 2888 2889 2890 2891 2892 2893

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
2894 2895
- (instancetype)initWithCapacity:(NSUInteger)numItems;

2896 2897 2898 2899 2900 2901 2902 2903
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
2904
- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key;
2905

2906 2907 2908 2909 2910 2911 2912 2913
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
2914
- (void)enumerateKeysAndUInt32sUsingBlock:
2915 2916
    (void (^)(uint64_t key, uint32_t value, BOOL *stop))block;

2917 2918 2919 2920 2921 2922
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
2923 2924
- (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary;

2925 2926 2927 2928 2929 2930
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
2931
- (void)setUInt32:(uint32_t)value forKey:(uint64_t)key;
2932

2933 2934 2935 2936 2937
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
2938
- (void)removeUInt32ForKey:(uint64_t)aKey;
2939 2940 2941 2942

/**
 * Removes all entries in this dictionary.
 **/
2943 2944 2945 2946 2947 2948
- (void)removeAll;

@end

#pragma mark - UInt64 -> Int32

2949 2950 2951 2952 2953 2954
/**
 * Class used for map fields of <uint64_t, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
2955 2956
@interface GPBUInt64Int32Dictionary : NSObject <NSCopying>

2957
/** Number of entries stored in this dictionary. */
2958 2959
@property(nonatomic, readonly) NSUInteger count;

2960 2961 2962
/**
 * @return A newly instanced and empty dictionary.
 **/
2963
+ (instancetype)dictionary;
2964 2965 2966 2967 2968 2969 2970 2971 2972

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
2973
+ (instancetype)dictionaryWithInt32:(int32_t)value
2974
                             forKey:(uint64_t)key;
2975 2976 2977 2978 2979 2980 2981 2982 2983 2984

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
2985
+ (instancetype)dictionaryWithInt32s:(const int32_t [])values
2986 2987
                             forKeys:(const uint64_t [])keys
                               count:(NSUInteger)count;
2988 2989 2990 2991 2992 2993 2994 2995 2996 2997

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
2998
+ (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary;
2999 3000 3001 3002 3003 3004 3005 3006

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
3007 3008
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

3009 3010 3011 3012 3013 3014 3015 3016 3017
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
3018
- (instancetype)initWithInt32s:(const int32_t [])values
3019 3020
                       forKeys:(const uint64_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
3021 3022 3023 3024 3025 3026 3027 3028

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
3029
- (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary;
3030 3031 3032 3033 3034 3035 3036 3037

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
3038 3039
- (instancetype)initWithCapacity:(NSUInteger)numItems;

3040 3041 3042 3043 3044 3045 3046 3047
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
3048
- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key;
3049

3050 3051 3052 3053 3054 3055 3056 3057
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
3058
- (void)enumerateKeysAndInt32sUsingBlock:
3059 3060
    (void (^)(uint64_t key, int32_t value, BOOL *stop))block;

3061 3062 3063 3064 3065 3066
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
3067 3068
- (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary;

3069 3070 3071 3072 3073 3074
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
3075
- (void)setInt32:(int32_t)value forKey:(uint64_t)key;
3076

3077 3078 3079 3080 3081
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
3082
- (void)removeInt32ForKey:(uint64_t)aKey;
3083 3084 3085 3086

/**
 * Removes all entries in this dictionary.
 **/
3087 3088 3089 3090 3091 3092
- (void)removeAll;

@end

#pragma mark - UInt64 -> UInt64

3093 3094 3095 3096 3097 3098
/**
 * Class used for map fields of <uint64_t, uint64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
3099 3100
@interface GPBUInt64UInt64Dictionary : NSObject <NSCopying>

3101
/** Number of entries stored in this dictionary. */
3102 3103
@property(nonatomic, readonly) NSUInteger count;

3104 3105 3106
/**
 * @return A newly instanced and empty dictionary.
 **/
3107
+ (instancetype)dictionary;
3108 3109 3110 3111 3112 3113 3114 3115 3116

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
3117 3118
+ (instancetype)dictionaryWithUInt64:(uint64_t)value
                              forKey:(uint64_t)key;
3119 3120 3121 3122 3123 3124 3125 3126 3127 3128

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
3129 3130 3131
+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
                              forKeys:(const uint64_t [])keys
                                count:(NSUInteger)count;
3132 3133 3134 3135 3136 3137 3138 3139 3140 3141

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
3142
+ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary;
3143 3144 3145 3146 3147 3148 3149 3150

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
3151 3152
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

3153 3154 3155 3156 3157 3158 3159 3160 3161
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
3162 3163 3164
- (instancetype)initWithUInt64s:(const uint64_t [])values
                        forKeys:(const uint64_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
3165 3166 3167 3168 3169 3170 3171 3172

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
3173
- (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary;
3174 3175 3176 3177 3178 3179 3180 3181

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
3182 3183
- (instancetype)initWithCapacity:(NSUInteger)numItems;

3184 3185 3186 3187 3188 3189 3190 3191
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
3192
- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key;
3193

3194 3195 3196 3197 3198 3199 3200 3201
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
3202
- (void)enumerateKeysAndUInt64sUsingBlock:
3203 3204
    (void (^)(uint64_t key, uint64_t value, BOOL *stop))block;

3205 3206 3207 3208 3209 3210
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
3211 3212
- (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary;

3213 3214 3215 3216 3217 3218
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
3219
- (void)setUInt64:(uint64_t)value forKey:(uint64_t)key;
3220

3221 3222 3223 3224 3225
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
3226
- (void)removeUInt64ForKey:(uint64_t)aKey;
3227 3228 3229 3230

/**
 * Removes all entries in this dictionary.
 **/
3231 3232 3233 3234 3235 3236
- (void)removeAll;

@end

#pragma mark - UInt64 -> Int64

3237 3238 3239 3240 3241 3242
/**
 * Class used for map fields of <uint64_t, int64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
3243 3244
@interface GPBUInt64Int64Dictionary : NSObject <NSCopying>

3245
/** Number of entries stored in this dictionary. */
3246 3247
@property(nonatomic, readonly) NSUInteger count;

3248 3249 3250
/**
 * @return A newly instanced and empty dictionary.
 **/
3251
+ (instancetype)dictionary;
3252 3253 3254 3255 3256 3257 3258 3259 3260

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
3261
+ (instancetype)dictionaryWithInt64:(int64_t)value
3262
                             forKey:(uint64_t)key;
3263 3264 3265 3266 3267 3268 3269 3270 3271 3272

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
3273
+ (instancetype)dictionaryWithInt64s:(const int64_t [])values
3274 3275
                             forKeys:(const uint64_t [])keys
                               count:(NSUInteger)count;
3276 3277 3278 3279 3280 3281 3282 3283 3284 3285

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
3286
+ (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary;
3287 3288 3289 3290 3291 3292 3293 3294

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
3295 3296
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

3297 3298 3299 3300 3301 3302 3303 3304 3305
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
3306
- (instancetype)initWithInt64s:(const int64_t [])values
3307 3308
                       forKeys:(const uint64_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
3309 3310 3311 3312 3313 3314 3315 3316

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
3317
- (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary;
3318 3319 3320 3321 3322 3323 3324 3325

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
3326 3327
- (instancetype)initWithCapacity:(NSUInteger)numItems;

3328 3329 3330 3331 3332 3333 3334 3335
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
3336
- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key;
3337

3338 3339 3340 3341 3342 3343 3344 3345
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
3346
- (void)enumerateKeysAndInt64sUsingBlock:
3347 3348
    (void (^)(uint64_t key, int64_t value, BOOL *stop))block;

3349 3350 3351 3352 3353 3354
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
3355 3356
- (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary;

3357 3358 3359 3360 3361 3362
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
3363
- (void)setInt64:(int64_t)value forKey:(uint64_t)key;
3364

3365 3366 3367 3368 3369
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
3370
- (void)removeInt64ForKey:(uint64_t)aKey;
3371 3372 3373 3374

/**
 * Removes all entries in this dictionary.
 **/
3375 3376 3377 3378 3379 3380
- (void)removeAll;

@end

#pragma mark - UInt64 -> Bool

3381 3382 3383 3384 3385 3386
/**
 * Class used for map fields of <uint64_t, BOOL>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
3387 3388
@interface GPBUInt64BoolDictionary : NSObject <NSCopying>

3389
/** Number of entries stored in this dictionary. */
3390 3391
@property(nonatomic, readonly) NSUInteger count;

3392 3393 3394
/**
 * @return A newly instanced and empty dictionary.
 **/
3395
+ (instancetype)dictionary;
3396 3397 3398 3399 3400 3401 3402 3403 3404

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
3405 3406
+ (instancetype)dictionaryWithBool:(BOOL)value
                            forKey:(uint64_t)key;
3407 3408 3409 3410 3411 3412 3413 3414 3415 3416

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
3417 3418 3419
+ (instancetype)dictionaryWithBools:(const BOOL [])values
                            forKeys:(const uint64_t [])keys
                              count:(NSUInteger)count;
3420 3421 3422 3423 3424 3425 3426 3427 3428 3429

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
3430
+ (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary;
3431 3432 3433 3434 3435 3436 3437 3438

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
3439 3440
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

3441 3442 3443 3444 3445 3446 3447 3448 3449
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
3450 3451 3452
- (instancetype)initWithBools:(const BOOL [])values
                      forKeys:(const uint64_t [])keys
                        count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
3453 3454 3455 3456 3457 3458 3459 3460

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
3461
- (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary;
3462 3463 3464 3465 3466 3467 3468 3469

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
3470 3471
- (instancetype)initWithCapacity:(NSUInteger)numItems;

3472 3473 3474 3475 3476 3477 3478 3479
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
3480
- (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key;
3481

3482 3483 3484 3485 3486 3487 3488 3489
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
3490
- (void)enumerateKeysAndBoolsUsingBlock:
3491 3492
    (void (^)(uint64_t key, BOOL value, BOOL *stop))block;

3493 3494 3495 3496 3497 3498
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
3499 3500
- (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary;

3501 3502 3503 3504 3505 3506
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
3507
- (void)setBool:(BOOL)value forKey:(uint64_t)key;
3508

3509 3510 3511 3512 3513
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
3514
- (void)removeBoolForKey:(uint64_t)aKey;
3515 3516 3517 3518

/**
 * Removes all entries in this dictionary.
 **/
3519 3520 3521 3522 3523 3524
- (void)removeAll;

@end

#pragma mark - UInt64 -> Float

3525 3526 3527 3528 3529 3530
/**
 * Class used for map fields of <uint64_t, float>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
3531 3532
@interface GPBUInt64FloatDictionary : NSObject <NSCopying>

3533
/** Number of entries stored in this dictionary. */
3534 3535
@property(nonatomic, readonly) NSUInteger count;

3536 3537 3538
/**
 * @return A newly instanced and empty dictionary.
 **/
3539
+ (instancetype)dictionary;
3540 3541 3542 3543 3544 3545 3546 3547 3548

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
3549
+ (instancetype)dictionaryWithFloat:(float)value
3550
                             forKey:(uint64_t)key;
3551 3552 3553 3554 3555 3556 3557 3558 3559 3560

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
3561
+ (instancetype)dictionaryWithFloats:(const float [])values
3562 3563
                             forKeys:(const uint64_t [])keys
                               count:(NSUInteger)count;
3564 3565 3566 3567 3568 3569 3570 3571 3572 3573

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
3574
+ (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary;
3575 3576 3577 3578 3579 3580 3581 3582

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
3583 3584
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

3585 3586 3587 3588 3589 3590 3591 3592 3593
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
3594
- (instancetype)initWithFloats:(const float [])values
3595 3596
                       forKeys:(const uint64_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
3597 3598 3599 3600 3601 3602 3603 3604

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
3605
- (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary;
3606 3607 3608 3609 3610 3611 3612 3613

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
3614 3615
- (instancetype)initWithCapacity:(NSUInteger)numItems;

3616 3617 3618 3619 3620 3621 3622 3623
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
3624
- (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key;
3625

3626 3627 3628 3629 3630 3631 3632 3633
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
3634
- (void)enumerateKeysAndFloatsUsingBlock:
3635 3636
    (void (^)(uint64_t key, float value, BOOL *stop))block;

3637 3638 3639 3640 3641 3642
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
3643 3644
- (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary;

3645 3646 3647 3648 3649 3650
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
3651
- (void)setFloat:(float)value forKey:(uint64_t)key;
3652

3653 3654 3655 3656 3657
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
3658
- (void)removeFloatForKey:(uint64_t)aKey;
3659 3660 3661 3662

/**
 * Removes all entries in this dictionary.
 **/
3663 3664 3665 3666 3667 3668
- (void)removeAll;

@end

#pragma mark - UInt64 -> Double

3669 3670 3671 3672 3673 3674
/**
 * Class used for map fields of <uint64_t, double>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
3675 3676
@interface GPBUInt64DoubleDictionary : NSObject <NSCopying>

3677
/** Number of entries stored in this dictionary. */
3678 3679
@property(nonatomic, readonly) NSUInteger count;

3680 3681 3682
/**
 * @return A newly instanced and empty dictionary.
 **/
3683
+ (instancetype)dictionary;
3684 3685 3686 3687 3688 3689 3690 3691 3692

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
3693 3694
+ (instancetype)dictionaryWithDouble:(double)value
                              forKey:(uint64_t)key;
3695 3696 3697 3698 3699 3700 3701 3702 3703 3704

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
3705 3706 3707
+ (instancetype)dictionaryWithDoubles:(const double [])values
                              forKeys:(const uint64_t [])keys
                                count:(NSUInteger)count;
3708 3709 3710 3711 3712 3713 3714 3715 3716 3717

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
3718
+ (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary;
3719 3720 3721 3722 3723 3724 3725 3726

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
3727 3728
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

3729 3730 3731 3732 3733 3734 3735 3736 3737
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
3738 3739 3740
- (instancetype)initWithDoubles:(const double [])values
                        forKeys:(const uint64_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
3741 3742 3743 3744 3745 3746 3747 3748

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
3749
- (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary;
3750 3751 3752 3753 3754 3755 3756 3757

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
3758 3759
- (instancetype)initWithCapacity:(NSUInteger)numItems;

3760 3761 3762 3763 3764 3765 3766 3767
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
3768
- (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key;
3769

3770 3771 3772 3773 3774 3775 3776 3777
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
3778
- (void)enumerateKeysAndDoublesUsingBlock:
3779 3780
    (void (^)(uint64_t key, double value, BOOL *stop))block;

3781 3782 3783 3784 3785 3786
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
3787 3788
- (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary;

3789 3790 3791 3792 3793 3794
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
3795
- (void)setDouble:(double)value forKey:(uint64_t)key;
3796

3797 3798 3799 3800 3801
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
3802
- (void)removeDoubleForKey:(uint64_t)aKey;
3803 3804 3805 3806

/**
 * Removes all entries in this dictionary.
 **/
3807 3808 3809 3810 3811 3812
- (void)removeAll;

@end

#pragma mark - UInt64 -> Enum

3813 3814 3815 3816 3817 3818
/**
 * Class used for map fields of <uint64_t, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
3819 3820
@interface GPBUInt64EnumDictionary : NSObject <NSCopying>

3821
/** Number of entries stored in this dictionary. */
3822
@property(nonatomic, readonly) NSUInteger count;
3823
/** The validation function to check if the enums are valid. */
3824 3825
@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;

3826 3827 3828
/**
 * @return A newly instanced and empty dictionary.
 **/
3829
+ (instancetype)dictionary;
3830 3831 3832 3833 3834 3835 3836 3837

/**
 * Creates and initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly instanced dictionary.
 **/
3838
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
3839 3840 3841 3842 3843 3844 3845 3846 3847 3848

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param func     The enum validation function for the dictionary.
 * @param rawValue The raw enum value to be placed in the dictionary.
 * @param key      The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
3849
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
3850 3851
                                        rawValue:(int32_t)rawValue
                                          forKey:(uint64_t)key;
3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
3863
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
3864 3865 3866
                                       rawValues:(const int32_t [])values
                                         forKeys:(const uint64_t [])keys
                                           count:(NSUInteger)count;
3867 3868 3869 3870 3871 3872 3873 3874 3875 3876

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
3877
+ (instancetype)dictionaryWithDictionary:(GPBUInt64EnumDictionary *)dictionary;
3878 3879 3880 3881 3882 3883 3884 3885 3886

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
3887
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
3888 3889
                                        capacity:(NSUInteger)numItems;

3890 3891 3892 3893 3894 3895 3896
/**
 * Initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly initialized dictionary.
 **/
3897
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908

/**
 * Initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly initialized dictionary with the keys and values in it.
 **/
3909
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
3910 3911 3912
                                 rawValues:(const int32_t [])values
                                   forKeys:(const uint64_t [])keys
                                     count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
3913 3914 3915 3916 3917 3918 3919 3920 3921 3922

/**
 * Initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly initialized dictionary with the entries from the given
 *         dictionary in it.
 **/
3923
- (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary;
3924 3925 3926 3927 3928 3929 3930 3931 3932

/**
 * Initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly initialized dictionary with the given capacity.
 **/
3933
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
3934 3935 3936 3937 3938 3939
                                  capacity:(NSUInteger)numItems;

// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
// is not a valid enumerator as defined by validationFunc. If the actual value is
// desired, use "raw" version of the method.

3940 3941 3942 3943 3944 3945 3946 3947
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
3948
- (BOOL)getEnum:(nullable int32_t *)value forKey:(uint64_t)key;
3949

3950 3951 3952 3953 3954 3955 3956 3957
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
3958
- (void)enumerateKeysAndEnumsUsingBlock:
3959 3960
    (void (^)(uint64_t key, int32_t value, BOOL *stop))block;

3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971
/**
 * Gets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue Pointer into which the value will be set, if found.
 * @param key      Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
3972
- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(uint64_t)key;
3973

3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param block The block to enumerate with.
 *   **key**:      The key for the current entry.
 *   **rawValue**: The value for the current entry
 *   **stop**:     A pointer to a boolean that when set stops the enumeration.
 **/
3985 3986 3987
- (void)enumerateKeysAndRawValuesUsingBlock:
    (void (^)(uint64_t key, int32_t rawValue, BOOL *stop))block;

3988 3989 3990 3991 3992 3993 3994 3995 3996
/**
 * Adds the keys and raw enum values from another dictionary.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
3997 3998 3999 4000 4001 4002 4003
- (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary;

// If value is not a valid enumerator as defined by validationFunc, these
// methods will assert in debug, and will log in release and assign the value
// to the default value. Use the rawValue methods below to assign non enumerator
// values.

4004 4005 4006 4007 4008 4009
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
4010
- (void)setEnum:(int32_t)value forKey:(uint64_t)key;
4011

4012 4013 4014 4015 4016 4017 4018 4019 4020
/**
 * Sets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue The raw enum value to set.
 * @param key      The key under which to store the raw enum value.
 **/
4021 4022
- (void)setRawValue:(int32_t)rawValue forKey:(uint64_t)key;

4023 4024 4025 4026 4027
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
4028
- (void)removeEnumForKey:(uint64_t)aKey;
4029 4030 4031 4032

/**
 * Removes all entries in this dictionary.
 **/
4033 4034 4035 4036 4037 4038
- (void)removeAll;

@end

#pragma mark - UInt64 -> Object

4039 4040 4041 4042 4043 4044
/**
 * Class used for map fields of <uint64_t, ObjectType>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
4045
@interface GPBUInt64ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
4046

4047
/** Number of entries stored in this dictionary. */
4048 4049
@property(nonatomic, readonly) NSUInteger count;

4050 4051 4052
/**
 * @return A newly instanced and empty dictionary.
 **/
4053
+ (instancetype)dictionary;
4054 4055 4056 4057 4058 4059 4060 4061 4062

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param object     The value to be placed in the dictionary.
 * @param key        The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
4063
+ (instancetype)dictionaryWithObject:(ObjectType)object
4064
                              forKey:(uint64_t)key;
4065 4066 4067 4068 4069 4070 4071 4072 4073 4074

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param objects      The values to be placed in the dictionary.
 * @param keys         The keys under which to store the values.
 * @param count        The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
4075
+ (instancetype)dictionaryWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects
4076 4077
                              forKeys:(const uint64_t [])keys
                                count:(NSUInteger)count;
4078 4079 4080 4081 4082 4083 4084 4085 4086 4087

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
4088
+ (instancetype)dictionaryWithDictionary:(GPBUInt64ObjectDictionary *)dictionary;
4089 4090 4091 4092 4093 4094 4095 4096

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
4097 4098
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

4099 4100 4101 4102 4103 4104 4105 4106 4107
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param objects      The values to be placed in this dictionary.
 * @param keys         The keys under which to store the values.
 * @param count        The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
4108
- (instancetype)initWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects
4109 4110
                        forKeys:(const uint64_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
4111 4112 4113 4114 4115 4116 4117 4118

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
4119
- (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary;
4120 4121 4122 4123 4124 4125 4126 4127

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
4128 4129
- (instancetype)initWithCapacity:(NSUInteger)numItems;

4130 4131 4132 4133 4134 4135 4136
/**
 * Fetches the object stored under the given key.
 *
 * @param key Key under which the value is stored, if present.
 *
 * @return The object if found, nil otherwise.
 **/
4137
- (ObjectType)objectForKey:(uint64_t)key;
4138

4139 4140 4141 4142 4143 4144 4145 4146
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:         The key for the current entry.
 *   **object**:      The value for the current entry
 *   **stop**:        A pointer to a boolean that when set stops the enumeration.
 **/
4147
- (void)enumerateKeysAndObjectsUsingBlock:
4148
    (void (^)(uint64_t key, ObjectType object, BOOL *stop))block;
4149

4150 4151 4152 4153 4154 4155
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
4156 4157
- (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary;

4158 4159 4160 4161 4162 4163
/**
 * Sets the value for the given key.
 *
 * @param object     The value to set.
 * @param key        The key under which to store the value.
 **/
4164
- (void)setObject:(ObjectType)object forKey:(uint64_t)key;
4165

4166 4167 4168 4169 4170
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
4171
- (void)removeObjectForKey:(uint64_t)aKey;
4172 4173 4174 4175

/**
 * Removes all entries in this dictionary.
 **/
4176 4177 4178 4179 4180 4181
- (void)removeAll;

@end

#pragma mark - Int64 -> UInt32

4182 4183 4184 4185 4186 4187
/**
 * Class used for map fields of <int64_t, uint32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
4188 4189
@interface GPBInt64UInt32Dictionary : NSObject <NSCopying>

4190
/** Number of entries stored in this dictionary. */
4191 4192
@property(nonatomic, readonly) NSUInteger count;

4193 4194 4195
/**
 * @return A newly instanced and empty dictionary.
 **/
4196
+ (instancetype)dictionary;
4197 4198 4199 4200 4201 4202 4203 4204 4205

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
4206 4207
+ (instancetype)dictionaryWithUInt32:(uint32_t)value
                              forKey:(int64_t)key;
4208 4209 4210 4211 4212 4213 4214 4215 4216 4217

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
4218 4219 4220
+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
                              forKeys:(const int64_t [])keys
                                count:(NSUInteger)count;
4221 4222 4223 4224 4225 4226 4227 4228 4229 4230

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
4231
+ (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary;
4232 4233 4234 4235 4236 4237 4238 4239

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
4240 4241
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

4242 4243 4244 4245 4246 4247 4248 4249 4250
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
4251 4252 4253
- (instancetype)initWithUInt32s:(const uint32_t [])values
                        forKeys:(const int64_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
4254 4255 4256 4257 4258 4259 4260 4261

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
4262
- (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary;
4263 4264 4265 4266 4267 4268 4269 4270

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
4271 4272
- (instancetype)initWithCapacity:(NSUInteger)numItems;

4273 4274 4275 4276 4277 4278 4279 4280
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
4281
- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key;
4282

4283 4284 4285 4286 4287 4288 4289 4290
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
4291
- (void)enumerateKeysAndUInt32sUsingBlock:
4292 4293
    (void (^)(int64_t key, uint32_t value, BOOL *stop))block;

4294 4295 4296 4297 4298 4299
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
4300 4301
- (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary;

4302 4303 4304 4305 4306 4307
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
4308
- (void)setUInt32:(uint32_t)value forKey:(int64_t)key;
4309

4310 4311 4312 4313 4314
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
4315
- (void)removeUInt32ForKey:(int64_t)aKey;
4316 4317 4318 4319

/**
 * Removes all entries in this dictionary.
 **/
4320 4321 4322 4323 4324 4325
- (void)removeAll;

@end

#pragma mark - Int64 -> Int32

4326 4327 4328 4329 4330 4331
/**
 * Class used for map fields of <int64_t, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
4332 4333
@interface GPBInt64Int32Dictionary : NSObject <NSCopying>

4334
/** Number of entries stored in this dictionary. */
4335 4336
@property(nonatomic, readonly) NSUInteger count;

4337 4338 4339
/**
 * @return A newly instanced and empty dictionary.
 **/
4340
+ (instancetype)dictionary;
4341 4342 4343 4344 4345 4346 4347 4348 4349

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
4350
+ (instancetype)dictionaryWithInt32:(int32_t)value
4351
                             forKey:(int64_t)key;
4352 4353 4354 4355 4356 4357 4358 4359 4360 4361

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
4362
+ (instancetype)dictionaryWithInt32s:(const int32_t [])values
4363 4364
                             forKeys:(const int64_t [])keys
                               count:(NSUInteger)count;
4365 4366 4367 4368 4369 4370 4371 4372 4373 4374

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
4375
+ (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary;
4376 4377 4378 4379 4380 4381 4382 4383

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
4384 4385
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

4386 4387 4388 4389 4390 4391 4392 4393 4394
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
4395
- (instancetype)initWithInt32s:(const int32_t [])values
4396 4397
                       forKeys:(const int64_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
4398 4399 4400 4401 4402 4403 4404 4405

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
4406
- (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary;
4407 4408 4409 4410 4411 4412 4413 4414

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
4415 4416
- (instancetype)initWithCapacity:(NSUInteger)numItems;

4417 4418 4419 4420 4421 4422 4423 4424
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
4425
- (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key;
4426

4427 4428 4429 4430 4431 4432 4433 4434
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
4435
- (void)enumerateKeysAndInt32sUsingBlock:
4436 4437
    (void (^)(int64_t key, int32_t value, BOOL *stop))block;

4438 4439 4440 4441 4442 4443
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
4444 4445
- (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary;

4446 4447 4448 4449 4450 4451
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
4452
- (void)setInt32:(int32_t)value forKey:(int64_t)key;
4453

4454 4455 4456 4457 4458
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
4459
- (void)removeInt32ForKey:(int64_t)aKey;
4460 4461 4462 4463

/**
 * Removes all entries in this dictionary.
 **/
4464 4465 4466 4467 4468 4469
- (void)removeAll;

@end

#pragma mark - Int64 -> UInt64

4470 4471 4472 4473 4474 4475
/**
 * Class used for map fields of <int64_t, uint64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
4476 4477
@interface GPBInt64UInt64Dictionary : NSObject <NSCopying>

4478
/** Number of entries stored in this dictionary. */
4479 4480
@property(nonatomic, readonly) NSUInteger count;

4481 4482 4483
/**
 * @return A newly instanced and empty dictionary.
 **/
4484
+ (instancetype)dictionary;
4485 4486 4487 4488 4489 4490 4491 4492 4493

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
4494 4495
+ (instancetype)dictionaryWithUInt64:(uint64_t)value
                              forKey:(int64_t)key;
4496 4497 4498 4499 4500 4501 4502 4503 4504 4505

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
4506 4507 4508
+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
                              forKeys:(const int64_t [])keys
                                count:(NSUInteger)count;
4509 4510 4511 4512 4513 4514 4515 4516 4517 4518

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
4519
+ (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary;
4520 4521 4522 4523 4524 4525 4526 4527

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
4528 4529
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

4530 4531 4532 4533 4534 4535 4536 4537 4538
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
4539 4540 4541
- (instancetype)initWithUInt64s:(const uint64_t [])values
                        forKeys:(const int64_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
4542 4543 4544 4545 4546 4547 4548 4549

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
4550
- (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary;
4551 4552 4553 4554 4555 4556 4557 4558

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
4559 4560
- (instancetype)initWithCapacity:(NSUInteger)numItems;

4561 4562 4563 4564 4565 4566 4567 4568
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
4569
- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key;
4570

4571 4572 4573 4574 4575 4576 4577 4578
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
4579
- (void)enumerateKeysAndUInt64sUsingBlock:
4580 4581
    (void (^)(int64_t key, uint64_t value, BOOL *stop))block;

4582 4583 4584 4585 4586 4587
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
4588 4589
- (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary;

4590 4591 4592 4593 4594 4595
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
4596
- (void)setUInt64:(uint64_t)value forKey:(int64_t)key;
4597

4598 4599 4600 4601 4602
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
4603
- (void)removeUInt64ForKey:(int64_t)aKey;
4604 4605 4606 4607

/**
 * Removes all entries in this dictionary.
 **/
4608 4609 4610 4611 4612 4613
- (void)removeAll;

@end

#pragma mark - Int64 -> Int64

4614 4615 4616 4617 4618 4619
/**
 * Class used for map fields of <int64_t, int64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
4620 4621
@interface GPBInt64Int64Dictionary : NSObject <NSCopying>

4622
/** Number of entries stored in this dictionary. */
4623 4624
@property(nonatomic, readonly) NSUInteger count;

4625 4626 4627
/**
 * @return A newly instanced and empty dictionary.
 **/
4628
+ (instancetype)dictionary;
4629 4630 4631 4632 4633 4634 4635 4636 4637

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
4638
+ (instancetype)dictionaryWithInt64:(int64_t)value
4639
                             forKey:(int64_t)key;
4640 4641 4642 4643 4644 4645 4646 4647 4648 4649

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
4650
+ (instancetype)dictionaryWithInt64s:(const int64_t [])values
4651 4652
                             forKeys:(const int64_t [])keys
                               count:(NSUInteger)count;
4653 4654 4655 4656 4657 4658 4659 4660 4661 4662

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
4663
+ (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary;
4664 4665 4666 4667 4668 4669 4670 4671

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
4672 4673
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

4674 4675 4676 4677 4678 4679 4680 4681 4682
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
4683
- (instancetype)initWithInt64s:(const int64_t [])values
4684 4685
                       forKeys:(const int64_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
4686 4687 4688 4689 4690 4691 4692 4693

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
4694
- (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary;
4695 4696 4697 4698 4699 4700 4701 4702

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
4703 4704
- (instancetype)initWithCapacity:(NSUInteger)numItems;

4705 4706 4707 4708 4709 4710 4711 4712
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
4713
- (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key;
4714

4715 4716 4717 4718 4719 4720 4721 4722
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
4723
- (void)enumerateKeysAndInt64sUsingBlock:
4724 4725
    (void (^)(int64_t key, int64_t value, BOOL *stop))block;

4726 4727 4728 4729 4730 4731
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
4732 4733
- (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary;

4734 4735 4736 4737 4738 4739
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
4740
- (void)setInt64:(int64_t)value forKey:(int64_t)key;
4741

4742 4743 4744 4745 4746
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
4747
- (void)removeInt64ForKey:(int64_t)aKey;
4748 4749 4750 4751

/**
 * Removes all entries in this dictionary.
 **/
4752 4753 4754 4755 4756 4757
- (void)removeAll;

@end

#pragma mark - Int64 -> Bool

4758 4759 4760 4761 4762 4763
/**
 * Class used for map fields of <int64_t, BOOL>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
4764 4765
@interface GPBInt64BoolDictionary : NSObject <NSCopying>

4766
/** Number of entries stored in this dictionary. */
4767 4768
@property(nonatomic, readonly) NSUInteger count;

4769 4770 4771
/**
 * @return A newly instanced and empty dictionary.
 **/
4772
+ (instancetype)dictionary;
4773 4774 4775 4776 4777 4778 4779 4780 4781

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
4782 4783
+ (instancetype)dictionaryWithBool:(BOOL)value
                            forKey:(int64_t)key;
4784 4785 4786 4787 4788 4789 4790 4791 4792 4793

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
4794 4795 4796
+ (instancetype)dictionaryWithBools:(const BOOL [])values
                            forKeys:(const int64_t [])keys
                              count:(NSUInteger)count;
4797 4798 4799 4800 4801 4802 4803 4804 4805 4806

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
4807
+ (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary;
4808 4809 4810 4811 4812 4813 4814 4815

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
4816 4817
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

4818 4819 4820 4821 4822 4823 4824 4825 4826
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
4827 4828 4829
- (instancetype)initWithBools:(const BOOL [])values
                      forKeys:(const int64_t [])keys
                        count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
4830 4831 4832 4833 4834 4835 4836 4837

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
4838
- (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary;
4839 4840 4841 4842 4843 4844 4845 4846

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
4847 4848
- (instancetype)initWithCapacity:(NSUInteger)numItems;

4849 4850 4851 4852 4853 4854 4855 4856
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
4857
- (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key;
4858

4859 4860 4861 4862 4863 4864 4865 4866
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
4867
- (void)enumerateKeysAndBoolsUsingBlock:
4868 4869
    (void (^)(int64_t key, BOOL value, BOOL *stop))block;

4870 4871 4872 4873 4874 4875
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
4876 4877
- (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary;

4878 4879 4880 4881 4882 4883
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
4884
- (void)setBool:(BOOL)value forKey:(int64_t)key;
4885

4886 4887 4888 4889 4890
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
4891
- (void)removeBoolForKey:(int64_t)aKey;
4892 4893 4894 4895

/**
 * Removes all entries in this dictionary.
 **/
4896 4897 4898 4899 4900 4901
- (void)removeAll;

@end

#pragma mark - Int64 -> Float

4902 4903 4904 4905 4906 4907
/**
 * Class used for map fields of <int64_t, float>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
4908 4909
@interface GPBInt64FloatDictionary : NSObject <NSCopying>

4910
/** Number of entries stored in this dictionary. */
4911 4912
@property(nonatomic, readonly) NSUInteger count;

4913 4914 4915
/**
 * @return A newly instanced and empty dictionary.
 **/
4916
+ (instancetype)dictionary;
4917 4918 4919 4920 4921 4922 4923 4924 4925

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
4926
+ (instancetype)dictionaryWithFloat:(float)value
4927
                             forKey:(int64_t)key;
4928 4929 4930 4931 4932 4933 4934 4935 4936 4937

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
4938
+ (instancetype)dictionaryWithFloats:(const float [])values
4939 4940
                             forKeys:(const int64_t [])keys
                               count:(NSUInteger)count;
4941 4942 4943 4944 4945 4946 4947 4948 4949 4950

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
4951
+ (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary;
4952 4953 4954 4955 4956 4957 4958 4959

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
4960 4961
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

4962 4963 4964 4965 4966 4967 4968 4969 4970
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
4971
- (instancetype)initWithFloats:(const float [])values
4972 4973
                       forKeys:(const int64_t [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
4974 4975 4976 4977 4978 4979 4980 4981

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
4982
- (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary;
4983 4984 4985 4986 4987 4988 4989 4990

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
4991 4992
- (instancetype)initWithCapacity:(NSUInteger)numItems;

4993 4994 4995 4996 4997 4998 4999 5000
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
5001
- (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key;
5002

5003 5004 5005 5006 5007 5008 5009 5010
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
5011
- (void)enumerateKeysAndFloatsUsingBlock:
5012 5013
    (void (^)(int64_t key, float value, BOOL *stop))block;

5014 5015 5016 5017 5018 5019
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
5020 5021
- (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary;

5022 5023 5024 5025 5026 5027
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
5028
- (void)setFloat:(float)value forKey:(int64_t)key;
5029

5030 5031 5032 5033 5034
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
5035
- (void)removeFloatForKey:(int64_t)aKey;
5036 5037 5038 5039

/**
 * Removes all entries in this dictionary.
 **/
5040 5041 5042 5043 5044 5045
- (void)removeAll;

@end

#pragma mark - Int64 -> Double

5046 5047 5048 5049 5050 5051
/**
 * Class used for map fields of <int64_t, double>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
5052 5053
@interface GPBInt64DoubleDictionary : NSObject <NSCopying>

5054
/** Number of entries stored in this dictionary. */
5055 5056
@property(nonatomic, readonly) NSUInteger count;

5057 5058 5059
/**
 * @return A newly instanced and empty dictionary.
 **/
5060
+ (instancetype)dictionary;
5061 5062 5063 5064 5065 5066 5067 5068 5069

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
5070 5071
+ (instancetype)dictionaryWithDouble:(double)value
                              forKey:(int64_t)key;
5072 5073 5074 5075 5076 5077 5078 5079 5080 5081

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
5082 5083 5084
+ (instancetype)dictionaryWithDoubles:(const double [])values
                              forKeys:(const int64_t [])keys
                                count:(NSUInteger)count;
5085 5086 5087 5088 5089 5090 5091 5092 5093 5094

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
5095
+ (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary;
5096 5097 5098 5099 5100 5101 5102 5103

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
5104 5105
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

5106 5107 5108 5109 5110 5111 5112 5113 5114
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
5115 5116 5117
- (instancetype)initWithDoubles:(const double [])values
                        forKeys:(const int64_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
5118 5119 5120 5121 5122 5123 5124 5125

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
5126
- (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary;
5127 5128 5129 5130 5131 5132 5133 5134

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
5135 5136
- (instancetype)initWithCapacity:(NSUInteger)numItems;

5137 5138 5139 5140 5141 5142 5143 5144
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
5145
- (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key;
5146

5147 5148 5149 5150 5151 5152 5153 5154
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
5155
- (void)enumerateKeysAndDoublesUsingBlock:
5156 5157
    (void (^)(int64_t key, double value, BOOL *stop))block;

5158 5159 5160 5161 5162 5163
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
5164 5165
- (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary;

5166 5167 5168 5169 5170 5171
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
5172
- (void)setDouble:(double)value forKey:(int64_t)key;
5173

5174 5175 5176 5177 5178
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
5179
- (void)removeDoubleForKey:(int64_t)aKey;
5180 5181 5182 5183

/**
 * Removes all entries in this dictionary.
 **/
5184 5185 5186 5187 5188 5189
- (void)removeAll;

@end

#pragma mark - Int64 -> Enum

5190 5191 5192 5193 5194 5195
/**
 * Class used for map fields of <int64_t, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
5196 5197
@interface GPBInt64EnumDictionary : NSObject <NSCopying>

5198
/** Number of entries stored in this dictionary. */
5199
@property(nonatomic, readonly) NSUInteger count;
5200
/** The validation function to check if the enums are valid. */
5201 5202
@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;

5203 5204 5205
/**
 * @return A newly instanced and empty dictionary.
 **/
5206
+ (instancetype)dictionary;
5207 5208 5209 5210 5211 5212 5213 5214

/**
 * Creates and initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly instanced dictionary.
 **/
5215
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
5216 5217 5218 5219 5220 5221 5222 5223 5224 5225

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param func     The enum validation function for the dictionary.
 * @param rawValue The raw enum value to be placed in the dictionary.
 * @param key      The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
5226
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
5227 5228
                                        rawValue:(int32_t)rawValue
                                          forKey:(int64_t)key;
5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
5240
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
5241 5242 5243
                                       rawValues:(const int32_t [])values
                                         forKeys:(const int64_t [])keys
                                           count:(NSUInteger)count;
5244 5245 5246 5247 5248 5249 5250 5251 5252 5253

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
5254
+ (instancetype)dictionaryWithDictionary:(GPBInt64EnumDictionary *)dictionary;
5255 5256 5257 5258 5259 5260 5261 5262 5263

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
5264
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
5265 5266
                                        capacity:(NSUInteger)numItems;

5267 5268 5269 5270 5271 5272 5273
/**
 * Initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly initialized dictionary.
 **/
5274
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285

/**
 * Initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly initialized dictionary with the keys and values in it.
 **/
5286
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
5287 5288 5289
                                 rawValues:(const int32_t [])values
                                   forKeys:(const int64_t [])keys
                                     count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
5290 5291 5292 5293 5294 5295 5296 5297 5298 5299

/**
 * Initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly initialized dictionary with the entries from the given
 *         dictionary in it.
 **/
5300
- (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary;
5301 5302 5303 5304 5305 5306 5307 5308 5309

/**
 * Initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly initialized dictionary with the given capacity.
 **/
5310
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
5311 5312 5313 5314 5315 5316
                                  capacity:(NSUInteger)numItems;

// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
// is not a valid enumerator as defined by validationFunc. If the actual value is
// desired, use "raw" version of the method.

5317 5318 5319 5320 5321 5322 5323 5324
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
5325
- (BOOL)getEnum:(nullable int32_t *)value forKey:(int64_t)key;
5326

5327 5328 5329 5330 5331 5332 5333 5334
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
5335
- (void)enumerateKeysAndEnumsUsingBlock:
5336 5337
    (void (^)(int64_t key, int32_t value, BOOL *stop))block;

5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348
/**
 * Gets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue Pointer into which the value will be set, if found.
 * @param key      Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
5349
- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(int64_t)key;
5350

5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param block The block to enumerate with.
 *   **key**:      The key for the current entry.
 *   **rawValue**: The value for the current entry
 *   **stop**:     A pointer to a boolean that when set stops the enumeration.
 **/
5362 5363 5364
- (void)enumerateKeysAndRawValuesUsingBlock:
    (void (^)(int64_t key, int32_t rawValue, BOOL *stop))block;

5365 5366 5367 5368 5369 5370 5371 5372 5373
/**
 * Adds the keys and raw enum values from another dictionary.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
5374 5375 5376 5377 5378 5379 5380
- (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary;

// If value is not a valid enumerator as defined by validationFunc, these
// methods will assert in debug, and will log in release and assign the value
// to the default value. Use the rawValue methods below to assign non enumerator
// values.

5381 5382 5383 5384 5385 5386
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
5387
- (void)setEnum:(int32_t)value forKey:(int64_t)key;
5388

5389 5390 5391 5392 5393 5394 5395 5396 5397
/**
 * Sets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue The raw enum value to set.
 * @param key      The key under which to store the raw enum value.
 **/
5398 5399
- (void)setRawValue:(int32_t)rawValue forKey:(int64_t)key;

5400 5401 5402 5403 5404
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
5405
- (void)removeEnumForKey:(int64_t)aKey;
5406 5407 5408 5409

/**
 * Removes all entries in this dictionary.
 **/
5410 5411 5412 5413 5414 5415
- (void)removeAll;

@end

#pragma mark - Int64 -> Object

5416 5417 5418 5419 5420 5421
/**
 * Class used for map fields of <int64_t, ObjectType>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
5422
@interface GPBInt64ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
5423

5424
/** Number of entries stored in this dictionary. */
5425 5426
@property(nonatomic, readonly) NSUInteger count;

5427 5428 5429
/**
 * @return A newly instanced and empty dictionary.
 **/
5430
+ (instancetype)dictionary;
5431 5432 5433 5434 5435 5436 5437 5438 5439

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param object     The value to be placed in the dictionary.
 * @param key        The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
5440
+ (instancetype)dictionaryWithObject:(ObjectType)object
5441
                              forKey:(int64_t)key;
5442 5443 5444 5445 5446 5447 5448 5449 5450 5451

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param objects      The values to be placed in the dictionary.
 * @param keys         The keys under which to store the values.
 * @param count        The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
5452
+ (instancetype)dictionaryWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects
5453 5454
                              forKeys:(const int64_t [])keys
                                count:(NSUInteger)count;
5455 5456 5457 5458 5459 5460 5461 5462 5463 5464

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
5465
+ (instancetype)dictionaryWithDictionary:(GPBInt64ObjectDictionary *)dictionary;
5466 5467 5468 5469 5470 5471 5472 5473

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
5474 5475
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

5476 5477 5478 5479 5480 5481 5482 5483 5484
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param objects      The values to be placed in this dictionary.
 * @param keys         The keys under which to store the values.
 * @param count        The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
5485
- (instancetype)initWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects
5486 5487
                        forKeys:(const int64_t [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
5488 5489 5490 5491 5492 5493 5494 5495

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
5496
- (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary;
5497 5498 5499 5500 5501 5502 5503 5504

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
5505 5506
- (instancetype)initWithCapacity:(NSUInteger)numItems;

5507 5508 5509 5510 5511 5512 5513
/**
 * Fetches the object stored under the given key.
 *
 * @param key Key under which the value is stored, if present.
 *
 * @return The object if found, nil otherwise.
 **/
5514
- (ObjectType)objectForKey:(int64_t)key;
5515

5516 5517 5518 5519 5520 5521 5522 5523
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:         The key for the current entry.
 *   **object**:      The value for the current entry
 *   **stop**:        A pointer to a boolean that when set stops the enumeration.
 **/
5524
- (void)enumerateKeysAndObjectsUsingBlock:
5525
    (void (^)(int64_t key, ObjectType object, BOOL *stop))block;
5526

5527 5528 5529 5530 5531 5532
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
5533 5534
- (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary;

5535 5536 5537 5538 5539 5540
/**
 * Sets the value for the given key.
 *
 * @param object     The value to set.
 * @param key        The key under which to store the value.
 **/
5541
- (void)setObject:(ObjectType)object forKey:(int64_t)key;
5542

5543 5544 5545 5546 5547
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
5548
- (void)removeObjectForKey:(int64_t)aKey;
5549 5550 5551 5552

/**
 * Removes all entries in this dictionary.
 **/
5553 5554 5555 5556 5557 5558
- (void)removeAll;

@end

#pragma mark - Bool -> UInt32

5559 5560 5561 5562 5563 5564
/**
 * Class used for map fields of <BOOL, uint32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
5565 5566
@interface GPBBoolUInt32Dictionary : NSObject <NSCopying>

5567
/** Number of entries stored in this dictionary. */
5568 5569
@property(nonatomic, readonly) NSUInteger count;

5570 5571 5572
/**
 * @return A newly instanced and empty dictionary.
 **/
5573
+ (instancetype)dictionary;
5574 5575 5576 5577 5578 5579 5580 5581 5582

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
5583 5584
+ (instancetype)dictionaryWithUInt32:(uint32_t)value
                              forKey:(BOOL)key;
5585 5586 5587 5588 5589 5590 5591 5592 5593 5594

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
5595 5596 5597
+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
                              forKeys:(const BOOL [])keys
                                count:(NSUInteger)count;
5598 5599 5600 5601 5602 5603 5604 5605 5606 5607

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
5608
+ (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary;
5609 5610 5611 5612 5613 5614 5615 5616

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
5617 5618
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

5619 5620 5621 5622 5623 5624 5625 5626 5627
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
5628 5629 5630
- (instancetype)initWithUInt32s:(const uint32_t [])values
                        forKeys:(const BOOL [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
5631 5632 5633 5634 5635 5636 5637 5638

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
5639
- (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary;
5640 5641 5642 5643 5644 5645 5646 5647

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
5648 5649
- (instancetype)initWithCapacity:(NSUInteger)numItems;

5650 5651 5652 5653 5654 5655 5656 5657
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
5658
- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(BOOL)key;
5659

5660 5661 5662 5663 5664 5665 5666 5667
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
5668
- (void)enumerateKeysAndUInt32sUsingBlock:
5669 5670
    (void (^)(BOOL key, uint32_t value, BOOL *stop))block;

5671 5672 5673 5674 5675 5676
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
5677 5678
- (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary;

5679 5680 5681 5682 5683 5684
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
5685
- (void)setUInt32:(uint32_t)value forKey:(BOOL)key;
5686

5687 5688 5689 5690 5691
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
5692
- (void)removeUInt32ForKey:(BOOL)aKey;
5693 5694 5695 5696

/**
 * Removes all entries in this dictionary.
 **/
5697 5698 5699 5700 5701 5702
- (void)removeAll;

@end

#pragma mark - Bool -> Int32

5703 5704 5705 5706 5707 5708
/**
 * Class used for map fields of <BOOL, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
5709 5710
@interface GPBBoolInt32Dictionary : NSObject <NSCopying>

5711
/** Number of entries stored in this dictionary. */
5712 5713
@property(nonatomic, readonly) NSUInteger count;

5714 5715 5716
/**
 * @return A newly instanced and empty dictionary.
 **/
5717
+ (instancetype)dictionary;
5718 5719 5720 5721 5722 5723 5724 5725 5726

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
5727
+ (instancetype)dictionaryWithInt32:(int32_t)value
5728
                             forKey:(BOOL)key;
5729 5730 5731 5732 5733 5734 5735 5736 5737 5738

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
5739
+ (instancetype)dictionaryWithInt32s:(const int32_t [])values
5740 5741
                             forKeys:(const BOOL [])keys
                               count:(NSUInteger)count;
5742 5743 5744 5745 5746 5747 5748 5749 5750 5751

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
5752
+ (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary;
5753 5754 5755 5756 5757 5758 5759 5760

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
5761 5762
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

5763 5764 5765 5766 5767 5768 5769 5770 5771
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
5772
- (instancetype)initWithInt32s:(const int32_t [])values
5773 5774
                       forKeys:(const BOOL [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
5775 5776 5777 5778 5779 5780 5781 5782

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
5783
- (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary;
5784 5785 5786 5787 5788 5789 5790 5791

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
5792 5793
- (instancetype)initWithCapacity:(NSUInteger)numItems;

5794 5795 5796 5797 5798 5799 5800 5801
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
5802
- (BOOL)getInt32:(nullable int32_t *)value forKey:(BOOL)key;
5803

5804 5805 5806 5807 5808 5809 5810 5811
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
5812
- (void)enumerateKeysAndInt32sUsingBlock:
5813 5814
    (void (^)(BOOL key, int32_t value, BOOL *stop))block;

5815 5816 5817 5818 5819 5820
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
5821 5822
- (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary;

5823 5824 5825 5826 5827 5828
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
5829
- (void)setInt32:(int32_t)value forKey:(BOOL)key;
5830

5831 5832 5833 5834 5835
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
5836
- (void)removeInt32ForKey:(BOOL)aKey;
5837 5838 5839 5840

/**
 * Removes all entries in this dictionary.
 **/
5841 5842 5843 5844 5845 5846
- (void)removeAll;

@end

#pragma mark - Bool -> UInt64

5847 5848 5849 5850 5851 5852
/**
 * Class used for map fields of <BOOL, uint64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
5853 5854
@interface GPBBoolUInt64Dictionary : NSObject <NSCopying>

5855
/** Number of entries stored in this dictionary. */
5856 5857
@property(nonatomic, readonly) NSUInteger count;

5858 5859 5860
/**
 * @return A newly instanced and empty dictionary.
 **/
5861
+ (instancetype)dictionary;
5862 5863 5864 5865 5866 5867 5868 5869 5870

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
5871 5872
+ (instancetype)dictionaryWithUInt64:(uint64_t)value
                              forKey:(BOOL)key;
5873 5874 5875 5876 5877 5878 5879 5880 5881 5882

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
5883 5884 5885
+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
                              forKeys:(const BOOL [])keys
                                count:(NSUInteger)count;
5886 5887 5888 5889 5890 5891 5892 5893 5894 5895

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
5896
+ (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary;
5897 5898 5899 5900 5901 5902 5903 5904

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
5905 5906
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

5907 5908 5909 5910 5911 5912 5913 5914 5915
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
5916 5917 5918
- (instancetype)initWithUInt64s:(const uint64_t [])values
                        forKeys:(const BOOL [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
5919 5920 5921 5922 5923 5924 5925 5926

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
5927
- (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary;
5928 5929 5930 5931 5932 5933 5934 5935

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
5936 5937
- (instancetype)initWithCapacity:(NSUInteger)numItems;

5938 5939 5940 5941 5942 5943 5944 5945
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
5946
- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(BOOL)key;
5947

5948 5949 5950 5951 5952 5953 5954 5955
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
5956
- (void)enumerateKeysAndUInt64sUsingBlock:
5957 5958
    (void (^)(BOOL key, uint64_t value, BOOL *stop))block;

5959 5960 5961 5962 5963 5964
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
5965 5966
- (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary;

5967 5968 5969 5970 5971 5972
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
5973
- (void)setUInt64:(uint64_t)value forKey:(BOOL)key;
5974

5975 5976 5977 5978 5979
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
5980
- (void)removeUInt64ForKey:(BOOL)aKey;
5981 5982 5983 5984

/**
 * Removes all entries in this dictionary.
 **/
5985 5986 5987 5988 5989 5990
- (void)removeAll;

@end

#pragma mark - Bool -> Int64

5991 5992 5993 5994 5995 5996
/**
 * Class used for map fields of <BOOL, int64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
5997 5998
@interface GPBBoolInt64Dictionary : NSObject <NSCopying>

5999
/** Number of entries stored in this dictionary. */
6000 6001
@property(nonatomic, readonly) NSUInteger count;

6002 6003 6004
/**
 * @return A newly instanced and empty dictionary.
 **/
6005
+ (instancetype)dictionary;
6006 6007 6008 6009 6010 6011 6012 6013 6014

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
6015
+ (instancetype)dictionaryWithInt64:(int64_t)value
6016
                             forKey:(BOOL)key;
6017 6018 6019 6020 6021 6022 6023 6024 6025 6026

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
6027
+ (instancetype)dictionaryWithInt64s:(const int64_t [])values
6028 6029
                             forKeys:(const BOOL [])keys
                               count:(NSUInteger)count;
6030 6031 6032 6033 6034 6035 6036 6037 6038 6039

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
6040
+ (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary;
6041 6042 6043 6044 6045 6046 6047 6048

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
6049 6050
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

6051 6052 6053 6054 6055 6056 6057 6058 6059
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
6060
- (instancetype)initWithInt64s:(const int64_t [])values
6061 6062
                       forKeys:(const BOOL [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
6063 6064 6065 6066 6067 6068 6069 6070

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
6071
- (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary;
6072 6073 6074 6075 6076 6077 6078 6079

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
6080 6081
- (instancetype)initWithCapacity:(NSUInteger)numItems;

6082 6083 6084 6085 6086 6087 6088 6089
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
6090
- (BOOL)getInt64:(nullable int64_t *)value forKey:(BOOL)key;
6091

6092 6093 6094 6095 6096 6097 6098 6099
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
6100
- (void)enumerateKeysAndInt64sUsingBlock:
6101 6102
    (void (^)(BOOL key, int64_t value, BOOL *stop))block;

6103 6104 6105 6106 6107 6108
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
6109 6110
- (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary;

6111 6112 6113 6114 6115 6116
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
6117
- (void)setInt64:(int64_t)value forKey:(BOOL)key;
6118

6119 6120 6121 6122 6123
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
6124
- (void)removeInt64ForKey:(BOOL)aKey;
6125 6126 6127 6128

/**
 * Removes all entries in this dictionary.
 **/
6129 6130 6131 6132 6133 6134
- (void)removeAll;

@end

#pragma mark - Bool -> Bool

6135 6136 6137 6138 6139 6140
/**
 * Class used for map fields of <BOOL, BOOL>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
6141 6142
@interface GPBBoolBoolDictionary : NSObject <NSCopying>

6143
/** Number of entries stored in this dictionary. */
6144 6145
@property(nonatomic, readonly) NSUInteger count;

6146 6147 6148
/**
 * @return A newly instanced and empty dictionary.
 **/
6149
+ (instancetype)dictionary;
6150 6151 6152 6153 6154 6155 6156 6157 6158

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
6159 6160
+ (instancetype)dictionaryWithBool:(BOOL)value
                            forKey:(BOOL)key;
6161 6162 6163 6164 6165 6166 6167 6168 6169 6170

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
6171 6172 6173
+ (instancetype)dictionaryWithBools:(const BOOL [])values
                            forKeys:(const BOOL [])keys
                              count:(NSUInteger)count;
6174 6175 6176 6177 6178 6179 6180 6181 6182 6183

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
6184
+ (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary;
6185 6186 6187 6188 6189 6190 6191 6192

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
6193 6194
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

6195 6196 6197 6198 6199 6200 6201 6202 6203
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
6204 6205 6206
- (instancetype)initWithBools:(const BOOL [])values
                      forKeys:(const BOOL [])keys
                        count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
6207 6208 6209 6210 6211 6212 6213 6214

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
6215
- (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary;
6216 6217 6218 6219 6220 6221 6222 6223

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
6224 6225
- (instancetype)initWithCapacity:(NSUInteger)numItems;

6226 6227 6228 6229 6230 6231 6232 6233
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
6234
- (BOOL)getBool:(nullable BOOL *)value forKey:(BOOL)key;
6235

6236 6237 6238 6239 6240 6241 6242 6243
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
6244
- (void)enumerateKeysAndBoolsUsingBlock:
6245 6246
    (void (^)(BOOL key, BOOL value, BOOL *stop))block;

6247 6248 6249 6250 6251 6252
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
6253 6254
- (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary;

6255 6256 6257 6258 6259 6260
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
6261
- (void)setBool:(BOOL)value forKey:(BOOL)key;
6262

6263 6264 6265 6266 6267
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
6268
- (void)removeBoolForKey:(BOOL)aKey;
6269 6270 6271 6272

/**
 * Removes all entries in this dictionary.
 **/
6273 6274 6275 6276 6277 6278
- (void)removeAll;

@end

#pragma mark - Bool -> Float

6279 6280 6281 6282 6283 6284
/**
 * Class used for map fields of <BOOL, float>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
6285 6286
@interface GPBBoolFloatDictionary : NSObject <NSCopying>

6287
/** Number of entries stored in this dictionary. */
6288 6289
@property(nonatomic, readonly) NSUInteger count;

6290 6291 6292
/**
 * @return A newly instanced and empty dictionary.
 **/
6293
+ (instancetype)dictionary;
6294 6295 6296 6297 6298 6299 6300 6301 6302

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
6303
+ (instancetype)dictionaryWithFloat:(float)value
6304
                             forKey:(BOOL)key;
6305 6306 6307 6308 6309 6310 6311 6312 6313 6314

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
6315
+ (instancetype)dictionaryWithFloats:(const float [])values
6316 6317
                             forKeys:(const BOOL [])keys
                               count:(NSUInteger)count;
6318 6319 6320 6321 6322 6323 6324 6325 6326 6327

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
6328
+ (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary;
6329 6330 6331 6332 6333 6334 6335 6336

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
6337 6338
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

6339 6340 6341 6342 6343 6344 6345 6346 6347
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
6348
- (instancetype)initWithFloats:(const float [])values
6349 6350
                       forKeys:(const BOOL [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
6351 6352 6353 6354 6355 6356 6357 6358

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
6359
- (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary;
6360 6361 6362 6363 6364 6365 6366 6367

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
6368 6369
- (instancetype)initWithCapacity:(NSUInteger)numItems;

6370 6371 6372 6373 6374 6375 6376 6377
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
6378
- (BOOL)getFloat:(nullable float *)value forKey:(BOOL)key;
6379

6380 6381 6382 6383 6384 6385 6386 6387
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
6388
- (void)enumerateKeysAndFloatsUsingBlock:
6389 6390
    (void (^)(BOOL key, float value, BOOL *stop))block;

6391 6392 6393 6394 6395 6396
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
6397 6398
- (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary;

6399 6400 6401 6402 6403 6404
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
6405
- (void)setFloat:(float)value forKey:(BOOL)key;
6406

6407 6408 6409 6410 6411
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
6412
- (void)removeFloatForKey:(BOOL)aKey;
6413 6414 6415 6416

/**
 * Removes all entries in this dictionary.
 **/
6417 6418 6419 6420 6421 6422
- (void)removeAll;

@end

#pragma mark - Bool -> Double

6423 6424 6425 6426 6427 6428
/**
 * Class used for map fields of <BOOL, double>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
6429 6430
@interface GPBBoolDoubleDictionary : NSObject <NSCopying>

6431
/** Number of entries stored in this dictionary. */
6432 6433
@property(nonatomic, readonly) NSUInteger count;

6434 6435 6436
/**
 * @return A newly instanced and empty dictionary.
 **/
6437
+ (instancetype)dictionary;
6438 6439 6440 6441 6442 6443 6444 6445 6446

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
6447 6448
+ (instancetype)dictionaryWithDouble:(double)value
                              forKey:(BOOL)key;
6449 6450 6451 6452 6453 6454 6455 6456 6457 6458

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
6459 6460 6461
+ (instancetype)dictionaryWithDoubles:(const double [])values
                              forKeys:(const BOOL [])keys
                                count:(NSUInteger)count;
6462 6463 6464 6465 6466 6467 6468 6469 6470 6471

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
6472
+ (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary;
6473 6474 6475 6476 6477 6478 6479 6480

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
6481 6482
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

6483 6484 6485 6486 6487 6488 6489 6490 6491
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
6492 6493 6494
- (instancetype)initWithDoubles:(const double [])values
                        forKeys:(const BOOL [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
6495 6496 6497 6498 6499 6500 6501 6502

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
6503
- (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary;
6504 6505 6506 6507 6508 6509 6510 6511

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
6512 6513
- (instancetype)initWithCapacity:(NSUInteger)numItems;

6514 6515 6516 6517 6518 6519 6520 6521
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
6522
- (BOOL)getDouble:(nullable double *)value forKey:(BOOL)key;
6523

6524 6525 6526 6527 6528 6529 6530 6531
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
6532
- (void)enumerateKeysAndDoublesUsingBlock:
6533 6534
    (void (^)(BOOL key, double value, BOOL *stop))block;

6535 6536 6537 6538 6539 6540
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
6541 6542
- (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary;

6543 6544 6545 6546 6547 6548
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
6549
- (void)setDouble:(double)value forKey:(BOOL)key;
6550

6551 6552 6553 6554 6555
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
6556
- (void)removeDoubleForKey:(BOOL)aKey;
6557 6558 6559 6560

/**
 * Removes all entries in this dictionary.
 **/
6561 6562 6563 6564 6565 6566
- (void)removeAll;

@end

#pragma mark - Bool -> Enum

6567 6568 6569 6570 6571 6572
/**
 * Class used for map fields of <BOOL, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
6573 6574
@interface GPBBoolEnumDictionary : NSObject <NSCopying>

6575
/** Number of entries stored in this dictionary. */
6576
@property(nonatomic, readonly) NSUInteger count;
6577
/** The validation function to check if the enums are valid. */
6578 6579
@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;

6580 6581 6582
/**
 * @return A newly instanced and empty dictionary.
 **/
6583
+ (instancetype)dictionary;
6584 6585 6586 6587 6588 6589 6590 6591

/**
 * Creates and initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly instanced dictionary.
 **/
6592
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
6593 6594 6595 6596 6597 6598 6599 6600 6601 6602

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param func     The enum validation function for the dictionary.
 * @param rawValue The raw enum value to be placed in the dictionary.
 * @param key      The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
6603
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
6604 6605
                                        rawValue:(int32_t)rawValue
                                          forKey:(BOOL)key;
6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
6617
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
6618 6619 6620
                                       rawValues:(const int32_t [])values
                                         forKeys:(const BOOL [])keys
                                           count:(NSUInteger)count;
6621 6622 6623 6624 6625 6626 6627 6628 6629 6630

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
6631
+ (instancetype)dictionaryWithDictionary:(GPBBoolEnumDictionary *)dictionary;
6632 6633 6634 6635 6636 6637 6638 6639 6640

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
6641
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
6642 6643
                                        capacity:(NSUInteger)numItems;

6644 6645 6646 6647 6648 6649 6650
/**
 * Initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly initialized dictionary.
 **/
6651
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662

/**
 * Initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly initialized dictionary with the keys and values in it.
 **/
6663
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
6664 6665 6666
                                 rawValues:(const int32_t [])values
                                   forKeys:(const BOOL [])keys
                                     count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
6667 6668 6669 6670 6671 6672 6673 6674 6675 6676

/**
 * Initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly initialized dictionary with the entries from the given
 *         dictionary in it.
 **/
6677
- (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary;
6678 6679 6680 6681 6682 6683 6684 6685 6686

/**
 * Initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly initialized dictionary with the given capacity.
 **/
6687
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
6688 6689 6690 6691 6692 6693
                                  capacity:(NSUInteger)numItems;

// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
// is not a valid enumerator as defined by validationFunc. If the actual value is
// desired, use "raw" version of the method.

6694 6695 6696 6697 6698 6699 6700 6701
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
6702
- (BOOL)getEnum:(nullable int32_t *)value forKey:(BOOL)key;
6703

6704 6705 6706 6707 6708 6709 6710 6711
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
6712
- (void)enumerateKeysAndEnumsUsingBlock:
6713 6714
    (void (^)(BOOL key, int32_t value, BOOL *stop))block;

6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725
/**
 * Gets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue Pointer into which the value will be set, if found.
 * @param key      Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
6726
- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(BOOL)key;
6727

6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param block The block to enumerate with.
 *   **key**:      The key for the current entry.
 *   **rawValue**: The value for the current entry
 *   **stop**:     A pointer to a boolean that when set stops the enumeration.
 **/
6739 6740 6741
- (void)enumerateKeysAndRawValuesUsingBlock:
    (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block;

6742 6743 6744 6745 6746 6747 6748 6749 6750
/**
 * Adds the keys and raw enum values from another dictionary.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
6751 6752 6753 6754 6755 6756 6757
- (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary;

// If value is not a valid enumerator as defined by validationFunc, these
// methods will assert in debug, and will log in release and assign the value
// to the default value. Use the rawValue methods below to assign non enumerator
// values.

6758 6759 6760 6761 6762 6763
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
6764
- (void)setEnum:(int32_t)value forKey:(BOOL)key;
6765

6766 6767 6768 6769 6770 6771 6772 6773 6774
/**
 * Sets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue The raw enum value to set.
 * @param key      The key under which to store the raw enum value.
 **/
6775 6776
- (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key;

6777 6778 6779 6780 6781
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
6782
- (void)removeEnumForKey:(BOOL)aKey;
6783 6784 6785 6786

/**
 * Removes all entries in this dictionary.
 **/
6787 6788 6789 6790 6791 6792
- (void)removeAll;

@end

#pragma mark - Bool -> Object

6793 6794 6795 6796 6797 6798
/**
 * Class used for map fields of <BOOL, ObjectType>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
6799
@interface GPBBoolObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
6800

6801
/** Number of entries stored in this dictionary. */
6802 6803
@property(nonatomic, readonly) NSUInteger count;

6804 6805 6806
/**
 * @return A newly instanced and empty dictionary.
 **/
6807
+ (instancetype)dictionary;
6808 6809 6810 6811 6812 6813 6814 6815 6816

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param object     The value to be placed in the dictionary.
 * @param key        The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
6817
+ (instancetype)dictionaryWithObject:(ObjectType)object
6818
                              forKey:(BOOL)key;
6819 6820 6821 6822 6823 6824 6825 6826 6827 6828

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param objects      The values to be placed in the dictionary.
 * @param keys         The keys under which to store the values.
 * @param count        The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
6829
+ (instancetype)dictionaryWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects
6830 6831
                              forKeys:(const BOOL [])keys
                                count:(NSUInteger)count;
6832 6833 6834 6835 6836 6837 6838 6839 6840 6841

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
6842
+ (instancetype)dictionaryWithDictionary:(GPBBoolObjectDictionary *)dictionary;
6843 6844 6845 6846 6847 6848 6849 6850

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
6851 6852
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

6853 6854 6855 6856 6857 6858 6859 6860 6861
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param objects      The values to be placed in this dictionary.
 * @param keys         The keys under which to store the values.
 * @param count        The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
6862
- (instancetype)initWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects
6863 6864
                        forKeys:(const BOOL [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
6865 6866 6867 6868 6869 6870 6871 6872

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
6873
- (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary;
6874 6875 6876 6877 6878 6879 6880 6881

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
6882 6883
- (instancetype)initWithCapacity:(NSUInteger)numItems;

6884 6885 6886 6887 6888 6889 6890
/**
 * Fetches the object stored under the given key.
 *
 * @param key Key under which the value is stored, if present.
 *
 * @return The object if found, nil otherwise.
 **/
6891
- (ObjectType)objectForKey:(BOOL)key;
6892

6893 6894 6895 6896 6897 6898 6899 6900
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:         The key for the current entry.
 *   **object**:      The value for the current entry
 *   **stop**:        A pointer to a boolean that when set stops the enumeration.
 **/
6901
- (void)enumerateKeysAndObjectsUsingBlock:
6902
    (void (^)(BOOL key, ObjectType object, BOOL *stop))block;
6903

6904 6905 6906 6907 6908 6909
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
6910 6911
- (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary;

6912 6913 6914 6915 6916 6917
/**
 * Sets the value for the given key.
 *
 * @param object     The value to set.
 * @param key        The key under which to store the value.
 **/
6918
- (void)setObject:(ObjectType)object forKey:(BOOL)key;
6919

6920 6921 6922 6923 6924
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
6925
- (void)removeObjectForKey:(BOOL)aKey;
6926 6927 6928 6929

/**
 * Removes all entries in this dictionary.
 **/
6930 6931 6932 6933 6934 6935
- (void)removeAll;

@end

#pragma mark - String -> UInt32

6936 6937 6938 6939 6940 6941
/**
 * Class used for map fields of <NSString, uint32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
6942 6943
@interface GPBStringUInt32Dictionary : NSObject <NSCopying>

6944
/** Number of entries stored in this dictionary. */
6945 6946
@property(nonatomic, readonly) NSUInteger count;

6947 6948 6949
/**
 * @return A newly instanced and empty dictionary.
 **/
6950
+ (instancetype)dictionary;
6951 6952 6953 6954 6955 6956 6957 6958 6959

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
6960 6961
+ (instancetype)dictionaryWithUInt32:(uint32_t)value
                              forKey:(NSString *)key;
6962 6963 6964 6965 6966 6967 6968 6969 6970 6971

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
6972 6973 6974
+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
                              forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                                count:(NSUInteger)count;
6975 6976 6977 6978 6979 6980 6981 6982 6983 6984

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
6985
+ (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary;
6986 6987 6988 6989 6990 6991 6992 6993

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
6994 6995
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

6996 6997 6998 6999 7000 7001 7002 7003 7004
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
7005 7006 7007
- (instancetype)initWithUInt32s:(const uint32_t [])values
                        forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
7008 7009 7010 7011 7012 7013 7014 7015

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
7016
- (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary;
7017 7018 7019 7020 7021 7022 7023 7024

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
7025 7026
- (instancetype)initWithCapacity:(NSUInteger)numItems;

7027 7028 7029 7030 7031 7032 7033 7034
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
7035
- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key;
7036

7037 7038 7039 7040 7041 7042 7043 7044
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
7045
- (void)enumerateKeysAndUInt32sUsingBlock:
7046 7047
    (void (^)(NSString *key, uint32_t value, BOOL *stop))block;

7048 7049 7050 7051 7052 7053
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
7054 7055
- (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary;

7056 7057 7058 7059 7060 7061
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
7062
- (void)setUInt32:(uint32_t)value forKey:(NSString *)key;
7063

7064 7065 7066 7067 7068
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
7069
- (void)removeUInt32ForKey:(NSString *)aKey;
7070 7071 7072 7073

/**
 * Removes all entries in this dictionary.
 **/
7074 7075 7076 7077 7078 7079
- (void)removeAll;

@end

#pragma mark - String -> Int32

7080 7081 7082 7083 7084 7085
/**
 * Class used for map fields of <NSString, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
7086 7087
@interface GPBStringInt32Dictionary : NSObject <NSCopying>

7088
/** Number of entries stored in this dictionary. */
7089 7090
@property(nonatomic, readonly) NSUInteger count;

7091 7092 7093
/**
 * @return A newly instanced and empty dictionary.
 **/
7094
+ (instancetype)dictionary;
7095 7096 7097 7098 7099 7100 7101 7102 7103

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
7104
+ (instancetype)dictionaryWithInt32:(int32_t)value
7105
                             forKey:(NSString *)key;
7106 7107 7108 7109 7110 7111 7112 7113 7114 7115

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
7116
+ (instancetype)dictionaryWithInt32s:(const int32_t [])values
7117 7118
                             forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                               count:(NSUInteger)count;
7119 7120 7121 7122 7123 7124 7125 7126 7127 7128

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
7129
+ (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary;
7130 7131 7132 7133 7134 7135 7136 7137

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
7138 7139
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

7140 7141 7142 7143 7144 7145 7146 7147 7148
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
7149
- (instancetype)initWithInt32s:(const int32_t [])values
7150 7151
                       forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
7152 7153 7154 7155 7156 7157 7158 7159

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
7160
- (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary;
7161 7162 7163 7164 7165 7166 7167 7168

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
7169 7170
- (instancetype)initWithCapacity:(NSUInteger)numItems;

7171 7172 7173 7174 7175 7176 7177 7178
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
7179
- (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key;
7180

7181 7182 7183 7184 7185 7186 7187 7188
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
7189
- (void)enumerateKeysAndInt32sUsingBlock:
7190 7191
    (void (^)(NSString *key, int32_t value, BOOL *stop))block;

7192 7193 7194 7195 7196 7197
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
7198 7199
- (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary;

7200 7201 7202 7203 7204 7205
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
7206
- (void)setInt32:(int32_t)value forKey:(NSString *)key;
7207

7208 7209 7210 7211 7212
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
7213
- (void)removeInt32ForKey:(NSString *)aKey;
7214 7215 7216 7217

/**
 * Removes all entries in this dictionary.
 **/
7218 7219 7220 7221 7222 7223
- (void)removeAll;

@end

#pragma mark - String -> UInt64

7224 7225 7226 7227 7228 7229
/**
 * Class used for map fields of <NSString, uint64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
7230 7231
@interface GPBStringUInt64Dictionary : NSObject <NSCopying>

7232
/** Number of entries stored in this dictionary. */
7233 7234
@property(nonatomic, readonly) NSUInteger count;

7235 7236 7237
/**
 * @return A newly instanced and empty dictionary.
 **/
7238
+ (instancetype)dictionary;
7239 7240 7241 7242 7243 7244 7245 7246 7247

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
7248 7249
+ (instancetype)dictionaryWithUInt64:(uint64_t)value
                              forKey:(NSString *)key;
7250 7251 7252 7253 7254 7255 7256 7257 7258 7259

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
7260 7261 7262
+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
                              forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                                count:(NSUInteger)count;
7263 7264 7265 7266 7267 7268 7269 7270 7271 7272

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
7273
+ (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary;
7274 7275 7276 7277 7278 7279 7280 7281

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
7282 7283
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

7284 7285 7286 7287 7288 7289 7290 7291 7292
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
7293 7294 7295
- (instancetype)initWithUInt64s:(const uint64_t [])values
                        forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
7296 7297 7298 7299 7300 7301 7302 7303

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
7304
- (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary;
7305 7306 7307 7308 7309 7310 7311 7312

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
7313 7314
- (instancetype)initWithCapacity:(NSUInteger)numItems;

7315 7316 7317 7318 7319 7320 7321 7322
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
7323
- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key;
7324

7325 7326 7327 7328 7329 7330 7331 7332
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
7333
- (void)enumerateKeysAndUInt64sUsingBlock:
7334 7335
    (void (^)(NSString *key, uint64_t value, BOOL *stop))block;

7336 7337 7338 7339 7340 7341
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
7342 7343
- (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary;

7344 7345 7346 7347 7348 7349
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
7350
- (void)setUInt64:(uint64_t)value forKey:(NSString *)key;
7351

7352 7353 7354 7355 7356
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
7357
- (void)removeUInt64ForKey:(NSString *)aKey;
7358 7359 7360 7361

/**
 * Removes all entries in this dictionary.
 **/
7362 7363 7364 7365 7366 7367
- (void)removeAll;

@end

#pragma mark - String -> Int64

7368 7369 7370 7371 7372 7373
/**
 * Class used for map fields of <NSString, int64_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
7374 7375
@interface GPBStringInt64Dictionary : NSObject <NSCopying>

7376
/** Number of entries stored in this dictionary. */
7377 7378
@property(nonatomic, readonly) NSUInteger count;

7379 7380 7381
/**
 * @return A newly instanced and empty dictionary.
 **/
7382
+ (instancetype)dictionary;
7383 7384 7385 7386 7387 7388 7389 7390 7391

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
7392
+ (instancetype)dictionaryWithInt64:(int64_t)value
7393
                             forKey:(NSString *)key;
7394 7395 7396 7397 7398 7399 7400 7401 7402 7403

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
7404
+ (instancetype)dictionaryWithInt64s:(const int64_t [])values
7405 7406
                             forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                               count:(NSUInteger)count;
7407 7408 7409 7410 7411 7412 7413 7414 7415 7416

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
7417
+ (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary;
7418 7419 7420 7421 7422 7423 7424 7425

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
7426 7427
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

7428 7429 7430 7431 7432 7433 7434 7435 7436
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
7437
- (instancetype)initWithInt64s:(const int64_t [])values
7438 7439
                       forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
7440 7441 7442 7443 7444 7445 7446 7447

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
7448
- (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary;
7449 7450 7451 7452 7453 7454 7455 7456

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
7457 7458
- (instancetype)initWithCapacity:(NSUInteger)numItems;

7459 7460 7461 7462 7463 7464 7465 7466
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
7467
- (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key;
7468

7469 7470 7471 7472 7473 7474 7475 7476
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
7477
- (void)enumerateKeysAndInt64sUsingBlock:
7478 7479
    (void (^)(NSString *key, int64_t value, BOOL *stop))block;

7480 7481 7482 7483 7484 7485
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
7486 7487
- (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary;

7488 7489 7490 7491 7492 7493
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
7494
- (void)setInt64:(int64_t)value forKey:(NSString *)key;
7495

7496 7497 7498 7499 7500
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
7501
- (void)removeInt64ForKey:(NSString *)aKey;
7502 7503 7504 7505

/**
 * Removes all entries in this dictionary.
 **/
7506 7507 7508 7509 7510 7511
- (void)removeAll;

@end

#pragma mark - String -> Bool

7512 7513 7514 7515 7516 7517
/**
 * Class used for map fields of <NSString, BOOL>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
7518 7519
@interface GPBStringBoolDictionary : NSObject <NSCopying>

7520
/** Number of entries stored in this dictionary. */
7521 7522
@property(nonatomic, readonly) NSUInteger count;

7523 7524 7525
/**
 * @return A newly instanced and empty dictionary.
 **/
7526
+ (instancetype)dictionary;
7527 7528 7529 7530 7531 7532 7533 7534 7535

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
7536 7537
+ (instancetype)dictionaryWithBool:(BOOL)value
                            forKey:(NSString *)key;
7538 7539 7540 7541 7542 7543 7544 7545 7546 7547

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
7548 7549 7550
+ (instancetype)dictionaryWithBools:(const BOOL [])values
                            forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                              count:(NSUInteger)count;
7551 7552 7553 7554 7555 7556 7557 7558 7559 7560

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
7561
+ (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary;
7562 7563 7564 7565 7566 7567 7568 7569

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
7570 7571
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

7572 7573 7574 7575 7576 7577 7578 7579 7580
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
7581 7582 7583
- (instancetype)initWithBools:(const BOOL [])values
                      forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                        count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
7584 7585 7586 7587 7588 7589 7590 7591

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
7592
- (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary;
7593 7594 7595 7596 7597 7598 7599 7600

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
7601 7602
- (instancetype)initWithCapacity:(NSUInteger)numItems;

7603 7604 7605 7606 7607 7608 7609 7610
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
7611
- (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key;
7612

7613 7614 7615 7616 7617 7618 7619 7620
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
7621
- (void)enumerateKeysAndBoolsUsingBlock:
7622 7623
    (void (^)(NSString *key, BOOL value, BOOL *stop))block;

7624 7625 7626 7627 7628 7629
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
7630 7631
- (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary;

7632 7633 7634 7635 7636 7637
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
7638
- (void)setBool:(BOOL)value forKey:(NSString *)key;
7639

7640 7641 7642 7643 7644
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
7645
- (void)removeBoolForKey:(NSString *)aKey;
7646 7647 7648 7649

/**
 * Removes all entries in this dictionary.
 **/
7650 7651 7652 7653 7654 7655
- (void)removeAll;

@end

#pragma mark - String -> Float

7656 7657 7658 7659 7660 7661
/**
 * Class used for map fields of <NSString, float>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
7662 7663
@interface GPBStringFloatDictionary : NSObject <NSCopying>

7664
/** Number of entries stored in this dictionary. */
7665 7666
@property(nonatomic, readonly) NSUInteger count;

7667 7668 7669
/**
 * @return A newly instanced and empty dictionary.
 **/
7670
+ (instancetype)dictionary;
7671 7672 7673 7674 7675 7676 7677 7678 7679

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
7680
+ (instancetype)dictionaryWithFloat:(float)value
7681
                             forKey:(NSString *)key;
7682 7683 7684 7685 7686 7687 7688 7689 7690 7691

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
7692
+ (instancetype)dictionaryWithFloats:(const float [])values
7693 7694
                             forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                               count:(NSUInteger)count;
7695 7696 7697 7698 7699 7700 7701 7702 7703 7704

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
7705
+ (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary;
7706 7707 7708 7709 7710 7711 7712 7713

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
7714 7715
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

7716 7717 7718 7719 7720 7721 7722 7723 7724
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
7725
- (instancetype)initWithFloats:(const float [])values
7726 7727
                       forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                         count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
7728 7729 7730 7731 7732 7733 7734 7735

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
7736
- (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary;
7737 7738 7739 7740 7741 7742 7743 7744

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
7745 7746
- (instancetype)initWithCapacity:(NSUInteger)numItems;

7747 7748 7749 7750 7751 7752 7753 7754
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
7755
- (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key;
7756

7757 7758 7759 7760 7761 7762 7763 7764
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
7765
- (void)enumerateKeysAndFloatsUsingBlock:
7766 7767
    (void (^)(NSString *key, float value, BOOL *stop))block;

7768 7769 7770 7771 7772 7773
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
7774 7775
- (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary;

7776 7777 7778 7779 7780 7781
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
7782
- (void)setFloat:(float)value forKey:(NSString *)key;
7783

7784 7785 7786 7787 7788
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
7789
- (void)removeFloatForKey:(NSString *)aKey;
7790 7791 7792 7793

/**
 * Removes all entries in this dictionary.
 **/
7794 7795 7796 7797 7798 7799
- (void)removeAll;

@end

#pragma mark - String -> Double

7800 7801 7802 7803 7804 7805
/**
 * Class used for map fields of <NSString, double>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
7806 7807
@interface GPBStringDoubleDictionary : NSObject <NSCopying>

7808
/** Number of entries stored in this dictionary. */
7809 7810
@property(nonatomic, readonly) NSUInteger count;

7811 7812 7813
/**
 * @return A newly instanced and empty dictionary.
 **/
7814
+ (instancetype)dictionary;
7815 7816 7817 7818 7819 7820 7821 7822 7823

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param value     The value to be placed in the dictionary.
 * @param key       The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
7824 7825
+ (instancetype)dictionaryWithDouble:(double)value
                              forKey:(NSString *)key;
7826 7827 7828 7829 7830 7831 7832 7833 7834 7835

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param values      The values to be placed in the dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
7836 7837 7838
+ (instancetype)dictionaryWithDoubles:(const double [])values
                              forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                                count:(NSUInteger)count;
7839 7840 7841 7842 7843 7844 7845 7846 7847 7848

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
7849
+ (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary;
7850 7851 7852 7853 7854 7855 7856 7857

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
7858 7859
+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;

7860 7861 7862 7863 7864 7865 7866 7867 7868
/**
 * Initializes this dictionary, copying the given values and keys.
 *
 * @param values      The values to be placed in this dictionary.
 * @param keys        The keys under which to store the values.
 * @param count       The number of elements to copy into the dictionary.
 *
 * @return A newly initialized dictionary with a copy of the values and keys.
 **/
7869 7870 7871
- (instancetype)initWithDoubles:(const double [])values
                        forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                          count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
7872 7873 7874 7875 7876 7877 7878 7879

/**
 * Initializes this dictionary, copying the entries from the given dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to this dictionary.
 *
 * @return A newly initialized dictionary with the entries of the given dictionary.
 **/
7880
- (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary;
7881 7882 7883 7884 7885 7886 7887 7888

/**
 * Initializes this dictionary with the requested capacity.
 *
 * @param numItems Number of items needed for this dictionary.
 *
 * @return A newly initialized dictionary with the requested capacity.
 **/
7889 7890
- (instancetype)initWithCapacity:(NSUInteger)numItems;

7891 7892 7893 7894 7895 7896 7897 7898
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
7899
- (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key;
7900

7901 7902 7903 7904 7905 7906 7907 7908
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
7909
- (void)enumerateKeysAndDoublesUsingBlock:
7910 7911
    (void (^)(NSString *key, double value, BOOL *stop))block;

7912 7913 7914 7915 7916 7917
/**
 * Adds the keys and values from another dictionary.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
7918 7919
- (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary;

7920 7921 7922 7923 7924 7925
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
7926
- (void)setDouble:(double)value forKey:(NSString *)key;
7927

7928 7929 7930 7931 7932
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
7933
- (void)removeDoubleForKey:(NSString *)aKey;
7934 7935 7936 7937

/**
 * Removes all entries in this dictionary.
 **/
7938 7939 7940 7941 7942 7943
- (void)removeAll;

@end

#pragma mark - String -> Enum

7944 7945 7946 7947 7948 7949
/**
 * Class used for map fields of <NSString, int32_t>
 * values. This performs better than boxing into NSNumbers in NSDictionaries.
 *
 * @note This class is not meant to be subclassed.
 **/
7950 7951
@interface GPBStringEnumDictionary : NSObject <NSCopying>

7952
/** Number of entries stored in this dictionary. */
7953
@property(nonatomic, readonly) NSUInteger count;
7954
/** The validation function to check if the enums are valid. */
7955 7956
@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;

7957 7958 7959
/**
 * @return A newly instanced and empty dictionary.
 **/
7960
+ (instancetype)dictionary;
7961 7962 7963 7964 7965 7966 7967 7968

/**
 * Creates and initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly instanced dictionary.
 **/
7969
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
7970 7971 7972 7973 7974 7975 7976 7977 7978 7979

/**
 * Creates and initializes a dictionary with the single entry given.
 *
 * @param func     The enum validation function for the dictionary.
 * @param rawValue The raw enum value to be placed in the dictionary.
 * @param key      The key under which to store the value.
 *
 * @return A newly instanced dictionary with the key and value in it.
 **/
7980
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
7981 7982
                                        rawValue:(int32_t)rawValue
                                          forKey:(NSString *)key;
7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993

/**
 * Creates and initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly instanced dictionary with the keys and values in it.
 **/
7994
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
7995 7996 7997
                                       rawValues:(const int32_t [])values
                                         forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                                           count:(NSUInteger)count;
7998 7999 8000 8001 8002 8003 8004 8005 8006 8007

/**
 * Creates and initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly instanced dictionary with the entries from the given
 *         dictionary in it.
 **/
8008
+ (instancetype)dictionaryWithDictionary:(GPBStringEnumDictionary *)dictionary;
8009 8010 8011 8012 8013 8014 8015 8016 8017

/**
 * Creates and initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly instanced dictionary with the given capacity.
 **/
8018
+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
8019 8020
                                        capacity:(NSUInteger)numItems;

8021 8022 8023 8024 8025 8026 8027
/**
 * Initializes a dictionary with the given validation function.
 *
 * @param func The enum validation function for the dictionary.
 *
 * @return A newly initialized dictionary.
 **/
8028
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039

/**
 * Initializes a dictionary with the entries given.
 *
 * @param func   The enum validation function for the dictionary.
 * @param values The raw enum values values to be placed in the dictionary.
 * @param keys   The keys under which to store the values.
 * @param count  The number of entries to store in the dictionary.
 *
 * @return A newly initialized dictionary with the keys and values in it.
 **/
8040
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
8041 8042 8043
                                 rawValues:(const int32_t [])values
                                   forKeys:(const NSString * GPB_UNSAFE_UNRETAINED [])keys
                                     count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
8044 8045 8046 8047 8048 8049 8050 8051 8052 8053

/**
 * Initializes a dictionary with the entries from the given.
 * dictionary.
 *
 * @param dictionary Dictionary containing the entries to add to the dictionary.
 *
 * @return A newly initialized dictionary with the entries from the given
 *         dictionary in it.
 **/
8054
- (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary;
8055 8056 8057 8058 8059 8060 8061 8062 8063

/**
 * Initializes a dictionary with the given capacity.
 *
 * @param func     The enum validation function for the dictionary.
 * @param numItems Capacity needed for the dictionary.
 *
 * @return A newly initialized dictionary with the given capacity.
 **/
8064
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
8065 8066 8067 8068 8069 8070
                                  capacity:(NSUInteger)numItems;

// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
// is not a valid enumerator as defined by validationFunc. If the actual value is
// desired, use "raw" version of the method.

8071 8072 8073 8074 8075 8076 8077 8078
/**
 * Gets the value for the given key.
 *
 * @param value Pointer into which the value will be set, if found.
 * @param key   Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
8079
- (BOOL)getEnum:(nullable int32_t *)value forKey:(NSString *)key;
8080

8081 8082 8083 8084 8085 8086 8087 8088
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @param block The block to enumerate with.
 *   **key**:        The key for the current entry.
 *   **value**:      The value for the current entry
 *   **stop**:       A pointer to a boolean that when set stops the enumeration.
 **/
8089
- (void)enumerateKeysAndEnumsUsingBlock:
8090 8091
    (void (^)(NSString *key, int32_t value, BOOL *stop))block;

8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102
/**
 * Gets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue Pointer into which the value will be set, if found.
 * @param key      Key under which the value is stored, if present.
 *
 * @return YES if the key was found and the value was copied, NO otherwise.
 **/
8103
- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(NSString *)key;
8104

8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115
/**
 * Enumerates the keys and values on this dictionary with the given block.
 *
 * @note This method bypass the validationFunc to enable the access of values that
 *       were not known at the time the binary was compiled.
 *
 * @param block The block to enumerate with.
 *   **key**:      The key for the current entry.
 *   **rawValue**: The value for the current entry
 *   **stop**:     A pointer to a boolean that when set stops the enumeration.
 **/
8116 8117 8118
- (void)enumerateKeysAndRawValuesUsingBlock:
    (void (^)(NSString *key, int32_t rawValue, BOOL *stop))block;

8119 8120 8121 8122 8123 8124 8125 8126 8127
/**
 * Adds the keys and raw enum values from another dictionary.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param otherDictionary Dictionary containing entries to be added to this
 *                        dictionary.
 **/
8128 8129 8130 8131 8132 8133 8134
- (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary;

// If value is not a valid enumerator as defined by validationFunc, these
// methods will assert in debug, and will log in release and assign the value
// to the default value. Use the rawValue methods below to assign non enumerator
// values.

8135 8136 8137 8138 8139 8140
/**
 * Sets the value for the given key.
 *
 * @param value     The value to set.
 * @param key       The key under which to store the value.
 **/
8141
- (void)setEnum:(int32_t)value forKey:(NSString *)key;
8142

8143 8144 8145 8146 8147 8148 8149 8150 8151
/**
 * Sets the raw enum value for the given key.
 *
 * @note This method bypass the validationFunc to enable the setting of values that
 *       were not known at the time the binary was compiled.
 *
 * @param rawValue The raw enum value to set.
 * @param key      The key under which to store the raw enum value.
 **/
8152 8153
- (void)setRawValue:(int32_t)rawValue forKey:(NSString *)key;

8154 8155 8156 8157 8158
/**
 * Removes the entry for the given key.
 *
 * @param aKey Key to be removed from this dictionary.
 **/
8159
- (void)removeEnumForKey:(NSString *)aKey;
8160 8161 8162 8163

/**
 * Removes all entries in this dictionary.
 **/
8164 8165 8166 8167 8168 8169
- (void)removeAll;

@end

//%PDDM-EXPAND-END DECLARE_DICTIONARIES()

8170 8171
NS_ASSUME_NONNULL_END

8172 8173 8174 8175 8176 8177 8178 8179 8180
//%PDDM-DEFINE DECLARE_DICTIONARIES()
//%DICTIONARY_INTERFACES_FOR_POD_KEY(UInt32, uint32_t)
//%DICTIONARY_INTERFACES_FOR_POD_KEY(Int32, int32_t)
//%DICTIONARY_INTERFACES_FOR_POD_KEY(UInt64, uint64_t)
//%DICTIONARY_INTERFACES_FOR_POD_KEY(Int64, int64_t)
//%DICTIONARY_INTERFACES_FOR_POD_KEY(Bool, BOOL)
//%DICTIONARY_POD_INTERFACES_FOR_KEY(String, NSString, *, OBJECT)
//%PDDM-DEFINE DICTIONARY_INTERFACES_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
//%DICTIONARY_POD_INTERFACES_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
8181
//%DICTIONARY_POD_KEY_TO_OBJECT_INTERFACE(KEY_NAME, KEY_TYPE, Object, ObjectType)
8182 8183 8184 8185 8186 8187 8188 8189 8190 8191
//%PDDM-DEFINE DICTIONARY_POD_INTERFACES_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, UInt32, uint32_t)
//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Int32, int32_t)
//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, UInt64, uint64_t)
//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Int64, int64_t)
//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Bool, BOOL)
//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Float, float)
//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Double, double)
//%DICTIONARY_KEY_TO_ENUM_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Enum, int32_t)
//%PDDM-DEFINE DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE)
8192
//%DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
8193
//%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_INTERFACE(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
8194 8195
//%DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, , POD, VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
//%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_TYPE, VNAME)
8196 8197 8198 8199 8200 8201 8202 8203
//%/**
//% * Gets the value for the given key.
//% * 
//% * @param value Pointer into which the value will be set, if found.
//% * @param key   Key under which the value is stored, if present.
//% * 
//% * @return YES if the key was found and the value was copied, NO otherwise.
//% **/
8204 8205
//%- (BOOL)get##VNAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key;
//%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_TYPE, VNAME)
8206 8207 8208 8209 8210 8211 8212
//%/**
//% * Fetches the object stored under the given key.
//% * 
//% * @param key Key under which the value is stored, if present.
//% * 
//% * @return The object if found, nil otherwise.
//% **/
8213
//%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key;
8214 8215
//%PDDM-DEFINE VALUE_FOR_KEY_Enum(KEY_TYPE, VALUE_TYPE, VNAME)
//%VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_TYPE, VNAME)
8216 8217 8218 8219 8220 8221
//%PDDM-DEFINE ARRAY_ARG_MODIFIERPOD()
// Nothing
//%PDDM-DEFINE ARRAY_ARG_MODIFIEREnum()
// Nothing
//%PDDM-DEFINE ARRAY_ARG_MODIFIEROBJECT()
//%GPB_UNSAFE_UNRETAINED ##
8222 8223 8224 8225 8226 8227
//%PDDM-DEFINE DICTIONARY_CLASS_DECLPOD(KEY_NAME, VALUE_NAME, VALUE_TYPE)
//%GPB##KEY_NAME##VALUE_NAME##Dictionary
//%PDDM-DEFINE DICTIONARY_CLASS_DECLEnum(KEY_NAME, VALUE_NAME, VALUE_TYPE)
//%GPB##KEY_NAME##VALUE_NAME##Dictionary
//%PDDM-DEFINE DICTIONARY_CLASS_DECLOBJECT(KEY_NAME, VALUE_NAME, VALUE_TYPE)
//%GPB##KEY_NAME##VALUE_NAME##Dictionary<__covariant VALUE_TYPE>
8228
//%PDDM-DEFINE DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
8229 8230
//%#pragma mark - KEY_NAME -> VALUE_NAME
//%
8231 8232 8233 8234 8235 8236
//%/**
//% * Class used for map fields of <##KEY_TYPE##, ##VALUE_TYPE##>
//% * values. This performs better than boxing into NSNumbers in NSDictionaries.
//% * 
//% * @note This class is not meant to be subclassed.
//% **/
8237
//%@interface DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) : NSObject <NSCopying>
8238
//%
8239
//%/** Number of entries stored in this dictionary. */
8240 8241
//%@property(nonatomic, readonly) NSUInteger count;
//%
8242 8243 8244
//%/**
//% * @return A newly instanced and empty dictionary.
//% **/
8245
//%+ (instancetype)dictionary;
8246 8247 8248 8249 8250 8251 8252 8253 8254
//%
//%/**
//% * Creates and initializes a dictionary with the single entry given.
//% * 
//% * @param ##VNAME_VAR     The value to be placed in the dictionary.
//% * @param key ##VNAME_VAR$S## The key under which to store the value.
//% * 
//% * @return A newly instanced dictionary with the key and value in it.
//% **/
8255
//%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)##VNAME_VAR
8256
//%                       ##VNAME$S## forKey:(KEY_TYPE##KisP$S##KisP)key;
8257 8258 8259 8260 8261 8262 8263 8264 8265 8266
//%
//%/**
//% * Creates and initializes a dictionary with the entries given.
//% * 
//% * @param ##VNAME_VAR##s      The values to be placed in the dictionary.
//% * @param keys ##VNAME_VAR$S##  The keys under which to store the values.
//% * @param count ##VNAME_VAR$S## The number of entries to store in the dictionary.
//% * 
//% * @return A newly instanced dictionary with the keys and values in it.
//% **/
8267
//%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[])##VNAME_VAR##s
8268 8269
//%                      ##VNAME$S##  forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[])keys
//%                      ##VNAME$S##    count:(NSUInteger)count;
8270 8271 8272 8273 8274 8275 8276 8277 8278 8279
//%
//%/**
//% * Creates and initializes a dictionary with the entries from the given.
//% * dictionary.
//% * 
//% * @param dictionary Dictionary containing the entries to add to the dictionary.
//% * 
//% * @return A newly instanced dictionary with the entries from the given
//% *         dictionary in it.
//% **/
8280
//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
8281 8282 8283 8284 8285 8286 8287 8288
//%
//%/**
//% * Creates and initializes a dictionary with the given capacity.
//% * 
//% * @param numItems Capacity needed for the dictionary.
//% * 
//% * @return A newly instanced dictionary with the given capacity.
//% **/
8289 8290
//%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
//%
8291 8292 8293 8294 8295 8296 8297 8298 8299
//%/**
//% * Initializes this dictionary, copying the given values and keys.
//% * 
//% * @param ##VNAME_VAR##s      The values to be placed in this dictionary.
//% * @param keys ##VNAME_VAR$S##  The keys under which to store the values.
//% * @param count ##VNAME_VAR$S## The number of elements to copy into the dictionary.
//% * 
//% * @return A newly initialized dictionary with a copy of the values and keys.
//% **/
8300
//%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[])##VNAME_VAR##s
8301 8302
//%                ##VNAME$S##  forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[])keys
//%                ##VNAME$S##    count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
8303 8304 8305 8306 8307 8308 8309 8310
//%
//%/**
//% * Initializes this dictionary, copying the entries from the given dictionary.
//% * 
//% * @param dictionary Dictionary containing the entries to add to this dictionary.
//% * 
//% * @return A newly initialized dictionary with the entries of the given dictionary.
//% **/
8311
//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
8312 8313 8314 8315 8316 8317 8318 8319
//%
//%/**
//% * Initializes this dictionary with the requested capacity.
//% * 
//% * @param numItems Number of items needed for this dictionary.
//% * 
//% * @return A newly initialized dictionary with the requested capacity.
//% **/
8320 8321
//%- (instancetype)initWithCapacity:(NSUInteger)numItems;
//%
8322
//%DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
8323
//%
8324 8325 8326 8327 8328 8329
//%/**
//% * Adds the keys and values from another dictionary.
//% * 
//% * @param otherDictionary Dictionary containing entries to be added to this
//% *                        dictionary.
//% **/
8330 8331
//%- (void)addEntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary;
//%
8332
//%DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
8333 8334 8335 8336 8337 8338 8339 8340 8341
//%
//%@end
//%

//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE)
//%DICTIONARY_KEY_TO_ENUM_INTERFACE2(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, Enum)
//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_INTERFACE2(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, VHELPER)
//%#pragma mark - KEY_NAME -> VALUE_NAME
//%
8342 8343 8344 8345 8346 8347
//%/**
//% * Class used for map fields of <##KEY_TYPE##, ##VALUE_TYPE##>
//% * values. This performs better than boxing into NSNumbers in NSDictionaries.
//% * 
//% * @note This class is not meant to be subclassed.
//% **/
8348 8349
//%@interface GPB##KEY_NAME##VALUE_NAME##Dictionary : NSObject <NSCopying>
//%
8350
//%/** Number of entries stored in this dictionary. */
8351
//%@property(nonatomic, readonly) NSUInteger count;
8352
//%/** The validation function to check if the enums are valid. */
8353 8354
//%@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
//%
8355 8356 8357
//%/**
//% * @return A newly instanced and empty dictionary.
//% **/
8358
//%+ (instancetype)dictionary;
8359 8360 8361 8362 8363 8364 8365 8366
//%
//%/**
//% * Creates and initializes a dictionary with the given validation function.
//% * 
//% * @param func The enum validation function for the dictionary.
//% * 
//% * @return A newly instanced dictionary.
//% **/
8367
//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
8368 8369 8370 8371 8372 8373 8374 8375 8376 8377
//%
//%/**
//% * Creates and initializes a dictionary with the single entry given.
//% * 
//% * @param func     The enum validation function for the dictionary.
//% * @param rawValue The raw enum value to be placed in the dictionary.
//% * @param key      The key under which to store the value.
//% * 
//% * @return A newly instanced dictionary with the key and value in it.
//% **/
8378
//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
8379 8380
//%                                        rawValue:(VALUE_TYPE)rawValue
//%                                          forKey:(KEY_TYPE##KisP$S##KisP)key;
8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391
//%
//%/**
//% * Creates and initializes a dictionary with the entries given.
//% * 
//% * @param func   The enum validation function for the dictionary.
//% * @param values The raw enum values values to be placed in the dictionary.
//% * @param keys   The keys under which to store the values.
//% * @param count  The number of entries to store in the dictionary.
//% * 
//% * @return A newly instanced dictionary with the keys and values in it.
//% **/
8392
//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
8393 8394 8395
//%                                       rawValues:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[])values
//%                                         forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[])keys
//%                                           count:(NSUInteger)count;
8396 8397 8398 8399 8400 8401 8402 8403 8404 8405
//%
//%/**
//% * Creates and initializes a dictionary with the entries from the given.
//% * dictionary.
//% * 
//% * @param dictionary Dictionary containing the entries to add to the dictionary.
//% * 
//% * @return A newly instanced dictionary with the entries from the given
//% *         dictionary in it.
//% **/
8406
//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
8407 8408 8409 8410 8411 8412 8413 8414 8415
//%
//%/**
//% * Creates and initializes a dictionary with the given capacity.
//% * 
//% * @param func     The enum validation function for the dictionary.
//% * @param numItems Capacity needed for the dictionary.
//% * 
//% * @return A newly instanced dictionary with the given capacity.
//% **/
8416
//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
8417 8418
//%                                        capacity:(NSUInteger)numItems;
//%
8419 8420 8421 8422 8423 8424 8425
//%/**
//% * Initializes a dictionary with the given validation function.
//% * 
//% * @param func The enum validation function for the dictionary.
//% * 
//% * @return A newly initialized dictionary.
//% **/
8426
//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437
//%
//%/**
//% * Initializes a dictionary with the entries given.
//% * 
//% * @param func   The enum validation function for the dictionary.
//% * @param values The raw enum values values to be placed in the dictionary.
//% * @param keys   The keys under which to store the values.
//% * @param count  The number of entries to store in the dictionary.
//% * 
//% * @return A newly initialized dictionary with the keys and values in it.
//% **/
8438
//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
8439 8440 8441
//%                                 rawValues:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[])values
//%                                   forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[])keys
//%                                     count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
8442 8443 8444 8445 8446 8447 8448 8449 8450 8451
//%
//%/**
//% * Initializes a dictionary with the entries from the given.
//% * dictionary.
//% * 
//% * @param dictionary Dictionary containing the entries to add to the dictionary.
//% * 
//% * @return A newly initialized dictionary with the entries from the given
//% *         dictionary in it.
//% **/
8452
//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
8453 8454 8455 8456 8457 8458 8459 8460 8461
//%
//%/**
//% * Initializes a dictionary with the given capacity.
//% * 
//% * @param func     The enum validation function for the dictionary.
//% * @param numItems Capacity needed for the dictionary.
//% * 
//% * @return A newly initialized dictionary with the given capacity.
//% **/
8462
//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
8463 8464 8465 8466 8467 8468
//%                                  capacity:(NSUInteger)numItems;
//%
//%// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
//%// is not a valid enumerator as defined by validationFunc. If the actual value is
//%// desired, use "raw" version of the method.
//%
8469
//%DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, Enum, value)
8470
//%
8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481
//%/**
//% * Gets the raw enum value for the given key.
//% * 
//% * @note This method bypass the validationFunc to enable the access of values that
//% *       were not known at the time the binary was compiled.
//% * 
//% * @param rawValue Pointer into which the value will be set, if found.
//% * @param key      Key under which the value is stored, if present.
//% * 
//% * @return YES if the key was found and the value was copied, NO otherwise.
//% **/
8482
//%- (BOOL)getRawValue:(nullable VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key;
8483
//%
8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494
//%/**
//% * Enumerates the keys and values on this dictionary with the given block.
//% * 
//% * @note This method bypass the validationFunc to enable the access of values that
//% *       were not known at the time the binary was compiled.
//% * 
//% * @param block The block to enumerate with.
//% *   **key**:      The key for the current entry.
//% *   **rawValue**: The value for the current entry
//% *   **stop**:     A pointer to a boolean that when set stops the enumeration.
//% **/
8495 8496 8497
//%- (void)enumerateKeysAndRawValuesUsingBlock:
//%    (void (^)(KEY_TYPE KisP##key, VALUE_TYPE rawValue, BOOL *stop))block;
//%
8498 8499 8500 8501 8502 8503 8504 8505 8506
//%/**
//% * Adds the keys and raw enum values from another dictionary.
//% * 
//% * @note This method bypass the validationFunc to enable the setting of values that
//% *       were not known at the time the binary was compiled.
//% * 
//% * @param otherDictionary Dictionary containing entries to be added to this
//% *                        dictionary.
//% **/
8507 8508 8509 8510 8511 8512 8513
//%- (void)addRawEntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary;
//%
//%// If value is not a valid enumerator as defined by validationFunc, these
//%// methods will assert in debug, and will log in release and assign the value
//%// to the default value. Use the rawValue methods below to assign non enumerator
//%// values.
//%
8514
//%DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, Enum, value)
8515 8516 8517 8518
//%
//%@end
//%

8519 8520
//%PDDM-DEFINE DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
//%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_TYPE, VNAME)
8521
//%
8522 8523 8524 8525 8526 8527 8528 8529
//%/**
//% * Enumerates the keys and values on this dictionary with the given block.
//% * 
//% * @param block The block to enumerate with.
//% *   **key**: ##VNAME_VAR$S##  The key for the current entry.
//% *   **VNAME_VAR**:      The value for the current entry
//% *   **stop**: ##VNAME_VAR$S## A pointer to a boolean that when set stops the enumeration.
//% **/
8530 8531
//%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
//%    (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block;
8532

8533
//%PDDM-DEFINE DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
8534 8535 8536 8537 8538 8539
//%/**
//% * Sets the value for the given key.
//% * 
//% * @param ##VNAME_VAR     The value to set.
//% * @param key ##VNAME_VAR$S## The key under which to store the value.
//% **/
8540
//%- (void)set##VNAME##:(VALUE_TYPE)##VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key;
8541
//%DICTIONARY_EXTRA_MUTABLE_METHODS_##VHELPER(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
8542 8543 8544 8545 8546
//%/**
//% * Removes the entry for the given key.
//% * 
//% * @param aKey Key to be removed from this dictionary.
//% **/
8547
//%- (void)remove##VNAME##ForKey:(KEY_TYPE##KisP$S##KisP)aKey;
8548 8549 8550 8551
//%
//%/**
//% * Removes all entries in this dictionary.
//% **/
8552 8553 8554 8555 8556 8557 8558 8559
//%- (void)removeAll;

//%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_POD(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
// Empty
//%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_OBJECT(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
// Empty
//%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_Enum(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
//%
8560 8561 8562 8563 8564 8565 8566 8567 8568
//%/**
//% * Sets the raw enum value for the given key.
//% * 
//% * @note This method bypass the validationFunc to enable the setting of values that
//% *       were not known at the time the binary was compiled.
//% * 
//% * @param rawValue The raw enum value to set.
//% * @param key      The key under which to store the raw enum value.
//% **/
8569 8570
//%- (void)setRawValue:(VALUE_TYPE)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key;
//%