You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8570 lines
282 KiB

6 years ago
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #import <Foundation/Foundation.h>
  31. #import "GPBRuntimeTypes.h"
  32. // Note on naming: for the classes holding numeric values, a more natural
  33. // naming of the method might be things like "-valueForKey:",
  34. // "-setValue:forKey:"; etc. But those selectors are also defined by Key Value
  35. // Coding (KVC) as categories on NSObject. So "overloading" the selectors with
  36. // other meanings can cause warnings (based on compiler settings), but more
  37. // importantly, some of those selector get called as KVC breaks up keypaths.
  38. // So if those selectors are used, using KVC will compile cleanly, but could
  39. // crash as it invokes those selectors with the wrong types of arguments.
  40. NS_ASSUME_NONNULL_BEGIN
  41. //%PDDM-EXPAND DECLARE_DICTIONARIES()
  42. // This block of code is generated, do not edit it directly.
  43. #pragma mark - UInt32 -> UInt32
  44. /**
  45. * Class used for map fields of <uint32_t, uint32_t>
  46. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  47. *
  48. * @note This class is not meant to be subclassed.
  49. **/
  50. @interface GPBUInt32UInt32Dictionary : NSObject <NSCopying>
  51. /** Number of entries stored in this dictionary. */
  52. @property(nonatomic, readonly) NSUInteger count;
  53. /**
  54. * @return A newly instanced and empty dictionary.
  55. **/
  56. + (instancetype)dictionary;
  57. /**
  58. * Creates and initializes a dictionary with the single entry given.
  59. *
  60. * @param value The value to be placed in the dictionary.
  61. * @param key The key under which to store the value.
  62. *
  63. * @return A newly instanced dictionary with the key and value in it.
  64. **/
  65. + (instancetype)dictionaryWithUInt32:(uint32_t)value
  66. forKey:(uint32_t)key;
  67. /**
  68. * Creates and initializes a dictionary with the entries given.
  69. *
  70. * @param values The values to be placed in the dictionary.
  71. * @param keys The keys under which to store the values.
  72. * @param count The number of entries to store in the dictionary.
  73. *
  74. * @return A newly instanced dictionary with the keys and values in it.
  75. **/
  76. + (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
  77. forKeys:(const uint32_t [__nullable])keys
  78. count:(NSUInteger)count;
  79. /**
  80. * Creates and initializes a dictionary with the entries from the given.
  81. * dictionary.
  82. *
  83. * @param dictionary Dictionary containing the entries to add to the dictionary.
  84. *
  85. * @return A newly instanced dictionary with the entries from the given
  86. * dictionary in it.
  87. **/
  88. + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary;
  89. /**
  90. * Creates and initializes a dictionary with the given capacity.
  91. *
  92. * @param numItems Capacity needed for the dictionary.
  93. *
  94. * @return A newly instanced dictionary with the given capacity.
  95. **/
  96. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  97. /**
  98. * Initializes this dictionary, copying the given values and keys.
  99. *
  100. * @param values The values to be placed in this dictionary.
  101. * @param keys The keys under which to store the values.
  102. * @param count The number of elements to copy into the dictionary.
  103. *
  104. * @return A newly initialized dictionary with a copy of the values and keys.
  105. **/
  106. - (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
  107. forKeys:(const uint32_t [__nullable])keys
  108. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  109. /**
  110. * Initializes this dictionary, copying the entries from the given dictionary.
  111. *
  112. * @param dictionary Dictionary containing the entries to add to this dictionary.
  113. *
  114. * @return A newly initialized dictionary with the entries of the given dictionary.
  115. **/
  116. - (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary;
  117. /**
  118. * Initializes this dictionary with the requested capacity.
  119. *
  120. * @param numItems Number of items needed for this dictionary.
  121. *
  122. * @return A newly initialized dictionary with the requested capacity.
  123. **/
  124. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  125. /**
  126. * Gets the value for the given key.
  127. *
  128. * @param value Pointer into which the value will be set, if found.
  129. * @param key Key under which the value is stored, if present.
  130. *
  131. * @return YES if the key was found and the value was copied, NO otherwise.
  132. **/
  133. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key;
  134. /**
  135. * Enumerates the keys and values on this dictionary with the given block.
  136. *
  137. * @param block The block to enumerate with.
  138. * **key**: The key for the current entry.
  139. * **value**: The value for the current entry
  140. * **stop**: A pointer to a boolean that when set stops the enumeration.
  141. **/
  142. - (void)enumerateKeysAndUInt32sUsingBlock:
  143. (void (^)(uint32_t key, uint32_t value, BOOL *stop))block;
  144. /**
  145. * Adds the keys and values from another dictionary.
  146. *
  147. * @param otherDictionary Dictionary containing entries to be added to this
  148. * dictionary.
  149. **/
  150. - (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary;
  151. /**
  152. * Sets the value for the given key.
  153. *
  154. * @param value The value to set.
  155. * @param key The key under which to store the value.
  156. **/
  157. - (void)setUInt32:(uint32_t)value forKey:(uint32_t)key;
  158. /**
  159. * Removes the entry for the given key.
  160. *
  161. * @param aKey Key to be removed from this dictionary.
  162. **/
  163. - (void)removeUInt32ForKey:(uint32_t)aKey;
  164. /**
  165. * Removes all entries in this dictionary.
  166. **/
  167. - (void)removeAll;
  168. @end
  169. #pragma mark - UInt32 -> Int32
  170. /**
  171. * Class used for map fields of <uint32_t, int32_t>
  172. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  173. *
  174. * @note This class is not meant to be subclassed.
  175. **/
  176. @interface GPBUInt32Int32Dictionary : NSObject <NSCopying>
  177. /** Number of entries stored in this dictionary. */
  178. @property(nonatomic, readonly) NSUInteger count;
  179. /**
  180. * @return A newly instanced and empty dictionary.
  181. **/
  182. + (instancetype)dictionary;
  183. /**
  184. * Creates and initializes a dictionary with the single entry given.
  185. *
  186. * @param value The value to be placed in the dictionary.
  187. * @param key The key under which to store the value.
  188. *
  189. * @return A newly instanced dictionary with the key and value in it.
  190. **/
  191. + (instancetype)dictionaryWithInt32:(int32_t)value
  192. forKey:(uint32_t)key;
  193. /**
  194. * Creates and initializes a dictionary with the entries given.
  195. *
  196. * @param values The values to be placed in the dictionary.
  197. * @param keys The keys under which to store the values.
  198. * @param count The number of entries to store in the dictionary.
  199. *
  200. * @return A newly instanced dictionary with the keys and values in it.
  201. **/
  202. + (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
  203. forKeys:(const uint32_t [__nullable])keys
  204. count:(NSUInteger)count;
  205. /**
  206. * Creates and initializes a dictionary with the entries from the given.
  207. * dictionary.
  208. *
  209. * @param dictionary Dictionary containing the entries to add to the dictionary.
  210. *
  211. * @return A newly instanced dictionary with the entries from the given
  212. * dictionary in it.
  213. **/
  214. + (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary;
  215. /**
  216. * Creates and initializes a dictionary with the given capacity.
  217. *
  218. * @param numItems Capacity needed for the dictionary.
  219. *
  220. * @return A newly instanced dictionary with the given capacity.
  221. **/
  222. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  223. /**
  224. * Initializes this dictionary, copying the given values and keys.
  225. *
  226. * @param values The values to be placed in this dictionary.
  227. * @param keys The keys under which to store the values.
  228. * @param count The number of elements to copy into the dictionary.
  229. *
  230. * @return A newly initialized dictionary with a copy of the values and keys.
  231. **/
  232. - (instancetype)initWithInt32s:(const int32_t [__nullable])values
  233. forKeys:(const uint32_t [__nullable])keys
  234. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  235. /**
  236. * Initializes this dictionary, copying the entries from the given dictionary.
  237. *
  238. * @param dictionary Dictionary containing the entries to add to this dictionary.
  239. *
  240. * @return A newly initialized dictionary with the entries of the given dictionary.
  241. **/
  242. - (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary;
  243. /**
  244. * Initializes this dictionary with the requested capacity.
  245. *
  246. * @param numItems Number of items needed for this dictionary.
  247. *
  248. * @return A newly initialized dictionary with the requested capacity.
  249. **/
  250. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  251. /**
  252. * Gets the value for the given key.
  253. *
  254. * @param value Pointer into which the value will be set, if found.
  255. * @param key Key under which the value is stored, if present.
  256. *
  257. * @return YES if the key was found and the value was copied, NO otherwise.
  258. **/
  259. - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key;
  260. /**
  261. * Enumerates the keys and values on this dictionary with the given block.
  262. *
  263. * @param block The block to enumerate with.
  264. * **key**: The key for the current entry.
  265. * **value**: The value for the current entry
  266. * **stop**: A pointer to a boolean that when set stops the enumeration.
  267. **/
  268. - (void)enumerateKeysAndInt32sUsingBlock:
  269. (void (^)(uint32_t key, int32_t value, BOOL *stop))block;
  270. /**
  271. * Adds the keys and values from another dictionary.
  272. *
  273. * @param otherDictionary Dictionary containing entries to be added to this
  274. * dictionary.
  275. **/
  276. - (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary;
  277. /**
  278. * Sets the value for the given key.
  279. *
  280. * @param value The value to set.
  281. * @param key The key under which to store the value.
  282. **/
  283. - (void)setInt32:(int32_t)value forKey:(uint32_t)key;
  284. /**
  285. * Removes the entry for the given key.
  286. *
  287. * @param aKey Key to be removed from this dictionary.
  288. **/
  289. - (void)removeInt32ForKey:(uint32_t)aKey;
  290. /**
  291. * Removes all entries in this dictionary.
  292. **/
  293. - (void)removeAll;
  294. @end
  295. #pragma mark - UInt32 -> UInt64
  296. /**
  297. * Class used for map fields of <uint32_t, uint64_t>
  298. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  299. *
  300. * @note This class is not meant to be subclassed.
  301. **/
  302. @interface GPBUInt32UInt64Dictionary : NSObject <NSCopying>
  303. /** Number of entries stored in this dictionary. */
  304. @property(nonatomic, readonly) NSUInteger count;
  305. /**
  306. * @return A newly instanced and empty dictionary.
  307. **/
  308. + (instancetype)dictionary;
  309. /**
  310. * Creates and initializes a dictionary with the single entry given.
  311. *
  312. * @param value The value to be placed in the dictionary.
  313. * @param key The key under which to store the value.
  314. *
  315. * @return A newly instanced dictionary with the key and value in it.
  316. **/
  317. + (instancetype)dictionaryWithUInt64:(uint64_t)value
  318. forKey:(uint32_t)key;
  319. /**
  320. * Creates and initializes a dictionary with the entries given.
  321. *
  322. * @param values The values to be placed in the dictionary.
  323. * @param keys The keys under which to store the values.
  324. * @param count The number of entries to store in the dictionary.
  325. *
  326. * @return A newly instanced dictionary with the keys and values in it.
  327. **/
  328. + (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
  329. forKeys:(const uint32_t [__nullable])keys
  330. count:(NSUInteger)count;
  331. /**
  332. * Creates and initializes a dictionary with the entries from the given.
  333. * dictionary.
  334. *
  335. * @param dictionary Dictionary containing the entries to add to the dictionary.
  336. *
  337. * @return A newly instanced dictionary with the entries from the given
  338. * dictionary in it.
  339. **/
  340. + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary;
  341. /**
  342. * Creates and initializes a dictionary with the given capacity.
  343. *
  344. * @param numItems Capacity needed for the dictionary.
  345. *
  346. * @return A newly instanced dictionary with the given capacity.
  347. **/
  348. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  349. /**
  350. * Initializes this dictionary, copying the given values and keys.
  351. *
  352. * @param values The values to be placed in this dictionary.
  353. * @param keys The keys under which to store the values.
  354. * @param count The number of elements to copy into the dictionary.
  355. *
  356. * @return A newly initialized dictionary with a copy of the values and keys.
  357. **/
  358. - (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
  359. forKeys:(const uint32_t [__nullable])keys
  360. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  361. /**
  362. * Initializes this dictionary, copying the entries from the given dictionary.
  363. *
  364. * @param dictionary Dictionary containing the entries to add to this dictionary.
  365. *
  366. * @return A newly initialized dictionary with the entries of the given dictionary.
  367. **/
  368. - (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary;
  369. /**
  370. * Initializes this dictionary with the requested capacity.
  371. *
  372. * @param numItems Number of items needed for this dictionary.
  373. *
  374. * @return A newly initialized dictionary with the requested capacity.
  375. **/
  376. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  377. /**
  378. * Gets the value for the given key.
  379. *
  380. * @param value Pointer into which the value will be set, if found.
  381. * @param key Key under which the value is stored, if present.
  382. *
  383. * @return YES if the key was found and the value was copied, NO otherwise.
  384. **/
  385. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key;
  386. /**
  387. * Enumerates the keys and values on this dictionary with the given block.
  388. *
  389. * @param block The block to enumerate with.
  390. * **key**: The key for the current entry.
  391. * **value**: The value for the current entry
  392. * **stop**: A pointer to a boolean that when set stops the enumeration.
  393. **/
  394. - (void)enumerateKeysAndUInt64sUsingBlock:
  395. (void (^)(uint32_t key, uint64_t value, BOOL *stop))block;
  396. /**
  397. * Adds the keys and values from another dictionary.
  398. *
  399. * @param otherDictionary Dictionary containing entries to be added to this
  400. * dictionary.
  401. **/
  402. - (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary;
  403. /**
  404. * Sets the value for the given key.
  405. *
  406. * @param value The value to set.
  407. * @param key The key under which to store the value.
  408. **/
  409. - (void)setUInt64:(uint64_t)value forKey:(uint32_t)key;
  410. /**
  411. * Removes the entry for the given key.
  412. *
  413. * @param aKey Key to be removed from this dictionary.
  414. **/
  415. - (void)removeUInt64ForKey:(uint32_t)aKey;
  416. /**
  417. * Removes all entries in this dictionary.
  418. **/
  419. - (void)removeAll;
  420. @end
  421. #pragma mark - UInt32 -> Int64
  422. /**
  423. * Class used for map fields of <uint32_t, int64_t>
  424. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  425. *
  426. * @note This class is not meant to be subclassed.
  427. **/
  428. @interface GPBUInt32Int64Dictionary : NSObject <NSCopying>
  429. /** Number of entries stored in this dictionary. */
  430. @property(nonatomic, readonly) NSUInteger count;
  431. /**
  432. * @return A newly instanced and empty dictionary.
  433. **/
  434. + (instancetype)dictionary;
  435. /**
  436. * Creates and initializes a dictionary with the single entry given.
  437. *
  438. * @param value The value to be placed in the dictionary.
  439. * @param key The key under which to store the value.
  440. *
  441. * @return A newly instanced dictionary with the key and value in it.
  442. **/
  443. + (instancetype)dictionaryWithInt64:(int64_t)value
  444. forKey:(uint32_t)key;
  445. /**
  446. * Creates and initializes a dictionary with the entries given.
  447. *
  448. * @param values The values to be placed in the dictionary.
  449. * @param keys The keys under which to store the values.
  450. * @param count The number of entries to store in the dictionary.
  451. *
  452. * @return A newly instanced dictionary with the keys and values in it.
  453. **/
  454. + (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
  455. forKeys:(const uint32_t [__nullable])keys
  456. count:(NSUInteger)count;
  457. /**
  458. * Creates and initializes a dictionary with the entries from the given.
  459. * dictionary.
  460. *
  461. * @param dictionary Dictionary containing the entries to add to the dictionary.
  462. *
  463. * @return A newly instanced dictionary with the entries from the given
  464. * dictionary in it.
  465. **/
  466. + (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary;
  467. /**
  468. * Creates and initializes a dictionary with the given capacity.
  469. *
  470. * @param numItems Capacity needed for the dictionary.
  471. *
  472. * @return A newly instanced dictionary with the given capacity.
  473. **/
  474. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  475. /**
  476. * Initializes this dictionary, copying the given values and keys.
  477. *
  478. * @param values The values to be placed in this dictionary.
  479. * @param keys The keys under which to store the values.
  480. * @param count The number of elements to copy into the dictionary.
  481. *
  482. * @return A newly initialized dictionary with a copy of the values and keys.
  483. **/
  484. - (instancetype)initWithInt64s:(const int64_t [__nullable])values
  485. forKeys:(const uint32_t [__nullable])keys
  486. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  487. /**
  488. * Initializes this dictionary, copying the entries from the given dictionary.
  489. *
  490. * @param dictionary Dictionary containing the entries to add to this dictionary.
  491. *
  492. * @return A newly initialized dictionary with the entries of the given dictionary.
  493. **/
  494. - (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary;
  495. /**
  496. * Initializes this dictionary with the requested capacity.
  497. *
  498. * @param numItems Number of items needed for this dictionary.
  499. *
  500. * @return A newly initialized dictionary with the requested capacity.
  501. **/
  502. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  503. /**
  504. * Gets the value for the given key.
  505. *
  506. * @param value Pointer into which the value will be set, if found.
  507. * @param key Key under which the value is stored, if present.
  508. *
  509. * @return YES if the key was found and the value was copied, NO otherwise.
  510. **/
  511. - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key;
  512. /**
  513. * Enumerates the keys and values on this dictionary with the given block.
  514. *
  515. * @param block The block to enumerate with.
  516. * **key**: The key for the current entry.
  517. * **value**: The value for the current entry
  518. * **stop**: A pointer to a boolean that when set stops the enumeration.
  519. **/
  520. - (void)enumerateKeysAndInt64sUsingBlock:
  521. (void (^)(uint32_t key, int64_t value, BOOL *stop))block;
  522. /**
  523. * Adds the keys and values from another dictionary.
  524. *
  525. * @param otherDictionary Dictionary containing entries to be added to this
  526. * dictionary.
  527. **/
  528. - (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary;
  529. /**
  530. * Sets the value for the given key.
  531. *
  532. * @param value The value to set.
  533. * @param key The key under which to store the value.
  534. **/
  535. - (void)setInt64:(int64_t)value forKey:(uint32_t)key;
  536. /**
  537. * Removes the entry for the given key.
  538. *
  539. * @param aKey Key to be removed from this dictionary.
  540. **/
  541. - (void)removeInt64ForKey:(uint32_t)aKey;
  542. /**
  543. * Removes all entries in this dictionary.
  544. **/
  545. - (void)removeAll;
  546. @end
  547. #pragma mark - UInt32 -> Bool
  548. /**
  549. * Class used for map fields of <uint32_t, BOOL>
  550. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  551. *
  552. * @note This class is not meant to be subclassed.
  553. **/
  554. @interface GPBUInt32BoolDictionary : NSObject <NSCopying>
  555. /** Number of entries stored in this dictionary. */
  556. @property(nonatomic, readonly) NSUInteger count;
  557. /**
  558. * @return A newly instanced and empty dictionary.
  559. **/
  560. + (instancetype)dictionary;
  561. /**
  562. * Creates and initializes a dictionary with the single entry given.
  563. *
  564. * @param value The value to be placed in the dictionary.
  565. * @param key The key under which to store the value.
  566. *
  567. * @return A newly instanced dictionary with the key and value in it.
  568. **/
  569. + (instancetype)dictionaryWithBool:(BOOL)value
  570. forKey:(uint32_t)key;
  571. /**
  572. * Creates and initializes a dictionary with the entries given.
  573. *
  574. * @param values The values to be placed in the dictionary.
  575. * @param keys The keys under which to store the values.
  576. * @param count The number of entries to store in the dictionary.
  577. *
  578. * @return A newly instanced dictionary with the keys and values in it.
  579. **/
  580. + (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
  581. forKeys:(const uint32_t [__nullable])keys
  582. count:(NSUInteger)count;
  583. /**
  584. * Creates and initializes a dictionary with the entries from the given.
  585. * dictionary.
  586. *
  587. * @param dictionary Dictionary containing the entries to add to the dictionary.
  588. *
  589. * @return A newly instanced dictionary with the entries from the given
  590. * dictionary in it.
  591. **/
  592. + (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary;
  593. /**
  594. * Creates and initializes a dictionary with the given capacity.
  595. *
  596. * @param numItems Capacity needed for the dictionary.
  597. *
  598. * @return A newly instanced dictionary with the given capacity.
  599. **/
  600. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  601. /**
  602. * Initializes this dictionary, copying the given values and keys.
  603. *
  604. * @param values The values to be placed in this dictionary.
  605. * @param keys The keys under which to store the values.
  606. * @param count The number of elements to copy into the dictionary.
  607. *
  608. * @return A newly initialized dictionary with a copy of the values and keys.
  609. **/
  610. - (instancetype)initWithBools:(const BOOL [__nullable])values
  611. forKeys:(const uint32_t [__nullable])keys
  612. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  613. /**
  614. * Initializes this dictionary, copying the entries from the given dictionary.
  615. *
  616. * @param dictionary Dictionary containing the entries to add to this dictionary.
  617. *
  618. * @return A newly initialized dictionary with the entries of the given dictionary.
  619. **/
  620. - (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary;
  621. /**
  622. * Initializes this dictionary with the requested capacity.
  623. *
  624. * @param numItems Number of items needed for this dictionary.
  625. *
  626. * @return A newly initialized dictionary with the requested capacity.
  627. **/
  628. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  629. /**
  630. * Gets the value for the given key.
  631. *
  632. * @param value Pointer into which the value will be set, if found.
  633. * @param key Key under which the value is stored, if present.
  634. *
  635. * @return YES if the key was found and the value was copied, NO otherwise.
  636. **/
  637. - (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key;
  638. /**
  639. * Enumerates the keys and values on this dictionary with the given block.
  640. *
  641. * @param block The block to enumerate with.
  642. * **key**: The key for the current entry.
  643. * **value**: The value for the current entry
  644. * **stop**: A pointer to a boolean that when set stops the enumeration.
  645. **/
  646. - (void)enumerateKeysAndBoolsUsingBlock:
  647. (void (^)(uint32_t key, BOOL value, BOOL *stop))block;
  648. /**
  649. * Adds the keys and values from another dictionary.
  650. *
  651. * @param otherDictionary Dictionary containing entries to be added to this
  652. * dictionary.
  653. **/
  654. - (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary;
  655. /**
  656. * Sets the value for the given key.
  657. *
  658. * @param value The value to set.
  659. * @param key The key under which to store the value.
  660. **/
  661. - (void)setBool:(BOOL)value forKey:(uint32_t)key;
  662. /**
  663. * Removes the entry for the given key.
  664. *
  665. * @param aKey Key to be removed from this dictionary.
  666. **/
  667. - (void)removeBoolForKey:(uint32_t)aKey;
  668. /**
  669. * Removes all entries in this dictionary.
  670. **/
  671. - (void)removeAll;
  672. @end
  673. #pragma mark - UInt32 -> Float
  674. /**
  675. * Class used for map fields of <uint32_t, float>
  676. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  677. *
  678. * @note This class is not meant to be subclassed.
  679. **/
  680. @interface GPBUInt32FloatDictionary : NSObject <NSCopying>
  681. /** Number of entries stored in this dictionary. */
  682. @property(nonatomic, readonly) NSUInteger count;
  683. /**
  684. * @return A newly instanced and empty dictionary.
  685. **/
  686. + (instancetype)dictionary;
  687. /**
  688. * Creates and initializes a dictionary with the single entry given.
  689. *
  690. * @param value The value to be placed in the dictionary.
  691. * @param key The key under which to store the value.
  692. *
  693. * @return A newly instanced dictionary with the key and value in it.
  694. **/
  695. + (instancetype)dictionaryWithFloat:(float)value
  696. forKey:(uint32_t)key;
  697. /**
  698. * Creates and initializes a dictionary with the entries given.
  699. *
  700. * @param values The values to be placed in the dictionary.
  701. * @param keys The keys under which to store the values.
  702. * @param count The number of entries to store in the dictionary.
  703. *
  704. * @return A newly instanced dictionary with the keys and values in it.
  705. **/
  706. + (instancetype)dictionaryWithFloats:(const float [__nullable])values
  707. forKeys:(const uint32_t [__nullable])keys
  708. count:(NSUInteger)count;
  709. /**
  710. * Creates and initializes a dictionary with the entries from the given.
  711. * dictionary.
  712. *
  713. * @param dictionary Dictionary containing the entries to add to the dictionary.
  714. *
  715. * @return A newly instanced dictionary with the entries from the given
  716. * dictionary in it.
  717. **/
  718. + (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary;
  719. /**
  720. * Creates and initializes a dictionary with the given capacity.
  721. *
  722. * @param numItems Capacity needed for the dictionary.
  723. *
  724. * @return A newly instanced dictionary with the given capacity.
  725. **/
  726. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  727. /**
  728. * Initializes this dictionary, copying the given values and keys.
  729. *
  730. * @param values The values to be placed in this dictionary.
  731. * @param keys The keys under which to store the values.
  732. * @param count The number of elements to copy into the dictionary.
  733. *
  734. * @return A newly initialized dictionary with a copy of the values and keys.
  735. **/
  736. - (instancetype)initWithFloats:(const float [__nullable])values
  737. forKeys:(const uint32_t [__nullable])keys
  738. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  739. /**
  740. * Initializes this dictionary, copying the entries from the given dictionary.
  741. *
  742. * @param dictionary Dictionary containing the entries to add to this dictionary.
  743. *
  744. * @return A newly initialized dictionary with the entries of the given dictionary.
  745. **/
  746. - (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary;
  747. /**
  748. * Initializes this dictionary with the requested capacity.
  749. *
  750. * @param numItems Number of items needed for this dictionary.
  751. *
  752. * @return A newly initialized dictionary with the requested capacity.
  753. **/
  754. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  755. /**
  756. * Gets the value for the given key.
  757. *
  758. * @param value Pointer into which the value will be set, if found.
  759. * @param key Key under which the value is stored, if present.
  760. *
  761. * @return YES if the key was found and the value was copied, NO otherwise.
  762. **/
  763. - (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key;
  764. /**
  765. * Enumerates the keys and values on this dictionary with the given block.
  766. *
  767. * @param block The block to enumerate with.
  768. * **key**: The key for the current entry.
  769. * **value**: The value for the current entry
  770. * **stop**: A pointer to a boolean that when set stops the enumeration.
  771. **/
  772. - (void)enumerateKeysAndFloatsUsingBlock:
  773. (void (^)(uint32_t key, float value, BOOL *stop))block;
  774. /**
  775. * Adds the keys and values from another dictionary.
  776. *
  777. * @param otherDictionary Dictionary containing entries to be added to this
  778. * dictionary.
  779. **/
  780. - (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary;
  781. /**
  782. * Sets the value for the given key.
  783. *
  784. * @param value The value to set.
  785. * @param key The key under which to store the value.
  786. **/
  787. - (void)setFloat:(float)value forKey:(uint32_t)key;
  788. /**
  789. * Removes the entry for the given key.
  790. *
  791. * @param aKey Key to be removed from this dictionary.
  792. **/
  793. - (void)removeFloatForKey:(uint32_t)aKey;
  794. /**
  795. * Removes all entries in this dictionary.
  796. **/
  797. - (void)removeAll;
  798. @end
  799. #pragma mark - UInt32 -> Double
  800. /**
  801. * Class used for map fields of <uint32_t, double>
  802. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  803. *
  804. * @note This class is not meant to be subclassed.
  805. **/
  806. @interface GPBUInt32DoubleDictionary : NSObject <NSCopying>
  807. /** Number of entries stored in this dictionary. */
  808. @property(nonatomic, readonly) NSUInteger count;
  809. /**
  810. * @return A newly instanced and empty dictionary.
  811. **/
  812. + (instancetype)dictionary;
  813. /**
  814. * Creates and initializes a dictionary with the single entry given.
  815. *
  816. * @param value The value to be placed in the dictionary.
  817. * @param key The key under which to store the value.
  818. *
  819. * @return A newly instanced dictionary with the key and value in it.
  820. **/
  821. + (instancetype)dictionaryWithDouble:(double)value
  822. forKey:(uint32_t)key;
  823. /**
  824. * Creates and initializes a dictionary with the entries given.
  825. *
  826. * @param values The values to be placed in the dictionary.
  827. * @param keys The keys under which to store the values.
  828. * @param count The number of entries to store in the dictionary.
  829. *
  830. * @return A newly instanced dictionary with the keys and values in it.
  831. **/
  832. + (instancetype)dictionaryWithDoubles:(const double [__nullable])values
  833. forKeys:(const uint32_t [__nullable])keys
  834. count:(NSUInteger)count;
  835. /**
  836. * Creates and initializes a dictionary with the entries from the given.
  837. * dictionary.
  838. *
  839. * @param dictionary Dictionary containing the entries to add to the dictionary.
  840. *
  841. * @return A newly instanced dictionary with the entries from the given
  842. * dictionary in it.
  843. **/
  844. + (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary;
  845. /**
  846. * Creates and initializes a dictionary with the given capacity.
  847. *
  848. * @param numItems Capacity needed for the dictionary.
  849. *
  850. * @return A newly instanced dictionary with the given capacity.
  851. **/
  852. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  853. /**
  854. * Initializes this dictionary, copying the given values and keys.
  855. *
  856. * @param values The values to be placed in this dictionary.
  857. * @param keys The keys under which to store the values.
  858. * @param count The number of elements to copy into the dictionary.
  859. *
  860. * @return A newly initialized dictionary with a copy of the values and keys.
  861. **/
  862. - (instancetype)initWithDoubles:(const double [__nullable])values
  863. forKeys:(const uint32_t [__nullable])keys
  864. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  865. /**
  866. * Initializes this dictionary, copying the entries from the given dictionary.
  867. *
  868. * @param dictionary Dictionary containing the entries to add to this dictionary.
  869. *
  870. * @return A newly initialized dictionary with the entries of the given dictionary.
  871. **/
  872. - (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary;
  873. /**
  874. * Initializes this dictionary with the requested capacity.
  875. *
  876. * @param numItems Number of items needed for this dictionary.
  877. *
  878. * @return A newly initialized dictionary with the requested capacity.
  879. **/
  880. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  881. /**
  882. * Gets the value for the given key.
  883. *
  884. * @param value Pointer into which the value will be set, if found.
  885. * @param key Key under which the value is stored, if present.
  886. *
  887. * @return YES if the key was found and the value was copied, NO otherwise.
  888. **/
  889. - (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key;
  890. /**
  891. * Enumerates the keys and values on this dictionary with the given block.
  892. *
  893. * @param block The block to enumerate with.
  894. * **key**: The key for the current entry.
  895. * **value**: The value for the current entry
  896. * **stop**: A pointer to a boolean that when set stops the enumeration.
  897. **/
  898. - (void)enumerateKeysAndDoublesUsingBlock:
  899. (void (^)(uint32_t key, double value, BOOL *stop))block;
  900. /**
  901. * Adds the keys and values from another dictionary.
  902. *
  903. * @param otherDictionary Dictionary containing entries to be added to this
  904. * dictionary.
  905. **/
  906. - (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary;
  907. /**
  908. * Sets the value for the given key.
  909. *
  910. * @param value The value to set.
  911. * @param key The key under which to store the value.
  912. **/
  913. - (void)setDouble:(double)value forKey:(uint32_t)key;
  914. /**
  915. * Removes the entry for the given key.
  916. *
  917. * @param aKey Key to be removed from this dictionary.
  918. **/
  919. - (void)removeDoubleForKey:(uint32_t)aKey;
  920. /**
  921. * Removes all entries in this dictionary.
  922. **/
  923. - (void)removeAll;
  924. @end
  925. #pragma mark - UInt32 -> Enum
  926. /**
  927. * Class used for map fields of <uint32_t, int32_t>
  928. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  929. *
  930. * @note This class is not meant to be subclassed.
  931. **/
  932. @interface GPBUInt32EnumDictionary : NSObject <NSCopying>
  933. /** Number of entries stored in this dictionary. */
  934. @property(nonatomic, readonly) NSUInteger count;
  935. /** The validation function to check if the enums are valid. */
  936. @property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
  937. /**
  938. * @return A newly instanced and empty dictionary.
  939. **/
  940. + (instancetype)dictionary;
  941. /**
  942. * Creates and initializes a dictionary with the given validation function.
  943. *
  944. * @param func The enum validation function for the dictionary.
  945. *
  946. * @return A newly instanced dictionary.
  947. **/
  948. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  949. /**
  950. * Creates and initializes a dictionary with the single entry given.
  951. *
  952. * @param func The enum validation function for the dictionary.
  953. * @param rawValue The raw enum value to be placed in the dictionary.
  954. * @param key The key under which to store the value.
  955. *
  956. * @return A newly instanced dictionary with the key and value in it.
  957. **/
  958. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  959. rawValue:(int32_t)rawValue
  960. forKey:(uint32_t)key;
  961. /**
  962. * Creates and initializes a dictionary with the entries given.
  963. *
  964. * @param func The enum validation function for the dictionary.
  965. * @param values The raw enum values values to be placed in the dictionary.
  966. * @param keys The keys under which to store the values.
  967. * @param count The number of entries to store in the dictionary.
  968. *
  969. * @return A newly instanced dictionary with the keys and values in it.
  970. **/
  971. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  972. rawValues:(const int32_t [__nullable])values
  973. forKeys:(const uint32_t [__nullable])keys
  974. count:(NSUInteger)count;
  975. /**
  976. * Creates and initializes a dictionary with the entries from the given.
  977. * dictionary.
  978. *
  979. * @param dictionary Dictionary containing the entries to add to the dictionary.
  980. *
  981. * @return A newly instanced dictionary with the entries from the given
  982. * dictionary in it.
  983. **/
  984. + (instancetype)dictionaryWithDictionary:(GPBUInt32EnumDictionary *)dictionary;
  985. /**
  986. * Creates and initializes a dictionary with the given capacity.
  987. *
  988. * @param func The enum validation function for the dictionary.
  989. * @param numItems Capacity needed for the dictionary.
  990. *
  991. * @return A newly instanced dictionary with the given capacity.
  992. **/
  993. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  994. capacity:(NSUInteger)numItems;
  995. /**
  996. * Initializes a dictionary with the given validation function.
  997. *
  998. * @param func The enum validation function for the dictionary.
  999. *
  1000. * @return A newly initialized dictionary.
  1001. **/
  1002. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  1003. /**
  1004. * Initializes a dictionary with the entries given.
  1005. *
  1006. * @param func The enum validation function for the dictionary.
  1007. * @param values The raw enum values values to be placed in the dictionary.
  1008. * @param keys The keys under which to store the values.
  1009. * @param count The number of entries to store in the dictionary.
  1010. *
  1011. * @return A newly initialized dictionary with the keys and values in it.
  1012. **/
  1013. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  1014. rawValues:(const int32_t [__nullable])values
  1015. forKeys:(const uint32_t [__nullable])keys
  1016. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  1017. /**
  1018. * Initializes a dictionary with the entries from the given.
  1019. * dictionary.
  1020. *
  1021. * @param dictionary Dictionary containing the entries to add to the dictionary.
  1022. *
  1023. * @return A newly initialized dictionary with the entries from the given
  1024. * dictionary in it.
  1025. **/
  1026. - (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary;
  1027. /**
  1028. * Initializes a dictionary with the given capacity.
  1029. *
  1030. * @param func The enum validation function for the dictionary.
  1031. * @param numItems Capacity needed for the dictionary.
  1032. *
  1033. * @return A newly initialized dictionary with the given capacity.
  1034. **/
  1035. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  1036. capacity:(NSUInteger)numItems;
  1037. // These will return kGPBUnrecognizedEnumeratorValue if the value for the key
  1038. // is not a valid enumerator as defined by validationFunc. If the actual value is
  1039. // desired, use "raw" version of the method.
  1040. /**
  1041. * Gets the value for the given key.
  1042. *
  1043. * @param value Pointer into which the value will be set, if found.
  1044. * @param key Key under which the value is stored, if present.
  1045. *
  1046. * @return YES if the key was found and the value was copied, NO otherwise.
  1047. **/
  1048. - (BOOL)getEnum:(nullable int32_t *)value forKey:(uint32_t)key;
  1049. /**
  1050. * Enumerates the keys and values on this dictionary with the given block.
  1051. *
  1052. * @param block The block to enumerate with.
  1053. * **key**: The key for the current entry.
  1054. * **value**: The value for the current entry
  1055. * **stop**: A pointer to a boolean that when set stops the enumeration.
  1056. **/
  1057. - (void)enumerateKeysAndEnumsUsingBlock:
  1058. (void (^)(uint32_t key, int32_t value, BOOL *stop))block;
  1059. /**
  1060. * Gets the raw enum value for the given key.
  1061. *
  1062. * @note This method bypass the validationFunc to enable the access of values that
  1063. * were not known at the time the binary was compiled.
  1064. *
  1065. * @param rawValue Pointer into which the value will be set, if found.
  1066. * @param key Key under which the value is stored, if present.
  1067. *
  1068. * @return YES if the key was found and the value was copied, NO otherwise.
  1069. **/
  1070. - (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(uint32_t)key;
  1071. /**
  1072. * Enumerates the keys and values on this dictionary with the given block.
  1073. *
  1074. * @note This method bypass the validationFunc to enable the access of values that
  1075. * were not known at the time the binary was compiled.
  1076. *
  1077. * @param block The block to enumerate with.
  1078. * **key**: The key for the current entry.
  1079. * **rawValue**: The value for the current entry
  1080. * **stop**: A pointer to a boolean that when set stops the enumeration.
  1081. **/
  1082. - (void)enumerateKeysAndRawValuesUsingBlock:
  1083. (void (^)(uint32_t key, int32_t rawValue, BOOL *stop))block;
  1084. /**
  1085. * Adds the keys and raw enum values from another dictionary.
  1086. *
  1087. * @note This method bypass the validationFunc to enable the setting of values that
  1088. * were not known at the time the binary was compiled.
  1089. *
  1090. * @param otherDictionary Dictionary containing entries to be added to this
  1091. * dictionary.
  1092. **/
  1093. - (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary;
  1094. // If value is not a valid enumerator as defined by validationFunc, these
  1095. // methods will assert in debug, and will log in release and assign the value
  1096. // to the default value. Use the rawValue methods below to assign non enumerator
  1097. // values.
  1098. /**
  1099. * Sets the value for the given key.
  1100. *
  1101. * @param value The value to set.
  1102. * @param key The key under which to store the value.
  1103. **/
  1104. - (void)setEnum:(int32_t)value forKey:(uint32_t)key;
  1105. /**
  1106. * Sets the raw enum value for the given key.
  1107. *
  1108. * @note This method bypass the validationFunc to enable the setting of values that
  1109. * were not known at the time the binary was compiled.
  1110. *
  1111. * @param rawValue The raw enum value to set.
  1112. * @param key The key under which to store the raw enum value.
  1113. **/
  1114. - (void)setRawValue:(int32_t)rawValue forKey:(uint32_t)key;
  1115. /**
  1116. * Removes the entry for the given key.
  1117. *
  1118. * @param aKey Key to be removed from this dictionary.
  1119. **/
  1120. - (void)removeEnumForKey:(uint32_t)aKey;
  1121. /**
  1122. * Removes all entries in this dictionary.
  1123. **/
  1124. - (void)removeAll;
  1125. @end
  1126. #pragma mark - UInt32 -> Object
  1127. /**
  1128. * Class used for map fields of <uint32_t, ObjectType>
  1129. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  1130. *
  1131. * @note This class is not meant to be subclassed.
  1132. **/
  1133. @interface GPBUInt32ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
  1134. /** Number of entries stored in this dictionary. */
  1135. @property(nonatomic, readonly) NSUInteger count;
  1136. /**
  1137. * @return A newly instanced and empty dictionary.
  1138. **/
  1139. + (instancetype)dictionary;
  1140. /**
  1141. * Creates and initializes a dictionary with the single entry given.
  1142. *
  1143. * @param object The value to be placed in the dictionary.
  1144. * @param key The key under which to store the value.
  1145. *
  1146. * @return A newly instanced dictionary with the key and value in it.
  1147. **/
  1148. + (instancetype)dictionaryWithObject:(ObjectType)object
  1149. forKey:(uint32_t)key;
  1150. /**
  1151. * Creates and initializes a dictionary with the entries given.
  1152. *
  1153. * @param objects The values to be placed in the dictionary.
  1154. * @param keys The keys under which to store the values.
  1155. * @param count The number of entries to store in the dictionary.
  1156. *
  1157. * @return A newly instanced dictionary with the keys and values in it.
  1158. **/
  1159. + (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
  1160. forKeys:(const uint32_t [__nullable])keys
  1161. count:(NSUInteger)count;
  1162. /**
  1163. * Creates and initializes a dictionary with the entries from the given.
  1164. * dictionary.
  1165. *
  1166. * @param dictionary Dictionary containing the entries to add to the dictionary.
  1167. *
  1168. * @return A newly instanced dictionary with the entries from the given
  1169. * dictionary in it.
  1170. **/
  1171. + (instancetype)dictionaryWithDictionary:(GPBUInt32ObjectDictionary *)dictionary;
  1172. /**
  1173. * Creates and initializes a dictionary with the given capacity.
  1174. *
  1175. * @param numItems Capacity needed for the dictionary.
  1176. *
  1177. * @return A newly instanced dictionary with the given capacity.
  1178. **/
  1179. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  1180. /**
  1181. * Initializes this dictionary, copying the given values and keys.
  1182. *
  1183. * @param objects The values to be placed in this dictionary.
  1184. * @param keys The keys under which to store the values.
  1185. * @param count The number of elements to copy into the dictionary.
  1186. *
  1187. * @return A newly initialized dictionary with a copy of the values and keys.
  1188. **/
  1189. - (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
  1190. forKeys:(const uint32_t [__nullable])keys
  1191. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  1192. /**
  1193. * Initializes this dictionary, copying the entries from the given dictionary.
  1194. *
  1195. * @param dictionary Dictionary containing the entries to add to this dictionary.
  1196. *
  1197. * @return A newly initialized dictionary with the entries of the given dictionary.
  1198. **/
  1199. - (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary;
  1200. /**
  1201. * Initializes this dictionary with the requested capacity.
  1202. *
  1203. * @param numItems Number of items needed for this dictionary.
  1204. *
  1205. * @return A newly initialized dictionary with the requested capacity.
  1206. **/
  1207. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  1208. /**
  1209. * Fetches the object stored under the given key.
  1210. *
  1211. * @param key Key under which the value is stored, if present.
  1212. *
  1213. * @return The object if found, nil otherwise.
  1214. **/
  1215. - (ObjectType)objectForKey:(uint32_t)key;
  1216. /**
  1217. * Enumerates the keys and values on this dictionary with the given block.
  1218. *
  1219. * @param block The block to enumerate with.
  1220. * **key**: The key for the current entry.
  1221. * **object**: The value for the current entry
  1222. * **stop**: A pointer to a boolean that when set stops the enumeration.
  1223. **/
  1224. - (void)enumerateKeysAndObjectsUsingBlock:
  1225. (void (^)(uint32_t key, ObjectType object, BOOL *stop))block;
  1226. /**
  1227. * Adds the keys and values from another dictionary.
  1228. *
  1229. * @param otherDictionary Dictionary containing entries to be added to this
  1230. * dictionary.
  1231. **/
  1232. - (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary;
  1233. /**
  1234. * Sets the value for the given key.
  1235. *
  1236. * @param object The value to set.
  1237. * @param key The key under which to store the value.
  1238. **/
  1239. - (void)setObject:(ObjectType)object forKey:(uint32_t)key;
  1240. /**
  1241. * Removes the entry for the given key.
  1242. *
  1243. * @param aKey Key to be removed from this dictionary.
  1244. **/
  1245. - (void)removeObjectForKey:(uint32_t)aKey;
  1246. /**
  1247. * Removes all entries in this dictionary.
  1248. **/
  1249. - (void)removeAll;
  1250. @end
  1251. #pragma mark - Int32 -> UInt32
  1252. /**
  1253. * Class used for map fields of <int32_t, uint32_t>
  1254. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  1255. *
  1256. * @note This class is not meant to be subclassed.
  1257. **/
  1258. @interface GPBInt32UInt32Dictionary : NSObject <NSCopying>
  1259. /** Number of entries stored in this dictionary. */
  1260. @property(nonatomic, readonly) NSUInteger count;
  1261. /**
  1262. * @return A newly instanced and empty dictionary.
  1263. **/
  1264. + (instancetype)dictionary;
  1265. /**
  1266. * Creates and initializes a dictionary with the single entry given.
  1267. *
  1268. * @param value The value to be placed in the dictionary.
  1269. * @param key The key under which to store the value.
  1270. *
  1271. * @return A newly instanced dictionary with the key and value in it.
  1272. **/
  1273. + (instancetype)dictionaryWithUInt32:(uint32_t)value
  1274. forKey:(int32_t)key;
  1275. /**
  1276. * Creates and initializes a dictionary with the entries given.
  1277. *
  1278. * @param values The values to be placed in the dictionary.
  1279. * @param keys The keys under which to store the values.
  1280. * @param count The number of entries to store in the dictionary.
  1281. *
  1282. * @return A newly instanced dictionary with the keys and values in it.
  1283. **/
  1284. + (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
  1285. forKeys:(const int32_t [__nullable])keys
  1286. count:(NSUInteger)count;
  1287. /**
  1288. * Creates and initializes a dictionary with the entries from the given.
  1289. * dictionary.
  1290. *
  1291. * @param dictionary Dictionary containing the entries to add to the dictionary.
  1292. *
  1293. * @return A newly instanced dictionary with the entries from the given
  1294. * dictionary in it.
  1295. **/
  1296. + (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary;
  1297. /**
  1298. * Creates and initializes a dictionary with the given capacity.
  1299. *
  1300. * @param numItems Capacity needed for the dictionary.
  1301. *
  1302. * @return A newly instanced dictionary with the given capacity.
  1303. **/
  1304. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  1305. /**
  1306. * Initializes this dictionary, copying the given values and keys.
  1307. *
  1308. * @param values The values to be placed in this dictionary.
  1309. * @param keys The keys under which to store the values.
  1310. * @param count The number of elements to copy into the dictionary.
  1311. *
  1312. * @return A newly initialized dictionary with a copy of the values and keys.
  1313. **/
  1314. - (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
  1315. forKeys:(const int32_t [__nullable])keys
  1316. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  1317. /**
  1318. * Initializes this dictionary, copying the entries from the given dictionary.
  1319. *
  1320. * @param dictionary Dictionary containing the entries to add to this dictionary.
  1321. *
  1322. * @return A newly initialized dictionary with the entries of the given dictionary.
  1323. **/
  1324. - (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary;
  1325. /**
  1326. * Initializes this dictionary with the requested capacity.
  1327. *
  1328. * @param numItems Number of items needed for this dictionary.
  1329. *
  1330. * @return A newly initialized dictionary with the requested capacity.
  1331. **/
  1332. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  1333. /**
  1334. * Gets the value for the given key.
  1335. *
  1336. * @param value Pointer into which the value will be set, if found.
  1337. * @param key Key under which the value is stored, if present.
  1338. *
  1339. * @return YES if the key was found and the value was copied, NO otherwise.
  1340. **/
  1341. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key;
  1342. /**
  1343. * Enumerates the keys and values on this dictionary with the given block.
  1344. *
  1345. * @param block The block to enumerate with.
  1346. * **key**: The key for the current entry.
  1347. * **value**: The value for the current entry
  1348. * **stop**: A pointer to a boolean that when set stops the enumeration.
  1349. **/
  1350. - (void)enumerateKeysAndUInt32sUsingBlock:
  1351. (void (^)(int32_t key, uint32_t value, BOOL *stop))block;
  1352. /**
  1353. * Adds the keys and values from another dictionary.
  1354. *
  1355. * @param otherDictionary Dictionary containing entries to be added to this
  1356. * dictionary.
  1357. **/
  1358. - (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary;
  1359. /**
  1360. * Sets the value for the given key.
  1361. *
  1362. * @param value The value to set.
  1363. * @param key The key under which to store the value.
  1364. **/
  1365. - (void)setUInt32:(uint32_t)value forKey:(int32_t)key;
  1366. /**
  1367. * Removes the entry for the given key.
  1368. *
  1369. * @param aKey Key to be removed from this dictionary.
  1370. **/
  1371. - (void)removeUInt32ForKey:(int32_t)aKey;
  1372. /**
  1373. * Removes all entries in this dictionary.
  1374. **/
  1375. - (void)removeAll;
  1376. @end
  1377. #pragma mark - Int32 -> Int32
  1378. /**
  1379. * Class used for map fields of <int32_t, int32_t>
  1380. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  1381. *
  1382. * @note This class is not meant to be subclassed.
  1383. **/
  1384. @interface GPBInt32Int32Dictionary : NSObject <NSCopying>
  1385. /** Number of entries stored in this dictionary. */
  1386. @property(nonatomic, readonly) NSUInteger count;
  1387. /**
  1388. * @return A newly instanced and empty dictionary.
  1389. **/
  1390. + (instancetype)dictionary;
  1391. /**
  1392. * Creates and initializes a dictionary with the single entry given.
  1393. *
  1394. * @param value The value to be placed in the dictionary.
  1395. * @param key The key under which to store the value.
  1396. *
  1397. * @return A newly instanced dictionary with the key and value in it.
  1398. **/
  1399. + (instancetype)dictionaryWithInt32:(int32_t)value
  1400. forKey:(int32_t)key;
  1401. /**
  1402. * Creates and initializes a dictionary with the entries given.
  1403. *
  1404. * @param values The values to be placed in the dictionary.
  1405. * @param keys The keys under which to store the values.
  1406. * @param count The number of entries to store in the dictionary.
  1407. *
  1408. * @return A newly instanced dictionary with the keys and values in it.
  1409. **/
  1410. + (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
  1411. forKeys:(const int32_t [__nullable])keys
  1412. count:(NSUInteger)count;
  1413. /**
  1414. * Creates and initializes a dictionary with the entries from the given.
  1415. * dictionary.
  1416. *
  1417. * @param dictionary Dictionary containing the entries to add to the dictionary.
  1418. *
  1419. * @return A newly instanced dictionary with the entries from the given
  1420. * dictionary in it.
  1421. **/
  1422. + (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary;
  1423. /**
  1424. * Creates and initializes a dictionary with the given capacity.
  1425. *
  1426. * @param numItems Capacity needed for the dictionary.
  1427. *
  1428. * @return A newly instanced dictionary with the given capacity.
  1429. **/
  1430. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  1431. /**
  1432. * Initializes this dictionary, copying the given values and keys.
  1433. *
  1434. * @param values The values to be placed in this dictionary.
  1435. * @param keys The keys under which to store the values.
  1436. * @param count The number of elements to copy into the dictionary.
  1437. *
  1438. * @return A newly initialized dictionary with a copy of the values and keys.
  1439. **/
  1440. - (instancetype)initWithInt32s:(const int32_t [__nullable])values
  1441. forKeys:(const int32_t [__nullable])keys
  1442. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  1443. /**
  1444. * Initializes this dictionary, copying the entries from the given dictionary.
  1445. *
  1446. * @param dictionary Dictionary containing the entries to add to this dictionary.
  1447. *
  1448. * @return A newly initialized dictionary with the entries of the given dictionary.
  1449. **/
  1450. - (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary;
  1451. /**
  1452. * Initializes this dictionary with the requested capacity.
  1453. *
  1454. * @param numItems Number of items needed for this dictionary.
  1455. *
  1456. * @return A newly initialized dictionary with the requested capacity.
  1457. **/
  1458. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  1459. /**
  1460. * Gets the value for the given key.
  1461. *
  1462. * @param value Pointer into which the value will be set, if found.
  1463. * @param key Key under which the value is stored, if present.
  1464. *
  1465. * @return YES if the key was found and the value was copied, NO otherwise.
  1466. **/
  1467. - (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key;
  1468. /**
  1469. * Enumerates the keys and values on this dictionary with the given block.
  1470. *
  1471. * @param block The block to enumerate with.
  1472. * **key**: The key for the current entry.
  1473. * **value**: The value for the current entry
  1474. * **stop**: A pointer to a boolean that when set stops the enumeration.
  1475. **/
  1476. - (void)enumerateKeysAndInt32sUsingBlock:
  1477. (void (^)(int32_t key, int32_t value, BOOL *stop))block;
  1478. /**
  1479. * Adds the keys and values from another dictionary.
  1480. *
  1481. * @param otherDictionary Dictionary containing entries to be added to this
  1482. * dictionary.
  1483. **/
  1484. - (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary;
  1485. /**
  1486. * Sets the value for the given key.
  1487. *
  1488. * @param value The value to set.
  1489. * @param key The key under which to store the value.
  1490. **/
  1491. - (void)setInt32:(int32_t)value forKey:(int32_t)key;
  1492. /**
  1493. * Removes the entry for the given key.
  1494. *
  1495. * @param aKey Key to be removed from this dictionary.
  1496. **/
  1497. - (void)removeInt32ForKey:(int32_t)aKey;
  1498. /**
  1499. * Removes all entries in this dictionary.
  1500. **/
  1501. - (void)removeAll;
  1502. @end
  1503. #pragma mark - Int32 -> UInt64
  1504. /**
  1505. * Class used for map fields of <int32_t, uint64_t>
  1506. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  1507. *
  1508. * @note This class is not meant to be subclassed.
  1509. **/
  1510. @interface GPBInt32UInt64Dictionary : NSObject <NSCopying>
  1511. /** Number of entries stored in this dictionary. */
  1512. @property(nonatomic, readonly) NSUInteger count;
  1513. /**
  1514. * @return A newly instanced and empty dictionary.
  1515. **/
  1516. + (instancetype)dictionary;
  1517. /**
  1518. * Creates and initializes a dictionary with the single entry given.
  1519. *
  1520. * @param value The value to be placed in the dictionary.
  1521. * @param key The key under which to store the value.
  1522. *
  1523. * @return A newly instanced dictionary with the key and value in it.
  1524. **/
  1525. + (instancetype)dictionaryWithUInt64:(uint64_t)value
  1526. forKey:(int32_t)key;
  1527. /**
  1528. * Creates and initializes a dictionary with the entries given.
  1529. *
  1530. * @param values The values to be placed in the dictionary.
  1531. * @param keys The keys under which to store the values.
  1532. * @param count The number of entries to store in the dictionary.
  1533. *
  1534. * @return A newly instanced dictionary with the keys and values in it.
  1535. **/
  1536. + (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
  1537. forKeys:(const int32_t [__nullable])keys
  1538. count:(NSUInteger)count;
  1539. /**
  1540. * Creates and initializes a dictionary with the entries from the given.
  1541. * dictionary.
  1542. *
  1543. * @param dictionary Dictionary containing the entries to add to the dictionary.
  1544. *
  1545. * @return A newly instanced dictionary with the entries from the given
  1546. * dictionary in it.
  1547. **/
  1548. + (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary;
  1549. /**
  1550. * Creates and initializes a dictionary with the given capacity.
  1551. *
  1552. * @param numItems Capacity needed for the dictionary.
  1553. *
  1554. * @return A newly instanced dictionary with the given capacity.
  1555. **/
  1556. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  1557. /**
  1558. * Initializes this dictionary, copying the given values and keys.
  1559. *
  1560. * @param values The values to be placed in this dictionary.
  1561. * @param keys The keys under which to store the values.
  1562. * @param count The number of elements to copy into the dictionary.
  1563. *
  1564. * @return A newly initialized dictionary with a copy of the values and keys.
  1565. **/
  1566. - (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
  1567. forKeys:(const int32_t [__nullable])keys
  1568. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  1569. /**
  1570. * Initializes this dictionary, copying the entries from the given dictionary.
  1571. *
  1572. * @param dictionary Dictionary containing the entries to add to this dictionary.
  1573. *
  1574. * @return A newly initialized dictionary with the entries of the given dictionary.
  1575. **/
  1576. - (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary;
  1577. /**
  1578. * Initializes this dictionary with the requested capacity.
  1579. *
  1580. * @param numItems Number of items needed for this dictionary.
  1581. *
  1582. * @return A newly initialized dictionary with the requested capacity.
  1583. **/
  1584. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  1585. /**
  1586. * Gets the value for the given key.
  1587. *
  1588. * @param value Pointer into which the value will be set, if found.
  1589. * @param key Key under which the value is stored, if present.
  1590. *
  1591. * @return YES if the key was found and the value was copied, NO otherwise.
  1592. **/
  1593. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key;
  1594. /**
  1595. * Enumerates the keys and values on this dictionary with the given block.
  1596. *
  1597. * @param block The block to enumerate with.
  1598. * **key**: The key for the current entry.
  1599. * **value**: The value for the current entry
  1600. * **stop**: A pointer to a boolean that when set stops the enumeration.
  1601. **/
  1602. - (void)enumerateKeysAndUInt64sUsingBlock:
  1603. (void (^)(int32_t key, uint64_t value, BOOL *stop))block;
  1604. /**
  1605. * Adds the keys and values from another dictionary.
  1606. *
  1607. * @param otherDictionary Dictionary containing entries to be added to this
  1608. * dictionary.
  1609. **/
  1610. - (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary;
  1611. /**
  1612. * Sets the value for the given key.
  1613. *
  1614. * @param value The value to set.
  1615. * @param key The key under which to store the value.
  1616. **/
  1617. - (void)setUInt64:(uint64_t)value forKey:(int32_t)key;
  1618. /**
  1619. * Removes the entry for the given key.
  1620. *
  1621. * @param aKey Key to be removed from this dictionary.
  1622. **/
  1623. - (void)removeUInt64ForKey:(int32_t)aKey;
  1624. /**
  1625. * Removes all entries in this dictionary.
  1626. **/
  1627. - (void)removeAll;
  1628. @end
  1629. #pragma mark - Int32 -> Int64
  1630. /**
  1631. * Class used for map fields of <int32_t, int64_t>
  1632. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  1633. *
  1634. * @note This class is not meant to be subclassed.
  1635. **/
  1636. @interface GPBInt32Int64Dictionary : NSObject <NSCopying>
  1637. /** Number of entries stored in this dictionary. */
  1638. @property(nonatomic, readonly) NSUInteger count;
  1639. /**
  1640. * @return A newly instanced and empty dictionary.
  1641. **/
  1642. + (instancetype)dictionary;
  1643. /**
  1644. * Creates and initializes a dictionary with the single entry given.
  1645. *
  1646. * @param value The value to be placed in the dictionary.
  1647. * @param key The key under which to store the value.
  1648. *
  1649. * @return A newly instanced dictionary with the key and value in it.
  1650. **/
  1651. + (instancetype)dictionaryWithInt64:(int64_t)value
  1652. forKey:(int32_t)key;
  1653. /**
  1654. * Creates and initializes a dictionary with the entries given.
  1655. *
  1656. * @param values The values to be placed in the dictionary.
  1657. * @param keys The keys under which to store the values.
  1658. * @param count The number of entries to store in the dictionary.
  1659. *
  1660. * @return A newly instanced dictionary with the keys and values in it.
  1661. **/
  1662. + (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
  1663. forKeys:(const int32_t [__nullable])keys
  1664. count:(NSUInteger)count;
  1665. /**
  1666. * Creates and initializes a dictionary with the entries from the given.
  1667. * dictionary.
  1668. *
  1669. * @param dictionary Dictionary containing the entries to add to the dictionary.
  1670. *
  1671. * @return A newly instanced dictionary with the entries from the given
  1672. * dictionary in it.
  1673. **/
  1674. + (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary;
  1675. /**
  1676. * Creates and initializes a dictionary with the given capacity.
  1677. *
  1678. * @param numItems Capacity needed for the dictionary.
  1679. *
  1680. * @return A newly instanced dictionary with the given capacity.
  1681. **/
  1682. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  1683. /**
  1684. * Initializes this dictionary, copying the given values and keys.
  1685. *
  1686. * @param values The values to be placed in this dictionary.
  1687. * @param keys The keys under which to store the values.
  1688. * @param count The number of elements to copy into the dictionary.
  1689. *
  1690. * @return A newly initialized dictionary with a copy of the values and keys.
  1691. **/
  1692. - (instancetype)initWithInt64s:(const int64_t [__nullable])values
  1693. forKeys:(const int32_t [__nullable])keys
  1694. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  1695. /**
  1696. * Initializes this dictionary, copying the entries from the given dictionary.
  1697. *
  1698. * @param dictionary Dictionary containing the entries to add to this dictionary.
  1699. *
  1700. * @return A newly initialized dictionary with the entries of the given dictionary.
  1701. **/
  1702. - (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary;
  1703. /**
  1704. * Initializes this dictionary with the requested capacity.
  1705. *
  1706. * @param numItems Number of items needed for this dictionary.
  1707. *
  1708. * @return A newly initialized dictionary with the requested capacity.
  1709. **/
  1710. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  1711. /**
  1712. * Gets the value for the given key.
  1713. *
  1714. * @param value Pointer into which the value will be set, if found.
  1715. * @param key Key under which the value is stored, if present.
  1716. *
  1717. * @return YES if the key was found and the value was copied, NO otherwise.
  1718. **/
  1719. - (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key;
  1720. /**
  1721. * Enumerates the keys and values on this dictionary with the given block.
  1722. *
  1723. * @param block The block to enumerate with.
  1724. * **key**: The key for the current entry.
  1725. * **value**: The value for the current entry
  1726. * **stop**: A pointer to a boolean that when set stops the enumeration.
  1727. **/
  1728. - (void)enumerateKeysAndInt64sUsingBlock:
  1729. (void (^)(int32_t key, int64_t value, BOOL *stop))block;
  1730. /**
  1731. * Adds the keys and values from another dictionary.
  1732. *
  1733. * @param otherDictionary Dictionary containing entries to be added to this
  1734. * dictionary.
  1735. **/
  1736. - (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary;
  1737. /**
  1738. * Sets the value for the given key.
  1739. *
  1740. * @param value The value to set.
  1741. * @param key The key under which to store the value.
  1742. **/
  1743. - (void)setInt64:(int64_t)value forKey:(int32_t)key;
  1744. /**
  1745. * Removes the entry for the given key.
  1746. *
  1747. * @param aKey Key to be removed from this dictionary.
  1748. **/
  1749. - (void)removeInt64ForKey:(int32_t)aKey;
  1750. /**
  1751. * Removes all entries in this dictionary.
  1752. **/
  1753. - (void)removeAll;
  1754. @end
  1755. #pragma mark - Int32 -> Bool
  1756. /**
  1757. * Class used for map fields of <int32_t, BOOL>
  1758. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  1759. *
  1760. * @note This class is not meant to be subclassed.
  1761. **/
  1762. @interface GPBInt32BoolDictionary : NSObject <NSCopying>
  1763. /** Number of entries stored in this dictionary. */
  1764. @property(nonatomic, readonly) NSUInteger count;
  1765. /**
  1766. * @return A newly instanced and empty dictionary.
  1767. **/
  1768. + (instancetype)dictionary;
  1769. /**
  1770. * Creates and initializes a dictionary with the single entry given.
  1771. *
  1772. * @param value The value to be placed in the dictionary.
  1773. * @param key The key under which to store the value.
  1774. *
  1775. * @return A newly instanced dictionary with the key and value in it.
  1776. **/
  1777. + (instancetype)dictionaryWithBool:(BOOL)value
  1778. forKey:(int32_t)key;
  1779. /**
  1780. * Creates and initializes a dictionary with the entries given.
  1781. *
  1782. * @param values The values to be placed in the dictionary.
  1783. * @param keys The keys under which to store the values.
  1784. * @param count The number of entries to store in the dictionary.
  1785. *
  1786. * @return A newly instanced dictionary with the keys and values in it.
  1787. **/
  1788. + (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
  1789. forKeys:(const int32_t [__nullable])keys
  1790. count:(NSUInteger)count;
  1791. /**
  1792. * Creates and initializes a dictionary with the entries from the given.
  1793. * dictionary.
  1794. *
  1795. * @param dictionary Dictionary containing the entries to add to the dictionary.
  1796. *
  1797. * @return A newly instanced dictionary with the entries from the given
  1798. * dictionary in it.
  1799. **/
  1800. + (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary;
  1801. /**
  1802. * Creates and initializes a dictionary with the given capacity.
  1803. *
  1804. * @param numItems Capacity needed for the dictionary.
  1805. *
  1806. * @return A newly instanced dictionary with the given capacity.
  1807. **/
  1808. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  1809. /**
  1810. * Initializes this dictionary, copying the given values and keys.
  1811. *
  1812. * @param values The values to be placed in this dictionary.
  1813. * @param keys The keys under which to store the values.
  1814. * @param count The number of elements to copy into the dictionary.
  1815. *
  1816. * @return A newly initialized dictionary with a copy of the values and keys.
  1817. **/
  1818. - (instancetype)initWithBools:(const BOOL [__nullable])values
  1819. forKeys:(const int32_t [__nullable])keys
  1820. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  1821. /**
  1822. * Initializes this dictionary, copying the entries from the given dictionary.
  1823. *
  1824. * @param dictionary Dictionary containing the entries to add to this dictionary.
  1825. *
  1826. * @return A newly initialized dictionary with the entries of the given dictionary.
  1827. **/
  1828. - (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary;
  1829. /**
  1830. * Initializes this dictionary with the requested capacity.
  1831. *
  1832. * @param numItems Number of items needed for this dictionary.
  1833. *
  1834. * @return A newly initialized dictionary with the requested capacity.
  1835. **/
  1836. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  1837. /**
  1838. * Gets the value for the given key.
  1839. *
  1840. * @param value Pointer into which the value will be set, if found.
  1841. * @param key Key under which the value is stored, if present.
  1842. *
  1843. * @return YES if the key was found and the value was copied, NO otherwise.
  1844. **/
  1845. - (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key;
  1846. /**
  1847. * Enumerates the keys and values on this dictionary with the given block.
  1848. *
  1849. * @param block The block to enumerate with.
  1850. * **key**: The key for the current entry.
  1851. * **value**: The value for the current entry
  1852. * **stop**: A pointer to a boolean that when set stops the enumeration.
  1853. **/
  1854. - (void)enumerateKeysAndBoolsUsingBlock:
  1855. (void (^)(int32_t key, BOOL value, BOOL *stop))block;
  1856. /**
  1857. * Adds the keys and values from another dictionary.
  1858. *
  1859. * @param otherDictionary Dictionary containing entries to be added to this
  1860. * dictionary.
  1861. **/
  1862. - (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary;
  1863. /**
  1864. * Sets the value for the given key.
  1865. *
  1866. * @param value The value to set.
  1867. * @param key The key under which to store the value.
  1868. **/
  1869. - (void)setBool:(BOOL)value forKey:(int32_t)key;
  1870. /**
  1871. * Removes the entry for the given key.
  1872. *
  1873. * @param aKey Key to be removed from this dictionary.
  1874. **/
  1875. - (void)removeBoolForKey:(int32_t)aKey;
  1876. /**
  1877. * Removes all entries in this dictionary.
  1878. **/
  1879. - (void)removeAll;
  1880. @end
  1881. #pragma mark - Int32 -> Float
  1882. /**
  1883. * Class used for map fields of <int32_t, float>
  1884. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  1885. *
  1886. * @note This class is not meant to be subclassed.
  1887. **/
  1888. @interface GPBInt32FloatDictionary : NSObject <NSCopying>
  1889. /** Number of entries stored in this dictionary. */
  1890. @property(nonatomic, readonly) NSUInteger count;
  1891. /**
  1892. * @return A newly instanced and empty dictionary.
  1893. **/
  1894. + (instancetype)dictionary;
  1895. /**
  1896. * Creates and initializes a dictionary with the single entry given.
  1897. *
  1898. * @param value The value to be placed in the dictionary.
  1899. * @param key The key under which to store the value.
  1900. *
  1901. * @return A newly instanced dictionary with the key and value in it.
  1902. **/
  1903. + (instancetype)dictionaryWithFloat:(float)value
  1904. forKey:(int32_t)key;
  1905. /**
  1906. * Creates and initializes a dictionary with the entries given.
  1907. *
  1908. * @param values The values to be placed in the dictionary.
  1909. * @param keys The keys under which to store the values.
  1910. * @param count The number of entries to store in the dictionary.
  1911. *
  1912. * @return A newly instanced dictionary with the keys and values in it.
  1913. **/
  1914. + (instancetype)dictionaryWithFloats:(const float [__nullable])values
  1915. forKeys:(const int32_t [__nullable])keys
  1916. count:(NSUInteger)count;
  1917. /**
  1918. * Creates and initializes a dictionary with the entries from the given.
  1919. * dictionary.
  1920. *
  1921. * @param dictionary Dictionary containing the entries to add to the dictionary.
  1922. *
  1923. * @return A newly instanced dictionary with the entries from the given
  1924. * dictionary in it.
  1925. **/
  1926. + (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary;
  1927. /**
  1928. * Creates and initializes a dictionary with the given capacity.
  1929. *
  1930. * @param numItems Capacity needed for the dictionary.
  1931. *
  1932. * @return A newly instanced dictionary with the given capacity.
  1933. **/
  1934. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  1935. /**
  1936. * Initializes this dictionary, copying the given values and keys.
  1937. *
  1938. * @param values The values to be placed in this dictionary.
  1939. * @param keys The keys under which to store the values.
  1940. * @param count The number of elements to copy into the dictionary.
  1941. *
  1942. * @return A newly initialized dictionary with a copy of the values and keys.
  1943. **/
  1944. - (instancetype)initWithFloats:(const float [__nullable])values
  1945. forKeys:(const int32_t [__nullable])keys
  1946. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  1947. /**
  1948. * Initializes this dictionary, copying the entries from the given dictionary.
  1949. *
  1950. * @param dictionary Dictionary containing the entries to add to this dictionary.
  1951. *
  1952. * @return A newly initialized dictionary with the entries of the given dictionary.
  1953. **/
  1954. - (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary;
  1955. /**
  1956. * Initializes this dictionary with the requested capacity.
  1957. *
  1958. * @param numItems Number of items needed for this dictionary.
  1959. *
  1960. * @return A newly initialized dictionary with the requested capacity.
  1961. **/
  1962. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  1963. /**
  1964. * Gets the value for the given key.
  1965. *
  1966. * @param value Pointer into which the value will be set, if found.
  1967. * @param key Key under which the value is stored, if present.
  1968. *
  1969. * @return YES if the key was found and the value was copied, NO otherwise.
  1970. **/
  1971. - (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key;
  1972. /**
  1973. * Enumerates the keys and values on this dictionary with the given block.
  1974. *
  1975. * @param block The block to enumerate with.
  1976. * **key**: The key for the current entry.
  1977. * **value**: The value for the current entry
  1978. * **stop**: A pointer to a boolean that when set stops the enumeration.
  1979. **/
  1980. - (void)enumerateKeysAndFloatsUsingBlock:
  1981. (void (^)(int32_t key, float value, BOOL *stop))block;
  1982. /**
  1983. * Adds the keys and values from another dictionary.
  1984. *
  1985. * @param otherDictionary Dictionary containing entries to be added to this
  1986. * dictionary.
  1987. **/
  1988. - (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary;
  1989. /**
  1990. * Sets the value for the given key.
  1991. *
  1992. * @param value The value to set.
  1993. * @param key The key under which to store the value.
  1994. **/
  1995. - (void)setFloat:(float)value forKey:(int32_t)key;
  1996. /**
  1997. * Removes the entry for the given key.
  1998. *
  1999. * @param aKey Key to be removed from this dictionary.
  2000. **/
  2001. - (void)removeFloatForKey:(int32_t)aKey;
  2002. /**
  2003. * Removes all entries in this dictionary.
  2004. **/
  2005. - (void)removeAll;
  2006. @end
  2007. #pragma mark - Int32 -> Double
  2008. /**
  2009. * Class used for map fields of <int32_t, double>
  2010. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  2011. *
  2012. * @note This class is not meant to be subclassed.
  2013. **/
  2014. @interface GPBInt32DoubleDictionary : NSObject <NSCopying>
  2015. /** Number of entries stored in this dictionary. */
  2016. @property(nonatomic, readonly) NSUInteger count;
  2017. /**
  2018. * @return A newly instanced and empty dictionary.
  2019. **/
  2020. + (instancetype)dictionary;
  2021. /**
  2022. * Creates and initializes a dictionary with the single entry given.
  2023. *
  2024. * @param value The value to be placed in the dictionary.
  2025. * @param key The key under which to store the value.
  2026. *
  2027. * @return A newly instanced dictionary with the key and value in it.
  2028. **/
  2029. + (instancetype)dictionaryWithDouble:(double)value
  2030. forKey:(int32_t)key;
  2031. /**
  2032. * Creates and initializes a dictionary with the entries given.
  2033. *
  2034. * @param values The values to be placed in the dictionary.
  2035. * @param keys The keys under which to store the values.
  2036. * @param count The number of entries to store in the dictionary.
  2037. *
  2038. * @return A newly instanced dictionary with the keys and values in it.
  2039. **/
  2040. + (instancetype)dictionaryWithDoubles:(const double [__nullable])values
  2041. forKeys:(const int32_t [__nullable])keys
  2042. count:(NSUInteger)count;
  2043. /**
  2044. * Creates and initializes a dictionary with the entries from the given.
  2045. * dictionary.
  2046. *
  2047. * @param dictionary Dictionary containing the entries to add to the dictionary.
  2048. *
  2049. * @return A newly instanced dictionary with the entries from the given
  2050. * dictionary in it.
  2051. **/
  2052. + (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary;
  2053. /**
  2054. * Creates and initializes a dictionary with the given capacity.
  2055. *
  2056. * @param numItems Capacity needed for the dictionary.
  2057. *
  2058. * @return A newly instanced dictionary with the given capacity.
  2059. **/
  2060. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  2061. /**
  2062. * Initializes this dictionary, copying the given values and keys.
  2063. *
  2064. * @param values The values to be placed in this dictionary.
  2065. * @param keys The keys under which to store the values.
  2066. * @param count The number of elements to copy into the dictionary.
  2067. *
  2068. * @return A newly initialized dictionary with a copy of the values and keys.
  2069. **/
  2070. - (instancetype)initWithDoubles:(const double [__nullable])values
  2071. forKeys:(const int32_t [__nullable])keys
  2072. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  2073. /**
  2074. * Initializes this dictionary, copying the entries from the given dictionary.
  2075. *
  2076. * @param dictionary Dictionary containing the entries to add to this dictionary.
  2077. *
  2078. * @return A newly initialized dictionary with the entries of the given dictionary.
  2079. **/
  2080. - (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary;
  2081. /**
  2082. * Initializes this dictionary with the requested capacity.
  2083. *
  2084. * @param numItems Number of items needed for this dictionary.
  2085. *
  2086. * @return A newly initialized dictionary with the requested capacity.
  2087. **/
  2088. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  2089. /**
  2090. * Gets the value for the given key.
  2091. *
  2092. * @param value Pointer into which the value will be set, if found.
  2093. * @param key Key under which the value is stored, if present.
  2094. *
  2095. * @return YES if the key was found and the value was copied, NO otherwise.
  2096. **/
  2097. - (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key;
  2098. /**
  2099. * Enumerates the keys and values on this dictionary with the given block.
  2100. *
  2101. * @param block The block to enumerate with.
  2102. * **key**: The key for the current entry.
  2103. * **value**: The value for the current entry
  2104. * **stop**: A pointer to a boolean that when set stops the enumeration.
  2105. **/
  2106. - (void)enumerateKeysAndDoublesUsingBlock:
  2107. (void (^)(int32_t key, double value, BOOL *stop))block;
  2108. /**
  2109. * Adds the keys and values from another dictionary.
  2110. *
  2111. * @param otherDictionary Dictionary containing entries to be added to this
  2112. * dictionary.
  2113. **/
  2114. - (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary;
  2115. /**
  2116. * Sets the value for the given key.
  2117. *
  2118. * @param value The value to set.
  2119. * @param key The key under which to store the value.
  2120. **/
  2121. - (void)setDouble:(double)value forKey:(int32_t)key;
  2122. /**
  2123. * Removes the entry for the given key.
  2124. *
  2125. * @param aKey Key to be removed from this dictionary.
  2126. **/
  2127. - (void)removeDoubleForKey:(int32_t)aKey;
  2128. /**
  2129. * Removes all entries in this dictionary.
  2130. **/
  2131. - (void)removeAll;
  2132. @end
  2133. #pragma mark - Int32 -> Enum
  2134. /**
  2135. * Class used for map fields of <int32_t, int32_t>
  2136. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  2137. *
  2138. * @note This class is not meant to be subclassed.
  2139. **/
  2140. @interface GPBInt32EnumDictionary : NSObject <NSCopying>
  2141. /** Number of entries stored in this dictionary. */
  2142. @property(nonatomic, readonly) NSUInteger count;
  2143. /** The validation function to check if the enums are valid. */
  2144. @property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
  2145. /**
  2146. * @return A newly instanced and empty dictionary.
  2147. **/
  2148. + (instancetype)dictionary;
  2149. /**
  2150. * Creates and initializes a dictionary with the given validation function.
  2151. *
  2152. * @param func The enum validation function for the dictionary.
  2153. *
  2154. * @return A newly instanced dictionary.
  2155. **/
  2156. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  2157. /**
  2158. * Creates and initializes a dictionary with the single entry given.
  2159. *
  2160. * @param func The enum validation function for the dictionary.
  2161. * @param rawValue The raw enum value to be placed in the dictionary.
  2162. * @param key The key under which to store the value.
  2163. *
  2164. * @return A newly instanced dictionary with the key and value in it.
  2165. **/
  2166. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  2167. rawValue:(int32_t)rawValue
  2168. forKey:(int32_t)key;
  2169. /**
  2170. * Creates and initializes a dictionary with the entries given.
  2171. *
  2172. * @param func The enum validation function for the dictionary.
  2173. * @param values The raw enum values values to be placed in the dictionary.
  2174. * @param keys The keys under which to store the values.
  2175. * @param count The number of entries to store in the dictionary.
  2176. *
  2177. * @return A newly instanced dictionary with the keys and values in it.
  2178. **/
  2179. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  2180. rawValues:(const int32_t [__nullable])values
  2181. forKeys:(const int32_t [__nullable])keys
  2182. count:(NSUInteger)count;
  2183. /**
  2184. * Creates and initializes a dictionary with the entries from the given.
  2185. * dictionary.
  2186. *
  2187. * @param dictionary Dictionary containing the entries to add to the dictionary.
  2188. *
  2189. * @return A newly instanced dictionary with the entries from the given
  2190. * dictionary in it.
  2191. **/
  2192. + (instancetype)dictionaryWithDictionary:(GPBInt32EnumDictionary *)dictionary;
  2193. /**
  2194. * Creates and initializes a dictionary with the given capacity.
  2195. *
  2196. * @param func The enum validation function for the dictionary.
  2197. * @param numItems Capacity needed for the dictionary.
  2198. *
  2199. * @return A newly instanced dictionary with the given capacity.
  2200. **/
  2201. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  2202. capacity:(NSUInteger)numItems;
  2203. /**
  2204. * Initializes a dictionary with the given validation function.
  2205. *
  2206. * @param func The enum validation function for the dictionary.
  2207. *
  2208. * @return A newly initialized dictionary.
  2209. **/
  2210. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  2211. /**
  2212. * Initializes a dictionary with the entries given.
  2213. *
  2214. * @param func The enum validation function for the dictionary.
  2215. * @param values The raw enum values values to be placed in the dictionary.
  2216. * @param keys The keys under which to store the values.
  2217. * @param count The number of entries to store in the dictionary.
  2218. *
  2219. * @return A newly initialized dictionary with the keys and values in it.
  2220. **/
  2221. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  2222. rawValues:(const int32_t [__nullable])values
  2223. forKeys:(const int32_t [__nullable])keys
  2224. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  2225. /**
  2226. * Initializes a dictionary with the entries from the given.
  2227. * dictionary.
  2228. *
  2229. * @param dictionary Dictionary containing the entries to add to the dictionary.
  2230. *
  2231. * @return A newly initialized dictionary with the entries from the given
  2232. * dictionary in it.
  2233. **/
  2234. - (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary;
  2235. /**
  2236. * Initializes a dictionary with the given capacity.
  2237. *
  2238. * @param func The enum validation function for the dictionary.
  2239. * @param numItems Capacity needed for the dictionary.
  2240. *
  2241. * @return A newly initialized dictionary with the given capacity.
  2242. **/
  2243. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  2244. capacity:(NSUInteger)numItems;
  2245. // These will return kGPBUnrecognizedEnumeratorValue if the value for the key
  2246. // is not a valid enumerator as defined by validationFunc. If the actual value is
  2247. // desired, use "raw" version of the method.
  2248. /**
  2249. * Gets the value for the given key.
  2250. *
  2251. * @param value Pointer into which the value will be set, if found.
  2252. * @param key Key under which the value is stored, if present.
  2253. *
  2254. * @return YES if the key was found and the value was copied, NO otherwise.
  2255. **/
  2256. - (BOOL)getEnum:(nullable int32_t *)value forKey:(int32_t)key;
  2257. /**
  2258. * Enumerates the keys and values on this dictionary with the given block.
  2259. *
  2260. * @param block The block to enumerate with.
  2261. * **key**: The key for the current entry.
  2262. * **value**: The value for the current entry
  2263. * **stop**: A pointer to a boolean that when set stops the enumeration.
  2264. **/
  2265. - (void)enumerateKeysAndEnumsUsingBlock:
  2266. (void (^)(int32_t key, int32_t value, BOOL *stop))block;
  2267. /**
  2268. * Gets the raw enum value for the given key.
  2269. *
  2270. * @note This method bypass the validationFunc to enable the access of values that
  2271. * were not known at the time the binary was compiled.
  2272. *
  2273. * @param rawValue Pointer into which the value will be set, if found.
  2274. * @param key Key under which the value is stored, if present.
  2275. *
  2276. * @return YES if the key was found and the value was copied, NO otherwise.
  2277. **/
  2278. - (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(int32_t)key;
  2279. /**
  2280. * Enumerates the keys and values on this dictionary with the given block.
  2281. *
  2282. * @note This method bypass the validationFunc to enable the access of values that
  2283. * were not known at the time the binary was compiled.
  2284. *
  2285. * @param block The block to enumerate with.
  2286. * **key**: The key for the current entry.
  2287. * **rawValue**: The value for the current entry
  2288. * **stop**: A pointer to a boolean that when set stops the enumeration.
  2289. **/
  2290. - (void)enumerateKeysAndRawValuesUsingBlock:
  2291. (void (^)(int32_t key, int32_t rawValue, BOOL *stop))block;
  2292. /**
  2293. * Adds the keys and raw enum values from another dictionary.
  2294. *
  2295. * @note This method bypass the validationFunc to enable the setting of values that
  2296. * were not known at the time the binary was compiled.
  2297. *
  2298. * @param otherDictionary Dictionary containing entries to be added to this
  2299. * dictionary.
  2300. **/
  2301. - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary;
  2302. // If value is not a valid enumerator as defined by validationFunc, these
  2303. // methods will assert in debug, and will log in release and assign the value
  2304. // to the default value. Use the rawValue methods below to assign non enumerator
  2305. // values.
  2306. /**
  2307. * Sets the value for the given key.
  2308. *
  2309. * @param value The value to set.
  2310. * @param key The key under which to store the value.
  2311. **/
  2312. - (void)setEnum:(int32_t)value forKey:(int32_t)key;
  2313. /**
  2314. * Sets the raw enum value for the given key.
  2315. *
  2316. * @note This method bypass the validationFunc to enable the setting of values that
  2317. * were not known at the time the binary was compiled.
  2318. *
  2319. * @param rawValue The raw enum value to set.
  2320. * @param key The key under which to store the raw enum value.
  2321. **/
  2322. - (void)setRawValue:(int32_t)rawValue forKey:(int32_t)key;
  2323. /**
  2324. * Removes the entry for the given key.
  2325. *
  2326. * @param aKey Key to be removed from this dictionary.
  2327. **/
  2328. - (void)removeEnumForKey:(int32_t)aKey;
  2329. /**
  2330. * Removes all entries in this dictionary.
  2331. **/
  2332. - (void)removeAll;
  2333. @end
  2334. #pragma mark - Int32 -> Object
  2335. /**
  2336. * Class used for map fields of <int32_t, ObjectType>
  2337. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  2338. *
  2339. * @note This class is not meant to be subclassed.
  2340. **/
  2341. @interface GPBInt32ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
  2342. /** Number of entries stored in this dictionary. */
  2343. @property(nonatomic, readonly) NSUInteger count;
  2344. /**
  2345. * @return A newly instanced and empty dictionary.
  2346. **/
  2347. + (instancetype)dictionary;
  2348. /**
  2349. * Creates and initializes a dictionary with the single entry given.
  2350. *
  2351. * @param object The value to be placed in the dictionary.
  2352. * @param key The key under which to store the value.
  2353. *
  2354. * @return A newly instanced dictionary with the key and value in it.
  2355. **/
  2356. + (instancetype)dictionaryWithObject:(ObjectType)object
  2357. forKey:(int32_t)key;
  2358. /**
  2359. * Creates and initializes a dictionary with the entries given.
  2360. *
  2361. * @param objects The values to be placed in the dictionary.
  2362. * @param keys The keys under which to store the values.
  2363. * @param count The number of entries to store in the dictionary.
  2364. *
  2365. * @return A newly instanced dictionary with the keys and values in it.
  2366. **/
  2367. + (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
  2368. forKeys:(const int32_t [__nullable])keys
  2369. count:(NSUInteger)count;
  2370. /**
  2371. * Creates and initializes a dictionary with the entries from the given.
  2372. * dictionary.
  2373. *
  2374. * @param dictionary Dictionary containing the entries to add to the dictionary.
  2375. *
  2376. * @return A newly instanced dictionary with the entries from the given
  2377. * dictionary in it.
  2378. **/
  2379. + (instancetype)dictionaryWithDictionary:(GPBInt32ObjectDictionary *)dictionary;
  2380. /**
  2381. * Creates and initializes a dictionary with the given capacity.
  2382. *
  2383. * @param numItems Capacity needed for the dictionary.
  2384. *
  2385. * @return A newly instanced dictionary with the given capacity.
  2386. **/
  2387. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  2388. /**
  2389. * Initializes this dictionary, copying the given values and keys.
  2390. *
  2391. * @param objects The values to be placed in this dictionary.
  2392. * @param keys The keys under which to store the values.
  2393. * @param count The number of elements to copy into the dictionary.
  2394. *
  2395. * @return A newly initialized dictionary with a copy of the values and keys.
  2396. **/
  2397. - (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
  2398. forKeys:(const int32_t [__nullable])keys
  2399. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  2400. /**
  2401. * Initializes this dictionary, copying the entries from the given dictionary.
  2402. *
  2403. * @param dictionary Dictionary containing the entries to add to this dictionary.
  2404. *
  2405. * @return A newly initialized dictionary with the entries of the given dictionary.
  2406. **/
  2407. - (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary;
  2408. /**
  2409. * Initializes this dictionary with the requested capacity.
  2410. *
  2411. * @param numItems Number of items needed for this dictionary.
  2412. *
  2413. * @return A newly initialized dictionary with the requested capacity.
  2414. **/
  2415. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  2416. /**
  2417. * Fetches the object stored under the given key.
  2418. *
  2419. * @param key Key under which the value is stored, if present.
  2420. *
  2421. * @return The object if found, nil otherwise.
  2422. **/
  2423. - (ObjectType)objectForKey:(int32_t)key;
  2424. /**
  2425. * Enumerates the keys and values on this dictionary with the given block.
  2426. *
  2427. * @param block The block to enumerate with.
  2428. * **key**: The key for the current entry.
  2429. * **object**: The value for the current entry
  2430. * **stop**: A pointer to a boolean that when set stops the enumeration.
  2431. **/
  2432. - (void)enumerateKeysAndObjectsUsingBlock:
  2433. (void (^)(int32_t key, ObjectType object, BOOL *stop))block;
  2434. /**
  2435. * Adds the keys and values from another dictionary.
  2436. *
  2437. * @param otherDictionary Dictionary containing entries to be added to this
  2438. * dictionary.
  2439. **/
  2440. - (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary;
  2441. /**
  2442. * Sets the value for the given key.
  2443. *
  2444. * @param object The value to set.
  2445. * @param key The key under which to store the value.
  2446. **/
  2447. - (void)setObject:(ObjectType)object forKey:(int32_t)key;
  2448. /**
  2449. * Removes the entry for the given key.
  2450. *
  2451. * @param aKey Key to be removed from this dictionary.
  2452. **/
  2453. - (void)removeObjectForKey:(int32_t)aKey;
  2454. /**
  2455. * Removes all entries in this dictionary.
  2456. **/
  2457. - (void)removeAll;
  2458. @end
  2459. #pragma mark - UInt64 -> UInt32
  2460. /**
  2461. * Class used for map fields of <uint64_t, uint32_t>
  2462. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  2463. *
  2464. * @note This class is not meant to be subclassed.
  2465. **/
  2466. @interface GPBUInt64UInt32Dictionary : NSObject <NSCopying>
  2467. /** Number of entries stored in this dictionary. */
  2468. @property(nonatomic, readonly) NSUInteger count;
  2469. /**
  2470. * @return A newly instanced and empty dictionary.
  2471. **/
  2472. + (instancetype)dictionary;
  2473. /**
  2474. * Creates and initializes a dictionary with the single entry given.
  2475. *
  2476. * @param value The value to be placed in the dictionary.
  2477. * @param key The key under which to store the value.
  2478. *
  2479. * @return A newly instanced dictionary with the key and value in it.
  2480. **/
  2481. + (instancetype)dictionaryWithUInt32:(uint32_t)value
  2482. forKey:(uint64_t)key;
  2483. /**
  2484. * Creates and initializes a dictionary with the entries given.
  2485. *
  2486. * @param values The values to be placed in the dictionary.
  2487. * @param keys The keys under which to store the values.
  2488. * @param count The number of entries to store in the dictionary.
  2489. *
  2490. * @return A newly instanced dictionary with the keys and values in it.
  2491. **/
  2492. + (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
  2493. forKeys:(const uint64_t [__nullable])keys
  2494. count:(NSUInteger)count;
  2495. /**
  2496. * Creates and initializes a dictionary with the entries from the given.
  2497. * dictionary.
  2498. *
  2499. * @param dictionary Dictionary containing the entries to add to the dictionary.
  2500. *
  2501. * @return A newly instanced dictionary with the entries from the given
  2502. * dictionary in it.
  2503. **/
  2504. + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary;
  2505. /**
  2506. * Creates and initializes a dictionary with the given capacity.
  2507. *
  2508. * @param numItems Capacity needed for the dictionary.
  2509. *
  2510. * @return A newly instanced dictionary with the given capacity.
  2511. **/
  2512. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  2513. /**
  2514. * Initializes this dictionary, copying the given values and keys.
  2515. *
  2516. * @param values The values to be placed in this dictionary.
  2517. * @param keys The keys under which to store the values.
  2518. * @param count The number of elements to copy into the dictionary.
  2519. *
  2520. * @return A newly initialized dictionary with a copy of the values and keys.
  2521. **/
  2522. - (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
  2523. forKeys:(const uint64_t [__nullable])keys
  2524. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  2525. /**
  2526. * Initializes this dictionary, copying the entries from the given dictionary.
  2527. *
  2528. * @param dictionary Dictionary containing the entries to add to this dictionary.
  2529. *
  2530. * @return A newly initialized dictionary with the entries of the given dictionary.
  2531. **/
  2532. - (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary;
  2533. /**
  2534. * Initializes this dictionary with the requested capacity.
  2535. *
  2536. * @param numItems Number of items needed for this dictionary.
  2537. *
  2538. * @return A newly initialized dictionary with the requested capacity.
  2539. **/
  2540. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  2541. /**
  2542. * Gets the value for the given key.
  2543. *
  2544. * @param value Pointer into which the value will be set, if found.
  2545. * @param key Key under which the value is stored, if present.
  2546. *
  2547. * @return YES if the key was found and the value was copied, NO otherwise.
  2548. **/
  2549. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key;
  2550. /**
  2551. * Enumerates the keys and values on this dictionary with the given block.
  2552. *
  2553. * @param block The block to enumerate with.
  2554. * **key**: The key for the current entry.
  2555. * **value**: The value for the current entry
  2556. * **stop**: A pointer to a boolean that when set stops the enumeration.
  2557. **/
  2558. - (void)enumerateKeysAndUInt32sUsingBlock:
  2559. (void (^)(uint64_t key, uint32_t value, BOOL *stop))block;
  2560. /**
  2561. * Adds the keys and values from another dictionary.
  2562. *
  2563. * @param otherDictionary Dictionary containing entries to be added to this
  2564. * dictionary.
  2565. **/
  2566. - (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary;
  2567. /**
  2568. * Sets the value for the given key.
  2569. *
  2570. * @param value The value to set.
  2571. * @param key The key under which to store the value.
  2572. **/
  2573. - (void)setUInt32:(uint32_t)value forKey:(uint64_t)key;
  2574. /**
  2575. * Removes the entry for the given key.
  2576. *
  2577. * @param aKey Key to be removed from this dictionary.
  2578. **/
  2579. - (void)removeUInt32ForKey:(uint64_t)aKey;
  2580. /**
  2581. * Removes all entries in this dictionary.
  2582. **/
  2583. - (void)removeAll;
  2584. @end
  2585. #pragma mark - UInt64 -> Int32
  2586. /**
  2587. * Class used for map fields of <uint64_t, int32_t>
  2588. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  2589. *
  2590. * @note This class is not meant to be subclassed.
  2591. **/
  2592. @interface GPBUInt64Int32Dictionary : NSObject <NSCopying>
  2593. /** Number of entries stored in this dictionary. */
  2594. @property(nonatomic, readonly) NSUInteger count;
  2595. /**
  2596. * @return A newly instanced and empty dictionary.
  2597. **/
  2598. + (instancetype)dictionary;
  2599. /**
  2600. * Creates and initializes a dictionary with the single entry given.
  2601. *
  2602. * @param value The value to be placed in the dictionary.
  2603. * @param key The key under which to store the value.
  2604. *
  2605. * @return A newly instanced dictionary with the key and value in it.
  2606. **/
  2607. + (instancetype)dictionaryWithInt32:(int32_t)value
  2608. forKey:(uint64_t)key;
  2609. /**
  2610. * Creates and initializes a dictionary with the entries given.
  2611. *
  2612. * @param values The values to be placed in the dictionary.
  2613. * @param keys The keys under which to store the values.
  2614. * @param count The number of entries to store in the dictionary.
  2615. *
  2616. * @return A newly instanced dictionary with the keys and values in it.
  2617. **/
  2618. + (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
  2619. forKeys:(const uint64_t [__nullable])keys
  2620. count:(NSUInteger)count;
  2621. /**
  2622. * Creates and initializes a dictionary with the entries from the given.
  2623. * dictionary.
  2624. *
  2625. * @param dictionary Dictionary containing the entries to add to the dictionary.
  2626. *
  2627. * @return A newly instanced dictionary with the entries from the given
  2628. * dictionary in it.
  2629. **/
  2630. + (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary;
  2631. /**
  2632. * Creates and initializes a dictionary with the given capacity.
  2633. *
  2634. * @param numItems Capacity needed for the dictionary.
  2635. *
  2636. * @return A newly instanced dictionary with the given capacity.
  2637. **/
  2638. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  2639. /**
  2640. * Initializes this dictionary, copying the given values and keys.
  2641. *
  2642. * @param values The values to be placed in this dictionary.
  2643. * @param keys The keys under which to store the values.
  2644. * @param count The number of elements to copy into the dictionary.
  2645. *
  2646. * @return A newly initialized dictionary with a copy of the values and keys.
  2647. **/
  2648. - (instancetype)initWithInt32s:(const int32_t [__nullable])values
  2649. forKeys:(const uint64_t [__nullable])keys
  2650. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  2651. /**
  2652. * Initializes this dictionary, copying the entries from the given dictionary.
  2653. *
  2654. * @param dictionary Dictionary containing the entries to add to this dictionary.
  2655. *
  2656. * @return A newly initialized dictionary with the entries of the given dictionary.
  2657. **/
  2658. - (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary;
  2659. /**
  2660. * Initializes this dictionary with the requested capacity.
  2661. *
  2662. * @param numItems Number of items needed for this dictionary.
  2663. *
  2664. * @return A newly initialized dictionary with the requested capacity.
  2665. **/
  2666. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  2667. /**
  2668. * Gets the value for the given key.
  2669. *
  2670. * @param value Pointer into which the value will be set, if found.
  2671. * @param key Key under which the value is stored, if present.
  2672. *
  2673. * @return YES if the key was found and the value was copied, NO otherwise.
  2674. **/
  2675. - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key;
  2676. /**
  2677. * Enumerates the keys and values on this dictionary with the given block.
  2678. *
  2679. * @param block The block to enumerate with.
  2680. * **key**: The key for the current entry.
  2681. * **value**: The value for the current entry
  2682. * **stop**: A pointer to a boolean that when set stops the enumeration.
  2683. **/
  2684. - (void)enumerateKeysAndInt32sUsingBlock:
  2685. (void (^)(uint64_t key, int32_t value, BOOL *stop))block;
  2686. /**
  2687. * Adds the keys and values from another dictionary.
  2688. *
  2689. * @param otherDictionary Dictionary containing entries to be added to this
  2690. * dictionary.
  2691. **/
  2692. - (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary;
  2693. /**
  2694. * Sets the value for the given key.
  2695. *
  2696. * @param value The value to set.
  2697. * @param key The key under which to store the value.
  2698. **/
  2699. - (void)setInt32:(int32_t)value forKey:(uint64_t)key;
  2700. /**
  2701. * Removes the entry for the given key.
  2702. *
  2703. * @param aKey Key to be removed from this dictionary.
  2704. **/
  2705. - (void)removeInt32ForKey:(uint64_t)aKey;
  2706. /**
  2707. * Removes all entries in this dictionary.
  2708. **/
  2709. - (void)removeAll;
  2710. @end
  2711. #pragma mark - UInt64 -> UInt64
  2712. /**
  2713. * Class used for map fields of <uint64_t, uint64_t>
  2714. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  2715. *
  2716. * @note This class is not meant to be subclassed.
  2717. **/
  2718. @interface GPBUInt64UInt64Dictionary : NSObject <NSCopying>
  2719. /** Number of entries stored in this dictionary. */
  2720. @property(nonatomic, readonly) NSUInteger count;
  2721. /**
  2722. * @return A newly instanced and empty dictionary.
  2723. **/
  2724. + (instancetype)dictionary;
  2725. /**
  2726. * Creates and initializes a dictionary with the single entry given.
  2727. *
  2728. * @param value The value to be placed in the dictionary.
  2729. * @param key The key under which to store the value.
  2730. *
  2731. * @return A newly instanced dictionary with the key and value in it.
  2732. **/
  2733. + (instancetype)dictionaryWithUInt64:(uint64_t)value
  2734. forKey:(uint64_t)key;
  2735. /**
  2736. * Creates and initializes a dictionary with the entries given.
  2737. *
  2738. * @param values The values to be placed in the dictionary.
  2739. * @param keys The keys under which to store the values.
  2740. * @param count The number of entries to store in the dictionary.
  2741. *
  2742. * @return A newly instanced dictionary with the keys and values in it.
  2743. **/
  2744. + (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
  2745. forKeys:(const uint64_t [__nullable])keys
  2746. count:(NSUInteger)count;
  2747. /**
  2748. * Creates and initializes a dictionary with the entries from the given.
  2749. * dictionary.
  2750. *
  2751. * @param dictionary Dictionary containing the entries to add to the dictionary.
  2752. *
  2753. * @return A newly instanced dictionary with the entries from the given
  2754. * dictionary in it.
  2755. **/
  2756. + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary;
  2757. /**
  2758. * Creates and initializes a dictionary with the given capacity.
  2759. *
  2760. * @param numItems Capacity needed for the dictionary.
  2761. *
  2762. * @return A newly instanced dictionary with the given capacity.
  2763. **/
  2764. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  2765. /**
  2766. * Initializes this dictionary, copying the given values and keys.
  2767. *
  2768. * @param values The values to be placed in this dictionary.
  2769. * @param keys The keys under which to store the values.
  2770. * @param count The number of elements to copy into the dictionary.
  2771. *
  2772. * @return A newly initialized dictionary with a copy of the values and keys.
  2773. **/
  2774. - (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
  2775. forKeys:(const uint64_t [__nullable])keys
  2776. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  2777. /**
  2778. * Initializes this dictionary, copying the entries from the given dictionary.
  2779. *
  2780. * @param dictionary Dictionary containing the entries to add to this dictionary.
  2781. *
  2782. * @return A newly initialized dictionary with the entries of the given dictionary.
  2783. **/
  2784. - (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary;
  2785. /**
  2786. * Initializes this dictionary with the requested capacity.
  2787. *
  2788. * @param numItems Number of items needed for this dictionary.
  2789. *
  2790. * @return A newly initialized dictionary with the requested capacity.
  2791. **/
  2792. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  2793. /**
  2794. * Gets the value for the given key.
  2795. *
  2796. * @param value Pointer into which the value will be set, if found.
  2797. * @param key Key under which the value is stored, if present.
  2798. *
  2799. * @return YES if the key was found and the value was copied, NO otherwise.
  2800. **/
  2801. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key;
  2802. /**
  2803. * Enumerates the keys and values on this dictionary with the given block.
  2804. *
  2805. * @param block The block to enumerate with.
  2806. * **key**: The key for the current entry.
  2807. * **value**: The value for the current entry
  2808. * **stop**: A pointer to a boolean that when set stops the enumeration.
  2809. **/
  2810. - (void)enumerateKeysAndUInt64sUsingBlock:
  2811. (void (^)(uint64_t key, uint64_t value, BOOL *stop))block;
  2812. /**
  2813. * Adds the keys and values from another dictionary.
  2814. *
  2815. * @param otherDictionary Dictionary containing entries to be added to this
  2816. * dictionary.
  2817. **/
  2818. - (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary;
  2819. /**
  2820. * Sets the value for the given key.
  2821. *
  2822. * @param value The value to set.
  2823. * @param key The key under which to store the value.
  2824. **/
  2825. - (void)setUInt64:(uint64_t)value forKey:(uint64_t)key;
  2826. /**
  2827. * Removes the entry for the given key.
  2828. *
  2829. * @param aKey Key to be removed from this dictionary.
  2830. **/
  2831. - (void)removeUInt64ForKey:(uint64_t)aKey;
  2832. /**
  2833. * Removes all entries in this dictionary.
  2834. **/
  2835. - (void)removeAll;
  2836. @end
  2837. #pragma mark - UInt64 -> Int64
  2838. /**
  2839. * Class used for map fields of <uint64_t, int64_t>
  2840. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  2841. *
  2842. * @note This class is not meant to be subclassed.
  2843. **/
  2844. @interface GPBUInt64Int64Dictionary : NSObject <NSCopying>
  2845. /** Number of entries stored in this dictionary. */
  2846. @property(nonatomic, readonly) NSUInteger count;
  2847. /**
  2848. * @return A newly instanced and empty dictionary.
  2849. **/
  2850. + (instancetype)dictionary;
  2851. /**
  2852. * Creates and initializes a dictionary with the single entry given.
  2853. *
  2854. * @param value The value to be placed in the dictionary.
  2855. * @param key The key under which to store the value.
  2856. *
  2857. * @return A newly instanced dictionary with the key and value in it.
  2858. **/
  2859. + (instancetype)dictionaryWithInt64:(int64_t)value
  2860. forKey:(uint64_t)key;
  2861. /**
  2862. * Creates and initializes a dictionary with the entries given.
  2863. *
  2864. * @param values The values to be placed in the dictionary.
  2865. * @param keys The keys under which to store the values.
  2866. * @param count The number of entries to store in the dictionary.
  2867. *
  2868. * @return A newly instanced dictionary with the keys and values in it.
  2869. **/
  2870. + (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
  2871. forKeys:(const uint64_t [__nullable])keys
  2872. count:(NSUInteger)count;
  2873. /**
  2874. * Creates and initializes a dictionary with the entries from the given.
  2875. * dictionary.
  2876. *
  2877. * @param dictionary Dictionary containing the entries to add to the dictionary.
  2878. *
  2879. * @return A newly instanced dictionary with the entries from the given
  2880. * dictionary in it.
  2881. **/
  2882. + (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary;
  2883. /**
  2884. * Creates and initializes a dictionary with the given capacity.
  2885. *
  2886. * @param numItems Capacity needed for the dictionary.
  2887. *
  2888. * @return A newly instanced dictionary with the given capacity.
  2889. **/
  2890. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  2891. /**
  2892. * Initializes this dictionary, copying the given values and keys.
  2893. *
  2894. * @param values The values to be placed in this dictionary.
  2895. * @param keys The keys under which to store the values.
  2896. * @param count The number of elements to copy into the dictionary.
  2897. *
  2898. * @return A newly initialized dictionary with a copy of the values and keys.
  2899. **/
  2900. - (instancetype)initWithInt64s:(const int64_t [__nullable])values
  2901. forKeys:(const uint64_t [__nullable])keys
  2902. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  2903. /**
  2904. * Initializes this dictionary, copying the entries from the given dictionary.
  2905. *
  2906. * @param dictionary Dictionary containing the entries to add to this dictionary.
  2907. *
  2908. * @return A newly initialized dictionary with the entries of the given dictionary.
  2909. **/
  2910. - (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary;
  2911. /**
  2912. * Initializes this dictionary with the requested capacity.
  2913. *
  2914. * @param numItems Number of items needed for this dictionary.
  2915. *
  2916. * @return A newly initialized dictionary with the requested capacity.
  2917. **/
  2918. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  2919. /**
  2920. * Gets the value for the given key.
  2921. *
  2922. * @param value Pointer into which the value will be set, if found.
  2923. * @param key Key under which the value is stored, if present.
  2924. *
  2925. * @return YES if the key was found and the value was copied, NO otherwise.
  2926. **/
  2927. - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key;
  2928. /**
  2929. * Enumerates the keys and values on this dictionary with the given block.
  2930. *
  2931. * @param block The block to enumerate with.
  2932. * **key**: The key for the current entry.
  2933. * **value**: The value for the current entry
  2934. * **stop**: A pointer to a boolean that when set stops the enumeration.
  2935. **/
  2936. - (void)enumerateKeysAndInt64sUsingBlock:
  2937. (void (^)(uint64_t key, int64_t value, BOOL *stop))block;
  2938. /**
  2939. * Adds the keys and values from another dictionary.
  2940. *
  2941. * @param otherDictionary Dictionary containing entries to be added to this
  2942. * dictionary.
  2943. **/
  2944. - (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary;
  2945. /**
  2946. * Sets the value for the given key.
  2947. *
  2948. * @param value The value to set.
  2949. * @param key The key under which to store the value.
  2950. **/
  2951. - (void)setInt64:(int64_t)value forKey:(uint64_t)key;
  2952. /**
  2953. * Removes the entry for the given key.
  2954. *
  2955. * @param aKey Key to be removed from this dictionary.
  2956. **/
  2957. - (void)removeInt64ForKey:(uint64_t)aKey;
  2958. /**
  2959. * Removes all entries in this dictionary.
  2960. **/
  2961. - (void)removeAll;
  2962. @end
  2963. #pragma mark - UInt64 -> Bool
  2964. /**
  2965. * Class used for map fields of <uint64_t, BOOL>
  2966. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  2967. *
  2968. * @note This class is not meant to be subclassed.
  2969. **/
  2970. @interface GPBUInt64BoolDictionary : NSObject <NSCopying>
  2971. /** Number of entries stored in this dictionary. */
  2972. @property(nonatomic, readonly) NSUInteger count;
  2973. /**
  2974. * @return A newly instanced and empty dictionary.
  2975. **/
  2976. + (instancetype)dictionary;
  2977. /**
  2978. * Creates and initializes a dictionary with the single entry given.
  2979. *
  2980. * @param value The value to be placed in the dictionary.
  2981. * @param key The key under which to store the value.
  2982. *
  2983. * @return A newly instanced dictionary with the key and value in it.
  2984. **/
  2985. + (instancetype)dictionaryWithBool:(BOOL)value
  2986. forKey:(uint64_t)key;
  2987. /**
  2988. * Creates and initializes a dictionary with the entries given.
  2989. *
  2990. * @param values The values to be placed in the dictionary.
  2991. * @param keys The keys under which to store the values.
  2992. * @param count The number of entries to store in the dictionary.
  2993. *
  2994. * @return A newly instanced dictionary with the keys and values in it.
  2995. **/
  2996. + (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
  2997. forKeys:(const uint64_t [__nullable])keys
  2998. count:(NSUInteger)count;
  2999. /**
  3000. * Creates and initializes a dictionary with the entries from the given.
  3001. * dictionary.
  3002. *
  3003. * @param dictionary Dictionary containing the entries to add to the dictionary.
  3004. *
  3005. * @return A newly instanced dictionary with the entries from the given
  3006. * dictionary in it.
  3007. **/
  3008. + (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary;
  3009. /**
  3010. * Creates and initializes a dictionary with the given capacity.
  3011. *
  3012. * @param numItems Capacity needed for the dictionary.
  3013. *
  3014. * @return A newly instanced dictionary with the given capacity.
  3015. **/
  3016. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  3017. /**
  3018. * Initializes this dictionary, copying the given values and keys.
  3019. *
  3020. * @param values The values to be placed in this dictionary.
  3021. * @param keys The keys under which to store the values.
  3022. * @param count The number of elements to copy into the dictionary.
  3023. *
  3024. * @return A newly initialized dictionary with a copy of the values and keys.
  3025. **/
  3026. - (instancetype)initWithBools:(const BOOL [__nullable])values
  3027. forKeys:(const uint64_t [__nullable])keys
  3028. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  3029. /**
  3030. * Initializes this dictionary, copying the entries from the given dictionary.
  3031. *
  3032. * @param dictionary Dictionary containing the entries to add to this dictionary.
  3033. *
  3034. * @return A newly initialized dictionary with the entries of the given dictionary.
  3035. **/
  3036. - (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary;
  3037. /**
  3038. * Initializes this dictionary with the requested capacity.
  3039. *
  3040. * @param numItems Number of items needed for this dictionary.
  3041. *
  3042. * @return A newly initialized dictionary with the requested capacity.
  3043. **/
  3044. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  3045. /**
  3046. * Gets the value for the given key.
  3047. *
  3048. * @param value Pointer into which the value will be set, if found.
  3049. * @param key Key under which the value is stored, if present.
  3050. *
  3051. * @return YES if the key was found and the value was copied, NO otherwise.
  3052. **/
  3053. - (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key;
  3054. /**
  3055. * Enumerates the keys and values on this dictionary with the given block.
  3056. *
  3057. * @param block The block to enumerate with.
  3058. * **key**: The key for the current entry.
  3059. * **value**: The value for the current entry
  3060. * **stop**: A pointer to a boolean that when set stops the enumeration.
  3061. **/
  3062. - (void)enumerateKeysAndBoolsUsingBlock:
  3063. (void (^)(uint64_t key, BOOL value, BOOL *stop))block;
  3064. /**
  3065. * Adds the keys and values from another dictionary.
  3066. *
  3067. * @param otherDictionary Dictionary containing entries to be added to this
  3068. * dictionary.
  3069. **/
  3070. - (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary;
  3071. /**
  3072. * Sets the value for the given key.
  3073. *
  3074. * @param value The value to set.
  3075. * @param key The key under which to store the value.
  3076. **/
  3077. - (void)setBool:(BOOL)value forKey:(uint64_t)key;
  3078. /**
  3079. * Removes the entry for the given key.
  3080. *
  3081. * @param aKey Key to be removed from this dictionary.
  3082. **/
  3083. - (void)removeBoolForKey:(uint64_t)aKey;
  3084. /**
  3085. * Removes all entries in this dictionary.
  3086. **/
  3087. - (void)removeAll;
  3088. @end
  3089. #pragma mark - UInt64 -> Float
  3090. /**
  3091. * Class used for map fields of <uint64_t, float>
  3092. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  3093. *
  3094. * @note This class is not meant to be subclassed.
  3095. **/
  3096. @interface GPBUInt64FloatDictionary : NSObject <NSCopying>
  3097. /** Number of entries stored in this dictionary. */
  3098. @property(nonatomic, readonly) NSUInteger count;
  3099. /**
  3100. * @return A newly instanced and empty dictionary.
  3101. **/
  3102. + (instancetype)dictionary;
  3103. /**
  3104. * Creates and initializes a dictionary with the single entry given.
  3105. *
  3106. * @param value The value to be placed in the dictionary.
  3107. * @param key The key under which to store the value.
  3108. *
  3109. * @return A newly instanced dictionary with the key and value in it.
  3110. **/
  3111. + (instancetype)dictionaryWithFloat:(float)value
  3112. forKey:(uint64_t)key;
  3113. /**
  3114. * Creates and initializes a dictionary with the entries given.
  3115. *
  3116. * @param values The values to be placed in the dictionary.
  3117. * @param keys The keys under which to store the values.
  3118. * @param count The number of entries to store in the dictionary.
  3119. *
  3120. * @return A newly instanced dictionary with the keys and values in it.
  3121. **/
  3122. + (instancetype)dictionaryWithFloats:(const float [__nullable])values
  3123. forKeys:(const uint64_t [__nullable])keys
  3124. count:(NSUInteger)count;
  3125. /**
  3126. * Creates and initializes a dictionary with the entries from the given.
  3127. * dictionary.
  3128. *
  3129. * @param dictionary Dictionary containing the entries to add to the dictionary.
  3130. *
  3131. * @return A newly instanced dictionary with the entries from the given
  3132. * dictionary in it.
  3133. **/
  3134. + (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary;
  3135. /**
  3136. * Creates and initializes a dictionary with the given capacity.
  3137. *
  3138. * @param numItems Capacity needed for the dictionary.
  3139. *
  3140. * @return A newly instanced dictionary with the given capacity.
  3141. **/
  3142. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  3143. /**
  3144. * Initializes this dictionary, copying the given values and keys.
  3145. *
  3146. * @param values The values to be placed in this dictionary.
  3147. * @param keys The keys under which to store the values.
  3148. * @param count The number of elements to copy into the dictionary.
  3149. *
  3150. * @return A newly initialized dictionary with a copy of the values and keys.
  3151. **/
  3152. - (instancetype)initWithFloats:(const float [__nullable])values
  3153. forKeys:(const uint64_t [__nullable])keys
  3154. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  3155. /**
  3156. * Initializes this dictionary, copying the entries from the given dictionary.
  3157. *
  3158. * @param dictionary Dictionary containing the entries to add to this dictionary.
  3159. *
  3160. * @return A newly initialized dictionary with the entries of the given dictionary.
  3161. **/
  3162. - (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary;
  3163. /**
  3164. * Initializes this dictionary with the requested capacity.
  3165. *
  3166. * @param numItems Number of items needed for this dictionary.
  3167. *
  3168. * @return A newly initialized dictionary with the requested capacity.
  3169. **/
  3170. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  3171. /**
  3172. * Gets the value for the given key.
  3173. *
  3174. * @param value Pointer into which the value will be set, if found.
  3175. * @param key Key under which the value is stored, if present.
  3176. *
  3177. * @return YES if the key was found and the value was copied, NO otherwise.
  3178. **/
  3179. - (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key;
  3180. /**
  3181. * Enumerates the keys and values on this dictionary with the given block.
  3182. *
  3183. * @param block The block to enumerate with.
  3184. * **key**: The key for the current entry.
  3185. * **value**: The value for the current entry
  3186. * **stop**: A pointer to a boolean that when set stops the enumeration.
  3187. **/
  3188. - (void)enumerateKeysAndFloatsUsingBlock:
  3189. (void (^)(uint64_t key, float value, BOOL *stop))block;
  3190. /**
  3191. * Adds the keys and values from another dictionary.
  3192. *
  3193. * @param otherDictionary Dictionary containing entries to be added to this
  3194. * dictionary.
  3195. **/
  3196. - (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary;
  3197. /**
  3198. * Sets the value for the given key.
  3199. *
  3200. * @param value The value to set.
  3201. * @param key The key under which to store the value.
  3202. **/
  3203. - (void)setFloat:(float)value forKey:(uint64_t)key;
  3204. /**
  3205. * Removes the entry for the given key.
  3206. *
  3207. * @param aKey Key to be removed from this dictionary.
  3208. **/
  3209. - (void)removeFloatForKey:(uint64_t)aKey;
  3210. /**
  3211. * Removes all entries in this dictionary.
  3212. **/
  3213. - (void)removeAll;
  3214. @end
  3215. #pragma mark - UInt64 -> Double
  3216. /**
  3217. * Class used for map fields of <uint64_t, double>
  3218. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  3219. *
  3220. * @note This class is not meant to be subclassed.
  3221. **/
  3222. @interface GPBUInt64DoubleDictionary : NSObject <NSCopying>
  3223. /** Number of entries stored in this dictionary. */
  3224. @property(nonatomic, readonly) NSUInteger count;
  3225. /**
  3226. * @return A newly instanced and empty dictionary.
  3227. **/
  3228. + (instancetype)dictionary;
  3229. /**
  3230. * Creates and initializes a dictionary with the single entry given.
  3231. *
  3232. * @param value The value to be placed in the dictionary.
  3233. * @param key The key under which to store the value.
  3234. *
  3235. * @return A newly instanced dictionary with the key and value in it.
  3236. **/
  3237. + (instancetype)dictionaryWithDouble:(double)value
  3238. forKey:(uint64_t)key;
  3239. /**
  3240. * Creates and initializes a dictionary with the entries given.
  3241. *
  3242. * @param values The values to be placed in the dictionary.
  3243. * @param keys The keys under which to store the values.
  3244. * @param count The number of entries to store in the dictionary.
  3245. *
  3246. * @return A newly instanced dictionary with the keys and values in it.
  3247. **/
  3248. + (instancetype)dictionaryWithDoubles:(const double [__nullable])values
  3249. forKeys:(const uint64_t [__nullable])keys
  3250. count:(NSUInteger)count;
  3251. /**
  3252. * Creates and initializes a dictionary with the entries from the given.
  3253. * dictionary.
  3254. *
  3255. * @param dictionary Dictionary containing the entries to add to the dictionary.
  3256. *
  3257. * @return A newly instanced dictionary with the entries from the given
  3258. * dictionary in it.
  3259. **/
  3260. + (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary;
  3261. /**
  3262. * Creates and initializes a dictionary with the given capacity.
  3263. *
  3264. * @param numItems Capacity needed for the dictionary.
  3265. *
  3266. * @return A newly instanced dictionary with the given capacity.
  3267. **/
  3268. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  3269. /**
  3270. * Initializes this dictionary, copying the given values and keys.
  3271. *
  3272. * @param values The values to be placed in this dictionary.
  3273. * @param keys The keys under which to store the values.
  3274. * @param count The number of elements to copy into the dictionary.
  3275. *
  3276. * @return A newly initialized dictionary with a copy of the values and keys.
  3277. **/
  3278. - (instancetype)initWithDoubles:(const double [__nullable])values
  3279. forKeys:(const uint64_t [__nullable])keys
  3280. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  3281. /**
  3282. * Initializes this dictionary, copying the entries from the given dictionary.
  3283. *
  3284. * @param dictionary Dictionary containing the entries to add to this dictionary.
  3285. *
  3286. * @return A newly initialized dictionary with the entries of the given dictionary.
  3287. **/
  3288. - (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary;
  3289. /**
  3290. * Initializes this dictionary with the requested capacity.
  3291. *
  3292. * @param numItems Number of items needed for this dictionary.
  3293. *
  3294. * @return A newly initialized dictionary with the requested capacity.
  3295. **/
  3296. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  3297. /**
  3298. * Gets the value for the given key.
  3299. *
  3300. * @param value Pointer into which the value will be set, if found.
  3301. * @param key Key under which the value is stored, if present.
  3302. *
  3303. * @return YES if the key was found and the value was copied, NO otherwise.
  3304. **/
  3305. - (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key;
  3306. /**
  3307. * Enumerates the keys and values on this dictionary with the given block.
  3308. *
  3309. * @param block The block to enumerate with.
  3310. * **key**: The key for the current entry.
  3311. * **value**: The value for the current entry
  3312. * **stop**: A pointer to a boolean that when set stops the enumeration.
  3313. **/
  3314. - (void)enumerateKeysAndDoublesUsingBlock:
  3315. (void (^)(uint64_t key, double value, BOOL *stop))block;
  3316. /**
  3317. * Adds the keys and values from another dictionary.
  3318. *
  3319. * @param otherDictionary Dictionary containing entries to be added to this
  3320. * dictionary.
  3321. **/
  3322. - (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary;
  3323. /**
  3324. * Sets the value for the given key.
  3325. *
  3326. * @param value The value to set.
  3327. * @param key The key under which to store the value.
  3328. **/
  3329. - (void)setDouble:(double)value forKey:(uint64_t)key;
  3330. /**
  3331. * Removes the entry for the given key.
  3332. *
  3333. * @param aKey Key to be removed from this dictionary.
  3334. **/
  3335. - (void)removeDoubleForKey:(uint64_t)aKey;
  3336. /**
  3337. * Removes all entries in this dictionary.
  3338. **/
  3339. - (void)removeAll;
  3340. @end
  3341. #pragma mark - UInt64 -> Enum
  3342. /**
  3343. * Class used for map fields of <uint64_t, int32_t>
  3344. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  3345. *
  3346. * @note This class is not meant to be subclassed.
  3347. **/
  3348. @interface GPBUInt64EnumDictionary : NSObject <NSCopying>
  3349. /** Number of entries stored in this dictionary. */
  3350. @property(nonatomic, readonly) NSUInteger count;
  3351. /** The validation function to check if the enums are valid. */
  3352. @property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
  3353. /**
  3354. * @return A newly instanced and empty dictionary.
  3355. **/
  3356. + (instancetype)dictionary;
  3357. /**
  3358. * Creates and initializes a dictionary with the given validation function.
  3359. *
  3360. * @param func The enum validation function for the dictionary.
  3361. *
  3362. * @return A newly instanced dictionary.
  3363. **/
  3364. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  3365. /**
  3366. * Creates and initializes a dictionary with the single entry given.
  3367. *
  3368. * @param func The enum validation function for the dictionary.
  3369. * @param rawValue The raw enum value to be placed in the dictionary.
  3370. * @param key The key under which to store the value.
  3371. *
  3372. * @return A newly instanced dictionary with the key and value in it.
  3373. **/
  3374. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  3375. rawValue:(int32_t)rawValue
  3376. forKey:(uint64_t)key;
  3377. /**
  3378. * Creates and initializes a dictionary with the entries given.
  3379. *
  3380. * @param func The enum validation function for the dictionary.
  3381. * @param values The raw enum values values to be placed in the dictionary.
  3382. * @param keys The keys under which to store the values.
  3383. * @param count The number of entries to store in the dictionary.
  3384. *
  3385. * @return A newly instanced dictionary with the keys and values in it.
  3386. **/
  3387. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  3388. rawValues:(const int32_t [__nullable])values
  3389. forKeys:(const uint64_t [__nullable])keys
  3390. count:(NSUInteger)count;
  3391. /**
  3392. * Creates and initializes a dictionary with the entries from the given.
  3393. * dictionary.
  3394. *
  3395. * @param dictionary Dictionary containing the entries to add to the dictionary.
  3396. *
  3397. * @return A newly instanced dictionary with the entries from the given
  3398. * dictionary in it.
  3399. **/
  3400. + (instancetype)dictionaryWithDictionary:(GPBUInt64EnumDictionary *)dictionary;
  3401. /**
  3402. * Creates and initializes a dictionary with the given capacity.
  3403. *
  3404. * @param func The enum validation function for the dictionary.
  3405. * @param numItems Capacity needed for the dictionary.
  3406. *
  3407. * @return A newly instanced dictionary with the given capacity.
  3408. **/
  3409. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  3410. capacity:(NSUInteger)numItems;
  3411. /**
  3412. * Initializes a dictionary with the given validation function.
  3413. *
  3414. * @param func The enum validation function for the dictionary.
  3415. *
  3416. * @return A newly initialized dictionary.
  3417. **/
  3418. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  3419. /**
  3420. * Initializes a dictionary with the entries given.
  3421. *
  3422. * @param func The enum validation function for the dictionary.
  3423. * @param values The raw enum values values to be placed in the dictionary.
  3424. * @param keys The keys under which to store the values.
  3425. * @param count The number of entries to store in the dictionary.
  3426. *
  3427. * @return A newly initialized dictionary with the keys and values in it.
  3428. **/
  3429. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  3430. rawValues:(const int32_t [__nullable])values
  3431. forKeys:(const uint64_t [__nullable])keys
  3432. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  3433. /**
  3434. * Initializes a dictionary with the entries from the given.
  3435. * dictionary.
  3436. *
  3437. * @param dictionary Dictionary containing the entries to add to the dictionary.
  3438. *
  3439. * @return A newly initialized dictionary with the entries from the given
  3440. * dictionary in it.
  3441. **/
  3442. - (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary;
  3443. /**
  3444. * Initializes a dictionary with the given capacity.
  3445. *
  3446. * @param func The enum validation function for the dictionary.
  3447. * @param numItems Capacity needed for the dictionary.
  3448. *
  3449. * @return A newly initialized dictionary with the given capacity.
  3450. **/
  3451. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  3452. capacity:(NSUInteger)numItems;
  3453. // These will return kGPBUnrecognizedEnumeratorValue if the value for the key
  3454. // is not a valid enumerator as defined by validationFunc. If the actual value is
  3455. // desired, use "raw" version of the method.
  3456. /**
  3457. * Gets the value for the given key.
  3458. *
  3459. * @param value Pointer into which the value will be set, if found.
  3460. * @param key Key under which the value is stored, if present.
  3461. *
  3462. * @return YES if the key was found and the value was copied, NO otherwise.
  3463. **/
  3464. - (BOOL)getEnum:(nullable int32_t *)value forKey:(uint64_t)key;
  3465. /**
  3466. * Enumerates the keys and values on this dictionary with the given block.
  3467. *
  3468. * @param block The block to enumerate with.
  3469. * **key**: The key for the current entry.
  3470. * **value**: The value for the current entry
  3471. * **stop**: A pointer to a boolean that when set stops the enumeration.
  3472. **/
  3473. - (void)enumerateKeysAndEnumsUsingBlock:
  3474. (void (^)(uint64_t key, int32_t value, BOOL *stop))block;
  3475. /**
  3476. * Gets the raw enum value for the given key.
  3477. *
  3478. * @note This method bypass the validationFunc to enable the access of values that
  3479. * were not known at the time the binary was compiled.
  3480. *
  3481. * @param rawValue Pointer into which the value will be set, if found.
  3482. * @param key Key under which the value is stored, if present.
  3483. *
  3484. * @return YES if the key was found and the value was copied, NO otherwise.
  3485. **/
  3486. - (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(uint64_t)key;
  3487. /**
  3488. * Enumerates the keys and values on this dictionary with the given block.
  3489. *
  3490. * @note This method bypass the validationFunc to enable the access of values that
  3491. * were not known at the time the binary was compiled.
  3492. *
  3493. * @param block The block to enumerate with.
  3494. * **key**: The key for the current entry.
  3495. * **rawValue**: The value for the current entry
  3496. * **stop**: A pointer to a boolean that when set stops the enumeration.
  3497. **/
  3498. - (void)enumerateKeysAndRawValuesUsingBlock:
  3499. (void (^)(uint64_t key, int32_t rawValue, BOOL *stop))block;
  3500. /**
  3501. * Adds the keys and raw enum values from another dictionary.
  3502. *
  3503. * @note This method bypass the validationFunc to enable the setting of values that
  3504. * were not known at the time the binary was compiled.
  3505. *
  3506. * @param otherDictionary Dictionary containing entries to be added to this
  3507. * dictionary.
  3508. **/
  3509. - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary;
  3510. // If value is not a valid enumerator as defined by validationFunc, these
  3511. // methods will assert in debug, and will log in release and assign the value
  3512. // to the default value. Use the rawValue methods below to assign non enumerator
  3513. // values.
  3514. /**
  3515. * Sets the value for the given key.
  3516. *
  3517. * @param value The value to set.
  3518. * @param key The key under which to store the value.
  3519. **/
  3520. - (void)setEnum:(int32_t)value forKey:(uint64_t)key;
  3521. /**
  3522. * Sets the raw enum value for the given key.
  3523. *
  3524. * @note This method bypass the validationFunc to enable the setting of values that
  3525. * were not known at the time the binary was compiled.
  3526. *
  3527. * @param rawValue The raw enum value to set.
  3528. * @param key The key under which to store the raw enum value.
  3529. **/
  3530. - (void)setRawValue:(int32_t)rawValue forKey:(uint64_t)key;
  3531. /**
  3532. * Removes the entry for the given key.
  3533. *
  3534. * @param aKey Key to be removed from this dictionary.
  3535. **/
  3536. - (void)removeEnumForKey:(uint64_t)aKey;
  3537. /**
  3538. * Removes all entries in this dictionary.
  3539. **/
  3540. - (void)removeAll;
  3541. @end
  3542. #pragma mark - UInt64 -> Object
  3543. /**
  3544. * Class used for map fields of <uint64_t, ObjectType>
  3545. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  3546. *
  3547. * @note This class is not meant to be subclassed.
  3548. **/
  3549. @interface GPBUInt64ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
  3550. /** Number of entries stored in this dictionary. */
  3551. @property(nonatomic, readonly) NSUInteger count;
  3552. /**
  3553. * @return A newly instanced and empty dictionary.
  3554. **/
  3555. + (instancetype)dictionary;
  3556. /**
  3557. * Creates and initializes a dictionary with the single entry given.
  3558. *
  3559. * @param object The value to be placed in the dictionary.
  3560. * @param key The key under which to store the value.
  3561. *
  3562. * @return A newly instanced dictionary with the key and value in it.
  3563. **/
  3564. + (instancetype)dictionaryWithObject:(ObjectType)object
  3565. forKey:(uint64_t)key;
  3566. /**
  3567. * Creates and initializes a dictionary with the entries given.
  3568. *
  3569. * @param objects The values to be placed in the dictionary.
  3570. * @param keys The keys under which to store the values.
  3571. * @param count The number of entries to store in the dictionary.
  3572. *
  3573. * @return A newly instanced dictionary with the keys and values in it.
  3574. **/
  3575. + (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
  3576. forKeys:(const uint64_t [__nullable])keys
  3577. count:(NSUInteger)count;
  3578. /**
  3579. * Creates and initializes a dictionary with the entries from the given.
  3580. * dictionary.
  3581. *
  3582. * @param dictionary Dictionary containing the entries to add to the dictionary.
  3583. *
  3584. * @return A newly instanced dictionary with the entries from the given
  3585. * dictionary in it.
  3586. **/
  3587. + (instancetype)dictionaryWithDictionary:(GPBUInt64ObjectDictionary *)dictionary;
  3588. /**
  3589. * Creates and initializes a dictionary with the given capacity.
  3590. *
  3591. * @param numItems Capacity needed for the dictionary.
  3592. *
  3593. * @return A newly instanced dictionary with the given capacity.
  3594. **/
  3595. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  3596. /**
  3597. * Initializes this dictionary, copying the given values and keys.
  3598. *
  3599. * @param objects The values to be placed in this dictionary.
  3600. * @param keys The keys under which to store the values.
  3601. * @param count The number of elements to copy into the dictionary.
  3602. *
  3603. * @return A newly initialized dictionary with a copy of the values and keys.
  3604. **/
  3605. - (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
  3606. forKeys:(const uint64_t [__nullable])keys
  3607. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  3608. /**
  3609. * Initializes this dictionary, copying the entries from the given dictionary.
  3610. *
  3611. * @param dictionary Dictionary containing the entries to add to this dictionary.
  3612. *
  3613. * @return A newly initialized dictionary with the entries of the given dictionary.
  3614. **/
  3615. - (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary;
  3616. /**
  3617. * Initializes this dictionary with the requested capacity.
  3618. *
  3619. * @param numItems Number of items needed for this dictionary.
  3620. *
  3621. * @return A newly initialized dictionary with the requested capacity.
  3622. **/
  3623. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  3624. /**
  3625. * Fetches the object stored under the given key.
  3626. *
  3627. * @param key Key under which the value is stored, if present.
  3628. *
  3629. * @return The object if found, nil otherwise.
  3630. **/
  3631. - (ObjectType)objectForKey:(uint64_t)key;
  3632. /**
  3633. * Enumerates the keys and values on this dictionary with the given block.
  3634. *
  3635. * @param block The block to enumerate with.
  3636. * **key**: The key for the current entry.
  3637. * **object**: The value for the current entry
  3638. * **stop**: A pointer to a boolean that when set stops the enumeration.
  3639. **/
  3640. - (void)enumerateKeysAndObjectsUsingBlock:
  3641. (void (^)(uint64_t key, ObjectType object, BOOL *stop))block;
  3642. /**
  3643. * Adds the keys and values from another dictionary.
  3644. *
  3645. * @param otherDictionary Dictionary containing entries to be added to this
  3646. * dictionary.
  3647. **/
  3648. - (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary;
  3649. /**
  3650. * Sets the value for the given key.
  3651. *
  3652. * @param object The value to set.
  3653. * @param key The key under which to store the value.
  3654. **/
  3655. - (void)setObject:(ObjectType)object forKey:(uint64_t)key;
  3656. /**
  3657. * Removes the entry for the given key.
  3658. *
  3659. * @param aKey Key to be removed from this dictionary.
  3660. **/
  3661. - (void)removeObjectForKey:(uint64_t)aKey;
  3662. /**
  3663. * Removes all entries in this dictionary.
  3664. **/
  3665. - (void)removeAll;
  3666. @end
  3667. #pragma mark - Int64 -> UInt32
  3668. /**
  3669. * Class used for map fields of <int64_t, uint32_t>
  3670. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  3671. *
  3672. * @note This class is not meant to be subclassed.
  3673. **/
  3674. @interface GPBInt64UInt32Dictionary : NSObject <NSCopying>
  3675. /** Number of entries stored in this dictionary. */
  3676. @property(nonatomic, readonly) NSUInteger count;
  3677. /**
  3678. * @return A newly instanced and empty dictionary.
  3679. **/
  3680. + (instancetype)dictionary;
  3681. /**
  3682. * Creates and initializes a dictionary with the single entry given.
  3683. *
  3684. * @param value The value to be placed in the dictionary.
  3685. * @param key The key under which to store the value.
  3686. *
  3687. * @return A newly instanced dictionary with the key and value in it.
  3688. **/
  3689. + (instancetype)dictionaryWithUInt32:(uint32_t)value
  3690. forKey:(int64_t)key;
  3691. /**
  3692. * Creates and initializes a dictionary with the entries given.
  3693. *
  3694. * @param values The values to be placed in the dictionary.
  3695. * @param keys The keys under which to store the values.
  3696. * @param count The number of entries to store in the dictionary.
  3697. *
  3698. * @return A newly instanced dictionary with the keys and values in it.
  3699. **/
  3700. + (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
  3701. forKeys:(const int64_t [__nullable])keys
  3702. count:(NSUInteger)count;
  3703. /**
  3704. * Creates and initializes a dictionary with the entries from the given.
  3705. * dictionary.
  3706. *
  3707. * @param dictionary Dictionary containing the entries to add to the dictionary.
  3708. *
  3709. * @return A newly instanced dictionary with the entries from the given
  3710. * dictionary in it.
  3711. **/
  3712. + (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary;
  3713. /**
  3714. * Creates and initializes a dictionary with the given capacity.
  3715. *
  3716. * @param numItems Capacity needed for the dictionary.
  3717. *
  3718. * @return A newly instanced dictionary with the given capacity.
  3719. **/
  3720. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  3721. /**
  3722. * Initializes this dictionary, copying the given values and keys.
  3723. *
  3724. * @param values The values to be placed in this dictionary.
  3725. * @param keys The keys under which to store the values.
  3726. * @param count The number of elements to copy into the dictionary.
  3727. *
  3728. * @return A newly initialized dictionary with a copy of the values and keys.
  3729. **/
  3730. - (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
  3731. forKeys:(const int64_t [__nullable])keys
  3732. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  3733. /**
  3734. * Initializes this dictionary, copying the entries from the given dictionary.
  3735. *
  3736. * @param dictionary Dictionary containing the entries to add to this dictionary.
  3737. *
  3738. * @return A newly initialized dictionary with the entries of the given dictionary.
  3739. **/
  3740. - (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary;
  3741. /**
  3742. * Initializes this dictionary with the requested capacity.
  3743. *
  3744. * @param numItems Number of items needed for this dictionary.
  3745. *
  3746. * @return A newly initialized dictionary with the requested capacity.
  3747. **/
  3748. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  3749. /**
  3750. * Gets the value for the given key.
  3751. *
  3752. * @param value Pointer into which the value will be set, if found.
  3753. * @param key Key under which the value is stored, if present.
  3754. *
  3755. * @return YES if the key was found and the value was copied, NO otherwise.
  3756. **/
  3757. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key;
  3758. /**
  3759. * Enumerates the keys and values on this dictionary with the given block.
  3760. *
  3761. * @param block The block to enumerate with.
  3762. * **key**: The key for the current entry.
  3763. * **value**: The value for the current entry
  3764. * **stop**: A pointer to a boolean that when set stops the enumeration.
  3765. **/
  3766. - (void)enumerateKeysAndUInt32sUsingBlock:
  3767. (void (^)(int64_t key, uint32_t value, BOOL *stop))block;
  3768. /**
  3769. * Adds the keys and values from another dictionary.
  3770. *
  3771. * @param otherDictionary Dictionary containing entries to be added to this
  3772. * dictionary.
  3773. **/
  3774. - (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary;
  3775. /**
  3776. * Sets the value for the given key.
  3777. *
  3778. * @param value The value to set.
  3779. * @param key The key under which to store the value.
  3780. **/
  3781. - (void)setUInt32:(uint32_t)value forKey:(int64_t)key;
  3782. /**
  3783. * Removes the entry for the given key.
  3784. *
  3785. * @param aKey Key to be removed from this dictionary.
  3786. **/
  3787. - (void)removeUInt32ForKey:(int64_t)aKey;
  3788. /**
  3789. * Removes all entries in this dictionary.
  3790. **/
  3791. - (void)removeAll;
  3792. @end
  3793. #pragma mark - Int64 -> Int32
  3794. /**
  3795. * Class used for map fields of <int64_t, int32_t>
  3796. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  3797. *
  3798. * @note This class is not meant to be subclassed.
  3799. **/
  3800. @interface GPBInt64Int32Dictionary : NSObject <NSCopying>
  3801. /** Number of entries stored in this dictionary. */
  3802. @property(nonatomic, readonly) NSUInteger count;
  3803. /**
  3804. * @return A newly instanced and empty dictionary.
  3805. **/
  3806. + (instancetype)dictionary;
  3807. /**
  3808. * Creates and initializes a dictionary with the single entry given.
  3809. *
  3810. * @param value The value to be placed in the dictionary.
  3811. * @param key The key under which to store the value.
  3812. *
  3813. * @return A newly instanced dictionary with the key and value in it.
  3814. **/
  3815. + (instancetype)dictionaryWithInt32:(int32_t)value
  3816. forKey:(int64_t)key;
  3817. /**
  3818. * Creates and initializes a dictionary with the entries given.
  3819. *
  3820. * @param values The values to be placed in the dictionary.
  3821. * @param keys The keys under which to store the values.
  3822. * @param count The number of entries to store in the dictionary.
  3823. *
  3824. * @return A newly instanced dictionary with the keys and values in it.
  3825. **/
  3826. + (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
  3827. forKeys:(const int64_t [__nullable])keys
  3828. count:(NSUInteger)count;
  3829. /**
  3830. * Creates and initializes a dictionary with the entries from the given.
  3831. * dictionary.
  3832. *
  3833. * @param dictionary Dictionary containing the entries to add to the dictionary.
  3834. *
  3835. * @return A newly instanced dictionary with the entries from the given
  3836. * dictionary in it.
  3837. **/
  3838. + (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary;
  3839. /**
  3840. * Creates and initializes a dictionary with the given capacity.
  3841. *
  3842. * @param numItems Capacity needed for the dictionary.
  3843. *
  3844. * @return A newly instanced dictionary with the given capacity.
  3845. **/
  3846. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  3847. /**
  3848. * Initializes this dictionary, copying the given values and keys.
  3849. *
  3850. * @param values The values to be placed in this dictionary.
  3851. * @param keys The keys under which to store the values.
  3852. * @param count The number of elements to copy into the dictionary.
  3853. *
  3854. * @return A newly initialized dictionary with a copy of the values and keys.
  3855. **/
  3856. - (instancetype)initWithInt32s:(const int32_t [__nullable])values
  3857. forKeys:(const int64_t [__nullable])keys
  3858. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  3859. /**
  3860. * Initializes this dictionary, copying the entries from the given dictionary.
  3861. *
  3862. * @param dictionary Dictionary containing the entries to add to this dictionary.
  3863. *
  3864. * @return A newly initialized dictionary with the entries of the given dictionary.
  3865. **/
  3866. - (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary;
  3867. /**
  3868. * Initializes this dictionary with the requested capacity.
  3869. *
  3870. * @param numItems Number of items needed for this dictionary.
  3871. *
  3872. * @return A newly initialized dictionary with the requested capacity.
  3873. **/
  3874. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  3875. /**
  3876. * Gets the value for the given key.
  3877. *
  3878. * @param value Pointer into which the value will be set, if found.
  3879. * @param key Key under which the value is stored, if present.
  3880. *
  3881. * @return YES if the key was found and the value was copied, NO otherwise.
  3882. **/
  3883. - (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key;
  3884. /**
  3885. * Enumerates the keys and values on this dictionary with the given block.
  3886. *
  3887. * @param block The block to enumerate with.
  3888. * **key**: The key for the current entry.
  3889. * **value**: The value for the current entry
  3890. * **stop**: A pointer to a boolean that when set stops the enumeration.
  3891. **/
  3892. - (void)enumerateKeysAndInt32sUsingBlock:
  3893. (void (^)(int64_t key, int32_t value, BOOL *stop))block;
  3894. /**
  3895. * Adds the keys and values from another dictionary.
  3896. *
  3897. * @param otherDictionary Dictionary containing entries to be added to this
  3898. * dictionary.
  3899. **/
  3900. - (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary;
  3901. /**
  3902. * Sets the value for the given key.
  3903. *
  3904. * @param value The value to set.
  3905. * @param key The key under which to store the value.
  3906. **/
  3907. - (void)setInt32:(int32_t)value forKey:(int64_t)key;
  3908. /**
  3909. * Removes the entry for the given key.
  3910. *
  3911. * @param aKey Key to be removed from this dictionary.
  3912. **/
  3913. - (void)removeInt32ForKey:(int64_t)aKey;
  3914. /**
  3915. * Removes all entries in this dictionary.
  3916. **/
  3917. - (void)removeAll;
  3918. @end
  3919. #pragma mark - Int64 -> UInt64
  3920. /**
  3921. * Class used for map fields of <int64_t, uint64_t>
  3922. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  3923. *
  3924. * @note This class is not meant to be subclassed.
  3925. **/
  3926. @interface GPBInt64UInt64Dictionary : NSObject <NSCopying>
  3927. /** Number of entries stored in this dictionary. */
  3928. @property(nonatomic, readonly) NSUInteger count;
  3929. /**
  3930. * @return A newly instanced and empty dictionary.
  3931. **/
  3932. + (instancetype)dictionary;
  3933. /**
  3934. * Creates and initializes a dictionary with the single entry given.
  3935. *
  3936. * @param value The value to be placed in the dictionary.
  3937. * @param key The key under which to store the value.
  3938. *
  3939. * @return A newly instanced dictionary with the key and value in it.
  3940. **/
  3941. + (instancetype)dictionaryWithUInt64:(uint64_t)value
  3942. forKey:(int64_t)key;
  3943. /**
  3944. * Creates and initializes a dictionary with the entries given.
  3945. *
  3946. * @param values The values to be placed in the dictionary.
  3947. * @param keys The keys under which to store the values.
  3948. * @param count The number of entries to store in the dictionary.
  3949. *
  3950. * @return A newly instanced dictionary with the keys and values in it.
  3951. **/
  3952. + (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
  3953. forKeys:(const int64_t [__nullable])keys
  3954. count:(NSUInteger)count;
  3955. /**
  3956. * Creates and initializes a dictionary with the entries from the given.
  3957. * dictionary.
  3958. *
  3959. * @param dictionary Dictionary containing the entries to add to the dictionary.
  3960. *
  3961. * @return A newly instanced dictionary with the entries from the given
  3962. * dictionary in it.
  3963. **/
  3964. + (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary;
  3965. /**
  3966. * Creates and initializes a dictionary with the given capacity.
  3967. *
  3968. * @param numItems Capacity needed for the dictionary.
  3969. *
  3970. * @return A newly instanced dictionary with the given capacity.
  3971. **/
  3972. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  3973. /**
  3974. * Initializes this dictionary, copying the given values and keys.
  3975. *
  3976. * @param values The values to be placed in this dictionary.
  3977. * @param keys The keys under which to store the values.
  3978. * @param count The number of elements to copy into the dictionary.
  3979. *
  3980. * @return A newly initialized dictionary with a copy of the values and keys.
  3981. **/
  3982. - (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
  3983. forKeys:(const int64_t [__nullable])keys
  3984. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  3985. /**
  3986. * Initializes this dictionary, copying the entries from the given dictionary.
  3987. *
  3988. * @param dictionary Dictionary containing the entries to add to this dictionary.
  3989. *
  3990. * @return A newly initialized dictionary with the entries of the given dictionary.
  3991. **/
  3992. - (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary;
  3993. /**
  3994. * Initializes this dictionary with the requested capacity.
  3995. *
  3996. * @param numItems Number of items needed for this dictionary.
  3997. *
  3998. * @return A newly initialized dictionary with the requested capacity.
  3999. **/
  4000. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  4001. /**
  4002. * Gets the value for the given key.
  4003. *
  4004. * @param value Pointer into which the value will be set, if found.
  4005. * @param key Key under which the value is stored, if present.
  4006. *
  4007. * @return YES if the key was found and the value was copied, NO otherwise.
  4008. **/
  4009. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key;
  4010. /**
  4011. * Enumerates the keys and values on this dictionary with the given block.
  4012. *
  4013. * @param block The block to enumerate with.
  4014. * **key**: The key for the current entry.
  4015. * **value**: The value for the current entry
  4016. * **stop**: A pointer to a boolean that when set stops the enumeration.
  4017. **/
  4018. - (void)enumerateKeysAndUInt64sUsingBlock:
  4019. (void (^)(int64_t key, uint64_t value, BOOL *stop))block;
  4020. /**
  4021. * Adds the keys and values from another dictionary.
  4022. *
  4023. * @param otherDictionary Dictionary containing entries to be added to this
  4024. * dictionary.
  4025. **/
  4026. - (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary;
  4027. /**
  4028. * Sets the value for the given key.
  4029. *
  4030. * @param value The value to set.
  4031. * @param key The key under which to store the value.
  4032. **/
  4033. - (void)setUInt64:(uint64_t)value forKey:(int64_t)key;
  4034. /**
  4035. * Removes the entry for the given key.
  4036. *
  4037. * @param aKey Key to be removed from this dictionary.
  4038. **/
  4039. - (void)removeUInt64ForKey:(int64_t)aKey;
  4040. /**
  4041. * Removes all entries in this dictionary.
  4042. **/
  4043. - (void)removeAll;
  4044. @end
  4045. #pragma mark - Int64 -> Int64
  4046. /**
  4047. * Class used for map fields of <int64_t, int64_t>
  4048. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  4049. *
  4050. * @note This class is not meant to be subclassed.
  4051. **/
  4052. @interface GPBInt64Int64Dictionary : NSObject <NSCopying>
  4053. /** Number of entries stored in this dictionary. */
  4054. @property(nonatomic, readonly) NSUInteger count;
  4055. /**
  4056. * @return A newly instanced and empty dictionary.
  4057. **/
  4058. + (instancetype)dictionary;
  4059. /**
  4060. * Creates and initializes a dictionary with the single entry given.
  4061. *
  4062. * @param value The value to be placed in the dictionary.
  4063. * @param key The key under which to store the value.
  4064. *
  4065. * @return A newly instanced dictionary with the key and value in it.
  4066. **/
  4067. + (instancetype)dictionaryWithInt64:(int64_t)value
  4068. forKey:(int64_t)key;
  4069. /**
  4070. * Creates and initializes a dictionary with the entries given.
  4071. *
  4072. * @param values The values to be placed in the dictionary.
  4073. * @param keys The keys under which to store the values.
  4074. * @param count The number of entries to store in the dictionary.
  4075. *
  4076. * @return A newly instanced dictionary with the keys and values in it.
  4077. **/
  4078. + (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
  4079. forKeys:(const int64_t [__nullable])keys
  4080. count:(NSUInteger)count;
  4081. /**
  4082. * Creates and initializes a dictionary with the entries from the given.
  4083. * dictionary.
  4084. *
  4085. * @param dictionary Dictionary containing the entries to add to the dictionary.
  4086. *
  4087. * @return A newly instanced dictionary with the entries from the given
  4088. * dictionary in it.
  4089. **/
  4090. + (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary;
  4091. /**
  4092. * Creates and initializes a dictionary with the given capacity.
  4093. *
  4094. * @param numItems Capacity needed for the dictionary.
  4095. *
  4096. * @return A newly instanced dictionary with the given capacity.
  4097. **/
  4098. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  4099. /**
  4100. * Initializes this dictionary, copying the given values and keys.
  4101. *
  4102. * @param values The values to be placed in this dictionary.
  4103. * @param keys The keys under which to store the values.
  4104. * @param count The number of elements to copy into the dictionary.
  4105. *
  4106. * @return A newly initialized dictionary with a copy of the values and keys.
  4107. **/
  4108. - (instancetype)initWithInt64s:(const int64_t [__nullable])values
  4109. forKeys:(const int64_t [__nullable])keys
  4110. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  4111. /**
  4112. * Initializes this dictionary, copying the entries from the given dictionary.
  4113. *
  4114. * @param dictionary Dictionary containing the entries to add to this dictionary.
  4115. *
  4116. * @return A newly initialized dictionary with the entries of the given dictionary.
  4117. **/
  4118. - (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary;
  4119. /**
  4120. * Initializes this dictionary with the requested capacity.
  4121. *
  4122. * @param numItems Number of items needed for this dictionary.
  4123. *
  4124. * @return A newly initialized dictionary with the requested capacity.
  4125. **/
  4126. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  4127. /**
  4128. * Gets the value for the given key.
  4129. *
  4130. * @param value Pointer into which the value will be set, if found.
  4131. * @param key Key under which the value is stored, if present.
  4132. *
  4133. * @return YES if the key was found and the value was copied, NO otherwise.
  4134. **/
  4135. - (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key;
  4136. /**
  4137. * Enumerates the keys and values on this dictionary with the given block.
  4138. *
  4139. * @param block The block to enumerate with.
  4140. * **key**: The key for the current entry.
  4141. * **value**: The value for the current entry
  4142. * **stop**: A pointer to a boolean that when set stops the enumeration.
  4143. **/
  4144. - (void)enumerateKeysAndInt64sUsingBlock:
  4145. (void (^)(int64_t key, int64_t value, BOOL *stop))block;
  4146. /**
  4147. * Adds the keys and values from another dictionary.
  4148. *
  4149. * @param otherDictionary Dictionary containing entries to be added to this
  4150. * dictionary.
  4151. **/
  4152. - (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary;
  4153. /**
  4154. * Sets the value for the given key.
  4155. *
  4156. * @param value The value to set.
  4157. * @param key The key under which to store the value.
  4158. **/
  4159. - (void)setInt64:(int64_t)value forKey:(int64_t)key;
  4160. /**
  4161. * Removes the entry for the given key.
  4162. *
  4163. * @param aKey Key to be removed from this dictionary.
  4164. **/
  4165. - (void)removeInt64ForKey:(int64_t)aKey;
  4166. /**
  4167. * Removes all entries in this dictionary.
  4168. **/
  4169. - (void)removeAll;
  4170. @end
  4171. #pragma mark - Int64 -> Bool
  4172. /**
  4173. * Class used for map fields of <int64_t, BOOL>
  4174. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  4175. *
  4176. * @note This class is not meant to be subclassed.
  4177. **/
  4178. @interface GPBInt64BoolDictionary : NSObject <NSCopying>
  4179. /** Number of entries stored in this dictionary. */
  4180. @property(nonatomic, readonly) NSUInteger count;
  4181. /**
  4182. * @return A newly instanced and empty dictionary.
  4183. **/
  4184. + (instancetype)dictionary;
  4185. /**
  4186. * Creates and initializes a dictionary with the single entry given.
  4187. *
  4188. * @param value The value to be placed in the dictionary.
  4189. * @param key The key under which to store the value.
  4190. *
  4191. * @return A newly instanced dictionary with the key and value in it.
  4192. **/
  4193. + (instancetype)dictionaryWithBool:(BOOL)value
  4194. forKey:(int64_t)key;
  4195. /**
  4196. * Creates and initializes a dictionary with the entries given.
  4197. *
  4198. * @param values The values to be placed in the dictionary.
  4199. * @param keys The keys under which to store the values.
  4200. * @param count The number of entries to store in the dictionary.
  4201. *
  4202. * @return A newly instanced dictionary with the keys and values in it.
  4203. **/
  4204. + (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
  4205. forKeys:(const int64_t [__nullable])keys
  4206. count:(NSUInteger)count;
  4207. /**
  4208. * Creates and initializes a dictionary with the entries from the given.
  4209. * dictionary.
  4210. *
  4211. * @param dictionary Dictionary containing the entries to add to the dictionary.
  4212. *
  4213. * @return A newly instanced dictionary with the entries from the given
  4214. * dictionary in it.
  4215. **/
  4216. + (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary;
  4217. /**
  4218. * Creates and initializes a dictionary with the given capacity.
  4219. *
  4220. * @param numItems Capacity needed for the dictionary.
  4221. *
  4222. * @return A newly instanced dictionary with the given capacity.
  4223. **/
  4224. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  4225. /**
  4226. * Initializes this dictionary, copying the given values and keys.
  4227. *
  4228. * @param values The values to be placed in this dictionary.
  4229. * @param keys The keys under which to store the values.
  4230. * @param count The number of elements to copy into the dictionary.
  4231. *
  4232. * @return A newly initialized dictionary with a copy of the values and keys.
  4233. **/
  4234. - (instancetype)initWithBools:(const BOOL [__nullable])values
  4235. forKeys:(const int64_t [__nullable])keys
  4236. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  4237. /**
  4238. * Initializes this dictionary, copying the entries from the given dictionary.
  4239. *
  4240. * @param dictionary Dictionary containing the entries to add to this dictionary.
  4241. *
  4242. * @return A newly initialized dictionary with the entries of the given dictionary.
  4243. **/
  4244. - (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary;
  4245. /**
  4246. * Initializes this dictionary with the requested capacity.
  4247. *
  4248. * @param numItems Number of items needed for this dictionary.
  4249. *
  4250. * @return A newly initialized dictionary with the requested capacity.
  4251. **/
  4252. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  4253. /**
  4254. * Gets the value for the given key.
  4255. *
  4256. * @param value Pointer into which the value will be set, if found.
  4257. * @param key Key under which the value is stored, if present.
  4258. *
  4259. * @return YES if the key was found and the value was copied, NO otherwise.
  4260. **/
  4261. - (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key;
  4262. /**
  4263. * Enumerates the keys and values on this dictionary with the given block.
  4264. *
  4265. * @param block The block to enumerate with.
  4266. * **key**: The key for the current entry.
  4267. * **value**: The value for the current entry
  4268. * **stop**: A pointer to a boolean that when set stops the enumeration.
  4269. **/
  4270. - (void)enumerateKeysAndBoolsUsingBlock:
  4271. (void (^)(int64_t key, BOOL value, BOOL *stop))block;
  4272. /**
  4273. * Adds the keys and values from another dictionary.
  4274. *
  4275. * @param otherDictionary Dictionary containing entries to be added to this
  4276. * dictionary.
  4277. **/
  4278. - (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary;
  4279. /**
  4280. * Sets the value for the given key.
  4281. *
  4282. * @param value The value to set.
  4283. * @param key The key under which to store the value.
  4284. **/
  4285. - (void)setBool:(BOOL)value forKey:(int64_t)key;
  4286. /**
  4287. * Removes the entry for the given key.
  4288. *
  4289. * @param aKey Key to be removed from this dictionary.
  4290. **/
  4291. - (void)removeBoolForKey:(int64_t)aKey;
  4292. /**
  4293. * Removes all entries in this dictionary.
  4294. **/
  4295. - (void)removeAll;
  4296. @end
  4297. #pragma mark - Int64 -> Float
  4298. /**
  4299. * Class used for map fields of <int64_t, float>
  4300. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  4301. *
  4302. * @note This class is not meant to be subclassed.
  4303. **/
  4304. @interface GPBInt64FloatDictionary : NSObject <NSCopying>
  4305. /** Number of entries stored in this dictionary. */
  4306. @property(nonatomic, readonly) NSUInteger count;
  4307. /**
  4308. * @return A newly instanced and empty dictionary.
  4309. **/
  4310. + (instancetype)dictionary;
  4311. /**
  4312. * Creates and initializes a dictionary with the single entry given.
  4313. *
  4314. * @param value The value to be placed in the dictionary.
  4315. * @param key The key under which to store the value.
  4316. *
  4317. * @return A newly instanced dictionary with the key and value in it.
  4318. **/
  4319. + (instancetype)dictionaryWithFloat:(float)value
  4320. forKey:(int64_t)key;
  4321. /**
  4322. * Creates and initializes a dictionary with the entries given.
  4323. *
  4324. * @param values The values to be placed in the dictionary.
  4325. * @param keys The keys under which to store the values.
  4326. * @param count The number of entries to store in the dictionary.
  4327. *
  4328. * @return A newly instanced dictionary with the keys and values in it.
  4329. **/
  4330. + (instancetype)dictionaryWithFloats:(const float [__nullable])values
  4331. forKeys:(const int64_t [__nullable])keys
  4332. count:(NSUInteger)count;
  4333. /**
  4334. * Creates and initializes a dictionary with the entries from the given.
  4335. * dictionary.
  4336. *
  4337. * @param dictionary Dictionary containing the entries to add to the dictionary.
  4338. *
  4339. * @return A newly instanced dictionary with the entries from the given
  4340. * dictionary in it.
  4341. **/
  4342. + (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary;
  4343. /**
  4344. * Creates and initializes a dictionary with the given capacity.
  4345. *
  4346. * @param numItems Capacity needed for the dictionary.
  4347. *
  4348. * @return A newly instanced dictionary with the given capacity.
  4349. **/
  4350. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  4351. /**
  4352. * Initializes this dictionary, copying the given values and keys.
  4353. *
  4354. * @param values The values to be placed in this dictionary.
  4355. * @param keys The keys under which to store the values.
  4356. * @param count The number of elements to copy into the dictionary.
  4357. *
  4358. * @return A newly initialized dictionary with a copy of the values and keys.
  4359. **/
  4360. - (instancetype)initWithFloats:(const float [__nullable])values
  4361. forKeys:(const int64_t [__nullable])keys
  4362. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  4363. /**
  4364. * Initializes this dictionary, copying the entries from the given dictionary.
  4365. *
  4366. * @param dictionary Dictionary containing the entries to add to this dictionary.
  4367. *
  4368. * @return A newly initialized dictionary with the entries of the given dictionary.
  4369. **/
  4370. - (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary;
  4371. /**
  4372. * Initializes this dictionary with the requested capacity.
  4373. *
  4374. * @param numItems Number of items needed for this dictionary.
  4375. *
  4376. * @return A newly initialized dictionary with the requested capacity.
  4377. **/
  4378. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  4379. /**
  4380. * Gets the value for the given key.
  4381. *
  4382. * @param value Pointer into which the value will be set, if found.
  4383. * @param key Key under which the value is stored, if present.
  4384. *
  4385. * @return YES if the key was found and the value was copied, NO otherwise.
  4386. **/
  4387. - (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key;
  4388. /**
  4389. * Enumerates the keys and values on this dictionary with the given block.
  4390. *
  4391. * @param block The block to enumerate with.
  4392. * **key**: The key for the current entry.
  4393. * **value**: The value for the current entry
  4394. * **stop**: A pointer to a boolean that when set stops the enumeration.
  4395. **/
  4396. - (void)enumerateKeysAndFloatsUsingBlock:
  4397. (void (^)(int64_t key, float value, BOOL *stop))block;
  4398. /**
  4399. * Adds the keys and values from another dictionary.
  4400. *
  4401. * @param otherDictionary Dictionary containing entries to be added to this
  4402. * dictionary.
  4403. **/
  4404. - (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary;
  4405. /**
  4406. * Sets the value for the given key.
  4407. *
  4408. * @param value The value to set.
  4409. * @param key The key under which to store the value.
  4410. **/
  4411. - (void)setFloat:(float)value forKey:(int64_t)key;
  4412. /**
  4413. * Removes the entry for the given key.
  4414. *
  4415. * @param aKey Key to be removed from this dictionary.
  4416. **/
  4417. - (void)removeFloatForKey:(int64_t)aKey;
  4418. /**
  4419. * Removes all entries in this dictionary.
  4420. **/
  4421. - (void)removeAll;
  4422. @end
  4423. #pragma mark - Int64 -> Double
  4424. /**
  4425. * Class used for map fields of <int64_t, double>
  4426. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  4427. *
  4428. * @note This class is not meant to be subclassed.
  4429. **/
  4430. @interface GPBInt64DoubleDictionary : NSObject <NSCopying>
  4431. /** Number of entries stored in this dictionary. */
  4432. @property(nonatomic, readonly) NSUInteger count;
  4433. /**
  4434. * @return A newly instanced and empty dictionary.
  4435. **/
  4436. + (instancetype)dictionary;
  4437. /**
  4438. * Creates and initializes a dictionary with the single entry given.
  4439. *
  4440. * @param value The value to be placed in the dictionary.
  4441. * @param key The key under which to store the value.
  4442. *
  4443. * @return A newly instanced dictionary with the key and value in it.
  4444. **/
  4445. + (instancetype)dictionaryWithDouble:(double)value
  4446. forKey:(int64_t)key;
  4447. /**
  4448. * Creates and initializes a dictionary with the entries given.
  4449. *
  4450. * @param values The values to be placed in the dictionary.
  4451. * @param keys The keys under which to store the values.
  4452. * @param count The number of entries to store in the dictionary.
  4453. *
  4454. * @return A newly instanced dictionary with the keys and values in it.
  4455. **/
  4456. + (instancetype)dictionaryWithDoubles:(const double [__nullable])values
  4457. forKeys:(const int64_t [__nullable])keys
  4458. count:(NSUInteger)count;
  4459. /**
  4460. * Creates and initializes a dictionary with the entries from the given.
  4461. * dictionary.
  4462. *
  4463. * @param dictionary Dictionary containing the entries to add to the dictionary.
  4464. *
  4465. * @return A newly instanced dictionary with the entries from the given
  4466. * dictionary in it.
  4467. **/
  4468. + (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary;
  4469. /**
  4470. * Creates and initializes a dictionary with the given capacity.
  4471. *
  4472. * @param numItems Capacity needed for the dictionary.
  4473. *
  4474. * @return A newly instanced dictionary with the given capacity.
  4475. **/
  4476. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  4477. /**
  4478. * Initializes this dictionary, copying the given values and keys.
  4479. *
  4480. * @param values The values to be placed in this dictionary.
  4481. * @param keys The keys under which to store the values.
  4482. * @param count The number of elements to copy into the dictionary.
  4483. *
  4484. * @return A newly initialized dictionary with a copy of the values and keys.
  4485. **/
  4486. - (instancetype)initWithDoubles:(const double [__nullable])values
  4487. forKeys:(const int64_t [__nullable])keys
  4488. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  4489. /**
  4490. * Initializes this dictionary, copying the entries from the given dictionary.
  4491. *
  4492. * @param dictionary Dictionary containing the entries to add to this dictionary.
  4493. *
  4494. * @return A newly initialized dictionary with the entries of the given dictionary.
  4495. **/
  4496. - (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary;
  4497. /**
  4498. * Initializes this dictionary with the requested capacity.
  4499. *
  4500. * @param numItems Number of items needed for this dictionary.
  4501. *
  4502. * @return A newly initialized dictionary with the requested capacity.
  4503. **/
  4504. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  4505. /**
  4506. * Gets the value for the given key.
  4507. *
  4508. * @param value Pointer into which the value will be set, if found.
  4509. * @param key Key under which the value is stored, if present.
  4510. *
  4511. * @return YES if the key was found and the value was copied, NO otherwise.
  4512. **/
  4513. - (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key;
  4514. /**
  4515. * Enumerates the keys and values on this dictionary with the given block.
  4516. *
  4517. * @param block The block to enumerate with.
  4518. * **key**: The key for the current entry.
  4519. * **value**: The value for the current entry
  4520. * **stop**: A pointer to a boolean that when set stops the enumeration.
  4521. **/
  4522. - (void)enumerateKeysAndDoublesUsingBlock:
  4523. (void (^)(int64_t key, double value, BOOL *stop))block;
  4524. /**
  4525. * Adds the keys and values from another dictionary.
  4526. *
  4527. * @param otherDictionary Dictionary containing entries to be added to this
  4528. * dictionary.
  4529. **/
  4530. - (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary;
  4531. /**
  4532. * Sets the value for the given key.
  4533. *
  4534. * @param value The value to set.
  4535. * @param key The key under which to store the value.
  4536. **/
  4537. - (void)setDouble:(double)value forKey:(int64_t)key;
  4538. /**
  4539. * Removes the entry for the given key.
  4540. *
  4541. * @param aKey Key to be removed from this dictionary.
  4542. **/
  4543. - (void)removeDoubleForKey:(int64_t)aKey;
  4544. /**
  4545. * Removes all entries in this dictionary.
  4546. **/
  4547. - (void)removeAll;
  4548. @end
  4549. #pragma mark - Int64 -> Enum
  4550. /**
  4551. * Class used for map fields of <int64_t, int32_t>
  4552. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  4553. *
  4554. * @note This class is not meant to be subclassed.
  4555. **/
  4556. @interface GPBInt64EnumDictionary : NSObject <NSCopying>
  4557. /** Number of entries stored in this dictionary. */
  4558. @property(nonatomic, readonly) NSUInteger count;
  4559. /** The validation function to check if the enums are valid. */
  4560. @property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
  4561. /**
  4562. * @return A newly instanced and empty dictionary.
  4563. **/
  4564. + (instancetype)dictionary;
  4565. /**
  4566. * Creates and initializes a dictionary with the given validation function.
  4567. *
  4568. * @param func The enum validation function for the dictionary.
  4569. *
  4570. * @return A newly instanced dictionary.
  4571. **/
  4572. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  4573. /**
  4574. * Creates and initializes a dictionary with the single entry given.
  4575. *
  4576. * @param func The enum validation function for the dictionary.
  4577. * @param rawValue The raw enum value to be placed in the dictionary.
  4578. * @param key The key under which to store the value.
  4579. *
  4580. * @return A newly instanced dictionary with the key and value in it.
  4581. **/
  4582. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  4583. rawValue:(int32_t)rawValue
  4584. forKey:(int64_t)key;
  4585. /**
  4586. * Creates and initializes a dictionary with the entries given.
  4587. *
  4588. * @param func The enum validation function for the dictionary.
  4589. * @param values The raw enum values values to be placed in the dictionary.
  4590. * @param keys The keys under which to store the values.
  4591. * @param count The number of entries to store in the dictionary.
  4592. *
  4593. * @return A newly instanced dictionary with the keys and values in it.
  4594. **/
  4595. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  4596. rawValues:(const int32_t [__nullable])values
  4597. forKeys:(const int64_t [__nullable])keys
  4598. count:(NSUInteger)count;
  4599. /**
  4600. * Creates and initializes a dictionary with the entries from the given.
  4601. * dictionary.
  4602. *
  4603. * @param dictionary Dictionary containing the entries to add to the dictionary.
  4604. *
  4605. * @return A newly instanced dictionary with the entries from the given
  4606. * dictionary in it.
  4607. **/
  4608. + (instancetype)dictionaryWithDictionary:(GPBInt64EnumDictionary *)dictionary;
  4609. /**
  4610. * Creates and initializes a dictionary with the given capacity.
  4611. *
  4612. * @param func The enum validation function for the dictionary.
  4613. * @param numItems Capacity needed for the dictionary.
  4614. *
  4615. * @return A newly instanced dictionary with the given capacity.
  4616. **/
  4617. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  4618. capacity:(NSUInteger)numItems;
  4619. /**
  4620. * Initializes a dictionary with the given validation function.
  4621. *
  4622. * @param func The enum validation function for the dictionary.
  4623. *
  4624. * @return A newly initialized dictionary.
  4625. **/
  4626. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  4627. /**
  4628. * Initializes a dictionary with the entries given.
  4629. *
  4630. * @param func The enum validation function for the dictionary.
  4631. * @param values The raw enum values values to be placed in the dictionary.
  4632. * @param keys The keys under which to store the values.
  4633. * @param count The number of entries to store in the dictionary.
  4634. *
  4635. * @return A newly initialized dictionary with the keys and values in it.
  4636. **/
  4637. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  4638. rawValues:(const int32_t [__nullable])values
  4639. forKeys:(const int64_t [__nullable])keys
  4640. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  4641. /**
  4642. * Initializes a dictionary with the entries from the given.
  4643. * dictionary.
  4644. *
  4645. * @param dictionary Dictionary containing the entries to add to the dictionary.
  4646. *
  4647. * @return A newly initialized dictionary with the entries from the given
  4648. * dictionary in it.
  4649. **/
  4650. - (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary;
  4651. /**
  4652. * Initializes a dictionary with the given capacity.
  4653. *
  4654. * @param func The enum validation function for the dictionary.
  4655. * @param numItems Capacity needed for the dictionary.
  4656. *
  4657. * @return A newly initialized dictionary with the given capacity.
  4658. **/
  4659. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  4660. capacity:(NSUInteger)numItems;
  4661. // These will return kGPBUnrecognizedEnumeratorValue if the value for the key
  4662. // is not a valid enumerator as defined by validationFunc. If the actual value is
  4663. // desired, use "raw" version of the method.
  4664. /**
  4665. * Gets the value for the given key.
  4666. *
  4667. * @param value Pointer into which the value will be set, if found.
  4668. * @param key Key under which the value is stored, if present.
  4669. *
  4670. * @return YES if the key was found and the value was copied, NO otherwise.
  4671. **/
  4672. - (BOOL)getEnum:(nullable int32_t *)value forKey:(int64_t)key;
  4673. /**
  4674. * Enumerates the keys and values on this dictionary with the given block.
  4675. *
  4676. * @param block The block to enumerate with.
  4677. * **key**: The key for the current entry.
  4678. * **value**: The value for the current entry
  4679. * **stop**: A pointer to a boolean that when set stops the enumeration.
  4680. **/
  4681. - (void)enumerateKeysAndEnumsUsingBlock:
  4682. (void (^)(int64_t key, int32_t value, BOOL *stop))block;
  4683. /**
  4684. * Gets the raw enum value for the given key.
  4685. *
  4686. * @note This method bypass the validationFunc to enable the access of values that
  4687. * were not known at the time the binary was compiled.
  4688. *
  4689. * @param rawValue Pointer into which the value will be set, if found.
  4690. * @param key Key under which the value is stored, if present.
  4691. *
  4692. * @return YES if the key was found and the value was copied, NO otherwise.
  4693. **/
  4694. - (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(int64_t)key;
  4695. /**
  4696. * Enumerates the keys and values on this dictionary with the given block.
  4697. *
  4698. * @note This method bypass the validationFunc to enable the access of values that
  4699. * were not known at the time the binary was compiled.
  4700. *
  4701. * @param block The block to enumerate with.
  4702. * **key**: The key for the current entry.
  4703. * **rawValue**: The value for the current entry
  4704. * **stop**: A pointer to a boolean that when set stops the enumeration.
  4705. **/
  4706. - (void)enumerateKeysAndRawValuesUsingBlock:
  4707. (void (^)(int64_t key, int32_t rawValue, BOOL *stop))block;
  4708. /**
  4709. * Adds the keys and raw enum values from another dictionary.
  4710. *
  4711. * @note This method bypass the validationFunc to enable the setting of values that
  4712. * were not known at the time the binary was compiled.
  4713. *
  4714. * @param otherDictionary Dictionary containing entries to be added to this
  4715. * dictionary.
  4716. **/
  4717. - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary;
  4718. // If value is not a valid enumerator as defined by validationFunc, these
  4719. // methods will assert in debug, and will log in release and assign the value
  4720. // to the default value. Use the rawValue methods below to assign non enumerator
  4721. // values.
  4722. /**
  4723. * Sets the value for the given key.
  4724. *
  4725. * @param value The value to set.
  4726. * @param key The key under which to store the value.
  4727. **/
  4728. - (void)setEnum:(int32_t)value forKey:(int64_t)key;
  4729. /**
  4730. * Sets the raw enum value for the given key.
  4731. *
  4732. * @note This method bypass the validationFunc to enable the setting of values that
  4733. * were not known at the time the binary was compiled.
  4734. *
  4735. * @param rawValue The raw enum value to set.
  4736. * @param key The key under which to store the raw enum value.
  4737. **/
  4738. - (void)setRawValue:(int32_t)rawValue forKey:(int64_t)key;
  4739. /**
  4740. * Removes the entry for the given key.
  4741. *
  4742. * @param aKey Key to be removed from this dictionary.
  4743. **/
  4744. - (void)removeEnumForKey:(int64_t)aKey;
  4745. /**
  4746. * Removes all entries in this dictionary.
  4747. **/
  4748. - (void)removeAll;
  4749. @end
  4750. #pragma mark - Int64 -> Object
  4751. /**
  4752. * Class used for map fields of <int64_t, ObjectType>
  4753. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  4754. *
  4755. * @note This class is not meant to be subclassed.
  4756. **/
  4757. @interface GPBInt64ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
  4758. /** Number of entries stored in this dictionary. */
  4759. @property(nonatomic, readonly) NSUInteger count;
  4760. /**
  4761. * @return A newly instanced and empty dictionary.
  4762. **/
  4763. + (instancetype)dictionary;
  4764. /**
  4765. * Creates and initializes a dictionary with the single entry given.
  4766. *
  4767. * @param object The value to be placed in the dictionary.
  4768. * @param key The key under which to store the value.
  4769. *
  4770. * @return A newly instanced dictionary with the key and value in it.
  4771. **/
  4772. + (instancetype)dictionaryWithObject:(ObjectType)object
  4773. forKey:(int64_t)key;
  4774. /**
  4775. * Creates and initializes a dictionary with the entries given.
  4776. *
  4777. * @param objects The values to be placed in the dictionary.
  4778. * @param keys The keys under which to store the values.
  4779. * @param count The number of entries to store in the dictionary.
  4780. *
  4781. * @return A newly instanced dictionary with the keys and values in it.
  4782. **/
  4783. + (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
  4784. forKeys:(const int64_t [__nullable])keys
  4785. count:(NSUInteger)count;
  4786. /**
  4787. * Creates and initializes a dictionary with the entries from the given.
  4788. * dictionary.
  4789. *
  4790. * @param dictionary Dictionary containing the entries to add to the dictionary.
  4791. *
  4792. * @return A newly instanced dictionary with the entries from the given
  4793. * dictionary in it.
  4794. **/
  4795. + (instancetype)dictionaryWithDictionary:(GPBInt64ObjectDictionary *)dictionary;
  4796. /**
  4797. * Creates and initializes a dictionary with the given capacity.
  4798. *
  4799. * @param numItems Capacity needed for the dictionary.
  4800. *
  4801. * @return A newly instanced dictionary with the given capacity.
  4802. **/
  4803. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  4804. /**
  4805. * Initializes this dictionary, copying the given values and keys.
  4806. *
  4807. * @param objects The values to be placed in this dictionary.
  4808. * @param keys The keys under which to store the values.
  4809. * @param count The number of elements to copy into the dictionary.
  4810. *
  4811. * @return A newly initialized dictionary with a copy of the values and keys.
  4812. **/
  4813. - (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
  4814. forKeys:(const int64_t [__nullable])keys
  4815. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  4816. /**
  4817. * Initializes this dictionary, copying the entries from the given dictionary.
  4818. *
  4819. * @param dictionary Dictionary containing the entries to add to this dictionary.
  4820. *
  4821. * @return A newly initialized dictionary with the entries of the given dictionary.
  4822. **/
  4823. - (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary;
  4824. /**
  4825. * Initializes this dictionary with the requested capacity.
  4826. *
  4827. * @param numItems Number of items needed for this dictionary.
  4828. *
  4829. * @return A newly initialized dictionary with the requested capacity.
  4830. **/
  4831. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  4832. /**
  4833. * Fetches the object stored under the given key.
  4834. *
  4835. * @param key Key under which the value is stored, if present.
  4836. *
  4837. * @return The object if found, nil otherwise.
  4838. **/
  4839. - (ObjectType)objectForKey:(int64_t)key;
  4840. /**
  4841. * Enumerates the keys and values on this dictionary with the given block.
  4842. *
  4843. * @param block The block to enumerate with.
  4844. * **key**: The key for the current entry.
  4845. * **object**: The value for the current entry
  4846. * **stop**: A pointer to a boolean that when set stops the enumeration.
  4847. **/
  4848. - (void)enumerateKeysAndObjectsUsingBlock:
  4849. (void (^)(int64_t key, ObjectType object, BOOL *stop))block;
  4850. /**
  4851. * Adds the keys and values from another dictionary.
  4852. *
  4853. * @param otherDictionary Dictionary containing entries to be added to this
  4854. * dictionary.
  4855. **/
  4856. - (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary;
  4857. /**
  4858. * Sets the value for the given key.
  4859. *
  4860. * @param object The value to set.
  4861. * @param key The key under which to store the value.
  4862. **/
  4863. - (void)setObject:(ObjectType)object forKey:(int64_t)key;
  4864. /**
  4865. * Removes the entry for the given key.
  4866. *
  4867. * @param aKey Key to be removed from this dictionary.
  4868. **/
  4869. - (void)removeObjectForKey:(int64_t)aKey;
  4870. /**
  4871. * Removes all entries in this dictionary.
  4872. **/
  4873. - (void)removeAll;
  4874. @end
  4875. #pragma mark - Bool -> UInt32
  4876. /**
  4877. * Class used for map fields of <BOOL, uint32_t>
  4878. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  4879. *
  4880. * @note This class is not meant to be subclassed.
  4881. **/
  4882. @interface GPBBoolUInt32Dictionary : NSObject <NSCopying>
  4883. /** Number of entries stored in this dictionary. */
  4884. @property(nonatomic, readonly) NSUInteger count;
  4885. /**
  4886. * @return A newly instanced and empty dictionary.
  4887. **/
  4888. + (instancetype)dictionary;
  4889. /**
  4890. * Creates and initializes a dictionary with the single entry given.
  4891. *
  4892. * @param value The value to be placed in the dictionary.
  4893. * @param key The key under which to store the value.
  4894. *
  4895. * @return A newly instanced dictionary with the key and value in it.
  4896. **/
  4897. + (instancetype)dictionaryWithUInt32:(uint32_t)value
  4898. forKey:(BOOL)key;
  4899. /**
  4900. * Creates and initializes a dictionary with the entries given.
  4901. *
  4902. * @param values The values to be placed in the dictionary.
  4903. * @param keys The keys under which to store the values.
  4904. * @param count The number of entries to store in the dictionary.
  4905. *
  4906. * @return A newly instanced dictionary with the keys and values in it.
  4907. **/
  4908. + (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
  4909. forKeys:(const BOOL [__nullable])keys
  4910. count:(NSUInteger)count;
  4911. /**
  4912. * Creates and initializes a dictionary with the entries from the given.
  4913. * dictionary.
  4914. *
  4915. * @param dictionary Dictionary containing the entries to add to the dictionary.
  4916. *
  4917. * @return A newly instanced dictionary with the entries from the given
  4918. * dictionary in it.
  4919. **/
  4920. + (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary;
  4921. /**
  4922. * Creates and initializes a dictionary with the given capacity.
  4923. *
  4924. * @param numItems Capacity needed for the dictionary.
  4925. *
  4926. * @return A newly instanced dictionary with the given capacity.
  4927. **/
  4928. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  4929. /**
  4930. * Initializes this dictionary, copying the given values and keys.
  4931. *
  4932. * @param values The values to be placed in this dictionary.
  4933. * @param keys The keys under which to store the values.
  4934. * @param count The number of elements to copy into the dictionary.
  4935. *
  4936. * @return A newly initialized dictionary with a copy of the values and keys.
  4937. **/
  4938. - (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
  4939. forKeys:(const BOOL [__nullable])keys
  4940. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  4941. /**
  4942. * Initializes this dictionary, copying the entries from the given dictionary.
  4943. *
  4944. * @param dictionary Dictionary containing the entries to add to this dictionary.
  4945. *
  4946. * @return A newly initialized dictionary with the entries of the given dictionary.
  4947. **/
  4948. - (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary;
  4949. /**
  4950. * Initializes this dictionary with the requested capacity.
  4951. *
  4952. * @param numItems Number of items needed for this dictionary.
  4953. *
  4954. * @return A newly initialized dictionary with the requested capacity.
  4955. **/
  4956. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  4957. /**
  4958. * Gets the value for the given key.
  4959. *
  4960. * @param value Pointer into which the value will be set, if found.
  4961. * @param key Key under which the value is stored, if present.
  4962. *
  4963. * @return YES if the key was found and the value was copied, NO otherwise.
  4964. **/
  4965. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(BOOL)key;
  4966. /**
  4967. * Enumerates the keys and values on this dictionary with the given block.
  4968. *
  4969. * @param block The block to enumerate with.
  4970. * **key**: The key for the current entry.
  4971. * **value**: The value for the current entry
  4972. * **stop**: A pointer to a boolean that when set stops the enumeration.
  4973. **/
  4974. - (void)enumerateKeysAndUInt32sUsingBlock:
  4975. (void (^)(BOOL key, uint32_t value, BOOL *stop))block;
  4976. /**
  4977. * Adds the keys and values from another dictionary.
  4978. *
  4979. * @param otherDictionary Dictionary containing entries to be added to this
  4980. * dictionary.
  4981. **/
  4982. - (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary;
  4983. /**
  4984. * Sets the value for the given key.
  4985. *
  4986. * @param value The value to set.
  4987. * @param key The key under which to store the value.
  4988. **/
  4989. - (void)setUInt32:(uint32_t)value forKey:(BOOL)key;
  4990. /**
  4991. * Removes the entry for the given key.
  4992. *
  4993. * @param aKey Key to be removed from this dictionary.
  4994. **/
  4995. - (void)removeUInt32ForKey:(BOOL)aKey;
  4996. /**
  4997. * Removes all entries in this dictionary.
  4998. **/
  4999. - (void)removeAll;
  5000. @end
  5001. #pragma mark - Bool -> Int32
  5002. /**
  5003. * Class used for map fields of <BOOL, int32_t>
  5004. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  5005. *
  5006. * @note This class is not meant to be subclassed.
  5007. **/
  5008. @interface GPBBoolInt32Dictionary : NSObject <NSCopying>
  5009. /** Number of entries stored in this dictionary. */
  5010. @property(nonatomic, readonly) NSUInteger count;
  5011. /**
  5012. * @return A newly instanced and empty dictionary.
  5013. **/
  5014. + (instancetype)dictionary;
  5015. /**
  5016. * Creates and initializes a dictionary with the single entry given.
  5017. *
  5018. * @param value The value to be placed in the dictionary.
  5019. * @param key The key under which to store the value.
  5020. *
  5021. * @return A newly instanced dictionary with the key and value in it.
  5022. **/
  5023. + (instancetype)dictionaryWithInt32:(int32_t)value
  5024. forKey:(BOOL)key;
  5025. /**
  5026. * Creates and initializes a dictionary with the entries given.
  5027. *
  5028. * @param values The values to be placed in the dictionary.
  5029. * @param keys The keys under which to store the values.
  5030. * @param count The number of entries to store in the dictionary.
  5031. *
  5032. * @return A newly instanced dictionary with the keys and values in it.
  5033. **/
  5034. + (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
  5035. forKeys:(const BOOL [__nullable])keys
  5036. count:(NSUInteger)count;
  5037. /**
  5038. * Creates and initializes a dictionary with the entries from the given.
  5039. * dictionary.
  5040. *
  5041. * @param dictionary Dictionary containing the entries to add to the dictionary.
  5042. *
  5043. * @return A newly instanced dictionary with the entries from the given
  5044. * dictionary in it.
  5045. **/
  5046. + (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary;
  5047. /**
  5048. * Creates and initializes a dictionary with the given capacity.
  5049. *
  5050. * @param numItems Capacity needed for the dictionary.
  5051. *
  5052. * @return A newly instanced dictionary with the given capacity.
  5053. **/
  5054. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  5055. /**
  5056. * Initializes this dictionary, copying the given values and keys.
  5057. *
  5058. * @param values The values to be placed in this dictionary.
  5059. * @param keys The keys under which to store the values.
  5060. * @param count The number of elements to copy into the dictionary.
  5061. *
  5062. * @return A newly initialized dictionary with a copy of the values and keys.
  5063. **/
  5064. - (instancetype)initWithInt32s:(const int32_t [__nullable])values
  5065. forKeys:(const BOOL [__nullable])keys
  5066. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  5067. /**
  5068. * Initializes this dictionary, copying the entries from the given dictionary.
  5069. *
  5070. * @param dictionary Dictionary containing the entries to add to this dictionary.
  5071. *
  5072. * @return A newly initialized dictionary with the entries of the given dictionary.
  5073. **/
  5074. - (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary;
  5075. /**
  5076. * Initializes this dictionary with the requested capacity.
  5077. *
  5078. * @param numItems Number of items needed for this dictionary.
  5079. *
  5080. * @return A newly initialized dictionary with the requested capacity.
  5081. **/
  5082. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  5083. /**
  5084. * Gets the value for the given key.
  5085. *
  5086. * @param value Pointer into which the value will be set, if found.
  5087. * @param key Key under which the value is stored, if present.
  5088. *
  5089. * @return YES if the key was found and the value was copied, NO otherwise.
  5090. **/
  5091. - (BOOL)getInt32:(nullable int32_t *)value forKey:(BOOL)key;
  5092. /**
  5093. * Enumerates the keys and values on this dictionary with the given block.
  5094. *
  5095. * @param block The block to enumerate with.
  5096. * **key**: The key for the current entry.
  5097. * **value**: The value for the current entry
  5098. * **stop**: A pointer to a boolean that when set stops the enumeration.
  5099. **/
  5100. - (void)enumerateKeysAndInt32sUsingBlock:
  5101. (void (^)(BOOL key, int32_t value, BOOL *stop))block;
  5102. /**
  5103. * Adds the keys and values from another dictionary.
  5104. *
  5105. * @param otherDictionary Dictionary containing entries to be added to this
  5106. * dictionary.
  5107. **/
  5108. - (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary;
  5109. /**
  5110. * Sets the value for the given key.
  5111. *
  5112. * @param value The value to set.
  5113. * @param key The key under which to store the value.
  5114. **/
  5115. - (void)setInt32:(int32_t)value forKey:(BOOL)key;
  5116. /**
  5117. * Removes the entry for the given key.
  5118. *
  5119. * @param aKey Key to be removed from this dictionary.
  5120. **/
  5121. - (void)removeInt32ForKey:(BOOL)aKey;
  5122. /**
  5123. * Removes all entries in this dictionary.
  5124. **/
  5125. - (void)removeAll;
  5126. @end
  5127. #pragma mark - Bool -> UInt64
  5128. /**
  5129. * Class used for map fields of <BOOL, uint64_t>
  5130. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  5131. *
  5132. * @note This class is not meant to be subclassed.
  5133. **/
  5134. @interface GPBBoolUInt64Dictionary : NSObject <NSCopying>
  5135. /** Number of entries stored in this dictionary. */
  5136. @property(nonatomic, readonly) NSUInteger count;
  5137. /**
  5138. * @return A newly instanced and empty dictionary.
  5139. **/
  5140. + (instancetype)dictionary;
  5141. /**
  5142. * Creates and initializes a dictionary with the single entry given.
  5143. *
  5144. * @param value The value to be placed in the dictionary.
  5145. * @param key The key under which to store the value.
  5146. *
  5147. * @return A newly instanced dictionary with the key and value in it.
  5148. **/
  5149. + (instancetype)dictionaryWithUInt64:(uint64_t)value
  5150. forKey:(BOOL)key;
  5151. /**
  5152. * Creates and initializes a dictionary with the entries given.
  5153. *
  5154. * @param values The values to be placed in the dictionary.
  5155. * @param keys The keys under which to store the values.
  5156. * @param count The number of entries to store in the dictionary.
  5157. *
  5158. * @return A newly instanced dictionary with the keys and values in it.
  5159. **/
  5160. + (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
  5161. forKeys:(const BOOL [__nullable])keys
  5162. count:(NSUInteger)count;
  5163. /**
  5164. * Creates and initializes a dictionary with the entries from the given.
  5165. * dictionary.
  5166. *
  5167. * @param dictionary Dictionary containing the entries to add to the dictionary.
  5168. *
  5169. * @return A newly instanced dictionary with the entries from the given
  5170. * dictionary in it.
  5171. **/
  5172. + (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary;
  5173. /**
  5174. * Creates and initializes a dictionary with the given capacity.
  5175. *
  5176. * @param numItems Capacity needed for the dictionary.
  5177. *
  5178. * @return A newly instanced dictionary with the given capacity.
  5179. **/
  5180. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  5181. /**
  5182. * Initializes this dictionary, copying the given values and keys.
  5183. *
  5184. * @param values The values to be placed in this dictionary.
  5185. * @param keys The keys under which to store the values.
  5186. * @param count The number of elements to copy into the dictionary.
  5187. *
  5188. * @return A newly initialized dictionary with a copy of the values and keys.
  5189. **/
  5190. - (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
  5191. forKeys:(const BOOL [__nullable])keys
  5192. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  5193. /**
  5194. * Initializes this dictionary, copying the entries from the given dictionary.
  5195. *
  5196. * @param dictionary Dictionary containing the entries to add to this dictionary.
  5197. *
  5198. * @return A newly initialized dictionary with the entries of the given dictionary.
  5199. **/
  5200. - (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary;
  5201. /**
  5202. * Initializes this dictionary with the requested capacity.
  5203. *
  5204. * @param numItems Number of items needed for this dictionary.
  5205. *
  5206. * @return A newly initialized dictionary with the requested capacity.
  5207. **/
  5208. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  5209. /**
  5210. * Gets the value for the given key.
  5211. *
  5212. * @param value Pointer into which the value will be set, if found.
  5213. * @param key Key under which the value is stored, if present.
  5214. *
  5215. * @return YES if the key was found and the value was copied, NO otherwise.
  5216. **/
  5217. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(BOOL)key;
  5218. /**
  5219. * Enumerates the keys and values on this dictionary with the given block.
  5220. *
  5221. * @param block The block to enumerate with.
  5222. * **key**: The key for the current entry.
  5223. * **value**: The value for the current entry
  5224. * **stop**: A pointer to a boolean that when set stops the enumeration.
  5225. **/
  5226. - (void)enumerateKeysAndUInt64sUsingBlock:
  5227. (void (^)(BOOL key, uint64_t value, BOOL *stop))block;
  5228. /**
  5229. * Adds the keys and values from another dictionary.
  5230. *
  5231. * @param otherDictionary Dictionary containing entries to be added to this
  5232. * dictionary.
  5233. **/
  5234. - (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary;
  5235. /**
  5236. * Sets the value for the given key.
  5237. *
  5238. * @param value The value to set.
  5239. * @param key The key under which to store the value.
  5240. **/
  5241. - (void)setUInt64:(uint64_t)value forKey:(BOOL)key;
  5242. /**
  5243. * Removes the entry for the given key.
  5244. *
  5245. * @param aKey Key to be removed from this dictionary.
  5246. **/
  5247. - (void)removeUInt64ForKey:(BOOL)aKey;
  5248. /**
  5249. * Removes all entries in this dictionary.
  5250. **/
  5251. - (void)removeAll;
  5252. @end
  5253. #pragma mark - Bool -> Int64
  5254. /**
  5255. * Class used for map fields of <BOOL, int64_t>
  5256. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  5257. *
  5258. * @note This class is not meant to be subclassed.
  5259. **/
  5260. @interface GPBBoolInt64Dictionary : NSObject <NSCopying>
  5261. /** Number of entries stored in this dictionary. */
  5262. @property(nonatomic, readonly) NSUInteger count;
  5263. /**
  5264. * @return A newly instanced and empty dictionary.
  5265. **/
  5266. + (instancetype)dictionary;
  5267. /**
  5268. * Creates and initializes a dictionary with the single entry given.
  5269. *
  5270. * @param value The value to be placed in the dictionary.
  5271. * @param key The key under which to store the value.
  5272. *
  5273. * @return A newly instanced dictionary with the key and value in it.
  5274. **/
  5275. + (instancetype)dictionaryWithInt64:(int64_t)value
  5276. forKey:(BOOL)key;
  5277. /**
  5278. * Creates and initializes a dictionary with the entries given.
  5279. *
  5280. * @param values The values to be placed in the dictionary.
  5281. * @param keys The keys under which to store the values.
  5282. * @param count The number of entries to store in the dictionary.
  5283. *
  5284. * @return A newly instanced dictionary with the keys and values in it.
  5285. **/
  5286. + (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
  5287. forKeys:(const BOOL [__nullable])keys
  5288. count:(NSUInteger)count;
  5289. /**
  5290. * Creates and initializes a dictionary with the entries from the given.
  5291. * dictionary.
  5292. *
  5293. * @param dictionary Dictionary containing the entries to add to the dictionary.
  5294. *
  5295. * @return A newly instanced dictionary with the entries from the given
  5296. * dictionary in it.
  5297. **/
  5298. + (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary;
  5299. /**
  5300. * Creates and initializes a dictionary with the given capacity.
  5301. *
  5302. * @param numItems Capacity needed for the dictionary.
  5303. *
  5304. * @return A newly instanced dictionary with the given capacity.
  5305. **/
  5306. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  5307. /**
  5308. * Initializes this dictionary, copying the given values and keys.
  5309. *
  5310. * @param values The values to be placed in this dictionary.
  5311. * @param keys The keys under which to store the values.
  5312. * @param count The number of elements to copy into the dictionary.
  5313. *
  5314. * @return A newly initialized dictionary with a copy of the values and keys.
  5315. **/
  5316. - (instancetype)initWithInt64s:(const int64_t [__nullable])values
  5317. forKeys:(const BOOL [__nullable])keys
  5318. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  5319. /**
  5320. * Initializes this dictionary, copying the entries from the given dictionary.
  5321. *
  5322. * @param dictionary Dictionary containing the entries to add to this dictionary.
  5323. *
  5324. * @return A newly initialized dictionary with the entries of the given dictionary.
  5325. **/
  5326. - (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary;
  5327. /**
  5328. * Initializes this dictionary with the requested capacity.
  5329. *
  5330. * @param numItems Number of items needed for this dictionary.
  5331. *
  5332. * @return A newly initialized dictionary with the requested capacity.
  5333. **/
  5334. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  5335. /**
  5336. * Gets the value for the given key.
  5337. *
  5338. * @param value Pointer into which the value will be set, if found.
  5339. * @param key Key under which the value is stored, if present.
  5340. *
  5341. * @return YES if the key was found and the value was copied, NO otherwise.
  5342. **/
  5343. - (BOOL)getInt64:(nullable int64_t *)value forKey:(BOOL)key;
  5344. /**
  5345. * Enumerates the keys and values on this dictionary with the given block.
  5346. *
  5347. * @param block The block to enumerate with.
  5348. * **key**: The key for the current entry.
  5349. * **value**: The value for the current entry
  5350. * **stop**: A pointer to a boolean that when set stops the enumeration.
  5351. **/
  5352. - (void)enumerateKeysAndInt64sUsingBlock:
  5353. (void (^)(BOOL key, int64_t value, BOOL *stop))block;
  5354. /**
  5355. * Adds the keys and values from another dictionary.
  5356. *
  5357. * @param otherDictionary Dictionary containing entries to be added to this
  5358. * dictionary.
  5359. **/
  5360. - (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary;
  5361. /**
  5362. * Sets the value for the given key.
  5363. *
  5364. * @param value The value to set.
  5365. * @param key The key under which to store the value.
  5366. **/
  5367. - (void)setInt64:(int64_t)value forKey:(BOOL)key;
  5368. /**
  5369. * Removes the entry for the given key.
  5370. *
  5371. * @param aKey Key to be removed from this dictionary.
  5372. **/
  5373. - (void)removeInt64ForKey:(BOOL)aKey;
  5374. /**
  5375. * Removes all entries in this dictionary.
  5376. **/
  5377. - (void)removeAll;
  5378. @end
  5379. #pragma mark - Bool -> Bool
  5380. /**
  5381. * Class used for map fields of <BOOL, BOOL>
  5382. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  5383. *
  5384. * @note This class is not meant to be subclassed.
  5385. **/
  5386. @interface GPBBoolBoolDictionary : NSObject <NSCopying>
  5387. /** Number of entries stored in this dictionary. */
  5388. @property(nonatomic, readonly) NSUInteger count;
  5389. /**
  5390. * @return A newly instanced and empty dictionary.
  5391. **/
  5392. + (instancetype)dictionary;
  5393. /**
  5394. * Creates and initializes a dictionary with the single entry given.
  5395. *
  5396. * @param value The value to be placed in the dictionary.
  5397. * @param key The key under which to store the value.
  5398. *
  5399. * @return A newly instanced dictionary with the key and value in it.
  5400. **/
  5401. + (instancetype)dictionaryWithBool:(BOOL)value
  5402. forKey:(BOOL)key;
  5403. /**
  5404. * Creates and initializes a dictionary with the entries given.
  5405. *
  5406. * @param values The values to be placed in the dictionary.
  5407. * @param keys The keys under which to store the values.
  5408. * @param count The number of entries to store in the dictionary.
  5409. *
  5410. * @return A newly instanced dictionary with the keys and values in it.
  5411. **/
  5412. + (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
  5413. forKeys:(const BOOL [__nullable])keys
  5414. count:(NSUInteger)count;
  5415. /**
  5416. * Creates and initializes a dictionary with the entries from the given.
  5417. * dictionary.
  5418. *
  5419. * @param dictionary Dictionary containing the entries to add to the dictionary.
  5420. *
  5421. * @return A newly instanced dictionary with the entries from the given
  5422. * dictionary in it.
  5423. **/
  5424. + (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary;
  5425. /**
  5426. * Creates and initializes a dictionary with the given capacity.
  5427. *
  5428. * @param numItems Capacity needed for the dictionary.
  5429. *
  5430. * @return A newly instanced dictionary with the given capacity.
  5431. **/
  5432. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  5433. /**
  5434. * Initializes this dictionary, copying the given values and keys.
  5435. *
  5436. * @param values The values to be placed in this dictionary.
  5437. * @param keys The keys under which to store the values.
  5438. * @param count The number of elements to copy into the dictionary.
  5439. *
  5440. * @return A newly initialized dictionary with a copy of the values and keys.
  5441. **/
  5442. - (instancetype)initWithBools:(const BOOL [__nullable])values
  5443. forKeys:(const BOOL [__nullable])keys
  5444. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  5445. /**
  5446. * Initializes this dictionary, copying the entries from the given dictionary.
  5447. *
  5448. * @param dictionary Dictionary containing the entries to add to this dictionary.
  5449. *
  5450. * @return A newly initialized dictionary with the entries of the given dictionary.
  5451. **/
  5452. - (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary;
  5453. /**
  5454. * Initializes this dictionary with the requested capacity.
  5455. *
  5456. * @param numItems Number of items needed for this dictionary.
  5457. *
  5458. * @return A newly initialized dictionary with the requested capacity.
  5459. **/
  5460. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  5461. /**
  5462. * Gets the value for the given key.
  5463. *
  5464. * @param value Pointer into which the value will be set, if found.
  5465. * @param key Key under which the value is stored, if present.
  5466. *
  5467. * @return YES if the key was found and the value was copied, NO otherwise.
  5468. **/
  5469. - (BOOL)getBool:(nullable BOOL *)value forKey:(BOOL)key;
  5470. /**
  5471. * Enumerates the keys and values on this dictionary with the given block.
  5472. *
  5473. * @param block The block to enumerate with.
  5474. * **key**: The key for the current entry.
  5475. * **value**: The value for the current entry
  5476. * **stop**: A pointer to a boolean that when set stops the enumeration.
  5477. **/
  5478. - (void)enumerateKeysAndBoolsUsingBlock:
  5479. (void (^)(BOOL key, BOOL value, BOOL *stop))block;
  5480. /**
  5481. * Adds the keys and values from another dictionary.
  5482. *
  5483. * @param otherDictionary Dictionary containing entries to be added to this
  5484. * dictionary.
  5485. **/
  5486. - (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary;
  5487. /**
  5488. * Sets the value for the given key.
  5489. *
  5490. * @param value The value to set.
  5491. * @param key The key under which to store the value.
  5492. **/
  5493. - (void)setBool:(BOOL)value forKey:(BOOL)key;
  5494. /**
  5495. * Removes the entry for the given key.
  5496. *
  5497. * @param aKey Key to be removed from this dictionary.
  5498. **/
  5499. - (void)removeBoolForKey:(BOOL)aKey;
  5500. /**
  5501. * Removes all entries in this dictionary.
  5502. **/
  5503. - (void)removeAll;
  5504. @end
  5505. #pragma mark - Bool -> Float
  5506. /**
  5507. * Class used for map fields of <BOOL, float>
  5508. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  5509. *
  5510. * @note This class is not meant to be subclassed.
  5511. **/
  5512. @interface GPBBoolFloatDictionary : NSObject <NSCopying>
  5513. /** Number of entries stored in this dictionary. */
  5514. @property(nonatomic, readonly) NSUInteger count;
  5515. /**
  5516. * @return A newly instanced and empty dictionary.
  5517. **/
  5518. + (instancetype)dictionary;
  5519. /**
  5520. * Creates and initializes a dictionary with the single entry given.
  5521. *
  5522. * @param value The value to be placed in the dictionary.
  5523. * @param key The key under which to store the value.
  5524. *
  5525. * @return A newly instanced dictionary with the key and value in it.
  5526. **/
  5527. + (instancetype)dictionaryWithFloat:(float)value
  5528. forKey:(BOOL)key;
  5529. /**
  5530. * Creates and initializes a dictionary with the entries given.
  5531. *
  5532. * @param values The values to be placed in the dictionary.
  5533. * @param keys The keys under which to store the values.
  5534. * @param count The number of entries to store in the dictionary.
  5535. *
  5536. * @return A newly instanced dictionary with the keys and values in it.
  5537. **/
  5538. + (instancetype)dictionaryWithFloats:(const float [__nullable])values
  5539. forKeys:(const BOOL [__nullable])keys
  5540. count:(NSUInteger)count;
  5541. /**
  5542. * Creates and initializes a dictionary with the entries from the given.
  5543. * dictionary.
  5544. *
  5545. * @param dictionary Dictionary containing the entries to add to the dictionary.
  5546. *
  5547. * @return A newly instanced dictionary with the entries from the given
  5548. * dictionary in it.
  5549. **/
  5550. + (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary;
  5551. /**
  5552. * Creates and initializes a dictionary with the given capacity.
  5553. *
  5554. * @param numItems Capacity needed for the dictionary.
  5555. *
  5556. * @return A newly instanced dictionary with the given capacity.
  5557. **/
  5558. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  5559. /**
  5560. * Initializes this dictionary, copying the given values and keys.
  5561. *
  5562. * @param values The values to be placed in this dictionary.
  5563. * @param keys The keys under which to store the values.
  5564. * @param count The number of elements to copy into the dictionary.
  5565. *
  5566. * @return A newly initialized dictionary with a copy of the values and keys.
  5567. **/
  5568. - (instancetype)initWithFloats:(const float [__nullable])values
  5569. forKeys:(const BOOL [__nullable])keys
  5570. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  5571. /**
  5572. * Initializes this dictionary, copying the entries from the given dictionary.
  5573. *
  5574. * @param dictionary Dictionary containing the entries to add to this dictionary.
  5575. *
  5576. * @return A newly initialized dictionary with the entries of the given dictionary.
  5577. **/
  5578. - (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary;
  5579. /**
  5580. * Initializes this dictionary with the requested capacity.
  5581. *
  5582. * @param numItems Number of items needed for this dictionary.
  5583. *
  5584. * @return A newly initialized dictionary with the requested capacity.
  5585. **/
  5586. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  5587. /**
  5588. * Gets the value for the given key.
  5589. *
  5590. * @param value Pointer into which the value will be set, if found.
  5591. * @param key Key under which the value is stored, if present.
  5592. *
  5593. * @return YES if the key was found and the value was copied, NO otherwise.
  5594. **/
  5595. - (BOOL)getFloat:(nullable float *)value forKey:(BOOL)key;
  5596. /**
  5597. * Enumerates the keys and values on this dictionary with the given block.
  5598. *
  5599. * @param block The block to enumerate with.
  5600. * **key**: The key for the current entry.
  5601. * **value**: The value for the current entry
  5602. * **stop**: A pointer to a boolean that when set stops the enumeration.
  5603. **/
  5604. - (void)enumerateKeysAndFloatsUsingBlock:
  5605. (void (^)(BOOL key, float value, BOOL *stop))block;
  5606. /**
  5607. * Adds the keys and values from another dictionary.
  5608. *
  5609. * @param otherDictionary Dictionary containing entries to be added to this
  5610. * dictionary.
  5611. **/
  5612. - (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary;
  5613. /**
  5614. * Sets the value for the given key.
  5615. *
  5616. * @param value The value to set.
  5617. * @param key The key under which to store the value.
  5618. **/
  5619. - (void)setFloat:(float)value forKey:(BOOL)key;
  5620. /**
  5621. * Removes the entry for the given key.
  5622. *
  5623. * @param aKey Key to be removed from this dictionary.
  5624. **/
  5625. - (void)removeFloatForKey:(BOOL)aKey;
  5626. /**
  5627. * Removes all entries in this dictionary.
  5628. **/
  5629. - (void)removeAll;
  5630. @end
  5631. #pragma mark - Bool -> Double
  5632. /**
  5633. * Class used for map fields of <BOOL, double>
  5634. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  5635. *
  5636. * @note This class is not meant to be subclassed.
  5637. **/
  5638. @interface GPBBoolDoubleDictionary : NSObject <NSCopying>
  5639. /** Number of entries stored in this dictionary. */
  5640. @property(nonatomic, readonly) NSUInteger count;
  5641. /**
  5642. * @return A newly instanced and empty dictionary.
  5643. **/
  5644. + (instancetype)dictionary;
  5645. /**
  5646. * Creates and initializes a dictionary with the single entry given.
  5647. *
  5648. * @param value The value to be placed in the dictionary.
  5649. * @param key The key under which to store the value.
  5650. *
  5651. * @return A newly instanced dictionary with the key and value in it.
  5652. **/
  5653. + (instancetype)dictionaryWithDouble:(double)value
  5654. forKey:(BOOL)key;
  5655. /**
  5656. * Creates and initializes a dictionary with the entries given.
  5657. *
  5658. * @param values The values to be placed in the dictionary.
  5659. * @param keys The keys under which to store the values.
  5660. * @param count The number of entries to store in the dictionary.
  5661. *
  5662. * @return A newly instanced dictionary with the keys and values in it.
  5663. **/
  5664. + (instancetype)dictionaryWithDoubles:(const double [__nullable])values
  5665. forKeys:(const BOOL [__nullable])keys
  5666. count:(NSUInteger)count;
  5667. /**
  5668. * Creates and initializes a dictionary with the entries from the given.
  5669. * dictionary.
  5670. *
  5671. * @param dictionary Dictionary containing the entries to add to the dictionary.
  5672. *
  5673. * @return A newly instanced dictionary with the entries from the given
  5674. * dictionary in it.
  5675. **/
  5676. + (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary;
  5677. /**
  5678. * Creates and initializes a dictionary with the given capacity.
  5679. *
  5680. * @param numItems Capacity needed for the dictionary.
  5681. *
  5682. * @return A newly instanced dictionary with the given capacity.
  5683. **/
  5684. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  5685. /**
  5686. * Initializes this dictionary, copying the given values and keys.
  5687. *
  5688. * @param values The values to be placed in this dictionary.
  5689. * @param keys The keys under which to store the values.
  5690. * @param count The number of elements to copy into the dictionary.
  5691. *
  5692. * @return A newly initialized dictionary with a copy of the values and keys.
  5693. **/
  5694. - (instancetype)initWithDoubles:(const double [__nullable])values
  5695. forKeys:(const BOOL [__nullable])keys
  5696. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  5697. /**
  5698. * Initializes this dictionary, copying the entries from the given dictionary.
  5699. *
  5700. * @param dictionary Dictionary containing the entries to add to this dictionary.
  5701. *
  5702. * @return A newly initialized dictionary with the entries of the given dictionary.
  5703. **/
  5704. - (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary;
  5705. /**
  5706. * Initializes this dictionary with the requested capacity.
  5707. *
  5708. * @param numItems Number of items needed for this dictionary.
  5709. *
  5710. * @return A newly initialized dictionary with the requested capacity.
  5711. **/
  5712. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  5713. /**
  5714. * Gets the value for the given key.
  5715. *
  5716. * @param value Pointer into which the value will be set, if found.
  5717. * @param key Key under which the value is stored, if present.
  5718. *
  5719. * @return YES if the key was found and the value was copied, NO otherwise.
  5720. **/
  5721. - (BOOL)getDouble:(nullable double *)value forKey:(BOOL)key;
  5722. /**
  5723. * Enumerates the keys and values on this dictionary with the given block.
  5724. *
  5725. * @param block The block to enumerate with.
  5726. * **key**: The key for the current entry.
  5727. * **value**: The value for the current entry
  5728. * **stop**: A pointer to a boolean that when set stops the enumeration.
  5729. **/
  5730. - (void)enumerateKeysAndDoublesUsingBlock:
  5731. (void (^)(BOOL key, double value, BOOL *stop))block;
  5732. /**
  5733. * Adds the keys and values from another dictionary.
  5734. *
  5735. * @param otherDictionary Dictionary containing entries to be added to this
  5736. * dictionary.
  5737. **/
  5738. - (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary;
  5739. /**
  5740. * Sets the value for the given key.
  5741. *
  5742. * @param value The value to set.
  5743. * @param key The key under which to store the value.
  5744. **/
  5745. - (void)setDouble:(double)value forKey:(BOOL)key;
  5746. /**
  5747. * Removes the entry for the given key.
  5748. *
  5749. * @param aKey Key to be removed from this dictionary.
  5750. **/
  5751. - (void)removeDoubleForKey:(BOOL)aKey;
  5752. /**
  5753. * Removes all entries in this dictionary.
  5754. **/
  5755. - (void)removeAll;
  5756. @end
  5757. #pragma mark - Bool -> Enum
  5758. /**
  5759. * Class used for map fields of <BOOL, int32_t>
  5760. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  5761. *
  5762. * @note This class is not meant to be subclassed.
  5763. **/
  5764. @interface GPBBoolEnumDictionary : NSObject <NSCopying>
  5765. /** Number of entries stored in this dictionary. */
  5766. @property(nonatomic, readonly) NSUInteger count;
  5767. /** The validation function to check if the enums are valid. */
  5768. @property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
  5769. /**
  5770. * @return A newly instanced and empty dictionary.
  5771. **/
  5772. + (instancetype)dictionary;
  5773. /**
  5774. * Creates and initializes a dictionary with the given validation function.
  5775. *
  5776. * @param func The enum validation function for the dictionary.
  5777. *
  5778. * @return A newly instanced dictionary.
  5779. **/
  5780. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  5781. /**
  5782. * Creates and initializes a dictionary with the single entry given.
  5783. *
  5784. * @param func The enum validation function for the dictionary.
  5785. * @param rawValue The raw enum value to be placed in the dictionary.
  5786. * @param key The key under which to store the value.
  5787. *
  5788. * @return A newly instanced dictionary with the key and value in it.
  5789. **/
  5790. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  5791. rawValue:(int32_t)rawValue
  5792. forKey:(BOOL)key;
  5793. /**
  5794. * Creates and initializes a dictionary with the entries given.
  5795. *
  5796. * @param func The enum validation function for the dictionary.
  5797. * @param values The raw enum values values to be placed in the dictionary.
  5798. * @param keys The keys under which to store the values.
  5799. * @param count The number of entries to store in the dictionary.
  5800. *
  5801. * @return A newly instanced dictionary with the keys and values in it.
  5802. **/
  5803. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  5804. rawValues:(const int32_t [__nullable])values
  5805. forKeys:(const BOOL [__nullable])keys
  5806. count:(NSUInteger)count;
  5807. /**
  5808. * Creates and initializes a dictionary with the entries from the given.
  5809. * dictionary.
  5810. *
  5811. * @param dictionary Dictionary containing the entries to add to the dictionary.
  5812. *
  5813. * @return A newly instanced dictionary with the entries from the given
  5814. * dictionary in it.
  5815. **/
  5816. + (instancetype)dictionaryWithDictionary:(GPBBoolEnumDictionary *)dictionary;
  5817. /**
  5818. * Creates and initializes a dictionary with the given capacity.
  5819. *
  5820. * @param func The enum validation function for the dictionary.
  5821. * @param numItems Capacity needed for the dictionary.
  5822. *
  5823. * @return A newly instanced dictionary with the given capacity.
  5824. **/
  5825. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  5826. capacity:(NSUInteger)numItems;
  5827. /**
  5828. * Initializes a dictionary with the given validation function.
  5829. *
  5830. * @param func The enum validation function for the dictionary.
  5831. *
  5832. * @return A newly initialized dictionary.
  5833. **/
  5834. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  5835. /**
  5836. * Initializes a dictionary with the entries given.
  5837. *
  5838. * @param func The enum validation function for the dictionary.
  5839. * @param values The raw enum values values to be placed in the dictionary.
  5840. * @param keys The keys under which to store the values.
  5841. * @param count The number of entries to store in the dictionary.
  5842. *
  5843. * @return A newly initialized dictionary with the keys and values in it.
  5844. **/
  5845. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  5846. rawValues:(const int32_t [__nullable])values
  5847. forKeys:(const BOOL [__nullable])keys
  5848. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  5849. /**
  5850. * Initializes a dictionary with the entries from the given.
  5851. * dictionary.
  5852. *
  5853. * @param dictionary Dictionary containing the entries to add to the dictionary.
  5854. *
  5855. * @return A newly initialized dictionary with the entries from the given
  5856. * dictionary in it.
  5857. **/
  5858. - (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary;
  5859. /**
  5860. * Initializes a dictionary with the given capacity.
  5861. *
  5862. * @param func The enum validation function for the dictionary.
  5863. * @param numItems Capacity needed for the dictionary.
  5864. *
  5865. * @return A newly initialized dictionary with the given capacity.
  5866. **/
  5867. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  5868. capacity:(NSUInteger)numItems;
  5869. // These will return kGPBUnrecognizedEnumeratorValue if the value for the key
  5870. // is not a valid enumerator as defined by validationFunc. If the actual value is
  5871. // desired, use "raw" version of the method.
  5872. /**
  5873. * Gets the value for the given key.
  5874. *
  5875. * @param value Pointer into which the value will be set, if found.
  5876. * @param key Key under which the value is stored, if present.
  5877. *
  5878. * @return YES if the key was found and the value was copied, NO otherwise.
  5879. **/
  5880. - (BOOL)getEnum:(nullable int32_t *)value forKey:(BOOL)key;
  5881. /**
  5882. * Enumerates the keys and values on this dictionary with the given block.
  5883. *
  5884. * @param block The block to enumerate with.
  5885. * **key**: The key for the current entry.
  5886. * **value**: The value for the current entry
  5887. * **stop**: A pointer to a boolean that when set stops the enumeration.
  5888. **/
  5889. - (void)enumerateKeysAndEnumsUsingBlock:
  5890. (void (^)(BOOL key, int32_t value, BOOL *stop))block;
  5891. /**
  5892. * Gets the raw enum value for the given key.
  5893. *
  5894. * @note This method bypass the validationFunc to enable the access of values that
  5895. * were not known at the time the binary was compiled.
  5896. *
  5897. * @param rawValue Pointer into which the value will be set, if found.
  5898. * @param key Key under which the value is stored, if present.
  5899. *
  5900. * @return YES if the key was found and the value was copied, NO otherwise.
  5901. **/
  5902. - (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(BOOL)key;
  5903. /**
  5904. * Enumerates the keys and values on this dictionary with the given block.
  5905. *
  5906. * @note This method bypass the validationFunc to enable the access of values that
  5907. * were not known at the time the binary was compiled.
  5908. *
  5909. * @param block The block to enumerate with.
  5910. * **key**: The key for the current entry.
  5911. * **rawValue**: The value for the current entry
  5912. * **stop**: A pointer to a boolean that when set stops the enumeration.
  5913. **/
  5914. - (void)enumerateKeysAndRawValuesUsingBlock:
  5915. (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block;
  5916. /**
  5917. * Adds the keys and raw enum values from another dictionary.
  5918. *
  5919. * @note This method bypass the validationFunc to enable the setting of values that
  5920. * were not known at the time the binary was compiled.
  5921. *
  5922. * @param otherDictionary Dictionary containing entries to be added to this
  5923. * dictionary.
  5924. **/
  5925. - (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary;
  5926. // If value is not a valid enumerator as defined by validationFunc, these
  5927. // methods will assert in debug, and will log in release and assign the value
  5928. // to the default value. Use the rawValue methods below to assign non enumerator
  5929. // values.
  5930. /**
  5931. * Sets the value for the given key.
  5932. *
  5933. * @param value The value to set.
  5934. * @param key The key under which to store the value.
  5935. **/
  5936. - (void)setEnum:(int32_t)value forKey:(BOOL)key;
  5937. /**
  5938. * Sets the raw enum value for the given key.
  5939. *
  5940. * @note This method bypass the validationFunc to enable the setting of values that
  5941. * were not known at the time the binary was compiled.
  5942. *
  5943. * @param rawValue The raw enum value to set.
  5944. * @param key The key under which to store the raw enum value.
  5945. **/
  5946. - (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key;
  5947. /**
  5948. * Removes the entry for the given key.
  5949. *
  5950. * @param aKey Key to be removed from this dictionary.
  5951. **/
  5952. - (void)removeEnumForKey:(BOOL)aKey;
  5953. /**
  5954. * Removes all entries in this dictionary.
  5955. **/
  5956. - (void)removeAll;
  5957. @end
  5958. #pragma mark - Bool -> Object
  5959. /**
  5960. * Class used for map fields of <BOOL, ObjectType>
  5961. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  5962. *
  5963. * @note This class is not meant to be subclassed.
  5964. **/
  5965. @interface GPBBoolObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
  5966. /** Number of entries stored in this dictionary. */
  5967. @property(nonatomic, readonly) NSUInteger count;
  5968. /**
  5969. * @return A newly instanced and empty dictionary.
  5970. **/
  5971. + (instancetype)dictionary;
  5972. /**
  5973. * Creates and initializes a dictionary with the single entry given.
  5974. *
  5975. * @param object The value to be placed in the dictionary.
  5976. * @param key The key under which to store the value.
  5977. *
  5978. * @return A newly instanced dictionary with the key and value in it.
  5979. **/
  5980. + (instancetype)dictionaryWithObject:(ObjectType)object
  5981. forKey:(BOOL)key;
  5982. /**
  5983. * Creates and initializes a dictionary with the entries given.
  5984. *
  5985. * @param objects The values to be placed in the dictionary.
  5986. * @param keys The keys under which to store the values.
  5987. * @param count The number of entries to store in the dictionary.
  5988. *
  5989. * @return A newly instanced dictionary with the keys and values in it.
  5990. **/
  5991. + (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
  5992. forKeys:(const BOOL [__nullable])keys
  5993. count:(NSUInteger)count;
  5994. /**
  5995. * Creates and initializes a dictionary with the entries from the given.
  5996. * dictionary.
  5997. *
  5998. * @param dictionary Dictionary containing the entries to add to the dictionary.
  5999. *
  6000. * @return A newly instanced dictionary with the entries from the given
  6001. * dictionary in it.
  6002. **/
  6003. + (instancetype)dictionaryWithDictionary:(GPBBoolObjectDictionary *)dictionary;
  6004. /**
  6005. * Creates and initializes a dictionary with the given capacity.
  6006. *
  6007. * @param numItems Capacity needed for the dictionary.
  6008. *
  6009. * @return A newly instanced dictionary with the given capacity.
  6010. **/
  6011. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  6012. /**
  6013. * Initializes this dictionary, copying the given values and keys.
  6014. *
  6015. * @param objects The values to be placed in this dictionary.
  6016. * @param keys The keys under which to store the values.
  6017. * @param count The number of elements to copy into the dictionary.
  6018. *
  6019. * @return A newly initialized dictionary with a copy of the values and keys.
  6020. **/
  6021. - (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
  6022. forKeys:(const BOOL [__nullable])keys
  6023. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  6024. /**
  6025. * Initializes this dictionary, copying the entries from the given dictionary.
  6026. *
  6027. * @param dictionary Dictionary containing the entries to add to this dictionary.
  6028. *
  6029. * @return A newly initialized dictionary with the entries of the given dictionary.
  6030. **/
  6031. - (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary;
  6032. /**
  6033. * Initializes this dictionary with the requested capacity.
  6034. *
  6035. * @param numItems Number of items needed for this dictionary.
  6036. *
  6037. * @return A newly initialized dictionary with the requested capacity.
  6038. **/
  6039. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  6040. /**
  6041. * Fetches the object stored under the given key.
  6042. *
  6043. * @param key Key under which the value is stored, if present.
  6044. *
  6045. * @return The object if found, nil otherwise.
  6046. **/
  6047. - (ObjectType)objectForKey:(BOOL)key;
  6048. /**
  6049. * Enumerates the keys and values on this dictionary with the given block.
  6050. *
  6051. * @param block The block to enumerate with.
  6052. * **key**: The key for the current entry.
  6053. * **object**: The value for the current entry
  6054. * **stop**: A pointer to a boolean that when set stops the enumeration.
  6055. **/
  6056. - (void)enumerateKeysAndObjectsUsingBlock:
  6057. (void (^)(BOOL key, ObjectType object, BOOL *stop))block;
  6058. /**
  6059. * Adds the keys and values from another dictionary.
  6060. *
  6061. * @param otherDictionary Dictionary containing entries to be added to this
  6062. * dictionary.
  6063. **/
  6064. - (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary;
  6065. /**
  6066. * Sets the value for the given key.
  6067. *
  6068. * @param object The value to set.
  6069. * @param key The key under which to store the value.
  6070. **/
  6071. - (void)setObject:(ObjectType)object forKey:(BOOL)key;
  6072. /**
  6073. * Removes the entry for the given key.
  6074. *
  6075. * @param aKey Key to be removed from this dictionary.
  6076. **/
  6077. - (void)removeObjectForKey:(BOOL)aKey;
  6078. /**
  6079. * Removes all entries in this dictionary.
  6080. **/
  6081. - (void)removeAll;
  6082. @end
  6083. #pragma mark - String -> UInt32
  6084. /**
  6085. * Class used for map fields of <NSString, uint32_t>
  6086. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  6087. *
  6088. * @note This class is not meant to be subclassed.
  6089. **/
  6090. @interface GPBStringUInt32Dictionary : NSObject <NSCopying>
  6091. /** Number of entries stored in this dictionary. */
  6092. @property(nonatomic, readonly) NSUInteger count;
  6093. /**
  6094. * @return A newly instanced and empty dictionary.
  6095. **/
  6096. + (instancetype)dictionary;
  6097. /**
  6098. * Creates and initializes a dictionary with the single entry given.
  6099. *
  6100. * @param value The value to be placed in the dictionary.
  6101. * @param key The key under which to store the value.
  6102. *
  6103. * @return A newly instanced dictionary with the key and value in it.
  6104. **/
  6105. + (instancetype)dictionaryWithUInt32:(uint32_t)value
  6106. forKey:(NSString *)key;
  6107. /**
  6108. * Creates and initializes a dictionary with the entries given.
  6109. *
  6110. * @param values The values to be placed in the dictionary.
  6111. * @param keys The keys under which to store the values.
  6112. * @param count The number of entries to store in the dictionary.
  6113. *
  6114. * @return A newly instanced dictionary with the keys and values in it.
  6115. **/
  6116. + (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
  6117. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6118. count:(NSUInteger)count;
  6119. /**
  6120. * Creates and initializes a dictionary with the entries from the given.
  6121. * dictionary.
  6122. *
  6123. * @param dictionary Dictionary containing the entries to add to the dictionary.
  6124. *
  6125. * @return A newly instanced dictionary with the entries from the given
  6126. * dictionary in it.
  6127. **/
  6128. + (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary;
  6129. /**
  6130. * Creates and initializes a dictionary with the given capacity.
  6131. *
  6132. * @param numItems Capacity needed for the dictionary.
  6133. *
  6134. * @return A newly instanced dictionary with the given capacity.
  6135. **/
  6136. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  6137. /**
  6138. * Initializes this dictionary, copying the given values and keys.
  6139. *
  6140. * @param values The values to be placed in this dictionary.
  6141. * @param keys The keys under which to store the values.
  6142. * @param count The number of elements to copy into the dictionary.
  6143. *
  6144. * @return A newly initialized dictionary with a copy of the values and keys.
  6145. **/
  6146. - (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
  6147. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6148. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  6149. /**
  6150. * Initializes this dictionary, copying the entries from the given dictionary.
  6151. *
  6152. * @param dictionary Dictionary containing the entries to add to this dictionary.
  6153. *
  6154. * @return A newly initialized dictionary with the entries of the given dictionary.
  6155. **/
  6156. - (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary;
  6157. /**
  6158. * Initializes this dictionary with the requested capacity.
  6159. *
  6160. * @param numItems Number of items needed for this dictionary.
  6161. *
  6162. * @return A newly initialized dictionary with the requested capacity.
  6163. **/
  6164. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  6165. /**
  6166. * Gets the value for the given key.
  6167. *
  6168. * @param value Pointer into which the value will be set, if found.
  6169. * @param key Key under which the value is stored, if present.
  6170. *
  6171. * @return YES if the key was found and the value was copied, NO otherwise.
  6172. **/
  6173. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key;
  6174. /**
  6175. * Enumerates the keys and values on this dictionary with the given block.
  6176. *
  6177. * @param block The block to enumerate with.
  6178. * **key**: The key for the current entry.
  6179. * **value**: The value for the current entry
  6180. * **stop**: A pointer to a boolean that when set stops the enumeration.
  6181. **/
  6182. - (void)enumerateKeysAndUInt32sUsingBlock:
  6183. (void (^)(NSString *key, uint32_t value, BOOL *stop))block;
  6184. /**
  6185. * Adds the keys and values from another dictionary.
  6186. *
  6187. * @param otherDictionary Dictionary containing entries to be added to this
  6188. * dictionary.
  6189. **/
  6190. - (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary;
  6191. /**
  6192. * Sets the value for the given key.
  6193. *
  6194. * @param value The value to set.
  6195. * @param key The key under which to store the value.
  6196. **/
  6197. - (void)setUInt32:(uint32_t)value forKey:(NSString *)key;
  6198. /**
  6199. * Removes the entry for the given key.
  6200. *
  6201. * @param aKey Key to be removed from this dictionary.
  6202. **/
  6203. - (void)removeUInt32ForKey:(NSString *)aKey;
  6204. /**
  6205. * Removes all entries in this dictionary.
  6206. **/
  6207. - (void)removeAll;
  6208. @end
  6209. #pragma mark - String -> Int32
  6210. /**
  6211. * Class used for map fields of <NSString, int32_t>
  6212. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  6213. *
  6214. * @note This class is not meant to be subclassed.
  6215. **/
  6216. @interface GPBStringInt32Dictionary : NSObject <NSCopying>
  6217. /** Number of entries stored in this dictionary. */
  6218. @property(nonatomic, readonly) NSUInteger count;
  6219. /**
  6220. * @return A newly instanced and empty dictionary.
  6221. **/
  6222. + (instancetype)dictionary;
  6223. /**
  6224. * Creates and initializes a dictionary with the single entry given.
  6225. *
  6226. * @param value The value to be placed in the dictionary.
  6227. * @param key The key under which to store the value.
  6228. *
  6229. * @return A newly instanced dictionary with the key and value in it.
  6230. **/
  6231. + (instancetype)dictionaryWithInt32:(int32_t)value
  6232. forKey:(NSString *)key;
  6233. /**
  6234. * Creates and initializes a dictionary with the entries given.
  6235. *
  6236. * @param values The values to be placed in the dictionary.
  6237. * @param keys The keys under which to store the values.
  6238. * @param count The number of entries to store in the dictionary.
  6239. *
  6240. * @return A newly instanced dictionary with the keys and values in it.
  6241. **/
  6242. + (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
  6243. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6244. count:(NSUInteger)count;
  6245. /**
  6246. * Creates and initializes a dictionary with the entries from the given.
  6247. * dictionary.
  6248. *
  6249. * @param dictionary Dictionary containing the entries to add to the dictionary.
  6250. *
  6251. * @return A newly instanced dictionary with the entries from the given
  6252. * dictionary in it.
  6253. **/
  6254. + (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary;
  6255. /**
  6256. * Creates and initializes a dictionary with the given capacity.
  6257. *
  6258. * @param numItems Capacity needed for the dictionary.
  6259. *
  6260. * @return A newly instanced dictionary with the given capacity.
  6261. **/
  6262. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  6263. /**
  6264. * Initializes this dictionary, copying the given values and keys.
  6265. *
  6266. * @param values The values to be placed in this dictionary.
  6267. * @param keys The keys under which to store the values.
  6268. * @param count The number of elements to copy into the dictionary.
  6269. *
  6270. * @return A newly initialized dictionary with a copy of the values and keys.
  6271. **/
  6272. - (instancetype)initWithInt32s:(const int32_t [__nullable])values
  6273. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6274. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  6275. /**
  6276. * Initializes this dictionary, copying the entries from the given dictionary.
  6277. *
  6278. * @param dictionary Dictionary containing the entries to add to this dictionary.
  6279. *
  6280. * @return A newly initialized dictionary with the entries of the given dictionary.
  6281. **/
  6282. - (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary;
  6283. /**
  6284. * Initializes this dictionary with the requested capacity.
  6285. *
  6286. * @param numItems Number of items needed for this dictionary.
  6287. *
  6288. * @return A newly initialized dictionary with the requested capacity.
  6289. **/
  6290. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  6291. /**
  6292. * Gets the value for the given key.
  6293. *
  6294. * @param value Pointer into which the value will be set, if found.
  6295. * @param key Key under which the value is stored, if present.
  6296. *
  6297. * @return YES if the key was found and the value was copied, NO otherwise.
  6298. **/
  6299. - (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key;
  6300. /**
  6301. * Enumerates the keys and values on this dictionary with the given block.
  6302. *
  6303. * @param block The block to enumerate with.
  6304. * **key**: The key for the current entry.
  6305. * **value**: The value for the current entry
  6306. * **stop**: A pointer to a boolean that when set stops the enumeration.
  6307. **/
  6308. - (void)enumerateKeysAndInt32sUsingBlock:
  6309. (void (^)(NSString *key, int32_t value, BOOL *stop))block;
  6310. /**
  6311. * Adds the keys and values from another dictionary.
  6312. *
  6313. * @param otherDictionary Dictionary containing entries to be added to this
  6314. * dictionary.
  6315. **/
  6316. - (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary;
  6317. /**
  6318. * Sets the value for the given key.
  6319. *
  6320. * @param value The value to set.
  6321. * @param key The key under which to store the value.
  6322. **/
  6323. - (void)setInt32:(int32_t)value forKey:(NSString *)key;
  6324. /**
  6325. * Removes the entry for the given key.
  6326. *
  6327. * @param aKey Key to be removed from this dictionary.
  6328. **/
  6329. - (void)removeInt32ForKey:(NSString *)aKey;
  6330. /**
  6331. * Removes all entries in this dictionary.
  6332. **/
  6333. - (void)removeAll;
  6334. @end
  6335. #pragma mark - String -> UInt64
  6336. /**
  6337. * Class used for map fields of <NSString, uint64_t>
  6338. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  6339. *
  6340. * @note This class is not meant to be subclassed.
  6341. **/
  6342. @interface GPBStringUInt64Dictionary : NSObject <NSCopying>
  6343. /** Number of entries stored in this dictionary. */
  6344. @property(nonatomic, readonly) NSUInteger count;
  6345. /**
  6346. * @return A newly instanced and empty dictionary.
  6347. **/
  6348. + (instancetype)dictionary;
  6349. /**
  6350. * Creates and initializes a dictionary with the single entry given.
  6351. *
  6352. * @param value The value to be placed in the dictionary.
  6353. * @param key The key under which to store the value.
  6354. *
  6355. * @return A newly instanced dictionary with the key and value in it.
  6356. **/
  6357. + (instancetype)dictionaryWithUInt64:(uint64_t)value
  6358. forKey:(NSString *)key;
  6359. /**
  6360. * Creates and initializes a dictionary with the entries given.
  6361. *
  6362. * @param values The values to be placed in the dictionary.
  6363. * @param keys The keys under which to store the values.
  6364. * @param count The number of entries to store in the dictionary.
  6365. *
  6366. * @return A newly instanced dictionary with the keys and values in it.
  6367. **/
  6368. + (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
  6369. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6370. count:(NSUInteger)count;
  6371. /**
  6372. * Creates and initializes a dictionary with the entries from the given.
  6373. * dictionary.
  6374. *
  6375. * @param dictionary Dictionary containing the entries to add to the dictionary.
  6376. *
  6377. * @return A newly instanced dictionary with the entries from the given
  6378. * dictionary in it.
  6379. **/
  6380. + (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary;
  6381. /**
  6382. * Creates and initializes a dictionary with the given capacity.
  6383. *
  6384. * @param numItems Capacity needed for the dictionary.
  6385. *
  6386. * @return A newly instanced dictionary with the given capacity.
  6387. **/
  6388. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  6389. /**
  6390. * Initializes this dictionary, copying the given values and keys.
  6391. *
  6392. * @param values The values to be placed in this dictionary.
  6393. * @param keys The keys under which to store the values.
  6394. * @param count The number of elements to copy into the dictionary.
  6395. *
  6396. * @return A newly initialized dictionary with a copy of the values and keys.
  6397. **/
  6398. - (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
  6399. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6400. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  6401. /**
  6402. * Initializes this dictionary, copying the entries from the given dictionary.
  6403. *
  6404. * @param dictionary Dictionary containing the entries to add to this dictionary.
  6405. *
  6406. * @return A newly initialized dictionary with the entries of the given dictionary.
  6407. **/
  6408. - (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary;
  6409. /**
  6410. * Initializes this dictionary with the requested capacity.
  6411. *
  6412. * @param numItems Number of items needed for this dictionary.
  6413. *
  6414. * @return A newly initialized dictionary with the requested capacity.
  6415. **/
  6416. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  6417. /**
  6418. * Gets the value for the given key.
  6419. *
  6420. * @param value Pointer into which the value will be set, if found.
  6421. * @param key Key under which the value is stored, if present.
  6422. *
  6423. * @return YES if the key was found and the value was copied, NO otherwise.
  6424. **/
  6425. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key;
  6426. /**
  6427. * Enumerates the keys and values on this dictionary with the given block.
  6428. *
  6429. * @param block The block to enumerate with.
  6430. * **key**: The key for the current entry.
  6431. * **value**: The value for the current entry
  6432. * **stop**: A pointer to a boolean that when set stops the enumeration.
  6433. **/
  6434. - (void)enumerateKeysAndUInt64sUsingBlock:
  6435. (void (^)(NSString *key, uint64_t value, BOOL *stop))block;
  6436. /**
  6437. * Adds the keys and values from another dictionary.
  6438. *
  6439. * @param otherDictionary Dictionary containing entries to be added to this
  6440. * dictionary.
  6441. **/
  6442. - (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary;
  6443. /**
  6444. * Sets the value for the given key.
  6445. *
  6446. * @param value The value to set.
  6447. * @param key The key under which to store the value.
  6448. **/
  6449. - (void)setUInt64:(uint64_t)value forKey:(NSString *)key;
  6450. /**
  6451. * Removes the entry for the given key.
  6452. *
  6453. * @param aKey Key to be removed from this dictionary.
  6454. **/
  6455. - (void)removeUInt64ForKey:(NSString *)aKey;
  6456. /**
  6457. * Removes all entries in this dictionary.
  6458. **/
  6459. - (void)removeAll;
  6460. @end
  6461. #pragma mark - String -> Int64
  6462. /**
  6463. * Class used for map fields of <NSString, int64_t>
  6464. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  6465. *
  6466. * @note This class is not meant to be subclassed.
  6467. **/
  6468. @interface GPBStringInt64Dictionary : NSObject <NSCopying>
  6469. /** Number of entries stored in this dictionary. */
  6470. @property(nonatomic, readonly) NSUInteger count;
  6471. /**
  6472. * @return A newly instanced and empty dictionary.
  6473. **/
  6474. + (instancetype)dictionary;
  6475. /**
  6476. * Creates and initializes a dictionary with the single entry given.
  6477. *
  6478. * @param value The value to be placed in the dictionary.
  6479. * @param key The key under which to store the value.
  6480. *
  6481. * @return A newly instanced dictionary with the key and value in it.
  6482. **/
  6483. + (instancetype)dictionaryWithInt64:(int64_t)value
  6484. forKey:(NSString *)key;
  6485. /**
  6486. * Creates and initializes a dictionary with the entries given.
  6487. *
  6488. * @param values The values to be placed in the dictionary.
  6489. * @param keys The keys under which to store the values.
  6490. * @param count The number of entries to store in the dictionary.
  6491. *
  6492. * @return A newly instanced dictionary with the keys and values in it.
  6493. **/
  6494. + (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
  6495. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6496. count:(NSUInteger)count;
  6497. /**
  6498. * Creates and initializes a dictionary with the entries from the given.
  6499. * dictionary.
  6500. *
  6501. * @param dictionary Dictionary containing the entries to add to the dictionary.
  6502. *
  6503. * @return A newly instanced dictionary with the entries from the given
  6504. * dictionary in it.
  6505. **/
  6506. + (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary;
  6507. /**
  6508. * Creates and initializes a dictionary with the given capacity.
  6509. *
  6510. * @param numItems Capacity needed for the dictionary.
  6511. *
  6512. * @return A newly instanced dictionary with the given capacity.
  6513. **/
  6514. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  6515. /**
  6516. * Initializes this dictionary, copying the given values and keys.
  6517. *
  6518. * @param values The values to be placed in this dictionary.
  6519. * @param keys The keys under which to store the values.
  6520. * @param count The number of elements to copy into the dictionary.
  6521. *
  6522. * @return A newly initialized dictionary with a copy of the values and keys.
  6523. **/
  6524. - (instancetype)initWithInt64s:(const int64_t [__nullable])values
  6525. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6526. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  6527. /**
  6528. * Initializes this dictionary, copying the entries from the given dictionary.
  6529. *
  6530. * @param dictionary Dictionary containing the entries to add to this dictionary.
  6531. *
  6532. * @return A newly initialized dictionary with the entries of the given dictionary.
  6533. **/
  6534. - (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary;
  6535. /**
  6536. * Initializes this dictionary with the requested capacity.
  6537. *
  6538. * @param numItems Number of items needed for this dictionary.
  6539. *
  6540. * @return A newly initialized dictionary with the requested capacity.
  6541. **/
  6542. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  6543. /**
  6544. * Gets the value for the given key.
  6545. *
  6546. * @param value Pointer into which the value will be set, if found.
  6547. * @param key Key under which the value is stored, if present.
  6548. *
  6549. * @return YES if the key was found and the value was copied, NO otherwise.
  6550. **/
  6551. - (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key;
  6552. /**
  6553. * Enumerates the keys and values on this dictionary with the given block.
  6554. *
  6555. * @param block The block to enumerate with.
  6556. * **key**: The key for the current entry.
  6557. * **value**: The value for the current entry
  6558. * **stop**: A pointer to a boolean that when set stops the enumeration.
  6559. **/
  6560. - (void)enumerateKeysAndInt64sUsingBlock:
  6561. (void (^)(NSString *key, int64_t value, BOOL *stop))block;
  6562. /**
  6563. * Adds the keys and values from another dictionary.
  6564. *
  6565. * @param otherDictionary Dictionary containing entries to be added to this
  6566. * dictionary.
  6567. **/
  6568. - (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary;
  6569. /**
  6570. * Sets the value for the given key.
  6571. *
  6572. * @param value The value to set.
  6573. * @param key The key under which to store the value.
  6574. **/
  6575. - (void)setInt64:(int64_t)value forKey:(NSString *)key;
  6576. /**
  6577. * Removes the entry for the given key.
  6578. *
  6579. * @param aKey Key to be removed from this dictionary.
  6580. **/
  6581. - (void)removeInt64ForKey:(NSString *)aKey;
  6582. /**
  6583. * Removes all entries in this dictionary.
  6584. **/
  6585. - (void)removeAll;
  6586. @end
  6587. #pragma mark - String -> Bool
  6588. /**
  6589. * Class used for map fields of <NSString, BOOL>
  6590. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  6591. *
  6592. * @note This class is not meant to be subclassed.
  6593. **/
  6594. @interface GPBStringBoolDictionary : NSObject <NSCopying>
  6595. /** Number of entries stored in this dictionary. */
  6596. @property(nonatomic, readonly) NSUInteger count;
  6597. /**
  6598. * @return A newly instanced and empty dictionary.
  6599. **/
  6600. + (instancetype)dictionary;
  6601. /**
  6602. * Creates and initializes a dictionary with the single entry given.
  6603. *
  6604. * @param value The value to be placed in the dictionary.
  6605. * @param key The key under which to store the value.
  6606. *
  6607. * @return A newly instanced dictionary with the key and value in it.
  6608. **/
  6609. + (instancetype)dictionaryWithBool:(BOOL)value
  6610. forKey:(NSString *)key;
  6611. /**
  6612. * Creates and initializes a dictionary with the entries given.
  6613. *
  6614. * @param values The values to be placed in the dictionary.
  6615. * @param keys The keys under which to store the values.
  6616. * @param count The number of entries to store in the dictionary.
  6617. *
  6618. * @return A newly instanced dictionary with the keys and values in it.
  6619. **/
  6620. + (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
  6621. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6622. count:(NSUInteger)count;
  6623. /**
  6624. * Creates and initializes a dictionary with the entries from the given.
  6625. * dictionary.
  6626. *
  6627. * @param dictionary Dictionary containing the entries to add to the dictionary.
  6628. *
  6629. * @return A newly instanced dictionary with the entries from the given
  6630. * dictionary in it.
  6631. **/
  6632. + (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary;
  6633. /**
  6634. * Creates and initializes a dictionary with the given capacity.
  6635. *
  6636. * @param numItems Capacity needed for the dictionary.
  6637. *
  6638. * @return A newly instanced dictionary with the given capacity.
  6639. **/
  6640. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  6641. /**
  6642. * Initializes this dictionary, copying the given values and keys.
  6643. *
  6644. * @param values The values to be placed in this dictionary.
  6645. * @param keys The keys under which to store the values.
  6646. * @param count The number of elements to copy into the dictionary.
  6647. *
  6648. * @return A newly initialized dictionary with a copy of the values and keys.
  6649. **/
  6650. - (instancetype)initWithBools:(const BOOL [__nullable])values
  6651. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6652. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  6653. /**
  6654. * Initializes this dictionary, copying the entries from the given dictionary.
  6655. *
  6656. * @param dictionary Dictionary containing the entries to add to this dictionary.
  6657. *
  6658. * @return A newly initialized dictionary with the entries of the given dictionary.
  6659. **/
  6660. - (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary;
  6661. /**
  6662. * Initializes this dictionary with the requested capacity.
  6663. *
  6664. * @param numItems Number of items needed for this dictionary.
  6665. *
  6666. * @return A newly initialized dictionary with the requested capacity.
  6667. **/
  6668. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  6669. /**
  6670. * Gets the value for the given key.
  6671. *
  6672. * @param value Pointer into which the value will be set, if found.
  6673. * @param key Key under which the value is stored, if present.
  6674. *
  6675. * @return YES if the key was found and the value was copied, NO otherwise.
  6676. **/
  6677. - (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key;
  6678. /**
  6679. * Enumerates the keys and values on this dictionary with the given block.
  6680. *
  6681. * @param block The block to enumerate with.
  6682. * **key**: The key for the current entry.
  6683. * **value**: The value for the current entry
  6684. * **stop**: A pointer to a boolean that when set stops the enumeration.
  6685. **/
  6686. - (void)enumerateKeysAndBoolsUsingBlock:
  6687. (void (^)(NSString *key, BOOL value, BOOL *stop))block;
  6688. /**
  6689. * Adds the keys and values from another dictionary.
  6690. *
  6691. * @param otherDictionary Dictionary containing entries to be added to this
  6692. * dictionary.
  6693. **/
  6694. - (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary;
  6695. /**
  6696. * Sets the value for the given key.
  6697. *
  6698. * @param value The value to set.
  6699. * @param key The key under which to store the value.
  6700. **/
  6701. - (void)setBool:(BOOL)value forKey:(NSString *)key;
  6702. /**
  6703. * Removes the entry for the given key.
  6704. *
  6705. * @param aKey Key to be removed from this dictionary.
  6706. **/
  6707. - (void)removeBoolForKey:(NSString *)aKey;
  6708. /**
  6709. * Removes all entries in this dictionary.
  6710. **/
  6711. - (void)removeAll;
  6712. @end
  6713. #pragma mark - String -> Float
  6714. /**
  6715. * Class used for map fields of <NSString, float>
  6716. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  6717. *
  6718. * @note This class is not meant to be subclassed.
  6719. **/
  6720. @interface GPBStringFloatDictionary : NSObject <NSCopying>
  6721. /** Number of entries stored in this dictionary. */
  6722. @property(nonatomic, readonly) NSUInteger count;
  6723. /**
  6724. * @return A newly instanced and empty dictionary.
  6725. **/
  6726. + (instancetype)dictionary;
  6727. /**
  6728. * Creates and initializes a dictionary with the single entry given.
  6729. *
  6730. * @param value The value to be placed in the dictionary.
  6731. * @param key The key under which to store the value.
  6732. *
  6733. * @return A newly instanced dictionary with the key and value in it.
  6734. **/
  6735. + (instancetype)dictionaryWithFloat:(float)value
  6736. forKey:(NSString *)key;
  6737. /**
  6738. * Creates and initializes a dictionary with the entries given.
  6739. *
  6740. * @param values The values to be placed in the dictionary.
  6741. * @param keys The keys under which to store the values.
  6742. * @param count The number of entries to store in the dictionary.
  6743. *
  6744. * @return A newly instanced dictionary with the keys and values in it.
  6745. **/
  6746. + (instancetype)dictionaryWithFloats:(const float [__nullable])values
  6747. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6748. count:(NSUInteger)count;
  6749. /**
  6750. * Creates and initializes a dictionary with the entries from the given.
  6751. * dictionary.
  6752. *
  6753. * @param dictionary Dictionary containing the entries to add to the dictionary.
  6754. *
  6755. * @return A newly instanced dictionary with the entries from the given
  6756. * dictionary in it.
  6757. **/
  6758. + (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary;
  6759. /**
  6760. * Creates and initializes a dictionary with the given capacity.
  6761. *
  6762. * @param numItems Capacity needed for the dictionary.
  6763. *
  6764. * @return A newly instanced dictionary with the given capacity.
  6765. **/
  6766. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  6767. /**
  6768. * Initializes this dictionary, copying the given values and keys.
  6769. *
  6770. * @param values The values to be placed in this dictionary.
  6771. * @param keys The keys under which to store the values.
  6772. * @param count The number of elements to copy into the dictionary.
  6773. *
  6774. * @return A newly initialized dictionary with a copy of the values and keys.
  6775. **/
  6776. - (instancetype)initWithFloats:(const float [__nullable])values
  6777. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6778. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  6779. /**
  6780. * Initializes this dictionary, copying the entries from the given dictionary.
  6781. *
  6782. * @param dictionary Dictionary containing the entries to add to this dictionary.
  6783. *
  6784. * @return A newly initialized dictionary with the entries of the given dictionary.
  6785. **/
  6786. - (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary;
  6787. /**
  6788. * Initializes this dictionary with the requested capacity.
  6789. *
  6790. * @param numItems Number of items needed for this dictionary.
  6791. *
  6792. * @return A newly initialized dictionary with the requested capacity.
  6793. **/
  6794. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  6795. /**
  6796. * Gets the value for the given key.
  6797. *
  6798. * @param value Pointer into which the value will be set, if found.
  6799. * @param key Key under which the value is stored, if present.
  6800. *
  6801. * @return YES if the key was found and the value was copied, NO otherwise.
  6802. **/
  6803. - (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key;
  6804. /**
  6805. * Enumerates the keys and values on this dictionary with the given block.
  6806. *
  6807. * @param block The block to enumerate with.
  6808. * **key**: The key for the current entry.
  6809. * **value**: The value for the current entry
  6810. * **stop**: A pointer to a boolean that when set stops the enumeration.
  6811. **/
  6812. - (void)enumerateKeysAndFloatsUsingBlock:
  6813. (void (^)(NSString *key, float value, BOOL *stop))block;
  6814. /**
  6815. * Adds the keys and values from another dictionary.
  6816. *
  6817. * @param otherDictionary Dictionary containing entries to be added to this
  6818. * dictionary.
  6819. **/
  6820. - (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary;
  6821. /**
  6822. * Sets the value for the given key.
  6823. *
  6824. * @param value The value to set.
  6825. * @param key The key under which to store the value.
  6826. **/
  6827. - (void)setFloat:(float)value forKey:(NSString *)key;
  6828. /**
  6829. * Removes the entry for the given key.
  6830. *
  6831. * @param aKey Key to be removed from this dictionary.
  6832. **/
  6833. - (void)removeFloatForKey:(NSString *)aKey;
  6834. /**
  6835. * Removes all entries in this dictionary.
  6836. **/
  6837. - (void)removeAll;
  6838. @end
  6839. #pragma mark - String -> Double
  6840. /**
  6841. * Class used for map fields of <NSString, double>
  6842. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  6843. *
  6844. * @note This class is not meant to be subclassed.
  6845. **/
  6846. @interface GPBStringDoubleDictionary : NSObject <NSCopying>
  6847. /** Number of entries stored in this dictionary. */
  6848. @property(nonatomic, readonly) NSUInteger count;
  6849. /**
  6850. * @return A newly instanced and empty dictionary.
  6851. **/
  6852. + (instancetype)dictionary;
  6853. /**
  6854. * Creates and initializes a dictionary with the single entry given.
  6855. *
  6856. * @param value The value to be placed in the dictionary.
  6857. * @param key The key under which to store the value.
  6858. *
  6859. * @return A newly instanced dictionary with the key and value in it.
  6860. **/
  6861. + (instancetype)dictionaryWithDouble:(double)value
  6862. forKey:(NSString *)key;
  6863. /**
  6864. * Creates and initializes a dictionary with the entries given.
  6865. *
  6866. * @param values The values to be placed in the dictionary.
  6867. * @param keys The keys under which to store the values.
  6868. * @param count The number of entries to store in the dictionary.
  6869. *
  6870. * @return A newly instanced dictionary with the keys and values in it.
  6871. **/
  6872. + (instancetype)dictionaryWithDoubles:(const double [__nullable])values
  6873. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6874. count:(NSUInteger)count;
  6875. /**
  6876. * Creates and initializes a dictionary with the entries from the given.
  6877. * dictionary.
  6878. *
  6879. * @param dictionary Dictionary containing the entries to add to the dictionary.
  6880. *
  6881. * @return A newly instanced dictionary with the entries from the given
  6882. * dictionary in it.
  6883. **/
  6884. + (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary;
  6885. /**
  6886. * Creates and initializes a dictionary with the given capacity.
  6887. *
  6888. * @param numItems Capacity needed for the dictionary.
  6889. *
  6890. * @return A newly instanced dictionary with the given capacity.
  6891. **/
  6892. + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  6893. /**
  6894. * Initializes this dictionary, copying the given values and keys.
  6895. *
  6896. * @param values The values to be placed in this dictionary.
  6897. * @param keys The keys under which to store the values.
  6898. * @param count The number of elements to copy into the dictionary.
  6899. *
  6900. * @return A newly initialized dictionary with a copy of the values and keys.
  6901. **/
  6902. - (instancetype)initWithDoubles:(const double [__nullable])values
  6903. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  6904. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  6905. /**
  6906. * Initializes this dictionary, copying the entries from the given dictionary.
  6907. *
  6908. * @param dictionary Dictionary containing the entries to add to this dictionary.
  6909. *
  6910. * @return A newly initialized dictionary with the entries of the given dictionary.
  6911. **/
  6912. - (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary;
  6913. /**
  6914. * Initializes this dictionary with the requested capacity.
  6915. *
  6916. * @param numItems Number of items needed for this dictionary.
  6917. *
  6918. * @return A newly initialized dictionary with the requested capacity.
  6919. **/
  6920. - (instancetype)initWithCapacity:(NSUInteger)numItems;
  6921. /**
  6922. * Gets the value for the given key.
  6923. *
  6924. * @param value Pointer into which the value will be set, if found.
  6925. * @param key Key under which the value is stored, if present.
  6926. *
  6927. * @return YES if the key was found and the value was copied, NO otherwise.
  6928. **/
  6929. - (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key;
  6930. /**
  6931. * Enumerates the keys and values on this dictionary with the given block.
  6932. *
  6933. * @param block The block to enumerate with.
  6934. * **key**: The key for the current entry.
  6935. * **value**: The value for the current entry
  6936. * **stop**: A pointer to a boolean that when set stops the enumeration.
  6937. **/
  6938. - (void)enumerateKeysAndDoublesUsingBlock:
  6939. (void (^)(NSString *key, double value, BOOL *stop))block;
  6940. /**
  6941. * Adds the keys and values from another dictionary.
  6942. *
  6943. * @param otherDictionary Dictionary containing entries to be added to this
  6944. * dictionary.
  6945. **/
  6946. - (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary;
  6947. /**
  6948. * Sets the value for the given key.
  6949. *
  6950. * @param value The value to set.
  6951. * @param key The key under which to store the value.
  6952. **/
  6953. - (void)setDouble:(double)value forKey:(NSString *)key;
  6954. /**
  6955. * Removes the entry for the given key.
  6956. *
  6957. * @param aKey Key to be removed from this dictionary.
  6958. **/
  6959. - (void)removeDoubleForKey:(NSString *)aKey;
  6960. /**
  6961. * Removes all entries in this dictionary.
  6962. **/
  6963. - (void)removeAll;
  6964. @end
  6965. #pragma mark - String -> Enum
  6966. /**
  6967. * Class used for map fields of <NSString, int32_t>
  6968. * values. This performs better than boxing into NSNumbers in NSDictionaries.
  6969. *
  6970. * @note This class is not meant to be subclassed.
  6971. **/
  6972. @interface GPBStringEnumDictionary : NSObject <NSCopying>
  6973. /** Number of entries stored in this dictionary. */
  6974. @property(nonatomic, readonly) NSUInteger count;
  6975. /** The validation function to check if the enums are valid. */
  6976. @property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
  6977. /**
  6978. * @return A newly instanced and empty dictionary.
  6979. **/
  6980. + (instancetype)dictionary;
  6981. /**
  6982. * Creates and initializes a dictionary with the given validation function.
  6983. *
  6984. * @param func The enum validation function for the dictionary.
  6985. *
  6986. * @return A newly instanced dictionary.
  6987. **/
  6988. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  6989. /**
  6990. * Creates and initializes a dictionary with the single entry given.
  6991. *
  6992. * @param func The enum validation function for the dictionary.
  6993. * @param rawValue The raw enum value to be placed in the dictionary.
  6994. * @param key The key under which to store the value.
  6995. *
  6996. * @return A newly instanced dictionary with the key and value in it.
  6997. **/
  6998. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  6999. rawValue:(int32_t)rawValue
  7000. forKey:(NSString *)key;
  7001. /**
  7002. * Creates and initializes a dictionary with the entries given.
  7003. *
  7004. * @param func The enum validation function for the dictionary.
  7005. * @param values The raw enum values values to be placed in the dictionary.
  7006. * @param keys The keys under which to store the values.
  7007. * @param count The number of entries to store in the dictionary.
  7008. *
  7009. * @return A newly instanced dictionary with the keys and values in it.
  7010. **/
  7011. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  7012. rawValues:(const int32_t [__nullable])values
  7013. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  7014. count:(NSUInteger)count;
  7015. /**
  7016. * Creates and initializes a dictionary with the entries from the given.
  7017. * dictionary.
  7018. *
  7019. * @param dictionary Dictionary containing the entries to add to the dictionary.
  7020. *
  7021. * @return A newly instanced dictionary with the entries from the given
  7022. * dictionary in it.
  7023. **/
  7024. + (instancetype)dictionaryWithDictionary:(GPBStringEnumDictionary *)dictionary;
  7025. /**
  7026. * Creates and initializes a dictionary with the given capacity.
  7027. *
  7028. * @param func The enum validation function for the dictionary.
  7029. * @param numItems Capacity needed for the dictionary.
  7030. *
  7031. * @return A newly instanced dictionary with the given capacity.
  7032. **/
  7033. + (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  7034. capacity:(NSUInteger)numItems;
  7035. /**
  7036. * Initializes a dictionary with the given validation function.
  7037. *
  7038. * @param func The enum validation function for the dictionary.
  7039. *
  7040. * @return A newly initialized dictionary.
  7041. **/
  7042. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  7043. /**
  7044. * Initializes a dictionary with the entries given.
  7045. *
  7046. * @param func The enum validation function for the dictionary.
  7047. * @param values The raw enum values values to be placed in the dictionary.
  7048. * @param keys The keys under which to store the values.
  7049. * @param count The number of entries to store in the dictionary.
  7050. *
  7051. * @return A newly initialized dictionary with the keys and values in it.
  7052. **/
  7053. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  7054. rawValues:(const int32_t [__nullable])values
  7055. forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
  7056. count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  7057. /**
  7058. * Initializes a dictionary with the entries from the given.
  7059. * dictionary.
  7060. *
  7061. * @param dictionary Dictionary containing the entries to add to the dictionary.
  7062. *
  7063. * @return A newly initialized dictionary with the entries from the given
  7064. * dictionary in it.
  7065. **/
  7066. - (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary;
  7067. /**
  7068. * Initializes a dictionary with the given capacity.
  7069. *
  7070. * @param func The enum validation function for the dictionary.
  7071. * @param numItems Capacity needed for the dictionary.
  7072. *
  7073. * @return A newly initialized dictionary with the given capacity.
  7074. **/
  7075. - (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  7076. capacity:(NSUInteger)numItems;
  7077. // These will return kGPBUnrecognizedEnumeratorValue if the value for the key
  7078. // is not a valid enumerator as defined by validationFunc. If the actual value is
  7079. // desired, use "raw" version of the method.
  7080. /**
  7081. * Gets the value for the given key.
  7082. *
  7083. * @param value Pointer into which the value will be set, if found.
  7084. * @param key Key under which the value is stored, if present.
  7085. *
  7086. * @return YES if the key was found and the value was copied, NO otherwise.
  7087. **/
  7088. - (BOOL)getEnum:(nullable int32_t *)value forKey:(NSString *)key;
  7089. /**
  7090. * Enumerates the keys and values on this dictionary with the given block.
  7091. *
  7092. * @param block The block to enumerate with.
  7093. * **key**: The key for the current entry.
  7094. * **value**: The value for the current entry
  7095. * **stop**: A pointer to a boolean that when set stops the enumeration.
  7096. **/
  7097. - (void)enumerateKeysAndEnumsUsingBlock:
  7098. (void (^)(NSString *key, int32_t value, BOOL *stop))block;
  7099. /**
  7100. * Gets the raw enum value for the given key.
  7101. *
  7102. * @note This method bypass the validationFunc to enable the access of values that
  7103. * were not known at the time the binary was compiled.
  7104. *
  7105. * @param rawValue Pointer into which the value will be set, if found.
  7106. * @param key Key under which the value is stored, if present.
  7107. *
  7108. * @return YES if the key was found and the value was copied, NO otherwise.
  7109. **/
  7110. - (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(NSString *)key;
  7111. /**
  7112. * Enumerates the keys and values on this dictionary with the given block.
  7113. *
  7114. * @note This method bypass the validationFunc to enable the access of values that
  7115. * were not known at the time the binary was compiled.
  7116. *
  7117. * @param block The block to enumerate with.
  7118. * **key**: The key for the current entry.
  7119. * **rawValue**: The value for the current entry
  7120. * **stop**: A pointer to a boolean that when set stops the enumeration.
  7121. **/
  7122. - (void)enumerateKeysAndRawValuesUsingBlock:
  7123. (void (^)(NSString *key, int32_t rawValue, BOOL *stop))block;
  7124. /**
  7125. * Adds the keys and raw enum values from another dictionary.
  7126. *
  7127. * @note This method bypass the validationFunc to enable the setting of values that
  7128. * were not known at the time the binary was compiled.
  7129. *
  7130. * @param otherDictionary Dictionary containing entries to be added to this
  7131. * dictionary.
  7132. **/
  7133. - (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary;
  7134. // If value is not a valid enumerator as defined by validationFunc, these
  7135. // methods will assert in debug, and will log in release and assign the value
  7136. // to the default value. Use the rawValue methods below to assign non enumerator
  7137. // values.
  7138. /**
  7139. * Sets the value for the given key.
  7140. *
  7141. * @param value The value to set.
  7142. * @param key The key under which to store the value.
  7143. **/
  7144. - (void)setEnum:(int32_t)value forKey:(NSString *)key;
  7145. /**
  7146. * Sets the raw enum value for the given key.
  7147. *
  7148. * @note This method bypass the validationFunc to enable the setting of values that
  7149. * were not known at the time the binary was compiled.
  7150. *
  7151. * @param rawValue The raw enum value to set.
  7152. * @param key The key under which to store the raw enum value.
  7153. **/
  7154. - (void)setRawValue:(int32_t)rawValue forKey:(NSString *)key;
  7155. /**
  7156. * Removes the entry for the given key.
  7157. *
  7158. * @param aKey Key to be removed from this dictionary.
  7159. **/
  7160. - (void)removeEnumForKey:(NSString *)aKey;
  7161. /**
  7162. * Removes all entries in this dictionary.
  7163. **/
  7164. - (void)removeAll;
  7165. @end
  7166. //%PDDM-EXPAND-END DECLARE_DICTIONARIES()
  7167. NS_ASSUME_NONNULL_END
  7168. //%PDDM-DEFINE DECLARE_DICTIONARIES()
  7169. //%DICTIONARY_INTERFACES_FOR_POD_KEY(UInt32, uint32_t)
  7170. //%DICTIONARY_INTERFACES_FOR_POD_KEY(Int32, int32_t)
  7171. //%DICTIONARY_INTERFACES_FOR_POD_KEY(UInt64, uint64_t)
  7172. //%DICTIONARY_INTERFACES_FOR_POD_KEY(Int64, int64_t)
  7173. //%DICTIONARY_INTERFACES_FOR_POD_KEY(Bool, BOOL)
  7174. //%DICTIONARY_POD_INTERFACES_FOR_KEY(String, NSString, *, OBJECT)
  7175. //%PDDM-DEFINE DICTIONARY_INTERFACES_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
  7176. //%DICTIONARY_POD_INTERFACES_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
  7177. //%DICTIONARY_POD_KEY_TO_OBJECT_INTERFACE(KEY_NAME, KEY_TYPE, Object, ObjectType)
  7178. //%PDDM-DEFINE DICTIONARY_POD_INTERFACES_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
  7179. //%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, UInt32, uint32_t)
  7180. //%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Int32, int32_t)
  7181. //%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, UInt64, uint64_t)
  7182. //%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Int64, int64_t)
  7183. //%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Bool, BOOL)
  7184. //%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Float, float)
  7185. //%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Double, double)
  7186. //%DICTIONARY_KEY_TO_ENUM_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Enum, int32_t)
  7187. //%PDDM-DEFINE DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE)
  7188. //%DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
  7189. //%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_INTERFACE(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
  7190. //%DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, , POD, VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
  7191. //%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_TYPE, VNAME)
  7192. //%/**
  7193. //% * Gets the value for the given key.
  7194. //% *
  7195. //% * @param value Pointer into which the value will be set, if found.
  7196. //% * @param key Key under which the value is stored, if present.
  7197. //% *
  7198. //% * @return YES if the key was found and the value was copied, NO otherwise.
  7199. //% **/
  7200. //%- (BOOL)get##VNAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key;
  7201. //%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_TYPE, VNAME)
  7202. //%/**
  7203. //% * Fetches the object stored under the given key.
  7204. //% *
  7205. //% * @param key Key under which the value is stored, if present.
  7206. //% *
  7207. //% * @return The object if found, nil otherwise.
  7208. //% **/
  7209. //%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key;
  7210. //%PDDM-DEFINE VALUE_FOR_KEY_Enum(KEY_TYPE, VALUE_TYPE, VNAME)
  7211. //%VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_TYPE, VNAME)
  7212. //%PDDM-DEFINE ARRAY_ARG_MODIFIERPOD()
  7213. // Nothing
  7214. //%PDDM-DEFINE ARRAY_ARG_MODIFIEREnum()
  7215. // Nothing
  7216. //%PDDM-DEFINE ARRAY_ARG_MODIFIEROBJECT()
  7217. //%__nonnull GPB_UNSAFE_UNRETAINED ##
  7218. //%PDDM-DEFINE DICTIONARY_CLASS_DECLPOD(KEY_NAME, VALUE_NAME, VALUE_TYPE)
  7219. //%GPB##KEY_NAME##VALUE_NAME##Dictionary
  7220. //%PDDM-DEFINE DICTIONARY_CLASS_DECLEnum(KEY_NAME, VALUE_NAME, VALUE_TYPE)
  7221. //%GPB##KEY_NAME##VALUE_NAME##Dictionary
  7222. //%PDDM-DEFINE DICTIONARY_CLASS_DECLOBJECT(KEY_NAME, VALUE_NAME, VALUE_TYPE)
  7223. //%GPB##KEY_NAME##VALUE_NAME##Dictionary<__covariant VALUE_TYPE>
  7224. //%PDDM-DEFINE DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
  7225. //%#pragma mark - KEY_NAME -> VALUE_NAME
  7226. //%
  7227. //%/**
  7228. //% * Class used for map fields of <##KEY_TYPE##, ##VALUE_TYPE##>
  7229. //% * values. This performs better than boxing into NSNumbers in NSDictionaries.
  7230. //% *
  7231. //% * @note This class is not meant to be subclassed.
  7232. //% **/
  7233. //%@interface DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) : NSObject <NSCopying>
  7234. //%
  7235. //%/** Number of entries stored in this dictionary. */
  7236. //%@property(nonatomic, readonly) NSUInteger count;
  7237. //%
  7238. //%/**
  7239. //% * @return A newly instanced and empty dictionary.
  7240. //% **/
  7241. //%+ (instancetype)dictionary;
  7242. //%
  7243. //%/**
  7244. //% * Creates and initializes a dictionary with the single entry given.
  7245. //% *
  7246. //% * @param ##VNAME_VAR The value to be placed in the dictionary.
  7247. //% * @param key ##VNAME_VAR$S## The key under which to store the value.
  7248. //% *
  7249. //% * @return A newly instanced dictionary with the key and value in it.
  7250. //% **/
  7251. //%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)##VNAME_VAR
  7252. //% ##VNAME$S## forKey:(KEY_TYPE##KisP$S##KisP)key;
  7253. //%
  7254. //%/**
  7255. //% * Creates and initializes a dictionary with the entries given.
  7256. //% *
  7257. //% * @param ##VNAME_VAR##s The values to be placed in the dictionary.
  7258. //% * @param keys ##VNAME_VAR$S## The keys under which to store the values.
  7259. //% * @param count ##VNAME_VAR$S## The number of entries to store in the dictionary.
  7260. //% *
  7261. //% * @return A newly instanced dictionary with the keys and values in it.
  7262. //% **/
  7263. //%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])##VNAME_VAR##s
  7264. //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
  7265. //% ##VNAME$S## count:(NSUInteger)count;
  7266. //%
  7267. //%/**
  7268. //% * Creates and initializes a dictionary with the entries from the given.
  7269. //% * dictionary.
  7270. //% *
  7271. //% * @param dictionary Dictionary containing the entries to add to the dictionary.
  7272. //% *
  7273. //% * @return A newly instanced dictionary with the entries from the given
  7274. //% * dictionary in it.
  7275. //% **/
  7276. //%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
  7277. //%
  7278. //%/**
  7279. //% * Creates and initializes a dictionary with the given capacity.
  7280. //% *
  7281. //% * @param numItems Capacity needed for the dictionary.
  7282. //% *
  7283. //% * @return A newly instanced dictionary with the given capacity.
  7284. //% **/
  7285. //%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
  7286. //%
  7287. //%/**
  7288. //% * Initializes this dictionary, copying the given values and keys.
  7289. //% *
  7290. //% * @param ##VNAME_VAR##s The values to be placed in this dictionary.
  7291. //% * @param keys ##VNAME_VAR$S## The keys under which to store the values.
  7292. //% * @param count ##VNAME_VAR$S## The number of elements to copy into the dictionary.
  7293. //% *
  7294. //% * @return A newly initialized dictionary with a copy of the values and keys.
  7295. //% **/
  7296. //%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])##VNAME_VAR##s
  7297. //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
  7298. //% ##VNAME$S## count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  7299. //%
  7300. //%/**
  7301. //% * Initializes this dictionary, copying the entries from the given dictionary.
  7302. //% *
  7303. //% * @param dictionary Dictionary containing the entries to add to this dictionary.
  7304. //% *
  7305. //% * @return A newly initialized dictionary with the entries of the given dictionary.
  7306. //% **/
  7307. //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
  7308. //%
  7309. //%/**
  7310. //% * Initializes this dictionary with the requested capacity.
  7311. //% *
  7312. //% * @param numItems Number of items needed for this dictionary.
  7313. //% *
  7314. //% * @return A newly initialized dictionary with the requested capacity.
  7315. //% **/
  7316. //%- (instancetype)initWithCapacity:(NSUInteger)numItems;
  7317. //%
  7318. //%DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
  7319. //%
  7320. //%/**
  7321. //% * Adds the keys and values from another dictionary.
  7322. //% *
  7323. //% * @param otherDictionary Dictionary containing entries to be added to this
  7324. //% * dictionary.
  7325. //% **/
  7326. //%- (void)addEntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary;
  7327. //%
  7328. //%DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
  7329. //%
  7330. //%@end
  7331. //%
  7332. //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE)
  7333. //%DICTIONARY_KEY_TO_ENUM_INTERFACE2(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, Enum)
  7334. //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_INTERFACE2(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, VHELPER)
  7335. //%#pragma mark - KEY_NAME -> VALUE_NAME
  7336. //%
  7337. //%/**
  7338. //% * Class used for map fields of <##KEY_TYPE##, ##VALUE_TYPE##>
  7339. //% * values. This performs better than boxing into NSNumbers in NSDictionaries.
  7340. //% *
  7341. //% * @note This class is not meant to be subclassed.
  7342. //% **/
  7343. //%@interface GPB##KEY_NAME##VALUE_NAME##Dictionary : NSObject <NSCopying>
  7344. //%
  7345. //%/** Number of entries stored in this dictionary. */
  7346. //%@property(nonatomic, readonly) NSUInteger count;
  7347. //%/** The validation function to check if the enums are valid. */
  7348. //%@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
  7349. //%
  7350. //%/**
  7351. //% * @return A newly instanced and empty dictionary.
  7352. //% **/
  7353. //%+ (instancetype)dictionary;
  7354. //%
  7355. //%/**
  7356. //% * Creates and initializes a dictionary with the given validation function.
  7357. //% *
  7358. //% * @param func The enum validation function for the dictionary.
  7359. //% *
  7360. //% * @return A newly instanced dictionary.
  7361. //% **/
  7362. //%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  7363. //%
  7364. //%/**
  7365. //% * Creates and initializes a dictionary with the single entry given.
  7366. //% *
  7367. //% * @param func The enum validation function for the dictionary.
  7368. //% * @param rawValue The raw enum value to be placed in the dictionary.
  7369. //% * @param key The key under which to store the value.
  7370. //% *
  7371. //% * @return A newly instanced dictionary with the key and value in it.
  7372. //% **/
  7373. //%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  7374. //% rawValue:(VALUE_TYPE)rawValue
  7375. //% forKey:(KEY_TYPE##KisP$S##KisP)key;
  7376. //%
  7377. //%/**
  7378. //% * Creates and initializes a dictionary with the entries given.
  7379. //% *
  7380. //% * @param func The enum validation function for the dictionary.
  7381. //% * @param values The raw enum values values to be placed in the dictionary.
  7382. //% * @param keys The keys under which to store the values.
  7383. //% * @param count The number of entries to store in the dictionary.
  7384. //% *
  7385. //% * @return A newly instanced dictionary with the keys and values in it.
  7386. //% **/
  7387. //%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  7388. //% rawValues:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])values
  7389. //% forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
  7390. //% count:(NSUInteger)count;
  7391. //%
  7392. //%/**
  7393. //% * Creates and initializes a dictionary with the entries from the given.
  7394. //% * dictionary.
  7395. //% *
  7396. //% * @param dictionary Dictionary containing the entries to add to the dictionary.
  7397. //% *
  7398. //% * @return A newly instanced dictionary with the entries from the given
  7399. //% * dictionary in it.
  7400. //% **/
  7401. //%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
  7402. //%
  7403. //%/**
  7404. //% * Creates and initializes a dictionary with the given capacity.
  7405. //% *
  7406. //% * @param func The enum validation function for the dictionary.
  7407. //% * @param numItems Capacity needed for the dictionary.
  7408. //% *
  7409. //% * @return A newly instanced dictionary with the given capacity.
  7410. //% **/
  7411. //%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
  7412. //% capacity:(NSUInteger)numItems;
  7413. //%
  7414. //%/**
  7415. //% * Initializes a dictionary with the given validation function.
  7416. //% *
  7417. //% * @param func The enum validation function for the dictionary.
  7418. //% *
  7419. //% * @return A newly initialized dictionary.
  7420. //% **/
  7421. //%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
  7422. //%
  7423. //%/**
  7424. //% * Initializes a dictionary with the entries given.
  7425. //% *
  7426. //% * @param func The enum validation function for the dictionary.
  7427. //% * @param values The raw enum values values to be placed in the dictionary.
  7428. //% * @param keys The keys under which to store the values.
  7429. //% * @param count The number of entries to store in the dictionary.
  7430. //% *
  7431. //% * @return A newly initialized dictionary with the keys and values in it.
  7432. //% **/
  7433. //%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  7434. //% rawValues:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])values
  7435. //% forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
  7436. //% count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
  7437. //%
  7438. //%/**
  7439. //% * Initializes a dictionary with the entries from the given.
  7440. //% * dictionary.
  7441. //% *
  7442. //% * @param dictionary Dictionary containing the entries to add to the dictionary.
  7443. //% *
  7444. //% * @return A newly initialized dictionary with the entries from the given
  7445. //% * dictionary in it.
  7446. //% **/
  7447. //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
  7448. //%
  7449. //%/**
  7450. //% * Initializes a dictionary with the given capacity.
  7451. //% *
  7452. //% * @param func The enum validation function for the dictionary.
  7453. //% * @param numItems Capacity needed for the dictionary.
  7454. //% *
  7455. //% * @return A newly initialized dictionary with the given capacity.
  7456. //% **/
  7457. //%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
  7458. //% capacity:(NSUInteger)numItems;
  7459. //%
  7460. //%// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
  7461. //%// is not a valid enumerator as defined by validationFunc. If the actual value is
  7462. //%// desired, use "raw" version of the method.
  7463. //%
  7464. //%DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, Enum, value)
  7465. //%
  7466. //%/**
  7467. //% * Gets the raw enum value for the given key.
  7468. //% *
  7469. //% * @note This method bypass the validationFunc to enable the access of values that
  7470. //% * were not known at the time the binary was compiled.
  7471. //% *
  7472. //% * @param rawValue Pointer into which the value will be set, if found.
  7473. //% * @param key Key under which the value is stored, if present.
  7474. //% *
  7475. //% * @return YES if the key was found and the value was copied, NO otherwise.
  7476. //% **/
  7477. //%- (BOOL)getRawValue:(nullable VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key;
  7478. //%
  7479. //%/**
  7480. //% * Enumerates the keys and values on this dictionary with the given block.
  7481. //% *
  7482. //% * @note This method bypass the validationFunc to enable the access of values that
  7483. //% * were not known at the time the binary was compiled.
  7484. //% *
  7485. //% * @param block The block to enumerate with.
  7486. //% * **key**: The key for the current entry.
  7487. //% * **rawValue**: The value for the current entry
  7488. //% * **stop**: A pointer to a boolean that when set stops the enumeration.
  7489. //% **/
  7490. //%- (void)enumerateKeysAndRawValuesUsingBlock:
  7491. //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE rawValue, BOOL *stop))block;
  7492. //%
  7493. //%/**
  7494. //% * Adds the keys and raw enum values from another dictionary.
  7495. //% *
  7496. //% * @note This method bypass the validationFunc to enable the setting of values that
  7497. //% * were not known at the time the binary was compiled.
  7498. //% *
  7499. //% * @param otherDictionary Dictionary containing entries to be added to this
  7500. //% * dictionary.
  7501. //% **/
  7502. //%- (void)addRawEntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary;
  7503. //%
  7504. //%// If value is not a valid enumerator as defined by validationFunc, these
  7505. //%// methods will assert in debug, and will log in release and assign the value
  7506. //%// to the default value. Use the rawValue methods below to assign non enumerator
  7507. //%// values.
  7508. //%
  7509. //%DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, Enum, value)
  7510. //%
  7511. //%@end
  7512. //%
  7513. //%PDDM-DEFINE DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
  7514. //%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_TYPE, VNAME)
  7515. //%
  7516. //%/**
  7517. //% * Enumerates the keys and values on this dictionary with the given block.
  7518. //% *
  7519. //% * @param block The block to enumerate with.
  7520. //% * **key**: ##VNAME_VAR$S## The key for the current entry.
  7521. //% * **VNAME_VAR**: The value for the current entry
  7522. //% * **stop**: ##VNAME_VAR$S## A pointer to a boolean that when set stops the enumeration.
  7523. //% **/
  7524. //%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
  7525. //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block;
  7526. //%PDDM-DEFINE DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
  7527. //%/**
  7528. //% * Sets the value for the given key.
  7529. //% *
  7530. //% * @param ##VNAME_VAR The value to set.
  7531. //% * @param key ##VNAME_VAR$S## The key under which to store the value.
  7532. //% **/
  7533. //%- (void)set##VNAME##:(VALUE_TYPE)##VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key;
  7534. //%DICTIONARY_EXTRA_MUTABLE_METHODS_##VHELPER(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
  7535. //%/**
  7536. //% * Removes the entry for the given key.
  7537. //% *
  7538. //% * @param aKey Key to be removed from this dictionary.
  7539. //% **/
  7540. //%- (void)remove##VNAME##ForKey:(KEY_TYPE##KisP$S##KisP)aKey;
  7541. //%
  7542. //%/**
  7543. //% * Removes all entries in this dictionary.
  7544. //% **/
  7545. //%- (void)removeAll;
  7546. //%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_POD(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
  7547. // Empty
  7548. //%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_OBJECT(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
  7549. // Empty
  7550. //%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_Enum(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
  7551. //%
  7552. //%/**
  7553. //% * Sets the raw enum value for the given key.
  7554. //% *
  7555. //% * @note This method bypass the validationFunc to enable the setting of values that
  7556. //% * were not known at the time the binary was compiled.
  7557. //% *
  7558. //% * @param rawValue The raw enum value to set.
  7559. //% * @param key The key under which to store the raw enum value.
  7560. //% **/
  7561. //%- (void)setRawValue:(VALUE_TYPE)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key;
  7562. //%