| OLD | NEW |
| (Empty) |
| 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 | |
| 31 #import "GPBDictionary_PackagePrivate.h" | |
| 32 | |
| 33 #import "GPBCodedInputStream_PackagePrivate.h" | |
| 34 #import "GPBCodedOutputStream.h" | |
| 35 #import "GPBDescriptor_PackagePrivate.h" | |
| 36 #import "GPBMessage_PackagePrivate.h" | |
| 37 #import "GPBUtilities_PackagePrivate.h" | |
| 38 | |
| 39 // ------------------------------ NOTE ------------------------------ | |
| 40 // At the moment, this is all using NSNumbers in NSDictionaries under | |
| 41 // the hood, but it is all hidden so we can come back and optimize | |
| 42 // with direct CFDictionary usage later. The reason that wasn't | |
| 43 // done yet is needing to support 32bit iOS builds. Otherwise | |
| 44 // it would be pretty simple to store all this data in CFDictionaries | |
| 45 // directly. | |
| 46 // ------------------------------------------------------------------ | |
| 47 | |
| 48 enum { | |
| 49 kMapKeyFieldNumber = 1, | |
| 50 kMapValueFieldNumber = 2, | |
| 51 }; | |
| 52 | |
| 53 static BOOL DictDefault_IsValidValue(int32_t value) { | |
| 54 // Anything but the bad value marker is allowed. | |
| 55 return (value != kGPBUnrecognizedEnumeratorValue); | |
| 56 } | |
| 57 | |
| 58 //%PDDM-DEFINE SERIALIZE_SUPPORT_2_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME
1, GPBDATATYPE_NAME2) | |
| 59 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t f
ieldNum, GPBDataType dataType) { | |
| 60 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) { | |
| 61 //% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value); | |
| 62 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) { | |
| 63 //% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value); | |
| 64 //% } else { | |
| 65 //% NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 66 //% return 0; | |
| 67 //% } | |
| 68 //%} | |
| 69 //% | |
| 70 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_
TYPE value, uint32_t fieldNum, GPBDataType dataType) { | |
| 71 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) { | |
| 72 //% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value]; | |
| 73 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) { | |
| 74 //% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value]; | |
| 75 //% } else { | |
| 76 //% NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 77 //% } | |
| 78 //%} | |
| 79 //% | |
| 80 //%PDDM-DEFINE SERIALIZE_SUPPORT_3_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME
1, GPBDATATYPE_NAME2, GPBDATATYPE_NAME3) | |
| 81 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t f
ieldNum, GPBDataType dataType) { | |
| 82 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) { | |
| 83 //% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value); | |
| 84 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) { | |
| 85 //% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value); | |
| 86 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) { | |
| 87 //% return GPBCompute##GPBDATATYPE_NAME3##Size(fieldNum, value); | |
| 88 //% } else { | |
| 89 //% NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 90 //% return 0; | |
| 91 //% } | |
| 92 //%} | |
| 93 //% | |
| 94 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_
TYPE value, uint32_t fieldNum, GPBDataType dataType) { | |
| 95 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) { | |
| 96 //% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value]; | |
| 97 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) { | |
| 98 //% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value]; | |
| 99 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) { | |
| 100 //% [stream write##GPBDATATYPE_NAME3##:fieldNum value:value]; | |
| 101 //% } else { | |
| 102 //% NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 103 //% } | |
| 104 //%} | |
| 105 //% | |
| 106 //%PDDM-DEFINE SIMPLE_SERIALIZE_SUPPORT(VALUE_NAME, VALUE_TYPE, VisP) | |
| 107 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint
32_t fieldNum, GPBDataType dataType) { | |
| 108 //% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType); | |
| 109 //% #pragma unused(dataType) // For when asserts are off in release. | |
| 110 //% return GPBCompute##VALUE_NAME##Size(fieldNum, value); | |
| 111 //%} | |
| 112 //% | |
| 113 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_
TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) { | |
| 114 //% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType); | |
| 115 //% #pragma unused(dataType) // For when asserts are off in release. | |
| 116 //% [stream write##VALUE_NAME##:fieldNum value:value]; | |
| 117 //%} | |
| 118 //% | |
| 119 //%PDDM-DEFINE SERIALIZE_SUPPORT_HELPERS() | |
| 120 //%SERIALIZE_SUPPORT_3_TYPE(Int32, int32_t, Int32, SInt32, SFixed32) | |
| 121 //%SERIALIZE_SUPPORT_2_TYPE(UInt32, uint32_t, UInt32, Fixed32) | |
| 122 //%SERIALIZE_SUPPORT_3_TYPE(Int64, int64_t, Int64, SInt64, SFixed64) | |
| 123 //%SERIALIZE_SUPPORT_2_TYPE(UInt64, uint64_t, UInt64, Fixed64) | |
| 124 //%SIMPLE_SERIALIZE_SUPPORT(Bool, BOOL, ) | |
| 125 //%SIMPLE_SERIALIZE_SUPPORT(Enum, int32_t, ) | |
| 126 //%SIMPLE_SERIALIZE_SUPPORT(Float, float, ) | |
| 127 //%SIMPLE_SERIALIZE_SUPPORT(Double, double, ) | |
| 128 //%SIMPLE_SERIALIZE_SUPPORT(String, NSString, *) | |
| 129 //%SERIALIZE_SUPPORT_3_TYPE(Object, id, Message, String, Bytes) | |
| 130 //%PDDM-EXPAND SERIALIZE_SUPPORT_HELPERS() | |
| 131 // This block of code is generated, do not edit it directly. | |
| 132 | |
| 133 static size_t ComputeDictInt32FieldSize(int32_t value, uint32_t fieldNum, GPBDat
aType dataType) { | |
| 134 if (dataType == GPBDataTypeInt32) { | |
| 135 return GPBComputeInt32Size(fieldNum, value); | |
| 136 } else if (dataType == GPBDataTypeSInt32) { | |
| 137 return GPBComputeSInt32Size(fieldNum, value); | |
| 138 } else if (dataType == GPBDataTypeSFixed32) { | |
| 139 return GPBComputeSFixed32Size(fieldNum, value); | |
| 140 } else { | |
| 141 NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 142 return 0; | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 static void WriteDictInt32Field(GPBCodedOutputStream *stream, int32_t value, uin
t32_t fieldNum, GPBDataType dataType) { | |
| 147 if (dataType == GPBDataTypeInt32) { | |
| 148 [stream writeInt32:fieldNum value:value]; | |
| 149 } else if (dataType == GPBDataTypeSInt32) { | |
| 150 [stream writeSInt32:fieldNum value:value]; | |
| 151 } else if (dataType == GPBDataTypeSFixed32) { | |
| 152 [stream writeSFixed32:fieldNum value:value]; | |
| 153 } else { | |
| 154 NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 155 } | |
| 156 } | |
| 157 | |
| 158 static size_t ComputeDictUInt32FieldSize(uint32_t value, uint32_t fieldNum, GPBD
ataType dataType) { | |
| 159 if (dataType == GPBDataTypeUInt32) { | |
| 160 return GPBComputeUInt32Size(fieldNum, value); | |
| 161 } else if (dataType == GPBDataTypeFixed32) { | |
| 162 return GPBComputeFixed32Size(fieldNum, value); | |
| 163 } else { | |
| 164 NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 165 return 0; | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 static void WriteDictUInt32Field(GPBCodedOutputStream *stream, uint32_t value, u
int32_t fieldNum, GPBDataType dataType) { | |
| 170 if (dataType == GPBDataTypeUInt32) { | |
| 171 [stream writeUInt32:fieldNum value:value]; | |
| 172 } else if (dataType == GPBDataTypeFixed32) { | |
| 173 [stream writeFixed32:fieldNum value:value]; | |
| 174 } else { | |
| 175 NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 176 } | |
| 177 } | |
| 178 | |
| 179 static size_t ComputeDictInt64FieldSize(int64_t value, uint32_t fieldNum, GPBDat
aType dataType) { | |
| 180 if (dataType == GPBDataTypeInt64) { | |
| 181 return GPBComputeInt64Size(fieldNum, value); | |
| 182 } else if (dataType == GPBDataTypeSInt64) { | |
| 183 return GPBComputeSInt64Size(fieldNum, value); | |
| 184 } else if (dataType == GPBDataTypeSFixed64) { | |
| 185 return GPBComputeSFixed64Size(fieldNum, value); | |
| 186 } else { | |
| 187 NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 188 return 0; | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 static void WriteDictInt64Field(GPBCodedOutputStream *stream, int64_t value, uin
t32_t fieldNum, GPBDataType dataType) { | |
| 193 if (dataType == GPBDataTypeInt64) { | |
| 194 [stream writeInt64:fieldNum value:value]; | |
| 195 } else if (dataType == GPBDataTypeSInt64) { | |
| 196 [stream writeSInt64:fieldNum value:value]; | |
| 197 } else if (dataType == GPBDataTypeSFixed64) { | |
| 198 [stream writeSFixed64:fieldNum value:value]; | |
| 199 } else { | |
| 200 NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 201 } | |
| 202 } | |
| 203 | |
| 204 static size_t ComputeDictUInt64FieldSize(uint64_t value, uint32_t fieldNum, GPBD
ataType dataType) { | |
| 205 if (dataType == GPBDataTypeUInt64) { | |
| 206 return GPBComputeUInt64Size(fieldNum, value); | |
| 207 } else if (dataType == GPBDataTypeFixed64) { | |
| 208 return GPBComputeFixed64Size(fieldNum, value); | |
| 209 } else { | |
| 210 NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 211 return 0; | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 static void WriteDictUInt64Field(GPBCodedOutputStream *stream, uint64_t value, u
int32_t fieldNum, GPBDataType dataType) { | |
| 216 if (dataType == GPBDataTypeUInt64) { | |
| 217 [stream writeUInt64:fieldNum value:value]; | |
| 218 } else if (dataType == GPBDataTypeFixed64) { | |
| 219 [stream writeFixed64:fieldNum value:value]; | |
| 220 } else { | |
| 221 NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 222 } | |
| 223 } | |
| 224 | |
| 225 static size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, GPBDataTyp
e dataType) { | |
| 226 NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType); | |
| 227 #pragma unused(dataType) // For when asserts are off in release. | |
| 228 return GPBComputeBoolSize(fieldNum, value); | |
| 229 } | |
| 230 | |
| 231 static void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_
t fieldNum, GPBDataType dataType) { | |
| 232 NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType); | |
| 233 #pragma unused(dataType) // For when asserts are off in release. | |
| 234 [stream writeBool:fieldNum value:value]; | |
| 235 } | |
| 236 | |
| 237 static size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, GPBData
Type dataType) { | |
| 238 NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType); | |
| 239 #pragma unused(dataType) // For when asserts are off in release. | |
| 240 return GPBComputeEnumSize(fieldNum, value); | |
| 241 } | |
| 242 | |
| 243 static void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint
32_t fieldNum, GPBDataType dataType) { | |
| 244 NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType); | |
| 245 #pragma unused(dataType) // For when asserts are off in release. | |
| 246 [stream writeEnum:fieldNum value:value]; | |
| 247 } | |
| 248 | |
| 249 static size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, GPBDataT
ype dataType) { | |
| 250 NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType); | |
| 251 #pragma unused(dataType) // For when asserts are off in release. | |
| 252 return GPBComputeFloatSize(fieldNum, value); | |
| 253 } | |
| 254 | |
| 255 static void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint3
2_t fieldNum, GPBDataType dataType) { | |
| 256 NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType); | |
| 257 #pragma unused(dataType) // For when asserts are off in release. | |
| 258 [stream writeFloat:fieldNum value:value]; | |
| 259 } | |
| 260 | |
| 261 static size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, GPBDat
aType dataType) { | |
| 262 NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType); | |
| 263 #pragma unused(dataType) // For when asserts are off in release. | |
| 264 return GPBComputeDoubleSize(fieldNum, value); | |
| 265 } | |
| 266 | |
| 267 static void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uin
t32_t fieldNum, GPBDataType dataType) { | |
| 268 NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType); | |
| 269 #pragma unused(dataType) // For when asserts are off in release. | |
| 270 [stream writeDouble:fieldNum value:value]; | |
| 271 } | |
| 272 | |
| 273 static size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, GPB
DataType dataType) { | |
| 274 NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType); | |
| 275 #pragma unused(dataType) // For when asserts are off in release. | |
| 276 return GPBComputeStringSize(fieldNum, value); | |
| 277 } | |
| 278 | |
| 279 static void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value,
uint32_t fieldNum, GPBDataType dataType) { | |
| 280 NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType); | |
| 281 #pragma unused(dataType) // For when asserts are off in release. | |
| 282 [stream writeString:fieldNum value:value]; | |
| 283 } | |
| 284 | |
| 285 static size_t ComputeDictObjectFieldSize(id value, uint32_t fieldNum, GPBDataTyp
e dataType) { | |
| 286 if (dataType == GPBDataTypeMessage) { | |
| 287 return GPBComputeMessageSize(fieldNum, value); | |
| 288 } else if (dataType == GPBDataTypeString) { | |
| 289 return GPBComputeStringSize(fieldNum, value); | |
| 290 } else if (dataType == GPBDataTypeBytes) { | |
| 291 return GPBComputeBytesSize(fieldNum, value); | |
| 292 } else { | |
| 293 NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 294 return 0; | |
| 295 } | |
| 296 } | |
| 297 | |
| 298 static void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_
t fieldNum, GPBDataType dataType) { | |
| 299 if (dataType == GPBDataTypeMessage) { | |
| 300 [stream writeMessage:fieldNum value:value]; | |
| 301 } else if (dataType == GPBDataTypeString) { | |
| 302 [stream writeString:fieldNum value:value]; | |
| 303 } else if (dataType == GPBDataTypeBytes) { | |
| 304 [stream writeBytes:fieldNum value:value]; | |
| 305 } else { | |
| 306 NSCAssert(NO, @"Unexpected type %d", dataType); | |
| 307 } | |
| 308 } | |
| 309 | |
| 310 //%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS() | |
| 311 | |
| 312 size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescri
ptor *field) { | |
| 313 GPBDataType mapValueType = GPBGetFieldDataType(field); | |
| 314 __block size_t result = 0; | |
| 315 [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { | |
| 316 #pragma unused(stop) | |
| 317 size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key); | |
| 318 msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueTyp
e); | |
| 319 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 320 }]; | |
| 321 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 322 result += tagSize * dict.count; | |
| 323 return result; | |
| 324 } | |
| 325 | |
| 326 void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream
, | |
| 327 NSDictionary *dict, | |
| 328 GPBFieldDescriptor *field) { | |
| 329 NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type"); | |
| 330 GPBDataType mapValueType = GPBGetFieldDataType(field); | |
| 331 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 332 [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { | |
| 333 #pragma unused(stop) | |
| 334 // Write the tag. | |
| 335 [outputStream writeInt32NoTag:tag]; | |
| 336 // Write the size of the message. | |
| 337 size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key); | |
| 338 msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueTyp
e); | |
| 339 | |
| 340 // Write the size and fields. | |
| 341 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 342 [outputStream writeString:kMapKeyFieldNumber value:key]; | |
| 343 WriteDictObjectField(outputStream, obj, kMapValueFieldNumber, mapValueType); | |
| 344 }]; | |
| 345 } | |
| 346 | |
| 347 BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescri
ptor *field) { | |
| 348 NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type"); | |
| 349 NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value
type"); | |
| 350 #pragma unused(field) // For when asserts are off in release. | |
| 351 for (GPBMessage *msg in [dict objectEnumerator]) { | |
| 352 if (!msg.initialized) { | |
| 353 return NO; | |
| 354 } | |
| 355 } | |
| 356 return YES; | |
| 357 } | |
| 358 | |
| 359 // Note: if the type is an object, it the retain pass back to the caller. | |
| 360 static void ReadValue(GPBCodedInputStream *stream, | |
| 361 GPBGenericValue *valueToFill, | |
| 362 GPBDataType type, | |
| 363 GPBExtensionRegistry *registry, | |
| 364 GPBFieldDescriptor *field) { | |
| 365 switch (type) { | |
| 366 case GPBDataTypeBool: | |
| 367 valueToFill->valueBool = GPBCodedInputStreamReadBool(&stream->state_); | |
| 368 break; | |
| 369 case GPBDataTypeFixed32: | |
| 370 valueToFill->valueUInt32 = GPBCodedInputStreamReadFixed32(&stream->state_)
; | |
| 371 break; | |
| 372 case GPBDataTypeSFixed32: | |
| 373 valueToFill->valueInt32 = GPBCodedInputStreamReadSFixed32(&stream->state_)
; | |
| 374 break; | |
| 375 case GPBDataTypeFloat: | |
| 376 valueToFill->valueFloat = GPBCodedInputStreamReadFloat(&stream->state_); | |
| 377 break; | |
| 378 case GPBDataTypeFixed64: | |
| 379 valueToFill->valueUInt64 = GPBCodedInputStreamReadFixed64(&stream->state_)
; | |
| 380 break; | |
| 381 case GPBDataTypeSFixed64: | |
| 382 valueToFill->valueInt64 = GPBCodedInputStreamReadSFixed64(&stream->state_)
; | |
| 383 break; | |
| 384 case GPBDataTypeDouble: | |
| 385 valueToFill->valueDouble = GPBCodedInputStreamReadDouble(&stream->state_); | |
| 386 break; | |
| 387 case GPBDataTypeInt32: | |
| 388 valueToFill->valueInt32 = GPBCodedInputStreamReadInt32(&stream->state_); | |
| 389 break; | |
| 390 case GPBDataTypeInt64: | |
| 391 valueToFill->valueInt64 = GPBCodedInputStreamReadInt32(&stream->state_); | |
| 392 break; | |
| 393 case GPBDataTypeSInt32: | |
| 394 valueToFill->valueInt32 = GPBCodedInputStreamReadSInt32(&stream->state_); | |
| 395 break; | |
| 396 case GPBDataTypeSInt64: | |
| 397 valueToFill->valueInt64 = GPBCodedInputStreamReadSInt64(&stream->state_); | |
| 398 break; | |
| 399 case GPBDataTypeUInt32: | |
| 400 valueToFill->valueUInt32 = GPBCodedInputStreamReadUInt32(&stream->state_); | |
| 401 break; | |
| 402 case GPBDataTypeUInt64: | |
| 403 valueToFill->valueUInt64 = GPBCodedInputStreamReadUInt64(&stream->state_); | |
| 404 break; | |
| 405 case GPBDataTypeBytes: | |
| 406 [valueToFill->valueData release]; | |
| 407 valueToFill->valueData = GPBCodedInputStreamReadRetainedBytes(&stream->sta
te_); | |
| 408 break; | |
| 409 case GPBDataTypeString: | |
| 410 [valueToFill->valueString release]; | |
| 411 valueToFill->valueString = GPBCodedInputStreamReadRetainedString(&stream->
state_); | |
| 412 break; | |
| 413 case GPBDataTypeMessage: { | |
| 414 GPBMessage *message = [[field.msgClass alloc] init]; | |
| 415 [stream readMessage:message extensionRegistry:registry]; | |
| 416 [valueToFill->valueMessage release]; | |
| 417 valueToFill->valueMessage = message; | |
| 418 break; | |
| 419 } | |
| 420 case GPBDataTypeGroup: | |
| 421 NSCAssert(NO, @"Can't happen"); | |
| 422 break; | |
| 423 case GPBDataTypeEnum: | |
| 424 valueToFill->valueEnum = GPBCodedInputStreamReadEnum(&stream->state_); | |
| 425 break; | |
| 426 } | |
| 427 } | |
| 428 | |
| 429 void GPBDictionaryReadEntry(id mapDictionary, | |
| 430 GPBCodedInputStream *stream, | |
| 431 GPBExtensionRegistry *registry, | |
| 432 GPBFieldDescriptor *field, | |
| 433 GPBMessage *parentMessage) { | |
| 434 GPBDataType keyDataType = field.mapKeyDataType; | |
| 435 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 436 | |
| 437 GPBGenericValue key; | |
| 438 GPBGenericValue value; | |
| 439 // Zero them (but pick up any enum default for proto2). | |
| 440 key.valueString = value.valueString = nil; | |
| 441 if (valueDataType == GPBDataTypeEnum) { | |
| 442 value = field.defaultValue; | |
| 443 } | |
| 444 | |
| 445 GPBCodedInputStreamState *state = &stream->state_; | |
| 446 uint32_t keyTag = | |
| 447 GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType,
NO)); | |
| 448 uint32_t valueTag = | |
| 449 GPBWireFormatMakeTag(kMapValueFieldNumber, GPBWireFormatForType(valueDataT
ype, NO)); | |
| 450 | |
| 451 BOOL hitError = NO; | |
| 452 while (YES) { | |
| 453 uint32_t tag = GPBCodedInputStreamReadTag(state); | |
| 454 if (tag == keyTag) { | |
| 455 ReadValue(stream, &key, keyDataType, registry, field); | |
| 456 } else if (tag == valueTag) { | |
| 457 ReadValue(stream, &value, valueDataType, registry, field); | |
| 458 } else if (tag == 0) { | |
| 459 // zero signals EOF / limit reached | |
| 460 break; | |
| 461 } else { // Unknown | |
| 462 if (![stream skipField:tag]){ | |
| 463 hitError = YES; | |
| 464 break; | |
| 465 } | |
| 466 } | |
| 467 } | |
| 468 | |
| 469 if (!hitError) { | |
| 470 // Handle the special defaults and/or missing key/value. | |
| 471 if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) { | |
| 472 key.valueString = [@"" retain]; | |
| 473 } | |
| 474 if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) { | |
| 475 switch (valueDataType) { | |
| 476 case GPBDataTypeString: | |
| 477 value.valueString = [@"" retain]; | |
| 478 break; | |
| 479 case GPBDataTypeBytes: | |
| 480 value.valueData = [GPBEmptyNSData() retain]; | |
| 481 break; | |
| 482 case GPBDataTypeMessage: { | |
| 483 value.valueMessage = [[field.msgClass alloc] init]; | |
| 484 break; | |
| 485 } | |
| 486 default: | |
| 487 // Nothing | |
| 488 break; | |
| 489 } | |
| 490 } | |
| 491 | |
| 492 if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)
) { | |
| 493 // mapDictionary is an NSMutableDictionary | |
| 494 [mapDictionary setObject:value.valueString forKey:key.valueString]; | |
| 495 } else { | |
| 496 if (valueDataType == GPBDataTypeEnum) { | |
| 497 if (GPBHasPreservingUnknownEnumSemantics([parentMessage descriptor].file
.syntax) || | |
| 498 [field isValidEnumValue:value.valueEnum]) { | |
| 499 [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key]; | |
| 500 } else { | |
| 501 NSData *data = [mapDictionary serializedDataForUnknownValue:value.valu
eEnum | |
| 502 forKey:&key | |
| 503 keyDataType:keyDataTyp
e]; | |
| 504 [parentMessage addUnknownMapEntry:GPBFieldNumber(field) value:data]; | |
| 505 } | |
| 506 } else { | |
| 507 [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key]; | |
| 508 } | |
| 509 } | |
| 510 } | |
| 511 | |
| 512 if (GPBDataTypeIsObject(keyDataType)) { | |
| 513 [key.valueString release]; | |
| 514 } | |
| 515 if (GPBDataTypeIsObject(valueDataType)) { | |
| 516 [value.valueString release]; | |
| 517 } | |
| 518 } | |
| 519 | |
| 520 // | |
| 521 // Macros for the common basic cases. | |
| 522 // | |
| 523 | |
| 524 //%PDDM-DEFINE DICTIONARY_IMPL_FOR_POD_KEY(KEY_NAME, KEY_TYPE) | |
| 525 //%DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, , POD) | |
| 526 //%DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, Object, id) | |
| 527 | |
| 528 //%PDDM-DEFINE DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER) | |
| 529 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPE
R) | |
| 530 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER) | |
| 531 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPE
R) | |
| 532 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER) | |
| 533 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER) | |
| 534 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER) | |
| 535 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER) | |
| 536 //%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER) | |
| 537 | |
| 538 //%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME,
VALUE_TYPE, KHELPER) | |
| 539 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHEL
PER, POD) | |
| 540 | |
| 541 //%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME,
VALUE_TYPE) | |
| 542 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJ
ECT) | |
| 543 | |
| 544 //%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALU
E_TYPE, KHELPER, VHELPER) | |
| 545 //%#pragma mark - KEY_NAME -> VALUE_NAME | |
| 546 //% | |
| 547 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { | |
| 548 //% @package | |
| 549 //% NSMutableDictionary *_dictionary; | |
| 550 //%} | |
| 551 //% | |
| 552 //%+ (instancetype)dictionary { | |
| 553 //% return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease
]; | |
| 554 //%} | |
| 555 //% | |
| 556 //%+ (instancetype)dictionaryWithValue:(VALUE_TYPE)value | |
| 557 //% forKey:(KEY_TYPE##KisP$S##KisP)key { | |
| 558 //% // Cast is needed so the compiler knows what class we are invoking initWith
Values:forKeys:count: | |
| 559 //% // on to get the type correct. | |
| 560 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithValue
s:&value | |
| 561 //% KEY_NAME$S VALUE_NAME$S forKeys:
&key | |
| 562 //% KEY_NAME$S VALUE_NAME$S count:
1] autorelease]; | |
| 563 //%} | |
| 564 //% | |
| 565 //%+ (instancetype)dictionaryWithValues:(const VALUE_TYPE [])values | |
| 566 //% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys | |
| 567 //% count:(NSUInteger)count { | |
| 568 //% // Cast is needed so the compiler knows what class we are invoking initWith
Values:forKeys:count: | |
| 569 //% // on to get the type correct. | |
| 570 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithValue
s:values | |
| 571 //% KEY_NAME$S VALUE_NAME$S forKeys:
keys | |
| 572 //% KEY_NAME$S VALUE_NAME$S count:
count] autorelease]; | |
| 573 //%} | |
| 574 //% | |
| 575 //%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictiona
ry *)dictionary { | |
| 576 //% // Cast is needed so the compiler knows what class we are invoking initWith
Values:forKeys:count: | |
| 577 //% // on to get the type correct. | |
| 578 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDicti
onary:dictionary] autorelease]; | |
| 579 //%} | |
| 580 //% | |
| 581 //%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 582 //% return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 583 //%} | |
| 584 //% | |
| 585 //%- (instancetype)init { | |
| 586 //% return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 587 //%} | |
| 588 //% | |
| 589 //%- (instancetype)initWithValues:(const VALUE_TYPE [])values | |
| 590 //% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys | |
| 591 //% count:(NSUInteger)count { | |
| 592 //% self = [super init]; | |
| 593 //% if (self) { | |
| 594 //% _dictionary = [[NSMutableDictionary alloc] init]; | |
| 595 //% if (count && values && keys) { | |
| 596 //% for (NSUInteger i = 0; i < count; ++i) { | |
| 597 //% [_dictionary setObject:WRAPPED##VHELPER(values[i]) forKey:WRAPPED##KH
ELPER(keys[i])]; | |
| 598 //% } | |
| 599 //% } | |
| 600 //% } | |
| 601 //% return self; | |
| 602 //%} | |
| 603 //% | |
| 604 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)d
ictionary { | |
| 605 //% self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 606 //% if (self) { | |
| 607 //% if (dictionary) { | |
| 608 //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 609 //% } | |
| 610 //% } | |
| 611 //% return self; | |
| 612 //%} | |
| 613 //% | |
| 614 //%- (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 615 //% #pragma unused(numItems) | |
| 616 //% return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 617 //%} | |
| 618 //% | |
| 619 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, K
HELPER, VHELPER, ) | |
| 620 //% | |
| 621 //%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELP
ER) | |
| 622 //% | |
| 623 //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHE
LPER, VHELPER, ) | |
| 624 //% | |
| 625 //%@end | |
| 626 //% | |
| 627 | |
| 628 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME,
VALUE_TYPE, KHELPER) | |
| 629 //%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE
, KHELPER, POD) | |
| 630 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME
, VALUE_TYPE, KHELPER, VHELPER) | |
| 631 //%#pragma mark - KEY_NAME -> VALUE_NAME | |
| 632 //% | |
| 633 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { | |
| 634 //% @package | |
| 635 //% NSMutableDictionary *_dictionary; | |
| 636 //% GPBEnumValidationFunc _validationFunc; | |
| 637 //%} | |
| 638 //% | |
| 639 //%@synthesize validationFunc = _validationFunc; | |
| 640 //% | |
| 641 //%+ (instancetype)dictionary { | |
| 642 //% return [[[self alloc] initWithValidationFunction:NULL | |
| 643 //% rawValues:NULL | |
| 644 //% forKeys:NULL | |
| 645 //% count:0] autorelease]; | |
| 646 //%} | |
| 647 //% | |
| 648 //%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
{ | |
| 649 //% return [[[self alloc] initWithValidationFunction:func | |
| 650 //% rawValues:NULL | |
| 651 //% forKeys:NULL | |
| 652 //% count:0] autorelease]; | |
| 653 //%} | |
| 654 //% | |
| 655 //%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 656 //% rawValue:(VALUE_TYPE)rawValue | |
| 657 //% forKey:(KEY_TYPE##KisP$S##KisP)key
{ | |
| 658 //% // Cast is needed so the compiler knows what class we are invoking initWith
Values:forKeys:count: | |
| 659 //% // on to get the type correct. | |
| 660 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithValid
ationFunction:func | |
| 661 //% KEY_NAME$S VALUE_NAME$S
rawValues:&rawValue | |
| 662 //% KEY_NAME$S VALUE_NAME$S
forKeys:&key | |
| 663 //% KEY_NAME$S VALUE_NAME$S
count:1] autorelease]; | |
| 664 //%} | |
| 665 //% | |
| 666 //%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 667 //% rawValues:(const VALUE_TYPE [])rawValu
es | |
| 668 //% forKeys:(const KEY_TYPE##KisP$S##Kis
P [])keys | |
| 669 //% count:(NSUInteger)count { | |
| 670 //% // Cast is needed so the compiler knows what class we are invoking initWith
Values:forKeys:count: | |
| 671 //% // on to get the type correct. | |
| 672 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithValid
ationFunction:func | |
| 673 //% KEY_NAME$S VALUE_NAME$S
rawValues:rawValues | |
| 674 //% KEY_NAME$S VALUE_NAME$S
forKeys:keys | |
| 675 //% KEY_NAME$S VALUE_NAME$S
count:count] autorelease]; | |
| 676 //%} | |
| 677 //% | |
| 678 //%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictiona
ry *)dictionary { | |
| 679 //% // Cast is needed so the compiler knows what class we are invoking initWith
Values:forKeys:count: | |
| 680 //% // on to get the type correct. | |
| 681 //% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDicti
onary:dictionary] autorelease]; | |
| 682 //%} | |
| 683 //% | |
| 684 //%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 685 //% capacity:(NSUInteger)numItems { | |
| 686 //% return [[[self alloc] initWithValidationFunction:func capacity:numItems] au
torelease]; | |
| 687 //%} | |
| 688 //% | |
| 689 //%- (instancetype)init { | |
| 690 //% return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL co
unt:0]; | |
| 691 //%} | |
| 692 //% | |
| 693 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 694 //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL co
unt:0]; | |
| 695 //%} | |
| 696 //% | |
| 697 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 698 //% rawValues:(const VALUE_TYPE [])rawValues | |
| 699 //% forKeys:(const KEY_TYPE##KisP$S##KisP [])k
eys | |
| 700 //% count:(NSUInteger)count { | |
| 701 //% self = [super init]; | |
| 702 //% if (self) { | |
| 703 //% _dictionary = [[NSMutableDictionary alloc] init]; | |
| 704 //% _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); | |
| 705 //% if (count && rawValues && keys) { | |
| 706 //% for (NSUInteger i = 0; i < count; ++i) { | |
| 707 //% [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED#
#KHELPER(keys[i])]; | |
| 708 //% } | |
| 709 //% } | |
| 710 //% } | |
| 711 //% return self; | |
| 712 //%} | |
| 713 //% | |
| 714 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)d
ictionary { | |
| 715 //% self = [self initWithValidationFunction:dictionary.validationFunc | |
| 716 //% rawValues:NULL | |
| 717 //% forKeys:NULL | |
| 718 //% count:0]; | |
| 719 //% if (self) { | |
| 720 //% if (dictionary) { | |
| 721 //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 722 //% } | |
| 723 //% } | |
| 724 //% return self; | |
| 725 //%} | |
| 726 //% | |
| 727 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 728 //% capacity:(NSUInteger)numItems { | |
| 729 //% #pragma unused(numItems) | |
| 730 //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL co
unt:0]; | |
| 731 //%} | |
| 732 //% | |
| 733 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, K
HELPER, VHELPER, Raw) | |
| 734 //% | |
| 735 //%- (BOOL)valueForKey:(KEY_TYPE##KisP$S##KisP)key value:(VALUE_TYPE *)value { | |
| 736 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; | |
| 737 //% if (wrapped && value) { | |
| 738 //% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped); | |
| 739 //% if (!_validationFunc(result)) { | |
| 740 //% result = kGPBUnrecognizedEnumeratorValue; | |
| 741 //% } | |
| 742 //% *value = result; | |
| 743 //% } | |
| 744 //% return (wrapped != NULL); | |
| 745 //%} | |
| 746 //% | |
| 747 //%- (BOOL)valueForKey:(KEY_TYPE##KisP$S##KisP)key rawValue:(VALUE_TYPE *)rawVal
ue { | |
| 748 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; | |
| 749 //% if (wrapped && rawValue) { | |
| 750 //% *rawValue = UNWRAP##VALUE_NAME(wrapped); | |
| 751 //% } | |
| 752 //% return (wrapped != NULL); | |
| 753 //%} | |
| 754 //% | |
| 755 //%- (void)enumerateKeysAndValuesUsingBlock: | |
| 756 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block { | |
| 757 //% GPBEnumValidationFunc func = _validationFunc; | |
| 758 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | |
| 759 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##aValue, | |
| 760 //% BOOL *stop) { | |
| 761 //% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue); | |
| 762 //% if (!func(unwrapped)) { | |
| 763 //% unwrapped = kGPBUnrecognizedEnumeratorValue; | |
| 764 //% } | |
| 765 //% block(UNWRAP##KEY_NAME(aKey), unwrapped, stop); | |
| 766 //% }]; | |
| 767 //%} | |
| 768 //% | |
| 769 //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHE
LPER, VHELPER, Raw) | |
| 770 //% | |
| 771 //%- (void)setValue:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key { | |
| 772 //% if (!_validationFunc(value)) { | |
| 773 //% [NSException raise:NSInvalidArgumentException | |
| 774 //% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to se
t an unknown enum value (%d)", | |
| 775 //% value]; | |
| 776 //% } | |
| 777 //% | |
| 778 //% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)
]; | |
| 779 //% if (_autocreator) { | |
| 780 //% GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 781 //% } | |
| 782 //%} | |
| 783 //% | |
| 784 //%@end | |
| 785 //% | |
| 786 | |
| 787 //%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, V
ALUE_TYPE, KHELPER, VHELPER, ACCESSOR_NAME) | |
| 788 //%- (void)dealloc { | |
| 789 //% NSAssert(!_autocreator, | |
| 790 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, | |
| 791 //% [self class], _autocreator); | |
| 792 //% [_dictionary release]; | |
| 793 //% [super dealloc]; | |
| 794 //%} | |
| 795 //% | |
| 796 //%- (instancetype)copyWithZone:(NSZone *)zone { | |
| 797 //% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWith
Dictionary:self]; | |
| 798 //%} | |
| 799 //% | |
| 800 //%- (BOOL)isEqual:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)other { | |
| 801 //% if (self == other) { | |
| 802 //% return YES; | |
| 803 //% } | |
| 804 //% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) { | |
| 805 //% return NO; | |
| 806 //% } | |
| 807 //% return [_dictionary isEqual:other->_dictionary]; | |
| 808 //%} | |
| 809 //% | |
| 810 //%- (NSUInteger)hash { | |
| 811 //% return _dictionary.count; | |
| 812 //%} | |
| 813 //% | |
| 814 //%- (NSString *)description { | |
| 815 //% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _d
ictionary]; | |
| 816 //%} | |
| 817 //% | |
| 818 //%- (NSUInteger)count { | |
| 819 //% return _dictionary.count; | |
| 820 //%} | |
| 821 //% | |
| 822 //%- (void)enumerateKeysAnd##ACCESSOR_NAME##ValuesUsingBlock: | |
| 823 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block { | |
| 824 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | |
| 825 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##aValue, | |
| 826 //% BOOL *stop) { | |
| 827 //% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(aValue), stop); | |
| 828 //% }]; | |
| 829 //%} | |
| 830 //% | |
| 831 //%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeA
sField:(GPBFieldDescriptor *)field { | |
| 832 //% NSUInteger count = _dictionary.count; | |
| 833 //% if (count == 0) { | |
| 834 //% return 0; | |
| 835 //% } | |
| 836 //% | |
| 837 //% GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 838 //% GPBDataType keyDataType = field.mapKeyDataType; | |
| 839 //% __block size_t result = 0; | |
| 840 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | |
| 841 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##aValue, | |
| 842 //% BOOL *stop) { | |
| 843 //% #pragma unused(stop) | |
| 844 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey),
kMapKeyFieldNumber, keyDataType); | |
| 845 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(aValue),
kMapValueFieldNumber, valueDataType); | |
| 846 //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 847 //% }]; | |
| 848 //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBData
TypeMessage); | |
| 849 //% result += tagSize * count; | |
| 850 //% return result; | |
| 851 //%} | |
| 852 //% | |
| 853 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 854 //% asField:(GPBFieldDescriptor *)field { | |
| 855 //% GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 856 //% GPBDataType keyDataType = field.mapKeyDataType; | |
| 857 //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLen
gthDelimited); | |
| 858 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYP
E)##aKey, | |
| 859 //% ENUM_TYPE##VHELPER(VALUE_T
YPE)##aValue, | |
| 860 //% BOOL *stop) { | |
| 861 //% #pragma unused(stop) | |
| 862 //% // Write the tag. | |
| 863 //% [outputStream writeInt32NoTag:tag]; | |
| 864 //% // Write the size of the message. | |
| 865 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey),
kMapKeyFieldNumber, keyDataType); | |
| 866 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(aValue),
kMapValueFieldNumber, valueDataType); | |
| 867 //% [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 868 //% // Write the fields. | |
| 869 //% WriteDict##KEY_NAME##Field(outputStream, UNWRAP##KEY_NAME(aKey), kMapKeyF
ieldNumber, keyDataType); | |
| 870 //% WriteDict##VALUE_NAME##Field(outputStream, UNWRAP##VALUE_NAME(aValue), kM
apValueFieldNumber, valueDataType); | |
| 871 //% }]; | |
| 872 //%} | |
| 873 //% | |
| 874 //%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericVal
ue:(GPBGenericValue *)value | |
| 875 //% forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 876 //% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_N
AME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)]; | |
| 877 //%} | |
| 878 //% | |
| 879 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 880 //% [self enumerateKeysAnd##ACCESSOR_NAME##ValuesUsingBlock:^(KEY_TYPE KisP##ke
y, VALUE_TYPE value, BOOL *stop) { | |
| 881 //% #pragma unused(stop) | |
| 882 //% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(value
)); | |
| 883 //% }]; | |
| 884 //%} | |
| 885 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VAL
UE_TYPE, KHELPER, VHELPER, ACCESSOR_NAME) | |
| 886 //%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME#
#Dictionary *)otherDictionary { | |
| 887 //% if (otherDictionary) { | |
| 888 //% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 889 //% if (_autocreator) { | |
| 890 //% GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 891 //% } | |
| 892 //% } | |
| 893 //%} | |
| 894 //% | |
| 895 //%- (void)set##ACCESSOR_NAME##Value:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S#
#KisP)key { | |
| 896 //% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)
]; | |
| 897 //% if (_autocreator) { | |
| 898 //% GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 899 //% } | |
| 900 //%} | |
| 901 //% | |
| 902 //%- (void)removeValueForKey:(KEY_TYPE##KisP$S##KisP)aKey { | |
| 903 //% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)]; | |
| 904 //%} | |
| 905 //% | |
| 906 //%- (void)removeAll { | |
| 907 //% [_dictionary removeAllObjects]; | |
| 908 //%} | |
| 909 | |
| 910 // | |
| 911 // Custom Generation for Bool keys | |
| 912 // | |
| 913 | |
| 914 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE) | |
| 915 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD) | |
| 916 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE) | |
| 917 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT) | |
| 918 | |
| 919 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER) | |
| 920 //%#pragma mark - Bool -> VALUE_NAME | |
| 921 //% | |
| 922 //%@implementation GPBBool##VALUE_NAME##Dictionary { | |
| 923 //% @package | |
| 924 //% VALUE_TYPE _values[2]; | |
| 925 //%BOOL_DICT_HAS_STORAGE_##HELPER()} | |
| 926 //% | |
| 927 //%+ (instancetype)dictionary { | |
| 928 //% return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease
]; | |
| 929 //%} | |
| 930 //% | |
| 931 //%+ (instancetype)dictionaryWithValue:(VALUE_TYPE)value | |
| 932 //% forKey:(BOOL)key { | |
| 933 //% // Cast is needed so the compiler knows what class we are invoking initWith
Values:forKeys:count: | |
| 934 //% // on to get the type correct. | |
| 935 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWithValues:&val
ue | |
| 936 //% VALUE_NAME$S forKeys:&key | |
| 937 //% VALUE_NAME$S count:1] aut
orelease]; | |
| 938 //%} | |
| 939 //% | |
| 940 //%+ (instancetype)dictionaryWithValues:(const VALUE_TYPE [])values | |
| 941 //% forKeys:(const BOOL [])keys | |
| 942 //% count:(NSUInteger)count { | |
| 943 //% // Cast is needed so the compiler knows what class we are invoking initWith
Values:forKeys:count: | |
| 944 //% // on to get the type correct. | |
| 945 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWithValues:valu
es | |
| 946 //% VALUE_NAME$S forKeys:keys | |
| 947 //% VALUE_NAME$S count:count]
autorelease]; | |
| 948 //%} | |
| 949 //% | |
| 950 //%+ (instancetype)dictionaryWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)d
ictionary { | |
| 951 //% // Cast is needed so the compiler knows what class we are invoking initWith
Values:forKeys:count: | |
| 952 //% // on to get the type correct. | |
| 953 //% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:
dictionary] autorelease]; | |
| 954 //%} | |
| 955 //% | |
| 956 //%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 957 //% return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 958 //%} | |
| 959 //% | |
| 960 //%- (instancetype)init { | |
| 961 //% return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 962 //%} | |
| 963 //% | |
| 964 //%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE) | |
| 965 //% | |
| 966 //%- (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 967 //% #pragma unused(numItems) | |
| 968 //% return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 969 //%} | |
| 970 //% | |
| 971 //%BOOL_DICT_DEALLOC##HELPER() | |
| 972 //% | |
| 973 //%- (instancetype)copyWithZone:(NSZone *)zone { | |
| 974 //% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictio
nary:self]; | |
| 975 //%} | |
| 976 //% | |
| 977 //%- (BOOL)isEqual:(GPBBool##VALUE_NAME##Dictionary *)other { | |
| 978 //% if (self == other) { | |
| 979 //% return YES; | |
| 980 //% } | |
| 981 //% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) { | |
| 982 //% return NO; | |
| 983 //% } | |
| 984 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, other->)) |
| | |
| 985 //% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, other->)))
{ | |
| 986 //% return NO; | |
| 987 //% } | |
| 988 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], other->_valu
es[0]))) || | |
| 989 //% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], other->_valu
es[1])))) { | |
| 990 //% return NO; | |
| 991 //% } | |
| 992 //% return YES; | |
| 993 //%} | |
| 994 //% | |
| 995 //%- (NSUInteger)hash { | |
| 996 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1,
) ? 1 : 0); | |
| 997 //%} | |
| 998 //% | |
| 999 //%- (NSString *)description { | |
| 1000 //% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [
self class], self]; | |
| 1001 //% if (BOOL_DICT_W_HAS##HELPER(0, )) { | |
| 1002 //% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]]; | |
| 1003 //% } | |
| 1004 //% if (BOOL_DICT_W_HAS##HELPER(1, )) { | |
| 1005 //% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]]
; | |
| 1006 //% } | |
| 1007 //% [result appendString:@" }"]; | |
| 1008 //% return result; | |
| 1009 //%} | |
| 1010 //% | |
| 1011 //%- (NSUInteger)count { | |
| 1012 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1,
) ? 1 : 0); | |
| 1013 //%} | |
| 1014 //% | |
| 1015 //%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_TYPE) | |
| 1016 //% | |
| 1017 //%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP) | |
| 1018 //% | |
| 1019 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 1020 //% if (BOOL_DICT_HAS##HELPER(0, )) { | |
| 1021 //% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0])); | |
| 1022 //% } | |
| 1023 //% if (BOOL_DICT_W_HAS##HELPER(1, )) { | |
| 1024 //% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1])); | |
| 1025 //% } | |
| 1026 //%} | |
| 1027 //% | |
| 1028 //%- (void)enumerateKeysAndValuesUsingBlock: | |
| 1029 //% (void (^)(BOOL key, VALUE_TYPE value, BOOL *stop))block { | |
| 1030 //% BOOL stop = NO; | |
| 1031 //% if (BOOL_DICT_HAS##HELPER(0, )) { | |
| 1032 //% block(NO, _values[0], &stop); | |
| 1033 //% } | |
| 1034 //% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) { | |
| 1035 //% block(YES, _values[1], &stop); | |
| 1036 //% } | |
| 1037 //%} | |
| 1038 //% | |
| 1039 //%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeA
sField:(GPBFieldDescriptor *)field { | |
| 1040 //% GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 1041 //% NSUInteger count = 0; | |
| 1042 //% size_t result = 0; | |
| 1043 //% for (int i = 0; i < 2; ++i) { | |
| 1044 //% if (BOOL_DICT_HAS##HELPER(i, )) { | |
| 1045 //% ++count; | |
| 1046 //% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber,
GPBDataTypeBool); | |
| 1047 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFiel
dNumber, valueDataType); | |
| 1048 //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 1049 //% } | |
| 1050 //% } | |
| 1051 //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBData
TypeMessage); | |
| 1052 //% result += tagSize * count; | |
| 1053 //% return result; | |
| 1054 //%} | |
| 1055 //% | |
| 1056 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 1057 //% asField:(GPBFieldDescriptor *)field { | |
| 1058 //% GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 1059 //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLen
gthDelimited); | |
| 1060 //% for (int i = 0; i < 2; ++i) { | |
| 1061 //% if (BOOL_DICT_HAS##HELPER(i, )) { | |
| 1062 //% // Write the tag. | |
| 1063 //% [outputStream writeInt32NoTag:tag]; | |
| 1064 //% // Write the size of the message. | |
| 1065 //% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber,
GPBDataTypeBool); | |
| 1066 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFiel
dNumber, valueDataType); | |
| 1067 //% [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 1068 //% // Write the fields. | |
| 1069 //% WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataT
ypeBool); | |
| 1070 //% WriteDict##VALUE_NAME##Field(outputStream, _values[i], kMapValueFieldNu
mber, valueDataType); | |
| 1071 //% } | |
| 1072 //% } | |
| 1073 //%} | |
| 1074 //% | |
| 1075 //%BOOL_DICT_MUTATIONS_##HELPER(VALUE_NAME, VALUE_TYPE) | |
| 1076 //% | |
| 1077 //%@end | |
| 1078 //% | |
| 1079 | |
| 1080 | |
| 1081 // | |
| 1082 // Helpers for PODs | |
| 1083 // | |
| 1084 | |
| 1085 //%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER) | |
| 1086 //%- (BOOL)valueForKey:(KEY_TYPE)key value:(VALUE_TYPE *)value { | |
| 1087 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; | |
| 1088 //% if (wrapped && value) { | |
| 1089 //% *value = UNWRAP##VALUE_NAME(wrapped); | |
| 1090 //% } | |
| 1091 //% return (wrapped != NULL); | |
| 1092 //%} | |
| 1093 //%PDDM-DEFINE WRAPPEDPOD(VALUE) | |
| 1094 //%@(VALUE) | |
| 1095 //%PDDM-DEFINE UNWRAPUInt32(VALUE) | |
| 1096 //%[VALUE unsignedIntValue] | |
| 1097 //%PDDM-DEFINE UNWRAPInt32(VALUE) | |
| 1098 //%[VALUE intValue] | |
| 1099 //%PDDM-DEFINE UNWRAPUInt64(VALUE) | |
| 1100 //%[VALUE unsignedLongLongValue] | |
| 1101 //%PDDM-DEFINE UNWRAPInt64(VALUE) | |
| 1102 //%[VALUE longLongValue] | |
| 1103 //%PDDM-DEFINE UNWRAPBool(VALUE) | |
| 1104 //%[VALUE boolValue] | |
| 1105 //%PDDM-DEFINE UNWRAPFloat(VALUE) | |
| 1106 //%[VALUE floatValue] | |
| 1107 //%PDDM-DEFINE UNWRAPDouble(VALUE) | |
| 1108 //%[VALUE doubleValue] | |
| 1109 //%PDDM-DEFINE UNWRAPEnum(VALUE) | |
| 1110 //%[VALUE intValue] | |
| 1111 //%PDDM-DEFINE TEXT_FORMAT_OBJUInt32(VALUE) | |
| 1112 //%[NSString stringWithFormat:@"%u", VALUE] | |
| 1113 //%PDDM-DEFINE TEXT_FORMAT_OBJInt32(VALUE) | |
| 1114 //%[NSString stringWithFormat:@"%d", VALUE] | |
| 1115 //%PDDM-DEFINE TEXT_FORMAT_OBJUInt64(VALUE) | |
| 1116 //%[NSString stringWithFormat:@"%llu", VALUE] | |
| 1117 //%PDDM-DEFINE TEXT_FORMAT_OBJInt64(VALUE) | |
| 1118 //%[NSString stringWithFormat:@"%lld", VALUE] | |
| 1119 //%PDDM-DEFINE TEXT_FORMAT_OBJBool(VALUE) | |
| 1120 //%(VALUE ? @"true" : @"false") | |
| 1121 //%PDDM-DEFINE TEXT_FORMAT_OBJFloat(VALUE) | |
| 1122 //%[NSString stringWithFormat:@"%.*g", FLT_DIG, VALUE] | |
| 1123 //%PDDM-DEFINE TEXT_FORMAT_OBJDouble(VALUE) | |
| 1124 //%[NSString stringWithFormat:@"%.*lg", DBL_DIG, VALUE] | |
| 1125 //%PDDM-DEFINE TEXT_FORMAT_OBJEnum(VALUE) | |
| 1126 //%@(VALUE) | |
| 1127 //%PDDM-DEFINE ENUM_TYPEPOD(TYPE) | |
| 1128 //%NSNumber * | |
| 1129 //%PDDM-DEFINE NEQ_POD(VAL1, VAL2) | |
| 1130 //%VAL1 != VAL2 | |
| 1131 //%PDDM-DEFINE EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME) | |
| 1132 // Empty | |
| 1133 //%PDDM-DEFINE BOOL_EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME) | |
| 1134 // Empty | |
| 1135 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD(KEY_NAME, VALUE_NAME) | |
| 1136 //%SERIAL_DATA_FOR_ENTRY_POD_##VALUE_NAME(KEY_NAME) | |
| 1137 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt32(KEY_NAME) | |
| 1138 // Empty | |
| 1139 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int32(KEY_NAME) | |
| 1140 // Empty | |
| 1141 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt64(KEY_NAME) | |
| 1142 // Empty | |
| 1143 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int64(KEY_NAME) | |
| 1144 // Empty | |
| 1145 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Bool(KEY_NAME) | |
| 1146 // Empty | |
| 1147 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Float(KEY_NAME) | |
| 1148 // Empty | |
| 1149 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Double(KEY_NAME) | |
| 1150 // Empty | |
| 1151 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Enum(KEY_NAME) | |
| 1152 //%- (NSData *)serializedDataForUnknownValue:(int32_t)value | |
| 1153 //% forKey:(GPBGenericValue *)key | |
| 1154 //% keyDataType:(GPBDataType)keyDataType { | |
| 1155 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(key->value##KEY_NAME, kMa
pKeyFieldNumber, keyDataType); | |
| 1156 //% msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTyp
eEnum); | |
| 1157 //% NSMutableData *data = [NSMutableData dataWithLength:msgSize]; | |
| 1158 //% GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWith
Data:data]; | |
| 1159 //% WriteDict##KEY_NAME##Field(outputStream, key->value##KEY_NAME, kMapKeyField
Number, keyDataType); | |
| 1160 //% WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEn
um); | |
| 1161 //% [outputStream release]; | |
| 1162 //% return data; | |
| 1163 //%} | |
| 1164 //% | |
| 1165 //%PDDM-DEFINE GPBVALUE_POD(VALUE_NAME) | |
| 1166 //%value##VALUE_NAME | |
| 1167 | |
| 1168 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD() | |
| 1169 //% BOOL _valueSet[2]; | |
| 1170 //% | |
| 1171 //%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE) | |
| 1172 //%- (instancetype)initWithValues:(const VALUE_TYPE [])values | |
| 1173 //% forKeys:(const BOOL [])keys | |
| 1174 //% count:(NSUInteger)count { | |
| 1175 //% self = [super init]; | |
| 1176 //% if (self) { | |
| 1177 //% for (NSUInteger i = 0; i < count; ++i) { | |
| 1178 //% int idx = keys[i] ? 1 : 0; | |
| 1179 //% _values[idx] = values[i]; | |
| 1180 //% _valueSet[idx] = YES; | |
| 1181 //% } | |
| 1182 //% } | |
| 1183 //% return self; | |
| 1184 //%} | |
| 1185 //% | |
| 1186 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)diction
ary { | |
| 1187 //% self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 1188 //% if (self) { | |
| 1189 //% if (dictionary) { | |
| 1190 //% for (int i = 0; i < 2; ++i) { | |
| 1191 //% if (dictionary->_valueSet[i]) { | |
| 1192 //% _values[i] = dictionary->_values[i]; | |
| 1193 //% _valueSet[i] = YES; | |
| 1194 //% } | |
| 1195 //% } | |
| 1196 //% } | |
| 1197 //% } | |
| 1198 //% return self; | |
| 1199 //%} | |
| 1200 //%PDDM-DEFINE BOOL_DICT_DEALLOCPOD() | |
| 1201 //%#if !defined(NS_BLOCK_ASSERTIONS) | |
| 1202 //%- (void)dealloc { | |
| 1203 //% NSAssert(!_autocreator, | |
| 1204 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, | |
| 1205 //% [self class], _autocreator); | |
| 1206 //% [super dealloc]; | |
| 1207 //%} | |
| 1208 //%#endif // !defined(NS_BLOCK_ASSERTIONS) | |
| 1209 //%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF) | |
| 1210 //%BOOL_DICT_HASPOD(IDX, REF) | |
| 1211 //%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF) | |
| 1212 //%REF##_valueSet[IDX] | |
| 1213 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_TYPE) | |
| 1214 //%- (BOOL)valueForKey:(BOOL)key value:(VALUE_TYPE *)value { | |
| 1215 //% int idx = (key ? 1 : 0); | |
| 1216 //% if (_valueSet[idx]) { | |
| 1217 //% if (value) { | |
| 1218 //% *value = _values[idx]; | |
| 1219 //% } | |
| 1220 //% return YES; | |
| 1221 //% } | |
| 1222 //% return NO; | |
| 1223 //%} | |
| 1224 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP) | |
| 1225 //%- (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 1226 //% forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 1227 //% int idx = (key->valueBool ? 1 : 0); | |
| 1228 //% _values[idx] = value->value##VALUE_NAME; | |
| 1229 //% _valueSet[idx] = YES; | |
| 1230 //%} | |
| 1231 //%PDDM-DEFINE BOOL_DICT_MUTATIONS_POD(VALUE_NAME, VALUE_TYPE) | |
| 1232 //%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDict
ionary { | |
| 1233 //% if (otherDictionary) { | |
| 1234 //% for (int i = 0; i < 2; ++i) { | |
| 1235 //% if (otherDictionary->_valueSet[i]) { | |
| 1236 //% _valueSet[i] = YES; | |
| 1237 //% _values[i] = otherDictionary->_values[i]; | |
| 1238 //% } | |
| 1239 //% } | |
| 1240 //% if (_autocreator) { | |
| 1241 //% GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 1242 //% } | |
| 1243 //% } | |
| 1244 //%} | |
| 1245 //% | |
| 1246 //%- (void)setValue:(VALUE_TYPE)value forKey:(BOOL)key { | |
| 1247 //% int idx = (key ? 1 : 0); | |
| 1248 //% _values[idx] = value; | |
| 1249 //% _valueSet[idx] = YES; | |
| 1250 //% if (_autocreator) { | |
| 1251 //% GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 1252 //% } | |
| 1253 //%} | |
| 1254 //% | |
| 1255 //%- (void)removeValueForKey:(BOOL)aKey { | |
| 1256 //% _valueSet[aKey ? 1 : 0] = NO; | |
| 1257 //%} | |
| 1258 //% | |
| 1259 //%- (void)removeAll { | |
| 1260 //% _valueSet[0] = NO; | |
| 1261 //% _valueSet[1] = NO; | |
| 1262 //%} | |
| 1263 //%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME) | |
| 1264 //%STR_FORMAT_##VALUE_NAME() | |
| 1265 //%PDDM-DEFINE STR_FORMAT_UInt32() | |
| 1266 //%%u | |
| 1267 //%PDDM-DEFINE STR_FORMAT_Int32() | |
| 1268 //%%d | |
| 1269 //%PDDM-DEFINE STR_FORMAT_UInt64() | |
| 1270 //%%llu | |
| 1271 //%PDDM-DEFINE STR_FORMAT_Int64() | |
| 1272 //%%lld | |
| 1273 //%PDDM-DEFINE STR_FORMAT_Bool() | |
| 1274 //%%d | |
| 1275 //%PDDM-DEFINE STR_FORMAT_Float() | |
| 1276 //%%f | |
| 1277 //%PDDM-DEFINE STR_FORMAT_Double() | |
| 1278 //%%lf | |
| 1279 | |
| 1280 // | |
| 1281 // Helpers for Objects | |
| 1282 // | |
| 1283 | |
| 1284 //%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER) | |
| 1285 //%- (VALUE_TYPE)valueForKey:(KEY_TYPE)key { | |
| 1286 //% VALUE_TYPE result = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; | |
| 1287 //% return result; | |
| 1288 //%} | |
| 1289 //%PDDM-DEFINE WRAPPEDOBJECT(VALUE) | |
| 1290 //%VALUE | |
| 1291 //%PDDM-DEFINE UNWRAPString(VALUE) | |
| 1292 //%VALUE | |
| 1293 //%PDDM-DEFINE UNWRAPObject(VALUE) | |
| 1294 //%VALUE | |
| 1295 //%PDDM-DEFINE TEXT_FORMAT_OBJString(VALUE) | |
| 1296 //%VALUE | |
| 1297 //%PDDM-DEFINE TEXT_FORMAT_OBJObject(VALUE) | |
| 1298 //%VALUE | |
| 1299 //%PDDM-DEFINE ENUM_TYPEOBJECT(TYPE) | |
| 1300 //%ENUM_TYPEOBJECT_##TYPE() | |
| 1301 //%PDDM-DEFINE ENUM_TYPEOBJECT_NSString() | |
| 1302 //%NSString * | |
| 1303 //%PDDM-DEFINE ENUM_TYPEOBJECT_id() | |
| 1304 //%id ## | |
| 1305 //%PDDM-DEFINE NEQ_OBJECT(VAL1, VAL2) | |
| 1306 //%![VAL1 isEqual:VAL2] | |
| 1307 //%PDDM-DEFINE EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME) | |
| 1308 //%- (BOOL)isInitialized { | |
| 1309 //% for (GPBMessage *msg in [_dictionary objectEnumerator]) { | |
| 1310 //% if (!msg.initialized) { | |
| 1311 //% return NO; | |
| 1312 //% } | |
| 1313 //% } | |
| 1314 //% return YES; | |
| 1315 //%} | |
| 1316 //% | |
| 1317 //%- (instancetype)deepCopyWithZone:(NSZone *)zone { | |
| 1318 //% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict = | |
| 1319 //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init]; | |
| 1320 //% [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey, | |
| 1321 //% GPBMessage *msg, | |
| 1322 //% BOOL *stop) { | |
| 1323 //% #pragma unused(stop) | |
| 1324 //% GPBMessage *copiedMsg = [msg copyWithZone:zone]; | |
| 1325 //% [newDict->_dictionary setObject:copiedMsg forKey:aKey]; | |
| 1326 //% [copiedMsg release]; | |
| 1327 //% }]; | |
| 1328 //% return newDict; | |
| 1329 //%} | |
| 1330 //% | |
| 1331 //% | |
| 1332 //%PDDM-DEFINE BOOL_EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME) | |
| 1333 //%- (BOOL)isInitialized { | |
| 1334 //% if (_values[0] && ![_values[0] isInitialized]) { | |
| 1335 //% return NO; | |
| 1336 //% } | |
| 1337 //% if (_values[1] && ![_values[1] isInitialized]) { | |
| 1338 //% return NO; | |
| 1339 //% } | |
| 1340 //% return YES; | |
| 1341 //%} | |
| 1342 //% | |
| 1343 //%- (instancetype)deepCopyWithZone:(NSZone *)zone { | |
| 1344 //% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict = | |
| 1345 //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init]; | |
| 1346 //% for (int i = 0; i < 2; ++i) { | |
| 1347 //% if (_values[i] != nil) { | |
| 1348 //% newDict->_values[i] = [_values[i] copyWithZone:zone]; | |
| 1349 //% } | |
| 1350 //% } | |
| 1351 //% return newDict; | |
| 1352 //%} | |
| 1353 //% | |
| 1354 //% | |
| 1355 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_OBJECT(KEY_NAME, VALUE_NAME) | |
| 1356 // Empty | |
| 1357 //%PDDM-DEFINE GPBVALUE_OBJECT(VALUE_NAME) | |
| 1358 //%valueString | |
| 1359 | |
| 1360 | |
| 1361 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_OBJECT() | |
| 1362 // Empty | |
| 1363 //%PDDM-DEFINE BOOL_DICT_INITS_OBJECT(VALUE_NAME, VALUE_TYPE) | |
| 1364 //%- (instancetype)initWithValues:(const VALUE_TYPE [])values | |
| 1365 //% forKeys:(const BOOL [])keys | |
| 1366 //% count:(NSUInteger)count { | |
| 1367 //% self = [super init]; | |
| 1368 //% if (self) { | |
| 1369 //% for (NSUInteger i = 0; i < count; ++i) { | |
| 1370 //% int idx = keys[i] ? 1 : 0; | |
| 1371 //% [_values[idx] release]; | |
| 1372 //% _values[idx] = (VALUE_TYPE)[values[i] retain]; | |
| 1373 //% } | |
| 1374 //% } | |
| 1375 //% return self; | |
| 1376 //%} | |
| 1377 //% | |
| 1378 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)diction
ary { | |
| 1379 //% self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 1380 //% if (self) { | |
| 1381 //% if (dictionary) { | |
| 1382 //% _values[0] = [dictionary->_values[0] retain]; | |
| 1383 //% _values[1] = [dictionary->_values[1] retain]; | |
| 1384 //% } | |
| 1385 //% } | |
| 1386 //% return self; | |
| 1387 //%} | |
| 1388 //%PDDM-DEFINE BOOL_DICT_DEALLOCOBJECT() | |
| 1389 //%- (void)dealloc { | |
| 1390 //% NSAssert(!_autocreator, | |
| 1391 //% @"%@: Autocreator must be cleared before release, autocreator: %@"
, | |
| 1392 //% [self class], _autocreator); | |
| 1393 //% [_values[0] release]; | |
| 1394 //% [_values[1] release]; | |
| 1395 //% [super dealloc]; | |
| 1396 //%} | |
| 1397 //%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF) | |
| 1398 //%(BOOL_DICT_HASOBJECT(IDX, REF)) | |
| 1399 //%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF) | |
| 1400 //%REF##_values[IDX] != nil | |
| 1401 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_TYPE) | |
| 1402 //%- (VALUE_TYPE)valueForKey:(BOOL)key { | |
| 1403 //% return _values[key ? 1 : 0]; | |
| 1404 //%} | |
| 1405 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP) | |
| 1406 //%- (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 1407 //% forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 1408 //% int idx = (key->valueBool ? 1 : 0); | |
| 1409 //% [_values[idx] release]; | |
| 1410 //% _values[idx] = [value->valueString retain]; | |
| 1411 //%} | |
| 1412 | |
| 1413 //%PDDM-DEFINE BOOL_DICT_MUTATIONS_OBJECT(VALUE_NAME, VALUE_TYPE) | |
| 1414 //%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDict
ionary { | |
| 1415 //% if (otherDictionary) { | |
| 1416 //% for (int i = 0; i < 2; ++i) { | |
| 1417 //% if (otherDictionary->_values[i] != nil) { | |
| 1418 //% [_values[i] release]; | |
| 1419 //% _values[i] = [otherDictionary->_values[i] retain]; | |
| 1420 //% } | |
| 1421 //% } | |
| 1422 //% if (_autocreator) { | |
| 1423 //% GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 1424 //% } | |
| 1425 //% } | |
| 1426 //%} | |
| 1427 //% | |
| 1428 //%- (void)setValue:(VALUE_TYPE)value forKey:(BOOL)key { | |
| 1429 //% int idx = (key ? 1 : 0); | |
| 1430 //% [_values[idx] release]; | |
| 1431 //% _values[idx] = [value retain]; | |
| 1432 //% if (_autocreator) { | |
| 1433 //% GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 1434 //% } | |
| 1435 //%} | |
| 1436 //% | |
| 1437 //%- (void)removeValueForKey:(BOOL)aKey { | |
| 1438 //% int idx = (aKey ? 1 : 0); | |
| 1439 //% [_values[idx] release]; | |
| 1440 //% _values[idx] = nil; | |
| 1441 //%} | |
| 1442 //% | |
| 1443 //%- (void)removeAll { | |
| 1444 //% for (int i = 0; i < 2; ++i) { | |
| 1445 //% [_values[i] release]; | |
| 1446 //% _values[i] = nil; | |
| 1447 //% } | |
| 1448 //%} | |
| 1449 //%PDDM-DEFINE STR_FORMAT_OBJECT(VALUE_NAME) | |
| 1450 //%%@ | |
| 1451 | |
| 1452 | |
| 1453 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt32, uint32_t) | |
| 1454 // This block of code is generated, do not edit it directly. | |
| 1455 | |
| 1456 #pragma mark - UInt32 -> UInt32 | |
| 1457 | |
| 1458 @implementation GPBUInt32UInt32Dictionary { | |
| 1459 @package | |
| 1460 NSMutableDictionary *_dictionary; | |
| 1461 } | |
| 1462 | |
| 1463 + (instancetype)dictionary { | |
| 1464 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 1465 } | |
| 1466 | |
| 1467 + (instancetype)dictionaryWithValue:(uint32_t)value | |
| 1468 forKey:(uint32_t)key { | |
| 1469 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 1470 // on to get the type correct. | |
| 1471 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithValues:&value | |
| 1472 forKeys:&key | |
| 1473 count:1] autoreleas
e]; | |
| 1474 } | |
| 1475 | |
| 1476 + (instancetype)dictionaryWithValues:(const uint32_t [])values | |
| 1477 forKeys:(const uint32_t [])keys | |
| 1478 count:(NSUInteger)count { | |
| 1479 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 1480 // on to get the type correct. | |
| 1481 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithValues:values | |
| 1482 forKeys:keys | |
| 1483 count:count] autore
lease]; | |
| 1484 } | |
| 1485 | |
| 1486 + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary
{ | |
| 1487 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 1488 // on to get the type correct. | |
| 1489 return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | |
| 1490 } | |
| 1491 | |
| 1492 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 1493 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 1494 } | |
| 1495 | |
| 1496 - (instancetype)init { | |
| 1497 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 1498 } | |
| 1499 | |
| 1500 - (instancetype)initWithValues:(const uint32_t [])values | |
| 1501 forKeys:(const uint32_t [])keys | |
| 1502 count:(NSUInteger)count { | |
| 1503 self = [super init]; | |
| 1504 if (self) { | |
| 1505 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 1506 if (count && values && keys) { | |
| 1507 for (NSUInteger i = 0; i < count; ++i) { | |
| 1508 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 1509 } | |
| 1510 } | |
| 1511 } | |
| 1512 return self; | |
| 1513 } | |
| 1514 | |
| 1515 - (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary { | |
| 1516 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 1517 if (self) { | |
| 1518 if (dictionary) { | |
| 1519 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 1520 } | |
| 1521 } | |
| 1522 return self; | |
| 1523 } | |
| 1524 | |
| 1525 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 1526 #pragma unused(numItems) | |
| 1527 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 1528 } | |
| 1529 | |
| 1530 - (void)dealloc { | |
| 1531 NSAssert(!_autocreator, | |
| 1532 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 1533 [self class], _autocreator); | |
| 1534 [_dictionary release]; | |
| 1535 [super dealloc]; | |
| 1536 } | |
| 1537 | |
| 1538 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 1539 return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; | |
| 1540 } | |
| 1541 | |
| 1542 - (BOOL)isEqual:(GPBUInt32UInt32Dictionary *)other { | |
| 1543 if (self == other) { | |
| 1544 return YES; | |
| 1545 } | |
| 1546 if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) { | |
| 1547 return NO; | |
| 1548 } | |
| 1549 return [_dictionary isEqual:other->_dictionary]; | |
| 1550 } | |
| 1551 | |
| 1552 - (NSUInteger)hash { | |
| 1553 return _dictionary.count; | |
| 1554 } | |
| 1555 | |
| 1556 - (NSString *)description { | |
| 1557 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 1558 } | |
| 1559 | |
| 1560 - (NSUInteger)count { | |
| 1561 return _dictionary.count; | |
| 1562 } | |
| 1563 | |
| 1564 - (void)enumerateKeysAndValuesUsingBlock: | |
| 1565 (void (^)(uint32_t key, uint32_t value, BOOL *stop))block { | |
| 1566 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 1567 NSNumber *aValue, | |
| 1568 BOOL *stop) { | |
| 1569 block([aKey unsignedIntValue], [aValue unsignedIntValue], stop); | |
| 1570 }]; | |
| 1571 } | |
| 1572 | |
| 1573 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 1574 NSUInteger count = _dictionary.count; | |
| 1575 if (count == 0) { | |
| 1576 return 0; | |
| 1577 } | |
| 1578 | |
| 1579 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 1580 GPBDataType keyDataType = field.mapKeyDataType; | |
| 1581 __block size_t result = 0; | |
| 1582 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 1583 NSNumber *aValue, | |
| 1584 BOOL *stop) { | |
| 1585 #pragma unused(stop) | |
| 1586 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 1587 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFi
eldNumber, valueDataType); | |
| 1588 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 1589 }]; | |
| 1590 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 1591 result += tagSize * count; | |
| 1592 return result; | |
| 1593 } | |
| 1594 | |
| 1595 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 1596 asField:(GPBFieldDescriptor *)field { | |
| 1597 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 1598 GPBDataType keyDataType = field.mapKeyDataType; | |
| 1599 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 1600 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 1601 NSNumber *aValue, | |
| 1602 BOOL *stop) { | |
| 1603 #pragma unused(stop) | |
| 1604 // Write the tag. | |
| 1605 [outputStream writeInt32NoTag:tag]; | |
| 1606 // Write the size of the message. | |
| 1607 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 1608 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFi
eldNumber, valueDataType); | |
| 1609 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 1610 // Write the fields. | |
| 1611 WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumb
er, keyDataType); | |
| 1612 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | |
| 1613 }]; | |
| 1614 } | |
| 1615 | |
| 1616 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 1617 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 1618 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)]; | |
| 1619 } | |
| 1620 | |
| 1621 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 1622 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, uint32_t value, BOOL *s
top) { | |
| 1623 #pragma unused(stop) | |
| 1624 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%u", value]); | |
| 1625 }]; | |
| 1626 } | |
| 1627 | |
| 1628 - (BOOL)valueForKey:(uint32_t)key value:(uint32_t *)value { | |
| 1629 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 1630 if (wrapped && value) { | |
| 1631 *value = [wrapped unsignedIntValue]; | |
| 1632 } | |
| 1633 return (wrapped != NULL); | |
| 1634 } | |
| 1635 | |
| 1636 - (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary { | |
| 1637 if (otherDictionary) { | |
| 1638 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 1639 if (_autocreator) { | |
| 1640 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 1641 } | |
| 1642 } | |
| 1643 } | |
| 1644 | |
| 1645 - (void)setValue:(uint32_t)value forKey:(uint32_t)key { | |
| 1646 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 1647 if (_autocreator) { | |
| 1648 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 1649 } | |
| 1650 } | |
| 1651 | |
| 1652 - (void)removeValueForKey:(uint32_t)aKey { | |
| 1653 [_dictionary removeObjectForKey:@(aKey)]; | |
| 1654 } | |
| 1655 | |
| 1656 - (void)removeAll { | |
| 1657 [_dictionary removeAllObjects]; | |
| 1658 } | |
| 1659 | |
| 1660 @end | |
| 1661 | |
| 1662 #pragma mark - UInt32 -> Int32 | |
| 1663 | |
| 1664 @implementation GPBUInt32Int32Dictionary { | |
| 1665 @package | |
| 1666 NSMutableDictionary *_dictionary; | |
| 1667 } | |
| 1668 | |
| 1669 + (instancetype)dictionary { | |
| 1670 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 1671 } | |
| 1672 | |
| 1673 + (instancetype)dictionaryWithValue:(int32_t)value | |
| 1674 forKey:(uint32_t)key { | |
| 1675 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 1676 // on to get the type correct. | |
| 1677 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithValues:&value | |
| 1678 forKeys:&key | |
| 1679 count:1] autorelease
]; | |
| 1680 } | |
| 1681 | |
| 1682 + (instancetype)dictionaryWithValues:(const int32_t [])values | |
| 1683 forKeys:(const uint32_t [])keys | |
| 1684 count:(NSUInteger)count { | |
| 1685 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 1686 // on to get the type correct. | |
| 1687 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithValues:values | |
| 1688 forKeys:keys | |
| 1689 count:count] autorel
ease]; | |
| 1690 } | |
| 1691 | |
| 1692 + (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary
{ | |
| 1693 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 1694 // on to get the type correct. | |
| 1695 return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 1696 } | |
| 1697 | |
| 1698 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 1699 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 1700 } | |
| 1701 | |
| 1702 - (instancetype)init { | |
| 1703 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 1704 } | |
| 1705 | |
| 1706 - (instancetype)initWithValues:(const int32_t [])values | |
| 1707 forKeys:(const uint32_t [])keys | |
| 1708 count:(NSUInteger)count { | |
| 1709 self = [super init]; | |
| 1710 if (self) { | |
| 1711 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 1712 if (count && values && keys) { | |
| 1713 for (NSUInteger i = 0; i < count; ++i) { | |
| 1714 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 1715 } | |
| 1716 } | |
| 1717 } | |
| 1718 return self; | |
| 1719 } | |
| 1720 | |
| 1721 - (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary { | |
| 1722 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 1723 if (self) { | |
| 1724 if (dictionary) { | |
| 1725 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 1726 } | |
| 1727 } | |
| 1728 return self; | |
| 1729 } | |
| 1730 | |
| 1731 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 1732 #pragma unused(numItems) | |
| 1733 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 1734 } | |
| 1735 | |
| 1736 - (void)dealloc { | |
| 1737 NSAssert(!_autocreator, | |
| 1738 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 1739 [self class], _autocreator); | |
| 1740 [_dictionary release]; | |
| 1741 [super dealloc]; | |
| 1742 } | |
| 1743 | |
| 1744 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 1745 return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 1746 } | |
| 1747 | |
| 1748 - (BOOL)isEqual:(GPBUInt32Int32Dictionary *)other { | |
| 1749 if (self == other) { | |
| 1750 return YES; | |
| 1751 } | |
| 1752 if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) { | |
| 1753 return NO; | |
| 1754 } | |
| 1755 return [_dictionary isEqual:other->_dictionary]; | |
| 1756 } | |
| 1757 | |
| 1758 - (NSUInteger)hash { | |
| 1759 return _dictionary.count; | |
| 1760 } | |
| 1761 | |
| 1762 - (NSString *)description { | |
| 1763 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 1764 } | |
| 1765 | |
| 1766 - (NSUInteger)count { | |
| 1767 return _dictionary.count; | |
| 1768 } | |
| 1769 | |
| 1770 - (void)enumerateKeysAndValuesUsingBlock: | |
| 1771 (void (^)(uint32_t key, int32_t value, BOOL *stop))block { | |
| 1772 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 1773 NSNumber *aValue, | |
| 1774 BOOL *stop) { | |
| 1775 block([aKey unsignedIntValue], [aValue intValue], stop); | |
| 1776 }]; | |
| 1777 } | |
| 1778 | |
| 1779 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 1780 NSUInteger count = _dictionary.count; | |
| 1781 if (count == 0) { | |
| 1782 return 0; | |
| 1783 } | |
| 1784 | |
| 1785 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 1786 GPBDataType keyDataType = field.mapKeyDataType; | |
| 1787 __block size_t result = 0; | |
| 1788 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 1789 NSNumber *aValue, | |
| 1790 BOOL *stop) { | |
| 1791 #pragma unused(stop) | |
| 1792 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 1793 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber
, valueDataType); | |
| 1794 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 1795 }]; | |
| 1796 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 1797 result += tagSize * count; | |
| 1798 return result; | |
| 1799 } | |
| 1800 | |
| 1801 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 1802 asField:(GPBFieldDescriptor *)field { | |
| 1803 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 1804 GPBDataType keyDataType = field.mapKeyDataType; | |
| 1805 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 1806 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 1807 NSNumber *aValue, | |
| 1808 BOOL *stop) { | |
| 1809 #pragma unused(stop) | |
| 1810 // Write the tag. | |
| 1811 [outputStream writeInt32NoTag:tag]; | |
| 1812 // Write the size of the message. | |
| 1813 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 1814 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber
, valueDataType); | |
| 1815 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 1816 // Write the fields. | |
| 1817 WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumb
er, keyDataType); | |
| 1818 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | |
| 1819 }]; | |
| 1820 } | |
| 1821 | |
| 1822 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 1823 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 1824 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)]; | |
| 1825 } | |
| 1826 | |
| 1827 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 1828 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, int32_t value, BOOL *st
op) { | |
| 1829 #pragma unused(stop) | |
| 1830 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%d", value]); | |
| 1831 }]; | |
| 1832 } | |
| 1833 | |
| 1834 - (BOOL)valueForKey:(uint32_t)key value:(int32_t *)value { | |
| 1835 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 1836 if (wrapped && value) { | |
| 1837 *value = [wrapped intValue]; | |
| 1838 } | |
| 1839 return (wrapped != NULL); | |
| 1840 } | |
| 1841 | |
| 1842 - (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary { | |
| 1843 if (otherDictionary) { | |
| 1844 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 1845 if (_autocreator) { | |
| 1846 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 1847 } | |
| 1848 } | |
| 1849 } | |
| 1850 | |
| 1851 - (void)setValue:(int32_t)value forKey:(uint32_t)key { | |
| 1852 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 1853 if (_autocreator) { | |
| 1854 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 1855 } | |
| 1856 } | |
| 1857 | |
| 1858 - (void)removeValueForKey:(uint32_t)aKey { | |
| 1859 [_dictionary removeObjectForKey:@(aKey)]; | |
| 1860 } | |
| 1861 | |
| 1862 - (void)removeAll { | |
| 1863 [_dictionary removeAllObjects]; | |
| 1864 } | |
| 1865 | |
| 1866 @end | |
| 1867 | |
| 1868 #pragma mark - UInt32 -> UInt64 | |
| 1869 | |
| 1870 @implementation GPBUInt32UInt64Dictionary { | |
| 1871 @package | |
| 1872 NSMutableDictionary *_dictionary; | |
| 1873 } | |
| 1874 | |
| 1875 + (instancetype)dictionary { | |
| 1876 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 1877 } | |
| 1878 | |
| 1879 + (instancetype)dictionaryWithValue:(uint64_t)value | |
| 1880 forKey:(uint32_t)key { | |
| 1881 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 1882 // on to get the type correct. | |
| 1883 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithValues:&value | |
| 1884 forKeys:&key | |
| 1885 count:1] autoreleas
e]; | |
| 1886 } | |
| 1887 | |
| 1888 + (instancetype)dictionaryWithValues:(const uint64_t [])values | |
| 1889 forKeys:(const uint32_t [])keys | |
| 1890 count:(NSUInteger)count { | |
| 1891 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 1892 // on to get the type correct. | |
| 1893 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithValues:values | |
| 1894 forKeys:keys | |
| 1895 count:count] autore
lease]; | |
| 1896 } | |
| 1897 | |
| 1898 + (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary
{ | |
| 1899 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 1900 // on to get the type correct. | |
| 1901 return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | |
| 1902 } | |
| 1903 | |
| 1904 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 1905 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 1906 } | |
| 1907 | |
| 1908 - (instancetype)init { | |
| 1909 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 1910 } | |
| 1911 | |
| 1912 - (instancetype)initWithValues:(const uint64_t [])values | |
| 1913 forKeys:(const uint32_t [])keys | |
| 1914 count:(NSUInteger)count { | |
| 1915 self = [super init]; | |
| 1916 if (self) { | |
| 1917 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 1918 if (count && values && keys) { | |
| 1919 for (NSUInteger i = 0; i < count; ++i) { | |
| 1920 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 1921 } | |
| 1922 } | |
| 1923 } | |
| 1924 return self; | |
| 1925 } | |
| 1926 | |
| 1927 - (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary { | |
| 1928 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 1929 if (self) { | |
| 1930 if (dictionary) { | |
| 1931 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 1932 } | |
| 1933 } | |
| 1934 return self; | |
| 1935 } | |
| 1936 | |
| 1937 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 1938 #pragma unused(numItems) | |
| 1939 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 1940 } | |
| 1941 | |
| 1942 - (void)dealloc { | |
| 1943 NSAssert(!_autocreator, | |
| 1944 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 1945 [self class], _autocreator); | |
| 1946 [_dictionary release]; | |
| 1947 [super dealloc]; | |
| 1948 } | |
| 1949 | |
| 1950 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 1951 return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; | |
| 1952 } | |
| 1953 | |
| 1954 - (BOOL)isEqual:(GPBUInt32UInt64Dictionary *)other { | |
| 1955 if (self == other) { | |
| 1956 return YES; | |
| 1957 } | |
| 1958 if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) { | |
| 1959 return NO; | |
| 1960 } | |
| 1961 return [_dictionary isEqual:other->_dictionary]; | |
| 1962 } | |
| 1963 | |
| 1964 - (NSUInteger)hash { | |
| 1965 return _dictionary.count; | |
| 1966 } | |
| 1967 | |
| 1968 - (NSString *)description { | |
| 1969 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 1970 } | |
| 1971 | |
| 1972 - (NSUInteger)count { | |
| 1973 return _dictionary.count; | |
| 1974 } | |
| 1975 | |
| 1976 - (void)enumerateKeysAndValuesUsingBlock: | |
| 1977 (void (^)(uint32_t key, uint64_t value, BOOL *stop))block { | |
| 1978 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 1979 NSNumber *aValue, | |
| 1980 BOOL *stop) { | |
| 1981 block([aKey unsignedIntValue], [aValue unsignedLongLongValue], stop); | |
| 1982 }]; | |
| 1983 } | |
| 1984 | |
| 1985 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 1986 NSUInteger count = _dictionary.count; | |
| 1987 if (count == 0) { | |
| 1988 return 0; | |
| 1989 } | |
| 1990 | |
| 1991 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 1992 GPBDataType keyDataType = field.mapKeyDataType; | |
| 1993 __block size_t result = 0; | |
| 1994 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 1995 NSNumber *aValue, | |
| 1996 BOOL *stop) { | |
| 1997 #pragma unused(stop) | |
| 1998 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 1999 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapVa
lueFieldNumber, valueDataType); | |
| 2000 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 2001 }]; | |
| 2002 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 2003 result += tagSize * count; | |
| 2004 return result; | |
| 2005 } | |
| 2006 | |
| 2007 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 2008 asField:(GPBFieldDescriptor *)field { | |
| 2009 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 2010 GPBDataType keyDataType = field.mapKeyDataType; | |
| 2011 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 2012 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2013 NSNumber *aValue, | |
| 2014 BOOL *stop) { | |
| 2015 #pragma unused(stop) | |
| 2016 // Write the tag. | |
| 2017 [outputStream writeInt32NoTag:tag]; | |
| 2018 // Write the size of the message. | |
| 2019 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 2020 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapVa
lueFieldNumber, valueDataType); | |
| 2021 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 2022 // Write the fields. | |
| 2023 WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumb
er, keyDataType); | |
| 2024 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | |
| 2025 }]; | |
| 2026 } | |
| 2027 | |
| 2028 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 2029 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 2030 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)]; | |
| 2031 } | |
| 2032 | |
| 2033 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 2034 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, uint64_t value, BOOL *s
top) { | |
| 2035 #pragma unused(stop) | |
| 2036 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%llu", value]); | |
| 2037 }]; | |
| 2038 } | |
| 2039 | |
| 2040 - (BOOL)valueForKey:(uint32_t)key value:(uint64_t *)value { | |
| 2041 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 2042 if (wrapped && value) { | |
| 2043 *value = [wrapped unsignedLongLongValue]; | |
| 2044 } | |
| 2045 return (wrapped != NULL); | |
| 2046 } | |
| 2047 | |
| 2048 - (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary { | |
| 2049 if (otherDictionary) { | |
| 2050 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 2051 if (_autocreator) { | |
| 2052 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 2053 } | |
| 2054 } | |
| 2055 } | |
| 2056 | |
| 2057 - (void)setValue:(uint64_t)value forKey:(uint32_t)key { | |
| 2058 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 2059 if (_autocreator) { | |
| 2060 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 2061 } | |
| 2062 } | |
| 2063 | |
| 2064 - (void)removeValueForKey:(uint32_t)aKey { | |
| 2065 [_dictionary removeObjectForKey:@(aKey)]; | |
| 2066 } | |
| 2067 | |
| 2068 - (void)removeAll { | |
| 2069 [_dictionary removeAllObjects]; | |
| 2070 } | |
| 2071 | |
| 2072 @end | |
| 2073 | |
| 2074 #pragma mark - UInt32 -> Int64 | |
| 2075 | |
| 2076 @implementation GPBUInt32Int64Dictionary { | |
| 2077 @package | |
| 2078 NSMutableDictionary *_dictionary; | |
| 2079 } | |
| 2080 | |
| 2081 + (instancetype)dictionary { | |
| 2082 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 2083 } | |
| 2084 | |
| 2085 + (instancetype)dictionaryWithValue:(int64_t)value | |
| 2086 forKey:(uint32_t)key { | |
| 2087 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2088 // on to get the type correct. | |
| 2089 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithValues:&value | |
| 2090 forKeys:&key | |
| 2091 count:1] autorelease
]; | |
| 2092 } | |
| 2093 | |
| 2094 + (instancetype)dictionaryWithValues:(const int64_t [])values | |
| 2095 forKeys:(const uint32_t [])keys | |
| 2096 count:(NSUInteger)count { | |
| 2097 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2098 // on to get the type correct. | |
| 2099 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithValues:values | |
| 2100 forKeys:keys | |
| 2101 count:count] autorel
ease]; | |
| 2102 } | |
| 2103 | |
| 2104 + (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary
{ | |
| 2105 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2106 // on to get the type correct. | |
| 2107 return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 2108 } | |
| 2109 | |
| 2110 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 2111 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 2112 } | |
| 2113 | |
| 2114 - (instancetype)init { | |
| 2115 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2116 } | |
| 2117 | |
| 2118 - (instancetype)initWithValues:(const int64_t [])values | |
| 2119 forKeys:(const uint32_t [])keys | |
| 2120 count:(NSUInteger)count { | |
| 2121 self = [super init]; | |
| 2122 if (self) { | |
| 2123 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 2124 if (count && values && keys) { | |
| 2125 for (NSUInteger i = 0; i < count; ++i) { | |
| 2126 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 2127 } | |
| 2128 } | |
| 2129 } | |
| 2130 return self; | |
| 2131 } | |
| 2132 | |
| 2133 - (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary { | |
| 2134 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2135 if (self) { | |
| 2136 if (dictionary) { | |
| 2137 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 2138 } | |
| 2139 } | |
| 2140 return self; | |
| 2141 } | |
| 2142 | |
| 2143 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 2144 #pragma unused(numItems) | |
| 2145 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2146 } | |
| 2147 | |
| 2148 - (void)dealloc { | |
| 2149 NSAssert(!_autocreator, | |
| 2150 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 2151 [self class], _autocreator); | |
| 2152 [_dictionary release]; | |
| 2153 [super dealloc]; | |
| 2154 } | |
| 2155 | |
| 2156 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 2157 return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 2158 } | |
| 2159 | |
| 2160 - (BOOL)isEqual:(GPBUInt32Int64Dictionary *)other { | |
| 2161 if (self == other) { | |
| 2162 return YES; | |
| 2163 } | |
| 2164 if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) { | |
| 2165 return NO; | |
| 2166 } | |
| 2167 return [_dictionary isEqual:other->_dictionary]; | |
| 2168 } | |
| 2169 | |
| 2170 - (NSUInteger)hash { | |
| 2171 return _dictionary.count; | |
| 2172 } | |
| 2173 | |
| 2174 - (NSString *)description { | |
| 2175 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 2176 } | |
| 2177 | |
| 2178 - (NSUInteger)count { | |
| 2179 return _dictionary.count; | |
| 2180 } | |
| 2181 | |
| 2182 - (void)enumerateKeysAndValuesUsingBlock: | |
| 2183 (void (^)(uint32_t key, int64_t value, BOOL *stop))block { | |
| 2184 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2185 NSNumber *aValue, | |
| 2186 BOOL *stop) { | |
| 2187 block([aKey unsignedIntValue], [aValue longLongValue], stop); | |
| 2188 }]; | |
| 2189 } | |
| 2190 | |
| 2191 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 2192 NSUInteger count = _dictionary.count; | |
| 2193 if (count == 0) { | |
| 2194 return 0; | |
| 2195 } | |
| 2196 | |
| 2197 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 2198 GPBDataType keyDataType = field.mapKeyDataType; | |
| 2199 __block size_t result = 0; | |
| 2200 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2201 NSNumber *aValue, | |
| 2202 BOOL *stop) { | |
| 2203 #pragma unused(stop) | |
| 2204 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 2205 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldN
umber, valueDataType); | |
| 2206 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 2207 }]; | |
| 2208 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 2209 result += tagSize * count; | |
| 2210 return result; | |
| 2211 } | |
| 2212 | |
| 2213 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 2214 asField:(GPBFieldDescriptor *)field { | |
| 2215 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 2216 GPBDataType keyDataType = field.mapKeyDataType; | |
| 2217 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 2218 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2219 NSNumber *aValue, | |
| 2220 BOOL *stop) { | |
| 2221 #pragma unused(stop) | |
| 2222 // Write the tag. | |
| 2223 [outputStream writeInt32NoTag:tag]; | |
| 2224 // Write the size of the message. | |
| 2225 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 2226 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldN
umber, valueDataType); | |
| 2227 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 2228 // Write the fields. | |
| 2229 WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumb
er, keyDataType); | |
| 2230 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | |
| 2231 }]; | |
| 2232 } | |
| 2233 | |
| 2234 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 2235 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 2236 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)]; | |
| 2237 } | |
| 2238 | |
| 2239 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 2240 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, int64_t value, BOOL *st
op) { | |
| 2241 #pragma unused(stop) | |
| 2242 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%lld", value]); | |
| 2243 }]; | |
| 2244 } | |
| 2245 | |
| 2246 - (BOOL)valueForKey:(uint32_t)key value:(int64_t *)value { | |
| 2247 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 2248 if (wrapped && value) { | |
| 2249 *value = [wrapped longLongValue]; | |
| 2250 } | |
| 2251 return (wrapped != NULL); | |
| 2252 } | |
| 2253 | |
| 2254 - (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary { | |
| 2255 if (otherDictionary) { | |
| 2256 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 2257 if (_autocreator) { | |
| 2258 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 2259 } | |
| 2260 } | |
| 2261 } | |
| 2262 | |
| 2263 - (void)setValue:(int64_t)value forKey:(uint32_t)key { | |
| 2264 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 2265 if (_autocreator) { | |
| 2266 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 2267 } | |
| 2268 } | |
| 2269 | |
| 2270 - (void)removeValueForKey:(uint32_t)aKey { | |
| 2271 [_dictionary removeObjectForKey:@(aKey)]; | |
| 2272 } | |
| 2273 | |
| 2274 - (void)removeAll { | |
| 2275 [_dictionary removeAllObjects]; | |
| 2276 } | |
| 2277 | |
| 2278 @end | |
| 2279 | |
| 2280 #pragma mark - UInt32 -> Bool | |
| 2281 | |
| 2282 @implementation GPBUInt32BoolDictionary { | |
| 2283 @package | |
| 2284 NSMutableDictionary *_dictionary; | |
| 2285 } | |
| 2286 | |
| 2287 + (instancetype)dictionary { | |
| 2288 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 2289 } | |
| 2290 | |
| 2291 + (instancetype)dictionaryWithValue:(BOOL)value | |
| 2292 forKey:(uint32_t)key { | |
| 2293 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2294 // on to get the type correct. | |
| 2295 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithValues:&value | |
| 2296 forKeys:&key | |
| 2297 count:1] autorelease]
; | |
| 2298 } | |
| 2299 | |
| 2300 + (instancetype)dictionaryWithValues:(const BOOL [])values | |
| 2301 forKeys:(const uint32_t [])keys | |
| 2302 count:(NSUInteger)count { | |
| 2303 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2304 // on to get the type correct. | |
| 2305 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithValues:values | |
| 2306 forKeys:keys | |
| 2307 count:count] autorele
ase]; | |
| 2308 } | |
| 2309 | |
| 2310 + (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary { | |
| 2311 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2312 // on to get the type correct. | |
| 2313 return [[(GPBUInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 2314 } | |
| 2315 | |
| 2316 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 2317 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 2318 } | |
| 2319 | |
| 2320 - (instancetype)init { | |
| 2321 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2322 } | |
| 2323 | |
| 2324 - (instancetype)initWithValues:(const BOOL [])values | |
| 2325 forKeys:(const uint32_t [])keys | |
| 2326 count:(NSUInteger)count { | |
| 2327 self = [super init]; | |
| 2328 if (self) { | |
| 2329 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 2330 if (count && values && keys) { | |
| 2331 for (NSUInteger i = 0; i < count; ++i) { | |
| 2332 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 2333 } | |
| 2334 } | |
| 2335 } | |
| 2336 return self; | |
| 2337 } | |
| 2338 | |
| 2339 - (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary { | |
| 2340 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2341 if (self) { | |
| 2342 if (dictionary) { | |
| 2343 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 2344 } | |
| 2345 } | |
| 2346 return self; | |
| 2347 } | |
| 2348 | |
| 2349 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 2350 #pragma unused(numItems) | |
| 2351 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2352 } | |
| 2353 | |
| 2354 - (void)dealloc { | |
| 2355 NSAssert(!_autocreator, | |
| 2356 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 2357 [self class], _autocreator); | |
| 2358 [_dictionary release]; | |
| 2359 [super dealloc]; | |
| 2360 } | |
| 2361 | |
| 2362 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 2363 return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 2364 } | |
| 2365 | |
| 2366 - (BOOL)isEqual:(GPBUInt32BoolDictionary *)other { | |
| 2367 if (self == other) { | |
| 2368 return YES; | |
| 2369 } | |
| 2370 if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) { | |
| 2371 return NO; | |
| 2372 } | |
| 2373 return [_dictionary isEqual:other->_dictionary]; | |
| 2374 } | |
| 2375 | |
| 2376 - (NSUInteger)hash { | |
| 2377 return _dictionary.count; | |
| 2378 } | |
| 2379 | |
| 2380 - (NSString *)description { | |
| 2381 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 2382 } | |
| 2383 | |
| 2384 - (NSUInteger)count { | |
| 2385 return _dictionary.count; | |
| 2386 } | |
| 2387 | |
| 2388 - (void)enumerateKeysAndValuesUsingBlock: | |
| 2389 (void (^)(uint32_t key, BOOL value, BOOL *stop))block { | |
| 2390 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2391 NSNumber *aValue, | |
| 2392 BOOL *stop) { | |
| 2393 block([aKey unsignedIntValue], [aValue boolValue], stop); | |
| 2394 }]; | |
| 2395 } | |
| 2396 | |
| 2397 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 2398 NSUInteger count = _dictionary.count; | |
| 2399 if (count == 0) { | |
| 2400 return 0; | |
| 2401 } | |
| 2402 | |
| 2403 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 2404 GPBDataType keyDataType = field.mapKeyDataType; | |
| 2405 __block size_t result = 0; | |
| 2406 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2407 NSNumber *aValue, | |
| 2408 BOOL *stop) { | |
| 2409 #pragma unused(stop) | |
| 2410 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 2411 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber
, valueDataType); | |
| 2412 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 2413 }]; | |
| 2414 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 2415 result += tagSize * count; | |
| 2416 return result; | |
| 2417 } | |
| 2418 | |
| 2419 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 2420 asField:(GPBFieldDescriptor *)field { | |
| 2421 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 2422 GPBDataType keyDataType = field.mapKeyDataType; | |
| 2423 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 2424 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2425 NSNumber *aValue, | |
| 2426 BOOL *stop) { | |
| 2427 #pragma unused(stop) | |
| 2428 // Write the tag. | |
| 2429 [outputStream writeInt32NoTag:tag]; | |
| 2430 // Write the size of the message. | |
| 2431 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 2432 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber
, valueDataType); | |
| 2433 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 2434 // Write the fields. | |
| 2435 WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumb
er, keyDataType); | |
| 2436 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | |
| 2437 }]; | |
| 2438 } | |
| 2439 | |
| 2440 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 2441 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 2442 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)]; | |
| 2443 } | |
| 2444 | |
| 2445 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 2446 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, BOOL value, BOOL *stop)
{ | |
| 2447 #pragma unused(stop) | |
| 2448 block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false")
); | |
| 2449 }]; | |
| 2450 } | |
| 2451 | |
| 2452 - (BOOL)valueForKey:(uint32_t)key value:(BOOL *)value { | |
| 2453 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 2454 if (wrapped && value) { | |
| 2455 *value = [wrapped boolValue]; | |
| 2456 } | |
| 2457 return (wrapped != NULL); | |
| 2458 } | |
| 2459 | |
| 2460 - (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary { | |
| 2461 if (otherDictionary) { | |
| 2462 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 2463 if (_autocreator) { | |
| 2464 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 2465 } | |
| 2466 } | |
| 2467 } | |
| 2468 | |
| 2469 - (void)setValue:(BOOL)value forKey:(uint32_t)key { | |
| 2470 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 2471 if (_autocreator) { | |
| 2472 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 2473 } | |
| 2474 } | |
| 2475 | |
| 2476 - (void)removeValueForKey:(uint32_t)aKey { | |
| 2477 [_dictionary removeObjectForKey:@(aKey)]; | |
| 2478 } | |
| 2479 | |
| 2480 - (void)removeAll { | |
| 2481 [_dictionary removeAllObjects]; | |
| 2482 } | |
| 2483 | |
| 2484 @end | |
| 2485 | |
| 2486 #pragma mark - UInt32 -> Float | |
| 2487 | |
| 2488 @implementation GPBUInt32FloatDictionary { | |
| 2489 @package | |
| 2490 NSMutableDictionary *_dictionary; | |
| 2491 } | |
| 2492 | |
| 2493 + (instancetype)dictionary { | |
| 2494 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 2495 } | |
| 2496 | |
| 2497 + (instancetype)dictionaryWithValue:(float)value | |
| 2498 forKey:(uint32_t)key { | |
| 2499 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2500 // on to get the type correct. | |
| 2501 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithValues:&value | |
| 2502 forKeys:&key | |
| 2503 count:1] autorelease
]; | |
| 2504 } | |
| 2505 | |
| 2506 + (instancetype)dictionaryWithValues:(const float [])values | |
| 2507 forKeys:(const uint32_t [])keys | |
| 2508 count:(NSUInteger)count { | |
| 2509 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2510 // on to get the type correct. | |
| 2511 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithValues:values | |
| 2512 forKeys:keys | |
| 2513 count:count] autorel
ease]; | |
| 2514 } | |
| 2515 | |
| 2516 + (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary
{ | |
| 2517 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2518 // on to get the type correct. | |
| 2519 return [[(GPBUInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 2520 } | |
| 2521 | |
| 2522 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 2523 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 2524 } | |
| 2525 | |
| 2526 - (instancetype)init { | |
| 2527 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2528 } | |
| 2529 | |
| 2530 - (instancetype)initWithValues:(const float [])values | |
| 2531 forKeys:(const uint32_t [])keys | |
| 2532 count:(NSUInteger)count { | |
| 2533 self = [super init]; | |
| 2534 if (self) { | |
| 2535 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 2536 if (count && values && keys) { | |
| 2537 for (NSUInteger i = 0; i < count; ++i) { | |
| 2538 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 2539 } | |
| 2540 } | |
| 2541 } | |
| 2542 return self; | |
| 2543 } | |
| 2544 | |
| 2545 - (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary { | |
| 2546 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2547 if (self) { | |
| 2548 if (dictionary) { | |
| 2549 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 2550 } | |
| 2551 } | |
| 2552 return self; | |
| 2553 } | |
| 2554 | |
| 2555 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 2556 #pragma unused(numItems) | |
| 2557 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2558 } | |
| 2559 | |
| 2560 - (void)dealloc { | |
| 2561 NSAssert(!_autocreator, | |
| 2562 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 2563 [self class], _autocreator); | |
| 2564 [_dictionary release]; | |
| 2565 [super dealloc]; | |
| 2566 } | |
| 2567 | |
| 2568 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 2569 return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 2570 } | |
| 2571 | |
| 2572 - (BOOL)isEqual:(GPBUInt32FloatDictionary *)other { | |
| 2573 if (self == other) { | |
| 2574 return YES; | |
| 2575 } | |
| 2576 if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) { | |
| 2577 return NO; | |
| 2578 } | |
| 2579 return [_dictionary isEqual:other->_dictionary]; | |
| 2580 } | |
| 2581 | |
| 2582 - (NSUInteger)hash { | |
| 2583 return _dictionary.count; | |
| 2584 } | |
| 2585 | |
| 2586 - (NSString *)description { | |
| 2587 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 2588 } | |
| 2589 | |
| 2590 - (NSUInteger)count { | |
| 2591 return _dictionary.count; | |
| 2592 } | |
| 2593 | |
| 2594 - (void)enumerateKeysAndValuesUsingBlock: | |
| 2595 (void (^)(uint32_t key, float value, BOOL *stop))block { | |
| 2596 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2597 NSNumber *aValue, | |
| 2598 BOOL *stop) { | |
| 2599 block([aKey unsignedIntValue], [aValue floatValue], stop); | |
| 2600 }]; | |
| 2601 } | |
| 2602 | |
| 2603 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 2604 NSUInteger count = _dictionary.count; | |
| 2605 if (count == 0) { | |
| 2606 return 0; | |
| 2607 } | |
| 2608 | |
| 2609 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 2610 GPBDataType keyDataType = field.mapKeyDataType; | |
| 2611 __block size_t result = 0; | |
| 2612 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2613 NSNumber *aValue, | |
| 2614 BOOL *stop) { | |
| 2615 #pragma unused(stop) | |
| 2616 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 2617 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumb
er, valueDataType); | |
| 2618 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 2619 }]; | |
| 2620 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 2621 result += tagSize * count; | |
| 2622 return result; | |
| 2623 } | |
| 2624 | |
| 2625 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 2626 asField:(GPBFieldDescriptor *)field { | |
| 2627 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 2628 GPBDataType keyDataType = field.mapKeyDataType; | |
| 2629 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 2630 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2631 NSNumber *aValue, | |
| 2632 BOOL *stop) { | |
| 2633 #pragma unused(stop) | |
| 2634 // Write the tag. | |
| 2635 [outputStream writeInt32NoTag:tag]; | |
| 2636 // Write the size of the message. | |
| 2637 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 2638 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumb
er, valueDataType); | |
| 2639 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 2640 // Write the fields. | |
| 2641 WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumb
er, keyDataType); | |
| 2642 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | |
| 2643 }]; | |
| 2644 } | |
| 2645 | |
| 2646 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 2647 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 2648 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)]; | |
| 2649 } | |
| 2650 | |
| 2651 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 2652 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, float value, BOOL *stop
) { | |
| 2653 #pragma unused(stop) | |
| 2654 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%.*g", FLT_DIG, value]); | |
| 2655 }]; | |
| 2656 } | |
| 2657 | |
| 2658 - (BOOL)valueForKey:(uint32_t)key value:(float *)value { | |
| 2659 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 2660 if (wrapped && value) { | |
| 2661 *value = [wrapped floatValue]; | |
| 2662 } | |
| 2663 return (wrapped != NULL); | |
| 2664 } | |
| 2665 | |
| 2666 - (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary { | |
| 2667 if (otherDictionary) { | |
| 2668 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 2669 if (_autocreator) { | |
| 2670 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 2671 } | |
| 2672 } | |
| 2673 } | |
| 2674 | |
| 2675 - (void)setValue:(float)value forKey:(uint32_t)key { | |
| 2676 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 2677 if (_autocreator) { | |
| 2678 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 2679 } | |
| 2680 } | |
| 2681 | |
| 2682 - (void)removeValueForKey:(uint32_t)aKey { | |
| 2683 [_dictionary removeObjectForKey:@(aKey)]; | |
| 2684 } | |
| 2685 | |
| 2686 - (void)removeAll { | |
| 2687 [_dictionary removeAllObjects]; | |
| 2688 } | |
| 2689 | |
| 2690 @end | |
| 2691 | |
| 2692 #pragma mark - UInt32 -> Double | |
| 2693 | |
| 2694 @implementation GPBUInt32DoubleDictionary { | |
| 2695 @package | |
| 2696 NSMutableDictionary *_dictionary; | |
| 2697 } | |
| 2698 | |
| 2699 + (instancetype)dictionary { | |
| 2700 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 2701 } | |
| 2702 | |
| 2703 + (instancetype)dictionaryWithValue:(double)value | |
| 2704 forKey:(uint32_t)key { | |
| 2705 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2706 // on to get the type correct. | |
| 2707 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithValues:&value | |
| 2708 forKeys:&key | |
| 2709 count:1] autoreleas
e]; | |
| 2710 } | |
| 2711 | |
| 2712 + (instancetype)dictionaryWithValues:(const double [])values | |
| 2713 forKeys:(const uint32_t [])keys | |
| 2714 count:(NSUInteger)count { | |
| 2715 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2716 // on to get the type correct. | |
| 2717 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithValues:values | |
| 2718 forKeys:keys | |
| 2719 count:count] autore
lease]; | |
| 2720 } | |
| 2721 | |
| 2722 + (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary
{ | |
| 2723 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2724 // on to get the type correct. | |
| 2725 return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | |
| 2726 } | |
| 2727 | |
| 2728 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 2729 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 2730 } | |
| 2731 | |
| 2732 - (instancetype)init { | |
| 2733 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2734 } | |
| 2735 | |
| 2736 - (instancetype)initWithValues:(const double [])values | |
| 2737 forKeys:(const uint32_t [])keys | |
| 2738 count:(NSUInteger)count { | |
| 2739 self = [super init]; | |
| 2740 if (self) { | |
| 2741 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 2742 if (count && values && keys) { | |
| 2743 for (NSUInteger i = 0; i < count; ++i) { | |
| 2744 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 2745 } | |
| 2746 } | |
| 2747 } | |
| 2748 return self; | |
| 2749 } | |
| 2750 | |
| 2751 - (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary { | |
| 2752 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2753 if (self) { | |
| 2754 if (dictionary) { | |
| 2755 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 2756 } | |
| 2757 } | |
| 2758 return self; | |
| 2759 } | |
| 2760 | |
| 2761 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 2762 #pragma unused(numItems) | |
| 2763 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 2764 } | |
| 2765 | |
| 2766 - (void)dealloc { | |
| 2767 NSAssert(!_autocreator, | |
| 2768 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 2769 [self class], _autocreator); | |
| 2770 [_dictionary release]; | |
| 2771 [super dealloc]; | |
| 2772 } | |
| 2773 | |
| 2774 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 2775 return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self
]; | |
| 2776 } | |
| 2777 | |
| 2778 - (BOOL)isEqual:(GPBUInt32DoubleDictionary *)other { | |
| 2779 if (self == other) { | |
| 2780 return YES; | |
| 2781 } | |
| 2782 if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) { | |
| 2783 return NO; | |
| 2784 } | |
| 2785 return [_dictionary isEqual:other->_dictionary]; | |
| 2786 } | |
| 2787 | |
| 2788 - (NSUInteger)hash { | |
| 2789 return _dictionary.count; | |
| 2790 } | |
| 2791 | |
| 2792 - (NSString *)description { | |
| 2793 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 2794 } | |
| 2795 | |
| 2796 - (NSUInteger)count { | |
| 2797 return _dictionary.count; | |
| 2798 } | |
| 2799 | |
| 2800 - (void)enumerateKeysAndValuesUsingBlock: | |
| 2801 (void (^)(uint32_t key, double value, BOOL *stop))block { | |
| 2802 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2803 NSNumber *aValue, | |
| 2804 BOOL *stop) { | |
| 2805 block([aKey unsignedIntValue], [aValue doubleValue], stop); | |
| 2806 }]; | |
| 2807 } | |
| 2808 | |
| 2809 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 2810 NSUInteger count = _dictionary.count; | |
| 2811 if (count == 0) { | |
| 2812 return 0; | |
| 2813 } | |
| 2814 | |
| 2815 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 2816 GPBDataType keyDataType = field.mapKeyDataType; | |
| 2817 __block size_t result = 0; | |
| 2818 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2819 NSNumber *aValue, | |
| 2820 BOOL *stop) { | |
| 2821 #pragma unused(stop) | |
| 2822 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 2823 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNu
mber, valueDataType); | |
| 2824 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 2825 }]; | |
| 2826 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 2827 result += tagSize * count; | |
| 2828 return result; | |
| 2829 } | |
| 2830 | |
| 2831 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 2832 asField:(GPBFieldDescriptor *)field { | |
| 2833 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 2834 GPBDataType keyDataType = field.mapKeyDataType; | |
| 2835 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 2836 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 2837 NSNumber *aValue, | |
| 2838 BOOL *stop) { | |
| 2839 #pragma unused(stop) | |
| 2840 // Write the tag. | |
| 2841 [outputStream writeInt32NoTag:tag]; | |
| 2842 // Write the size of the message. | |
| 2843 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 2844 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNu
mber, valueDataType); | |
| 2845 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 2846 // Write the fields. | |
| 2847 WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumb
er, keyDataType); | |
| 2848 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | |
| 2849 }]; | |
| 2850 } | |
| 2851 | |
| 2852 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 2853 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 2854 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)]; | |
| 2855 } | |
| 2856 | |
| 2857 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 2858 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, double value, BOOL *sto
p) { | |
| 2859 #pragma unused(stop) | |
| 2860 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@
"%.*lg", DBL_DIG, value]); | |
| 2861 }]; | |
| 2862 } | |
| 2863 | |
| 2864 - (BOOL)valueForKey:(uint32_t)key value:(double *)value { | |
| 2865 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 2866 if (wrapped && value) { | |
| 2867 *value = [wrapped doubleValue]; | |
| 2868 } | |
| 2869 return (wrapped != NULL); | |
| 2870 } | |
| 2871 | |
| 2872 - (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary { | |
| 2873 if (otherDictionary) { | |
| 2874 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 2875 if (_autocreator) { | |
| 2876 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 2877 } | |
| 2878 } | |
| 2879 } | |
| 2880 | |
| 2881 - (void)setValue:(double)value forKey:(uint32_t)key { | |
| 2882 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 2883 if (_autocreator) { | |
| 2884 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 2885 } | |
| 2886 } | |
| 2887 | |
| 2888 - (void)removeValueForKey:(uint32_t)aKey { | |
| 2889 [_dictionary removeObjectForKey:@(aKey)]; | |
| 2890 } | |
| 2891 | |
| 2892 - (void)removeAll { | |
| 2893 [_dictionary removeAllObjects]; | |
| 2894 } | |
| 2895 | |
| 2896 @end | |
| 2897 | |
| 2898 #pragma mark - UInt32 -> Enum | |
| 2899 | |
| 2900 @implementation GPBUInt32EnumDictionary { | |
| 2901 @package | |
| 2902 NSMutableDictionary *_dictionary; | |
| 2903 GPBEnumValidationFunc _validationFunc; | |
| 2904 } | |
| 2905 | |
| 2906 @synthesize validationFunc = _validationFunc; | |
| 2907 | |
| 2908 + (instancetype)dictionary { | |
| 2909 return [[[self alloc] initWithValidationFunction:NULL | |
| 2910 rawValues:NULL | |
| 2911 forKeys:NULL | |
| 2912 count:0] autorelease]; | |
| 2913 } | |
| 2914 | |
| 2915 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 2916 return [[[self alloc] initWithValidationFunction:func | |
| 2917 rawValues:NULL | |
| 2918 forKeys:NULL | |
| 2919 count:0] autorelease]; | |
| 2920 } | |
| 2921 | |
| 2922 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 2923 rawValue:(int32_t)rawValue | |
| 2924 forKey:(uint32_t)key { | |
| 2925 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2926 // on to get the type correct. | |
| 2927 return [[(GPBUInt32EnumDictionary*)[self alloc] initWithValidationFunction:fun
c | |
| 2928 rawValues:&ra
wValue | |
| 2929 forKeys:&ke
y | |
| 2930 count:1]
autorelease]; | |
| 2931 } | |
| 2932 | |
| 2933 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 2934 rawValues:(const int32_t [])rawValues | |
| 2935 forKeys:(const uint32_t [])keys | |
| 2936 count:(NSUInteger)count { | |
| 2937 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2938 // on to get the type correct. | |
| 2939 return [[(GPBUInt32EnumDictionary*)[self alloc] initWithValidationFunction:fun
c | |
| 2940 rawValues:raw
Values | |
| 2941 forKeys:key
s | |
| 2942 count:cou
nt] autorelease]; | |
| 2943 } | |
| 2944 | |
| 2945 + (instancetype)dictionaryWithDictionary:(GPBUInt32EnumDictionary *)dictionary { | |
| 2946 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 2947 // on to get the type correct. | |
| 2948 return [[(GPBUInt32EnumDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 2949 } | |
| 2950 | |
| 2951 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 2952 capacity:(NSUInteger)numItems { | |
| 2953 return [[[self alloc] initWithValidationFunction:func capacity:numItems] autor
elease]; | |
| 2954 } | |
| 2955 | |
| 2956 - (instancetype)init { | |
| 2957 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count
:0]; | |
| 2958 } | |
| 2959 | |
| 2960 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 2961 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 2962 } | |
| 2963 | |
| 2964 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 2965 rawValues:(const int32_t [])rawValues | |
| 2966 forKeys:(const uint32_t [])keys | |
| 2967 count:(NSUInteger)count { | |
| 2968 self = [super init]; | |
| 2969 if (self) { | |
| 2970 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 2971 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); | |
| 2972 if (count && rawValues && keys) { | |
| 2973 for (NSUInteger i = 0; i < count; ++i) { | |
| 2974 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])]; | |
| 2975 } | |
| 2976 } | |
| 2977 } | |
| 2978 return self; | |
| 2979 } | |
| 2980 | |
| 2981 - (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary { | |
| 2982 self = [self initWithValidationFunction:dictionary.validationFunc | |
| 2983 rawValues:NULL | |
| 2984 forKeys:NULL | |
| 2985 count:0]; | |
| 2986 if (self) { | |
| 2987 if (dictionary) { | |
| 2988 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 2989 } | |
| 2990 } | |
| 2991 return self; | |
| 2992 } | |
| 2993 | |
| 2994 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 2995 capacity:(NSUInteger)numItems { | |
| 2996 #pragma unused(numItems) | |
| 2997 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 2998 } | |
| 2999 | |
| 3000 - (void)dealloc { | |
| 3001 NSAssert(!_autocreator, | |
| 3002 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 3003 [self class], _autocreator); | |
| 3004 [_dictionary release]; | |
| 3005 [super dealloc]; | |
| 3006 } | |
| 3007 | |
| 3008 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 3009 return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 3010 } | |
| 3011 | |
| 3012 - (BOOL)isEqual:(GPBUInt32EnumDictionary *)other { | |
| 3013 if (self == other) { | |
| 3014 return YES; | |
| 3015 } | |
| 3016 if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) { | |
| 3017 return NO; | |
| 3018 } | |
| 3019 return [_dictionary isEqual:other->_dictionary]; | |
| 3020 } | |
| 3021 | |
| 3022 - (NSUInteger)hash { | |
| 3023 return _dictionary.count; | |
| 3024 } | |
| 3025 | |
| 3026 - (NSString *)description { | |
| 3027 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 3028 } | |
| 3029 | |
| 3030 - (NSUInteger)count { | |
| 3031 return _dictionary.count; | |
| 3032 } | |
| 3033 | |
| 3034 - (void)enumerateKeysAndRawValuesUsingBlock: | |
| 3035 (void (^)(uint32_t key, int32_t value, BOOL *stop))block { | |
| 3036 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3037 NSNumber *aValue, | |
| 3038 BOOL *stop) { | |
| 3039 block([aKey unsignedIntValue], [aValue intValue], stop); | |
| 3040 }]; | |
| 3041 } | |
| 3042 | |
| 3043 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 3044 NSUInteger count = _dictionary.count; | |
| 3045 if (count == 0) { | |
| 3046 return 0; | |
| 3047 } | |
| 3048 | |
| 3049 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 3050 GPBDataType keyDataType = field.mapKeyDataType; | |
| 3051 __block size_t result = 0; | |
| 3052 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3053 NSNumber *aValue, | |
| 3054 BOOL *stop) { | |
| 3055 #pragma unused(stop) | |
| 3056 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 3057 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber,
valueDataType); | |
| 3058 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 3059 }]; | |
| 3060 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 3061 result += tagSize * count; | |
| 3062 return result; | |
| 3063 } | |
| 3064 | |
| 3065 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 3066 asField:(GPBFieldDescriptor *)field { | |
| 3067 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 3068 GPBDataType keyDataType = field.mapKeyDataType; | |
| 3069 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 3070 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3071 NSNumber *aValue, | |
| 3072 BOOL *stop) { | |
| 3073 #pragma unused(stop) | |
| 3074 // Write the tag. | |
| 3075 [outputStream writeInt32NoTag:tag]; | |
| 3076 // Write the size of the message. | |
| 3077 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 3078 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber,
valueDataType); | |
| 3079 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 3080 // Write the fields. | |
| 3081 WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumb
er, keyDataType); | |
| 3082 WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, va
lueDataType); | |
| 3083 }]; | |
| 3084 } | |
| 3085 | |
| 3086 - (NSData *)serializedDataForUnknownValue:(int32_t)value | |
| 3087 forKey:(GPBGenericValue *)key | |
| 3088 keyDataType:(GPBDataType)keyDataType { | |
| 3089 size_t msgSize = ComputeDictUInt32FieldSize(key->valueUInt32, kMapKeyFieldNumb
er, keyDataType); | |
| 3090 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEn
um); | |
| 3091 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; | |
| 3092 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithDat
a:data]; | |
| 3093 WriteDictUInt32Field(outputStream, key->valueUInt32, kMapKeyFieldNumber, keyDa
taType); | |
| 3094 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum)
; | |
| 3095 [outputStream release]; | |
| 3096 return data; | |
| 3097 } | |
| 3098 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 3099 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 3100 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)]; | |
| 3101 } | |
| 3102 | |
| 3103 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 3104 [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL
*stop) { | |
| 3105 #pragma unused(stop) | |
| 3106 block([NSString stringWithFormat:@"%u", key], @(value)); | |
| 3107 }]; | |
| 3108 } | |
| 3109 | |
| 3110 - (BOOL)valueForKey:(uint32_t)key value:(int32_t *)value { | |
| 3111 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 3112 if (wrapped && value) { | |
| 3113 int32_t result = [wrapped intValue]; | |
| 3114 if (!_validationFunc(result)) { | |
| 3115 result = kGPBUnrecognizedEnumeratorValue; | |
| 3116 } | |
| 3117 *value = result; | |
| 3118 } | |
| 3119 return (wrapped != NULL); | |
| 3120 } | |
| 3121 | |
| 3122 - (BOOL)valueForKey:(uint32_t)key rawValue:(int32_t *)rawValue { | |
| 3123 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 3124 if (wrapped && rawValue) { | |
| 3125 *rawValue = [wrapped intValue]; | |
| 3126 } | |
| 3127 return (wrapped != NULL); | |
| 3128 } | |
| 3129 | |
| 3130 - (void)enumerateKeysAndValuesUsingBlock: | |
| 3131 (void (^)(uint32_t key, int32_t value, BOOL *stop))block { | |
| 3132 GPBEnumValidationFunc func = _validationFunc; | |
| 3133 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3134 NSNumber *aValue, | |
| 3135 BOOL *stop) { | |
| 3136 int32_t unwrapped = [aValue intValue]; | |
| 3137 if (!func(unwrapped)) { | |
| 3138 unwrapped = kGPBUnrecognizedEnumeratorValue; | |
| 3139 } | |
| 3140 block([aKey unsignedIntValue], unwrapped, stop); | |
| 3141 }]; | |
| 3142 } | |
| 3143 | |
| 3144 - (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary { | |
| 3145 if (otherDictionary) { | |
| 3146 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 3147 if (_autocreator) { | |
| 3148 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 3149 } | |
| 3150 } | |
| 3151 } | |
| 3152 | |
| 3153 - (void)setRawValue:(int32_t)value forKey:(uint32_t)key { | |
| 3154 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 3155 if (_autocreator) { | |
| 3156 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 3157 } | |
| 3158 } | |
| 3159 | |
| 3160 - (void)removeValueForKey:(uint32_t)aKey { | |
| 3161 [_dictionary removeObjectForKey:@(aKey)]; | |
| 3162 } | |
| 3163 | |
| 3164 - (void)removeAll { | |
| 3165 [_dictionary removeAllObjects]; | |
| 3166 } | |
| 3167 | |
| 3168 - (void)setValue:(int32_t)value forKey:(uint32_t)key { | |
| 3169 if (!_validationFunc(value)) { | |
| 3170 [NSException raise:NSInvalidArgumentException | |
| 3171 format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum
value (%d)", | |
| 3172 value]; | |
| 3173 } | |
| 3174 | |
| 3175 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 3176 if (_autocreator) { | |
| 3177 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 3178 } | |
| 3179 } | |
| 3180 | |
| 3181 @end | |
| 3182 | |
| 3183 #pragma mark - UInt32 -> Object | |
| 3184 | |
| 3185 @implementation GPBUInt32ObjectDictionary { | |
| 3186 @package | |
| 3187 NSMutableDictionary *_dictionary; | |
| 3188 } | |
| 3189 | |
| 3190 + (instancetype)dictionary { | |
| 3191 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 3192 } | |
| 3193 | |
| 3194 + (instancetype)dictionaryWithValue:(id)value | |
| 3195 forKey:(uint32_t)key { | |
| 3196 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3197 // on to get the type correct. | |
| 3198 return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithValues:&value | |
| 3199 forKeys:&key | |
| 3200 count:1] autoreleas
e]; | |
| 3201 } | |
| 3202 | |
| 3203 + (instancetype)dictionaryWithValues:(const id [])values | |
| 3204 forKeys:(const uint32_t [])keys | |
| 3205 count:(NSUInteger)count { | |
| 3206 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3207 // on to get the type correct. | |
| 3208 return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithValues:values | |
| 3209 forKeys:keys | |
| 3210 count:count] autore
lease]; | |
| 3211 } | |
| 3212 | |
| 3213 + (instancetype)dictionaryWithDictionary:(GPBUInt32ObjectDictionary *)dictionary
{ | |
| 3214 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3215 // on to get the type correct. | |
| 3216 return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | |
| 3217 } | |
| 3218 | |
| 3219 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 3220 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 3221 } | |
| 3222 | |
| 3223 - (instancetype)init { | |
| 3224 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3225 } | |
| 3226 | |
| 3227 - (instancetype)initWithValues:(const id [])values | |
| 3228 forKeys:(const uint32_t [])keys | |
| 3229 count:(NSUInteger)count { | |
| 3230 self = [super init]; | |
| 3231 if (self) { | |
| 3232 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 3233 if (count && values && keys) { | |
| 3234 for (NSUInteger i = 0; i < count; ++i) { | |
| 3235 [_dictionary setObject:values[i] forKey:@(keys[i])]; | |
| 3236 } | |
| 3237 } | |
| 3238 } | |
| 3239 return self; | |
| 3240 } | |
| 3241 | |
| 3242 - (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary { | |
| 3243 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3244 if (self) { | |
| 3245 if (dictionary) { | |
| 3246 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 3247 } | |
| 3248 } | |
| 3249 return self; | |
| 3250 } | |
| 3251 | |
| 3252 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 3253 #pragma unused(numItems) | |
| 3254 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3255 } | |
| 3256 | |
| 3257 - (void)dealloc { | |
| 3258 NSAssert(!_autocreator, | |
| 3259 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 3260 [self class], _autocreator); | |
| 3261 [_dictionary release]; | |
| 3262 [super dealloc]; | |
| 3263 } | |
| 3264 | |
| 3265 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 3266 return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self
]; | |
| 3267 } | |
| 3268 | |
| 3269 - (BOOL)isEqual:(GPBUInt32ObjectDictionary *)other { | |
| 3270 if (self == other) { | |
| 3271 return YES; | |
| 3272 } | |
| 3273 if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) { | |
| 3274 return NO; | |
| 3275 } | |
| 3276 return [_dictionary isEqual:other->_dictionary]; | |
| 3277 } | |
| 3278 | |
| 3279 - (NSUInteger)hash { | |
| 3280 return _dictionary.count; | |
| 3281 } | |
| 3282 | |
| 3283 - (NSString *)description { | |
| 3284 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 3285 } | |
| 3286 | |
| 3287 - (NSUInteger)count { | |
| 3288 return _dictionary.count; | |
| 3289 } | |
| 3290 | |
| 3291 - (void)enumerateKeysAndValuesUsingBlock: | |
| 3292 (void (^)(uint32_t key, id value, BOOL *stop))block { | |
| 3293 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3294 id aValue, | |
| 3295 BOOL *stop) { | |
| 3296 block([aKey unsignedIntValue], aValue, stop); | |
| 3297 }]; | |
| 3298 } | |
| 3299 | |
| 3300 - (BOOL)isInitialized { | |
| 3301 for (GPBMessage *msg in [_dictionary objectEnumerator]) { | |
| 3302 if (!msg.initialized) { | |
| 3303 return NO; | |
| 3304 } | |
| 3305 } | |
| 3306 return YES; | |
| 3307 } | |
| 3308 | |
| 3309 - (instancetype)deepCopyWithZone:(NSZone *)zone { | |
| 3310 GPBUInt32ObjectDictionary *newDict = | |
| 3311 [[GPBUInt32ObjectDictionary alloc] init]; | |
| 3312 [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey, | |
| 3313 GPBMessage *msg, | |
| 3314 BOOL *stop) { | |
| 3315 #pragma unused(stop) | |
| 3316 GPBMessage *copiedMsg = [msg copyWithZone:zone]; | |
| 3317 [newDict->_dictionary setObject:copiedMsg forKey:aKey]; | |
| 3318 [copiedMsg release]; | |
| 3319 }]; | |
| 3320 return newDict; | |
| 3321 } | |
| 3322 | |
| 3323 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 3324 NSUInteger count = _dictionary.count; | |
| 3325 if (count == 0) { | |
| 3326 return 0; | |
| 3327 } | |
| 3328 | |
| 3329 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 3330 GPBDataType keyDataType = field.mapKeyDataType; | |
| 3331 __block size_t result = 0; | |
| 3332 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3333 id aValue, | |
| 3334 BOOL *stop) { | |
| 3335 #pragma unused(stop) | |
| 3336 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 3337 msgSize += ComputeDictObjectFieldSize(aValue, kMapValueFieldNumber, valueDat
aType); | |
| 3338 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 3339 }]; | |
| 3340 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 3341 result += tagSize * count; | |
| 3342 return result; | |
| 3343 } | |
| 3344 | |
| 3345 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 3346 asField:(GPBFieldDescriptor *)field { | |
| 3347 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 3348 GPBDataType keyDataType = field.mapKeyDataType; | |
| 3349 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 3350 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3351 id aValue, | |
| 3352 BOOL *stop) { | |
| 3353 #pragma unused(stop) | |
| 3354 // Write the tag. | |
| 3355 [outputStream writeInt32NoTag:tag]; | |
| 3356 // Write the size of the message. | |
| 3357 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKey
FieldNumber, keyDataType); | |
| 3358 msgSize += ComputeDictObjectFieldSize(aValue, kMapValueFieldNumber, valueDat
aType); | |
| 3359 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 3360 // Write the fields. | |
| 3361 WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumb
er, keyDataType); | |
| 3362 WriteDictObjectField(outputStream, aValue, kMapValueFieldNumber, valueDataTy
pe); | |
| 3363 }]; | |
| 3364 } | |
| 3365 | |
| 3366 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 3367 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 3368 [_dictionary setObject:value->valueString forKey:@(key->valueUInt32)]; | |
| 3369 } | |
| 3370 | |
| 3371 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 3372 [self enumerateKeysAndValuesUsingBlock:^(uint32_t key, id value, BOOL *stop) { | |
| 3373 #pragma unused(stop) | |
| 3374 block([NSString stringWithFormat:@"%u", key], value); | |
| 3375 }]; | |
| 3376 } | |
| 3377 | |
| 3378 - (id)valueForKey:(uint32_t)key { | |
| 3379 id result = [_dictionary objectForKey:@(key)]; | |
| 3380 return result; | |
| 3381 } | |
| 3382 | |
| 3383 - (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary { | |
| 3384 if (otherDictionary) { | |
| 3385 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 3386 if (_autocreator) { | |
| 3387 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 3388 } | |
| 3389 } | |
| 3390 } | |
| 3391 | |
| 3392 - (void)setValue:(id)value forKey:(uint32_t)key { | |
| 3393 [_dictionary setObject:value forKey:@(key)]; | |
| 3394 if (_autocreator) { | |
| 3395 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 3396 } | |
| 3397 } | |
| 3398 | |
| 3399 - (void)removeValueForKey:(uint32_t)aKey { | |
| 3400 [_dictionary removeObjectForKey:@(aKey)]; | |
| 3401 } | |
| 3402 | |
| 3403 - (void)removeAll { | |
| 3404 [_dictionary removeAllObjects]; | |
| 3405 } | |
| 3406 | |
| 3407 @end | |
| 3408 | |
| 3409 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int32, int32_t) | |
| 3410 // This block of code is generated, do not edit it directly. | |
| 3411 | |
| 3412 #pragma mark - Int32 -> UInt32 | |
| 3413 | |
| 3414 @implementation GPBInt32UInt32Dictionary { | |
| 3415 @package | |
| 3416 NSMutableDictionary *_dictionary; | |
| 3417 } | |
| 3418 | |
| 3419 + (instancetype)dictionary { | |
| 3420 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 3421 } | |
| 3422 | |
| 3423 + (instancetype)dictionaryWithValue:(uint32_t)value | |
| 3424 forKey:(int32_t)key { | |
| 3425 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3426 // on to get the type correct. | |
| 3427 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithValues:&value | |
| 3428 forKeys:&key | |
| 3429 count:1] autorelease
]; | |
| 3430 } | |
| 3431 | |
| 3432 + (instancetype)dictionaryWithValues:(const uint32_t [])values | |
| 3433 forKeys:(const int32_t [])keys | |
| 3434 count:(NSUInteger)count { | |
| 3435 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3436 // on to get the type correct. | |
| 3437 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithValues:values | |
| 3438 forKeys:keys | |
| 3439 count:count] autorel
ease]; | |
| 3440 } | |
| 3441 | |
| 3442 + (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary
{ | |
| 3443 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3444 // on to get the type correct. | |
| 3445 return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 3446 } | |
| 3447 | |
| 3448 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 3449 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 3450 } | |
| 3451 | |
| 3452 - (instancetype)init { | |
| 3453 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3454 } | |
| 3455 | |
| 3456 - (instancetype)initWithValues:(const uint32_t [])values | |
| 3457 forKeys:(const int32_t [])keys | |
| 3458 count:(NSUInteger)count { | |
| 3459 self = [super init]; | |
| 3460 if (self) { | |
| 3461 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 3462 if (count && values && keys) { | |
| 3463 for (NSUInteger i = 0; i < count; ++i) { | |
| 3464 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 3465 } | |
| 3466 } | |
| 3467 } | |
| 3468 return self; | |
| 3469 } | |
| 3470 | |
| 3471 - (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary { | |
| 3472 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3473 if (self) { | |
| 3474 if (dictionary) { | |
| 3475 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 3476 } | |
| 3477 } | |
| 3478 return self; | |
| 3479 } | |
| 3480 | |
| 3481 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 3482 #pragma unused(numItems) | |
| 3483 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3484 } | |
| 3485 | |
| 3486 - (void)dealloc { | |
| 3487 NSAssert(!_autocreator, | |
| 3488 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 3489 [self class], _autocreator); | |
| 3490 [_dictionary release]; | |
| 3491 [super dealloc]; | |
| 3492 } | |
| 3493 | |
| 3494 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 3495 return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 3496 } | |
| 3497 | |
| 3498 - (BOOL)isEqual:(GPBInt32UInt32Dictionary *)other { | |
| 3499 if (self == other) { | |
| 3500 return YES; | |
| 3501 } | |
| 3502 if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) { | |
| 3503 return NO; | |
| 3504 } | |
| 3505 return [_dictionary isEqual:other->_dictionary]; | |
| 3506 } | |
| 3507 | |
| 3508 - (NSUInteger)hash { | |
| 3509 return _dictionary.count; | |
| 3510 } | |
| 3511 | |
| 3512 - (NSString *)description { | |
| 3513 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 3514 } | |
| 3515 | |
| 3516 - (NSUInteger)count { | |
| 3517 return _dictionary.count; | |
| 3518 } | |
| 3519 | |
| 3520 - (void)enumerateKeysAndValuesUsingBlock: | |
| 3521 (void (^)(int32_t key, uint32_t value, BOOL *stop))block { | |
| 3522 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3523 NSNumber *aValue, | |
| 3524 BOOL *stop) { | |
| 3525 block([aKey intValue], [aValue unsignedIntValue], stop); | |
| 3526 }]; | |
| 3527 } | |
| 3528 | |
| 3529 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 3530 NSUInteger count = _dictionary.count; | |
| 3531 if (count == 0) { | |
| 3532 return 0; | |
| 3533 } | |
| 3534 | |
| 3535 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 3536 GPBDataType keyDataType = field.mapKeyDataType; | |
| 3537 __block size_t result = 0; | |
| 3538 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3539 NSNumber *aValue, | |
| 3540 BOOL *stop) { | |
| 3541 #pragma unused(stop) | |
| 3542 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 3543 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFi
eldNumber, valueDataType); | |
| 3544 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 3545 }]; | |
| 3546 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 3547 result += tagSize * count; | |
| 3548 return result; | |
| 3549 } | |
| 3550 | |
| 3551 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 3552 asField:(GPBFieldDescriptor *)field { | |
| 3553 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 3554 GPBDataType keyDataType = field.mapKeyDataType; | |
| 3555 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 3556 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3557 NSNumber *aValue, | |
| 3558 BOOL *stop) { | |
| 3559 #pragma unused(stop) | |
| 3560 // Write the tag. | |
| 3561 [outputStream writeInt32NoTag:tag]; | |
| 3562 // Write the size of the message. | |
| 3563 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 3564 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFi
eldNumber, valueDataType); | |
| 3565 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 3566 // Write the fields. | |
| 3567 WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDa
taType); | |
| 3568 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | |
| 3569 }]; | |
| 3570 } | |
| 3571 | |
| 3572 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 3573 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 3574 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)]; | |
| 3575 } | |
| 3576 | |
| 3577 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 3578 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, uint32_t value, BOOL *st
op) { | |
| 3579 #pragma unused(stop) | |
| 3580 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%u", value]); | |
| 3581 }]; | |
| 3582 } | |
| 3583 | |
| 3584 - (BOOL)valueForKey:(int32_t)key value:(uint32_t *)value { | |
| 3585 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 3586 if (wrapped && value) { | |
| 3587 *value = [wrapped unsignedIntValue]; | |
| 3588 } | |
| 3589 return (wrapped != NULL); | |
| 3590 } | |
| 3591 | |
| 3592 - (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary { | |
| 3593 if (otherDictionary) { | |
| 3594 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 3595 if (_autocreator) { | |
| 3596 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 3597 } | |
| 3598 } | |
| 3599 } | |
| 3600 | |
| 3601 - (void)setValue:(uint32_t)value forKey:(int32_t)key { | |
| 3602 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 3603 if (_autocreator) { | |
| 3604 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 3605 } | |
| 3606 } | |
| 3607 | |
| 3608 - (void)removeValueForKey:(int32_t)aKey { | |
| 3609 [_dictionary removeObjectForKey:@(aKey)]; | |
| 3610 } | |
| 3611 | |
| 3612 - (void)removeAll { | |
| 3613 [_dictionary removeAllObjects]; | |
| 3614 } | |
| 3615 | |
| 3616 @end | |
| 3617 | |
| 3618 #pragma mark - Int32 -> Int32 | |
| 3619 | |
| 3620 @implementation GPBInt32Int32Dictionary { | |
| 3621 @package | |
| 3622 NSMutableDictionary *_dictionary; | |
| 3623 } | |
| 3624 | |
| 3625 + (instancetype)dictionary { | |
| 3626 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 3627 } | |
| 3628 | |
| 3629 + (instancetype)dictionaryWithValue:(int32_t)value | |
| 3630 forKey:(int32_t)key { | |
| 3631 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3632 // on to get the type correct. | |
| 3633 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithValues:&value | |
| 3634 forKeys:&key | |
| 3635 count:1] autorelease]
; | |
| 3636 } | |
| 3637 | |
| 3638 + (instancetype)dictionaryWithValues:(const int32_t [])values | |
| 3639 forKeys:(const int32_t [])keys | |
| 3640 count:(NSUInteger)count { | |
| 3641 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3642 // on to get the type correct. | |
| 3643 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithValues:values | |
| 3644 forKeys:keys | |
| 3645 count:count] autorele
ase]; | |
| 3646 } | |
| 3647 | |
| 3648 + (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary { | |
| 3649 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3650 // on to get the type correct. | |
| 3651 return [[(GPBInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 3652 } | |
| 3653 | |
| 3654 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 3655 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 3656 } | |
| 3657 | |
| 3658 - (instancetype)init { | |
| 3659 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3660 } | |
| 3661 | |
| 3662 - (instancetype)initWithValues:(const int32_t [])values | |
| 3663 forKeys:(const int32_t [])keys | |
| 3664 count:(NSUInteger)count { | |
| 3665 self = [super init]; | |
| 3666 if (self) { | |
| 3667 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 3668 if (count && values && keys) { | |
| 3669 for (NSUInteger i = 0; i < count; ++i) { | |
| 3670 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 3671 } | |
| 3672 } | |
| 3673 } | |
| 3674 return self; | |
| 3675 } | |
| 3676 | |
| 3677 - (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary { | |
| 3678 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3679 if (self) { | |
| 3680 if (dictionary) { | |
| 3681 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 3682 } | |
| 3683 } | |
| 3684 return self; | |
| 3685 } | |
| 3686 | |
| 3687 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 3688 #pragma unused(numItems) | |
| 3689 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3690 } | |
| 3691 | |
| 3692 - (void)dealloc { | |
| 3693 NSAssert(!_autocreator, | |
| 3694 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 3695 [self class], _autocreator); | |
| 3696 [_dictionary release]; | |
| 3697 [super dealloc]; | |
| 3698 } | |
| 3699 | |
| 3700 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 3701 return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]; | |
| 3702 } | |
| 3703 | |
| 3704 - (BOOL)isEqual:(GPBInt32Int32Dictionary *)other { | |
| 3705 if (self == other) { | |
| 3706 return YES; | |
| 3707 } | |
| 3708 if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) { | |
| 3709 return NO; | |
| 3710 } | |
| 3711 return [_dictionary isEqual:other->_dictionary]; | |
| 3712 } | |
| 3713 | |
| 3714 - (NSUInteger)hash { | |
| 3715 return _dictionary.count; | |
| 3716 } | |
| 3717 | |
| 3718 - (NSString *)description { | |
| 3719 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 3720 } | |
| 3721 | |
| 3722 - (NSUInteger)count { | |
| 3723 return _dictionary.count; | |
| 3724 } | |
| 3725 | |
| 3726 - (void)enumerateKeysAndValuesUsingBlock: | |
| 3727 (void (^)(int32_t key, int32_t value, BOOL *stop))block { | |
| 3728 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3729 NSNumber *aValue, | |
| 3730 BOOL *stop) { | |
| 3731 block([aKey intValue], [aValue intValue], stop); | |
| 3732 }]; | |
| 3733 } | |
| 3734 | |
| 3735 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 3736 NSUInteger count = _dictionary.count; | |
| 3737 if (count == 0) { | |
| 3738 return 0; | |
| 3739 } | |
| 3740 | |
| 3741 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 3742 GPBDataType keyDataType = field.mapKeyDataType; | |
| 3743 __block size_t result = 0; | |
| 3744 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3745 NSNumber *aValue, | |
| 3746 BOOL *stop) { | |
| 3747 #pragma unused(stop) | |
| 3748 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 3749 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber
, valueDataType); | |
| 3750 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 3751 }]; | |
| 3752 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 3753 result += tagSize * count; | |
| 3754 return result; | |
| 3755 } | |
| 3756 | |
| 3757 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 3758 asField:(GPBFieldDescriptor *)field { | |
| 3759 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 3760 GPBDataType keyDataType = field.mapKeyDataType; | |
| 3761 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 3762 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3763 NSNumber *aValue, | |
| 3764 BOOL *stop) { | |
| 3765 #pragma unused(stop) | |
| 3766 // Write the tag. | |
| 3767 [outputStream writeInt32NoTag:tag]; | |
| 3768 // Write the size of the message. | |
| 3769 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 3770 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber
, valueDataType); | |
| 3771 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 3772 // Write the fields. | |
| 3773 WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDa
taType); | |
| 3774 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | |
| 3775 }]; | |
| 3776 } | |
| 3777 | |
| 3778 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 3779 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 3780 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)]; | |
| 3781 } | |
| 3782 | |
| 3783 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 3784 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, int32_t value, BOOL *sto
p) { | |
| 3785 #pragma unused(stop) | |
| 3786 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%d", value]); | |
| 3787 }]; | |
| 3788 } | |
| 3789 | |
| 3790 - (BOOL)valueForKey:(int32_t)key value:(int32_t *)value { | |
| 3791 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 3792 if (wrapped && value) { | |
| 3793 *value = [wrapped intValue]; | |
| 3794 } | |
| 3795 return (wrapped != NULL); | |
| 3796 } | |
| 3797 | |
| 3798 - (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary { | |
| 3799 if (otherDictionary) { | |
| 3800 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 3801 if (_autocreator) { | |
| 3802 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 3803 } | |
| 3804 } | |
| 3805 } | |
| 3806 | |
| 3807 - (void)setValue:(int32_t)value forKey:(int32_t)key { | |
| 3808 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 3809 if (_autocreator) { | |
| 3810 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 3811 } | |
| 3812 } | |
| 3813 | |
| 3814 - (void)removeValueForKey:(int32_t)aKey { | |
| 3815 [_dictionary removeObjectForKey:@(aKey)]; | |
| 3816 } | |
| 3817 | |
| 3818 - (void)removeAll { | |
| 3819 [_dictionary removeAllObjects]; | |
| 3820 } | |
| 3821 | |
| 3822 @end | |
| 3823 | |
| 3824 #pragma mark - Int32 -> UInt64 | |
| 3825 | |
| 3826 @implementation GPBInt32UInt64Dictionary { | |
| 3827 @package | |
| 3828 NSMutableDictionary *_dictionary; | |
| 3829 } | |
| 3830 | |
| 3831 + (instancetype)dictionary { | |
| 3832 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 3833 } | |
| 3834 | |
| 3835 + (instancetype)dictionaryWithValue:(uint64_t)value | |
| 3836 forKey:(int32_t)key { | |
| 3837 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3838 // on to get the type correct. | |
| 3839 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithValues:&value | |
| 3840 forKeys:&key | |
| 3841 count:1] autorelease
]; | |
| 3842 } | |
| 3843 | |
| 3844 + (instancetype)dictionaryWithValues:(const uint64_t [])values | |
| 3845 forKeys:(const int32_t [])keys | |
| 3846 count:(NSUInteger)count { | |
| 3847 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3848 // on to get the type correct. | |
| 3849 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithValues:values | |
| 3850 forKeys:keys | |
| 3851 count:count] autorel
ease]; | |
| 3852 } | |
| 3853 | |
| 3854 + (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary
{ | |
| 3855 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 3856 // on to get the type correct. | |
| 3857 return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 3858 } | |
| 3859 | |
| 3860 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 3861 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 3862 } | |
| 3863 | |
| 3864 - (instancetype)init { | |
| 3865 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3866 } | |
| 3867 | |
| 3868 - (instancetype)initWithValues:(const uint64_t [])values | |
| 3869 forKeys:(const int32_t [])keys | |
| 3870 count:(NSUInteger)count { | |
| 3871 self = [super init]; | |
| 3872 if (self) { | |
| 3873 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 3874 if (count && values && keys) { | |
| 3875 for (NSUInteger i = 0; i < count; ++i) { | |
| 3876 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 3877 } | |
| 3878 } | |
| 3879 } | |
| 3880 return self; | |
| 3881 } | |
| 3882 | |
| 3883 - (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary { | |
| 3884 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3885 if (self) { | |
| 3886 if (dictionary) { | |
| 3887 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 3888 } | |
| 3889 } | |
| 3890 return self; | |
| 3891 } | |
| 3892 | |
| 3893 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 3894 #pragma unused(numItems) | |
| 3895 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 3896 } | |
| 3897 | |
| 3898 - (void)dealloc { | |
| 3899 NSAssert(!_autocreator, | |
| 3900 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 3901 [self class], _autocreator); | |
| 3902 [_dictionary release]; | |
| 3903 [super dealloc]; | |
| 3904 } | |
| 3905 | |
| 3906 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 3907 return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 3908 } | |
| 3909 | |
| 3910 - (BOOL)isEqual:(GPBInt32UInt64Dictionary *)other { | |
| 3911 if (self == other) { | |
| 3912 return YES; | |
| 3913 } | |
| 3914 if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) { | |
| 3915 return NO; | |
| 3916 } | |
| 3917 return [_dictionary isEqual:other->_dictionary]; | |
| 3918 } | |
| 3919 | |
| 3920 - (NSUInteger)hash { | |
| 3921 return _dictionary.count; | |
| 3922 } | |
| 3923 | |
| 3924 - (NSString *)description { | |
| 3925 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 3926 } | |
| 3927 | |
| 3928 - (NSUInteger)count { | |
| 3929 return _dictionary.count; | |
| 3930 } | |
| 3931 | |
| 3932 - (void)enumerateKeysAndValuesUsingBlock: | |
| 3933 (void (^)(int32_t key, uint64_t value, BOOL *stop))block { | |
| 3934 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3935 NSNumber *aValue, | |
| 3936 BOOL *stop) { | |
| 3937 block([aKey intValue], [aValue unsignedLongLongValue], stop); | |
| 3938 }]; | |
| 3939 } | |
| 3940 | |
| 3941 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 3942 NSUInteger count = _dictionary.count; | |
| 3943 if (count == 0) { | |
| 3944 return 0; | |
| 3945 } | |
| 3946 | |
| 3947 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 3948 GPBDataType keyDataType = field.mapKeyDataType; | |
| 3949 __block size_t result = 0; | |
| 3950 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3951 NSNumber *aValue, | |
| 3952 BOOL *stop) { | |
| 3953 #pragma unused(stop) | |
| 3954 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 3955 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapVa
lueFieldNumber, valueDataType); | |
| 3956 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 3957 }]; | |
| 3958 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 3959 result += tagSize * count; | |
| 3960 return result; | |
| 3961 } | |
| 3962 | |
| 3963 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 3964 asField:(GPBFieldDescriptor *)field { | |
| 3965 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 3966 GPBDataType keyDataType = field.mapKeyDataType; | |
| 3967 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 3968 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 3969 NSNumber *aValue, | |
| 3970 BOOL *stop) { | |
| 3971 #pragma unused(stop) | |
| 3972 // Write the tag. | |
| 3973 [outputStream writeInt32NoTag:tag]; | |
| 3974 // Write the size of the message. | |
| 3975 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 3976 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapVa
lueFieldNumber, valueDataType); | |
| 3977 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 3978 // Write the fields. | |
| 3979 WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDa
taType); | |
| 3980 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | |
| 3981 }]; | |
| 3982 } | |
| 3983 | |
| 3984 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 3985 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 3986 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)]; | |
| 3987 } | |
| 3988 | |
| 3989 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 3990 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, uint64_t value, BOOL *st
op) { | |
| 3991 #pragma unused(stop) | |
| 3992 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%llu", value]); | |
| 3993 }]; | |
| 3994 } | |
| 3995 | |
| 3996 - (BOOL)valueForKey:(int32_t)key value:(uint64_t *)value { | |
| 3997 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 3998 if (wrapped && value) { | |
| 3999 *value = [wrapped unsignedLongLongValue]; | |
| 4000 } | |
| 4001 return (wrapped != NULL); | |
| 4002 } | |
| 4003 | |
| 4004 - (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary { | |
| 4005 if (otherDictionary) { | |
| 4006 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 4007 if (_autocreator) { | |
| 4008 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 4009 } | |
| 4010 } | |
| 4011 } | |
| 4012 | |
| 4013 - (void)setValue:(uint64_t)value forKey:(int32_t)key { | |
| 4014 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 4015 if (_autocreator) { | |
| 4016 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 4017 } | |
| 4018 } | |
| 4019 | |
| 4020 - (void)removeValueForKey:(int32_t)aKey { | |
| 4021 [_dictionary removeObjectForKey:@(aKey)]; | |
| 4022 } | |
| 4023 | |
| 4024 - (void)removeAll { | |
| 4025 [_dictionary removeAllObjects]; | |
| 4026 } | |
| 4027 | |
| 4028 @end | |
| 4029 | |
| 4030 #pragma mark - Int32 -> Int64 | |
| 4031 | |
| 4032 @implementation GPBInt32Int64Dictionary { | |
| 4033 @package | |
| 4034 NSMutableDictionary *_dictionary; | |
| 4035 } | |
| 4036 | |
| 4037 + (instancetype)dictionary { | |
| 4038 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 4039 } | |
| 4040 | |
| 4041 + (instancetype)dictionaryWithValue:(int64_t)value | |
| 4042 forKey:(int32_t)key { | |
| 4043 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4044 // on to get the type correct. | |
| 4045 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithValues:&value | |
| 4046 forKeys:&key | |
| 4047 count:1] autorelease]
; | |
| 4048 } | |
| 4049 | |
| 4050 + (instancetype)dictionaryWithValues:(const int64_t [])values | |
| 4051 forKeys:(const int32_t [])keys | |
| 4052 count:(NSUInteger)count { | |
| 4053 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4054 // on to get the type correct. | |
| 4055 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithValues:values | |
| 4056 forKeys:keys | |
| 4057 count:count] autorele
ase]; | |
| 4058 } | |
| 4059 | |
| 4060 + (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary { | |
| 4061 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4062 // on to get the type correct. | |
| 4063 return [[(GPBInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 4064 } | |
| 4065 | |
| 4066 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 4067 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 4068 } | |
| 4069 | |
| 4070 - (instancetype)init { | |
| 4071 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4072 } | |
| 4073 | |
| 4074 - (instancetype)initWithValues:(const int64_t [])values | |
| 4075 forKeys:(const int32_t [])keys | |
| 4076 count:(NSUInteger)count { | |
| 4077 self = [super init]; | |
| 4078 if (self) { | |
| 4079 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 4080 if (count && values && keys) { | |
| 4081 for (NSUInteger i = 0; i < count; ++i) { | |
| 4082 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 4083 } | |
| 4084 } | |
| 4085 } | |
| 4086 return self; | |
| 4087 } | |
| 4088 | |
| 4089 - (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary { | |
| 4090 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4091 if (self) { | |
| 4092 if (dictionary) { | |
| 4093 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 4094 } | |
| 4095 } | |
| 4096 return self; | |
| 4097 } | |
| 4098 | |
| 4099 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 4100 #pragma unused(numItems) | |
| 4101 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4102 } | |
| 4103 | |
| 4104 - (void)dealloc { | |
| 4105 NSAssert(!_autocreator, | |
| 4106 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 4107 [self class], _autocreator); | |
| 4108 [_dictionary release]; | |
| 4109 [super dealloc]; | |
| 4110 } | |
| 4111 | |
| 4112 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 4113 return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]; | |
| 4114 } | |
| 4115 | |
| 4116 - (BOOL)isEqual:(GPBInt32Int64Dictionary *)other { | |
| 4117 if (self == other) { | |
| 4118 return YES; | |
| 4119 } | |
| 4120 if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) { | |
| 4121 return NO; | |
| 4122 } | |
| 4123 return [_dictionary isEqual:other->_dictionary]; | |
| 4124 } | |
| 4125 | |
| 4126 - (NSUInteger)hash { | |
| 4127 return _dictionary.count; | |
| 4128 } | |
| 4129 | |
| 4130 - (NSString *)description { | |
| 4131 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 4132 } | |
| 4133 | |
| 4134 - (NSUInteger)count { | |
| 4135 return _dictionary.count; | |
| 4136 } | |
| 4137 | |
| 4138 - (void)enumerateKeysAndValuesUsingBlock: | |
| 4139 (void (^)(int32_t key, int64_t value, BOOL *stop))block { | |
| 4140 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4141 NSNumber *aValue, | |
| 4142 BOOL *stop) { | |
| 4143 block([aKey intValue], [aValue longLongValue], stop); | |
| 4144 }]; | |
| 4145 } | |
| 4146 | |
| 4147 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 4148 NSUInteger count = _dictionary.count; | |
| 4149 if (count == 0) { | |
| 4150 return 0; | |
| 4151 } | |
| 4152 | |
| 4153 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 4154 GPBDataType keyDataType = field.mapKeyDataType; | |
| 4155 __block size_t result = 0; | |
| 4156 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4157 NSNumber *aValue, | |
| 4158 BOOL *stop) { | |
| 4159 #pragma unused(stop) | |
| 4160 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 4161 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldN
umber, valueDataType); | |
| 4162 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 4163 }]; | |
| 4164 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 4165 result += tagSize * count; | |
| 4166 return result; | |
| 4167 } | |
| 4168 | |
| 4169 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 4170 asField:(GPBFieldDescriptor *)field { | |
| 4171 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 4172 GPBDataType keyDataType = field.mapKeyDataType; | |
| 4173 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 4174 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4175 NSNumber *aValue, | |
| 4176 BOOL *stop) { | |
| 4177 #pragma unused(stop) | |
| 4178 // Write the tag. | |
| 4179 [outputStream writeInt32NoTag:tag]; | |
| 4180 // Write the size of the message. | |
| 4181 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 4182 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldN
umber, valueDataType); | |
| 4183 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 4184 // Write the fields. | |
| 4185 WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDa
taType); | |
| 4186 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | |
| 4187 }]; | |
| 4188 } | |
| 4189 | |
| 4190 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 4191 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 4192 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)]; | |
| 4193 } | |
| 4194 | |
| 4195 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 4196 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, int64_t value, BOOL *sto
p) { | |
| 4197 #pragma unused(stop) | |
| 4198 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%lld", value]); | |
| 4199 }]; | |
| 4200 } | |
| 4201 | |
| 4202 - (BOOL)valueForKey:(int32_t)key value:(int64_t *)value { | |
| 4203 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 4204 if (wrapped && value) { | |
| 4205 *value = [wrapped longLongValue]; | |
| 4206 } | |
| 4207 return (wrapped != NULL); | |
| 4208 } | |
| 4209 | |
| 4210 - (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary { | |
| 4211 if (otherDictionary) { | |
| 4212 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 4213 if (_autocreator) { | |
| 4214 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 4215 } | |
| 4216 } | |
| 4217 } | |
| 4218 | |
| 4219 - (void)setValue:(int64_t)value forKey:(int32_t)key { | |
| 4220 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 4221 if (_autocreator) { | |
| 4222 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 4223 } | |
| 4224 } | |
| 4225 | |
| 4226 - (void)removeValueForKey:(int32_t)aKey { | |
| 4227 [_dictionary removeObjectForKey:@(aKey)]; | |
| 4228 } | |
| 4229 | |
| 4230 - (void)removeAll { | |
| 4231 [_dictionary removeAllObjects]; | |
| 4232 } | |
| 4233 | |
| 4234 @end | |
| 4235 | |
| 4236 #pragma mark - Int32 -> Bool | |
| 4237 | |
| 4238 @implementation GPBInt32BoolDictionary { | |
| 4239 @package | |
| 4240 NSMutableDictionary *_dictionary; | |
| 4241 } | |
| 4242 | |
| 4243 + (instancetype)dictionary { | |
| 4244 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 4245 } | |
| 4246 | |
| 4247 + (instancetype)dictionaryWithValue:(BOOL)value | |
| 4248 forKey:(int32_t)key { | |
| 4249 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4250 // on to get the type correct. | |
| 4251 return [[(GPBInt32BoolDictionary*)[self alloc] initWithValues:&value | |
| 4252 forKeys:&key | |
| 4253 count:1] autorelease]; | |
| 4254 } | |
| 4255 | |
| 4256 + (instancetype)dictionaryWithValues:(const BOOL [])values | |
| 4257 forKeys:(const int32_t [])keys | |
| 4258 count:(NSUInteger)count { | |
| 4259 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4260 // on to get the type correct. | |
| 4261 return [[(GPBInt32BoolDictionary*)[self alloc] initWithValues:values | |
| 4262 forKeys:keys | |
| 4263 count:count] autorelea
se]; | |
| 4264 } | |
| 4265 | |
| 4266 + (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary { | |
| 4267 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4268 // on to get the type correct. | |
| 4269 return [[(GPBInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 4270 } | |
| 4271 | |
| 4272 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 4273 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 4274 } | |
| 4275 | |
| 4276 - (instancetype)init { | |
| 4277 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4278 } | |
| 4279 | |
| 4280 - (instancetype)initWithValues:(const BOOL [])values | |
| 4281 forKeys:(const int32_t [])keys | |
| 4282 count:(NSUInteger)count { | |
| 4283 self = [super init]; | |
| 4284 if (self) { | |
| 4285 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 4286 if (count && values && keys) { | |
| 4287 for (NSUInteger i = 0; i < count; ++i) { | |
| 4288 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 4289 } | |
| 4290 } | |
| 4291 } | |
| 4292 return self; | |
| 4293 } | |
| 4294 | |
| 4295 - (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary { | |
| 4296 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4297 if (self) { | |
| 4298 if (dictionary) { | |
| 4299 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 4300 } | |
| 4301 } | |
| 4302 return self; | |
| 4303 } | |
| 4304 | |
| 4305 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 4306 #pragma unused(numItems) | |
| 4307 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4308 } | |
| 4309 | |
| 4310 - (void)dealloc { | |
| 4311 NSAssert(!_autocreator, | |
| 4312 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 4313 [self class], _autocreator); | |
| 4314 [_dictionary release]; | |
| 4315 [super dealloc]; | |
| 4316 } | |
| 4317 | |
| 4318 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 4319 return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 4320 } | |
| 4321 | |
| 4322 - (BOOL)isEqual:(GPBInt32BoolDictionary *)other { | |
| 4323 if (self == other) { | |
| 4324 return YES; | |
| 4325 } | |
| 4326 if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) { | |
| 4327 return NO; | |
| 4328 } | |
| 4329 return [_dictionary isEqual:other->_dictionary]; | |
| 4330 } | |
| 4331 | |
| 4332 - (NSUInteger)hash { | |
| 4333 return _dictionary.count; | |
| 4334 } | |
| 4335 | |
| 4336 - (NSString *)description { | |
| 4337 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 4338 } | |
| 4339 | |
| 4340 - (NSUInteger)count { | |
| 4341 return _dictionary.count; | |
| 4342 } | |
| 4343 | |
| 4344 - (void)enumerateKeysAndValuesUsingBlock: | |
| 4345 (void (^)(int32_t key, BOOL value, BOOL *stop))block { | |
| 4346 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4347 NSNumber *aValue, | |
| 4348 BOOL *stop) { | |
| 4349 block([aKey intValue], [aValue boolValue], stop); | |
| 4350 }]; | |
| 4351 } | |
| 4352 | |
| 4353 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 4354 NSUInteger count = _dictionary.count; | |
| 4355 if (count == 0) { | |
| 4356 return 0; | |
| 4357 } | |
| 4358 | |
| 4359 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 4360 GPBDataType keyDataType = field.mapKeyDataType; | |
| 4361 __block size_t result = 0; | |
| 4362 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4363 NSNumber *aValue, | |
| 4364 BOOL *stop) { | |
| 4365 #pragma unused(stop) | |
| 4366 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 4367 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber
, valueDataType); | |
| 4368 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 4369 }]; | |
| 4370 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 4371 result += tagSize * count; | |
| 4372 return result; | |
| 4373 } | |
| 4374 | |
| 4375 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 4376 asField:(GPBFieldDescriptor *)field { | |
| 4377 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 4378 GPBDataType keyDataType = field.mapKeyDataType; | |
| 4379 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 4380 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4381 NSNumber *aValue, | |
| 4382 BOOL *stop) { | |
| 4383 #pragma unused(stop) | |
| 4384 // Write the tag. | |
| 4385 [outputStream writeInt32NoTag:tag]; | |
| 4386 // Write the size of the message. | |
| 4387 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 4388 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber
, valueDataType); | |
| 4389 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 4390 // Write the fields. | |
| 4391 WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDa
taType); | |
| 4392 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | |
| 4393 }]; | |
| 4394 } | |
| 4395 | |
| 4396 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 4397 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 4398 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)]; | |
| 4399 } | |
| 4400 | |
| 4401 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 4402 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, BOOL value, BOOL *stop)
{ | |
| 4403 #pragma unused(stop) | |
| 4404 block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false")
); | |
| 4405 }]; | |
| 4406 } | |
| 4407 | |
| 4408 - (BOOL)valueForKey:(int32_t)key value:(BOOL *)value { | |
| 4409 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 4410 if (wrapped && value) { | |
| 4411 *value = [wrapped boolValue]; | |
| 4412 } | |
| 4413 return (wrapped != NULL); | |
| 4414 } | |
| 4415 | |
| 4416 - (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary { | |
| 4417 if (otherDictionary) { | |
| 4418 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 4419 if (_autocreator) { | |
| 4420 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 4421 } | |
| 4422 } | |
| 4423 } | |
| 4424 | |
| 4425 - (void)setValue:(BOOL)value forKey:(int32_t)key { | |
| 4426 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 4427 if (_autocreator) { | |
| 4428 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 4429 } | |
| 4430 } | |
| 4431 | |
| 4432 - (void)removeValueForKey:(int32_t)aKey { | |
| 4433 [_dictionary removeObjectForKey:@(aKey)]; | |
| 4434 } | |
| 4435 | |
| 4436 - (void)removeAll { | |
| 4437 [_dictionary removeAllObjects]; | |
| 4438 } | |
| 4439 | |
| 4440 @end | |
| 4441 | |
| 4442 #pragma mark - Int32 -> Float | |
| 4443 | |
| 4444 @implementation GPBInt32FloatDictionary { | |
| 4445 @package | |
| 4446 NSMutableDictionary *_dictionary; | |
| 4447 } | |
| 4448 | |
| 4449 + (instancetype)dictionary { | |
| 4450 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 4451 } | |
| 4452 | |
| 4453 + (instancetype)dictionaryWithValue:(float)value | |
| 4454 forKey:(int32_t)key { | |
| 4455 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4456 // on to get the type correct. | |
| 4457 return [[(GPBInt32FloatDictionary*)[self alloc] initWithValues:&value | |
| 4458 forKeys:&key | |
| 4459 count:1] autorelease]
; | |
| 4460 } | |
| 4461 | |
| 4462 + (instancetype)dictionaryWithValues:(const float [])values | |
| 4463 forKeys:(const int32_t [])keys | |
| 4464 count:(NSUInteger)count { | |
| 4465 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4466 // on to get the type correct. | |
| 4467 return [[(GPBInt32FloatDictionary*)[self alloc] initWithValues:values | |
| 4468 forKeys:keys | |
| 4469 count:count] autorele
ase]; | |
| 4470 } | |
| 4471 | |
| 4472 + (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary { | |
| 4473 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4474 // on to get the type correct. | |
| 4475 return [[(GPBInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 4476 } | |
| 4477 | |
| 4478 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 4479 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 4480 } | |
| 4481 | |
| 4482 - (instancetype)init { | |
| 4483 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4484 } | |
| 4485 | |
| 4486 - (instancetype)initWithValues:(const float [])values | |
| 4487 forKeys:(const int32_t [])keys | |
| 4488 count:(NSUInteger)count { | |
| 4489 self = [super init]; | |
| 4490 if (self) { | |
| 4491 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 4492 if (count && values && keys) { | |
| 4493 for (NSUInteger i = 0; i < count; ++i) { | |
| 4494 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 4495 } | |
| 4496 } | |
| 4497 } | |
| 4498 return self; | |
| 4499 } | |
| 4500 | |
| 4501 - (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary { | |
| 4502 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4503 if (self) { | |
| 4504 if (dictionary) { | |
| 4505 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 4506 } | |
| 4507 } | |
| 4508 return self; | |
| 4509 } | |
| 4510 | |
| 4511 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 4512 #pragma unused(numItems) | |
| 4513 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4514 } | |
| 4515 | |
| 4516 - (void)dealloc { | |
| 4517 NSAssert(!_autocreator, | |
| 4518 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 4519 [self class], _autocreator); | |
| 4520 [_dictionary release]; | |
| 4521 [super dealloc]; | |
| 4522 } | |
| 4523 | |
| 4524 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 4525 return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 4526 } | |
| 4527 | |
| 4528 - (BOOL)isEqual:(GPBInt32FloatDictionary *)other { | |
| 4529 if (self == other) { | |
| 4530 return YES; | |
| 4531 } | |
| 4532 if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) { | |
| 4533 return NO; | |
| 4534 } | |
| 4535 return [_dictionary isEqual:other->_dictionary]; | |
| 4536 } | |
| 4537 | |
| 4538 - (NSUInteger)hash { | |
| 4539 return _dictionary.count; | |
| 4540 } | |
| 4541 | |
| 4542 - (NSString *)description { | |
| 4543 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 4544 } | |
| 4545 | |
| 4546 - (NSUInteger)count { | |
| 4547 return _dictionary.count; | |
| 4548 } | |
| 4549 | |
| 4550 - (void)enumerateKeysAndValuesUsingBlock: | |
| 4551 (void (^)(int32_t key, float value, BOOL *stop))block { | |
| 4552 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4553 NSNumber *aValue, | |
| 4554 BOOL *stop) { | |
| 4555 block([aKey intValue], [aValue floatValue], stop); | |
| 4556 }]; | |
| 4557 } | |
| 4558 | |
| 4559 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 4560 NSUInteger count = _dictionary.count; | |
| 4561 if (count == 0) { | |
| 4562 return 0; | |
| 4563 } | |
| 4564 | |
| 4565 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 4566 GPBDataType keyDataType = field.mapKeyDataType; | |
| 4567 __block size_t result = 0; | |
| 4568 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4569 NSNumber *aValue, | |
| 4570 BOOL *stop) { | |
| 4571 #pragma unused(stop) | |
| 4572 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 4573 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumb
er, valueDataType); | |
| 4574 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 4575 }]; | |
| 4576 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 4577 result += tagSize * count; | |
| 4578 return result; | |
| 4579 } | |
| 4580 | |
| 4581 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 4582 asField:(GPBFieldDescriptor *)field { | |
| 4583 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 4584 GPBDataType keyDataType = field.mapKeyDataType; | |
| 4585 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 4586 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4587 NSNumber *aValue, | |
| 4588 BOOL *stop) { | |
| 4589 #pragma unused(stop) | |
| 4590 // Write the tag. | |
| 4591 [outputStream writeInt32NoTag:tag]; | |
| 4592 // Write the size of the message. | |
| 4593 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 4594 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumb
er, valueDataType); | |
| 4595 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 4596 // Write the fields. | |
| 4597 WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDa
taType); | |
| 4598 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | |
| 4599 }]; | |
| 4600 } | |
| 4601 | |
| 4602 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 4603 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 4604 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)]; | |
| 4605 } | |
| 4606 | |
| 4607 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 4608 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, float value, BOOL *stop)
{ | |
| 4609 #pragma unused(stop) | |
| 4610 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%.*g", FLT_DIG, value]); | |
| 4611 }]; | |
| 4612 } | |
| 4613 | |
| 4614 - (BOOL)valueForKey:(int32_t)key value:(float *)value { | |
| 4615 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 4616 if (wrapped && value) { | |
| 4617 *value = [wrapped floatValue]; | |
| 4618 } | |
| 4619 return (wrapped != NULL); | |
| 4620 } | |
| 4621 | |
| 4622 - (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary { | |
| 4623 if (otherDictionary) { | |
| 4624 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 4625 if (_autocreator) { | |
| 4626 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 4627 } | |
| 4628 } | |
| 4629 } | |
| 4630 | |
| 4631 - (void)setValue:(float)value forKey:(int32_t)key { | |
| 4632 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 4633 if (_autocreator) { | |
| 4634 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 4635 } | |
| 4636 } | |
| 4637 | |
| 4638 - (void)removeValueForKey:(int32_t)aKey { | |
| 4639 [_dictionary removeObjectForKey:@(aKey)]; | |
| 4640 } | |
| 4641 | |
| 4642 - (void)removeAll { | |
| 4643 [_dictionary removeAllObjects]; | |
| 4644 } | |
| 4645 | |
| 4646 @end | |
| 4647 | |
| 4648 #pragma mark - Int32 -> Double | |
| 4649 | |
| 4650 @implementation GPBInt32DoubleDictionary { | |
| 4651 @package | |
| 4652 NSMutableDictionary *_dictionary; | |
| 4653 } | |
| 4654 | |
| 4655 + (instancetype)dictionary { | |
| 4656 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 4657 } | |
| 4658 | |
| 4659 + (instancetype)dictionaryWithValue:(double)value | |
| 4660 forKey:(int32_t)key { | |
| 4661 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4662 // on to get the type correct. | |
| 4663 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithValues:&value | |
| 4664 forKeys:&key | |
| 4665 count:1] autorelease
]; | |
| 4666 } | |
| 4667 | |
| 4668 + (instancetype)dictionaryWithValues:(const double [])values | |
| 4669 forKeys:(const int32_t [])keys | |
| 4670 count:(NSUInteger)count { | |
| 4671 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4672 // on to get the type correct. | |
| 4673 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithValues:values | |
| 4674 forKeys:keys | |
| 4675 count:count] autorel
ease]; | |
| 4676 } | |
| 4677 | |
| 4678 + (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary
{ | |
| 4679 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4680 // on to get the type correct. | |
| 4681 return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 4682 } | |
| 4683 | |
| 4684 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 4685 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 4686 } | |
| 4687 | |
| 4688 - (instancetype)init { | |
| 4689 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4690 } | |
| 4691 | |
| 4692 - (instancetype)initWithValues:(const double [])values | |
| 4693 forKeys:(const int32_t [])keys | |
| 4694 count:(NSUInteger)count { | |
| 4695 self = [super init]; | |
| 4696 if (self) { | |
| 4697 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 4698 if (count && values && keys) { | |
| 4699 for (NSUInteger i = 0; i < count; ++i) { | |
| 4700 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 4701 } | |
| 4702 } | |
| 4703 } | |
| 4704 return self; | |
| 4705 } | |
| 4706 | |
| 4707 - (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary { | |
| 4708 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4709 if (self) { | |
| 4710 if (dictionary) { | |
| 4711 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 4712 } | |
| 4713 } | |
| 4714 return self; | |
| 4715 } | |
| 4716 | |
| 4717 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 4718 #pragma unused(numItems) | |
| 4719 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 4720 } | |
| 4721 | |
| 4722 - (void)dealloc { | |
| 4723 NSAssert(!_autocreator, | |
| 4724 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 4725 [self class], _autocreator); | |
| 4726 [_dictionary release]; | |
| 4727 [super dealloc]; | |
| 4728 } | |
| 4729 | |
| 4730 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 4731 return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 4732 } | |
| 4733 | |
| 4734 - (BOOL)isEqual:(GPBInt32DoubleDictionary *)other { | |
| 4735 if (self == other) { | |
| 4736 return YES; | |
| 4737 } | |
| 4738 if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) { | |
| 4739 return NO; | |
| 4740 } | |
| 4741 return [_dictionary isEqual:other->_dictionary]; | |
| 4742 } | |
| 4743 | |
| 4744 - (NSUInteger)hash { | |
| 4745 return _dictionary.count; | |
| 4746 } | |
| 4747 | |
| 4748 - (NSString *)description { | |
| 4749 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 4750 } | |
| 4751 | |
| 4752 - (NSUInteger)count { | |
| 4753 return _dictionary.count; | |
| 4754 } | |
| 4755 | |
| 4756 - (void)enumerateKeysAndValuesUsingBlock: | |
| 4757 (void (^)(int32_t key, double value, BOOL *stop))block { | |
| 4758 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4759 NSNumber *aValue, | |
| 4760 BOOL *stop) { | |
| 4761 block([aKey intValue], [aValue doubleValue], stop); | |
| 4762 }]; | |
| 4763 } | |
| 4764 | |
| 4765 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 4766 NSUInteger count = _dictionary.count; | |
| 4767 if (count == 0) { | |
| 4768 return 0; | |
| 4769 } | |
| 4770 | |
| 4771 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 4772 GPBDataType keyDataType = field.mapKeyDataType; | |
| 4773 __block size_t result = 0; | |
| 4774 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4775 NSNumber *aValue, | |
| 4776 BOOL *stop) { | |
| 4777 #pragma unused(stop) | |
| 4778 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 4779 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNu
mber, valueDataType); | |
| 4780 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 4781 }]; | |
| 4782 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 4783 result += tagSize * count; | |
| 4784 return result; | |
| 4785 } | |
| 4786 | |
| 4787 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 4788 asField:(GPBFieldDescriptor *)field { | |
| 4789 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 4790 GPBDataType keyDataType = field.mapKeyDataType; | |
| 4791 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 4792 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4793 NSNumber *aValue, | |
| 4794 BOOL *stop) { | |
| 4795 #pragma unused(stop) | |
| 4796 // Write the tag. | |
| 4797 [outputStream writeInt32NoTag:tag]; | |
| 4798 // Write the size of the message. | |
| 4799 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 4800 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNu
mber, valueDataType); | |
| 4801 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 4802 // Write the fields. | |
| 4803 WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDa
taType); | |
| 4804 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | |
| 4805 }]; | |
| 4806 } | |
| 4807 | |
| 4808 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 4809 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 4810 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)]; | |
| 4811 } | |
| 4812 | |
| 4813 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 4814 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, double value, BOOL *stop
) { | |
| 4815 #pragma unused(stop) | |
| 4816 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@
"%.*lg", DBL_DIG, value]); | |
| 4817 }]; | |
| 4818 } | |
| 4819 | |
| 4820 - (BOOL)valueForKey:(int32_t)key value:(double *)value { | |
| 4821 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 4822 if (wrapped && value) { | |
| 4823 *value = [wrapped doubleValue]; | |
| 4824 } | |
| 4825 return (wrapped != NULL); | |
| 4826 } | |
| 4827 | |
| 4828 - (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary { | |
| 4829 if (otherDictionary) { | |
| 4830 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 4831 if (_autocreator) { | |
| 4832 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 4833 } | |
| 4834 } | |
| 4835 } | |
| 4836 | |
| 4837 - (void)setValue:(double)value forKey:(int32_t)key { | |
| 4838 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 4839 if (_autocreator) { | |
| 4840 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 4841 } | |
| 4842 } | |
| 4843 | |
| 4844 - (void)removeValueForKey:(int32_t)aKey { | |
| 4845 [_dictionary removeObjectForKey:@(aKey)]; | |
| 4846 } | |
| 4847 | |
| 4848 - (void)removeAll { | |
| 4849 [_dictionary removeAllObjects]; | |
| 4850 } | |
| 4851 | |
| 4852 @end | |
| 4853 | |
| 4854 #pragma mark - Int32 -> Enum | |
| 4855 | |
| 4856 @implementation GPBInt32EnumDictionary { | |
| 4857 @package | |
| 4858 NSMutableDictionary *_dictionary; | |
| 4859 GPBEnumValidationFunc _validationFunc; | |
| 4860 } | |
| 4861 | |
| 4862 @synthesize validationFunc = _validationFunc; | |
| 4863 | |
| 4864 + (instancetype)dictionary { | |
| 4865 return [[[self alloc] initWithValidationFunction:NULL | |
| 4866 rawValues:NULL | |
| 4867 forKeys:NULL | |
| 4868 count:0] autorelease]; | |
| 4869 } | |
| 4870 | |
| 4871 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 4872 return [[[self alloc] initWithValidationFunction:func | |
| 4873 rawValues:NULL | |
| 4874 forKeys:NULL | |
| 4875 count:0] autorelease]; | |
| 4876 } | |
| 4877 | |
| 4878 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 4879 rawValue:(int32_t)rawValue | |
| 4880 forKey:(int32_t)key { | |
| 4881 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4882 // on to get the type correct. | |
| 4883 return [[(GPBInt32EnumDictionary*)[self alloc] initWithValidationFunction:func | |
| 4884 rawValues:&raw
Value | |
| 4885 forKeys:&key | |
| 4886 count:1] a
utorelease]; | |
| 4887 } | |
| 4888 | |
| 4889 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 4890 rawValues:(const int32_t [])rawValues | |
| 4891 forKeys:(const int32_t [])keys | |
| 4892 count:(NSUInteger)count { | |
| 4893 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4894 // on to get the type correct. | |
| 4895 return [[(GPBInt32EnumDictionary*)[self alloc] initWithValidationFunction:func | |
| 4896 rawValues:rawV
alues | |
| 4897 forKeys:keys | |
| 4898 count:coun
t] autorelease]; | |
| 4899 } | |
| 4900 | |
| 4901 + (instancetype)dictionaryWithDictionary:(GPBInt32EnumDictionary *)dictionary { | |
| 4902 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 4903 // on to get the type correct. | |
| 4904 return [[(GPBInt32EnumDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 4905 } | |
| 4906 | |
| 4907 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 4908 capacity:(NSUInteger)numItems { | |
| 4909 return [[[self alloc] initWithValidationFunction:func capacity:numItems] autor
elease]; | |
| 4910 } | |
| 4911 | |
| 4912 - (instancetype)init { | |
| 4913 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count
:0]; | |
| 4914 } | |
| 4915 | |
| 4916 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 4917 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 4918 } | |
| 4919 | |
| 4920 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 4921 rawValues:(const int32_t [])rawValues | |
| 4922 forKeys:(const int32_t [])keys | |
| 4923 count:(NSUInteger)count { | |
| 4924 self = [super init]; | |
| 4925 if (self) { | |
| 4926 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 4927 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); | |
| 4928 if (count && rawValues && keys) { | |
| 4929 for (NSUInteger i = 0; i < count; ++i) { | |
| 4930 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])]; | |
| 4931 } | |
| 4932 } | |
| 4933 } | |
| 4934 return self; | |
| 4935 } | |
| 4936 | |
| 4937 - (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary { | |
| 4938 self = [self initWithValidationFunction:dictionary.validationFunc | |
| 4939 rawValues:NULL | |
| 4940 forKeys:NULL | |
| 4941 count:0]; | |
| 4942 if (self) { | |
| 4943 if (dictionary) { | |
| 4944 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 4945 } | |
| 4946 } | |
| 4947 return self; | |
| 4948 } | |
| 4949 | |
| 4950 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 4951 capacity:(NSUInteger)numItems { | |
| 4952 #pragma unused(numItems) | |
| 4953 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 4954 } | |
| 4955 | |
| 4956 - (void)dealloc { | |
| 4957 NSAssert(!_autocreator, | |
| 4958 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 4959 [self class], _autocreator); | |
| 4960 [_dictionary release]; | |
| 4961 [super dealloc]; | |
| 4962 } | |
| 4963 | |
| 4964 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 4965 return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 4966 } | |
| 4967 | |
| 4968 - (BOOL)isEqual:(GPBInt32EnumDictionary *)other { | |
| 4969 if (self == other) { | |
| 4970 return YES; | |
| 4971 } | |
| 4972 if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) { | |
| 4973 return NO; | |
| 4974 } | |
| 4975 return [_dictionary isEqual:other->_dictionary]; | |
| 4976 } | |
| 4977 | |
| 4978 - (NSUInteger)hash { | |
| 4979 return _dictionary.count; | |
| 4980 } | |
| 4981 | |
| 4982 - (NSString *)description { | |
| 4983 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 4984 } | |
| 4985 | |
| 4986 - (NSUInteger)count { | |
| 4987 return _dictionary.count; | |
| 4988 } | |
| 4989 | |
| 4990 - (void)enumerateKeysAndRawValuesUsingBlock: | |
| 4991 (void (^)(int32_t key, int32_t value, BOOL *stop))block { | |
| 4992 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 4993 NSNumber *aValue, | |
| 4994 BOOL *stop) { | |
| 4995 block([aKey intValue], [aValue intValue], stop); | |
| 4996 }]; | |
| 4997 } | |
| 4998 | |
| 4999 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 5000 NSUInteger count = _dictionary.count; | |
| 5001 if (count == 0) { | |
| 5002 return 0; | |
| 5003 } | |
| 5004 | |
| 5005 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 5006 GPBDataType keyDataType = field.mapKeyDataType; | |
| 5007 __block size_t result = 0; | |
| 5008 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5009 NSNumber *aValue, | |
| 5010 BOOL *stop) { | |
| 5011 #pragma unused(stop) | |
| 5012 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 5013 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber,
valueDataType); | |
| 5014 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 5015 }]; | |
| 5016 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 5017 result += tagSize * count; | |
| 5018 return result; | |
| 5019 } | |
| 5020 | |
| 5021 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 5022 asField:(GPBFieldDescriptor *)field { | |
| 5023 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 5024 GPBDataType keyDataType = field.mapKeyDataType; | |
| 5025 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 5026 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5027 NSNumber *aValue, | |
| 5028 BOOL *stop) { | |
| 5029 #pragma unused(stop) | |
| 5030 // Write the tag. | |
| 5031 [outputStream writeInt32NoTag:tag]; | |
| 5032 // Write the size of the message. | |
| 5033 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 5034 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber,
valueDataType); | |
| 5035 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 5036 // Write the fields. | |
| 5037 WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDa
taType); | |
| 5038 WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, va
lueDataType); | |
| 5039 }]; | |
| 5040 } | |
| 5041 | |
| 5042 - (NSData *)serializedDataForUnknownValue:(int32_t)value | |
| 5043 forKey:(GPBGenericValue *)key | |
| 5044 keyDataType:(GPBDataType)keyDataType { | |
| 5045 size_t msgSize = ComputeDictInt32FieldSize(key->valueInt32, kMapKeyFieldNumber
, keyDataType); | |
| 5046 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEn
um); | |
| 5047 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; | |
| 5048 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithDat
a:data]; | |
| 5049 WriteDictInt32Field(outputStream, key->valueInt32, kMapKeyFieldNumber, keyData
Type); | |
| 5050 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum)
; | |
| 5051 [outputStream release]; | |
| 5052 return data; | |
| 5053 } | |
| 5054 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 5055 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 5056 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)]; | |
| 5057 } | |
| 5058 | |
| 5059 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 5060 [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *
stop) { | |
| 5061 #pragma unused(stop) | |
| 5062 block([NSString stringWithFormat:@"%d", key], @(value)); | |
| 5063 }]; | |
| 5064 } | |
| 5065 | |
| 5066 - (BOOL)valueForKey:(int32_t)key value:(int32_t *)value { | |
| 5067 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 5068 if (wrapped && value) { | |
| 5069 int32_t result = [wrapped intValue]; | |
| 5070 if (!_validationFunc(result)) { | |
| 5071 result = kGPBUnrecognizedEnumeratorValue; | |
| 5072 } | |
| 5073 *value = result; | |
| 5074 } | |
| 5075 return (wrapped != NULL); | |
| 5076 } | |
| 5077 | |
| 5078 - (BOOL)valueForKey:(int32_t)key rawValue:(int32_t *)rawValue { | |
| 5079 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 5080 if (wrapped && rawValue) { | |
| 5081 *rawValue = [wrapped intValue]; | |
| 5082 } | |
| 5083 return (wrapped != NULL); | |
| 5084 } | |
| 5085 | |
| 5086 - (void)enumerateKeysAndValuesUsingBlock: | |
| 5087 (void (^)(int32_t key, int32_t value, BOOL *stop))block { | |
| 5088 GPBEnumValidationFunc func = _validationFunc; | |
| 5089 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5090 NSNumber *aValue, | |
| 5091 BOOL *stop) { | |
| 5092 int32_t unwrapped = [aValue intValue]; | |
| 5093 if (!func(unwrapped)) { | |
| 5094 unwrapped = kGPBUnrecognizedEnumeratorValue; | |
| 5095 } | |
| 5096 block([aKey intValue], unwrapped, stop); | |
| 5097 }]; | |
| 5098 } | |
| 5099 | |
| 5100 - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary { | |
| 5101 if (otherDictionary) { | |
| 5102 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 5103 if (_autocreator) { | |
| 5104 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 5105 } | |
| 5106 } | |
| 5107 } | |
| 5108 | |
| 5109 - (void)setRawValue:(int32_t)value forKey:(int32_t)key { | |
| 5110 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 5111 if (_autocreator) { | |
| 5112 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 5113 } | |
| 5114 } | |
| 5115 | |
| 5116 - (void)removeValueForKey:(int32_t)aKey { | |
| 5117 [_dictionary removeObjectForKey:@(aKey)]; | |
| 5118 } | |
| 5119 | |
| 5120 - (void)removeAll { | |
| 5121 [_dictionary removeAllObjects]; | |
| 5122 } | |
| 5123 | |
| 5124 - (void)setValue:(int32_t)value forKey:(int32_t)key { | |
| 5125 if (!_validationFunc(value)) { | |
| 5126 [NSException raise:NSInvalidArgumentException | |
| 5127 format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum
value (%d)", | |
| 5128 value]; | |
| 5129 } | |
| 5130 | |
| 5131 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 5132 if (_autocreator) { | |
| 5133 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 5134 } | |
| 5135 } | |
| 5136 | |
| 5137 @end | |
| 5138 | |
| 5139 #pragma mark - Int32 -> Object | |
| 5140 | |
| 5141 @implementation GPBInt32ObjectDictionary { | |
| 5142 @package | |
| 5143 NSMutableDictionary *_dictionary; | |
| 5144 } | |
| 5145 | |
| 5146 + (instancetype)dictionary { | |
| 5147 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 5148 } | |
| 5149 | |
| 5150 + (instancetype)dictionaryWithValue:(id)value | |
| 5151 forKey:(int32_t)key { | |
| 5152 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5153 // on to get the type correct. | |
| 5154 return [[(GPBInt32ObjectDictionary*)[self alloc] initWithValues:&value | |
| 5155 forKeys:&key | |
| 5156 count:1] autorelease
]; | |
| 5157 } | |
| 5158 | |
| 5159 + (instancetype)dictionaryWithValues:(const id [])values | |
| 5160 forKeys:(const int32_t [])keys | |
| 5161 count:(NSUInteger)count { | |
| 5162 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5163 // on to get the type correct. | |
| 5164 return [[(GPBInt32ObjectDictionary*)[self alloc] initWithValues:values | |
| 5165 forKeys:keys | |
| 5166 count:count] autorel
ease]; | |
| 5167 } | |
| 5168 | |
| 5169 + (instancetype)dictionaryWithDictionary:(GPBInt32ObjectDictionary *)dictionary
{ | |
| 5170 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5171 // on to get the type correct. | |
| 5172 return [[(GPBInt32ObjectDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 5173 } | |
| 5174 | |
| 5175 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 5176 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 5177 } | |
| 5178 | |
| 5179 - (instancetype)init { | |
| 5180 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5181 } | |
| 5182 | |
| 5183 - (instancetype)initWithValues:(const id [])values | |
| 5184 forKeys:(const int32_t [])keys | |
| 5185 count:(NSUInteger)count { | |
| 5186 self = [super init]; | |
| 5187 if (self) { | |
| 5188 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 5189 if (count && values && keys) { | |
| 5190 for (NSUInteger i = 0; i < count; ++i) { | |
| 5191 [_dictionary setObject:values[i] forKey:@(keys[i])]; | |
| 5192 } | |
| 5193 } | |
| 5194 } | |
| 5195 return self; | |
| 5196 } | |
| 5197 | |
| 5198 - (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary { | |
| 5199 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5200 if (self) { | |
| 5201 if (dictionary) { | |
| 5202 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 5203 } | |
| 5204 } | |
| 5205 return self; | |
| 5206 } | |
| 5207 | |
| 5208 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 5209 #pragma unused(numItems) | |
| 5210 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5211 } | |
| 5212 | |
| 5213 - (void)dealloc { | |
| 5214 NSAssert(!_autocreator, | |
| 5215 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 5216 [self class], _autocreator); | |
| 5217 [_dictionary release]; | |
| 5218 [super dealloc]; | |
| 5219 } | |
| 5220 | |
| 5221 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 5222 return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 5223 } | |
| 5224 | |
| 5225 - (BOOL)isEqual:(GPBInt32ObjectDictionary *)other { | |
| 5226 if (self == other) { | |
| 5227 return YES; | |
| 5228 } | |
| 5229 if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) { | |
| 5230 return NO; | |
| 5231 } | |
| 5232 return [_dictionary isEqual:other->_dictionary]; | |
| 5233 } | |
| 5234 | |
| 5235 - (NSUInteger)hash { | |
| 5236 return _dictionary.count; | |
| 5237 } | |
| 5238 | |
| 5239 - (NSString *)description { | |
| 5240 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 5241 } | |
| 5242 | |
| 5243 - (NSUInteger)count { | |
| 5244 return _dictionary.count; | |
| 5245 } | |
| 5246 | |
| 5247 - (void)enumerateKeysAndValuesUsingBlock: | |
| 5248 (void (^)(int32_t key, id value, BOOL *stop))block { | |
| 5249 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5250 id aValue, | |
| 5251 BOOL *stop) { | |
| 5252 block([aKey intValue], aValue, stop); | |
| 5253 }]; | |
| 5254 } | |
| 5255 | |
| 5256 - (BOOL)isInitialized { | |
| 5257 for (GPBMessage *msg in [_dictionary objectEnumerator]) { | |
| 5258 if (!msg.initialized) { | |
| 5259 return NO; | |
| 5260 } | |
| 5261 } | |
| 5262 return YES; | |
| 5263 } | |
| 5264 | |
| 5265 - (instancetype)deepCopyWithZone:(NSZone *)zone { | |
| 5266 GPBInt32ObjectDictionary *newDict = | |
| 5267 [[GPBInt32ObjectDictionary alloc] init]; | |
| 5268 [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey, | |
| 5269 GPBMessage *msg, | |
| 5270 BOOL *stop) { | |
| 5271 #pragma unused(stop) | |
| 5272 GPBMessage *copiedMsg = [msg copyWithZone:zone]; | |
| 5273 [newDict->_dictionary setObject:copiedMsg forKey:aKey]; | |
| 5274 [copiedMsg release]; | |
| 5275 }]; | |
| 5276 return newDict; | |
| 5277 } | |
| 5278 | |
| 5279 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 5280 NSUInteger count = _dictionary.count; | |
| 5281 if (count == 0) { | |
| 5282 return 0; | |
| 5283 } | |
| 5284 | |
| 5285 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 5286 GPBDataType keyDataType = field.mapKeyDataType; | |
| 5287 __block size_t result = 0; | |
| 5288 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5289 id aValue, | |
| 5290 BOOL *stop) { | |
| 5291 #pragma unused(stop) | |
| 5292 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 5293 msgSize += ComputeDictObjectFieldSize(aValue, kMapValueFieldNumber, valueDat
aType); | |
| 5294 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 5295 }]; | |
| 5296 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 5297 result += tagSize * count; | |
| 5298 return result; | |
| 5299 } | |
| 5300 | |
| 5301 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 5302 asField:(GPBFieldDescriptor *)field { | |
| 5303 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 5304 GPBDataType keyDataType = field.mapKeyDataType; | |
| 5305 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 5306 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5307 id aValue, | |
| 5308 BOOL *stop) { | |
| 5309 #pragma unused(stop) | |
| 5310 // Write the tag. | |
| 5311 [outputStream writeInt32NoTag:tag]; | |
| 5312 // Write the size of the message. | |
| 5313 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumb
er, keyDataType); | |
| 5314 msgSize += ComputeDictObjectFieldSize(aValue, kMapValueFieldNumber, valueDat
aType); | |
| 5315 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 5316 // Write the fields. | |
| 5317 WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDa
taType); | |
| 5318 WriteDictObjectField(outputStream, aValue, kMapValueFieldNumber, valueDataTy
pe); | |
| 5319 }]; | |
| 5320 } | |
| 5321 | |
| 5322 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 5323 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 5324 [_dictionary setObject:value->valueString forKey:@(key->valueInt32)]; | |
| 5325 } | |
| 5326 | |
| 5327 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 5328 [self enumerateKeysAndValuesUsingBlock:^(int32_t key, id value, BOOL *stop) { | |
| 5329 #pragma unused(stop) | |
| 5330 block([NSString stringWithFormat:@"%d", key], value); | |
| 5331 }]; | |
| 5332 } | |
| 5333 | |
| 5334 - (id)valueForKey:(int32_t)key { | |
| 5335 id result = [_dictionary objectForKey:@(key)]; | |
| 5336 return result; | |
| 5337 } | |
| 5338 | |
| 5339 - (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary { | |
| 5340 if (otherDictionary) { | |
| 5341 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 5342 if (_autocreator) { | |
| 5343 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 5344 } | |
| 5345 } | |
| 5346 } | |
| 5347 | |
| 5348 - (void)setValue:(id)value forKey:(int32_t)key { | |
| 5349 [_dictionary setObject:value forKey:@(key)]; | |
| 5350 if (_autocreator) { | |
| 5351 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 5352 } | |
| 5353 } | |
| 5354 | |
| 5355 - (void)removeValueForKey:(int32_t)aKey { | |
| 5356 [_dictionary removeObjectForKey:@(aKey)]; | |
| 5357 } | |
| 5358 | |
| 5359 - (void)removeAll { | |
| 5360 [_dictionary removeAllObjects]; | |
| 5361 } | |
| 5362 | |
| 5363 @end | |
| 5364 | |
| 5365 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt64, uint64_t) | |
| 5366 // This block of code is generated, do not edit it directly. | |
| 5367 | |
| 5368 #pragma mark - UInt64 -> UInt32 | |
| 5369 | |
| 5370 @implementation GPBUInt64UInt32Dictionary { | |
| 5371 @package | |
| 5372 NSMutableDictionary *_dictionary; | |
| 5373 } | |
| 5374 | |
| 5375 + (instancetype)dictionary { | |
| 5376 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 5377 } | |
| 5378 | |
| 5379 + (instancetype)dictionaryWithValue:(uint32_t)value | |
| 5380 forKey:(uint64_t)key { | |
| 5381 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5382 // on to get the type correct. | |
| 5383 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithValues:&value | |
| 5384 forKeys:&key | |
| 5385 count:1] autoreleas
e]; | |
| 5386 } | |
| 5387 | |
| 5388 + (instancetype)dictionaryWithValues:(const uint32_t [])values | |
| 5389 forKeys:(const uint64_t [])keys | |
| 5390 count:(NSUInteger)count { | |
| 5391 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5392 // on to get the type correct. | |
| 5393 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithValues:values | |
| 5394 forKeys:keys | |
| 5395 count:count] autore
lease]; | |
| 5396 } | |
| 5397 | |
| 5398 + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary
{ | |
| 5399 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5400 // on to get the type correct. | |
| 5401 return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | |
| 5402 } | |
| 5403 | |
| 5404 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 5405 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 5406 } | |
| 5407 | |
| 5408 - (instancetype)init { | |
| 5409 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5410 } | |
| 5411 | |
| 5412 - (instancetype)initWithValues:(const uint32_t [])values | |
| 5413 forKeys:(const uint64_t [])keys | |
| 5414 count:(NSUInteger)count { | |
| 5415 self = [super init]; | |
| 5416 if (self) { | |
| 5417 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 5418 if (count && values && keys) { | |
| 5419 for (NSUInteger i = 0; i < count; ++i) { | |
| 5420 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 5421 } | |
| 5422 } | |
| 5423 } | |
| 5424 return self; | |
| 5425 } | |
| 5426 | |
| 5427 - (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary { | |
| 5428 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5429 if (self) { | |
| 5430 if (dictionary) { | |
| 5431 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 5432 } | |
| 5433 } | |
| 5434 return self; | |
| 5435 } | |
| 5436 | |
| 5437 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 5438 #pragma unused(numItems) | |
| 5439 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5440 } | |
| 5441 | |
| 5442 - (void)dealloc { | |
| 5443 NSAssert(!_autocreator, | |
| 5444 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 5445 [self class], _autocreator); | |
| 5446 [_dictionary release]; | |
| 5447 [super dealloc]; | |
| 5448 } | |
| 5449 | |
| 5450 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 5451 return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; | |
| 5452 } | |
| 5453 | |
| 5454 - (BOOL)isEqual:(GPBUInt64UInt32Dictionary *)other { | |
| 5455 if (self == other) { | |
| 5456 return YES; | |
| 5457 } | |
| 5458 if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) { | |
| 5459 return NO; | |
| 5460 } | |
| 5461 return [_dictionary isEqual:other->_dictionary]; | |
| 5462 } | |
| 5463 | |
| 5464 - (NSUInteger)hash { | |
| 5465 return _dictionary.count; | |
| 5466 } | |
| 5467 | |
| 5468 - (NSString *)description { | |
| 5469 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 5470 } | |
| 5471 | |
| 5472 - (NSUInteger)count { | |
| 5473 return _dictionary.count; | |
| 5474 } | |
| 5475 | |
| 5476 - (void)enumerateKeysAndValuesUsingBlock: | |
| 5477 (void (^)(uint64_t key, uint32_t value, BOOL *stop))block { | |
| 5478 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5479 NSNumber *aValue, | |
| 5480 BOOL *stop) { | |
| 5481 block([aKey unsignedLongLongValue], [aValue unsignedIntValue], stop); | |
| 5482 }]; | |
| 5483 } | |
| 5484 | |
| 5485 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 5486 NSUInteger count = _dictionary.count; | |
| 5487 if (count == 0) { | |
| 5488 return 0; | |
| 5489 } | |
| 5490 | |
| 5491 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 5492 GPBDataType keyDataType = field.mapKeyDataType; | |
| 5493 __block size_t result = 0; | |
| 5494 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5495 NSNumber *aValue, | |
| 5496 BOOL *stop) { | |
| 5497 #pragma unused(stop) | |
| 5498 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 5499 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFi
eldNumber, valueDataType); | |
| 5500 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 5501 }]; | |
| 5502 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 5503 result += tagSize * count; | |
| 5504 return result; | |
| 5505 } | |
| 5506 | |
| 5507 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 5508 asField:(GPBFieldDescriptor *)field { | |
| 5509 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 5510 GPBDataType keyDataType = field.mapKeyDataType; | |
| 5511 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 5512 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5513 NSNumber *aValue, | |
| 5514 BOOL *stop) { | |
| 5515 #pragma unused(stop) | |
| 5516 // Write the tag. | |
| 5517 [outputStream writeInt32NoTag:tag]; | |
| 5518 // Write the size of the message. | |
| 5519 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 5520 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFi
eldNumber, valueDataType); | |
| 5521 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 5522 // Write the fields. | |
| 5523 WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 5524 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | |
| 5525 }]; | |
| 5526 } | |
| 5527 | |
| 5528 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 5529 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 5530 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)]; | |
| 5531 } | |
| 5532 | |
| 5533 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 5534 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, uint32_t value, BOOL *s
top) { | |
| 5535 #pragma unused(stop) | |
| 5536 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%u", value]); | |
| 5537 }]; | |
| 5538 } | |
| 5539 | |
| 5540 - (BOOL)valueForKey:(uint64_t)key value:(uint32_t *)value { | |
| 5541 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 5542 if (wrapped && value) { | |
| 5543 *value = [wrapped unsignedIntValue]; | |
| 5544 } | |
| 5545 return (wrapped != NULL); | |
| 5546 } | |
| 5547 | |
| 5548 - (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary { | |
| 5549 if (otherDictionary) { | |
| 5550 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 5551 if (_autocreator) { | |
| 5552 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 5553 } | |
| 5554 } | |
| 5555 } | |
| 5556 | |
| 5557 - (void)setValue:(uint32_t)value forKey:(uint64_t)key { | |
| 5558 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 5559 if (_autocreator) { | |
| 5560 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 5561 } | |
| 5562 } | |
| 5563 | |
| 5564 - (void)removeValueForKey:(uint64_t)aKey { | |
| 5565 [_dictionary removeObjectForKey:@(aKey)]; | |
| 5566 } | |
| 5567 | |
| 5568 - (void)removeAll { | |
| 5569 [_dictionary removeAllObjects]; | |
| 5570 } | |
| 5571 | |
| 5572 @end | |
| 5573 | |
| 5574 #pragma mark - UInt64 -> Int32 | |
| 5575 | |
| 5576 @implementation GPBUInt64Int32Dictionary { | |
| 5577 @package | |
| 5578 NSMutableDictionary *_dictionary; | |
| 5579 } | |
| 5580 | |
| 5581 + (instancetype)dictionary { | |
| 5582 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 5583 } | |
| 5584 | |
| 5585 + (instancetype)dictionaryWithValue:(int32_t)value | |
| 5586 forKey:(uint64_t)key { | |
| 5587 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5588 // on to get the type correct. | |
| 5589 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithValues:&value | |
| 5590 forKeys:&key | |
| 5591 count:1] autorelease
]; | |
| 5592 } | |
| 5593 | |
| 5594 + (instancetype)dictionaryWithValues:(const int32_t [])values | |
| 5595 forKeys:(const uint64_t [])keys | |
| 5596 count:(NSUInteger)count { | |
| 5597 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5598 // on to get the type correct. | |
| 5599 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithValues:values | |
| 5600 forKeys:keys | |
| 5601 count:count] autorel
ease]; | |
| 5602 } | |
| 5603 | |
| 5604 + (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary
{ | |
| 5605 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5606 // on to get the type correct. | |
| 5607 return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 5608 } | |
| 5609 | |
| 5610 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 5611 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 5612 } | |
| 5613 | |
| 5614 - (instancetype)init { | |
| 5615 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5616 } | |
| 5617 | |
| 5618 - (instancetype)initWithValues:(const int32_t [])values | |
| 5619 forKeys:(const uint64_t [])keys | |
| 5620 count:(NSUInteger)count { | |
| 5621 self = [super init]; | |
| 5622 if (self) { | |
| 5623 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 5624 if (count && values && keys) { | |
| 5625 for (NSUInteger i = 0; i < count; ++i) { | |
| 5626 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 5627 } | |
| 5628 } | |
| 5629 } | |
| 5630 return self; | |
| 5631 } | |
| 5632 | |
| 5633 - (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary { | |
| 5634 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5635 if (self) { | |
| 5636 if (dictionary) { | |
| 5637 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 5638 } | |
| 5639 } | |
| 5640 return self; | |
| 5641 } | |
| 5642 | |
| 5643 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 5644 #pragma unused(numItems) | |
| 5645 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5646 } | |
| 5647 | |
| 5648 - (void)dealloc { | |
| 5649 NSAssert(!_autocreator, | |
| 5650 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 5651 [self class], _autocreator); | |
| 5652 [_dictionary release]; | |
| 5653 [super dealloc]; | |
| 5654 } | |
| 5655 | |
| 5656 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 5657 return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 5658 } | |
| 5659 | |
| 5660 - (BOOL)isEqual:(GPBUInt64Int32Dictionary *)other { | |
| 5661 if (self == other) { | |
| 5662 return YES; | |
| 5663 } | |
| 5664 if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) { | |
| 5665 return NO; | |
| 5666 } | |
| 5667 return [_dictionary isEqual:other->_dictionary]; | |
| 5668 } | |
| 5669 | |
| 5670 - (NSUInteger)hash { | |
| 5671 return _dictionary.count; | |
| 5672 } | |
| 5673 | |
| 5674 - (NSString *)description { | |
| 5675 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 5676 } | |
| 5677 | |
| 5678 - (NSUInteger)count { | |
| 5679 return _dictionary.count; | |
| 5680 } | |
| 5681 | |
| 5682 - (void)enumerateKeysAndValuesUsingBlock: | |
| 5683 (void (^)(uint64_t key, int32_t value, BOOL *stop))block { | |
| 5684 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5685 NSNumber *aValue, | |
| 5686 BOOL *stop) { | |
| 5687 block([aKey unsignedLongLongValue], [aValue intValue], stop); | |
| 5688 }]; | |
| 5689 } | |
| 5690 | |
| 5691 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 5692 NSUInteger count = _dictionary.count; | |
| 5693 if (count == 0) { | |
| 5694 return 0; | |
| 5695 } | |
| 5696 | |
| 5697 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 5698 GPBDataType keyDataType = field.mapKeyDataType; | |
| 5699 __block size_t result = 0; | |
| 5700 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5701 NSNumber *aValue, | |
| 5702 BOOL *stop) { | |
| 5703 #pragma unused(stop) | |
| 5704 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 5705 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber
, valueDataType); | |
| 5706 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 5707 }]; | |
| 5708 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 5709 result += tagSize * count; | |
| 5710 return result; | |
| 5711 } | |
| 5712 | |
| 5713 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 5714 asField:(GPBFieldDescriptor *)field { | |
| 5715 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 5716 GPBDataType keyDataType = field.mapKeyDataType; | |
| 5717 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 5718 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5719 NSNumber *aValue, | |
| 5720 BOOL *stop) { | |
| 5721 #pragma unused(stop) | |
| 5722 // Write the tag. | |
| 5723 [outputStream writeInt32NoTag:tag]; | |
| 5724 // Write the size of the message. | |
| 5725 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 5726 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber
, valueDataType); | |
| 5727 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 5728 // Write the fields. | |
| 5729 WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 5730 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | |
| 5731 }]; | |
| 5732 } | |
| 5733 | |
| 5734 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 5735 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 5736 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)]; | |
| 5737 } | |
| 5738 | |
| 5739 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 5740 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, int32_t value, BOOL *st
op) { | |
| 5741 #pragma unused(stop) | |
| 5742 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%d", value]); | |
| 5743 }]; | |
| 5744 } | |
| 5745 | |
| 5746 - (BOOL)valueForKey:(uint64_t)key value:(int32_t *)value { | |
| 5747 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 5748 if (wrapped && value) { | |
| 5749 *value = [wrapped intValue]; | |
| 5750 } | |
| 5751 return (wrapped != NULL); | |
| 5752 } | |
| 5753 | |
| 5754 - (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary { | |
| 5755 if (otherDictionary) { | |
| 5756 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 5757 if (_autocreator) { | |
| 5758 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 5759 } | |
| 5760 } | |
| 5761 } | |
| 5762 | |
| 5763 - (void)setValue:(int32_t)value forKey:(uint64_t)key { | |
| 5764 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 5765 if (_autocreator) { | |
| 5766 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 5767 } | |
| 5768 } | |
| 5769 | |
| 5770 - (void)removeValueForKey:(uint64_t)aKey { | |
| 5771 [_dictionary removeObjectForKey:@(aKey)]; | |
| 5772 } | |
| 5773 | |
| 5774 - (void)removeAll { | |
| 5775 [_dictionary removeAllObjects]; | |
| 5776 } | |
| 5777 | |
| 5778 @end | |
| 5779 | |
| 5780 #pragma mark - UInt64 -> UInt64 | |
| 5781 | |
| 5782 @implementation GPBUInt64UInt64Dictionary { | |
| 5783 @package | |
| 5784 NSMutableDictionary *_dictionary; | |
| 5785 } | |
| 5786 | |
| 5787 + (instancetype)dictionary { | |
| 5788 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 5789 } | |
| 5790 | |
| 5791 + (instancetype)dictionaryWithValue:(uint64_t)value | |
| 5792 forKey:(uint64_t)key { | |
| 5793 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5794 // on to get the type correct. | |
| 5795 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithValues:&value | |
| 5796 forKeys:&key | |
| 5797 count:1] autoreleas
e]; | |
| 5798 } | |
| 5799 | |
| 5800 + (instancetype)dictionaryWithValues:(const uint64_t [])values | |
| 5801 forKeys:(const uint64_t [])keys | |
| 5802 count:(NSUInteger)count { | |
| 5803 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5804 // on to get the type correct. | |
| 5805 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithValues:values | |
| 5806 forKeys:keys | |
| 5807 count:count] autore
lease]; | |
| 5808 } | |
| 5809 | |
| 5810 + (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary
{ | |
| 5811 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 5812 // on to get the type correct. | |
| 5813 return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | |
| 5814 } | |
| 5815 | |
| 5816 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 5817 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 5818 } | |
| 5819 | |
| 5820 - (instancetype)init { | |
| 5821 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5822 } | |
| 5823 | |
| 5824 - (instancetype)initWithValues:(const uint64_t [])values | |
| 5825 forKeys:(const uint64_t [])keys | |
| 5826 count:(NSUInteger)count { | |
| 5827 self = [super init]; | |
| 5828 if (self) { | |
| 5829 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 5830 if (count && values && keys) { | |
| 5831 for (NSUInteger i = 0; i < count; ++i) { | |
| 5832 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 5833 } | |
| 5834 } | |
| 5835 } | |
| 5836 return self; | |
| 5837 } | |
| 5838 | |
| 5839 - (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary { | |
| 5840 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5841 if (self) { | |
| 5842 if (dictionary) { | |
| 5843 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 5844 } | |
| 5845 } | |
| 5846 return self; | |
| 5847 } | |
| 5848 | |
| 5849 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 5850 #pragma unused(numItems) | |
| 5851 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 5852 } | |
| 5853 | |
| 5854 - (void)dealloc { | |
| 5855 NSAssert(!_autocreator, | |
| 5856 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 5857 [self class], _autocreator); | |
| 5858 [_dictionary release]; | |
| 5859 [super dealloc]; | |
| 5860 } | |
| 5861 | |
| 5862 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 5863 return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; | |
| 5864 } | |
| 5865 | |
| 5866 - (BOOL)isEqual:(GPBUInt64UInt64Dictionary *)other { | |
| 5867 if (self == other) { | |
| 5868 return YES; | |
| 5869 } | |
| 5870 if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) { | |
| 5871 return NO; | |
| 5872 } | |
| 5873 return [_dictionary isEqual:other->_dictionary]; | |
| 5874 } | |
| 5875 | |
| 5876 - (NSUInteger)hash { | |
| 5877 return _dictionary.count; | |
| 5878 } | |
| 5879 | |
| 5880 - (NSString *)description { | |
| 5881 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 5882 } | |
| 5883 | |
| 5884 - (NSUInteger)count { | |
| 5885 return _dictionary.count; | |
| 5886 } | |
| 5887 | |
| 5888 - (void)enumerateKeysAndValuesUsingBlock: | |
| 5889 (void (^)(uint64_t key, uint64_t value, BOOL *stop))block { | |
| 5890 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5891 NSNumber *aValue, | |
| 5892 BOOL *stop) { | |
| 5893 block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], stop); | |
| 5894 }]; | |
| 5895 } | |
| 5896 | |
| 5897 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 5898 NSUInteger count = _dictionary.count; | |
| 5899 if (count == 0) { | |
| 5900 return 0; | |
| 5901 } | |
| 5902 | |
| 5903 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 5904 GPBDataType keyDataType = field.mapKeyDataType; | |
| 5905 __block size_t result = 0; | |
| 5906 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5907 NSNumber *aValue, | |
| 5908 BOOL *stop) { | |
| 5909 #pragma unused(stop) | |
| 5910 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 5911 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapVa
lueFieldNumber, valueDataType); | |
| 5912 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 5913 }]; | |
| 5914 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 5915 result += tagSize * count; | |
| 5916 return result; | |
| 5917 } | |
| 5918 | |
| 5919 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 5920 asField:(GPBFieldDescriptor *)field { | |
| 5921 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 5922 GPBDataType keyDataType = field.mapKeyDataType; | |
| 5923 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 5924 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 5925 NSNumber *aValue, | |
| 5926 BOOL *stop) { | |
| 5927 #pragma unused(stop) | |
| 5928 // Write the tag. | |
| 5929 [outputStream writeInt32NoTag:tag]; | |
| 5930 // Write the size of the message. | |
| 5931 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 5932 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapVa
lueFieldNumber, valueDataType); | |
| 5933 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 5934 // Write the fields. | |
| 5935 WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 5936 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | |
| 5937 }]; | |
| 5938 } | |
| 5939 | |
| 5940 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 5941 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 5942 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)]; | |
| 5943 } | |
| 5944 | |
| 5945 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 5946 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, uint64_t value, BOOL *s
top) { | |
| 5947 #pragma unused(stop) | |
| 5948 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%llu", value]); | |
| 5949 }]; | |
| 5950 } | |
| 5951 | |
| 5952 - (BOOL)valueForKey:(uint64_t)key value:(uint64_t *)value { | |
| 5953 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 5954 if (wrapped && value) { | |
| 5955 *value = [wrapped unsignedLongLongValue]; | |
| 5956 } | |
| 5957 return (wrapped != NULL); | |
| 5958 } | |
| 5959 | |
| 5960 - (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary { | |
| 5961 if (otherDictionary) { | |
| 5962 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 5963 if (_autocreator) { | |
| 5964 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 5965 } | |
| 5966 } | |
| 5967 } | |
| 5968 | |
| 5969 - (void)setValue:(uint64_t)value forKey:(uint64_t)key { | |
| 5970 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 5971 if (_autocreator) { | |
| 5972 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 5973 } | |
| 5974 } | |
| 5975 | |
| 5976 - (void)removeValueForKey:(uint64_t)aKey { | |
| 5977 [_dictionary removeObjectForKey:@(aKey)]; | |
| 5978 } | |
| 5979 | |
| 5980 - (void)removeAll { | |
| 5981 [_dictionary removeAllObjects]; | |
| 5982 } | |
| 5983 | |
| 5984 @end | |
| 5985 | |
| 5986 #pragma mark - UInt64 -> Int64 | |
| 5987 | |
| 5988 @implementation GPBUInt64Int64Dictionary { | |
| 5989 @package | |
| 5990 NSMutableDictionary *_dictionary; | |
| 5991 } | |
| 5992 | |
| 5993 + (instancetype)dictionary { | |
| 5994 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 5995 } | |
| 5996 | |
| 5997 + (instancetype)dictionaryWithValue:(int64_t)value | |
| 5998 forKey:(uint64_t)key { | |
| 5999 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6000 // on to get the type correct. | |
| 6001 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithValues:&value | |
| 6002 forKeys:&key | |
| 6003 count:1] autorelease
]; | |
| 6004 } | |
| 6005 | |
| 6006 + (instancetype)dictionaryWithValues:(const int64_t [])values | |
| 6007 forKeys:(const uint64_t [])keys | |
| 6008 count:(NSUInteger)count { | |
| 6009 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6010 // on to get the type correct. | |
| 6011 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithValues:values | |
| 6012 forKeys:keys | |
| 6013 count:count] autorel
ease]; | |
| 6014 } | |
| 6015 | |
| 6016 + (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary
{ | |
| 6017 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6018 // on to get the type correct. | |
| 6019 return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 6020 } | |
| 6021 | |
| 6022 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 6023 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 6024 } | |
| 6025 | |
| 6026 - (instancetype)init { | |
| 6027 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6028 } | |
| 6029 | |
| 6030 - (instancetype)initWithValues:(const int64_t [])values | |
| 6031 forKeys:(const uint64_t [])keys | |
| 6032 count:(NSUInteger)count { | |
| 6033 self = [super init]; | |
| 6034 if (self) { | |
| 6035 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 6036 if (count && values && keys) { | |
| 6037 for (NSUInteger i = 0; i < count; ++i) { | |
| 6038 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 6039 } | |
| 6040 } | |
| 6041 } | |
| 6042 return self; | |
| 6043 } | |
| 6044 | |
| 6045 - (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary { | |
| 6046 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6047 if (self) { | |
| 6048 if (dictionary) { | |
| 6049 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 6050 } | |
| 6051 } | |
| 6052 return self; | |
| 6053 } | |
| 6054 | |
| 6055 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 6056 #pragma unused(numItems) | |
| 6057 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6058 } | |
| 6059 | |
| 6060 - (void)dealloc { | |
| 6061 NSAssert(!_autocreator, | |
| 6062 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 6063 [self class], _autocreator); | |
| 6064 [_dictionary release]; | |
| 6065 [super dealloc]; | |
| 6066 } | |
| 6067 | |
| 6068 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 6069 return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 6070 } | |
| 6071 | |
| 6072 - (BOOL)isEqual:(GPBUInt64Int64Dictionary *)other { | |
| 6073 if (self == other) { | |
| 6074 return YES; | |
| 6075 } | |
| 6076 if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) { | |
| 6077 return NO; | |
| 6078 } | |
| 6079 return [_dictionary isEqual:other->_dictionary]; | |
| 6080 } | |
| 6081 | |
| 6082 - (NSUInteger)hash { | |
| 6083 return _dictionary.count; | |
| 6084 } | |
| 6085 | |
| 6086 - (NSString *)description { | |
| 6087 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 6088 } | |
| 6089 | |
| 6090 - (NSUInteger)count { | |
| 6091 return _dictionary.count; | |
| 6092 } | |
| 6093 | |
| 6094 - (void)enumerateKeysAndValuesUsingBlock: | |
| 6095 (void (^)(uint64_t key, int64_t value, BOOL *stop))block { | |
| 6096 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6097 NSNumber *aValue, | |
| 6098 BOOL *stop) { | |
| 6099 block([aKey unsignedLongLongValue], [aValue longLongValue], stop); | |
| 6100 }]; | |
| 6101 } | |
| 6102 | |
| 6103 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 6104 NSUInteger count = _dictionary.count; | |
| 6105 if (count == 0) { | |
| 6106 return 0; | |
| 6107 } | |
| 6108 | |
| 6109 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 6110 GPBDataType keyDataType = field.mapKeyDataType; | |
| 6111 __block size_t result = 0; | |
| 6112 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6113 NSNumber *aValue, | |
| 6114 BOOL *stop) { | |
| 6115 #pragma unused(stop) | |
| 6116 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 6117 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldN
umber, valueDataType); | |
| 6118 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 6119 }]; | |
| 6120 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 6121 result += tagSize * count; | |
| 6122 return result; | |
| 6123 } | |
| 6124 | |
| 6125 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 6126 asField:(GPBFieldDescriptor *)field { | |
| 6127 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 6128 GPBDataType keyDataType = field.mapKeyDataType; | |
| 6129 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 6130 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6131 NSNumber *aValue, | |
| 6132 BOOL *stop) { | |
| 6133 #pragma unused(stop) | |
| 6134 // Write the tag. | |
| 6135 [outputStream writeInt32NoTag:tag]; | |
| 6136 // Write the size of the message. | |
| 6137 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 6138 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldN
umber, valueDataType); | |
| 6139 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 6140 // Write the fields. | |
| 6141 WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 6142 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | |
| 6143 }]; | |
| 6144 } | |
| 6145 | |
| 6146 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 6147 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 6148 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)]; | |
| 6149 } | |
| 6150 | |
| 6151 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 6152 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, int64_t value, BOOL *st
op) { | |
| 6153 #pragma unused(stop) | |
| 6154 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%lld", value]); | |
| 6155 }]; | |
| 6156 } | |
| 6157 | |
| 6158 - (BOOL)valueForKey:(uint64_t)key value:(int64_t *)value { | |
| 6159 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 6160 if (wrapped && value) { | |
| 6161 *value = [wrapped longLongValue]; | |
| 6162 } | |
| 6163 return (wrapped != NULL); | |
| 6164 } | |
| 6165 | |
| 6166 - (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary { | |
| 6167 if (otherDictionary) { | |
| 6168 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 6169 if (_autocreator) { | |
| 6170 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 6171 } | |
| 6172 } | |
| 6173 } | |
| 6174 | |
| 6175 - (void)setValue:(int64_t)value forKey:(uint64_t)key { | |
| 6176 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 6177 if (_autocreator) { | |
| 6178 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 6179 } | |
| 6180 } | |
| 6181 | |
| 6182 - (void)removeValueForKey:(uint64_t)aKey { | |
| 6183 [_dictionary removeObjectForKey:@(aKey)]; | |
| 6184 } | |
| 6185 | |
| 6186 - (void)removeAll { | |
| 6187 [_dictionary removeAllObjects]; | |
| 6188 } | |
| 6189 | |
| 6190 @end | |
| 6191 | |
| 6192 #pragma mark - UInt64 -> Bool | |
| 6193 | |
| 6194 @implementation GPBUInt64BoolDictionary { | |
| 6195 @package | |
| 6196 NSMutableDictionary *_dictionary; | |
| 6197 } | |
| 6198 | |
| 6199 + (instancetype)dictionary { | |
| 6200 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 6201 } | |
| 6202 | |
| 6203 + (instancetype)dictionaryWithValue:(BOOL)value | |
| 6204 forKey:(uint64_t)key { | |
| 6205 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6206 // on to get the type correct. | |
| 6207 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithValues:&value | |
| 6208 forKeys:&key | |
| 6209 count:1] autorelease]
; | |
| 6210 } | |
| 6211 | |
| 6212 + (instancetype)dictionaryWithValues:(const BOOL [])values | |
| 6213 forKeys:(const uint64_t [])keys | |
| 6214 count:(NSUInteger)count { | |
| 6215 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6216 // on to get the type correct. | |
| 6217 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithValues:values | |
| 6218 forKeys:keys | |
| 6219 count:count] autorele
ase]; | |
| 6220 } | |
| 6221 | |
| 6222 + (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary { | |
| 6223 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6224 // on to get the type correct. | |
| 6225 return [[(GPBUInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 6226 } | |
| 6227 | |
| 6228 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 6229 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 6230 } | |
| 6231 | |
| 6232 - (instancetype)init { | |
| 6233 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6234 } | |
| 6235 | |
| 6236 - (instancetype)initWithValues:(const BOOL [])values | |
| 6237 forKeys:(const uint64_t [])keys | |
| 6238 count:(NSUInteger)count { | |
| 6239 self = [super init]; | |
| 6240 if (self) { | |
| 6241 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 6242 if (count && values && keys) { | |
| 6243 for (NSUInteger i = 0; i < count; ++i) { | |
| 6244 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 6245 } | |
| 6246 } | |
| 6247 } | |
| 6248 return self; | |
| 6249 } | |
| 6250 | |
| 6251 - (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary { | |
| 6252 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6253 if (self) { | |
| 6254 if (dictionary) { | |
| 6255 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 6256 } | |
| 6257 } | |
| 6258 return self; | |
| 6259 } | |
| 6260 | |
| 6261 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 6262 #pragma unused(numItems) | |
| 6263 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6264 } | |
| 6265 | |
| 6266 - (void)dealloc { | |
| 6267 NSAssert(!_autocreator, | |
| 6268 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 6269 [self class], _autocreator); | |
| 6270 [_dictionary release]; | |
| 6271 [super dealloc]; | |
| 6272 } | |
| 6273 | |
| 6274 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 6275 return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 6276 } | |
| 6277 | |
| 6278 - (BOOL)isEqual:(GPBUInt64BoolDictionary *)other { | |
| 6279 if (self == other) { | |
| 6280 return YES; | |
| 6281 } | |
| 6282 if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) { | |
| 6283 return NO; | |
| 6284 } | |
| 6285 return [_dictionary isEqual:other->_dictionary]; | |
| 6286 } | |
| 6287 | |
| 6288 - (NSUInteger)hash { | |
| 6289 return _dictionary.count; | |
| 6290 } | |
| 6291 | |
| 6292 - (NSString *)description { | |
| 6293 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 6294 } | |
| 6295 | |
| 6296 - (NSUInteger)count { | |
| 6297 return _dictionary.count; | |
| 6298 } | |
| 6299 | |
| 6300 - (void)enumerateKeysAndValuesUsingBlock: | |
| 6301 (void (^)(uint64_t key, BOOL value, BOOL *stop))block { | |
| 6302 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6303 NSNumber *aValue, | |
| 6304 BOOL *stop) { | |
| 6305 block([aKey unsignedLongLongValue], [aValue boolValue], stop); | |
| 6306 }]; | |
| 6307 } | |
| 6308 | |
| 6309 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 6310 NSUInteger count = _dictionary.count; | |
| 6311 if (count == 0) { | |
| 6312 return 0; | |
| 6313 } | |
| 6314 | |
| 6315 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 6316 GPBDataType keyDataType = field.mapKeyDataType; | |
| 6317 __block size_t result = 0; | |
| 6318 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6319 NSNumber *aValue, | |
| 6320 BOOL *stop) { | |
| 6321 #pragma unused(stop) | |
| 6322 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 6323 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber
, valueDataType); | |
| 6324 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 6325 }]; | |
| 6326 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 6327 result += tagSize * count; | |
| 6328 return result; | |
| 6329 } | |
| 6330 | |
| 6331 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 6332 asField:(GPBFieldDescriptor *)field { | |
| 6333 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 6334 GPBDataType keyDataType = field.mapKeyDataType; | |
| 6335 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 6336 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6337 NSNumber *aValue, | |
| 6338 BOOL *stop) { | |
| 6339 #pragma unused(stop) | |
| 6340 // Write the tag. | |
| 6341 [outputStream writeInt32NoTag:tag]; | |
| 6342 // Write the size of the message. | |
| 6343 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 6344 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber
, valueDataType); | |
| 6345 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 6346 // Write the fields. | |
| 6347 WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 6348 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | |
| 6349 }]; | |
| 6350 } | |
| 6351 | |
| 6352 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 6353 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 6354 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)]; | |
| 6355 } | |
| 6356 | |
| 6357 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 6358 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, BOOL value, BOOL *stop)
{ | |
| 6359 #pragma unused(stop) | |
| 6360 block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false
")); | |
| 6361 }]; | |
| 6362 } | |
| 6363 | |
| 6364 - (BOOL)valueForKey:(uint64_t)key value:(BOOL *)value { | |
| 6365 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 6366 if (wrapped && value) { | |
| 6367 *value = [wrapped boolValue]; | |
| 6368 } | |
| 6369 return (wrapped != NULL); | |
| 6370 } | |
| 6371 | |
| 6372 - (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary { | |
| 6373 if (otherDictionary) { | |
| 6374 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 6375 if (_autocreator) { | |
| 6376 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 6377 } | |
| 6378 } | |
| 6379 } | |
| 6380 | |
| 6381 - (void)setValue:(BOOL)value forKey:(uint64_t)key { | |
| 6382 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 6383 if (_autocreator) { | |
| 6384 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 6385 } | |
| 6386 } | |
| 6387 | |
| 6388 - (void)removeValueForKey:(uint64_t)aKey { | |
| 6389 [_dictionary removeObjectForKey:@(aKey)]; | |
| 6390 } | |
| 6391 | |
| 6392 - (void)removeAll { | |
| 6393 [_dictionary removeAllObjects]; | |
| 6394 } | |
| 6395 | |
| 6396 @end | |
| 6397 | |
| 6398 #pragma mark - UInt64 -> Float | |
| 6399 | |
| 6400 @implementation GPBUInt64FloatDictionary { | |
| 6401 @package | |
| 6402 NSMutableDictionary *_dictionary; | |
| 6403 } | |
| 6404 | |
| 6405 + (instancetype)dictionary { | |
| 6406 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 6407 } | |
| 6408 | |
| 6409 + (instancetype)dictionaryWithValue:(float)value | |
| 6410 forKey:(uint64_t)key { | |
| 6411 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6412 // on to get the type correct. | |
| 6413 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithValues:&value | |
| 6414 forKeys:&key | |
| 6415 count:1] autorelease
]; | |
| 6416 } | |
| 6417 | |
| 6418 + (instancetype)dictionaryWithValues:(const float [])values | |
| 6419 forKeys:(const uint64_t [])keys | |
| 6420 count:(NSUInteger)count { | |
| 6421 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6422 // on to get the type correct. | |
| 6423 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithValues:values | |
| 6424 forKeys:keys | |
| 6425 count:count] autorel
ease]; | |
| 6426 } | |
| 6427 | |
| 6428 + (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary
{ | |
| 6429 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6430 // on to get the type correct. | |
| 6431 return [[(GPBUInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 6432 } | |
| 6433 | |
| 6434 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 6435 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 6436 } | |
| 6437 | |
| 6438 - (instancetype)init { | |
| 6439 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6440 } | |
| 6441 | |
| 6442 - (instancetype)initWithValues:(const float [])values | |
| 6443 forKeys:(const uint64_t [])keys | |
| 6444 count:(NSUInteger)count { | |
| 6445 self = [super init]; | |
| 6446 if (self) { | |
| 6447 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 6448 if (count && values && keys) { | |
| 6449 for (NSUInteger i = 0; i < count; ++i) { | |
| 6450 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 6451 } | |
| 6452 } | |
| 6453 } | |
| 6454 return self; | |
| 6455 } | |
| 6456 | |
| 6457 - (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary { | |
| 6458 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6459 if (self) { | |
| 6460 if (dictionary) { | |
| 6461 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 6462 } | |
| 6463 } | |
| 6464 return self; | |
| 6465 } | |
| 6466 | |
| 6467 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 6468 #pragma unused(numItems) | |
| 6469 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6470 } | |
| 6471 | |
| 6472 - (void)dealloc { | |
| 6473 NSAssert(!_autocreator, | |
| 6474 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 6475 [self class], _autocreator); | |
| 6476 [_dictionary release]; | |
| 6477 [super dealloc]; | |
| 6478 } | |
| 6479 | |
| 6480 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 6481 return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 6482 } | |
| 6483 | |
| 6484 - (BOOL)isEqual:(GPBUInt64FloatDictionary *)other { | |
| 6485 if (self == other) { | |
| 6486 return YES; | |
| 6487 } | |
| 6488 if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) { | |
| 6489 return NO; | |
| 6490 } | |
| 6491 return [_dictionary isEqual:other->_dictionary]; | |
| 6492 } | |
| 6493 | |
| 6494 - (NSUInteger)hash { | |
| 6495 return _dictionary.count; | |
| 6496 } | |
| 6497 | |
| 6498 - (NSString *)description { | |
| 6499 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 6500 } | |
| 6501 | |
| 6502 - (NSUInteger)count { | |
| 6503 return _dictionary.count; | |
| 6504 } | |
| 6505 | |
| 6506 - (void)enumerateKeysAndValuesUsingBlock: | |
| 6507 (void (^)(uint64_t key, float value, BOOL *stop))block { | |
| 6508 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6509 NSNumber *aValue, | |
| 6510 BOOL *stop) { | |
| 6511 block([aKey unsignedLongLongValue], [aValue floatValue], stop); | |
| 6512 }]; | |
| 6513 } | |
| 6514 | |
| 6515 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 6516 NSUInteger count = _dictionary.count; | |
| 6517 if (count == 0) { | |
| 6518 return 0; | |
| 6519 } | |
| 6520 | |
| 6521 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 6522 GPBDataType keyDataType = field.mapKeyDataType; | |
| 6523 __block size_t result = 0; | |
| 6524 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6525 NSNumber *aValue, | |
| 6526 BOOL *stop) { | |
| 6527 #pragma unused(stop) | |
| 6528 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 6529 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumb
er, valueDataType); | |
| 6530 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 6531 }]; | |
| 6532 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 6533 result += tagSize * count; | |
| 6534 return result; | |
| 6535 } | |
| 6536 | |
| 6537 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 6538 asField:(GPBFieldDescriptor *)field { | |
| 6539 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 6540 GPBDataType keyDataType = field.mapKeyDataType; | |
| 6541 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 6542 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6543 NSNumber *aValue, | |
| 6544 BOOL *stop) { | |
| 6545 #pragma unused(stop) | |
| 6546 // Write the tag. | |
| 6547 [outputStream writeInt32NoTag:tag]; | |
| 6548 // Write the size of the message. | |
| 6549 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 6550 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumb
er, valueDataType); | |
| 6551 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 6552 // Write the fields. | |
| 6553 WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 6554 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | |
| 6555 }]; | |
| 6556 } | |
| 6557 | |
| 6558 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 6559 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 6560 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)]; | |
| 6561 } | |
| 6562 | |
| 6563 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 6564 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, float value, BOOL *stop
) { | |
| 6565 #pragma unused(stop) | |
| 6566 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%.*g", FLT_DIG, value]); | |
| 6567 }]; | |
| 6568 } | |
| 6569 | |
| 6570 - (BOOL)valueForKey:(uint64_t)key value:(float *)value { | |
| 6571 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 6572 if (wrapped && value) { | |
| 6573 *value = [wrapped floatValue]; | |
| 6574 } | |
| 6575 return (wrapped != NULL); | |
| 6576 } | |
| 6577 | |
| 6578 - (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary { | |
| 6579 if (otherDictionary) { | |
| 6580 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 6581 if (_autocreator) { | |
| 6582 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 6583 } | |
| 6584 } | |
| 6585 } | |
| 6586 | |
| 6587 - (void)setValue:(float)value forKey:(uint64_t)key { | |
| 6588 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 6589 if (_autocreator) { | |
| 6590 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 6591 } | |
| 6592 } | |
| 6593 | |
| 6594 - (void)removeValueForKey:(uint64_t)aKey { | |
| 6595 [_dictionary removeObjectForKey:@(aKey)]; | |
| 6596 } | |
| 6597 | |
| 6598 - (void)removeAll { | |
| 6599 [_dictionary removeAllObjects]; | |
| 6600 } | |
| 6601 | |
| 6602 @end | |
| 6603 | |
| 6604 #pragma mark - UInt64 -> Double | |
| 6605 | |
| 6606 @implementation GPBUInt64DoubleDictionary { | |
| 6607 @package | |
| 6608 NSMutableDictionary *_dictionary; | |
| 6609 } | |
| 6610 | |
| 6611 + (instancetype)dictionary { | |
| 6612 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 6613 } | |
| 6614 | |
| 6615 + (instancetype)dictionaryWithValue:(double)value | |
| 6616 forKey:(uint64_t)key { | |
| 6617 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6618 // on to get the type correct. | |
| 6619 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithValues:&value | |
| 6620 forKeys:&key | |
| 6621 count:1] autoreleas
e]; | |
| 6622 } | |
| 6623 | |
| 6624 + (instancetype)dictionaryWithValues:(const double [])values | |
| 6625 forKeys:(const uint64_t [])keys | |
| 6626 count:(NSUInteger)count { | |
| 6627 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6628 // on to get the type correct. | |
| 6629 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithValues:values | |
| 6630 forKeys:keys | |
| 6631 count:count] autore
lease]; | |
| 6632 } | |
| 6633 | |
| 6634 + (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary
{ | |
| 6635 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6636 // on to get the type correct. | |
| 6637 return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | |
| 6638 } | |
| 6639 | |
| 6640 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 6641 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 6642 } | |
| 6643 | |
| 6644 - (instancetype)init { | |
| 6645 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6646 } | |
| 6647 | |
| 6648 - (instancetype)initWithValues:(const double [])values | |
| 6649 forKeys:(const uint64_t [])keys | |
| 6650 count:(NSUInteger)count { | |
| 6651 self = [super init]; | |
| 6652 if (self) { | |
| 6653 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 6654 if (count && values && keys) { | |
| 6655 for (NSUInteger i = 0; i < count; ++i) { | |
| 6656 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 6657 } | |
| 6658 } | |
| 6659 } | |
| 6660 return self; | |
| 6661 } | |
| 6662 | |
| 6663 - (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary { | |
| 6664 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6665 if (self) { | |
| 6666 if (dictionary) { | |
| 6667 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 6668 } | |
| 6669 } | |
| 6670 return self; | |
| 6671 } | |
| 6672 | |
| 6673 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 6674 #pragma unused(numItems) | |
| 6675 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 6676 } | |
| 6677 | |
| 6678 - (void)dealloc { | |
| 6679 NSAssert(!_autocreator, | |
| 6680 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 6681 [self class], _autocreator); | |
| 6682 [_dictionary release]; | |
| 6683 [super dealloc]; | |
| 6684 } | |
| 6685 | |
| 6686 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 6687 return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self
]; | |
| 6688 } | |
| 6689 | |
| 6690 - (BOOL)isEqual:(GPBUInt64DoubleDictionary *)other { | |
| 6691 if (self == other) { | |
| 6692 return YES; | |
| 6693 } | |
| 6694 if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) { | |
| 6695 return NO; | |
| 6696 } | |
| 6697 return [_dictionary isEqual:other->_dictionary]; | |
| 6698 } | |
| 6699 | |
| 6700 - (NSUInteger)hash { | |
| 6701 return _dictionary.count; | |
| 6702 } | |
| 6703 | |
| 6704 - (NSString *)description { | |
| 6705 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 6706 } | |
| 6707 | |
| 6708 - (NSUInteger)count { | |
| 6709 return _dictionary.count; | |
| 6710 } | |
| 6711 | |
| 6712 - (void)enumerateKeysAndValuesUsingBlock: | |
| 6713 (void (^)(uint64_t key, double value, BOOL *stop))block { | |
| 6714 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6715 NSNumber *aValue, | |
| 6716 BOOL *stop) { | |
| 6717 block([aKey unsignedLongLongValue], [aValue doubleValue], stop); | |
| 6718 }]; | |
| 6719 } | |
| 6720 | |
| 6721 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 6722 NSUInteger count = _dictionary.count; | |
| 6723 if (count == 0) { | |
| 6724 return 0; | |
| 6725 } | |
| 6726 | |
| 6727 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 6728 GPBDataType keyDataType = field.mapKeyDataType; | |
| 6729 __block size_t result = 0; | |
| 6730 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6731 NSNumber *aValue, | |
| 6732 BOOL *stop) { | |
| 6733 #pragma unused(stop) | |
| 6734 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 6735 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNu
mber, valueDataType); | |
| 6736 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 6737 }]; | |
| 6738 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 6739 result += tagSize * count; | |
| 6740 return result; | |
| 6741 } | |
| 6742 | |
| 6743 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 6744 asField:(GPBFieldDescriptor *)field { | |
| 6745 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 6746 GPBDataType keyDataType = field.mapKeyDataType; | |
| 6747 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 6748 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6749 NSNumber *aValue, | |
| 6750 BOOL *stop) { | |
| 6751 #pragma unused(stop) | |
| 6752 // Write the tag. | |
| 6753 [outputStream writeInt32NoTag:tag]; | |
| 6754 // Write the size of the message. | |
| 6755 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 6756 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNu
mber, valueDataType); | |
| 6757 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 6758 // Write the fields. | |
| 6759 WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 6760 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | |
| 6761 }]; | |
| 6762 } | |
| 6763 | |
| 6764 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 6765 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 6766 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)]; | |
| 6767 } | |
| 6768 | |
| 6769 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 6770 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, double value, BOOL *sto
p) { | |
| 6771 #pragma unused(stop) | |
| 6772 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat
:@"%.*lg", DBL_DIG, value]); | |
| 6773 }]; | |
| 6774 } | |
| 6775 | |
| 6776 - (BOOL)valueForKey:(uint64_t)key value:(double *)value { | |
| 6777 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 6778 if (wrapped && value) { | |
| 6779 *value = [wrapped doubleValue]; | |
| 6780 } | |
| 6781 return (wrapped != NULL); | |
| 6782 } | |
| 6783 | |
| 6784 - (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary { | |
| 6785 if (otherDictionary) { | |
| 6786 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 6787 if (_autocreator) { | |
| 6788 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 6789 } | |
| 6790 } | |
| 6791 } | |
| 6792 | |
| 6793 - (void)setValue:(double)value forKey:(uint64_t)key { | |
| 6794 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 6795 if (_autocreator) { | |
| 6796 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 6797 } | |
| 6798 } | |
| 6799 | |
| 6800 - (void)removeValueForKey:(uint64_t)aKey { | |
| 6801 [_dictionary removeObjectForKey:@(aKey)]; | |
| 6802 } | |
| 6803 | |
| 6804 - (void)removeAll { | |
| 6805 [_dictionary removeAllObjects]; | |
| 6806 } | |
| 6807 | |
| 6808 @end | |
| 6809 | |
| 6810 #pragma mark - UInt64 -> Enum | |
| 6811 | |
| 6812 @implementation GPBUInt64EnumDictionary { | |
| 6813 @package | |
| 6814 NSMutableDictionary *_dictionary; | |
| 6815 GPBEnumValidationFunc _validationFunc; | |
| 6816 } | |
| 6817 | |
| 6818 @synthesize validationFunc = _validationFunc; | |
| 6819 | |
| 6820 + (instancetype)dictionary { | |
| 6821 return [[[self alloc] initWithValidationFunction:NULL | |
| 6822 rawValues:NULL | |
| 6823 forKeys:NULL | |
| 6824 count:0] autorelease]; | |
| 6825 } | |
| 6826 | |
| 6827 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 6828 return [[[self alloc] initWithValidationFunction:func | |
| 6829 rawValues:NULL | |
| 6830 forKeys:NULL | |
| 6831 count:0] autorelease]; | |
| 6832 } | |
| 6833 | |
| 6834 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 6835 rawValue:(int32_t)rawValue | |
| 6836 forKey:(uint64_t)key { | |
| 6837 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6838 // on to get the type correct. | |
| 6839 return [[(GPBUInt64EnumDictionary*)[self alloc] initWithValidationFunction:fun
c | |
| 6840 rawValues:&ra
wValue | |
| 6841 forKeys:&ke
y | |
| 6842 count:1]
autorelease]; | |
| 6843 } | |
| 6844 | |
| 6845 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 6846 rawValues:(const int32_t [])rawValues | |
| 6847 forKeys:(const uint64_t [])keys | |
| 6848 count:(NSUInteger)count { | |
| 6849 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6850 // on to get the type correct. | |
| 6851 return [[(GPBUInt64EnumDictionary*)[self alloc] initWithValidationFunction:fun
c | |
| 6852 rawValues:raw
Values | |
| 6853 forKeys:key
s | |
| 6854 count:cou
nt] autorelease]; | |
| 6855 } | |
| 6856 | |
| 6857 + (instancetype)dictionaryWithDictionary:(GPBUInt64EnumDictionary *)dictionary { | |
| 6858 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 6859 // on to get the type correct. | |
| 6860 return [[(GPBUInt64EnumDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 6861 } | |
| 6862 | |
| 6863 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 6864 capacity:(NSUInteger)numItems { | |
| 6865 return [[[self alloc] initWithValidationFunction:func capacity:numItems] autor
elease]; | |
| 6866 } | |
| 6867 | |
| 6868 - (instancetype)init { | |
| 6869 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count
:0]; | |
| 6870 } | |
| 6871 | |
| 6872 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 6873 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 6874 } | |
| 6875 | |
| 6876 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 6877 rawValues:(const int32_t [])rawValues | |
| 6878 forKeys:(const uint64_t [])keys | |
| 6879 count:(NSUInteger)count { | |
| 6880 self = [super init]; | |
| 6881 if (self) { | |
| 6882 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 6883 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); | |
| 6884 if (count && rawValues && keys) { | |
| 6885 for (NSUInteger i = 0; i < count; ++i) { | |
| 6886 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])]; | |
| 6887 } | |
| 6888 } | |
| 6889 } | |
| 6890 return self; | |
| 6891 } | |
| 6892 | |
| 6893 - (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary { | |
| 6894 self = [self initWithValidationFunction:dictionary.validationFunc | |
| 6895 rawValues:NULL | |
| 6896 forKeys:NULL | |
| 6897 count:0]; | |
| 6898 if (self) { | |
| 6899 if (dictionary) { | |
| 6900 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 6901 } | |
| 6902 } | |
| 6903 return self; | |
| 6904 } | |
| 6905 | |
| 6906 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 6907 capacity:(NSUInteger)numItems { | |
| 6908 #pragma unused(numItems) | |
| 6909 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 6910 } | |
| 6911 | |
| 6912 - (void)dealloc { | |
| 6913 NSAssert(!_autocreator, | |
| 6914 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 6915 [self class], _autocreator); | |
| 6916 [_dictionary release]; | |
| 6917 [super dealloc]; | |
| 6918 } | |
| 6919 | |
| 6920 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 6921 return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 6922 } | |
| 6923 | |
| 6924 - (BOOL)isEqual:(GPBUInt64EnumDictionary *)other { | |
| 6925 if (self == other) { | |
| 6926 return YES; | |
| 6927 } | |
| 6928 if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) { | |
| 6929 return NO; | |
| 6930 } | |
| 6931 return [_dictionary isEqual:other->_dictionary]; | |
| 6932 } | |
| 6933 | |
| 6934 - (NSUInteger)hash { | |
| 6935 return _dictionary.count; | |
| 6936 } | |
| 6937 | |
| 6938 - (NSString *)description { | |
| 6939 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 6940 } | |
| 6941 | |
| 6942 - (NSUInteger)count { | |
| 6943 return _dictionary.count; | |
| 6944 } | |
| 6945 | |
| 6946 - (void)enumerateKeysAndRawValuesUsingBlock: | |
| 6947 (void (^)(uint64_t key, int32_t value, BOOL *stop))block { | |
| 6948 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6949 NSNumber *aValue, | |
| 6950 BOOL *stop) { | |
| 6951 block([aKey unsignedLongLongValue], [aValue intValue], stop); | |
| 6952 }]; | |
| 6953 } | |
| 6954 | |
| 6955 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 6956 NSUInteger count = _dictionary.count; | |
| 6957 if (count == 0) { | |
| 6958 return 0; | |
| 6959 } | |
| 6960 | |
| 6961 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 6962 GPBDataType keyDataType = field.mapKeyDataType; | |
| 6963 __block size_t result = 0; | |
| 6964 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6965 NSNumber *aValue, | |
| 6966 BOOL *stop) { | |
| 6967 #pragma unused(stop) | |
| 6968 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 6969 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber,
valueDataType); | |
| 6970 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 6971 }]; | |
| 6972 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 6973 result += tagSize * count; | |
| 6974 return result; | |
| 6975 } | |
| 6976 | |
| 6977 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 6978 asField:(GPBFieldDescriptor *)field { | |
| 6979 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 6980 GPBDataType keyDataType = field.mapKeyDataType; | |
| 6981 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 6982 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 6983 NSNumber *aValue, | |
| 6984 BOOL *stop) { | |
| 6985 #pragma unused(stop) | |
| 6986 // Write the tag. | |
| 6987 [outputStream writeInt32NoTag:tag]; | |
| 6988 // Write the size of the message. | |
| 6989 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 6990 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber,
valueDataType); | |
| 6991 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 6992 // Write the fields. | |
| 6993 WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 6994 WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, va
lueDataType); | |
| 6995 }]; | |
| 6996 } | |
| 6997 | |
| 6998 - (NSData *)serializedDataForUnknownValue:(int32_t)value | |
| 6999 forKey:(GPBGenericValue *)key | |
| 7000 keyDataType:(GPBDataType)keyDataType { | |
| 7001 size_t msgSize = ComputeDictUInt64FieldSize(key->valueUInt64, kMapKeyFieldNumb
er, keyDataType); | |
| 7002 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEn
um); | |
| 7003 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; | |
| 7004 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithDat
a:data]; | |
| 7005 WriteDictUInt64Field(outputStream, key->valueUInt64, kMapKeyFieldNumber, keyDa
taType); | |
| 7006 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum)
; | |
| 7007 [outputStream release]; | |
| 7008 return data; | |
| 7009 } | |
| 7010 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 7011 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 7012 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)]; | |
| 7013 } | |
| 7014 | |
| 7015 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 7016 [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL
*stop) { | |
| 7017 #pragma unused(stop) | |
| 7018 block([NSString stringWithFormat:@"%llu", key], @(value)); | |
| 7019 }]; | |
| 7020 } | |
| 7021 | |
| 7022 - (BOOL)valueForKey:(uint64_t)key value:(int32_t *)value { | |
| 7023 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 7024 if (wrapped && value) { | |
| 7025 int32_t result = [wrapped intValue]; | |
| 7026 if (!_validationFunc(result)) { | |
| 7027 result = kGPBUnrecognizedEnumeratorValue; | |
| 7028 } | |
| 7029 *value = result; | |
| 7030 } | |
| 7031 return (wrapped != NULL); | |
| 7032 } | |
| 7033 | |
| 7034 - (BOOL)valueForKey:(uint64_t)key rawValue:(int32_t *)rawValue { | |
| 7035 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 7036 if (wrapped && rawValue) { | |
| 7037 *rawValue = [wrapped intValue]; | |
| 7038 } | |
| 7039 return (wrapped != NULL); | |
| 7040 } | |
| 7041 | |
| 7042 - (void)enumerateKeysAndValuesUsingBlock: | |
| 7043 (void (^)(uint64_t key, int32_t value, BOOL *stop))block { | |
| 7044 GPBEnumValidationFunc func = _validationFunc; | |
| 7045 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7046 NSNumber *aValue, | |
| 7047 BOOL *stop) { | |
| 7048 int32_t unwrapped = [aValue intValue]; | |
| 7049 if (!func(unwrapped)) { | |
| 7050 unwrapped = kGPBUnrecognizedEnumeratorValue; | |
| 7051 } | |
| 7052 block([aKey unsignedLongLongValue], unwrapped, stop); | |
| 7053 }]; | |
| 7054 } | |
| 7055 | |
| 7056 - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary { | |
| 7057 if (otherDictionary) { | |
| 7058 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 7059 if (_autocreator) { | |
| 7060 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 7061 } | |
| 7062 } | |
| 7063 } | |
| 7064 | |
| 7065 - (void)setRawValue:(int32_t)value forKey:(uint64_t)key { | |
| 7066 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 7067 if (_autocreator) { | |
| 7068 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 7069 } | |
| 7070 } | |
| 7071 | |
| 7072 - (void)removeValueForKey:(uint64_t)aKey { | |
| 7073 [_dictionary removeObjectForKey:@(aKey)]; | |
| 7074 } | |
| 7075 | |
| 7076 - (void)removeAll { | |
| 7077 [_dictionary removeAllObjects]; | |
| 7078 } | |
| 7079 | |
| 7080 - (void)setValue:(int32_t)value forKey:(uint64_t)key { | |
| 7081 if (!_validationFunc(value)) { | |
| 7082 [NSException raise:NSInvalidArgumentException | |
| 7083 format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum
value (%d)", | |
| 7084 value]; | |
| 7085 } | |
| 7086 | |
| 7087 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 7088 if (_autocreator) { | |
| 7089 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 7090 } | |
| 7091 } | |
| 7092 | |
| 7093 @end | |
| 7094 | |
| 7095 #pragma mark - UInt64 -> Object | |
| 7096 | |
| 7097 @implementation GPBUInt64ObjectDictionary { | |
| 7098 @package | |
| 7099 NSMutableDictionary *_dictionary; | |
| 7100 } | |
| 7101 | |
| 7102 + (instancetype)dictionary { | |
| 7103 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 7104 } | |
| 7105 | |
| 7106 + (instancetype)dictionaryWithValue:(id)value | |
| 7107 forKey:(uint64_t)key { | |
| 7108 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7109 // on to get the type correct. | |
| 7110 return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithValues:&value | |
| 7111 forKeys:&key | |
| 7112 count:1] autoreleas
e]; | |
| 7113 } | |
| 7114 | |
| 7115 + (instancetype)dictionaryWithValues:(const id [])values | |
| 7116 forKeys:(const uint64_t [])keys | |
| 7117 count:(NSUInteger)count { | |
| 7118 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7119 // on to get the type correct. | |
| 7120 return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithValues:values | |
| 7121 forKeys:keys | |
| 7122 count:count] autore
lease]; | |
| 7123 } | |
| 7124 | |
| 7125 + (instancetype)dictionaryWithDictionary:(GPBUInt64ObjectDictionary *)dictionary
{ | |
| 7126 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7127 // on to get the type correct. | |
| 7128 return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | |
| 7129 } | |
| 7130 | |
| 7131 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 7132 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 7133 } | |
| 7134 | |
| 7135 - (instancetype)init { | |
| 7136 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7137 } | |
| 7138 | |
| 7139 - (instancetype)initWithValues:(const id [])values | |
| 7140 forKeys:(const uint64_t [])keys | |
| 7141 count:(NSUInteger)count { | |
| 7142 self = [super init]; | |
| 7143 if (self) { | |
| 7144 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 7145 if (count && values && keys) { | |
| 7146 for (NSUInteger i = 0; i < count; ++i) { | |
| 7147 [_dictionary setObject:values[i] forKey:@(keys[i])]; | |
| 7148 } | |
| 7149 } | |
| 7150 } | |
| 7151 return self; | |
| 7152 } | |
| 7153 | |
| 7154 - (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary { | |
| 7155 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7156 if (self) { | |
| 7157 if (dictionary) { | |
| 7158 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 7159 } | |
| 7160 } | |
| 7161 return self; | |
| 7162 } | |
| 7163 | |
| 7164 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 7165 #pragma unused(numItems) | |
| 7166 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7167 } | |
| 7168 | |
| 7169 - (void)dealloc { | |
| 7170 NSAssert(!_autocreator, | |
| 7171 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 7172 [self class], _autocreator); | |
| 7173 [_dictionary release]; | |
| 7174 [super dealloc]; | |
| 7175 } | |
| 7176 | |
| 7177 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 7178 return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self
]; | |
| 7179 } | |
| 7180 | |
| 7181 - (BOOL)isEqual:(GPBUInt64ObjectDictionary *)other { | |
| 7182 if (self == other) { | |
| 7183 return YES; | |
| 7184 } | |
| 7185 if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) { | |
| 7186 return NO; | |
| 7187 } | |
| 7188 return [_dictionary isEqual:other->_dictionary]; | |
| 7189 } | |
| 7190 | |
| 7191 - (NSUInteger)hash { | |
| 7192 return _dictionary.count; | |
| 7193 } | |
| 7194 | |
| 7195 - (NSString *)description { | |
| 7196 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 7197 } | |
| 7198 | |
| 7199 - (NSUInteger)count { | |
| 7200 return _dictionary.count; | |
| 7201 } | |
| 7202 | |
| 7203 - (void)enumerateKeysAndValuesUsingBlock: | |
| 7204 (void (^)(uint64_t key, id value, BOOL *stop))block { | |
| 7205 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7206 id aValue, | |
| 7207 BOOL *stop) { | |
| 7208 block([aKey unsignedLongLongValue], aValue, stop); | |
| 7209 }]; | |
| 7210 } | |
| 7211 | |
| 7212 - (BOOL)isInitialized { | |
| 7213 for (GPBMessage *msg in [_dictionary objectEnumerator]) { | |
| 7214 if (!msg.initialized) { | |
| 7215 return NO; | |
| 7216 } | |
| 7217 } | |
| 7218 return YES; | |
| 7219 } | |
| 7220 | |
| 7221 - (instancetype)deepCopyWithZone:(NSZone *)zone { | |
| 7222 GPBUInt64ObjectDictionary *newDict = | |
| 7223 [[GPBUInt64ObjectDictionary alloc] init]; | |
| 7224 [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey, | |
| 7225 GPBMessage *msg, | |
| 7226 BOOL *stop) { | |
| 7227 #pragma unused(stop) | |
| 7228 GPBMessage *copiedMsg = [msg copyWithZone:zone]; | |
| 7229 [newDict->_dictionary setObject:copiedMsg forKey:aKey]; | |
| 7230 [copiedMsg release]; | |
| 7231 }]; | |
| 7232 return newDict; | |
| 7233 } | |
| 7234 | |
| 7235 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 7236 NSUInteger count = _dictionary.count; | |
| 7237 if (count == 0) { | |
| 7238 return 0; | |
| 7239 } | |
| 7240 | |
| 7241 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 7242 GPBDataType keyDataType = field.mapKeyDataType; | |
| 7243 __block size_t result = 0; | |
| 7244 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7245 id aValue, | |
| 7246 BOOL *stop) { | |
| 7247 #pragma unused(stop) | |
| 7248 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 7249 msgSize += ComputeDictObjectFieldSize(aValue, kMapValueFieldNumber, valueDat
aType); | |
| 7250 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 7251 }]; | |
| 7252 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 7253 result += tagSize * count; | |
| 7254 return result; | |
| 7255 } | |
| 7256 | |
| 7257 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 7258 asField:(GPBFieldDescriptor *)field { | |
| 7259 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 7260 GPBDataType keyDataType = field.mapKeyDataType; | |
| 7261 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 7262 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7263 id aValue, | |
| 7264 BOOL *stop) { | |
| 7265 #pragma unused(stop) | |
| 7266 // Write the tag. | |
| 7267 [outputStream writeInt32NoTag:tag]; | |
| 7268 // Write the size of the message. | |
| 7269 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kM
apKeyFieldNumber, keyDataType); | |
| 7270 msgSize += ComputeDictObjectFieldSize(aValue, kMapValueFieldNumber, valueDat
aType); | |
| 7271 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 7272 // Write the fields. | |
| 7273 WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 7274 WriteDictObjectField(outputStream, aValue, kMapValueFieldNumber, valueDataTy
pe); | |
| 7275 }]; | |
| 7276 } | |
| 7277 | |
| 7278 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 7279 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 7280 [_dictionary setObject:value->valueString forKey:@(key->valueUInt64)]; | |
| 7281 } | |
| 7282 | |
| 7283 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 7284 [self enumerateKeysAndValuesUsingBlock:^(uint64_t key, id value, BOOL *stop) { | |
| 7285 #pragma unused(stop) | |
| 7286 block([NSString stringWithFormat:@"%llu", key], value); | |
| 7287 }]; | |
| 7288 } | |
| 7289 | |
| 7290 - (id)valueForKey:(uint64_t)key { | |
| 7291 id result = [_dictionary objectForKey:@(key)]; | |
| 7292 return result; | |
| 7293 } | |
| 7294 | |
| 7295 - (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary { | |
| 7296 if (otherDictionary) { | |
| 7297 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 7298 if (_autocreator) { | |
| 7299 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 7300 } | |
| 7301 } | |
| 7302 } | |
| 7303 | |
| 7304 - (void)setValue:(id)value forKey:(uint64_t)key { | |
| 7305 [_dictionary setObject:value forKey:@(key)]; | |
| 7306 if (_autocreator) { | |
| 7307 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 7308 } | |
| 7309 } | |
| 7310 | |
| 7311 - (void)removeValueForKey:(uint64_t)aKey { | |
| 7312 [_dictionary removeObjectForKey:@(aKey)]; | |
| 7313 } | |
| 7314 | |
| 7315 - (void)removeAll { | |
| 7316 [_dictionary removeAllObjects]; | |
| 7317 } | |
| 7318 | |
| 7319 @end | |
| 7320 | |
| 7321 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int64, int64_t) | |
| 7322 // This block of code is generated, do not edit it directly. | |
| 7323 | |
| 7324 #pragma mark - Int64 -> UInt32 | |
| 7325 | |
| 7326 @implementation GPBInt64UInt32Dictionary { | |
| 7327 @package | |
| 7328 NSMutableDictionary *_dictionary; | |
| 7329 } | |
| 7330 | |
| 7331 + (instancetype)dictionary { | |
| 7332 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 7333 } | |
| 7334 | |
| 7335 + (instancetype)dictionaryWithValue:(uint32_t)value | |
| 7336 forKey:(int64_t)key { | |
| 7337 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7338 // on to get the type correct. | |
| 7339 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithValues:&value | |
| 7340 forKeys:&key | |
| 7341 count:1] autorelease
]; | |
| 7342 } | |
| 7343 | |
| 7344 + (instancetype)dictionaryWithValues:(const uint32_t [])values | |
| 7345 forKeys:(const int64_t [])keys | |
| 7346 count:(NSUInteger)count { | |
| 7347 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7348 // on to get the type correct. | |
| 7349 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithValues:values | |
| 7350 forKeys:keys | |
| 7351 count:count] autorel
ease]; | |
| 7352 } | |
| 7353 | |
| 7354 + (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary
{ | |
| 7355 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7356 // on to get the type correct. | |
| 7357 return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 7358 } | |
| 7359 | |
| 7360 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 7361 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 7362 } | |
| 7363 | |
| 7364 - (instancetype)init { | |
| 7365 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7366 } | |
| 7367 | |
| 7368 - (instancetype)initWithValues:(const uint32_t [])values | |
| 7369 forKeys:(const int64_t [])keys | |
| 7370 count:(NSUInteger)count { | |
| 7371 self = [super init]; | |
| 7372 if (self) { | |
| 7373 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 7374 if (count && values && keys) { | |
| 7375 for (NSUInteger i = 0; i < count; ++i) { | |
| 7376 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 7377 } | |
| 7378 } | |
| 7379 } | |
| 7380 return self; | |
| 7381 } | |
| 7382 | |
| 7383 - (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary { | |
| 7384 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7385 if (self) { | |
| 7386 if (dictionary) { | |
| 7387 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 7388 } | |
| 7389 } | |
| 7390 return self; | |
| 7391 } | |
| 7392 | |
| 7393 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 7394 #pragma unused(numItems) | |
| 7395 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7396 } | |
| 7397 | |
| 7398 - (void)dealloc { | |
| 7399 NSAssert(!_autocreator, | |
| 7400 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 7401 [self class], _autocreator); | |
| 7402 [_dictionary release]; | |
| 7403 [super dealloc]; | |
| 7404 } | |
| 7405 | |
| 7406 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 7407 return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 7408 } | |
| 7409 | |
| 7410 - (BOOL)isEqual:(GPBInt64UInt32Dictionary *)other { | |
| 7411 if (self == other) { | |
| 7412 return YES; | |
| 7413 } | |
| 7414 if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) { | |
| 7415 return NO; | |
| 7416 } | |
| 7417 return [_dictionary isEqual:other->_dictionary]; | |
| 7418 } | |
| 7419 | |
| 7420 - (NSUInteger)hash { | |
| 7421 return _dictionary.count; | |
| 7422 } | |
| 7423 | |
| 7424 - (NSString *)description { | |
| 7425 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 7426 } | |
| 7427 | |
| 7428 - (NSUInteger)count { | |
| 7429 return _dictionary.count; | |
| 7430 } | |
| 7431 | |
| 7432 - (void)enumerateKeysAndValuesUsingBlock: | |
| 7433 (void (^)(int64_t key, uint32_t value, BOOL *stop))block { | |
| 7434 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7435 NSNumber *aValue, | |
| 7436 BOOL *stop) { | |
| 7437 block([aKey longLongValue], [aValue unsignedIntValue], stop); | |
| 7438 }]; | |
| 7439 } | |
| 7440 | |
| 7441 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 7442 NSUInteger count = _dictionary.count; | |
| 7443 if (count == 0) { | |
| 7444 return 0; | |
| 7445 } | |
| 7446 | |
| 7447 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 7448 GPBDataType keyDataType = field.mapKeyDataType; | |
| 7449 __block size_t result = 0; | |
| 7450 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7451 NSNumber *aValue, | |
| 7452 BOOL *stop) { | |
| 7453 #pragma unused(stop) | |
| 7454 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 7455 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFi
eldNumber, valueDataType); | |
| 7456 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 7457 }]; | |
| 7458 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 7459 result += tagSize * count; | |
| 7460 return result; | |
| 7461 } | |
| 7462 | |
| 7463 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 7464 asField:(GPBFieldDescriptor *)field { | |
| 7465 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 7466 GPBDataType keyDataType = field.mapKeyDataType; | |
| 7467 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 7468 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7469 NSNumber *aValue, | |
| 7470 BOOL *stop) { | |
| 7471 #pragma unused(stop) | |
| 7472 // Write the tag. | |
| 7473 [outputStream writeInt32NoTag:tag]; | |
| 7474 // Write the size of the message. | |
| 7475 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 7476 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFi
eldNumber, valueDataType); | |
| 7477 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 7478 // Write the fields. | |
| 7479 WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber,
keyDataType); | |
| 7480 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | |
| 7481 }]; | |
| 7482 } | |
| 7483 | |
| 7484 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 7485 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 7486 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)]; | |
| 7487 } | |
| 7488 | |
| 7489 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 7490 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, uint32_t value, BOOL *st
op) { | |
| 7491 #pragma unused(stop) | |
| 7492 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%u", value]); | |
| 7493 }]; | |
| 7494 } | |
| 7495 | |
| 7496 - (BOOL)valueForKey:(int64_t)key value:(uint32_t *)value { | |
| 7497 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 7498 if (wrapped && value) { | |
| 7499 *value = [wrapped unsignedIntValue]; | |
| 7500 } | |
| 7501 return (wrapped != NULL); | |
| 7502 } | |
| 7503 | |
| 7504 - (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary { | |
| 7505 if (otherDictionary) { | |
| 7506 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 7507 if (_autocreator) { | |
| 7508 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 7509 } | |
| 7510 } | |
| 7511 } | |
| 7512 | |
| 7513 - (void)setValue:(uint32_t)value forKey:(int64_t)key { | |
| 7514 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 7515 if (_autocreator) { | |
| 7516 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 7517 } | |
| 7518 } | |
| 7519 | |
| 7520 - (void)removeValueForKey:(int64_t)aKey { | |
| 7521 [_dictionary removeObjectForKey:@(aKey)]; | |
| 7522 } | |
| 7523 | |
| 7524 - (void)removeAll { | |
| 7525 [_dictionary removeAllObjects]; | |
| 7526 } | |
| 7527 | |
| 7528 @end | |
| 7529 | |
| 7530 #pragma mark - Int64 -> Int32 | |
| 7531 | |
| 7532 @implementation GPBInt64Int32Dictionary { | |
| 7533 @package | |
| 7534 NSMutableDictionary *_dictionary; | |
| 7535 } | |
| 7536 | |
| 7537 + (instancetype)dictionary { | |
| 7538 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 7539 } | |
| 7540 | |
| 7541 + (instancetype)dictionaryWithValue:(int32_t)value | |
| 7542 forKey:(int64_t)key { | |
| 7543 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7544 // on to get the type correct. | |
| 7545 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithValues:&value | |
| 7546 forKeys:&key | |
| 7547 count:1] autorelease]
; | |
| 7548 } | |
| 7549 | |
| 7550 + (instancetype)dictionaryWithValues:(const int32_t [])values | |
| 7551 forKeys:(const int64_t [])keys | |
| 7552 count:(NSUInteger)count { | |
| 7553 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7554 // on to get the type correct. | |
| 7555 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithValues:values | |
| 7556 forKeys:keys | |
| 7557 count:count] autorele
ase]; | |
| 7558 } | |
| 7559 | |
| 7560 + (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary { | |
| 7561 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7562 // on to get the type correct. | |
| 7563 return [[(GPBInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 7564 } | |
| 7565 | |
| 7566 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 7567 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 7568 } | |
| 7569 | |
| 7570 - (instancetype)init { | |
| 7571 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7572 } | |
| 7573 | |
| 7574 - (instancetype)initWithValues:(const int32_t [])values | |
| 7575 forKeys:(const int64_t [])keys | |
| 7576 count:(NSUInteger)count { | |
| 7577 self = [super init]; | |
| 7578 if (self) { | |
| 7579 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 7580 if (count && values && keys) { | |
| 7581 for (NSUInteger i = 0; i < count; ++i) { | |
| 7582 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 7583 } | |
| 7584 } | |
| 7585 } | |
| 7586 return self; | |
| 7587 } | |
| 7588 | |
| 7589 - (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary { | |
| 7590 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7591 if (self) { | |
| 7592 if (dictionary) { | |
| 7593 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 7594 } | |
| 7595 } | |
| 7596 return self; | |
| 7597 } | |
| 7598 | |
| 7599 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 7600 #pragma unused(numItems) | |
| 7601 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7602 } | |
| 7603 | |
| 7604 - (void)dealloc { | |
| 7605 NSAssert(!_autocreator, | |
| 7606 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 7607 [self class], _autocreator); | |
| 7608 [_dictionary release]; | |
| 7609 [super dealloc]; | |
| 7610 } | |
| 7611 | |
| 7612 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 7613 return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]; | |
| 7614 } | |
| 7615 | |
| 7616 - (BOOL)isEqual:(GPBInt64Int32Dictionary *)other { | |
| 7617 if (self == other) { | |
| 7618 return YES; | |
| 7619 } | |
| 7620 if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) { | |
| 7621 return NO; | |
| 7622 } | |
| 7623 return [_dictionary isEqual:other->_dictionary]; | |
| 7624 } | |
| 7625 | |
| 7626 - (NSUInteger)hash { | |
| 7627 return _dictionary.count; | |
| 7628 } | |
| 7629 | |
| 7630 - (NSString *)description { | |
| 7631 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 7632 } | |
| 7633 | |
| 7634 - (NSUInteger)count { | |
| 7635 return _dictionary.count; | |
| 7636 } | |
| 7637 | |
| 7638 - (void)enumerateKeysAndValuesUsingBlock: | |
| 7639 (void (^)(int64_t key, int32_t value, BOOL *stop))block { | |
| 7640 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7641 NSNumber *aValue, | |
| 7642 BOOL *stop) { | |
| 7643 block([aKey longLongValue], [aValue intValue], stop); | |
| 7644 }]; | |
| 7645 } | |
| 7646 | |
| 7647 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 7648 NSUInteger count = _dictionary.count; | |
| 7649 if (count == 0) { | |
| 7650 return 0; | |
| 7651 } | |
| 7652 | |
| 7653 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 7654 GPBDataType keyDataType = field.mapKeyDataType; | |
| 7655 __block size_t result = 0; | |
| 7656 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7657 NSNumber *aValue, | |
| 7658 BOOL *stop) { | |
| 7659 #pragma unused(stop) | |
| 7660 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 7661 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber
, valueDataType); | |
| 7662 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 7663 }]; | |
| 7664 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 7665 result += tagSize * count; | |
| 7666 return result; | |
| 7667 } | |
| 7668 | |
| 7669 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 7670 asField:(GPBFieldDescriptor *)field { | |
| 7671 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 7672 GPBDataType keyDataType = field.mapKeyDataType; | |
| 7673 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 7674 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7675 NSNumber *aValue, | |
| 7676 BOOL *stop) { | |
| 7677 #pragma unused(stop) | |
| 7678 // Write the tag. | |
| 7679 [outputStream writeInt32NoTag:tag]; | |
| 7680 // Write the size of the message. | |
| 7681 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 7682 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber
, valueDataType); | |
| 7683 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 7684 // Write the fields. | |
| 7685 WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber,
keyDataType); | |
| 7686 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | |
| 7687 }]; | |
| 7688 } | |
| 7689 | |
| 7690 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 7691 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 7692 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)]; | |
| 7693 } | |
| 7694 | |
| 7695 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 7696 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, int32_t value, BOOL *sto
p) { | |
| 7697 #pragma unused(stop) | |
| 7698 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%d", value]); | |
| 7699 }]; | |
| 7700 } | |
| 7701 | |
| 7702 - (BOOL)valueForKey:(int64_t)key value:(int32_t *)value { | |
| 7703 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 7704 if (wrapped && value) { | |
| 7705 *value = [wrapped intValue]; | |
| 7706 } | |
| 7707 return (wrapped != NULL); | |
| 7708 } | |
| 7709 | |
| 7710 - (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary { | |
| 7711 if (otherDictionary) { | |
| 7712 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 7713 if (_autocreator) { | |
| 7714 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 7715 } | |
| 7716 } | |
| 7717 } | |
| 7718 | |
| 7719 - (void)setValue:(int32_t)value forKey:(int64_t)key { | |
| 7720 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 7721 if (_autocreator) { | |
| 7722 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 7723 } | |
| 7724 } | |
| 7725 | |
| 7726 - (void)removeValueForKey:(int64_t)aKey { | |
| 7727 [_dictionary removeObjectForKey:@(aKey)]; | |
| 7728 } | |
| 7729 | |
| 7730 - (void)removeAll { | |
| 7731 [_dictionary removeAllObjects]; | |
| 7732 } | |
| 7733 | |
| 7734 @end | |
| 7735 | |
| 7736 #pragma mark - Int64 -> UInt64 | |
| 7737 | |
| 7738 @implementation GPBInt64UInt64Dictionary { | |
| 7739 @package | |
| 7740 NSMutableDictionary *_dictionary; | |
| 7741 } | |
| 7742 | |
| 7743 + (instancetype)dictionary { | |
| 7744 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 7745 } | |
| 7746 | |
| 7747 + (instancetype)dictionaryWithValue:(uint64_t)value | |
| 7748 forKey:(int64_t)key { | |
| 7749 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7750 // on to get the type correct. | |
| 7751 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithValues:&value | |
| 7752 forKeys:&key | |
| 7753 count:1] autorelease
]; | |
| 7754 } | |
| 7755 | |
| 7756 + (instancetype)dictionaryWithValues:(const uint64_t [])values | |
| 7757 forKeys:(const int64_t [])keys | |
| 7758 count:(NSUInteger)count { | |
| 7759 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7760 // on to get the type correct. | |
| 7761 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithValues:values | |
| 7762 forKeys:keys | |
| 7763 count:count] autorel
ease]; | |
| 7764 } | |
| 7765 | |
| 7766 + (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary
{ | |
| 7767 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7768 // on to get the type correct. | |
| 7769 return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 7770 } | |
| 7771 | |
| 7772 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 7773 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 7774 } | |
| 7775 | |
| 7776 - (instancetype)init { | |
| 7777 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7778 } | |
| 7779 | |
| 7780 - (instancetype)initWithValues:(const uint64_t [])values | |
| 7781 forKeys:(const int64_t [])keys | |
| 7782 count:(NSUInteger)count { | |
| 7783 self = [super init]; | |
| 7784 if (self) { | |
| 7785 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 7786 if (count && values && keys) { | |
| 7787 for (NSUInteger i = 0; i < count; ++i) { | |
| 7788 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 7789 } | |
| 7790 } | |
| 7791 } | |
| 7792 return self; | |
| 7793 } | |
| 7794 | |
| 7795 - (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary { | |
| 7796 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7797 if (self) { | |
| 7798 if (dictionary) { | |
| 7799 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 7800 } | |
| 7801 } | |
| 7802 return self; | |
| 7803 } | |
| 7804 | |
| 7805 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 7806 #pragma unused(numItems) | |
| 7807 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7808 } | |
| 7809 | |
| 7810 - (void)dealloc { | |
| 7811 NSAssert(!_autocreator, | |
| 7812 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 7813 [self class], _autocreator); | |
| 7814 [_dictionary release]; | |
| 7815 [super dealloc]; | |
| 7816 } | |
| 7817 | |
| 7818 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 7819 return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 7820 } | |
| 7821 | |
| 7822 - (BOOL)isEqual:(GPBInt64UInt64Dictionary *)other { | |
| 7823 if (self == other) { | |
| 7824 return YES; | |
| 7825 } | |
| 7826 if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) { | |
| 7827 return NO; | |
| 7828 } | |
| 7829 return [_dictionary isEqual:other->_dictionary]; | |
| 7830 } | |
| 7831 | |
| 7832 - (NSUInteger)hash { | |
| 7833 return _dictionary.count; | |
| 7834 } | |
| 7835 | |
| 7836 - (NSString *)description { | |
| 7837 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 7838 } | |
| 7839 | |
| 7840 - (NSUInteger)count { | |
| 7841 return _dictionary.count; | |
| 7842 } | |
| 7843 | |
| 7844 - (void)enumerateKeysAndValuesUsingBlock: | |
| 7845 (void (^)(int64_t key, uint64_t value, BOOL *stop))block { | |
| 7846 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7847 NSNumber *aValue, | |
| 7848 BOOL *stop) { | |
| 7849 block([aKey longLongValue], [aValue unsignedLongLongValue], stop); | |
| 7850 }]; | |
| 7851 } | |
| 7852 | |
| 7853 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 7854 NSUInteger count = _dictionary.count; | |
| 7855 if (count == 0) { | |
| 7856 return 0; | |
| 7857 } | |
| 7858 | |
| 7859 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 7860 GPBDataType keyDataType = field.mapKeyDataType; | |
| 7861 __block size_t result = 0; | |
| 7862 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7863 NSNumber *aValue, | |
| 7864 BOOL *stop) { | |
| 7865 #pragma unused(stop) | |
| 7866 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 7867 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapVa
lueFieldNumber, valueDataType); | |
| 7868 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 7869 }]; | |
| 7870 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 7871 result += tagSize * count; | |
| 7872 return result; | |
| 7873 } | |
| 7874 | |
| 7875 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 7876 asField:(GPBFieldDescriptor *)field { | |
| 7877 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 7878 GPBDataType keyDataType = field.mapKeyDataType; | |
| 7879 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 7880 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 7881 NSNumber *aValue, | |
| 7882 BOOL *stop) { | |
| 7883 #pragma unused(stop) | |
| 7884 // Write the tag. | |
| 7885 [outputStream writeInt32NoTag:tag]; | |
| 7886 // Write the size of the message. | |
| 7887 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 7888 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapVa
lueFieldNumber, valueDataType); | |
| 7889 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 7890 // Write the fields. | |
| 7891 WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber,
keyDataType); | |
| 7892 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | |
| 7893 }]; | |
| 7894 } | |
| 7895 | |
| 7896 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 7897 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 7898 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)]; | |
| 7899 } | |
| 7900 | |
| 7901 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 7902 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, uint64_t value, BOOL *st
op) { | |
| 7903 #pragma unused(stop) | |
| 7904 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%llu", value]); | |
| 7905 }]; | |
| 7906 } | |
| 7907 | |
| 7908 - (BOOL)valueForKey:(int64_t)key value:(uint64_t *)value { | |
| 7909 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 7910 if (wrapped && value) { | |
| 7911 *value = [wrapped unsignedLongLongValue]; | |
| 7912 } | |
| 7913 return (wrapped != NULL); | |
| 7914 } | |
| 7915 | |
| 7916 - (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary { | |
| 7917 if (otherDictionary) { | |
| 7918 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 7919 if (_autocreator) { | |
| 7920 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 7921 } | |
| 7922 } | |
| 7923 } | |
| 7924 | |
| 7925 - (void)setValue:(uint64_t)value forKey:(int64_t)key { | |
| 7926 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 7927 if (_autocreator) { | |
| 7928 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 7929 } | |
| 7930 } | |
| 7931 | |
| 7932 - (void)removeValueForKey:(int64_t)aKey { | |
| 7933 [_dictionary removeObjectForKey:@(aKey)]; | |
| 7934 } | |
| 7935 | |
| 7936 - (void)removeAll { | |
| 7937 [_dictionary removeAllObjects]; | |
| 7938 } | |
| 7939 | |
| 7940 @end | |
| 7941 | |
| 7942 #pragma mark - Int64 -> Int64 | |
| 7943 | |
| 7944 @implementation GPBInt64Int64Dictionary { | |
| 7945 @package | |
| 7946 NSMutableDictionary *_dictionary; | |
| 7947 } | |
| 7948 | |
| 7949 + (instancetype)dictionary { | |
| 7950 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 7951 } | |
| 7952 | |
| 7953 + (instancetype)dictionaryWithValue:(int64_t)value | |
| 7954 forKey:(int64_t)key { | |
| 7955 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7956 // on to get the type correct. | |
| 7957 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithValues:&value | |
| 7958 forKeys:&key | |
| 7959 count:1] autorelease]
; | |
| 7960 } | |
| 7961 | |
| 7962 + (instancetype)dictionaryWithValues:(const int64_t [])values | |
| 7963 forKeys:(const int64_t [])keys | |
| 7964 count:(NSUInteger)count { | |
| 7965 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7966 // on to get the type correct. | |
| 7967 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithValues:values | |
| 7968 forKeys:keys | |
| 7969 count:count] autorele
ase]; | |
| 7970 } | |
| 7971 | |
| 7972 + (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary { | |
| 7973 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 7974 // on to get the type correct. | |
| 7975 return [[(GPBInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 7976 } | |
| 7977 | |
| 7978 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 7979 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 7980 } | |
| 7981 | |
| 7982 - (instancetype)init { | |
| 7983 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 7984 } | |
| 7985 | |
| 7986 - (instancetype)initWithValues:(const int64_t [])values | |
| 7987 forKeys:(const int64_t [])keys | |
| 7988 count:(NSUInteger)count { | |
| 7989 self = [super init]; | |
| 7990 if (self) { | |
| 7991 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 7992 if (count && values && keys) { | |
| 7993 for (NSUInteger i = 0; i < count; ++i) { | |
| 7994 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 7995 } | |
| 7996 } | |
| 7997 } | |
| 7998 return self; | |
| 7999 } | |
| 8000 | |
| 8001 - (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary { | |
| 8002 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 8003 if (self) { | |
| 8004 if (dictionary) { | |
| 8005 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 8006 } | |
| 8007 } | |
| 8008 return self; | |
| 8009 } | |
| 8010 | |
| 8011 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 8012 #pragma unused(numItems) | |
| 8013 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 8014 } | |
| 8015 | |
| 8016 - (void)dealloc { | |
| 8017 NSAssert(!_autocreator, | |
| 8018 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 8019 [self class], _autocreator); | |
| 8020 [_dictionary release]; | |
| 8021 [super dealloc]; | |
| 8022 } | |
| 8023 | |
| 8024 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 8025 return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]; | |
| 8026 } | |
| 8027 | |
| 8028 - (BOOL)isEqual:(GPBInt64Int64Dictionary *)other { | |
| 8029 if (self == other) { | |
| 8030 return YES; | |
| 8031 } | |
| 8032 if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) { | |
| 8033 return NO; | |
| 8034 } | |
| 8035 return [_dictionary isEqual:other->_dictionary]; | |
| 8036 } | |
| 8037 | |
| 8038 - (NSUInteger)hash { | |
| 8039 return _dictionary.count; | |
| 8040 } | |
| 8041 | |
| 8042 - (NSString *)description { | |
| 8043 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 8044 } | |
| 8045 | |
| 8046 - (NSUInteger)count { | |
| 8047 return _dictionary.count; | |
| 8048 } | |
| 8049 | |
| 8050 - (void)enumerateKeysAndValuesUsingBlock: | |
| 8051 (void (^)(int64_t key, int64_t value, BOOL *stop))block { | |
| 8052 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8053 NSNumber *aValue, | |
| 8054 BOOL *stop) { | |
| 8055 block([aKey longLongValue], [aValue longLongValue], stop); | |
| 8056 }]; | |
| 8057 } | |
| 8058 | |
| 8059 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 8060 NSUInteger count = _dictionary.count; | |
| 8061 if (count == 0) { | |
| 8062 return 0; | |
| 8063 } | |
| 8064 | |
| 8065 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 8066 GPBDataType keyDataType = field.mapKeyDataType; | |
| 8067 __block size_t result = 0; | |
| 8068 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8069 NSNumber *aValue, | |
| 8070 BOOL *stop) { | |
| 8071 #pragma unused(stop) | |
| 8072 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 8073 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldN
umber, valueDataType); | |
| 8074 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 8075 }]; | |
| 8076 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 8077 result += tagSize * count; | |
| 8078 return result; | |
| 8079 } | |
| 8080 | |
| 8081 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 8082 asField:(GPBFieldDescriptor *)field { | |
| 8083 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 8084 GPBDataType keyDataType = field.mapKeyDataType; | |
| 8085 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 8086 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8087 NSNumber *aValue, | |
| 8088 BOOL *stop) { | |
| 8089 #pragma unused(stop) | |
| 8090 // Write the tag. | |
| 8091 [outputStream writeInt32NoTag:tag]; | |
| 8092 // Write the size of the message. | |
| 8093 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 8094 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldN
umber, valueDataType); | |
| 8095 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 8096 // Write the fields. | |
| 8097 WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber,
keyDataType); | |
| 8098 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | |
| 8099 }]; | |
| 8100 } | |
| 8101 | |
| 8102 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 8103 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 8104 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)]; | |
| 8105 } | |
| 8106 | |
| 8107 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 8108 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, int64_t value, BOOL *sto
p) { | |
| 8109 #pragma unused(stop) | |
| 8110 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%lld", value]); | |
| 8111 }]; | |
| 8112 } | |
| 8113 | |
| 8114 - (BOOL)valueForKey:(int64_t)key value:(int64_t *)value { | |
| 8115 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 8116 if (wrapped && value) { | |
| 8117 *value = [wrapped longLongValue]; | |
| 8118 } | |
| 8119 return (wrapped != NULL); | |
| 8120 } | |
| 8121 | |
| 8122 - (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary { | |
| 8123 if (otherDictionary) { | |
| 8124 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 8125 if (_autocreator) { | |
| 8126 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 8127 } | |
| 8128 } | |
| 8129 } | |
| 8130 | |
| 8131 - (void)setValue:(int64_t)value forKey:(int64_t)key { | |
| 8132 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 8133 if (_autocreator) { | |
| 8134 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 8135 } | |
| 8136 } | |
| 8137 | |
| 8138 - (void)removeValueForKey:(int64_t)aKey { | |
| 8139 [_dictionary removeObjectForKey:@(aKey)]; | |
| 8140 } | |
| 8141 | |
| 8142 - (void)removeAll { | |
| 8143 [_dictionary removeAllObjects]; | |
| 8144 } | |
| 8145 | |
| 8146 @end | |
| 8147 | |
| 8148 #pragma mark - Int64 -> Bool | |
| 8149 | |
| 8150 @implementation GPBInt64BoolDictionary { | |
| 8151 @package | |
| 8152 NSMutableDictionary *_dictionary; | |
| 8153 } | |
| 8154 | |
| 8155 + (instancetype)dictionary { | |
| 8156 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 8157 } | |
| 8158 | |
| 8159 + (instancetype)dictionaryWithValue:(BOOL)value | |
| 8160 forKey:(int64_t)key { | |
| 8161 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8162 // on to get the type correct. | |
| 8163 return [[(GPBInt64BoolDictionary*)[self alloc] initWithValues:&value | |
| 8164 forKeys:&key | |
| 8165 count:1] autorelease]; | |
| 8166 } | |
| 8167 | |
| 8168 + (instancetype)dictionaryWithValues:(const BOOL [])values | |
| 8169 forKeys:(const int64_t [])keys | |
| 8170 count:(NSUInteger)count { | |
| 8171 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8172 // on to get the type correct. | |
| 8173 return [[(GPBInt64BoolDictionary*)[self alloc] initWithValues:values | |
| 8174 forKeys:keys | |
| 8175 count:count] autorelea
se]; | |
| 8176 } | |
| 8177 | |
| 8178 + (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary { | |
| 8179 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8180 // on to get the type correct. | |
| 8181 return [[(GPBInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 8182 } | |
| 8183 | |
| 8184 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 8185 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 8186 } | |
| 8187 | |
| 8188 - (instancetype)init { | |
| 8189 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 8190 } | |
| 8191 | |
| 8192 - (instancetype)initWithValues:(const BOOL [])values | |
| 8193 forKeys:(const int64_t [])keys | |
| 8194 count:(NSUInteger)count { | |
| 8195 self = [super init]; | |
| 8196 if (self) { | |
| 8197 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 8198 if (count && values && keys) { | |
| 8199 for (NSUInteger i = 0; i < count; ++i) { | |
| 8200 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 8201 } | |
| 8202 } | |
| 8203 } | |
| 8204 return self; | |
| 8205 } | |
| 8206 | |
| 8207 - (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary { | |
| 8208 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 8209 if (self) { | |
| 8210 if (dictionary) { | |
| 8211 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 8212 } | |
| 8213 } | |
| 8214 return self; | |
| 8215 } | |
| 8216 | |
| 8217 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 8218 #pragma unused(numItems) | |
| 8219 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 8220 } | |
| 8221 | |
| 8222 - (void)dealloc { | |
| 8223 NSAssert(!_autocreator, | |
| 8224 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 8225 [self class], _autocreator); | |
| 8226 [_dictionary release]; | |
| 8227 [super dealloc]; | |
| 8228 } | |
| 8229 | |
| 8230 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 8231 return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 8232 } | |
| 8233 | |
| 8234 - (BOOL)isEqual:(GPBInt64BoolDictionary *)other { | |
| 8235 if (self == other) { | |
| 8236 return YES; | |
| 8237 } | |
| 8238 if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) { | |
| 8239 return NO; | |
| 8240 } | |
| 8241 return [_dictionary isEqual:other->_dictionary]; | |
| 8242 } | |
| 8243 | |
| 8244 - (NSUInteger)hash { | |
| 8245 return _dictionary.count; | |
| 8246 } | |
| 8247 | |
| 8248 - (NSString *)description { | |
| 8249 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 8250 } | |
| 8251 | |
| 8252 - (NSUInteger)count { | |
| 8253 return _dictionary.count; | |
| 8254 } | |
| 8255 | |
| 8256 - (void)enumerateKeysAndValuesUsingBlock: | |
| 8257 (void (^)(int64_t key, BOOL value, BOOL *stop))block { | |
| 8258 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8259 NSNumber *aValue, | |
| 8260 BOOL *stop) { | |
| 8261 block([aKey longLongValue], [aValue boolValue], stop); | |
| 8262 }]; | |
| 8263 } | |
| 8264 | |
| 8265 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 8266 NSUInteger count = _dictionary.count; | |
| 8267 if (count == 0) { | |
| 8268 return 0; | |
| 8269 } | |
| 8270 | |
| 8271 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 8272 GPBDataType keyDataType = field.mapKeyDataType; | |
| 8273 __block size_t result = 0; | |
| 8274 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8275 NSNumber *aValue, | |
| 8276 BOOL *stop) { | |
| 8277 #pragma unused(stop) | |
| 8278 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 8279 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber
, valueDataType); | |
| 8280 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 8281 }]; | |
| 8282 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 8283 result += tagSize * count; | |
| 8284 return result; | |
| 8285 } | |
| 8286 | |
| 8287 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 8288 asField:(GPBFieldDescriptor *)field { | |
| 8289 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 8290 GPBDataType keyDataType = field.mapKeyDataType; | |
| 8291 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 8292 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8293 NSNumber *aValue, | |
| 8294 BOOL *stop) { | |
| 8295 #pragma unused(stop) | |
| 8296 // Write the tag. | |
| 8297 [outputStream writeInt32NoTag:tag]; | |
| 8298 // Write the size of the message. | |
| 8299 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 8300 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber
, valueDataType); | |
| 8301 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 8302 // Write the fields. | |
| 8303 WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber,
keyDataType); | |
| 8304 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | |
| 8305 }]; | |
| 8306 } | |
| 8307 | |
| 8308 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 8309 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 8310 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)]; | |
| 8311 } | |
| 8312 | |
| 8313 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 8314 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, BOOL value, BOOL *stop)
{ | |
| 8315 #pragma unused(stop) | |
| 8316 block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false
")); | |
| 8317 }]; | |
| 8318 } | |
| 8319 | |
| 8320 - (BOOL)valueForKey:(int64_t)key value:(BOOL *)value { | |
| 8321 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 8322 if (wrapped && value) { | |
| 8323 *value = [wrapped boolValue]; | |
| 8324 } | |
| 8325 return (wrapped != NULL); | |
| 8326 } | |
| 8327 | |
| 8328 - (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary { | |
| 8329 if (otherDictionary) { | |
| 8330 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 8331 if (_autocreator) { | |
| 8332 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 8333 } | |
| 8334 } | |
| 8335 } | |
| 8336 | |
| 8337 - (void)setValue:(BOOL)value forKey:(int64_t)key { | |
| 8338 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 8339 if (_autocreator) { | |
| 8340 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 8341 } | |
| 8342 } | |
| 8343 | |
| 8344 - (void)removeValueForKey:(int64_t)aKey { | |
| 8345 [_dictionary removeObjectForKey:@(aKey)]; | |
| 8346 } | |
| 8347 | |
| 8348 - (void)removeAll { | |
| 8349 [_dictionary removeAllObjects]; | |
| 8350 } | |
| 8351 | |
| 8352 @end | |
| 8353 | |
| 8354 #pragma mark - Int64 -> Float | |
| 8355 | |
| 8356 @implementation GPBInt64FloatDictionary { | |
| 8357 @package | |
| 8358 NSMutableDictionary *_dictionary; | |
| 8359 } | |
| 8360 | |
| 8361 + (instancetype)dictionary { | |
| 8362 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 8363 } | |
| 8364 | |
| 8365 + (instancetype)dictionaryWithValue:(float)value | |
| 8366 forKey:(int64_t)key { | |
| 8367 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8368 // on to get the type correct. | |
| 8369 return [[(GPBInt64FloatDictionary*)[self alloc] initWithValues:&value | |
| 8370 forKeys:&key | |
| 8371 count:1] autorelease]
; | |
| 8372 } | |
| 8373 | |
| 8374 + (instancetype)dictionaryWithValues:(const float [])values | |
| 8375 forKeys:(const int64_t [])keys | |
| 8376 count:(NSUInteger)count { | |
| 8377 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8378 // on to get the type correct. | |
| 8379 return [[(GPBInt64FloatDictionary*)[self alloc] initWithValues:values | |
| 8380 forKeys:keys | |
| 8381 count:count] autorele
ase]; | |
| 8382 } | |
| 8383 | |
| 8384 + (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary { | |
| 8385 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8386 // on to get the type correct. | |
| 8387 return [[(GPBInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 8388 } | |
| 8389 | |
| 8390 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 8391 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 8392 } | |
| 8393 | |
| 8394 - (instancetype)init { | |
| 8395 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 8396 } | |
| 8397 | |
| 8398 - (instancetype)initWithValues:(const float [])values | |
| 8399 forKeys:(const int64_t [])keys | |
| 8400 count:(NSUInteger)count { | |
| 8401 self = [super init]; | |
| 8402 if (self) { | |
| 8403 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 8404 if (count && values && keys) { | |
| 8405 for (NSUInteger i = 0; i < count; ++i) { | |
| 8406 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 8407 } | |
| 8408 } | |
| 8409 } | |
| 8410 return self; | |
| 8411 } | |
| 8412 | |
| 8413 - (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary { | |
| 8414 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 8415 if (self) { | |
| 8416 if (dictionary) { | |
| 8417 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 8418 } | |
| 8419 } | |
| 8420 return self; | |
| 8421 } | |
| 8422 | |
| 8423 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 8424 #pragma unused(numItems) | |
| 8425 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 8426 } | |
| 8427 | |
| 8428 - (void)dealloc { | |
| 8429 NSAssert(!_autocreator, | |
| 8430 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 8431 [self class], _autocreator); | |
| 8432 [_dictionary release]; | |
| 8433 [super dealloc]; | |
| 8434 } | |
| 8435 | |
| 8436 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 8437 return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 8438 } | |
| 8439 | |
| 8440 - (BOOL)isEqual:(GPBInt64FloatDictionary *)other { | |
| 8441 if (self == other) { | |
| 8442 return YES; | |
| 8443 } | |
| 8444 if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) { | |
| 8445 return NO; | |
| 8446 } | |
| 8447 return [_dictionary isEqual:other->_dictionary]; | |
| 8448 } | |
| 8449 | |
| 8450 - (NSUInteger)hash { | |
| 8451 return _dictionary.count; | |
| 8452 } | |
| 8453 | |
| 8454 - (NSString *)description { | |
| 8455 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 8456 } | |
| 8457 | |
| 8458 - (NSUInteger)count { | |
| 8459 return _dictionary.count; | |
| 8460 } | |
| 8461 | |
| 8462 - (void)enumerateKeysAndValuesUsingBlock: | |
| 8463 (void (^)(int64_t key, float value, BOOL *stop))block { | |
| 8464 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8465 NSNumber *aValue, | |
| 8466 BOOL *stop) { | |
| 8467 block([aKey longLongValue], [aValue floatValue], stop); | |
| 8468 }]; | |
| 8469 } | |
| 8470 | |
| 8471 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 8472 NSUInteger count = _dictionary.count; | |
| 8473 if (count == 0) { | |
| 8474 return 0; | |
| 8475 } | |
| 8476 | |
| 8477 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 8478 GPBDataType keyDataType = field.mapKeyDataType; | |
| 8479 __block size_t result = 0; | |
| 8480 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8481 NSNumber *aValue, | |
| 8482 BOOL *stop) { | |
| 8483 #pragma unused(stop) | |
| 8484 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 8485 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumb
er, valueDataType); | |
| 8486 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 8487 }]; | |
| 8488 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 8489 result += tagSize * count; | |
| 8490 return result; | |
| 8491 } | |
| 8492 | |
| 8493 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 8494 asField:(GPBFieldDescriptor *)field { | |
| 8495 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 8496 GPBDataType keyDataType = field.mapKeyDataType; | |
| 8497 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 8498 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8499 NSNumber *aValue, | |
| 8500 BOOL *stop) { | |
| 8501 #pragma unused(stop) | |
| 8502 // Write the tag. | |
| 8503 [outputStream writeInt32NoTag:tag]; | |
| 8504 // Write the size of the message. | |
| 8505 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 8506 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumb
er, valueDataType); | |
| 8507 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 8508 // Write the fields. | |
| 8509 WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber,
keyDataType); | |
| 8510 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | |
| 8511 }]; | |
| 8512 } | |
| 8513 | |
| 8514 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 8515 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 8516 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)]; | |
| 8517 } | |
| 8518 | |
| 8519 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 8520 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, float value, BOOL *stop)
{ | |
| 8521 #pragma unused(stop) | |
| 8522 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%.*g", FLT_DIG, value]); | |
| 8523 }]; | |
| 8524 } | |
| 8525 | |
| 8526 - (BOOL)valueForKey:(int64_t)key value:(float *)value { | |
| 8527 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 8528 if (wrapped && value) { | |
| 8529 *value = [wrapped floatValue]; | |
| 8530 } | |
| 8531 return (wrapped != NULL); | |
| 8532 } | |
| 8533 | |
| 8534 - (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary { | |
| 8535 if (otherDictionary) { | |
| 8536 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 8537 if (_autocreator) { | |
| 8538 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 8539 } | |
| 8540 } | |
| 8541 } | |
| 8542 | |
| 8543 - (void)setValue:(float)value forKey:(int64_t)key { | |
| 8544 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 8545 if (_autocreator) { | |
| 8546 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 8547 } | |
| 8548 } | |
| 8549 | |
| 8550 - (void)removeValueForKey:(int64_t)aKey { | |
| 8551 [_dictionary removeObjectForKey:@(aKey)]; | |
| 8552 } | |
| 8553 | |
| 8554 - (void)removeAll { | |
| 8555 [_dictionary removeAllObjects]; | |
| 8556 } | |
| 8557 | |
| 8558 @end | |
| 8559 | |
| 8560 #pragma mark - Int64 -> Double | |
| 8561 | |
| 8562 @implementation GPBInt64DoubleDictionary { | |
| 8563 @package | |
| 8564 NSMutableDictionary *_dictionary; | |
| 8565 } | |
| 8566 | |
| 8567 + (instancetype)dictionary { | |
| 8568 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 8569 } | |
| 8570 | |
| 8571 + (instancetype)dictionaryWithValue:(double)value | |
| 8572 forKey:(int64_t)key { | |
| 8573 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8574 // on to get the type correct. | |
| 8575 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithValues:&value | |
| 8576 forKeys:&key | |
| 8577 count:1] autorelease
]; | |
| 8578 } | |
| 8579 | |
| 8580 + (instancetype)dictionaryWithValues:(const double [])values | |
| 8581 forKeys:(const int64_t [])keys | |
| 8582 count:(NSUInteger)count { | |
| 8583 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8584 // on to get the type correct. | |
| 8585 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithValues:values | |
| 8586 forKeys:keys | |
| 8587 count:count] autorel
ease]; | |
| 8588 } | |
| 8589 | |
| 8590 + (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary
{ | |
| 8591 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8592 // on to get the type correct. | |
| 8593 return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 8594 } | |
| 8595 | |
| 8596 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 8597 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 8598 } | |
| 8599 | |
| 8600 - (instancetype)init { | |
| 8601 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 8602 } | |
| 8603 | |
| 8604 - (instancetype)initWithValues:(const double [])values | |
| 8605 forKeys:(const int64_t [])keys | |
| 8606 count:(NSUInteger)count { | |
| 8607 self = [super init]; | |
| 8608 if (self) { | |
| 8609 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 8610 if (count && values && keys) { | |
| 8611 for (NSUInteger i = 0; i < count; ++i) { | |
| 8612 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; | |
| 8613 } | |
| 8614 } | |
| 8615 } | |
| 8616 return self; | |
| 8617 } | |
| 8618 | |
| 8619 - (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary { | |
| 8620 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 8621 if (self) { | |
| 8622 if (dictionary) { | |
| 8623 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 8624 } | |
| 8625 } | |
| 8626 return self; | |
| 8627 } | |
| 8628 | |
| 8629 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 8630 #pragma unused(numItems) | |
| 8631 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 8632 } | |
| 8633 | |
| 8634 - (void)dealloc { | |
| 8635 NSAssert(!_autocreator, | |
| 8636 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 8637 [self class], _autocreator); | |
| 8638 [_dictionary release]; | |
| 8639 [super dealloc]; | |
| 8640 } | |
| 8641 | |
| 8642 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 8643 return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 8644 } | |
| 8645 | |
| 8646 - (BOOL)isEqual:(GPBInt64DoubleDictionary *)other { | |
| 8647 if (self == other) { | |
| 8648 return YES; | |
| 8649 } | |
| 8650 if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) { | |
| 8651 return NO; | |
| 8652 } | |
| 8653 return [_dictionary isEqual:other->_dictionary]; | |
| 8654 } | |
| 8655 | |
| 8656 - (NSUInteger)hash { | |
| 8657 return _dictionary.count; | |
| 8658 } | |
| 8659 | |
| 8660 - (NSString *)description { | |
| 8661 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 8662 } | |
| 8663 | |
| 8664 - (NSUInteger)count { | |
| 8665 return _dictionary.count; | |
| 8666 } | |
| 8667 | |
| 8668 - (void)enumerateKeysAndValuesUsingBlock: | |
| 8669 (void (^)(int64_t key, double value, BOOL *stop))block { | |
| 8670 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8671 NSNumber *aValue, | |
| 8672 BOOL *stop) { | |
| 8673 block([aKey longLongValue], [aValue doubleValue], stop); | |
| 8674 }]; | |
| 8675 } | |
| 8676 | |
| 8677 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 8678 NSUInteger count = _dictionary.count; | |
| 8679 if (count == 0) { | |
| 8680 return 0; | |
| 8681 } | |
| 8682 | |
| 8683 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 8684 GPBDataType keyDataType = field.mapKeyDataType; | |
| 8685 __block size_t result = 0; | |
| 8686 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8687 NSNumber *aValue, | |
| 8688 BOOL *stop) { | |
| 8689 #pragma unused(stop) | |
| 8690 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 8691 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNu
mber, valueDataType); | |
| 8692 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 8693 }]; | |
| 8694 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 8695 result += tagSize * count; | |
| 8696 return result; | |
| 8697 } | |
| 8698 | |
| 8699 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 8700 asField:(GPBFieldDescriptor *)field { | |
| 8701 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 8702 GPBDataType keyDataType = field.mapKeyDataType; | |
| 8703 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 8704 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8705 NSNumber *aValue, | |
| 8706 BOOL *stop) { | |
| 8707 #pragma unused(stop) | |
| 8708 // Write the tag. | |
| 8709 [outputStream writeInt32NoTag:tag]; | |
| 8710 // Write the size of the message. | |
| 8711 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 8712 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNu
mber, valueDataType); | |
| 8713 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 8714 // Write the fields. | |
| 8715 WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber,
keyDataType); | |
| 8716 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | |
| 8717 }]; | |
| 8718 } | |
| 8719 | |
| 8720 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 8721 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 8722 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)]; | |
| 8723 } | |
| 8724 | |
| 8725 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 8726 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, double value, BOOL *stop
) { | |
| 8727 #pragma unused(stop) | |
| 8728 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat
:@"%.*lg", DBL_DIG, value]); | |
| 8729 }]; | |
| 8730 } | |
| 8731 | |
| 8732 - (BOOL)valueForKey:(int64_t)key value:(double *)value { | |
| 8733 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 8734 if (wrapped && value) { | |
| 8735 *value = [wrapped doubleValue]; | |
| 8736 } | |
| 8737 return (wrapped != NULL); | |
| 8738 } | |
| 8739 | |
| 8740 - (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary { | |
| 8741 if (otherDictionary) { | |
| 8742 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 8743 if (_autocreator) { | |
| 8744 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 8745 } | |
| 8746 } | |
| 8747 } | |
| 8748 | |
| 8749 - (void)setValue:(double)value forKey:(int64_t)key { | |
| 8750 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 8751 if (_autocreator) { | |
| 8752 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 8753 } | |
| 8754 } | |
| 8755 | |
| 8756 - (void)removeValueForKey:(int64_t)aKey { | |
| 8757 [_dictionary removeObjectForKey:@(aKey)]; | |
| 8758 } | |
| 8759 | |
| 8760 - (void)removeAll { | |
| 8761 [_dictionary removeAllObjects]; | |
| 8762 } | |
| 8763 | |
| 8764 @end | |
| 8765 | |
| 8766 #pragma mark - Int64 -> Enum | |
| 8767 | |
| 8768 @implementation GPBInt64EnumDictionary { | |
| 8769 @package | |
| 8770 NSMutableDictionary *_dictionary; | |
| 8771 GPBEnumValidationFunc _validationFunc; | |
| 8772 } | |
| 8773 | |
| 8774 @synthesize validationFunc = _validationFunc; | |
| 8775 | |
| 8776 + (instancetype)dictionary { | |
| 8777 return [[[self alloc] initWithValidationFunction:NULL | |
| 8778 rawValues:NULL | |
| 8779 forKeys:NULL | |
| 8780 count:0] autorelease]; | |
| 8781 } | |
| 8782 | |
| 8783 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 8784 return [[[self alloc] initWithValidationFunction:func | |
| 8785 rawValues:NULL | |
| 8786 forKeys:NULL | |
| 8787 count:0] autorelease]; | |
| 8788 } | |
| 8789 | |
| 8790 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 8791 rawValue:(int32_t)rawValue | |
| 8792 forKey:(int64_t)key { | |
| 8793 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8794 // on to get the type correct. | |
| 8795 return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:func | |
| 8796 rawValues:&raw
Value | |
| 8797 forKeys:&key | |
| 8798 count:1] a
utorelease]; | |
| 8799 } | |
| 8800 | |
| 8801 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 8802 rawValues:(const int32_t [])rawValues | |
| 8803 forKeys:(const int64_t [])keys | |
| 8804 count:(NSUInteger)count { | |
| 8805 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8806 // on to get the type correct. | |
| 8807 return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:func | |
| 8808 rawValues:rawV
alues | |
| 8809 forKeys:keys | |
| 8810 count:coun
t] autorelease]; | |
| 8811 } | |
| 8812 | |
| 8813 + (instancetype)dictionaryWithDictionary:(GPBInt64EnumDictionary *)dictionary { | |
| 8814 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 8815 // on to get the type correct. | |
| 8816 return [[(GPBInt64EnumDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 8817 } | |
| 8818 | |
| 8819 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 8820 capacity:(NSUInteger)numItems { | |
| 8821 return [[[self alloc] initWithValidationFunction:func capacity:numItems] autor
elease]; | |
| 8822 } | |
| 8823 | |
| 8824 - (instancetype)init { | |
| 8825 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count
:0]; | |
| 8826 } | |
| 8827 | |
| 8828 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 8829 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 8830 } | |
| 8831 | |
| 8832 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 8833 rawValues:(const int32_t [])rawValues | |
| 8834 forKeys:(const int64_t [])keys | |
| 8835 count:(NSUInteger)count { | |
| 8836 self = [super init]; | |
| 8837 if (self) { | |
| 8838 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 8839 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); | |
| 8840 if (count && rawValues && keys) { | |
| 8841 for (NSUInteger i = 0; i < count; ++i) { | |
| 8842 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])]; | |
| 8843 } | |
| 8844 } | |
| 8845 } | |
| 8846 return self; | |
| 8847 } | |
| 8848 | |
| 8849 - (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary { | |
| 8850 self = [self initWithValidationFunction:dictionary.validationFunc | |
| 8851 rawValues:NULL | |
| 8852 forKeys:NULL | |
| 8853 count:0]; | |
| 8854 if (self) { | |
| 8855 if (dictionary) { | |
| 8856 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 8857 } | |
| 8858 } | |
| 8859 return self; | |
| 8860 } | |
| 8861 | |
| 8862 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 8863 capacity:(NSUInteger)numItems { | |
| 8864 #pragma unused(numItems) | |
| 8865 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 8866 } | |
| 8867 | |
| 8868 - (void)dealloc { | |
| 8869 NSAssert(!_autocreator, | |
| 8870 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 8871 [self class], _autocreator); | |
| 8872 [_dictionary release]; | |
| 8873 [super dealloc]; | |
| 8874 } | |
| 8875 | |
| 8876 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 8877 return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 8878 } | |
| 8879 | |
| 8880 - (BOOL)isEqual:(GPBInt64EnumDictionary *)other { | |
| 8881 if (self == other) { | |
| 8882 return YES; | |
| 8883 } | |
| 8884 if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) { | |
| 8885 return NO; | |
| 8886 } | |
| 8887 return [_dictionary isEqual:other->_dictionary]; | |
| 8888 } | |
| 8889 | |
| 8890 - (NSUInteger)hash { | |
| 8891 return _dictionary.count; | |
| 8892 } | |
| 8893 | |
| 8894 - (NSString *)description { | |
| 8895 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 8896 } | |
| 8897 | |
| 8898 - (NSUInteger)count { | |
| 8899 return _dictionary.count; | |
| 8900 } | |
| 8901 | |
| 8902 - (void)enumerateKeysAndRawValuesUsingBlock: | |
| 8903 (void (^)(int64_t key, int32_t value, BOOL *stop))block { | |
| 8904 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8905 NSNumber *aValue, | |
| 8906 BOOL *stop) { | |
| 8907 block([aKey longLongValue], [aValue intValue], stop); | |
| 8908 }]; | |
| 8909 } | |
| 8910 | |
| 8911 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 8912 NSUInteger count = _dictionary.count; | |
| 8913 if (count == 0) { | |
| 8914 return 0; | |
| 8915 } | |
| 8916 | |
| 8917 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 8918 GPBDataType keyDataType = field.mapKeyDataType; | |
| 8919 __block size_t result = 0; | |
| 8920 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8921 NSNumber *aValue, | |
| 8922 BOOL *stop) { | |
| 8923 #pragma unused(stop) | |
| 8924 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 8925 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber,
valueDataType); | |
| 8926 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 8927 }]; | |
| 8928 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 8929 result += tagSize * count; | |
| 8930 return result; | |
| 8931 } | |
| 8932 | |
| 8933 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 8934 asField:(GPBFieldDescriptor *)field { | |
| 8935 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 8936 GPBDataType keyDataType = field.mapKeyDataType; | |
| 8937 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 8938 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 8939 NSNumber *aValue, | |
| 8940 BOOL *stop) { | |
| 8941 #pragma unused(stop) | |
| 8942 // Write the tag. | |
| 8943 [outputStream writeInt32NoTag:tag]; | |
| 8944 // Write the size of the message. | |
| 8945 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 8946 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber,
valueDataType); | |
| 8947 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 8948 // Write the fields. | |
| 8949 WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber,
keyDataType); | |
| 8950 WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, va
lueDataType); | |
| 8951 }]; | |
| 8952 } | |
| 8953 | |
| 8954 - (NSData *)serializedDataForUnknownValue:(int32_t)value | |
| 8955 forKey:(GPBGenericValue *)key | |
| 8956 keyDataType:(GPBDataType)keyDataType { | |
| 8957 size_t msgSize = ComputeDictInt64FieldSize(key->valueInt64, kMapKeyFieldNumber
, keyDataType); | |
| 8958 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEn
um); | |
| 8959 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; | |
| 8960 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithDat
a:data]; | |
| 8961 WriteDictInt64Field(outputStream, key->valueInt64, kMapKeyFieldNumber, keyData
Type); | |
| 8962 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum)
; | |
| 8963 [outputStream release]; | |
| 8964 return data; | |
| 8965 } | |
| 8966 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 8967 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 8968 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)]; | |
| 8969 } | |
| 8970 | |
| 8971 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 8972 [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *
stop) { | |
| 8973 #pragma unused(stop) | |
| 8974 block([NSString stringWithFormat:@"%lld", key], @(value)); | |
| 8975 }]; | |
| 8976 } | |
| 8977 | |
| 8978 - (BOOL)valueForKey:(int64_t)key value:(int32_t *)value { | |
| 8979 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 8980 if (wrapped && value) { | |
| 8981 int32_t result = [wrapped intValue]; | |
| 8982 if (!_validationFunc(result)) { | |
| 8983 result = kGPBUnrecognizedEnumeratorValue; | |
| 8984 } | |
| 8985 *value = result; | |
| 8986 } | |
| 8987 return (wrapped != NULL); | |
| 8988 } | |
| 8989 | |
| 8990 - (BOOL)valueForKey:(int64_t)key rawValue:(int32_t *)rawValue { | |
| 8991 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; | |
| 8992 if (wrapped && rawValue) { | |
| 8993 *rawValue = [wrapped intValue]; | |
| 8994 } | |
| 8995 return (wrapped != NULL); | |
| 8996 } | |
| 8997 | |
| 8998 - (void)enumerateKeysAndValuesUsingBlock: | |
| 8999 (void (^)(int64_t key, int32_t value, BOOL *stop))block { | |
| 9000 GPBEnumValidationFunc func = _validationFunc; | |
| 9001 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 9002 NSNumber *aValue, | |
| 9003 BOOL *stop) { | |
| 9004 int32_t unwrapped = [aValue intValue]; | |
| 9005 if (!func(unwrapped)) { | |
| 9006 unwrapped = kGPBUnrecognizedEnumeratorValue; | |
| 9007 } | |
| 9008 block([aKey longLongValue], unwrapped, stop); | |
| 9009 }]; | |
| 9010 } | |
| 9011 | |
| 9012 - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary { | |
| 9013 if (otherDictionary) { | |
| 9014 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 9015 if (_autocreator) { | |
| 9016 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 9017 } | |
| 9018 } | |
| 9019 } | |
| 9020 | |
| 9021 - (void)setRawValue:(int32_t)value forKey:(int64_t)key { | |
| 9022 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 9023 if (_autocreator) { | |
| 9024 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 9025 } | |
| 9026 } | |
| 9027 | |
| 9028 - (void)removeValueForKey:(int64_t)aKey { | |
| 9029 [_dictionary removeObjectForKey:@(aKey)]; | |
| 9030 } | |
| 9031 | |
| 9032 - (void)removeAll { | |
| 9033 [_dictionary removeAllObjects]; | |
| 9034 } | |
| 9035 | |
| 9036 - (void)setValue:(int32_t)value forKey:(int64_t)key { | |
| 9037 if (!_validationFunc(value)) { | |
| 9038 [NSException raise:NSInvalidArgumentException | |
| 9039 format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum
value (%d)", | |
| 9040 value]; | |
| 9041 } | |
| 9042 | |
| 9043 [_dictionary setObject:@(value) forKey:@(key)]; | |
| 9044 if (_autocreator) { | |
| 9045 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 9046 } | |
| 9047 } | |
| 9048 | |
| 9049 @end | |
| 9050 | |
| 9051 #pragma mark - Int64 -> Object | |
| 9052 | |
| 9053 @implementation GPBInt64ObjectDictionary { | |
| 9054 @package | |
| 9055 NSMutableDictionary *_dictionary; | |
| 9056 } | |
| 9057 | |
| 9058 + (instancetype)dictionary { | |
| 9059 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 9060 } | |
| 9061 | |
| 9062 + (instancetype)dictionaryWithValue:(id)value | |
| 9063 forKey:(int64_t)key { | |
| 9064 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9065 // on to get the type correct. | |
| 9066 return [[(GPBInt64ObjectDictionary*)[self alloc] initWithValues:&value | |
| 9067 forKeys:&key | |
| 9068 count:1] autorelease
]; | |
| 9069 } | |
| 9070 | |
| 9071 + (instancetype)dictionaryWithValues:(const id [])values | |
| 9072 forKeys:(const int64_t [])keys | |
| 9073 count:(NSUInteger)count { | |
| 9074 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9075 // on to get the type correct. | |
| 9076 return [[(GPBInt64ObjectDictionary*)[self alloc] initWithValues:values | |
| 9077 forKeys:keys | |
| 9078 count:count] autorel
ease]; | |
| 9079 } | |
| 9080 | |
| 9081 + (instancetype)dictionaryWithDictionary:(GPBInt64ObjectDictionary *)dictionary
{ | |
| 9082 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9083 // on to get the type correct. | |
| 9084 return [[(GPBInt64ObjectDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 9085 } | |
| 9086 | |
| 9087 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 9088 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 9089 } | |
| 9090 | |
| 9091 - (instancetype)init { | |
| 9092 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9093 } | |
| 9094 | |
| 9095 - (instancetype)initWithValues:(const id [])values | |
| 9096 forKeys:(const int64_t [])keys | |
| 9097 count:(NSUInteger)count { | |
| 9098 self = [super init]; | |
| 9099 if (self) { | |
| 9100 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 9101 if (count && values && keys) { | |
| 9102 for (NSUInteger i = 0; i < count; ++i) { | |
| 9103 [_dictionary setObject:values[i] forKey:@(keys[i])]; | |
| 9104 } | |
| 9105 } | |
| 9106 } | |
| 9107 return self; | |
| 9108 } | |
| 9109 | |
| 9110 - (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary { | |
| 9111 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9112 if (self) { | |
| 9113 if (dictionary) { | |
| 9114 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 9115 } | |
| 9116 } | |
| 9117 return self; | |
| 9118 } | |
| 9119 | |
| 9120 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 9121 #pragma unused(numItems) | |
| 9122 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9123 } | |
| 9124 | |
| 9125 - (void)dealloc { | |
| 9126 NSAssert(!_autocreator, | |
| 9127 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 9128 [self class], _autocreator); | |
| 9129 [_dictionary release]; | |
| 9130 [super dealloc]; | |
| 9131 } | |
| 9132 | |
| 9133 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 9134 return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 9135 } | |
| 9136 | |
| 9137 - (BOOL)isEqual:(GPBInt64ObjectDictionary *)other { | |
| 9138 if (self == other) { | |
| 9139 return YES; | |
| 9140 } | |
| 9141 if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) { | |
| 9142 return NO; | |
| 9143 } | |
| 9144 return [_dictionary isEqual:other->_dictionary]; | |
| 9145 } | |
| 9146 | |
| 9147 - (NSUInteger)hash { | |
| 9148 return _dictionary.count; | |
| 9149 } | |
| 9150 | |
| 9151 - (NSString *)description { | |
| 9152 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 9153 } | |
| 9154 | |
| 9155 - (NSUInteger)count { | |
| 9156 return _dictionary.count; | |
| 9157 } | |
| 9158 | |
| 9159 - (void)enumerateKeysAndValuesUsingBlock: | |
| 9160 (void (^)(int64_t key, id value, BOOL *stop))block { | |
| 9161 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 9162 id aValue, | |
| 9163 BOOL *stop) { | |
| 9164 block([aKey longLongValue], aValue, stop); | |
| 9165 }]; | |
| 9166 } | |
| 9167 | |
| 9168 - (BOOL)isInitialized { | |
| 9169 for (GPBMessage *msg in [_dictionary objectEnumerator]) { | |
| 9170 if (!msg.initialized) { | |
| 9171 return NO; | |
| 9172 } | |
| 9173 } | |
| 9174 return YES; | |
| 9175 } | |
| 9176 | |
| 9177 - (instancetype)deepCopyWithZone:(NSZone *)zone { | |
| 9178 GPBInt64ObjectDictionary *newDict = | |
| 9179 [[GPBInt64ObjectDictionary alloc] init]; | |
| 9180 [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey, | |
| 9181 GPBMessage *msg, | |
| 9182 BOOL *stop) { | |
| 9183 #pragma unused(stop) | |
| 9184 GPBMessage *copiedMsg = [msg copyWithZone:zone]; | |
| 9185 [newDict->_dictionary setObject:copiedMsg forKey:aKey]; | |
| 9186 [copiedMsg release]; | |
| 9187 }]; | |
| 9188 return newDict; | |
| 9189 } | |
| 9190 | |
| 9191 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 9192 NSUInteger count = _dictionary.count; | |
| 9193 if (count == 0) { | |
| 9194 return 0; | |
| 9195 } | |
| 9196 | |
| 9197 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 9198 GPBDataType keyDataType = field.mapKeyDataType; | |
| 9199 __block size_t result = 0; | |
| 9200 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 9201 id aValue, | |
| 9202 BOOL *stop) { | |
| 9203 #pragma unused(stop) | |
| 9204 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 9205 msgSize += ComputeDictObjectFieldSize(aValue, kMapValueFieldNumber, valueDat
aType); | |
| 9206 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 9207 }]; | |
| 9208 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 9209 result += tagSize * count; | |
| 9210 return result; | |
| 9211 } | |
| 9212 | |
| 9213 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 9214 asField:(GPBFieldDescriptor *)field { | |
| 9215 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 9216 GPBDataType keyDataType = field.mapKeyDataType; | |
| 9217 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 9218 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, | |
| 9219 id aValue, | |
| 9220 BOOL *stop) { | |
| 9221 #pragma unused(stop) | |
| 9222 // Write the tag. | |
| 9223 [outputStream writeInt32NoTag:tag]; | |
| 9224 // Write the size of the message. | |
| 9225 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFiel
dNumber, keyDataType); | |
| 9226 msgSize += ComputeDictObjectFieldSize(aValue, kMapValueFieldNumber, valueDat
aType); | |
| 9227 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 9228 // Write the fields. | |
| 9229 WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber,
keyDataType); | |
| 9230 WriteDictObjectField(outputStream, aValue, kMapValueFieldNumber, valueDataTy
pe); | |
| 9231 }]; | |
| 9232 } | |
| 9233 | |
| 9234 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 9235 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 9236 [_dictionary setObject:value->valueString forKey:@(key->valueInt64)]; | |
| 9237 } | |
| 9238 | |
| 9239 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 9240 [self enumerateKeysAndValuesUsingBlock:^(int64_t key, id value, BOOL *stop) { | |
| 9241 #pragma unused(stop) | |
| 9242 block([NSString stringWithFormat:@"%lld", key], value); | |
| 9243 }]; | |
| 9244 } | |
| 9245 | |
| 9246 - (id)valueForKey:(int64_t)key { | |
| 9247 id result = [_dictionary objectForKey:@(key)]; | |
| 9248 return result; | |
| 9249 } | |
| 9250 | |
| 9251 - (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary { | |
| 9252 if (otherDictionary) { | |
| 9253 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 9254 if (_autocreator) { | |
| 9255 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 9256 } | |
| 9257 } | |
| 9258 } | |
| 9259 | |
| 9260 - (void)setValue:(id)value forKey:(int64_t)key { | |
| 9261 [_dictionary setObject:value forKey:@(key)]; | |
| 9262 if (_autocreator) { | |
| 9263 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 9264 } | |
| 9265 } | |
| 9266 | |
| 9267 - (void)removeValueForKey:(int64_t)aKey { | |
| 9268 [_dictionary removeObjectForKey:@(aKey)]; | |
| 9269 } | |
| 9270 | |
| 9271 - (void)removeAll { | |
| 9272 [_dictionary removeAllObjects]; | |
| 9273 } | |
| 9274 | |
| 9275 @end | |
| 9276 | |
| 9277 //%PDDM-EXPAND DICTIONARY_POD_IMPL_FOR_KEY(String, NSString, *, OBJECT) | |
| 9278 // This block of code is generated, do not edit it directly. | |
| 9279 | |
| 9280 #pragma mark - String -> UInt32 | |
| 9281 | |
| 9282 @implementation GPBStringUInt32Dictionary { | |
| 9283 @package | |
| 9284 NSMutableDictionary *_dictionary; | |
| 9285 } | |
| 9286 | |
| 9287 + (instancetype)dictionary { | |
| 9288 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 9289 } | |
| 9290 | |
| 9291 + (instancetype)dictionaryWithValue:(uint32_t)value | |
| 9292 forKey:(NSString *)key { | |
| 9293 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9294 // on to get the type correct. | |
| 9295 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithValues:&value | |
| 9296 forKeys:&key | |
| 9297 count:1] autoreleas
e]; | |
| 9298 } | |
| 9299 | |
| 9300 + (instancetype)dictionaryWithValues:(const uint32_t [])values | |
| 9301 forKeys:(const NSString * [])keys | |
| 9302 count:(NSUInteger)count { | |
| 9303 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9304 // on to get the type correct. | |
| 9305 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithValues:values | |
| 9306 forKeys:keys | |
| 9307 count:count] autore
lease]; | |
| 9308 } | |
| 9309 | |
| 9310 + (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary
{ | |
| 9311 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9312 // on to get the type correct. | |
| 9313 return [[(GPBStringUInt32Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | |
| 9314 } | |
| 9315 | |
| 9316 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 9317 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 9318 } | |
| 9319 | |
| 9320 - (instancetype)init { | |
| 9321 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9322 } | |
| 9323 | |
| 9324 - (instancetype)initWithValues:(const uint32_t [])values | |
| 9325 forKeys:(const NSString * [])keys | |
| 9326 count:(NSUInteger)count { | |
| 9327 self = [super init]; | |
| 9328 if (self) { | |
| 9329 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 9330 if (count && values && keys) { | |
| 9331 for (NSUInteger i = 0; i < count; ++i) { | |
| 9332 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | |
| 9333 } | |
| 9334 } | |
| 9335 } | |
| 9336 return self; | |
| 9337 } | |
| 9338 | |
| 9339 - (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary { | |
| 9340 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9341 if (self) { | |
| 9342 if (dictionary) { | |
| 9343 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 9344 } | |
| 9345 } | |
| 9346 return self; | |
| 9347 } | |
| 9348 | |
| 9349 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 9350 #pragma unused(numItems) | |
| 9351 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9352 } | |
| 9353 | |
| 9354 - (void)dealloc { | |
| 9355 NSAssert(!_autocreator, | |
| 9356 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 9357 [self class], _autocreator); | |
| 9358 [_dictionary release]; | |
| 9359 [super dealloc]; | |
| 9360 } | |
| 9361 | |
| 9362 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 9363 return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self
]; | |
| 9364 } | |
| 9365 | |
| 9366 - (BOOL)isEqual:(GPBStringUInt32Dictionary *)other { | |
| 9367 if (self == other) { | |
| 9368 return YES; | |
| 9369 } | |
| 9370 if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) { | |
| 9371 return NO; | |
| 9372 } | |
| 9373 return [_dictionary isEqual:other->_dictionary]; | |
| 9374 } | |
| 9375 | |
| 9376 - (NSUInteger)hash { | |
| 9377 return _dictionary.count; | |
| 9378 } | |
| 9379 | |
| 9380 - (NSString *)description { | |
| 9381 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 9382 } | |
| 9383 | |
| 9384 - (NSUInteger)count { | |
| 9385 return _dictionary.count; | |
| 9386 } | |
| 9387 | |
| 9388 - (void)enumerateKeysAndValuesUsingBlock: | |
| 9389 (void (^)(NSString *key, uint32_t value, BOOL *stop))block { | |
| 9390 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 9391 NSNumber *aValue, | |
| 9392 BOOL *stop) { | |
| 9393 block(aKey, [aValue unsignedIntValue], stop); | |
| 9394 }]; | |
| 9395 } | |
| 9396 | |
| 9397 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 9398 NSUInteger count = _dictionary.count; | |
| 9399 if (count == 0) { | |
| 9400 return 0; | |
| 9401 } | |
| 9402 | |
| 9403 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 9404 GPBDataType keyDataType = field.mapKeyDataType; | |
| 9405 __block size_t result = 0; | |
| 9406 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 9407 NSNumber *aValue, | |
| 9408 BOOL *stop) { | |
| 9409 #pragma unused(stop) | |
| 9410 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 9411 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFi
eldNumber, valueDataType); | |
| 9412 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 9413 }]; | |
| 9414 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 9415 result += tagSize * count; | |
| 9416 return result; | |
| 9417 } | |
| 9418 | |
| 9419 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 9420 asField:(GPBFieldDescriptor *)field { | |
| 9421 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 9422 GPBDataType keyDataType = field.mapKeyDataType; | |
| 9423 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 9424 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 9425 NSNumber *aValue, | |
| 9426 BOOL *stop) { | |
| 9427 #pragma unused(stop) | |
| 9428 // Write the tag. | |
| 9429 [outputStream writeInt32NoTag:tag]; | |
| 9430 // Write the size of the message. | |
| 9431 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 9432 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFi
eldNumber, valueDataType); | |
| 9433 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 9434 // Write the fields. | |
| 9435 WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); | |
| 9436 WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueField
Number, valueDataType); | |
| 9437 }]; | |
| 9438 } | |
| 9439 | |
| 9440 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 9441 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 9442 [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString]; | |
| 9443 } | |
| 9444 | |
| 9445 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 9446 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, uint32_t value, BOOL *
stop) { | |
| 9447 #pragma unused(stop) | |
| 9448 block(key, [NSString stringWithFormat:@"%u", value]); | |
| 9449 }]; | |
| 9450 } | |
| 9451 | |
| 9452 - (BOOL)valueForKey:(NSString *)key value:(uint32_t *)value { | |
| 9453 NSNumber *wrapped = [_dictionary objectForKey:key]; | |
| 9454 if (wrapped && value) { | |
| 9455 *value = [wrapped unsignedIntValue]; | |
| 9456 } | |
| 9457 return (wrapped != NULL); | |
| 9458 } | |
| 9459 | |
| 9460 - (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary { | |
| 9461 if (otherDictionary) { | |
| 9462 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 9463 if (_autocreator) { | |
| 9464 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 9465 } | |
| 9466 } | |
| 9467 } | |
| 9468 | |
| 9469 - (void)setValue:(uint32_t)value forKey:(NSString *)key { | |
| 9470 [_dictionary setObject:@(value) forKey:key]; | |
| 9471 if (_autocreator) { | |
| 9472 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 9473 } | |
| 9474 } | |
| 9475 | |
| 9476 - (void)removeValueForKey:(NSString *)aKey { | |
| 9477 [_dictionary removeObjectForKey:aKey]; | |
| 9478 } | |
| 9479 | |
| 9480 - (void)removeAll { | |
| 9481 [_dictionary removeAllObjects]; | |
| 9482 } | |
| 9483 | |
| 9484 @end | |
| 9485 | |
| 9486 #pragma mark - String -> Int32 | |
| 9487 | |
| 9488 @implementation GPBStringInt32Dictionary { | |
| 9489 @package | |
| 9490 NSMutableDictionary *_dictionary; | |
| 9491 } | |
| 9492 | |
| 9493 + (instancetype)dictionary { | |
| 9494 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 9495 } | |
| 9496 | |
| 9497 + (instancetype)dictionaryWithValue:(int32_t)value | |
| 9498 forKey:(NSString *)key { | |
| 9499 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9500 // on to get the type correct. | |
| 9501 return [[(GPBStringInt32Dictionary*)[self alloc] initWithValues:&value | |
| 9502 forKeys:&key | |
| 9503 count:1] autorelease
]; | |
| 9504 } | |
| 9505 | |
| 9506 + (instancetype)dictionaryWithValues:(const int32_t [])values | |
| 9507 forKeys:(const NSString * [])keys | |
| 9508 count:(NSUInteger)count { | |
| 9509 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9510 // on to get the type correct. | |
| 9511 return [[(GPBStringInt32Dictionary*)[self alloc] initWithValues:values | |
| 9512 forKeys:keys | |
| 9513 count:count] autorel
ease]; | |
| 9514 } | |
| 9515 | |
| 9516 + (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary
{ | |
| 9517 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9518 // on to get the type correct. | |
| 9519 return [[(GPBStringInt32Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 9520 } | |
| 9521 | |
| 9522 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 9523 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 9524 } | |
| 9525 | |
| 9526 - (instancetype)init { | |
| 9527 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9528 } | |
| 9529 | |
| 9530 - (instancetype)initWithValues:(const int32_t [])values | |
| 9531 forKeys:(const NSString * [])keys | |
| 9532 count:(NSUInteger)count { | |
| 9533 self = [super init]; | |
| 9534 if (self) { | |
| 9535 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 9536 if (count && values && keys) { | |
| 9537 for (NSUInteger i = 0; i < count; ++i) { | |
| 9538 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | |
| 9539 } | |
| 9540 } | |
| 9541 } | |
| 9542 return self; | |
| 9543 } | |
| 9544 | |
| 9545 - (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary { | |
| 9546 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9547 if (self) { | |
| 9548 if (dictionary) { | |
| 9549 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 9550 } | |
| 9551 } | |
| 9552 return self; | |
| 9553 } | |
| 9554 | |
| 9555 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 9556 #pragma unused(numItems) | |
| 9557 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9558 } | |
| 9559 | |
| 9560 - (void)dealloc { | |
| 9561 NSAssert(!_autocreator, | |
| 9562 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 9563 [self class], _autocreator); | |
| 9564 [_dictionary release]; | |
| 9565 [super dealloc]; | |
| 9566 } | |
| 9567 | |
| 9568 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 9569 return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 9570 } | |
| 9571 | |
| 9572 - (BOOL)isEqual:(GPBStringInt32Dictionary *)other { | |
| 9573 if (self == other) { | |
| 9574 return YES; | |
| 9575 } | |
| 9576 if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) { | |
| 9577 return NO; | |
| 9578 } | |
| 9579 return [_dictionary isEqual:other->_dictionary]; | |
| 9580 } | |
| 9581 | |
| 9582 - (NSUInteger)hash { | |
| 9583 return _dictionary.count; | |
| 9584 } | |
| 9585 | |
| 9586 - (NSString *)description { | |
| 9587 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 9588 } | |
| 9589 | |
| 9590 - (NSUInteger)count { | |
| 9591 return _dictionary.count; | |
| 9592 } | |
| 9593 | |
| 9594 - (void)enumerateKeysAndValuesUsingBlock: | |
| 9595 (void (^)(NSString *key, int32_t value, BOOL *stop))block { | |
| 9596 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 9597 NSNumber *aValue, | |
| 9598 BOOL *stop) { | |
| 9599 block(aKey, [aValue intValue], stop); | |
| 9600 }]; | |
| 9601 } | |
| 9602 | |
| 9603 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 9604 NSUInteger count = _dictionary.count; | |
| 9605 if (count == 0) { | |
| 9606 return 0; | |
| 9607 } | |
| 9608 | |
| 9609 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 9610 GPBDataType keyDataType = field.mapKeyDataType; | |
| 9611 __block size_t result = 0; | |
| 9612 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 9613 NSNumber *aValue, | |
| 9614 BOOL *stop) { | |
| 9615 #pragma unused(stop) | |
| 9616 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 9617 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber
, valueDataType); | |
| 9618 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 9619 }]; | |
| 9620 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 9621 result += tagSize * count; | |
| 9622 return result; | |
| 9623 } | |
| 9624 | |
| 9625 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 9626 asField:(GPBFieldDescriptor *)field { | |
| 9627 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 9628 GPBDataType keyDataType = field.mapKeyDataType; | |
| 9629 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 9630 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 9631 NSNumber *aValue, | |
| 9632 BOOL *stop) { | |
| 9633 #pragma unused(stop) | |
| 9634 // Write the tag. | |
| 9635 [outputStream writeInt32NoTag:tag]; | |
| 9636 // Write the size of the message. | |
| 9637 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 9638 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber
, valueDataType); | |
| 9639 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 9640 // Write the fields. | |
| 9641 WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); | |
| 9642 WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, v
alueDataType); | |
| 9643 }]; | |
| 9644 } | |
| 9645 | |
| 9646 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 9647 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 9648 [_dictionary setObject:@(value->valueInt32) forKey:key->valueString]; | |
| 9649 } | |
| 9650 | |
| 9651 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 9652 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, int32_t value, BOOL *s
top) { | |
| 9653 #pragma unused(stop) | |
| 9654 block(key, [NSString stringWithFormat:@"%d", value]); | |
| 9655 }]; | |
| 9656 } | |
| 9657 | |
| 9658 - (BOOL)valueForKey:(NSString *)key value:(int32_t *)value { | |
| 9659 NSNumber *wrapped = [_dictionary objectForKey:key]; | |
| 9660 if (wrapped && value) { | |
| 9661 *value = [wrapped intValue]; | |
| 9662 } | |
| 9663 return (wrapped != NULL); | |
| 9664 } | |
| 9665 | |
| 9666 - (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary { | |
| 9667 if (otherDictionary) { | |
| 9668 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 9669 if (_autocreator) { | |
| 9670 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 9671 } | |
| 9672 } | |
| 9673 } | |
| 9674 | |
| 9675 - (void)setValue:(int32_t)value forKey:(NSString *)key { | |
| 9676 [_dictionary setObject:@(value) forKey:key]; | |
| 9677 if (_autocreator) { | |
| 9678 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 9679 } | |
| 9680 } | |
| 9681 | |
| 9682 - (void)removeValueForKey:(NSString *)aKey { | |
| 9683 [_dictionary removeObjectForKey:aKey]; | |
| 9684 } | |
| 9685 | |
| 9686 - (void)removeAll { | |
| 9687 [_dictionary removeAllObjects]; | |
| 9688 } | |
| 9689 | |
| 9690 @end | |
| 9691 | |
| 9692 #pragma mark - String -> UInt64 | |
| 9693 | |
| 9694 @implementation GPBStringUInt64Dictionary { | |
| 9695 @package | |
| 9696 NSMutableDictionary *_dictionary; | |
| 9697 } | |
| 9698 | |
| 9699 + (instancetype)dictionary { | |
| 9700 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 9701 } | |
| 9702 | |
| 9703 + (instancetype)dictionaryWithValue:(uint64_t)value | |
| 9704 forKey:(NSString *)key { | |
| 9705 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9706 // on to get the type correct. | |
| 9707 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithValues:&value | |
| 9708 forKeys:&key | |
| 9709 count:1] autoreleas
e]; | |
| 9710 } | |
| 9711 | |
| 9712 + (instancetype)dictionaryWithValues:(const uint64_t [])values | |
| 9713 forKeys:(const NSString * [])keys | |
| 9714 count:(NSUInteger)count { | |
| 9715 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9716 // on to get the type correct. | |
| 9717 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithValues:values | |
| 9718 forKeys:keys | |
| 9719 count:count] autore
lease]; | |
| 9720 } | |
| 9721 | |
| 9722 + (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary
{ | |
| 9723 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9724 // on to get the type correct. | |
| 9725 return [[(GPBStringUInt64Dictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | |
| 9726 } | |
| 9727 | |
| 9728 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 9729 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 9730 } | |
| 9731 | |
| 9732 - (instancetype)init { | |
| 9733 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9734 } | |
| 9735 | |
| 9736 - (instancetype)initWithValues:(const uint64_t [])values | |
| 9737 forKeys:(const NSString * [])keys | |
| 9738 count:(NSUInteger)count { | |
| 9739 self = [super init]; | |
| 9740 if (self) { | |
| 9741 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 9742 if (count && values && keys) { | |
| 9743 for (NSUInteger i = 0; i < count; ++i) { | |
| 9744 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | |
| 9745 } | |
| 9746 } | |
| 9747 } | |
| 9748 return self; | |
| 9749 } | |
| 9750 | |
| 9751 - (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary { | |
| 9752 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9753 if (self) { | |
| 9754 if (dictionary) { | |
| 9755 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 9756 } | |
| 9757 } | |
| 9758 return self; | |
| 9759 } | |
| 9760 | |
| 9761 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 9762 #pragma unused(numItems) | |
| 9763 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9764 } | |
| 9765 | |
| 9766 - (void)dealloc { | |
| 9767 NSAssert(!_autocreator, | |
| 9768 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 9769 [self class], _autocreator); | |
| 9770 [_dictionary release]; | |
| 9771 [super dealloc]; | |
| 9772 } | |
| 9773 | |
| 9774 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 9775 return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self
]; | |
| 9776 } | |
| 9777 | |
| 9778 - (BOOL)isEqual:(GPBStringUInt64Dictionary *)other { | |
| 9779 if (self == other) { | |
| 9780 return YES; | |
| 9781 } | |
| 9782 if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) { | |
| 9783 return NO; | |
| 9784 } | |
| 9785 return [_dictionary isEqual:other->_dictionary]; | |
| 9786 } | |
| 9787 | |
| 9788 - (NSUInteger)hash { | |
| 9789 return _dictionary.count; | |
| 9790 } | |
| 9791 | |
| 9792 - (NSString *)description { | |
| 9793 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 9794 } | |
| 9795 | |
| 9796 - (NSUInteger)count { | |
| 9797 return _dictionary.count; | |
| 9798 } | |
| 9799 | |
| 9800 - (void)enumerateKeysAndValuesUsingBlock: | |
| 9801 (void (^)(NSString *key, uint64_t value, BOOL *stop))block { | |
| 9802 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 9803 NSNumber *aValue, | |
| 9804 BOOL *stop) { | |
| 9805 block(aKey, [aValue unsignedLongLongValue], stop); | |
| 9806 }]; | |
| 9807 } | |
| 9808 | |
| 9809 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 9810 NSUInteger count = _dictionary.count; | |
| 9811 if (count == 0) { | |
| 9812 return 0; | |
| 9813 } | |
| 9814 | |
| 9815 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 9816 GPBDataType keyDataType = field.mapKeyDataType; | |
| 9817 __block size_t result = 0; | |
| 9818 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 9819 NSNumber *aValue, | |
| 9820 BOOL *stop) { | |
| 9821 #pragma unused(stop) | |
| 9822 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 9823 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapVa
lueFieldNumber, valueDataType); | |
| 9824 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 9825 }]; | |
| 9826 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 9827 result += tagSize * count; | |
| 9828 return result; | |
| 9829 } | |
| 9830 | |
| 9831 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 9832 asField:(GPBFieldDescriptor *)field { | |
| 9833 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 9834 GPBDataType keyDataType = field.mapKeyDataType; | |
| 9835 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 9836 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 9837 NSNumber *aValue, | |
| 9838 BOOL *stop) { | |
| 9839 #pragma unused(stop) | |
| 9840 // Write the tag. | |
| 9841 [outputStream writeInt32NoTag:tag]; | |
| 9842 // Write the size of the message. | |
| 9843 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 9844 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapVa
lueFieldNumber, valueDataType); | |
| 9845 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 9846 // Write the fields. | |
| 9847 WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); | |
| 9848 WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValue
FieldNumber, valueDataType); | |
| 9849 }]; | |
| 9850 } | |
| 9851 | |
| 9852 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 9853 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 9854 [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString]; | |
| 9855 } | |
| 9856 | |
| 9857 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 9858 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, uint64_t value, BOOL *
stop) { | |
| 9859 #pragma unused(stop) | |
| 9860 block(key, [NSString stringWithFormat:@"%llu", value]); | |
| 9861 }]; | |
| 9862 } | |
| 9863 | |
| 9864 - (BOOL)valueForKey:(NSString *)key value:(uint64_t *)value { | |
| 9865 NSNumber *wrapped = [_dictionary objectForKey:key]; | |
| 9866 if (wrapped && value) { | |
| 9867 *value = [wrapped unsignedLongLongValue]; | |
| 9868 } | |
| 9869 return (wrapped != NULL); | |
| 9870 } | |
| 9871 | |
| 9872 - (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary { | |
| 9873 if (otherDictionary) { | |
| 9874 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 9875 if (_autocreator) { | |
| 9876 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 9877 } | |
| 9878 } | |
| 9879 } | |
| 9880 | |
| 9881 - (void)setValue:(uint64_t)value forKey:(NSString *)key { | |
| 9882 [_dictionary setObject:@(value) forKey:key]; | |
| 9883 if (_autocreator) { | |
| 9884 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 9885 } | |
| 9886 } | |
| 9887 | |
| 9888 - (void)removeValueForKey:(NSString *)aKey { | |
| 9889 [_dictionary removeObjectForKey:aKey]; | |
| 9890 } | |
| 9891 | |
| 9892 - (void)removeAll { | |
| 9893 [_dictionary removeAllObjects]; | |
| 9894 } | |
| 9895 | |
| 9896 @end | |
| 9897 | |
| 9898 #pragma mark - String -> Int64 | |
| 9899 | |
| 9900 @implementation GPBStringInt64Dictionary { | |
| 9901 @package | |
| 9902 NSMutableDictionary *_dictionary; | |
| 9903 } | |
| 9904 | |
| 9905 + (instancetype)dictionary { | |
| 9906 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 9907 } | |
| 9908 | |
| 9909 + (instancetype)dictionaryWithValue:(int64_t)value | |
| 9910 forKey:(NSString *)key { | |
| 9911 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9912 // on to get the type correct. | |
| 9913 return [[(GPBStringInt64Dictionary*)[self alloc] initWithValues:&value | |
| 9914 forKeys:&key | |
| 9915 count:1] autorelease
]; | |
| 9916 } | |
| 9917 | |
| 9918 + (instancetype)dictionaryWithValues:(const int64_t [])values | |
| 9919 forKeys:(const NSString * [])keys | |
| 9920 count:(NSUInteger)count { | |
| 9921 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9922 // on to get the type correct. | |
| 9923 return [[(GPBStringInt64Dictionary*)[self alloc] initWithValues:values | |
| 9924 forKeys:keys | |
| 9925 count:count] autorel
ease]; | |
| 9926 } | |
| 9927 | |
| 9928 + (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary
{ | |
| 9929 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 9930 // on to get the type correct. | |
| 9931 return [[(GPBStringInt64Dictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 9932 } | |
| 9933 | |
| 9934 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 9935 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 9936 } | |
| 9937 | |
| 9938 - (instancetype)init { | |
| 9939 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9940 } | |
| 9941 | |
| 9942 - (instancetype)initWithValues:(const int64_t [])values | |
| 9943 forKeys:(const NSString * [])keys | |
| 9944 count:(NSUInteger)count { | |
| 9945 self = [super init]; | |
| 9946 if (self) { | |
| 9947 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 9948 if (count && values && keys) { | |
| 9949 for (NSUInteger i = 0; i < count; ++i) { | |
| 9950 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | |
| 9951 } | |
| 9952 } | |
| 9953 } | |
| 9954 return self; | |
| 9955 } | |
| 9956 | |
| 9957 - (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary { | |
| 9958 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9959 if (self) { | |
| 9960 if (dictionary) { | |
| 9961 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 9962 } | |
| 9963 } | |
| 9964 return self; | |
| 9965 } | |
| 9966 | |
| 9967 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 9968 #pragma unused(numItems) | |
| 9969 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 9970 } | |
| 9971 | |
| 9972 - (void)dealloc { | |
| 9973 NSAssert(!_autocreator, | |
| 9974 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 9975 [self class], _autocreator); | |
| 9976 [_dictionary release]; | |
| 9977 [super dealloc]; | |
| 9978 } | |
| 9979 | |
| 9980 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 9981 return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 9982 } | |
| 9983 | |
| 9984 - (BOOL)isEqual:(GPBStringInt64Dictionary *)other { | |
| 9985 if (self == other) { | |
| 9986 return YES; | |
| 9987 } | |
| 9988 if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) { | |
| 9989 return NO; | |
| 9990 } | |
| 9991 return [_dictionary isEqual:other->_dictionary]; | |
| 9992 } | |
| 9993 | |
| 9994 - (NSUInteger)hash { | |
| 9995 return _dictionary.count; | |
| 9996 } | |
| 9997 | |
| 9998 - (NSString *)description { | |
| 9999 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 10000 } | |
| 10001 | |
| 10002 - (NSUInteger)count { | |
| 10003 return _dictionary.count; | |
| 10004 } | |
| 10005 | |
| 10006 - (void)enumerateKeysAndValuesUsingBlock: | |
| 10007 (void (^)(NSString *key, int64_t value, BOOL *stop))block { | |
| 10008 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10009 NSNumber *aValue, | |
| 10010 BOOL *stop) { | |
| 10011 block(aKey, [aValue longLongValue], stop); | |
| 10012 }]; | |
| 10013 } | |
| 10014 | |
| 10015 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 10016 NSUInteger count = _dictionary.count; | |
| 10017 if (count == 0) { | |
| 10018 return 0; | |
| 10019 } | |
| 10020 | |
| 10021 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 10022 GPBDataType keyDataType = field.mapKeyDataType; | |
| 10023 __block size_t result = 0; | |
| 10024 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10025 NSNumber *aValue, | |
| 10026 BOOL *stop) { | |
| 10027 #pragma unused(stop) | |
| 10028 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 10029 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldN
umber, valueDataType); | |
| 10030 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 10031 }]; | |
| 10032 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 10033 result += tagSize * count; | |
| 10034 return result; | |
| 10035 } | |
| 10036 | |
| 10037 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 10038 asField:(GPBFieldDescriptor *)field { | |
| 10039 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 10040 GPBDataType keyDataType = field.mapKeyDataType; | |
| 10041 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 10042 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10043 NSNumber *aValue, | |
| 10044 BOOL *stop) { | |
| 10045 #pragma unused(stop) | |
| 10046 // Write the tag. | |
| 10047 [outputStream writeInt32NoTag:tag]; | |
| 10048 // Write the size of the message. | |
| 10049 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 10050 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldN
umber, valueDataType); | |
| 10051 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 10052 // Write the fields. | |
| 10053 WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); | |
| 10054 WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumb
er, valueDataType); | |
| 10055 }]; | |
| 10056 } | |
| 10057 | |
| 10058 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 10059 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 10060 [_dictionary setObject:@(value->valueInt64) forKey:key->valueString]; | |
| 10061 } | |
| 10062 | |
| 10063 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 10064 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, int64_t value, BOOL *s
top) { | |
| 10065 #pragma unused(stop) | |
| 10066 block(key, [NSString stringWithFormat:@"%lld", value]); | |
| 10067 }]; | |
| 10068 } | |
| 10069 | |
| 10070 - (BOOL)valueForKey:(NSString *)key value:(int64_t *)value { | |
| 10071 NSNumber *wrapped = [_dictionary objectForKey:key]; | |
| 10072 if (wrapped && value) { | |
| 10073 *value = [wrapped longLongValue]; | |
| 10074 } | |
| 10075 return (wrapped != NULL); | |
| 10076 } | |
| 10077 | |
| 10078 - (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary { | |
| 10079 if (otherDictionary) { | |
| 10080 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 10081 if (_autocreator) { | |
| 10082 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 10083 } | |
| 10084 } | |
| 10085 } | |
| 10086 | |
| 10087 - (void)setValue:(int64_t)value forKey:(NSString *)key { | |
| 10088 [_dictionary setObject:@(value) forKey:key]; | |
| 10089 if (_autocreator) { | |
| 10090 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 10091 } | |
| 10092 } | |
| 10093 | |
| 10094 - (void)removeValueForKey:(NSString *)aKey { | |
| 10095 [_dictionary removeObjectForKey:aKey]; | |
| 10096 } | |
| 10097 | |
| 10098 - (void)removeAll { | |
| 10099 [_dictionary removeAllObjects]; | |
| 10100 } | |
| 10101 | |
| 10102 @end | |
| 10103 | |
| 10104 #pragma mark - String -> Bool | |
| 10105 | |
| 10106 @implementation GPBStringBoolDictionary { | |
| 10107 @package | |
| 10108 NSMutableDictionary *_dictionary; | |
| 10109 } | |
| 10110 | |
| 10111 + (instancetype)dictionary { | |
| 10112 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 10113 } | |
| 10114 | |
| 10115 + (instancetype)dictionaryWithValue:(BOOL)value | |
| 10116 forKey:(NSString *)key { | |
| 10117 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10118 // on to get the type correct. | |
| 10119 return [[(GPBStringBoolDictionary*)[self alloc] initWithValues:&value | |
| 10120 forKeys:&key | |
| 10121 count:1] autorelease]
; | |
| 10122 } | |
| 10123 | |
| 10124 + (instancetype)dictionaryWithValues:(const BOOL [])values | |
| 10125 forKeys:(const NSString * [])keys | |
| 10126 count:(NSUInteger)count { | |
| 10127 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10128 // on to get the type correct. | |
| 10129 return [[(GPBStringBoolDictionary*)[self alloc] initWithValues:values | |
| 10130 forKeys:keys | |
| 10131 count:count] autorele
ase]; | |
| 10132 } | |
| 10133 | |
| 10134 + (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary { | |
| 10135 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10136 // on to get the type correct. | |
| 10137 return [[(GPBStringBoolDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 10138 } | |
| 10139 | |
| 10140 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 10141 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 10142 } | |
| 10143 | |
| 10144 - (instancetype)init { | |
| 10145 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 10146 } | |
| 10147 | |
| 10148 - (instancetype)initWithValues:(const BOOL [])values | |
| 10149 forKeys:(const NSString * [])keys | |
| 10150 count:(NSUInteger)count { | |
| 10151 self = [super init]; | |
| 10152 if (self) { | |
| 10153 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 10154 if (count && values && keys) { | |
| 10155 for (NSUInteger i = 0; i < count; ++i) { | |
| 10156 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | |
| 10157 } | |
| 10158 } | |
| 10159 } | |
| 10160 return self; | |
| 10161 } | |
| 10162 | |
| 10163 - (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary { | |
| 10164 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 10165 if (self) { | |
| 10166 if (dictionary) { | |
| 10167 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 10168 } | |
| 10169 } | |
| 10170 return self; | |
| 10171 } | |
| 10172 | |
| 10173 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 10174 #pragma unused(numItems) | |
| 10175 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 10176 } | |
| 10177 | |
| 10178 - (void)dealloc { | |
| 10179 NSAssert(!_autocreator, | |
| 10180 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 10181 [self class], _autocreator); | |
| 10182 [_dictionary release]; | |
| 10183 [super dealloc]; | |
| 10184 } | |
| 10185 | |
| 10186 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 10187 return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 10188 } | |
| 10189 | |
| 10190 - (BOOL)isEqual:(GPBStringBoolDictionary *)other { | |
| 10191 if (self == other) { | |
| 10192 return YES; | |
| 10193 } | |
| 10194 if (![other isKindOfClass:[GPBStringBoolDictionary class]]) { | |
| 10195 return NO; | |
| 10196 } | |
| 10197 return [_dictionary isEqual:other->_dictionary]; | |
| 10198 } | |
| 10199 | |
| 10200 - (NSUInteger)hash { | |
| 10201 return _dictionary.count; | |
| 10202 } | |
| 10203 | |
| 10204 - (NSString *)description { | |
| 10205 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 10206 } | |
| 10207 | |
| 10208 - (NSUInteger)count { | |
| 10209 return _dictionary.count; | |
| 10210 } | |
| 10211 | |
| 10212 - (void)enumerateKeysAndValuesUsingBlock: | |
| 10213 (void (^)(NSString *key, BOOL value, BOOL *stop))block { | |
| 10214 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10215 NSNumber *aValue, | |
| 10216 BOOL *stop) { | |
| 10217 block(aKey, [aValue boolValue], stop); | |
| 10218 }]; | |
| 10219 } | |
| 10220 | |
| 10221 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 10222 NSUInteger count = _dictionary.count; | |
| 10223 if (count == 0) { | |
| 10224 return 0; | |
| 10225 } | |
| 10226 | |
| 10227 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 10228 GPBDataType keyDataType = field.mapKeyDataType; | |
| 10229 __block size_t result = 0; | |
| 10230 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10231 NSNumber *aValue, | |
| 10232 BOOL *stop) { | |
| 10233 #pragma unused(stop) | |
| 10234 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 10235 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber
, valueDataType); | |
| 10236 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 10237 }]; | |
| 10238 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 10239 result += tagSize * count; | |
| 10240 return result; | |
| 10241 } | |
| 10242 | |
| 10243 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 10244 asField:(GPBFieldDescriptor *)field { | |
| 10245 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 10246 GPBDataType keyDataType = field.mapKeyDataType; | |
| 10247 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 10248 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10249 NSNumber *aValue, | |
| 10250 BOOL *stop) { | |
| 10251 #pragma unused(stop) | |
| 10252 // Write the tag. | |
| 10253 [outputStream writeInt32NoTag:tag]; | |
| 10254 // Write the size of the message. | |
| 10255 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 10256 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber
, valueDataType); | |
| 10257 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 10258 // Write the fields. | |
| 10259 WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); | |
| 10260 WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, v
alueDataType); | |
| 10261 }]; | |
| 10262 } | |
| 10263 | |
| 10264 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 10265 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 10266 [_dictionary setObject:@(value->valueBool) forKey:key->valueString]; | |
| 10267 } | |
| 10268 | |
| 10269 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 10270 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, BOOL value, BOOL *stop
) { | |
| 10271 #pragma unused(stop) | |
| 10272 block(key, (value ? @"true" : @"false")); | |
| 10273 }]; | |
| 10274 } | |
| 10275 | |
| 10276 - (BOOL)valueForKey:(NSString *)key value:(BOOL *)value { | |
| 10277 NSNumber *wrapped = [_dictionary objectForKey:key]; | |
| 10278 if (wrapped && value) { | |
| 10279 *value = [wrapped boolValue]; | |
| 10280 } | |
| 10281 return (wrapped != NULL); | |
| 10282 } | |
| 10283 | |
| 10284 - (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary { | |
| 10285 if (otherDictionary) { | |
| 10286 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 10287 if (_autocreator) { | |
| 10288 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 10289 } | |
| 10290 } | |
| 10291 } | |
| 10292 | |
| 10293 - (void)setValue:(BOOL)value forKey:(NSString *)key { | |
| 10294 [_dictionary setObject:@(value) forKey:key]; | |
| 10295 if (_autocreator) { | |
| 10296 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 10297 } | |
| 10298 } | |
| 10299 | |
| 10300 - (void)removeValueForKey:(NSString *)aKey { | |
| 10301 [_dictionary removeObjectForKey:aKey]; | |
| 10302 } | |
| 10303 | |
| 10304 - (void)removeAll { | |
| 10305 [_dictionary removeAllObjects]; | |
| 10306 } | |
| 10307 | |
| 10308 @end | |
| 10309 | |
| 10310 #pragma mark - String -> Float | |
| 10311 | |
| 10312 @implementation GPBStringFloatDictionary { | |
| 10313 @package | |
| 10314 NSMutableDictionary *_dictionary; | |
| 10315 } | |
| 10316 | |
| 10317 + (instancetype)dictionary { | |
| 10318 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 10319 } | |
| 10320 | |
| 10321 + (instancetype)dictionaryWithValue:(float)value | |
| 10322 forKey:(NSString *)key { | |
| 10323 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10324 // on to get the type correct. | |
| 10325 return [[(GPBStringFloatDictionary*)[self alloc] initWithValues:&value | |
| 10326 forKeys:&key | |
| 10327 count:1] autorelease
]; | |
| 10328 } | |
| 10329 | |
| 10330 + (instancetype)dictionaryWithValues:(const float [])values | |
| 10331 forKeys:(const NSString * [])keys | |
| 10332 count:(NSUInteger)count { | |
| 10333 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10334 // on to get the type correct. | |
| 10335 return [[(GPBStringFloatDictionary*)[self alloc] initWithValues:values | |
| 10336 forKeys:keys | |
| 10337 count:count] autorel
ease]; | |
| 10338 } | |
| 10339 | |
| 10340 + (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary
{ | |
| 10341 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10342 // on to get the type correct. | |
| 10343 return [[(GPBStringFloatDictionary*)[self alloc] initWithDictionary:dictionary
] autorelease]; | |
| 10344 } | |
| 10345 | |
| 10346 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 10347 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 10348 } | |
| 10349 | |
| 10350 - (instancetype)init { | |
| 10351 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 10352 } | |
| 10353 | |
| 10354 - (instancetype)initWithValues:(const float [])values | |
| 10355 forKeys:(const NSString * [])keys | |
| 10356 count:(NSUInteger)count { | |
| 10357 self = [super init]; | |
| 10358 if (self) { | |
| 10359 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 10360 if (count && values && keys) { | |
| 10361 for (NSUInteger i = 0; i < count; ++i) { | |
| 10362 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | |
| 10363 } | |
| 10364 } | |
| 10365 } | |
| 10366 return self; | |
| 10367 } | |
| 10368 | |
| 10369 - (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary { | |
| 10370 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 10371 if (self) { | |
| 10372 if (dictionary) { | |
| 10373 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 10374 } | |
| 10375 } | |
| 10376 return self; | |
| 10377 } | |
| 10378 | |
| 10379 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 10380 #pragma unused(numItems) | |
| 10381 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 10382 } | |
| 10383 | |
| 10384 - (void)dealloc { | |
| 10385 NSAssert(!_autocreator, | |
| 10386 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 10387 [self class], _autocreator); | |
| 10388 [_dictionary release]; | |
| 10389 [super dealloc]; | |
| 10390 } | |
| 10391 | |
| 10392 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 10393 return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self]
; | |
| 10394 } | |
| 10395 | |
| 10396 - (BOOL)isEqual:(GPBStringFloatDictionary *)other { | |
| 10397 if (self == other) { | |
| 10398 return YES; | |
| 10399 } | |
| 10400 if (![other isKindOfClass:[GPBStringFloatDictionary class]]) { | |
| 10401 return NO; | |
| 10402 } | |
| 10403 return [_dictionary isEqual:other->_dictionary]; | |
| 10404 } | |
| 10405 | |
| 10406 - (NSUInteger)hash { | |
| 10407 return _dictionary.count; | |
| 10408 } | |
| 10409 | |
| 10410 - (NSString *)description { | |
| 10411 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 10412 } | |
| 10413 | |
| 10414 - (NSUInteger)count { | |
| 10415 return _dictionary.count; | |
| 10416 } | |
| 10417 | |
| 10418 - (void)enumerateKeysAndValuesUsingBlock: | |
| 10419 (void (^)(NSString *key, float value, BOOL *stop))block { | |
| 10420 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10421 NSNumber *aValue, | |
| 10422 BOOL *stop) { | |
| 10423 block(aKey, [aValue floatValue], stop); | |
| 10424 }]; | |
| 10425 } | |
| 10426 | |
| 10427 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 10428 NSUInteger count = _dictionary.count; | |
| 10429 if (count == 0) { | |
| 10430 return 0; | |
| 10431 } | |
| 10432 | |
| 10433 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 10434 GPBDataType keyDataType = field.mapKeyDataType; | |
| 10435 __block size_t result = 0; | |
| 10436 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10437 NSNumber *aValue, | |
| 10438 BOOL *stop) { | |
| 10439 #pragma unused(stop) | |
| 10440 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 10441 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumb
er, valueDataType); | |
| 10442 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 10443 }]; | |
| 10444 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 10445 result += tagSize * count; | |
| 10446 return result; | |
| 10447 } | |
| 10448 | |
| 10449 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 10450 asField:(GPBFieldDescriptor *)field { | |
| 10451 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 10452 GPBDataType keyDataType = field.mapKeyDataType; | |
| 10453 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 10454 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10455 NSNumber *aValue, | |
| 10456 BOOL *stop) { | |
| 10457 #pragma unused(stop) | |
| 10458 // Write the tag. | |
| 10459 [outputStream writeInt32NoTag:tag]; | |
| 10460 // Write the size of the message. | |
| 10461 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 10462 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumb
er, valueDataType); | |
| 10463 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 10464 // Write the fields. | |
| 10465 WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); | |
| 10466 WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber,
valueDataType); | |
| 10467 }]; | |
| 10468 } | |
| 10469 | |
| 10470 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 10471 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 10472 [_dictionary setObject:@(value->valueFloat) forKey:key->valueString]; | |
| 10473 } | |
| 10474 | |
| 10475 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 10476 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, float value, BOOL *sto
p) { | |
| 10477 #pragma unused(stop) | |
| 10478 block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); | |
| 10479 }]; | |
| 10480 } | |
| 10481 | |
| 10482 - (BOOL)valueForKey:(NSString *)key value:(float *)value { | |
| 10483 NSNumber *wrapped = [_dictionary objectForKey:key]; | |
| 10484 if (wrapped && value) { | |
| 10485 *value = [wrapped floatValue]; | |
| 10486 } | |
| 10487 return (wrapped != NULL); | |
| 10488 } | |
| 10489 | |
| 10490 - (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary { | |
| 10491 if (otherDictionary) { | |
| 10492 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 10493 if (_autocreator) { | |
| 10494 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 10495 } | |
| 10496 } | |
| 10497 } | |
| 10498 | |
| 10499 - (void)setValue:(float)value forKey:(NSString *)key { | |
| 10500 [_dictionary setObject:@(value) forKey:key]; | |
| 10501 if (_autocreator) { | |
| 10502 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 10503 } | |
| 10504 } | |
| 10505 | |
| 10506 - (void)removeValueForKey:(NSString *)aKey { | |
| 10507 [_dictionary removeObjectForKey:aKey]; | |
| 10508 } | |
| 10509 | |
| 10510 - (void)removeAll { | |
| 10511 [_dictionary removeAllObjects]; | |
| 10512 } | |
| 10513 | |
| 10514 @end | |
| 10515 | |
| 10516 #pragma mark - String -> Double | |
| 10517 | |
| 10518 @implementation GPBStringDoubleDictionary { | |
| 10519 @package | |
| 10520 NSMutableDictionary *_dictionary; | |
| 10521 } | |
| 10522 | |
| 10523 + (instancetype)dictionary { | |
| 10524 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 10525 } | |
| 10526 | |
| 10527 + (instancetype)dictionaryWithValue:(double)value | |
| 10528 forKey:(NSString *)key { | |
| 10529 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10530 // on to get the type correct. | |
| 10531 return [[(GPBStringDoubleDictionary*)[self alloc] initWithValues:&value | |
| 10532 forKeys:&key | |
| 10533 count:1] autoreleas
e]; | |
| 10534 } | |
| 10535 | |
| 10536 + (instancetype)dictionaryWithValues:(const double [])values | |
| 10537 forKeys:(const NSString * [])keys | |
| 10538 count:(NSUInteger)count { | |
| 10539 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10540 // on to get the type correct. | |
| 10541 return [[(GPBStringDoubleDictionary*)[self alloc] initWithValues:values | |
| 10542 forKeys:keys | |
| 10543 count:count] autore
lease]; | |
| 10544 } | |
| 10545 | |
| 10546 + (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary
{ | |
| 10547 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10548 // on to get the type correct. | |
| 10549 return [[(GPBStringDoubleDictionary*)[self alloc] initWithDictionary:dictionar
y] autorelease]; | |
| 10550 } | |
| 10551 | |
| 10552 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 10553 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 10554 } | |
| 10555 | |
| 10556 - (instancetype)init { | |
| 10557 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 10558 } | |
| 10559 | |
| 10560 - (instancetype)initWithValues:(const double [])values | |
| 10561 forKeys:(const NSString * [])keys | |
| 10562 count:(NSUInteger)count { | |
| 10563 self = [super init]; | |
| 10564 if (self) { | |
| 10565 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 10566 if (count && values && keys) { | |
| 10567 for (NSUInteger i = 0; i < count; ++i) { | |
| 10568 [_dictionary setObject:@(values[i]) forKey:keys[i]]; | |
| 10569 } | |
| 10570 } | |
| 10571 } | |
| 10572 return self; | |
| 10573 } | |
| 10574 | |
| 10575 - (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary { | |
| 10576 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 10577 if (self) { | |
| 10578 if (dictionary) { | |
| 10579 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 10580 } | |
| 10581 } | |
| 10582 return self; | |
| 10583 } | |
| 10584 | |
| 10585 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 10586 #pragma unused(numItems) | |
| 10587 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 10588 } | |
| 10589 | |
| 10590 - (void)dealloc { | |
| 10591 NSAssert(!_autocreator, | |
| 10592 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 10593 [self class], _autocreator); | |
| 10594 [_dictionary release]; | |
| 10595 [super dealloc]; | |
| 10596 } | |
| 10597 | |
| 10598 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 10599 return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self
]; | |
| 10600 } | |
| 10601 | |
| 10602 - (BOOL)isEqual:(GPBStringDoubleDictionary *)other { | |
| 10603 if (self == other) { | |
| 10604 return YES; | |
| 10605 } | |
| 10606 if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) { | |
| 10607 return NO; | |
| 10608 } | |
| 10609 return [_dictionary isEqual:other->_dictionary]; | |
| 10610 } | |
| 10611 | |
| 10612 - (NSUInteger)hash { | |
| 10613 return _dictionary.count; | |
| 10614 } | |
| 10615 | |
| 10616 - (NSString *)description { | |
| 10617 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 10618 } | |
| 10619 | |
| 10620 - (NSUInteger)count { | |
| 10621 return _dictionary.count; | |
| 10622 } | |
| 10623 | |
| 10624 - (void)enumerateKeysAndValuesUsingBlock: | |
| 10625 (void (^)(NSString *key, double value, BOOL *stop))block { | |
| 10626 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10627 NSNumber *aValue, | |
| 10628 BOOL *stop) { | |
| 10629 block(aKey, [aValue doubleValue], stop); | |
| 10630 }]; | |
| 10631 } | |
| 10632 | |
| 10633 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 10634 NSUInteger count = _dictionary.count; | |
| 10635 if (count == 0) { | |
| 10636 return 0; | |
| 10637 } | |
| 10638 | |
| 10639 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 10640 GPBDataType keyDataType = field.mapKeyDataType; | |
| 10641 __block size_t result = 0; | |
| 10642 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10643 NSNumber *aValue, | |
| 10644 BOOL *stop) { | |
| 10645 #pragma unused(stop) | |
| 10646 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 10647 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNu
mber, valueDataType); | |
| 10648 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 10649 }]; | |
| 10650 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 10651 result += tagSize * count; | |
| 10652 return result; | |
| 10653 } | |
| 10654 | |
| 10655 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 10656 asField:(GPBFieldDescriptor *)field { | |
| 10657 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 10658 GPBDataType keyDataType = field.mapKeyDataType; | |
| 10659 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 10660 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10661 NSNumber *aValue, | |
| 10662 BOOL *stop) { | |
| 10663 #pragma unused(stop) | |
| 10664 // Write the tag. | |
| 10665 [outputStream writeInt32NoTag:tag]; | |
| 10666 // Write the size of the message. | |
| 10667 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 10668 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNu
mber, valueDataType); | |
| 10669 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 10670 // Write the fields. | |
| 10671 WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); | |
| 10672 WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumbe
r, valueDataType); | |
| 10673 }]; | |
| 10674 } | |
| 10675 | |
| 10676 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 10677 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 10678 [_dictionary setObject:@(value->valueDouble) forKey:key->valueString]; | |
| 10679 } | |
| 10680 | |
| 10681 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 10682 [self enumerateKeysAndValuesUsingBlock:^(NSString *key, double value, BOOL *st
op) { | |
| 10683 #pragma unused(stop) | |
| 10684 block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); | |
| 10685 }]; | |
| 10686 } | |
| 10687 | |
| 10688 - (BOOL)valueForKey:(NSString *)key value:(double *)value { | |
| 10689 NSNumber *wrapped = [_dictionary objectForKey:key]; | |
| 10690 if (wrapped && value) { | |
| 10691 *value = [wrapped doubleValue]; | |
| 10692 } | |
| 10693 return (wrapped != NULL); | |
| 10694 } | |
| 10695 | |
| 10696 - (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary { | |
| 10697 if (otherDictionary) { | |
| 10698 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 10699 if (_autocreator) { | |
| 10700 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 10701 } | |
| 10702 } | |
| 10703 } | |
| 10704 | |
| 10705 - (void)setValue:(double)value forKey:(NSString *)key { | |
| 10706 [_dictionary setObject:@(value) forKey:key]; | |
| 10707 if (_autocreator) { | |
| 10708 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 10709 } | |
| 10710 } | |
| 10711 | |
| 10712 - (void)removeValueForKey:(NSString *)aKey { | |
| 10713 [_dictionary removeObjectForKey:aKey]; | |
| 10714 } | |
| 10715 | |
| 10716 - (void)removeAll { | |
| 10717 [_dictionary removeAllObjects]; | |
| 10718 } | |
| 10719 | |
| 10720 @end | |
| 10721 | |
| 10722 #pragma mark - String -> Enum | |
| 10723 | |
| 10724 @implementation GPBStringEnumDictionary { | |
| 10725 @package | |
| 10726 NSMutableDictionary *_dictionary; | |
| 10727 GPBEnumValidationFunc _validationFunc; | |
| 10728 } | |
| 10729 | |
| 10730 @synthesize validationFunc = _validationFunc; | |
| 10731 | |
| 10732 + (instancetype)dictionary { | |
| 10733 return [[[self alloc] initWithValidationFunction:NULL | |
| 10734 rawValues:NULL | |
| 10735 forKeys:NULL | |
| 10736 count:0] autorelease]; | |
| 10737 } | |
| 10738 | |
| 10739 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 10740 return [[[self alloc] initWithValidationFunction:func | |
| 10741 rawValues:NULL | |
| 10742 forKeys:NULL | |
| 10743 count:0] autorelease]; | |
| 10744 } | |
| 10745 | |
| 10746 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 10747 rawValue:(int32_t)rawValue | |
| 10748 forKey:(NSString *)key { | |
| 10749 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10750 // on to get the type correct. | |
| 10751 return [[(GPBStringEnumDictionary*)[self alloc] initWithValidationFunction:fun
c | |
| 10752 rawValues:&ra
wValue | |
| 10753 forKeys:&ke
y | |
| 10754 count:1]
autorelease]; | |
| 10755 } | |
| 10756 | |
| 10757 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 10758 rawValues:(const int32_t [])rawValues | |
| 10759 forKeys:(const NSString * [])keys | |
| 10760 count:(NSUInteger)count { | |
| 10761 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10762 // on to get the type correct. | |
| 10763 return [[(GPBStringEnumDictionary*)[self alloc] initWithValidationFunction:fun
c | |
| 10764 rawValues:raw
Values | |
| 10765 forKeys:key
s | |
| 10766 count:cou
nt] autorelease]; | |
| 10767 } | |
| 10768 | |
| 10769 + (instancetype)dictionaryWithDictionary:(GPBStringEnumDictionary *)dictionary { | |
| 10770 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 10771 // on to get the type correct. | |
| 10772 return [[(GPBStringEnumDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 10773 } | |
| 10774 | |
| 10775 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 10776 capacity:(NSUInteger)numItems { | |
| 10777 return [[[self alloc] initWithValidationFunction:func capacity:numItems] autor
elease]; | |
| 10778 } | |
| 10779 | |
| 10780 - (instancetype)init { | |
| 10781 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count
:0]; | |
| 10782 } | |
| 10783 | |
| 10784 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 10785 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 10786 } | |
| 10787 | |
| 10788 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 10789 rawValues:(const int32_t [])rawValues | |
| 10790 forKeys:(const NSString * [])keys | |
| 10791 count:(NSUInteger)count { | |
| 10792 self = [super init]; | |
| 10793 if (self) { | |
| 10794 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 10795 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); | |
| 10796 if (count && rawValues && keys) { | |
| 10797 for (NSUInteger i = 0; i < count; ++i) { | |
| 10798 [_dictionary setObject:@(rawValues[i]) forKey:keys[i]]; | |
| 10799 } | |
| 10800 } | |
| 10801 } | |
| 10802 return self; | |
| 10803 } | |
| 10804 | |
| 10805 - (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary { | |
| 10806 self = [self initWithValidationFunction:dictionary.validationFunc | |
| 10807 rawValues:NULL | |
| 10808 forKeys:NULL | |
| 10809 count:0]; | |
| 10810 if (self) { | |
| 10811 if (dictionary) { | |
| 10812 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; | |
| 10813 } | |
| 10814 } | |
| 10815 return self; | |
| 10816 } | |
| 10817 | |
| 10818 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 10819 capacity:(NSUInteger)numItems { | |
| 10820 #pragma unused(numItems) | |
| 10821 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 10822 } | |
| 10823 | |
| 10824 - (void)dealloc { | |
| 10825 NSAssert(!_autocreator, | |
| 10826 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 10827 [self class], _autocreator); | |
| 10828 [_dictionary release]; | |
| 10829 [super dealloc]; | |
| 10830 } | |
| 10831 | |
| 10832 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 10833 return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 10834 } | |
| 10835 | |
| 10836 - (BOOL)isEqual:(GPBStringEnumDictionary *)other { | |
| 10837 if (self == other) { | |
| 10838 return YES; | |
| 10839 } | |
| 10840 if (![other isKindOfClass:[GPBStringEnumDictionary class]]) { | |
| 10841 return NO; | |
| 10842 } | |
| 10843 return [_dictionary isEqual:other->_dictionary]; | |
| 10844 } | |
| 10845 | |
| 10846 - (NSUInteger)hash { | |
| 10847 return _dictionary.count; | |
| 10848 } | |
| 10849 | |
| 10850 - (NSString *)description { | |
| 10851 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dict
ionary]; | |
| 10852 } | |
| 10853 | |
| 10854 - (NSUInteger)count { | |
| 10855 return _dictionary.count; | |
| 10856 } | |
| 10857 | |
| 10858 - (void)enumerateKeysAndRawValuesUsingBlock: | |
| 10859 (void (^)(NSString *key, int32_t value, BOOL *stop))block { | |
| 10860 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10861 NSNumber *aValue, | |
| 10862 BOOL *stop) { | |
| 10863 block(aKey, [aValue intValue], stop); | |
| 10864 }]; | |
| 10865 } | |
| 10866 | |
| 10867 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 10868 NSUInteger count = _dictionary.count; | |
| 10869 if (count == 0) { | |
| 10870 return 0; | |
| 10871 } | |
| 10872 | |
| 10873 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 10874 GPBDataType keyDataType = field.mapKeyDataType; | |
| 10875 __block size_t result = 0; | |
| 10876 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10877 NSNumber *aValue, | |
| 10878 BOOL *stop) { | |
| 10879 #pragma unused(stop) | |
| 10880 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 10881 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber,
valueDataType); | |
| 10882 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 10883 }]; | |
| 10884 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 10885 result += tagSize * count; | |
| 10886 return result; | |
| 10887 } | |
| 10888 | |
| 10889 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 10890 asField:(GPBFieldDescriptor *)field { | |
| 10891 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 10892 GPBDataType keyDataType = field.mapKeyDataType; | |
| 10893 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 10894 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10895 NSNumber *aValue, | |
| 10896 BOOL *stop) { | |
| 10897 #pragma unused(stop) | |
| 10898 // Write the tag. | |
| 10899 [outputStream writeInt32NoTag:tag]; | |
| 10900 // Write the size of the message. | |
| 10901 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDat
aType); | |
| 10902 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber,
valueDataType); | |
| 10903 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 10904 // Write the fields. | |
| 10905 WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); | |
| 10906 WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, va
lueDataType); | |
| 10907 }]; | |
| 10908 } | |
| 10909 | |
| 10910 - (NSData *)serializedDataForUnknownValue:(int32_t)value | |
| 10911 forKey:(GPBGenericValue *)key | |
| 10912 keyDataType:(GPBDataType)keyDataType { | |
| 10913 size_t msgSize = ComputeDictStringFieldSize(key->valueString, kMapKeyFieldNumb
er, keyDataType); | |
| 10914 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEn
um); | |
| 10915 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; | |
| 10916 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithDat
a:data]; | |
| 10917 WriteDictStringField(outputStream, key->valueString, kMapKeyFieldNumber, keyDa
taType); | |
| 10918 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum)
; | |
| 10919 [outputStream release]; | |
| 10920 return data; | |
| 10921 } | |
| 10922 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 10923 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 10924 [_dictionary setObject:@(value->valueEnum) forKey:key->valueString]; | |
| 10925 } | |
| 10926 | |
| 10927 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 10928 [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL
*stop) { | |
| 10929 #pragma unused(stop) | |
| 10930 block(key, @(value)); | |
| 10931 }]; | |
| 10932 } | |
| 10933 | |
| 10934 - (BOOL)valueForKey:(NSString *)key value:(int32_t *)value { | |
| 10935 NSNumber *wrapped = [_dictionary objectForKey:key]; | |
| 10936 if (wrapped && value) { | |
| 10937 int32_t result = [wrapped intValue]; | |
| 10938 if (!_validationFunc(result)) { | |
| 10939 result = kGPBUnrecognizedEnumeratorValue; | |
| 10940 } | |
| 10941 *value = result; | |
| 10942 } | |
| 10943 return (wrapped != NULL); | |
| 10944 } | |
| 10945 | |
| 10946 - (BOOL)valueForKey:(NSString *)key rawValue:(int32_t *)rawValue { | |
| 10947 NSNumber *wrapped = [_dictionary objectForKey:key]; | |
| 10948 if (wrapped && rawValue) { | |
| 10949 *rawValue = [wrapped intValue]; | |
| 10950 } | |
| 10951 return (wrapped != NULL); | |
| 10952 } | |
| 10953 | |
| 10954 - (void)enumerateKeysAndValuesUsingBlock: | |
| 10955 (void (^)(NSString *key, int32_t value, BOOL *stop))block { | |
| 10956 GPBEnumValidationFunc func = _validationFunc; | |
| 10957 [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, | |
| 10958 NSNumber *aValue, | |
| 10959 BOOL *stop) { | |
| 10960 int32_t unwrapped = [aValue intValue]; | |
| 10961 if (!func(unwrapped)) { | |
| 10962 unwrapped = kGPBUnrecognizedEnumeratorValue; | |
| 10963 } | |
| 10964 block(aKey, unwrapped, stop); | |
| 10965 }]; | |
| 10966 } | |
| 10967 | |
| 10968 - (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary { | |
| 10969 if (otherDictionary) { | |
| 10970 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; | |
| 10971 if (_autocreator) { | |
| 10972 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 10973 } | |
| 10974 } | |
| 10975 } | |
| 10976 | |
| 10977 - (void)setRawValue:(int32_t)value forKey:(NSString *)key { | |
| 10978 [_dictionary setObject:@(value) forKey:key]; | |
| 10979 if (_autocreator) { | |
| 10980 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 10981 } | |
| 10982 } | |
| 10983 | |
| 10984 - (void)removeValueForKey:(NSString *)aKey { | |
| 10985 [_dictionary removeObjectForKey:aKey]; | |
| 10986 } | |
| 10987 | |
| 10988 - (void)removeAll { | |
| 10989 [_dictionary removeAllObjects]; | |
| 10990 } | |
| 10991 | |
| 10992 - (void)setValue:(int32_t)value forKey:(NSString *)key { | |
| 10993 if (!_validationFunc(value)) { | |
| 10994 [NSException raise:NSInvalidArgumentException | |
| 10995 format:@"GPBStringEnumDictionary: Attempt to set an unknown enum
value (%d)", | |
| 10996 value]; | |
| 10997 } | |
| 10998 | |
| 10999 [_dictionary setObject:@(value) forKey:key]; | |
| 11000 if (_autocreator) { | |
| 11001 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 11002 } | |
| 11003 } | |
| 11004 | |
| 11005 @end | |
| 11006 | |
| 11007 //%PDDM-EXPAND-END (5 expansions) | |
| 11008 | |
| 11009 | |
| 11010 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt32, uint32_t) | |
| 11011 // This block of code is generated, do not edit it directly. | |
| 11012 | |
| 11013 #pragma mark - Bool -> UInt32 | |
| 11014 | |
| 11015 @implementation GPBBoolUInt32Dictionary { | |
| 11016 @package | |
| 11017 uint32_t _values[2]; | |
| 11018 BOOL _valueSet[2]; | |
| 11019 } | |
| 11020 | |
| 11021 + (instancetype)dictionary { | |
| 11022 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 11023 } | |
| 11024 | |
| 11025 + (instancetype)dictionaryWithValue:(uint32_t)value | |
| 11026 forKey:(BOOL)key { | |
| 11027 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11028 // on to get the type correct. | |
| 11029 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithValues:&value | |
| 11030 forKeys:&key | |
| 11031 count:1] autorelease]
; | |
| 11032 } | |
| 11033 | |
| 11034 + (instancetype)dictionaryWithValues:(const uint32_t [])values | |
| 11035 forKeys:(const BOOL [])keys | |
| 11036 count:(NSUInteger)count { | |
| 11037 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11038 // on to get the type correct. | |
| 11039 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithValues:values | |
| 11040 forKeys:keys | |
| 11041 count:count] autorele
ase]; | |
| 11042 } | |
| 11043 | |
| 11044 + (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { | |
| 11045 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11046 // on to get the type correct. | |
| 11047 return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 11048 } | |
| 11049 | |
| 11050 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 11051 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 11052 } | |
| 11053 | |
| 11054 - (instancetype)init { | |
| 11055 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11056 } | |
| 11057 | |
| 11058 - (instancetype)initWithValues:(const uint32_t [])values | |
| 11059 forKeys:(const BOOL [])keys | |
| 11060 count:(NSUInteger)count { | |
| 11061 self = [super init]; | |
| 11062 if (self) { | |
| 11063 for (NSUInteger i = 0; i < count; ++i) { | |
| 11064 int idx = keys[i] ? 1 : 0; | |
| 11065 _values[idx] = values[i]; | |
| 11066 _valueSet[idx] = YES; | |
| 11067 } | |
| 11068 } | |
| 11069 return self; | |
| 11070 } | |
| 11071 | |
| 11072 - (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { | |
| 11073 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11074 if (self) { | |
| 11075 if (dictionary) { | |
| 11076 for (int i = 0; i < 2; ++i) { | |
| 11077 if (dictionary->_valueSet[i]) { | |
| 11078 _values[i] = dictionary->_values[i]; | |
| 11079 _valueSet[i] = YES; | |
| 11080 } | |
| 11081 } | |
| 11082 } | |
| 11083 } | |
| 11084 return self; | |
| 11085 } | |
| 11086 | |
| 11087 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 11088 #pragma unused(numItems) | |
| 11089 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11090 } | |
| 11091 | |
| 11092 #if !defined(NS_BLOCK_ASSERTIONS) | |
| 11093 - (void)dealloc { | |
| 11094 NSAssert(!_autocreator, | |
| 11095 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 11096 [self class], _autocreator); | |
| 11097 [super dealloc]; | |
| 11098 } | |
| 11099 #endif // !defined(NS_BLOCK_ASSERTIONS) | |
| 11100 | |
| 11101 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 11102 return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self]; | |
| 11103 } | |
| 11104 | |
| 11105 - (BOOL)isEqual:(GPBBoolUInt32Dictionary *)other { | |
| 11106 if (self == other) { | |
| 11107 return YES; | |
| 11108 } | |
| 11109 if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) { | |
| 11110 return NO; | |
| 11111 } | |
| 11112 if ((_valueSet[0] != other->_valueSet[0]) || | |
| 11113 (_valueSet[1] != other->_valueSet[1])) { | |
| 11114 return NO; | |
| 11115 } | |
| 11116 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | |
| 11117 (_valueSet[1] && (_values[1] != other->_values[1]))) { | |
| 11118 return NO; | |
| 11119 } | |
| 11120 return YES; | |
| 11121 } | |
| 11122 | |
| 11123 - (NSUInteger)hash { | |
| 11124 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 11125 } | |
| 11126 | |
| 11127 - (NSString *)description { | |
| 11128 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | |
| 11129 if (_valueSet[0]) { | |
| 11130 [result appendFormat:@"NO: %u", _values[0]]; | |
| 11131 } | |
| 11132 if (_valueSet[1]) { | |
| 11133 [result appendFormat:@"YES: %u", _values[1]]; | |
| 11134 } | |
| 11135 [result appendString:@" }"]; | |
| 11136 return result; | |
| 11137 } | |
| 11138 | |
| 11139 - (NSUInteger)count { | |
| 11140 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 11141 } | |
| 11142 | |
| 11143 - (BOOL)valueForKey:(BOOL)key value:(uint32_t *)value { | |
| 11144 int idx = (key ? 1 : 0); | |
| 11145 if (_valueSet[idx]) { | |
| 11146 if (value) { | |
| 11147 *value = _values[idx]; | |
| 11148 } | |
| 11149 return YES; | |
| 11150 } | |
| 11151 return NO; | |
| 11152 } | |
| 11153 | |
| 11154 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 11155 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 11156 int idx = (key->valueBool ? 1 : 0); | |
| 11157 _values[idx] = value->valueUInt32; | |
| 11158 _valueSet[idx] = YES; | |
| 11159 } | |
| 11160 | |
| 11161 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 11162 if (_valueSet[0]) { | |
| 11163 block(@"false", [NSString stringWithFormat:@"%u", _values[0]]); | |
| 11164 } | |
| 11165 if (_valueSet[1]) { | |
| 11166 block(@"true", [NSString stringWithFormat:@"%u", _values[1]]); | |
| 11167 } | |
| 11168 } | |
| 11169 | |
| 11170 - (void)enumerateKeysAndValuesUsingBlock: | |
| 11171 (void (^)(BOOL key, uint32_t value, BOOL *stop))block { | |
| 11172 BOOL stop = NO; | |
| 11173 if (_valueSet[0]) { | |
| 11174 block(NO, _values[0], &stop); | |
| 11175 } | |
| 11176 if (!stop && _valueSet[1]) { | |
| 11177 block(YES, _values[1], &stop); | |
| 11178 } | |
| 11179 } | |
| 11180 | |
| 11181 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 11182 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 11183 NSUInteger count = 0; | |
| 11184 size_t result = 0; | |
| 11185 for (int i = 0; i < 2; ++i) { | |
| 11186 if (_valueSet[i]) { | |
| 11187 ++count; | |
| 11188 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 11189 msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, va
lueDataType); | |
| 11190 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 11191 } | |
| 11192 } | |
| 11193 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 11194 result += tagSize * count; | |
| 11195 return result; | |
| 11196 } | |
| 11197 | |
| 11198 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 11199 asField:(GPBFieldDescriptor *)field { | |
| 11200 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 11201 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 11202 for (int i = 0; i < 2; ++i) { | |
| 11203 if (_valueSet[i]) { | |
| 11204 // Write the tag. | |
| 11205 [outputStream writeInt32NoTag:tag]; | |
| 11206 // Write the size of the message. | |
| 11207 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 11208 msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, va
lueDataType); | |
| 11209 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 11210 // Write the fields. | |
| 11211 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataType
Bool); | |
| 11212 WriteDictUInt32Field(outputStream, _values[i], kMapValueFieldNumber, value
DataType); | |
| 11213 } | |
| 11214 } | |
| 11215 } | |
| 11216 | |
| 11217 - (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary { | |
| 11218 if (otherDictionary) { | |
| 11219 for (int i = 0; i < 2; ++i) { | |
| 11220 if (otherDictionary->_valueSet[i]) { | |
| 11221 _valueSet[i] = YES; | |
| 11222 _values[i] = otherDictionary->_values[i]; | |
| 11223 } | |
| 11224 } | |
| 11225 if (_autocreator) { | |
| 11226 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 11227 } | |
| 11228 } | |
| 11229 } | |
| 11230 | |
| 11231 - (void)setValue:(uint32_t)value forKey:(BOOL)key { | |
| 11232 int idx = (key ? 1 : 0); | |
| 11233 _values[idx] = value; | |
| 11234 _valueSet[idx] = YES; | |
| 11235 if (_autocreator) { | |
| 11236 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 11237 } | |
| 11238 } | |
| 11239 | |
| 11240 - (void)removeValueForKey:(BOOL)aKey { | |
| 11241 _valueSet[aKey ? 1 : 0] = NO; | |
| 11242 } | |
| 11243 | |
| 11244 - (void)removeAll { | |
| 11245 _valueSet[0] = NO; | |
| 11246 _valueSet[1] = NO; | |
| 11247 } | |
| 11248 | |
| 11249 @end | |
| 11250 | |
| 11251 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t) | |
| 11252 // This block of code is generated, do not edit it directly. | |
| 11253 | |
| 11254 #pragma mark - Bool -> Int32 | |
| 11255 | |
| 11256 @implementation GPBBoolInt32Dictionary { | |
| 11257 @package | |
| 11258 int32_t _values[2]; | |
| 11259 BOOL _valueSet[2]; | |
| 11260 } | |
| 11261 | |
| 11262 + (instancetype)dictionary { | |
| 11263 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 11264 } | |
| 11265 | |
| 11266 + (instancetype)dictionaryWithValue:(int32_t)value | |
| 11267 forKey:(BOOL)key { | |
| 11268 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11269 // on to get the type correct. | |
| 11270 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithValues:&value | |
| 11271 forKeys:&key | |
| 11272 count:1] autorelease]; | |
| 11273 } | |
| 11274 | |
| 11275 + (instancetype)dictionaryWithValues:(const int32_t [])values | |
| 11276 forKeys:(const BOOL [])keys | |
| 11277 count:(NSUInteger)count { | |
| 11278 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11279 // on to get the type correct. | |
| 11280 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithValues:values | |
| 11281 forKeys:keys | |
| 11282 count:count] autorelea
se]; | |
| 11283 } | |
| 11284 | |
| 11285 + (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary { | |
| 11286 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11287 // on to get the type correct. | |
| 11288 return [[(GPBBoolInt32Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 11289 } | |
| 11290 | |
| 11291 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 11292 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 11293 } | |
| 11294 | |
| 11295 - (instancetype)init { | |
| 11296 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11297 } | |
| 11298 | |
| 11299 - (instancetype)initWithValues:(const int32_t [])values | |
| 11300 forKeys:(const BOOL [])keys | |
| 11301 count:(NSUInteger)count { | |
| 11302 self = [super init]; | |
| 11303 if (self) { | |
| 11304 for (NSUInteger i = 0; i < count; ++i) { | |
| 11305 int idx = keys[i] ? 1 : 0; | |
| 11306 _values[idx] = values[i]; | |
| 11307 _valueSet[idx] = YES; | |
| 11308 } | |
| 11309 } | |
| 11310 return self; | |
| 11311 } | |
| 11312 | |
| 11313 - (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary { | |
| 11314 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11315 if (self) { | |
| 11316 if (dictionary) { | |
| 11317 for (int i = 0; i < 2; ++i) { | |
| 11318 if (dictionary->_valueSet[i]) { | |
| 11319 _values[i] = dictionary->_values[i]; | |
| 11320 _valueSet[i] = YES; | |
| 11321 } | |
| 11322 } | |
| 11323 } | |
| 11324 } | |
| 11325 return self; | |
| 11326 } | |
| 11327 | |
| 11328 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 11329 #pragma unused(numItems) | |
| 11330 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11331 } | |
| 11332 | |
| 11333 #if !defined(NS_BLOCK_ASSERTIONS) | |
| 11334 - (void)dealloc { | |
| 11335 NSAssert(!_autocreator, | |
| 11336 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 11337 [self class], _autocreator); | |
| 11338 [super dealloc]; | |
| 11339 } | |
| 11340 #endif // !defined(NS_BLOCK_ASSERTIONS) | |
| 11341 | |
| 11342 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 11343 return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self]; | |
| 11344 } | |
| 11345 | |
| 11346 - (BOOL)isEqual:(GPBBoolInt32Dictionary *)other { | |
| 11347 if (self == other) { | |
| 11348 return YES; | |
| 11349 } | |
| 11350 if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) { | |
| 11351 return NO; | |
| 11352 } | |
| 11353 if ((_valueSet[0] != other->_valueSet[0]) || | |
| 11354 (_valueSet[1] != other->_valueSet[1])) { | |
| 11355 return NO; | |
| 11356 } | |
| 11357 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | |
| 11358 (_valueSet[1] && (_values[1] != other->_values[1]))) { | |
| 11359 return NO; | |
| 11360 } | |
| 11361 return YES; | |
| 11362 } | |
| 11363 | |
| 11364 - (NSUInteger)hash { | |
| 11365 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 11366 } | |
| 11367 | |
| 11368 - (NSString *)description { | |
| 11369 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | |
| 11370 if (_valueSet[0]) { | |
| 11371 [result appendFormat:@"NO: %d", _values[0]]; | |
| 11372 } | |
| 11373 if (_valueSet[1]) { | |
| 11374 [result appendFormat:@"YES: %d", _values[1]]; | |
| 11375 } | |
| 11376 [result appendString:@" }"]; | |
| 11377 return result; | |
| 11378 } | |
| 11379 | |
| 11380 - (NSUInteger)count { | |
| 11381 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 11382 } | |
| 11383 | |
| 11384 - (BOOL)valueForKey:(BOOL)key value:(int32_t *)value { | |
| 11385 int idx = (key ? 1 : 0); | |
| 11386 if (_valueSet[idx]) { | |
| 11387 if (value) { | |
| 11388 *value = _values[idx]; | |
| 11389 } | |
| 11390 return YES; | |
| 11391 } | |
| 11392 return NO; | |
| 11393 } | |
| 11394 | |
| 11395 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 11396 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 11397 int idx = (key->valueBool ? 1 : 0); | |
| 11398 _values[idx] = value->valueInt32; | |
| 11399 _valueSet[idx] = YES; | |
| 11400 } | |
| 11401 | |
| 11402 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 11403 if (_valueSet[0]) { | |
| 11404 block(@"false", [NSString stringWithFormat:@"%d", _values[0]]); | |
| 11405 } | |
| 11406 if (_valueSet[1]) { | |
| 11407 block(@"true", [NSString stringWithFormat:@"%d", _values[1]]); | |
| 11408 } | |
| 11409 } | |
| 11410 | |
| 11411 - (void)enumerateKeysAndValuesUsingBlock: | |
| 11412 (void (^)(BOOL key, int32_t value, BOOL *stop))block { | |
| 11413 BOOL stop = NO; | |
| 11414 if (_valueSet[0]) { | |
| 11415 block(NO, _values[0], &stop); | |
| 11416 } | |
| 11417 if (!stop && _valueSet[1]) { | |
| 11418 block(YES, _values[1], &stop); | |
| 11419 } | |
| 11420 } | |
| 11421 | |
| 11422 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 11423 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 11424 NSUInteger count = 0; | |
| 11425 size_t result = 0; | |
| 11426 for (int i = 0; i < 2; ++i) { | |
| 11427 if (_valueSet[i]) { | |
| 11428 ++count; | |
| 11429 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 11430 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, val
ueDataType); | |
| 11431 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 11432 } | |
| 11433 } | |
| 11434 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 11435 result += tagSize * count; | |
| 11436 return result; | |
| 11437 } | |
| 11438 | |
| 11439 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 11440 asField:(GPBFieldDescriptor *)field { | |
| 11441 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 11442 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 11443 for (int i = 0; i < 2; ++i) { | |
| 11444 if (_valueSet[i]) { | |
| 11445 // Write the tag. | |
| 11446 [outputStream writeInt32NoTag:tag]; | |
| 11447 // Write the size of the message. | |
| 11448 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 11449 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, val
ueDataType); | |
| 11450 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 11451 // Write the fields. | |
| 11452 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataType
Bool); | |
| 11453 WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueD
ataType); | |
| 11454 } | |
| 11455 } | |
| 11456 } | |
| 11457 | |
| 11458 - (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary { | |
| 11459 if (otherDictionary) { | |
| 11460 for (int i = 0; i < 2; ++i) { | |
| 11461 if (otherDictionary->_valueSet[i]) { | |
| 11462 _valueSet[i] = YES; | |
| 11463 _values[i] = otherDictionary->_values[i]; | |
| 11464 } | |
| 11465 } | |
| 11466 if (_autocreator) { | |
| 11467 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 11468 } | |
| 11469 } | |
| 11470 } | |
| 11471 | |
| 11472 - (void)setValue:(int32_t)value forKey:(BOOL)key { | |
| 11473 int idx = (key ? 1 : 0); | |
| 11474 _values[idx] = value; | |
| 11475 _valueSet[idx] = YES; | |
| 11476 if (_autocreator) { | |
| 11477 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 11478 } | |
| 11479 } | |
| 11480 | |
| 11481 - (void)removeValueForKey:(BOOL)aKey { | |
| 11482 _valueSet[aKey ? 1 : 0] = NO; | |
| 11483 } | |
| 11484 | |
| 11485 - (void)removeAll { | |
| 11486 _valueSet[0] = NO; | |
| 11487 _valueSet[1] = NO; | |
| 11488 } | |
| 11489 | |
| 11490 @end | |
| 11491 | |
| 11492 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t) | |
| 11493 // This block of code is generated, do not edit it directly. | |
| 11494 | |
| 11495 #pragma mark - Bool -> UInt64 | |
| 11496 | |
| 11497 @implementation GPBBoolUInt64Dictionary { | |
| 11498 @package | |
| 11499 uint64_t _values[2]; | |
| 11500 BOOL _valueSet[2]; | |
| 11501 } | |
| 11502 | |
| 11503 + (instancetype)dictionary { | |
| 11504 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 11505 } | |
| 11506 | |
| 11507 + (instancetype)dictionaryWithValue:(uint64_t)value | |
| 11508 forKey:(BOOL)key { | |
| 11509 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11510 // on to get the type correct. | |
| 11511 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithValues:&value | |
| 11512 forKeys:&key | |
| 11513 count:1] autorelease]
; | |
| 11514 } | |
| 11515 | |
| 11516 + (instancetype)dictionaryWithValues:(const uint64_t [])values | |
| 11517 forKeys:(const BOOL [])keys | |
| 11518 count:(NSUInteger)count { | |
| 11519 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11520 // on to get the type correct. | |
| 11521 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithValues:values | |
| 11522 forKeys:keys | |
| 11523 count:count] autorele
ase]; | |
| 11524 } | |
| 11525 | |
| 11526 + (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { | |
| 11527 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11528 // on to get the type correct. | |
| 11529 return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 11530 } | |
| 11531 | |
| 11532 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 11533 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 11534 } | |
| 11535 | |
| 11536 - (instancetype)init { | |
| 11537 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11538 } | |
| 11539 | |
| 11540 - (instancetype)initWithValues:(const uint64_t [])values | |
| 11541 forKeys:(const BOOL [])keys | |
| 11542 count:(NSUInteger)count { | |
| 11543 self = [super init]; | |
| 11544 if (self) { | |
| 11545 for (NSUInteger i = 0; i < count; ++i) { | |
| 11546 int idx = keys[i] ? 1 : 0; | |
| 11547 _values[idx] = values[i]; | |
| 11548 _valueSet[idx] = YES; | |
| 11549 } | |
| 11550 } | |
| 11551 return self; | |
| 11552 } | |
| 11553 | |
| 11554 - (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { | |
| 11555 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11556 if (self) { | |
| 11557 if (dictionary) { | |
| 11558 for (int i = 0; i < 2; ++i) { | |
| 11559 if (dictionary->_valueSet[i]) { | |
| 11560 _values[i] = dictionary->_values[i]; | |
| 11561 _valueSet[i] = YES; | |
| 11562 } | |
| 11563 } | |
| 11564 } | |
| 11565 } | |
| 11566 return self; | |
| 11567 } | |
| 11568 | |
| 11569 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 11570 #pragma unused(numItems) | |
| 11571 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11572 } | |
| 11573 | |
| 11574 #if !defined(NS_BLOCK_ASSERTIONS) | |
| 11575 - (void)dealloc { | |
| 11576 NSAssert(!_autocreator, | |
| 11577 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 11578 [self class], _autocreator); | |
| 11579 [super dealloc]; | |
| 11580 } | |
| 11581 #endif // !defined(NS_BLOCK_ASSERTIONS) | |
| 11582 | |
| 11583 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 11584 return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self]; | |
| 11585 } | |
| 11586 | |
| 11587 - (BOOL)isEqual:(GPBBoolUInt64Dictionary *)other { | |
| 11588 if (self == other) { | |
| 11589 return YES; | |
| 11590 } | |
| 11591 if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) { | |
| 11592 return NO; | |
| 11593 } | |
| 11594 if ((_valueSet[0] != other->_valueSet[0]) || | |
| 11595 (_valueSet[1] != other->_valueSet[1])) { | |
| 11596 return NO; | |
| 11597 } | |
| 11598 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | |
| 11599 (_valueSet[1] && (_values[1] != other->_values[1]))) { | |
| 11600 return NO; | |
| 11601 } | |
| 11602 return YES; | |
| 11603 } | |
| 11604 | |
| 11605 - (NSUInteger)hash { | |
| 11606 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 11607 } | |
| 11608 | |
| 11609 - (NSString *)description { | |
| 11610 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | |
| 11611 if (_valueSet[0]) { | |
| 11612 [result appendFormat:@"NO: %llu", _values[0]]; | |
| 11613 } | |
| 11614 if (_valueSet[1]) { | |
| 11615 [result appendFormat:@"YES: %llu", _values[1]]; | |
| 11616 } | |
| 11617 [result appendString:@" }"]; | |
| 11618 return result; | |
| 11619 } | |
| 11620 | |
| 11621 - (NSUInteger)count { | |
| 11622 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 11623 } | |
| 11624 | |
| 11625 - (BOOL)valueForKey:(BOOL)key value:(uint64_t *)value { | |
| 11626 int idx = (key ? 1 : 0); | |
| 11627 if (_valueSet[idx]) { | |
| 11628 if (value) { | |
| 11629 *value = _values[idx]; | |
| 11630 } | |
| 11631 return YES; | |
| 11632 } | |
| 11633 return NO; | |
| 11634 } | |
| 11635 | |
| 11636 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 11637 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 11638 int idx = (key->valueBool ? 1 : 0); | |
| 11639 _values[idx] = value->valueUInt64; | |
| 11640 _valueSet[idx] = YES; | |
| 11641 } | |
| 11642 | |
| 11643 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 11644 if (_valueSet[0]) { | |
| 11645 block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]); | |
| 11646 } | |
| 11647 if (_valueSet[1]) { | |
| 11648 block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]); | |
| 11649 } | |
| 11650 } | |
| 11651 | |
| 11652 - (void)enumerateKeysAndValuesUsingBlock: | |
| 11653 (void (^)(BOOL key, uint64_t value, BOOL *stop))block { | |
| 11654 BOOL stop = NO; | |
| 11655 if (_valueSet[0]) { | |
| 11656 block(NO, _values[0], &stop); | |
| 11657 } | |
| 11658 if (!stop && _valueSet[1]) { | |
| 11659 block(YES, _values[1], &stop); | |
| 11660 } | |
| 11661 } | |
| 11662 | |
| 11663 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 11664 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 11665 NSUInteger count = 0; | |
| 11666 size_t result = 0; | |
| 11667 for (int i = 0; i < 2; ++i) { | |
| 11668 if (_valueSet[i]) { | |
| 11669 ++count; | |
| 11670 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 11671 msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, va
lueDataType); | |
| 11672 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 11673 } | |
| 11674 } | |
| 11675 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 11676 result += tagSize * count; | |
| 11677 return result; | |
| 11678 } | |
| 11679 | |
| 11680 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 11681 asField:(GPBFieldDescriptor *)field { | |
| 11682 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 11683 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 11684 for (int i = 0; i < 2; ++i) { | |
| 11685 if (_valueSet[i]) { | |
| 11686 // Write the tag. | |
| 11687 [outputStream writeInt32NoTag:tag]; | |
| 11688 // Write the size of the message. | |
| 11689 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 11690 msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, va
lueDataType); | |
| 11691 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 11692 // Write the fields. | |
| 11693 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataType
Bool); | |
| 11694 WriteDictUInt64Field(outputStream, _values[i], kMapValueFieldNumber, value
DataType); | |
| 11695 } | |
| 11696 } | |
| 11697 } | |
| 11698 | |
| 11699 - (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary { | |
| 11700 if (otherDictionary) { | |
| 11701 for (int i = 0; i < 2; ++i) { | |
| 11702 if (otherDictionary->_valueSet[i]) { | |
| 11703 _valueSet[i] = YES; | |
| 11704 _values[i] = otherDictionary->_values[i]; | |
| 11705 } | |
| 11706 } | |
| 11707 if (_autocreator) { | |
| 11708 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 11709 } | |
| 11710 } | |
| 11711 } | |
| 11712 | |
| 11713 - (void)setValue:(uint64_t)value forKey:(BOOL)key { | |
| 11714 int idx = (key ? 1 : 0); | |
| 11715 _values[idx] = value; | |
| 11716 _valueSet[idx] = YES; | |
| 11717 if (_autocreator) { | |
| 11718 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 11719 } | |
| 11720 } | |
| 11721 | |
| 11722 - (void)removeValueForKey:(BOOL)aKey { | |
| 11723 _valueSet[aKey ? 1 : 0] = NO; | |
| 11724 } | |
| 11725 | |
| 11726 - (void)removeAll { | |
| 11727 _valueSet[0] = NO; | |
| 11728 _valueSet[1] = NO; | |
| 11729 } | |
| 11730 | |
| 11731 @end | |
| 11732 | |
| 11733 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t) | |
| 11734 // This block of code is generated, do not edit it directly. | |
| 11735 | |
| 11736 #pragma mark - Bool -> Int64 | |
| 11737 | |
| 11738 @implementation GPBBoolInt64Dictionary { | |
| 11739 @package | |
| 11740 int64_t _values[2]; | |
| 11741 BOOL _valueSet[2]; | |
| 11742 } | |
| 11743 | |
| 11744 + (instancetype)dictionary { | |
| 11745 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 11746 } | |
| 11747 | |
| 11748 + (instancetype)dictionaryWithValue:(int64_t)value | |
| 11749 forKey:(BOOL)key { | |
| 11750 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11751 // on to get the type correct. | |
| 11752 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithValues:&value | |
| 11753 forKeys:&key | |
| 11754 count:1] autorelease]; | |
| 11755 } | |
| 11756 | |
| 11757 + (instancetype)dictionaryWithValues:(const int64_t [])values | |
| 11758 forKeys:(const BOOL [])keys | |
| 11759 count:(NSUInteger)count { | |
| 11760 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11761 // on to get the type correct. | |
| 11762 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithValues:values | |
| 11763 forKeys:keys | |
| 11764 count:count] autorelea
se]; | |
| 11765 } | |
| 11766 | |
| 11767 + (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary { | |
| 11768 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11769 // on to get the type correct. | |
| 11770 return [[(GPBBoolInt64Dictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 11771 } | |
| 11772 | |
| 11773 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 11774 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 11775 } | |
| 11776 | |
| 11777 - (instancetype)init { | |
| 11778 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11779 } | |
| 11780 | |
| 11781 - (instancetype)initWithValues:(const int64_t [])values | |
| 11782 forKeys:(const BOOL [])keys | |
| 11783 count:(NSUInteger)count { | |
| 11784 self = [super init]; | |
| 11785 if (self) { | |
| 11786 for (NSUInteger i = 0; i < count; ++i) { | |
| 11787 int idx = keys[i] ? 1 : 0; | |
| 11788 _values[idx] = values[i]; | |
| 11789 _valueSet[idx] = YES; | |
| 11790 } | |
| 11791 } | |
| 11792 return self; | |
| 11793 } | |
| 11794 | |
| 11795 - (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary { | |
| 11796 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11797 if (self) { | |
| 11798 if (dictionary) { | |
| 11799 for (int i = 0; i < 2; ++i) { | |
| 11800 if (dictionary->_valueSet[i]) { | |
| 11801 _values[i] = dictionary->_values[i]; | |
| 11802 _valueSet[i] = YES; | |
| 11803 } | |
| 11804 } | |
| 11805 } | |
| 11806 } | |
| 11807 return self; | |
| 11808 } | |
| 11809 | |
| 11810 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 11811 #pragma unused(numItems) | |
| 11812 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 11813 } | |
| 11814 | |
| 11815 #if !defined(NS_BLOCK_ASSERTIONS) | |
| 11816 - (void)dealloc { | |
| 11817 NSAssert(!_autocreator, | |
| 11818 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 11819 [self class], _autocreator); | |
| 11820 [super dealloc]; | |
| 11821 } | |
| 11822 #endif // !defined(NS_BLOCK_ASSERTIONS) | |
| 11823 | |
| 11824 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 11825 return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self]; | |
| 11826 } | |
| 11827 | |
| 11828 - (BOOL)isEqual:(GPBBoolInt64Dictionary *)other { | |
| 11829 if (self == other) { | |
| 11830 return YES; | |
| 11831 } | |
| 11832 if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) { | |
| 11833 return NO; | |
| 11834 } | |
| 11835 if ((_valueSet[0] != other->_valueSet[0]) || | |
| 11836 (_valueSet[1] != other->_valueSet[1])) { | |
| 11837 return NO; | |
| 11838 } | |
| 11839 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | |
| 11840 (_valueSet[1] && (_values[1] != other->_values[1]))) { | |
| 11841 return NO; | |
| 11842 } | |
| 11843 return YES; | |
| 11844 } | |
| 11845 | |
| 11846 - (NSUInteger)hash { | |
| 11847 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 11848 } | |
| 11849 | |
| 11850 - (NSString *)description { | |
| 11851 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | |
| 11852 if (_valueSet[0]) { | |
| 11853 [result appendFormat:@"NO: %lld", _values[0]]; | |
| 11854 } | |
| 11855 if (_valueSet[1]) { | |
| 11856 [result appendFormat:@"YES: %lld", _values[1]]; | |
| 11857 } | |
| 11858 [result appendString:@" }"]; | |
| 11859 return result; | |
| 11860 } | |
| 11861 | |
| 11862 - (NSUInteger)count { | |
| 11863 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 11864 } | |
| 11865 | |
| 11866 - (BOOL)valueForKey:(BOOL)key value:(int64_t *)value { | |
| 11867 int idx = (key ? 1 : 0); | |
| 11868 if (_valueSet[idx]) { | |
| 11869 if (value) { | |
| 11870 *value = _values[idx]; | |
| 11871 } | |
| 11872 return YES; | |
| 11873 } | |
| 11874 return NO; | |
| 11875 } | |
| 11876 | |
| 11877 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 11878 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 11879 int idx = (key->valueBool ? 1 : 0); | |
| 11880 _values[idx] = value->valueInt64; | |
| 11881 _valueSet[idx] = YES; | |
| 11882 } | |
| 11883 | |
| 11884 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 11885 if (_valueSet[0]) { | |
| 11886 block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]); | |
| 11887 } | |
| 11888 if (_valueSet[1]) { | |
| 11889 block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]); | |
| 11890 } | |
| 11891 } | |
| 11892 | |
| 11893 - (void)enumerateKeysAndValuesUsingBlock: | |
| 11894 (void (^)(BOOL key, int64_t value, BOOL *stop))block { | |
| 11895 BOOL stop = NO; | |
| 11896 if (_valueSet[0]) { | |
| 11897 block(NO, _values[0], &stop); | |
| 11898 } | |
| 11899 if (!stop && _valueSet[1]) { | |
| 11900 block(YES, _values[1], &stop); | |
| 11901 } | |
| 11902 } | |
| 11903 | |
| 11904 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 11905 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 11906 NSUInteger count = 0; | |
| 11907 size_t result = 0; | |
| 11908 for (int i = 0; i < 2; ++i) { | |
| 11909 if (_valueSet[i]) { | |
| 11910 ++count; | |
| 11911 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 11912 msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, val
ueDataType); | |
| 11913 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 11914 } | |
| 11915 } | |
| 11916 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 11917 result += tagSize * count; | |
| 11918 return result; | |
| 11919 } | |
| 11920 | |
| 11921 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 11922 asField:(GPBFieldDescriptor *)field { | |
| 11923 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 11924 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 11925 for (int i = 0; i < 2; ++i) { | |
| 11926 if (_valueSet[i]) { | |
| 11927 // Write the tag. | |
| 11928 [outputStream writeInt32NoTag:tag]; | |
| 11929 // Write the size of the message. | |
| 11930 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 11931 msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, val
ueDataType); | |
| 11932 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 11933 // Write the fields. | |
| 11934 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataType
Bool); | |
| 11935 WriteDictInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueD
ataType); | |
| 11936 } | |
| 11937 } | |
| 11938 } | |
| 11939 | |
| 11940 - (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary { | |
| 11941 if (otherDictionary) { | |
| 11942 for (int i = 0; i < 2; ++i) { | |
| 11943 if (otherDictionary->_valueSet[i]) { | |
| 11944 _valueSet[i] = YES; | |
| 11945 _values[i] = otherDictionary->_values[i]; | |
| 11946 } | |
| 11947 } | |
| 11948 if (_autocreator) { | |
| 11949 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 11950 } | |
| 11951 } | |
| 11952 } | |
| 11953 | |
| 11954 - (void)setValue:(int64_t)value forKey:(BOOL)key { | |
| 11955 int idx = (key ? 1 : 0); | |
| 11956 _values[idx] = value; | |
| 11957 _valueSet[idx] = YES; | |
| 11958 if (_autocreator) { | |
| 11959 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 11960 } | |
| 11961 } | |
| 11962 | |
| 11963 - (void)removeValueForKey:(BOOL)aKey { | |
| 11964 _valueSet[aKey ? 1 : 0] = NO; | |
| 11965 } | |
| 11966 | |
| 11967 - (void)removeAll { | |
| 11968 _valueSet[0] = NO; | |
| 11969 _valueSet[1] = NO; | |
| 11970 } | |
| 11971 | |
| 11972 @end | |
| 11973 | |
| 11974 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL) | |
| 11975 // This block of code is generated, do not edit it directly. | |
| 11976 | |
| 11977 #pragma mark - Bool -> Bool | |
| 11978 | |
| 11979 @implementation GPBBoolBoolDictionary { | |
| 11980 @package | |
| 11981 BOOL _values[2]; | |
| 11982 BOOL _valueSet[2]; | |
| 11983 } | |
| 11984 | |
| 11985 + (instancetype)dictionary { | |
| 11986 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 11987 } | |
| 11988 | |
| 11989 + (instancetype)dictionaryWithValue:(BOOL)value | |
| 11990 forKey:(BOOL)key { | |
| 11991 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 11992 // on to get the type correct. | |
| 11993 return [[(GPBBoolBoolDictionary*)[self alloc] initWithValues:&value | |
| 11994 forKeys:&key | |
| 11995 count:1] autorelease]; | |
| 11996 } | |
| 11997 | |
| 11998 + (instancetype)dictionaryWithValues:(const BOOL [])values | |
| 11999 forKeys:(const BOOL [])keys | |
| 12000 count:(NSUInteger)count { | |
| 12001 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12002 // on to get the type correct. | |
| 12003 return [[(GPBBoolBoolDictionary*)[self alloc] initWithValues:values | |
| 12004 forKeys:keys | |
| 12005 count:count] autoreleas
e]; | |
| 12006 } | |
| 12007 | |
| 12008 + (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary { | |
| 12009 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12010 // on to get the type correct. | |
| 12011 return [[(GPBBoolBoolDictionary*)[self alloc] initWithDictionary:dictionary] a
utorelease]; | |
| 12012 } | |
| 12013 | |
| 12014 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 12015 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 12016 } | |
| 12017 | |
| 12018 - (instancetype)init { | |
| 12019 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12020 } | |
| 12021 | |
| 12022 - (instancetype)initWithValues:(const BOOL [])values | |
| 12023 forKeys:(const BOOL [])keys | |
| 12024 count:(NSUInteger)count { | |
| 12025 self = [super init]; | |
| 12026 if (self) { | |
| 12027 for (NSUInteger i = 0; i < count; ++i) { | |
| 12028 int idx = keys[i] ? 1 : 0; | |
| 12029 _values[idx] = values[i]; | |
| 12030 _valueSet[idx] = YES; | |
| 12031 } | |
| 12032 } | |
| 12033 return self; | |
| 12034 } | |
| 12035 | |
| 12036 - (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary { | |
| 12037 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12038 if (self) { | |
| 12039 if (dictionary) { | |
| 12040 for (int i = 0; i < 2; ++i) { | |
| 12041 if (dictionary->_valueSet[i]) { | |
| 12042 _values[i] = dictionary->_values[i]; | |
| 12043 _valueSet[i] = YES; | |
| 12044 } | |
| 12045 } | |
| 12046 } | |
| 12047 } | |
| 12048 return self; | |
| 12049 } | |
| 12050 | |
| 12051 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 12052 #pragma unused(numItems) | |
| 12053 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12054 } | |
| 12055 | |
| 12056 #if !defined(NS_BLOCK_ASSERTIONS) | |
| 12057 - (void)dealloc { | |
| 12058 NSAssert(!_autocreator, | |
| 12059 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 12060 [self class], _autocreator); | |
| 12061 [super dealloc]; | |
| 12062 } | |
| 12063 #endif // !defined(NS_BLOCK_ASSERTIONS) | |
| 12064 | |
| 12065 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 12066 return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 12067 } | |
| 12068 | |
| 12069 - (BOOL)isEqual:(GPBBoolBoolDictionary *)other { | |
| 12070 if (self == other) { | |
| 12071 return YES; | |
| 12072 } | |
| 12073 if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) { | |
| 12074 return NO; | |
| 12075 } | |
| 12076 if ((_valueSet[0] != other->_valueSet[0]) || | |
| 12077 (_valueSet[1] != other->_valueSet[1])) { | |
| 12078 return NO; | |
| 12079 } | |
| 12080 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | |
| 12081 (_valueSet[1] && (_values[1] != other->_values[1]))) { | |
| 12082 return NO; | |
| 12083 } | |
| 12084 return YES; | |
| 12085 } | |
| 12086 | |
| 12087 - (NSUInteger)hash { | |
| 12088 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 12089 } | |
| 12090 | |
| 12091 - (NSString *)description { | |
| 12092 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | |
| 12093 if (_valueSet[0]) { | |
| 12094 [result appendFormat:@"NO: %d", _values[0]]; | |
| 12095 } | |
| 12096 if (_valueSet[1]) { | |
| 12097 [result appendFormat:@"YES: %d", _values[1]]; | |
| 12098 } | |
| 12099 [result appendString:@" }"]; | |
| 12100 return result; | |
| 12101 } | |
| 12102 | |
| 12103 - (NSUInteger)count { | |
| 12104 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 12105 } | |
| 12106 | |
| 12107 - (BOOL)valueForKey:(BOOL)key value:(BOOL *)value { | |
| 12108 int idx = (key ? 1 : 0); | |
| 12109 if (_valueSet[idx]) { | |
| 12110 if (value) { | |
| 12111 *value = _values[idx]; | |
| 12112 } | |
| 12113 return YES; | |
| 12114 } | |
| 12115 return NO; | |
| 12116 } | |
| 12117 | |
| 12118 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 12119 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 12120 int idx = (key->valueBool ? 1 : 0); | |
| 12121 _values[idx] = value->valueBool; | |
| 12122 _valueSet[idx] = YES; | |
| 12123 } | |
| 12124 | |
| 12125 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 12126 if (_valueSet[0]) { | |
| 12127 block(@"false", (_values[0] ? @"true" : @"false")); | |
| 12128 } | |
| 12129 if (_valueSet[1]) { | |
| 12130 block(@"true", (_values[1] ? @"true" : @"false")); | |
| 12131 } | |
| 12132 } | |
| 12133 | |
| 12134 - (void)enumerateKeysAndValuesUsingBlock: | |
| 12135 (void (^)(BOOL key, BOOL value, BOOL *stop))block { | |
| 12136 BOOL stop = NO; | |
| 12137 if (_valueSet[0]) { | |
| 12138 block(NO, _values[0], &stop); | |
| 12139 } | |
| 12140 if (!stop && _valueSet[1]) { | |
| 12141 block(YES, _values[1], &stop); | |
| 12142 } | |
| 12143 } | |
| 12144 | |
| 12145 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 12146 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 12147 NSUInteger count = 0; | |
| 12148 size_t result = 0; | |
| 12149 for (int i = 0; i < 2; ++i) { | |
| 12150 if (_valueSet[i]) { | |
| 12151 ++count; | |
| 12152 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 12153 msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valu
eDataType); | |
| 12154 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 12155 } | |
| 12156 } | |
| 12157 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 12158 result += tagSize * count; | |
| 12159 return result; | |
| 12160 } | |
| 12161 | |
| 12162 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 12163 asField:(GPBFieldDescriptor *)field { | |
| 12164 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 12165 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 12166 for (int i = 0; i < 2; ++i) { | |
| 12167 if (_valueSet[i]) { | |
| 12168 // Write the tag. | |
| 12169 [outputStream writeInt32NoTag:tag]; | |
| 12170 // Write the size of the message. | |
| 12171 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 12172 msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valu
eDataType); | |
| 12173 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 12174 // Write the fields. | |
| 12175 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataType
Bool); | |
| 12176 WriteDictBoolField(outputStream, _values[i], kMapValueFieldNumber, valueDa
taType); | |
| 12177 } | |
| 12178 } | |
| 12179 } | |
| 12180 | |
| 12181 - (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary { | |
| 12182 if (otherDictionary) { | |
| 12183 for (int i = 0; i < 2; ++i) { | |
| 12184 if (otherDictionary->_valueSet[i]) { | |
| 12185 _valueSet[i] = YES; | |
| 12186 _values[i] = otherDictionary->_values[i]; | |
| 12187 } | |
| 12188 } | |
| 12189 if (_autocreator) { | |
| 12190 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 12191 } | |
| 12192 } | |
| 12193 } | |
| 12194 | |
| 12195 - (void)setValue:(BOOL)value forKey:(BOOL)key { | |
| 12196 int idx = (key ? 1 : 0); | |
| 12197 _values[idx] = value; | |
| 12198 _valueSet[idx] = YES; | |
| 12199 if (_autocreator) { | |
| 12200 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 12201 } | |
| 12202 } | |
| 12203 | |
| 12204 - (void)removeValueForKey:(BOOL)aKey { | |
| 12205 _valueSet[aKey ? 1 : 0] = NO; | |
| 12206 } | |
| 12207 | |
| 12208 - (void)removeAll { | |
| 12209 _valueSet[0] = NO; | |
| 12210 _valueSet[1] = NO; | |
| 12211 } | |
| 12212 | |
| 12213 @end | |
| 12214 | |
| 12215 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float) | |
| 12216 // This block of code is generated, do not edit it directly. | |
| 12217 | |
| 12218 #pragma mark - Bool -> Float | |
| 12219 | |
| 12220 @implementation GPBBoolFloatDictionary { | |
| 12221 @package | |
| 12222 float _values[2]; | |
| 12223 BOOL _valueSet[2]; | |
| 12224 } | |
| 12225 | |
| 12226 + (instancetype)dictionary { | |
| 12227 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 12228 } | |
| 12229 | |
| 12230 + (instancetype)dictionaryWithValue:(float)value | |
| 12231 forKey:(BOOL)key { | |
| 12232 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12233 // on to get the type correct. | |
| 12234 return [[(GPBBoolFloatDictionary*)[self alloc] initWithValues:&value | |
| 12235 forKeys:&key | |
| 12236 count:1] autorelease]; | |
| 12237 } | |
| 12238 | |
| 12239 + (instancetype)dictionaryWithValues:(const float [])values | |
| 12240 forKeys:(const BOOL [])keys | |
| 12241 count:(NSUInteger)count { | |
| 12242 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12243 // on to get the type correct. | |
| 12244 return [[(GPBBoolFloatDictionary*)[self alloc] initWithValues:values | |
| 12245 forKeys:keys | |
| 12246 count:count] autorelea
se]; | |
| 12247 } | |
| 12248 | |
| 12249 + (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary { | |
| 12250 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12251 // on to get the type correct. | |
| 12252 return [[(GPBBoolFloatDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 12253 } | |
| 12254 | |
| 12255 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 12256 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 12257 } | |
| 12258 | |
| 12259 - (instancetype)init { | |
| 12260 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12261 } | |
| 12262 | |
| 12263 - (instancetype)initWithValues:(const float [])values | |
| 12264 forKeys:(const BOOL [])keys | |
| 12265 count:(NSUInteger)count { | |
| 12266 self = [super init]; | |
| 12267 if (self) { | |
| 12268 for (NSUInteger i = 0; i < count; ++i) { | |
| 12269 int idx = keys[i] ? 1 : 0; | |
| 12270 _values[idx] = values[i]; | |
| 12271 _valueSet[idx] = YES; | |
| 12272 } | |
| 12273 } | |
| 12274 return self; | |
| 12275 } | |
| 12276 | |
| 12277 - (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary { | |
| 12278 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12279 if (self) { | |
| 12280 if (dictionary) { | |
| 12281 for (int i = 0; i < 2; ++i) { | |
| 12282 if (dictionary->_valueSet[i]) { | |
| 12283 _values[i] = dictionary->_values[i]; | |
| 12284 _valueSet[i] = YES; | |
| 12285 } | |
| 12286 } | |
| 12287 } | |
| 12288 } | |
| 12289 return self; | |
| 12290 } | |
| 12291 | |
| 12292 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 12293 #pragma unused(numItems) | |
| 12294 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12295 } | |
| 12296 | |
| 12297 #if !defined(NS_BLOCK_ASSERTIONS) | |
| 12298 - (void)dealloc { | |
| 12299 NSAssert(!_autocreator, | |
| 12300 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 12301 [self class], _autocreator); | |
| 12302 [super dealloc]; | |
| 12303 } | |
| 12304 #endif // !defined(NS_BLOCK_ASSERTIONS) | |
| 12305 | |
| 12306 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 12307 return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 12308 } | |
| 12309 | |
| 12310 - (BOOL)isEqual:(GPBBoolFloatDictionary *)other { | |
| 12311 if (self == other) { | |
| 12312 return YES; | |
| 12313 } | |
| 12314 if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) { | |
| 12315 return NO; | |
| 12316 } | |
| 12317 if ((_valueSet[0] != other->_valueSet[0]) || | |
| 12318 (_valueSet[1] != other->_valueSet[1])) { | |
| 12319 return NO; | |
| 12320 } | |
| 12321 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | |
| 12322 (_valueSet[1] && (_values[1] != other->_values[1]))) { | |
| 12323 return NO; | |
| 12324 } | |
| 12325 return YES; | |
| 12326 } | |
| 12327 | |
| 12328 - (NSUInteger)hash { | |
| 12329 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 12330 } | |
| 12331 | |
| 12332 - (NSString *)description { | |
| 12333 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | |
| 12334 if (_valueSet[0]) { | |
| 12335 [result appendFormat:@"NO: %f", _values[0]]; | |
| 12336 } | |
| 12337 if (_valueSet[1]) { | |
| 12338 [result appendFormat:@"YES: %f", _values[1]]; | |
| 12339 } | |
| 12340 [result appendString:@" }"]; | |
| 12341 return result; | |
| 12342 } | |
| 12343 | |
| 12344 - (NSUInteger)count { | |
| 12345 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 12346 } | |
| 12347 | |
| 12348 - (BOOL)valueForKey:(BOOL)key value:(float *)value { | |
| 12349 int idx = (key ? 1 : 0); | |
| 12350 if (_valueSet[idx]) { | |
| 12351 if (value) { | |
| 12352 *value = _values[idx]; | |
| 12353 } | |
| 12354 return YES; | |
| 12355 } | |
| 12356 return NO; | |
| 12357 } | |
| 12358 | |
| 12359 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 12360 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 12361 int idx = (key->valueBool ? 1 : 0); | |
| 12362 _values[idx] = value->valueFloat; | |
| 12363 _valueSet[idx] = YES; | |
| 12364 } | |
| 12365 | |
| 12366 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 12367 if (_valueSet[0]) { | |
| 12368 block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]); | |
| 12369 } | |
| 12370 if (_valueSet[1]) { | |
| 12371 block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]); | |
| 12372 } | |
| 12373 } | |
| 12374 | |
| 12375 - (void)enumerateKeysAndValuesUsingBlock: | |
| 12376 (void (^)(BOOL key, float value, BOOL *stop))block { | |
| 12377 BOOL stop = NO; | |
| 12378 if (_valueSet[0]) { | |
| 12379 block(NO, _values[0], &stop); | |
| 12380 } | |
| 12381 if (!stop && _valueSet[1]) { | |
| 12382 block(YES, _values[1], &stop); | |
| 12383 } | |
| 12384 } | |
| 12385 | |
| 12386 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 12387 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 12388 NSUInteger count = 0; | |
| 12389 size_t result = 0; | |
| 12390 for (int i = 0; i < 2; ++i) { | |
| 12391 if (_valueSet[i]) { | |
| 12392 ++count; | |
| 12393 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 12394 msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, val
ueDataType); | |
| 12395 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 12396 } | |
| 12397 } | |
| 12398 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 12399 result += tagSize * count; | |
| 12400 return result; | |
| 12401 } | |
| 12402 | |
| 12403 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 12404 asField:(GPBFieldDescriptor *)field { | |
| 12405 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 12406 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 12407 for (int i = 0; i < 2; ++i) { | |
| 12408 if (_valueSet[i]) { | |
| 12409 // Write the tag. | |
| 12410 [outputStream writeInt32NoTag:tag]; | |
| 12411 // Write the size of the message. | |
| 12412 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 12413 msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, val
ueDataType); | |
| 12414 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 12415 // Write the fields. | |
| 12416 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataType
Bool); | |
| 12417 WriteDictFloatField(outputStream, _values[i], kMapValueFieldNumber, valueD
ataType); | |
| 12418 } | |
| 12419 } | |
| 12420 } | |
| 12421 | |
| 12422 - (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary { | |
| 12423 if (otherDictionary) { | |
| 12424 for (int i = 0; i < 2; ++i) { | |
| 12425 if (otherDictionary->_valueSet[i]) { | |
| 12426 _valueSet[i] = YES; | |
| 12427 _values[i] = otherDictionary->_values[i]; | |
| 12428 } | |
| 12429 } | |
| 12430 if (_autocreator) { | |
| 12431 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 12432 } | |
| 12433 } | |
| 12434 } | |
| 12435 | |
| 12436 - (void)setValue:(float)value forKey:(BOOL)key { | |
| 12437 int idx = (key ? 1 : 0); | |
| 12438 _values[idx] = value; | |
| 12439 _valueSet[idx] = YES; | |
| 12440 if (_autocreator) { | |
| 12441 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 12442 } | |
| 12443 } | |
| 12444 | |
| 12445 - (void)removeValueForKey:(BOOL)aKey { | |
| 12446 _valueSet[aKey ? 1 : 0] = NO; | |
| 12447 } | |
| 12448 | |
| 12449 - (void)removeAll { | |
| 12450 _valueSet[0] = NO; | |
| 12451 _valueSet[1] = NO; | |
| 12452 } | |
| 12453 | |
| 12454 @end | |
| 12455 | |
| 12456 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double) | |
| 12457 // This block of code is generated, do not edit it directly. | |
| 12458 | |
| 12459 #pragma mark - Bool -> Double | |
| 12460 | |
| 12461 @implementation GPBBoolDoubleDictionary { | |
| 12462 @package | |
| 12463 double _values[2]; | |
| 12464 BOOL _valueSet[2]; | |
| 12465 } | |
| 12466 | |
| 12467 + (instancetype)dictionary { | |
| 12468 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 12469 } | |
| 12470 | |
| 12471 + (instancetype)dictionaryWithValue:(double)value | |
| 12472 forKey:(BOOL)key { | |
| 12473 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12474 // on to get the type correct. | |
| 12475 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithValues:&value | |
| 12476 forKeys:&key | |
| 12477 count:1] autorelease]
; | |
| 12478 } | |
| 12479 | |
| 12480 + (instancetype)dictionaryWithValues:(const double [])values | |
| 12481 forKeys:(const BOOL [])keys | |
| 12482 count:(NSUInteger)count { | |
| 12483 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12484 // on to get the type correct. | |
| 12485 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithValues:values | |
| 12486 forKeys:keys | |
| 12487 count:count] autorele
ase]; | |
| 12488 } | |
| 12489 | |
| 12490 + (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary { | |
| 12491 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12492 // on to get the type correct. | |
| 12493 return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 12494 } | |
| 12495 | |
| 12496 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 12497 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 12498 } | |
| 12499 | |
| 12500 - (instancetype)init { | |
| 12501 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12502 } | |
| 12503 | |
| 12504 - (instancetype)initWithValues:(const double [])values | |
| 12505 forKeys:(const BOOL [])keys | |
| 12506 count:(NSUInteger)count { | |
| 12507 self = [super init]; | |
| 12508 if (self) { | |
| 12509 for (NSUInteger i = 0; i < count; ++i) { | |
| 12510 int idx = keys[i] ? 1 : 0; | |
| 12511 _values[idx] = values[i]; | |
| 12512 _valueSet[idx] = YES; | |
| 12513 } | |
| 12514 } | |
| 12515 return self; | |
| 12516 } | |
| 12517 | |
| 12518 - (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary { | |
| 12519 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12520 if (self) { | |
| 12521 if (dictionary) { | |
| 12522 for (int i = 0; i < 2; ++i) { | |
| 12523 if (dictionary->_valueSet[i]) { | |
| 12524 _values[i] = dictionary->_values[i]; | |
| 12525 _valueSet[i] = YES; | |
| 12526 } | |
| 12527 } | |
| 12528 } | |
| 12529 } | |
| 12530 return self; | |
| 12531 } | |
| 12532 | |
| 12533 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 12534 #pragma unused(numItems) | |
| 12535 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12536 } | |
| 12537 | |
| 12538 #if !defined(NS_BLOCK_ASSERTIONS) | |
| 12539 - (void)dealloc { | |
| 12540 NSAssert(!_autocreator, | |
| 12541 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 12542 [self class], _autocreator); | |
| 12543 [super dealloc]; | |
| 12544 } | |
| 12545 #endif // !defined(NS_BLOCK_ASSERTIONS) | |
| 12546 | |
| 12547 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 12548 return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 12549 } | |
| 12550 | |
| 12551 - (BOOL)isEqual:(GPBBoolDoubleDictionary *)other { | |
| 12552 if (self == other) { | |
| 12553 return YES; | |
| 12554 } | |
| 12555 if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) { | |
| 12556 return NO; | |
| 12557 } | |
| 12558 if ((_valueSet[0] != other->_valueSet[0]) || | |
| 12559 (_valueSet[1] != other->_valueSet[1])) { | |
| 12560 return NO; | |
| 12561 } | |
| 12562 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | |
| 12563 (_valueSet[1] && (_values[1] != other->_values[1]))) { | |
| 12564 return NO; | |
| 12565 } | |
| 12566 return YES; | |
| 12567 } | |
| 12568 | |
| 12569 - (NSUInteger)hash { | |
| 12570 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 12571 } | |
| 12572 | |
| 12573 - (NSString *)description { | |
| 12574 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | |
| 12575 if (_valueSet[0]) { | |
| 12576 [result appendFormat:@"NO: %lf", _values[0]]; | |
| 12577 } | |
| 12578 if (_valueSet[1]) { | |
| 12579 [result appendFormat:@"YES: %lf", _values[1]]; | |
| 12580 } | |
| 12581 [result appendString:@" }"]; | |
| 12582 return result; | |
| 12583 } | |
| 12584 | |
| 12585 - (NSUInteger)count { | |
| 12586 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 12587 } | |
| 12588 | |
| 12589 - (BOOL)valueForKey:(BOOL)key value:(double *)value { | |
| 12590 int idx = (key ? 1 : 0); | |
| 12591 if (_valueSet[idx]) { | |
| 12592 if (value) { | |
| 12593 *value = _values[idx]; | |
| 12594 } | |
| 12595 return YES; | |
| 12596 } | |
| 12597 return NO; | |
| 12598 } | |
| 12599 | |
| 12600 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 12601 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 12602 int idx = (key->valueBool ? 1 : 0); | |
| 12603 _values[idx] = value->valueDouble; | |
| 12604 _valueSet[idx] = YES; | |
| 12605 } | |
| 12606 | |
| 12607 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 12608 if (_valueSet[0]) { | |
| 12609 block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]); | |
| 12610 } | |
| 12611 if (_valueSet[1]) { | |
| 12612 block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]); | |
| 12613 } | |
| 12614 } | |
| 12615 | |
| 12616 - (void)enumerateKeysAndValuesUsingBlock: | |
| 12617 (void (^)(BOOL key, double value, BOOL *stop))block { | |
| 12618 BOOL stop = NO; | |
| 12619 if (_valueSet[0]) { | |
| 12620 block(NO, _values[0], &stop); | |
| 12621 } | |
| 12622 if (!stop && _valueSet[1]) { | |
| 12623 block(YES, _values[1], &stop); | |
| 12624 } | |
| 12625 } | |
| 12626 | |
| 12627 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 12628 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 12629 NSUInteger count = 0; | |
| 12630 size_t result = 0; | |
| 12631 for (int i = 0; i < 2; ++i) { | |
| 12632 if (_valueSet[i]) { | |
| 12633 ++count; | |
| 12634 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 12635 msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, va
lueDataType); | |
| 12636 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 12637 } | |
| 12638 } | |
| 12639 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 12640 result += tagSize * count; | |
| 12641 return result; | |
| 12642 } | |
| 12643 | |
| 12644 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 12645 asField:(GPBFieldDescriptor *)field { | |
| 12646 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 12647 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 12648 for (int i = 0; i < 2; ++i) { | |
| 12649 if (_valueSet[i]) { | |
| 12650 // Write the tag. | |
| 12651 [outputStream writeInt32NoTag:tag]; | |
| 12652 // Write the size of the message. | |
| 12653 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 12654 msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, va
lueDataType); | |
| 12655 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 12656 // Write the fields. | |
| 12657 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataType
Bool); | |
| 12658 WriteDictDoubleField(outputStream, _values[i], kMapValueFieldNumber, value
DataType); | |
| 12659 } | |
| 12660 } | |
| 12661 } | |
| 12662 | |
| 12663 - (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary { | |
| 12664 if (otherDictionary) { | |
| 12665 for (int i = 0; i < 2; ++i) { | |
| 12666 if (otherDictionary->_valueSet[i]) { | |
| 12667 _valueSet[i] = YES; | |
| 12668 _values[i] = otherDictionary->_values[i]; | |
| 12669 } | |
| 12670 } | |
| 12671 if (_autocreator) { | |
| 12672 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 12673 } | |
| 12674 } | |
| 12675 } | |
| 12676 | |
| 12677 - (void)setValue:(double)value forKey:(BOOL)key { | |
| 12678 int idx = (key ? 1 : 0); | |
| 12679 _values[idx] = value; | |
| 12680 _valueSet[idx] = YES; | |
| 12681 if (_autocreator) { | |
| 12682 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 12683 } | |
| 12684 } | |
| 12685 | |
| 12686 - (void)removeValueForKey:(BOOL)aKey { | |
| 12687 _valueSet[aKey ? 1 : 0] = NO; | |
| 12688 } | |
| 12689 | |
| 12690 - (void)removeAll { | |
| 12691 _valueSet[0] = NO; | |
| 12692 _valueSet[1] = NO; | |
| 12693 } | |
| 12694 | |
| 12695 @end | |
| 12696 | |
| 12697 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(Object, id) | |
| 12698 // This block of code is generated, do not edit it directly. | |
| 12699 | |
| 12700 #pragma mark - Bool -> Object | |
| 12701 | |
| 12702 @implementation GPBBoolObjectDictionary { | |
| 12703 @package | |
| 12704 id _values[2]; | |
| 12705 } | |
| 12706 | |
| 12707 + (instancetype)dictionary { | |
| 12708 return [[[self alloc] initWithValues:NULL forKeys:NULL count:0] autorelease]; | |
| 12709 } | |
| 12710 | |
| 12711 + (instancetype)dictionaryWithValue:(id)value | |
| 12712 forKey:(BOOL)key { | |
| 12713 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12714 // on to get the type correct. | |
| 12715 return [[(GPBBoolObjectDictionary*)[self alloc] initWithValues:&value | |
| 12716 forKeys:&key | |
| 12717 count:1] autorelease]
; | |
| 12718 } | |
| 12719 | |
| 12720 + (instancetype)dictionaryWithValues:(const id [])values | |
| 12721 forKeys:(const BOOL [])keys | |
| 12722 count:(NSUInteger)count { | |
| 12723 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12724 // on to get the type correct. | |
| 12725 return [[(GPBBoolObjectDictionary*)[self alloc] initWithValues:values | |
| 12726 forKeys:keys | |
| 12727 count:count] autorele
ase]; | |
| 12728 } | |
| 12729 | |
| 12730 + (instancetype)dictionaryWithDictionary:(GPBBoolObjectDictionary *)dictionary { | |
| 12731 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12732 // on to get the type correct. | |
| 12733 return [[(GPBBoolObjectDictionary*)[self alloc] initWithDictionary:dictionary]
autorelease]; | |
| 12734 } | |
| 12735 | |
| 12736 + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { | |
| 12737 return [[[self alloc] initWithCapacity:numItems] autorelease]; | |
| 12738 } | |
| 12739 | |
| 12740 - (instancetype)init { | |
| 12741 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12742 } | |
| 12743 | |
| 12744 - (instancetype)initWithValues:(const id [])values | |
| 12745 forKeys:(const BOOL [])keys | |
| 12746 count:(NSUInteger)count { | |
| 12747 self = [super init]; | |
| 12748 if (self) { | |
| 12749 for (NSUInteger i = 0; i < count; ++i) { | |
| 12750 int idx = keys[i] ? 1 : 0; | |
| 12751 [_values[idx] release]; | |
| 12752 _values[idx] = (id)[values[i] retain]; | |
| 12753 } | |
| 12754 } | |
| 12755 return self; | |
| 12756 } | |
| 12757 | |
| 12758 - (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary { | |
| 12759 self = [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12760 if (self) { | |
| 12761 if (dictionary) { | |
| 12762 _values[0] = [dictionary->_values[0] retain]; | |
| 12763 _values[1] = [dictionary->_values[1] retain]; | |
| 12764 } | |
| 12765 } | |
| 12766 return self; | |
| 12767 } | |
| 12768 | |
| 12769 - (instancetype)initWithCapacity:(NSUInteger)numItems { | |
| 12770 #pragma unused(numItems) | |
| 12771 return [self initWithValues:NULL forKeys:NULL count:0]; | |
| 12772 } | |
| 12773 | |
| 12774 - (void)dealloc { | |
| 12775 NSAssert(!_autocreator, | |
| 12776 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 12777 [self class], _autocreator); | |
| 12778 [_values[0] release]; | |
| 12779 [_values[1] release]; | |
| 12780 [super dealloc]; | |
| 12781 } | |
| 12782 | |
| 12783 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 12784 return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 12785 } | |
| 12786 | |
| 12787 - (BOOL)isEqual:(GPBBoolObjectDictionary *)other { | |
| 12788 if (self == other) { | |
| 12789 return YES; | |
| 12790 } | |
| 12791 if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) { | |
| 12792 return NO; | |
| 12793 } | |
| 12794 if (((_values[0] != nil) != (other->_values[0] != nil)) || | |
| 12795 ((_values[1] != nil) != (other->_values[1] != nil))) { | |
| 12796 return NO; | |
| 12797 } | |
| 12798 if (((_values[0] != nil) && (![_values[0] isEqual:other->_values[0]])) || | |
| 12799 ((_values[1] != nil) && (![_values[1] isEqual:other->_values[1]]))) { | |
| 12800 return NO; | |
| 12801 } | |
| 12802 return YES; | |
| 12803 } | |
| 12804 | |
| 12805 - (NSUInteger)hash { | |
| 12806 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0); | |
| 12807 } | |
| 12808 | |
| 12809 - (NSString *)description { | |
| 12810 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | |
| 12811 if ((_values[0] != nil)) { | |
| 12812 [result appendFormat:@"NO: %@", _values[0]]; | |
| 12813 } | |
| 12814 if ((_values[1] != nil)) { | |
| 12815 [result appendFormat:@"YES: %@", _values[1]]; | |
| 12816 } | |
| 12817 [result appendString:@" }"]; | |
| 12818 return result; | |
| 12819 } | |
| 12820 | |
| 12821 - (NSUInteger)count { | |
| 12822 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0); | |
| 12823 } | |
| 12824 | |
| 12825 - (id)valueForKey:(BOOL)key { | |
| 12826 return _values[key ? 1 : 0]; | |
| 12827 } | |
| 12828 | |
| 12829 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 12830 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 12831 int idx = (key->valueBool ? 1 : 0); | |
| 12832 [_values[idx] release]; | |
| 12833 _values[idx] = [value->valueString retain]; | |
| 12834 } | |
| 12835 | |
| 12836 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 12837 if (_values[0] != nil) { | |
| 12838 block(@"false", _values[0]); | |
| 12839 } | |
| 12840 if ((_values[1] != nil)) { | |
| 12841 block(@"true", _values[1]); | |
| 12842 } | |
| 12843 } | |
| 12844 | |
| 12845 - (void)enumerateKeysAndValuesUsingBlock: | |
| 12846 (void (^)(BOOL key, id value, BOOL *stop))block { | |
| 12847 BOOL stop = NO; | |
| 12848 if (_values[0] != nil) { | |
| 12849 block(NO, _values[0], &stop); | |
| 12850 } | |
| 12851 if (!stop && (_values[1] != nil)) { | |
| 12852 block(YES, _values[1], &stop); | |
| 12853 } | |
| 12854 } | |
| 12855 | |
| 12856 - (BOOL)isInitialized { | |
| 12857 if (_values[0] && ![_values[0] isInitialized]) { | |
| 12858 return NO; | |
| 12859 } | |
| 12860 if (_values[1] && ![_values[1] isInitialized]) { | |
| 12861 return NO; | |
| 12862 } | |
| 12863 return YES; | |
| 12864 } | |
| 12865 | |
| 12866 - (instancetype)deepCopyWithZone:(NSZone *)zone { | |
| 12867 GPBBoolObjectDictionary *newDict = | |
| 12868 [[GPBBoolObjectDictionary alloc] init]; | |
| 12869 for (int i = 0; i < 2; ++i) { | |
| 12870 if (_values[i] != nil) { | |
| 12871 newDict->_values[i] = [_values[i] copyWithZone:zone]; | |
| 12872 } | |
| 12873 } | |
| 12874 return newDict; | |
| 12875 } | |
| 12876 | |
| 12877 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 12878 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 12879 NSUInteger count = 0; | |
| 12880 size_t result = 0; | |
| 12881 for (int i = 0; i < 2; ++i) { | |
| 12882 if (_values[i] != nil) { | |
| 12883 ++count; | |
| 12884 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 12885 msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, va
lueDataType); | |
| 12886 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 12887 } | |
| 12888 } | |
| 12889 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 12890 result += tagSize * count; | |
| 12891 return result; | |
| 12892 } | |
| 12893 | |
| 12894 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 12895 asField:(GPBFieldDescriptor *)field { | |
| 12896 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 12897 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 12898 for (int i = 0; i < 2; ++i) { | |
| 12899 if (_values[i] != nil) { | |
| 12900 // Write the tag. | |
| 12901 [outputStream writeInt32NoTag:tag]; | |
| 12902 // Write the size of the message. | |
| 12903 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 12904 msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, va
lueDataType); | |
| 12905 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 12906 // Write the fields. | |
| 12907 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataType
Bool); | |
| 12908 WriteDictObjectField(outputStream, _values[i], kMapValueFieldNumber, value
DataType); | |
| 12909 } | |
| 12910 } | |
| 12911 } | |
| 12912 | |
| 12913 - (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary { | |
| 12914 if (otherDictionary) { | |
| 12915 for (int i = 0; i < 2; ++i) { | |
| 12916 if (otherDictionary->_values[i] != nil) { | |
| 12917 [_values[i] release]; | |
| 12918 _values[i] = [otherDictionary->_values[i] retain]; | |
| 12919 } | |
| 12920 } | |
| 12921 if (_autocreator) { | |
| 12922 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 12923 } | |
| 12924 } | |
| 12925 } | |
| 12926 | |
| 12927 - (void)setValue:(id)value forKey:(BOOL)key { | |
| 12928 int idx = (key ? 1 : 0); | |
| 12929 [_values[idx] release]; | |
| 12930 _values[idx] = [value retain]; | |
| 12931 if (_autocreator) { | |
| 12932 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 12933 } | |
| 12934 } | |
| 12935 | |
| 12936 - (void)removeValueForKey:(BOOL)aKey { | |
| 12937 int idx = (aKey ? 1 : 0); | |
| 12938 [_values[idx] release]; | |
| 12939 _values[idx] = nil; | |
| 12940 } | |
| 12941 | |
| 12942 - (void)removeAll { | |
| 12943 for (int i = 0; i < 2; ++i) { | |
| 12944 [_values[i] release]; | |
| 12945 _values[i] = nil; | |
| 12946 } | |
| 12947 } | |
| 12948 | |
| 12949 @end | |
| 12950 | |
| 12951 //%PDDM-EXPAND-END (8 expansions) | |
| 12952 | |
| 12953 #pragma mark - Bool -> Enum | |
| 12954 | |
| 12955 @implementation GPBBoolEnumDictionary { | |
| 12956 @package | |
| 12957 GPBEnumValidationFunc _validationFunc; | |
| 12958 int32_t _values[2]; | |
| 12959 BOOL _valueSet[2]; | |
| 12960 } | |
| 12961 | |
| 12962 @synthesize validationFunc = _validationFunc; | |
| 12963 | |
| 12964 + (instancetype)dictionary { | |
| 12965 return [[[self alloc] initWithValidationFunction:NULL | |
| 12966 rawValues:NULL | |
| 12967 forKeys:NULL | |
| 12968 count:0] autorelease]; | |
| 12969 } | |
| 12970 | |
| 12971 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 12972 return [[[self alloc] initWithValidationFunction:func | |
| 12973 rawValues:NULL | |
| 12974 forKeys:NULL | |
| 12975 count:0] autorelease]; | |
| 12976 } | |
| 12977 | |
| 12978 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 12979 rawValue:(int32_t)rawValue | |
| 12980 forKey:(BOOL)key { | |
| 12981 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12982 // on to get the type correct. | |
| 12983 return [[(GPBBoolEnumDictionary*)[self alloc] initWithValidationFunction:func | |
| 12984 rawValues:&rawV
alue | |
| 12985 forKeys:&key | |
| 12986 count:1] au
torelease]; | |
| 12987 } | |
| 12988 | |
| 12989 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 12990 rawValues:(const int32_t [])values | |
| 12991 forKeys:(const BOOL [])keys | |
| 12992 count:(NSUInteger)count { | |
| 12993 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 12994 // on to get the type correct. | |
| 12995 return [[(GPBBoolEnumDictionary*)[self alloc] initWithValidationFunction:func | |
| 12996 rawValues:value
s | |
| 12997 forKeys:keys | |
| 12998 count:count
] autorelease]; | |
| 12999 } | |
| 13000 | |
| 13001 + (instancetype)dictionaryWithDictionary:(GPBBoolEnumDictionary *)dictionary { | |
| 13002 // Cast is needed so the compiler knows what class we are invoking initWithVal
ues:forKeys:count: | |
| 13003 // on to get the type correct. | |
| 13004 return [[(GPBBoolEnumDictionary*)[self alloc] initWithDictionary:dictionary] a
utorelease]; | |
| 13005 } | |
| 13006 | |
| 13007 + (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func | |
| 13008 capacity:(NSUInteger)numItems { | |
| 13009 return [[[self alloc] initWithValidationFunction:func capacity:numItems] autor
elease]; | |
| 13010 } | |
| 13011 | |
| 13012 - (instancetype)init { | |
| 13013 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count
:0]; | |
| 13014 } | |
| 13015 | |
| 13016 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { | |
| 13017 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 13018 } | |
| 13019 | |
| 13020 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 13021 rawValues:(const int32_t [])rawValues | |
| 13022 forKeys:(const BOOL [])keys | |
| 13023 count:(NSUInteger)count { | |
| 13024 self = [super init]; | |
| 13025 if (self) { | |
| 13026 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); | |
| 13027 for (NSUInteger i = 0; i < count; ++i) { | |
| 13028 int idx = keys[i] ? 1 : 0; | |
| 13029 _values[idx] = rawValues[i]; | |
| 13030 _valueSet[idx] = YES; | |
| 13031 } | |
| 13032 } | |
| 13033 return self; | |
| 13034 } | |
| 13035 | |
| 13036 - (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary { | |
| 13037 self = [self initWithValidationFunction:dictionary.validationFunc | |
| 13038 rawValues:NULL | |
| 13039 forKeys:NULL | |
| 13040 count:0]; | |
| 13041 if (self) { | |
| 13042 if (dictionary) { | |
| 13043 for (int i = 0; i < 2; ++i) { | |
| 13044 if (dictionary->_valueSet[i]) { | |
| 13045 _values[i] = dictionary->_values[i]; | |
| 13046 _valueSet[i] = YES; | |
| 13047 } | |
| 13048 } | |
| 13049 } | |
| 13050 } | |
| 13051 return self; | |
| 13052 } | |
| 13053 | |
| 13054 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func | |
| 13055 capacity:(NSUInteger)numItems { | |
| 13056 #pragma unused(numItems) | |
| 13057 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count
:0]; | |
| 13058 } | |
| 13059 | |
| 13060 #if !defined(NS_BLOCK_ASSERTIONS) | |
| 13061 - (void)dealloc { | |
| 13062 NSAssert(!_autocreator, | |
| 13063 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 13064 [self class], _autocreator); | |
| 13065 [super dealloc]; | |
| 13066 } | |
| 13067 #endif // !defined(NS_BLOCK_ASSERTIONS) | |
| 13068 | |
| 13069 - (instancetype)copyWithZone:(NSZone *)zone { | |
| 13070 return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self]; | |
| 13071 } | |
| 13072 | |
| 13073 - (BOOL)isEqual:(GPBBoolEnumDictionary *)other { | |
| 13074 if (self == other) { | |
| 13075 return YES; | |
| 13076 } | |
| 13077 if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) { | |
| 13078 return NO; | |
| 13079 } | |
| 13080 if ((_valueSet[0] != other->_valueSet[0]) || | |
| 13081 (_valueSet[1] != other->_valueSet[1])) { | |
| 13082 return NO; | |
| 13083 } | |
| 13084 if ((_valueSet[0] && (_values[0] != other->_values[0])) || | |
| 13085 (_valueSet[1] && (_values[1] != other->_values[1]))) { | |
| 13086 return NO; | |
| 13087 } | |
| 13088 return YES; | |
| 13089 } | |
| 13090 | |
| 13091 - (NSUInteger)hash { | |
| 13092 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 13093 } | |
| 13094 | |
| 13095 - (NSString *)description { | |
| 13096 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [sel
f class], self]; | |
| 13097 if (_valueSet[0]) { | |
| 13098 [result appendFormat:@"NO: %d", _values[0]]; | |
| 13099 } | |
| 13100 if (_valueSet[1]) { | |
| 13101 [result appendFormat:@"YES: %d", _values[1]]; | |
| 13102 } | |
| 13103 [result appendString:@" }"]; | |
| 13104 return result; | |
| 13105 } | |
| 13106 | |
| 13107 - (NSUInteger)count { | |
| 13108 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); | |
| 13109 } | |
| 13110 | |
| 13111 - (BOOL)valueForKey:(BOOL)key value:(int32_t*)value { | |
| 13112 int idx = (key ? 1 : 0); | |
| 13113 if (_valueSet[idx]) { | |
| 13114 if (value) { | |
| 13115 int32_t result = _values[idx]; | |
| 13116 if (!_validationFunc(result)) { | |
| 13117 result = kGPBUnrecognizedEnumeratorValue; | |
| 13118 } | |
| 13119 *value = result; | |
| 13120 } | |
| 13121 return YES; | |
| 13122 } | |
| 13123 return NO; | |
| 13124 } | |
| 13125 | |
| 13126 - (BOOL)valueForKey:(BOOL)key rawValue:(int32_t*)rawValue { | |
| 13127 int idx = (key ? 1 : 0); | |
| 13128 if (_valueSet[idx]) { | |
| 13129 if (rawValue) { | |
| 13130 *rawValue = _values[idx]; | |
| 13131 } | |
| 13132 return YES; | |
| 13133 } | |
| 13134 return NO; | |
| 13135 } | |
| 13136 | |
| 13137 - (void)enumerateKeysAndValuesUsingBlock: | |
| 13138 (void (^)(BOOL key, int32_t value, BOOL *stop))block { | |
| 13139 BOOL stop = NO; | |
| 13140 if (_valueSet[0]) { | |
| 13141 block(NO, _values[0], &stop); | |
| 13142 } | |
| 13143 if (!stop && _valueSet[1]) { | |
| 13144 block(YES, _values[1], &stop); | |
| 13145 } | |
| 13146 } | |
| 13147 | |
| 13148 - (void)enumerateKeysAndRawValuesUsingBlock: | |
| 13149 (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block { | |
| 13150 BOOL stop = NO; | |
| 13151 GPBEnumValidationFunc func = _validationFunc; | |
| 13152 int32_t validatedValue; | |
| 13153 if (_valueSet[0]) { | |
| 13154 validatedValue = _values[0]; | |
| 13155 if (!func(validatedValue)) { | |
| 13156 validatedValue = kGPBUnrecognizedEnumeratorValue; | |
| 13157 } | |
| 13158 block(NO, validatedValue, &stop); | |
| 13159 } | |
| 13160 if (!stop && _valueSet[1]) { | |
| 13161 validatedValue = _values[1]; | |
| 13162 if (!func(validatedValue)) { | |
| 13163 validatedValue = kGPBUnrecognizedEnumeratorValue; | |
| 13164 } | |
| 13165 block(YES, validatedValue, &stop); | |
| 13166 } | |
| 13167 } | |
| 13168 | |
| 13169 //%PDDM-EXPAND SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool) | |
| 13170 // This block of code is generated, do not edit it directly. | |
| 13171 | |
| 13172 - (NSData *)serializedDataForUnknownValue:(int32_t)value | |
| 13173 forKey:(GPBGenericValue *)key | |
| 13174 keyDataType:(GPBDataType)keyDataType { | |
| 13175 size_t msgSize = ComputeDictBoolFieldSize(key->valueBool, kMapKeyFieldNumber,
keyDataType); | |
| 13176 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEn
um); | |
| 13177 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; | |
| 13178 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithDat
a:data]; | |
| 13179 WriteDictBoolField(outputStream, key->valueBool, kMapKeyFieldNumber, keyDataTy
pe); | |
| 13180 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum)
; | |
| 13181 [outputStream release]; | |
| 13182 return data; | |
| 13183 } | |
| 13184 | |
| 13185 //%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool) | |
| 13186 | |
| 13187 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { | |
| 13188 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 13189 NSUInteger count = 0; | |
| 13190 size_t result = 0; | |
| 13191 for (int i = 0; i < 2; ++i) { | |
| 13192 if (_valueSet[i]) { | |
| 13193 ++count; | |
| 13194 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 13195 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, val
ueDataType); | |
| 13196 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; | |
| 13197 } | |
| 13198 } | |
| 13199 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTyp
eMessage); | |
| 13200 result += tagSize * count; | |
| 13201 return result; | |
| 13202 } | |
| 13203 | |
| 13204 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream | |
| 13205 asField:(GPBFieldDescriptor *)field { | |
| 13206 GPBDataType valueDataType = GPBGetFieldDataType(field); | |
| 13207 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLength
Delimited); | |
| 13208 for (int i = 0; i < 2; ++i) { | |
| 13209 if (_valueSet[i]) { | |
| 13210 // Write the tag. | |
| 13211 [outputStream writeInt32NoTag:tag]; | |
| 13212 // Write the size of the message. | |
| 13213 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GP
BDataTypeBool); | |
| 13214 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, val
ueDataType); | |
| 13215 [outputStream writeInt32NoTag:(int32_t)msgSize]; | |
| 13216 // Write the fields. | |
| 13217 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataType
Bool); | |
| 13218 WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueD
ataType); | |
| 13219 } | |
| 13220 } | |
| 13221 } | |
| 13222 | |
| 13223 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block { | |
| 13224 if (_valueSet[0]) { | |
| 13225 block(@"false", @(_values[0])); | |
| 13226 } | |
| 13227 if (_valueSet[1]) { | |
| 13228 block(@"true", @(_values[1])); | |
| 13229 } | |
| 13230 } | |
| 13231 | |
| 13232 - (void)setGPBGenericValue:(GPBGenericValue *)value | |
| 13233 forGPBGenericValueKey:(GPBGenericValue *)key { | |
| 13234 int idx = (key->valueBool ? 1 : 0); | |
| 13235 _values[idx] = value->valueInt32; | |
| 13236 _valueSet[idx] = YES; | |
| 13237 } | |
| 13238 | |
| 13239 - (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary { | |
| 13240 if (otherDictionary) { | |
| 13241 for (int i = 0; i < 2; ++i) { | |
| 13242 if (otherDictionary->_valueSet[i]) { | |
| 13243 _valueSet[i] = YES; | |
| 13244 _values[i] = otherDictionary->_values[i]; | |
| 13245 } | |
| 13246 } | |
| 13247 if (_autocreator) { | |
| 13248 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 13249 } | |
| 13250 } | |
| 13251 } | |
| 13252 | |
| 13253 - (void)setValue:(int32_t)value forKey:(BOOL)key { | |
| 13254 if (!_validationFunc(value)) { | |
| 13255 [NSException raise:NSInvalidArgumentException | |
| 13256 format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum v
alue (%d)", | |
| 13257 value]; | |
| 13258 } | |
| 13259 int idx = (key ? 1 : 0); | |
| 13260 _values[idx] = value; | |
| 13261 _valueSet[idx] = YES; | |
| 13262 if (_autocreator) { | |
| 13263 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 13264 } | |
| 13265 } | |
| 13266 | |
| 13267 - (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key { | |
| 13268 int idx = (key ? 1 : 0); | |
| 13269 _values[idx] = rawValue; | |
| 13270 _valueSet[idx] = YES; | |
| 13271 if (_autocreator) { | |
| 13272 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 13273 } | |
| 13274 } | |
| 13275 | |
| 13276 - (void)removeValueForKey:(BOOL)aKey { | |
| 13277 _valueSet[aKey ? 1 : 0] = NO; | |
| 13278 } | |
| 13279 | |
| 13280 - (void)removeAll { | |
| 13281 _valueSet[0] = NO; | |
| 13282 _valueSet[1] = NO; | |
| 13283 } | |
| 13284 | |
| 13285 @end | |
| 13286 | |
| 13287 #pragma mark - NSDictionary Subclass | |
| 13288 | |
| 13289 @implementation GPBAutocreatedDictionary { | |
| 13290 NSMutableDictionary *_dictionary; | |
| 13291 } | |
| 13292 | |
| 13293 - (void)dealloc { | |
| 13294 NSAssert(!_autocreator, | |
| 13295 @"%@: Autocreator must be cleared before release, autocreator: %@", | |
| 13296 [self class], _autocreator); | |
| 13297 [_dictionary release]; | |
| 13298 [super dealloc]; | |
| 13299 } | |
| 13300 | |
| 13301 #pragma mark Required NSDictionary overrides | |
| 13302 | |
| 13303 - (instancetype)initWithObjects:(const id [])objects | |
| 13304 forKeys:(const id<NSCopying> [])keys | |
| 13305 count:(NSUInteger)count { | |
| 13306 self = [super init]; | |
| 13307 if (self) { | |
| 13308 _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects | |
| 13309 forKeys:keys | |
| 13310 count:count]; | |
| 13311 } | |
| 13312 return self; | |
| 13313 } | |
| 13314 | |
| 13315 - (NSUInteger)count { | |
| 13316 return [_dictionary count]; | |
| 13317 } | |
| 13318 | |
| 13319 - (id)objectForKey:(id)aKey { | |
| 13320 return [_dictionary objectForKey:aKey]; | |
| 13321 } | |
| 13322 | |
| 13323 - (NSEnumerator *)keyEnumerator { | |
| 13324 if (_dictionary == nil) { | |
| 13325 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 13326 } | |
| 13327 return [_dictionary keyEnumerator]; | |
| 13328 } | |
| 13329 | |
| 13330 #pragma mark Required NSMutableDictionary overrides | |
| 13331 | |
| 13332 // Only need to call GPBAutocreatedDictionaryModified() when adding things | |
| 13333 // since we only autocreate empty dictionaries. | |
| 13334 | |
| 13335 - (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey { | |
| 13336 if (_dictionary == nil) { | |
| 13337 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 13338 } | |
| 13339 [_dictionary setObject:anObject forKey:aKey]; | |
| 13340 if (_autocreator) { | |
| 13341 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 13342 } | |
| 13343 } | |
| 13344 | |
| 13345 - (void)removeObjectForKey:(id)aKey { | |
| 13346 [_dictionary removeObjectForKey:aKey]; | |
| 13347 } | |
| 13348 | |
| 13349 #pragma mark Extra things hooked | |
| 13350 | |
| 13351 - (id)copyWithZone:(NSZone *)zone { | |
| 13352 if (_dictionary == nil) { | |
| 13353 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 13354 } | |
| 13355 return [_dictionary copyWithZone:zone]; | |
| 13356 } | |
| 13357 | |
| 13358 - (id)mutableCopyWithZone:(NSZone *)zone { | |
| 13359 if (_dictionary == nil) { | |
| 13360 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 13361 } | |
| 13362 return [_dictionary mutableCopyWithZone:zone]; | |
| 13363 } | |
| 13364 | |
| 13365 - (id)objectForKeyedSubscript:(id)key { | |
| 13366 return [_dictionary objectForKeyedSubscript:key]; | |
| 13367 } | |
| 13368 | |
| 13369 - (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key { | |
| 13370 if (_dictionary == nil) { | |
| 13371 _dictionary = [[NSMutableDictionary alloc] init]; | |
| 13372 } | |
| 13373 [_dictionary setObject:obj forKeyedSubscript:key]; | |
| 13374 if (_autocreator) { | |
| 13375 GPBAutocreatedDictionaryModified(_autocreator, self); | |
| 13376 } | |
| 13377 } | |
| 13378 | |
| 13379 - (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key, | |
| 13380 id obj, | |
| 13381 BOOL *stop))block { | |
| 13382 [_dictionary enumerateKeysAndObjectsUsingBlock:block]; | |
| 13383 } | |
| 13384 | |
| 13385 - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts | |
| 13386 usingBlock:(void (^)(id key, | |
| 13387 id obj, | |
| 13388 BOOL *stop))block { | |
| 13389 [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block]; | |
| 13390 } | |
| 13391 | |
| 13392 @end | |
| OLD | NEW |