Overview
Comment: | Various style improvements. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
c7e66feb303408157ea0f212ded7d3ac |
User & Date: | js on 2011-04-22 16:23:38 |
Other Links: | manifest | tags |
Context
2011-04-22
| ||
16:31 |
Make OFCopying and OFComparing conform to OFObject. Also make OFMutableCopying conform to OFCopying. check-in: b46a3eccdb user: js tags: trunk | |
16:23 | Various style improvements. check-in: c7e66feb30 user: js tags: trunk | |
15:48 | Style improvements in OFDate. check-in: 8c349fdf52 user: js tags: trunk | |
Changes
Modified src/OFArray.h from [463e7000aa] to [e10afe8afa].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFCollection.h" #import "OFEnumerator.h" @class OFDataArray; @class OFString; #ifdef OF_HAVE_BLOCKS | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | #import "OFCollection.h" #import "OFEnumerator.h" @class OFDataArray; @class OFString; #ifdef OF_HAVE_BLOCKS typedef void (^of_array_enumeration_block_t)(id object, size_t index, BOOL *stop); typedef BOOL (^of_array_filter_block_t)(id odject, size_t index); typedef id (^of_array_map_block_t)(id object, size_t index); #endif /** * \brief A class for storing objects in an array. */ @interface OFArray: OFObject <OFCopying, OFMutableCopying, OFCollection, OFFastEnumeration> { OFDataArray *array; } /** * \return A new autoreleased OFArray */ + array; /** * Creates a new OFArray with the specified object. * * \param object An object * \return A new autoreleased OFArray */ + arrayWithObject: (id)object; /** * Creates a new OFArray with the specified objects, terminated by nil. * * \param firstObject The first object in the array * \return A new autoreleased OFArray */ + arrayWithObjects: (id)firstObject, ...; /** * Creates a new OFArray with the objects from the specified C array. * * \param objects A C array of objects, terminated with nil * \return A new autoreleased OFArray */ + arrayWithCArray: (id*)objects; /** * Creates a new OFArray with the objects from the specified C array of the * specified length. * * \param objects A C array of objects * \param length The length of the C array * \return A new autoreleased OFArray */ + arrayWithCArray: (id*)objects length: (size_t)length; /** * Initializes an OFArray with the specified object. * * \param object An object * \return An initialized OFArray */ - initWithObject: (id)object; /** * Initializes an OFArray with the specified objects. * * \param firstObject The first object * \return An initialized OFArray */ - initWithObjects: (id)firstObject, ...; /** * Initializes an OFArray with the specified object and a va_list. * * \param firstObject The first object * \param arguments A va_list * \return An initialized OFArray */ - initWithObject: (id)firstObject argumentList: (va_list)arguments; /** * Initializes an OFArray with the objects from the specified C array. * * \param objects A C array of objects, terminated with nil * \return An initialized OFArray */ - initWithCArray: (id*)objects; /** * Initializes an OFArray with the objects from the specified C array of the * specified length. * * \param objects A C array of objects * \param length The length of the C array * \return An initialized OFArray */ - initWithCArray: (id*)objects length: (size_t)length; /** * \return The objects of the array as a C array */ - (id*)cArray; /** |
︙ | ︙ | |||
139 140 141 142 143 144 145 | */ - (id)objectAtIndex: (size_t)index; /** * Returns the index of the first object that is equivalent to the specified * object or OF_INVALID_INDEX if it was not found. * | | | | | | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | */ - (id)objectAtIndex: (size_t)index; /** * Returns the index of the first object that is equivalent to the specified * object or OF_INVALID_INDEX if it was not found. * * \param object The object whose index is returned * \return The index of the first object equivalent to the specified object * or OF_INVALID_INDEX if it was not found */ - (size_t)indexOfObject: (id)object; /** * Returns the index of the first object that has the same address as the * specified object or OF_INVALID_INDEX if it was not found. * * \param object The object whose index is returned * \return The index of the first object that has the same aaddress as * the specified object or OF_INVALID_INDEX if it was not found */ - (size_t)indexOfObjectIdenticalTo: (id)object; /** * Returns the first object of the array or nil. * * The returned object is <i>not</i> retained and autoreleased for performance * reasons! * |
︙ | ︙ | |||
214 215 216 217 218 219 220 | - (void)makeObjectsPerformSelector: (SEL)selector; /** * Performs the specified selector on all objects in the array with the * specified object. * * \param selector The selector to perform on all objects in the array | | | | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | - (void)makeObjectsPerformSelector: (SEL)selector; /** * Performs the specified selector on all objects in the array with the * specified object. * * \param selector The selector to perform on all objects in the array * \param object The object to perform the selector with on all objects in the * array */ - (void)makeObjectsPerformSelector: (SEL)selector withObject: (id)object; #ifdef OF_HAVE_BLOCKS /** * Executes a block for each object. * * \param block The block to execute for each object */ |
︙ | ︙ |
Modified src/OFArray.m from [57851d31d6] to [b8875e845f].
︙ | ︙ | |||
30 31 32 33 34 35 36 | @implementation OFArray + array { return [[[self alloc] init] autorelease]; } | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | @implementation OFArray + array { return [[[self alloc] init] autorelease]; } + arrayWithObject: (id)object { return [[[self alloc] initWithObject: object] autorelease]; } + arrayWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [[[self alloc] initWithObject: firstObject argumentList: arguments] autorelease]; va_end(arguments); return ret; } + arrayWithCArray: (id*)objects { return [[[self alloc] initWithCArray: objects] autorelease]; } + arrayWithCArray: (id*)objects length: (size_t)length { return [[[self alloc] initWithCArray: objects length: length] autorelease]; } - init { self = [super init]; @try { array = [[OFDataArray alloc] initWithItemSize: sizeof(id)]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithObject: (id)object { self = [self init]; @try { [array addItem: &object]; [object retain]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [self initWithObject: firstObject argumentList: arguments]; va_end(arguments); return ret; } - initWithObject: (id)firstObject argumentList: (va_list)arguments { self = [self init]; @try { id object; [array addItem: &firstObject]; while ((object = va_arg(arguments, id)) != nil) { [array addItem: &object]; [object retain]; } } @catch (id e) { [self release]; @throw e; } return self; } - initWithCArray: (id*)objects { self = [self init]; @try { id *object; size_t count = 0; for (object = objects; *object != nil; object++) { [*object retain]; count++; } [array addNItems: count fromCArray: objects]; } @catch (id e) { id *object; for (object = objects; *object != nil; object++) [*object release]; [self release]; @throw e; } return self; } - initWithCArray: (id*)objects length: (size_t)length { self = [self init]; @try { size_t i; for (i = 0; i < length; i++) [objects[i] retain]; [array addNItems: length fromCArray: objects]; } @catch (id e) { size_t i; for (i = 0; i < length; i++) [objects[i] release]; [self release]; @throw e; } return self; } |
︙ | ︙ | |||
194 195 196 197 198 199 200 | - copy { return [self retain]; } - mutableCopy { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | - copy { return [self retain]; } - mutableCopy { OFArray *mutableCopy = [[OFMutableArray alloc] init]; id *cArray; size_t count, i; cArray = [array cArray]; count = [array count]; [mutableCopy->array addNItems: count fromCArray: cArray]; for (i = 0; i < count; i++) [cArray[i] retain]; return mutableCopy; } - (id)objectAtIndex: (size_t)index { return *((id*)[array itemAtIndex: index]); } - (size_t)indexOfObject: (id)object { id *cArray = [array cArray]; size_t i, count = [array count]; if (cArray == NULL) return OF_INVALID_INDEX; for (i = 0; i < count; i++) if ([cArray[i] isEqual: object]) return i; return OF_INVALID_INDEX; } - (size_t)indexOfObjectIdenticalTo: (id)object { id *cArray = [array cArray]; size_t i, count = [array count]; if (cArray == NULL) return OF_INVALID_INDEX; for (i = 0; i < count; i++) if (cArray[i] == object) return i; return OF_INVALID_INDEX; } - (BOOL)containsObject: (id)object { id *cArray = [array cArray]; size_t i, count = [array count]; if (cArray == NULL) return NO; for (i = 0; i < count; i++) if ([cArray[i] isEqual: object]) return YES; return NO; } - (BOOL)containsObjectIdenticalTo: (id)object { id *cArray = [array cArray]; size_t i, count = [array count]; if (cArray == NULL) return NO; for (i = 0; i < count; i++) if (cArray[i] == object) return YES; return NO; } - (id)firstObject { id *firstObject = [array firstItem]; return (firstObject != NULL ? *firstObject : nil); } - (id)lastObject { id *lastObject = [array lastItem]; return (lastObject != NULL ? *lastObject : nil); } - (OFArray*)objectsFromIndex: (size_t)start toIndex: (size_t)end { size_t count = [array count]; |
︙ | ︙ | |||
310 311 312 313 314 315 316 | return [self objectsFromIndex: range.start toIndex: range.start + range.length]; } - (OFString*)componentsJoinedByString: (OFString*)separator { OFAutoreleasePool *pool; | | | | | | | | | | | | > | | | > > < | | | | | | | 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | return [self objectsFromIndex: range.start toIndex: range.start + range.length]; } - (OFString*)componentsJoinedByString: (OFString*)separator { OFAutoreleasePool *pool; OFString *ret; OFObject **cArray = [array cArray]; size_t i, count = [array count]; IMP append; if (count == 0) return @""; if (count == 1) return [cArray[0] description]; ret = [OFMutableString string]; append = [ret methodForSelector: @selector(appendString:)]; pool = [[OFAutoreleasePool alloc] init]; for (i = 0; i < count - 1; i++) { append(ret, @selector(appendString:), [cArray[i] description]); append(ret, @selector(appendString:), separator); [pool releaseObjects]; } append(ret, @selector(appendString:), [cArray[i] description]); [pool release]; /* * Class swizzle the string to be immutable. We declared the return type * to be OFString*, so it can't be modified anyway. But not swizzling it * would create a real copy each time -[copy] is called. */ ret->isa = [OFString class]; return ret; } - (BOOL)isEqual: (id)object { OFArray *otherArray; id *cArray, *otherCArray; size_t i, count; if (![object isKindOfClass: [OFArray class]]) return NO; otherArray = (OFArray*)object; count = [array count]; if (count != [otherArray count]) return NO; cArray = [array cArray]; otherCArray = [otherArray cArray]; for (i = 0; i < count; i++) if (![cArray[i] isEqual: otherCArray[i]]) return NO; return YES; } - (uint32_t)hash { id *cArray = [array cArray]; size_t i, count = [array count]; uint32_t hash; OF_HASH_INIT(hash); for (i = 0; i < count; i++) { uint32_t h = [cArray[i] hash]; OF_HASH_ADD(hash, h >> 24); OF_HASH_ADD(hash, (h >> 16) & 0xFF); OF_HASH_ADD(hash, (h >> 8) & 0xFF); OF_HASH_ADD(hash, h & 0xFF); } |
︙ | ︙ | |||
422 423 424 425 426 427 428 | */ ret->isa = [OFString class]; return ret; } - (void)makeObjectsPerformSelector: (SEL)selector { | | | | | | | | | 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | */ ret->isa = [OFString class]; return ret; } - (void)makeObjectsPerformSelector: (SEL)selector { id *cArray = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) ((void(*)(id, SEL))[cArray[i] methodForSelector: selector])(cArray[i], selector); } - (void)makeObjectsPerformSelector: (SEL)selector withObject: (id)object { id *cArray = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) ((void(*)(id, SEL, id))[cArray[i] methodForSelector: selector])(cArray[i], selector, object); } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count_ { size_t count = [array count]; |
︙ | ︙ | |||
471 472 473 474 475 476 477 | mutationsPointer: NULL] autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; | | | | | | 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | mutationsPointer: NULL] autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; id *cArray = [array cArray]; size_t i, count = [array count]; BOOL stop = NO; for (i = 0; i < count && !stop; i++) { block(cArray[i], i, &stop); [pool releaseObjects]; } [pool release]; } - (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFArray *ret; size_t count = [array count]; id *tmp = [self allocMemoryForNItems: count withSize: sizeof(id)]; @try { id *cArray = [array cArray]; size_t i; for (i = 0; i < count; i++) tmp[i] = block(cArray[i], i); ret = [[OFArray alloc] initWithCArray: tmp length: count]; @try { [pool release]; } @finally { |
︙ | ︙ | |||
522 523 524 525 526 527 528 | OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFArray *ret; size_t count = [array count]; id *tmp = [self allocMemoryForNItems: count withSize: sizeof(id)]; @try { | | | | | | | 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFArray *ret; size_t count = [array count]; id *tmp = [self allocMemoryForNItems: count withSize: sizeof(id)]; @try { id *cArray = [array cArray]; size_t i, j = 0; for (i = 0; i < count; i++) { if (block(cArray[i], i)) tmp[j++] = cArray[i]; [pool releaseObjects]; } [pool release]; ret = [OFArray arrayWithCArray: tmp length: j]; } @finally { [self freeMemory: tmp]; } return ret; } #endif - (void)dealloc { id *cArray = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) [cArray[i] release]; [array release]; [super dealloc]; } @end |
︙ | ︙ |
Modified src/OFDataArray+Hashing.m from [499df88bcb] to [8e2c5834df].
︙ | ︙ | |||
26 27 28 29 30 31 32 | @implementation OFDataArray (Hashing) - (OFString*)MD5Hash { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMD5Hash *hash = [OFMD5Hash MD5Hash]; uint8_t *digest; | | | | | | | | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | @implementation OFDataArray (Hashing) - (OFString*)MD5Hash { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMD5Hash *hash = [OFMD5Hash MD5Hash]; uint8_t *digest; char cRet[OF_MD5_DIGEST_SIZE * 2]; size_t i; [hash updateWithBuffer: data ofSize: count * itemSize]; digest = [hash digest]; for (i = 0; i < OF_MD5_DIGEST_SIZE; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; cRet[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); cRet[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } [pool release]; return [OFString stringWithCString: cRet length: 32]; } - (OFString*)SHA1Hash { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMD5Hash *hash = [OFSHA1Hash SHA1Hash]; uint8_t *digest; char cRet[OF_SHA1_DIGEST_SIZE * 2]; size_t i; [hash updateWithBuffer: data ofSize: count * itemSize]; digest = [hash digest]; for (i = 0; i < OF_SHA1_DIGEST_SIZE; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; cRet[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); cRet[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } [pool release]; return [OFString stringWithCString: cRet length: 40]; } @end |
Modified src/OFDataArray.h from [a50c0cfed5] to [52c9a087ea].
︙ | ︙ | |||
35 36 37 38 39 40 41 | @property (readonly) size_t count; @property (readonly) size_t itemSize; #endif /** * Creates a new OFDataArray whose items all have the same size. * | | | | | | | | | | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | @property (readonly) size_t count; @property (readonly) size_t itemSize; #endif /** * Creates a new OFDataArray whose items all have the same size. * * \param itemSize The size of each element in the OFDataArray * \return A new autoreleased OFDataArray */ + dataArrayWithItemSize: (size_t)itemSize; /** * Creates a new OFDataArary with an item size of 1, containing the data of the * specified file. * * \param path The path of the file * \return A new autoreleased OFDataArray */ + dataArrayWithContentsOfFile: (OFString*)path; /** * Creates a new OFDataArray with an item size of 1, containing the data of the * Base64-encoded string. * * \param string The string with the Base64-encoded data * \return A new autoreleased OFDataArray */ + dataArrayWithBase64EncodedString: (OFString*)string; /** * Initializes an already allocated OFDataArray whose items all have the same * size. * * \param itemSize The size of each element in the OFDataArray * \return An initialized OFDataArray */ - initWithItemSize: (size_t)itemSize; /** * Initializes an already allocated OFDataArray with an item size of 1, * containing the data of the specified file. * * \param path The path of the file * \return An initialized OFDataArray */ - initWithContentsOfFile: (OFString*)path; /** * Initializes an already allocated OFDataArray with an item size of 1, * containing the data of the Base64-encoded string. * * \param string The string with the Base64-encoded data * \return A initialized OFDataArray */ - initWithBase64EncodedString: (OFString*)string; /** * \return The number of items in the OFDataArray */ - (size_t)count; /** |
︙ | ︙ | |||
137 138 139 140 141 142 143 | */ - (void)addItem: (const void*)item atIndex: (size_t)index; /** * Adds items from a C array to the OFDataArray. * | | | | | | | | | | | | | | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | */ - (void)addItem: (const void*)item atIndex: (size_t)index; /** * Adds items from a C array to the OFDataArray. * * \param nItems The number of items to add * \param cArray A C array containing the items to add */ - (void)addNItems: (size_t)nItems fromCArray: (const void*)cArray; /** * Adds items from a C array to the OFDataArray at the specified index. * * \param nItems The number of items to add * \param cArray A C array containing the items to add * \param index The index where the items should be added */ - (void)addNItems: (size_t)nItems fromCArray: (const void*)cArray atIndex: (size_t)index; /** * Removes the item at the specified index. * * \param index The index of the item to remove */ - (void)removeItemAtIndex: (size_t)index; /** * Removes the specified amount of items from the end of the OFDataArray. * * \param nItems The number of items to remove */ - (void)removeNItems: (size_t)nItems; /** * Removes the specified amount of items at the specified index. * * \param nItems The number of items to remove * \param index The index at which the items are removed */ - (void)removeNItems: (size_t)nItems atIndex: (size_t)index; /** * \return A string containing the data in Base64 encoding */ - (OFString*)stringByBase64Encoding; @end |
︙ | ︙ |
Modified src/OFDataArray.m from [a29caa1d81] to [c17a542e4e].
︙ | ︙ | |||
36 37 38 39 40 41 42 | /* References for static linking */ void _references_to_categories_of_OFDataArray(void) { _OFDataArray_Hashing_reference = 1; }; @implementation OFDataArray | | | | | | | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | /* References for static linking */ void _references_to_categories_of_OFDataArray(void) { _OFDataArray_Hashing_reference = 1; }; @implementation OFDataArray + dataArrayWithItemSize: (size_t)itemSize { return [[[self alloc] initWithItemSize: itemSize] autorelease]; } + dataArrayWithContentsOfFile: (OFString*)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; } + dataArrayWithBase64EncodedString: (OFString*)string { return [[[self alloc] initWithBase64EncodedString: string] autorelease]; } - init { Class c = isa; [self release]; @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithItemSize: (size_t)itemSize_ { self = [super init]; @try { if (itemSize_ == 0) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; itemSize = itemSize_; data = NULL; } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ | |||
90 91 92 93 94 95 96 | OFFile *file = [[OFFile alloc] initWithPath: path mode: @"rb"]; itemSize = 1; data = NULL; @try { | | | | | | | | | | | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | OFFile *file = [[OFFile alloc] initWithPath: path mode: @"rb"]; itemSize = 1; data = NULL; @try { char *buffer = [self allocMemoryWithSize: of_pagesize]; while (![file isAtEndOfStream]) { size_t length; length = [file readNBytes: of_pagesize intoBuffer: buffer]; [self addNItems: length fromCArray: buffer]; } [self freeMemory: buffer]; } @finally { [file release]; } } @catch (id e) { [self release]; @throw e; } return self; } - initWithBase64EncodedString: (OFString*)string { self = [super init]; itemSize = 1; data = NULL; if (!of_base64_decode(self, [string cString], [string cStringLength])) { Class c = isa; [self release]; @throw [OFInvalidEncodingException newWithClass: c]; } return self; } |
︙ | ︙ | |||
190 191 192 193 194 195 196 | atIndex: (size_t)index { [self addNItems: 1 fromCArray: item atIndex: index]; } | | | | | | | | | | | | | | | | | | | | | | | > | | | | > > | > > > | | | | > | | | > > | | | | | | | | | 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | atIndex: (size_t)index { [self addNItems: 1 fromCArray: item atIndex: index]; } - (void)addNItems: (size_t)nItems fromCArray: (const void*)cArray { if (nItems > SIZE_MAX - count) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMemory: data toNItems: count + nItems withSize: itemSize]; memcpy(data + count * itemSize, cArray, nItems * itemSize); count += nItems; } - (void)addNItems: (size_t)nItems fromCArray: (const void*)cArray atIndex: (size_t)index { if (nItems > SIZE_MAX - count) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMemory: data toNItems: count + nItems withSize: itemSize]; memmove(data + (index + nItems) * itemSize, data + index * itemSize, (count - index) * itemSize); memcpy(data + index * itemSize, cArray, nItems * itemSize); count += nItems; } - (void)removeItemAtIndex: (size_t)index { [self removeNItems: 1 atIndex: index]; } - (void)removeNItems: (size_t)nItems { if (nItems > count) @throw [OFOutOfRangeException newWithClass: isa]; count -= nItems; @try { data = [self resizeMemory: data toNItems: count withSize: itemSize]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ [e release]; } } - (void)removeNItems: (size_t)nItems atIndex: (size_t)index { if (nItems > count) @throw [OFOutOfRangeException newWithClass: isa]; memmove(data + index * itemSize, data + (index + nItems) * itemSize, (count - index - nItems) * itemSize); count -= nItems; @try { data = [self resizeMemory: data toNItems: count withSize: itemSize]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ [e release]; } } - copy { OFDataArray *copy = [[OFDataArray alloc] initWithItemSize: itemSize]; [copy addNItems: count fromCArray: data]; return copy; } - (BOOL)isEqual: (id)object { OFDataArray *otherDataArray; if (![object isKindOfClass: [OFDataArray class]]) return NO; otherDataArray = (OFDataArray*)object; if ([otherDataArray count] != count || [otherDataArray itemSize] != itemSize) return NO; if (memcmp([otherDataArray cArray], data, count * itemSize)) return NO; return YES; } - (of_comparison_result_t)compare: (id)object { OFDataArray *otherDataArray; int comparison; size_t otherCount, minimumCount; if (![object isKindOfClass: [OFDataArray class]]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; otherDataArray = (OFDataArray*)object; if ([otherDataArray itemSize] != itemSize) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; otherCount = [otherDataArray count]; minimumCount = (count > otherCount ? otherCount : count); if ((comparison = memcmp(data, [otherDataArray cArray], minimumCount * itemSize)) == 0) { if (count > otherCount) return OF_ORDERED_DESCENDING; if (count < otherCount) return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; } if (comparison > 0) return OF_ORDERED_DESCENDING; else return OF_ORDERED_ASCENDING; } - (uint32_t)hash { |
︙ | ︙ | |||
339 340 341 342 343 344 345 | return of_base64_encode(data, count * itemSize); } @end @implementation OFBigDataArray - (void)addItem: (const void*)item { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | return of_base64_encode(data, count * itemSize); } @end @implementation OFBigDataArray - (void)addItem: (const void*)item { size_t newSize, lastPageByte; if (SIZE_MAX - count < 1 || count + 1 > SIZE_MAX / itemSize) @throw [OFOutOfRangeException newWithClass: isa]; lastPageByte = of_pagesize - 1; newSize = ((count + 1) * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data toSize: newSize]; memcpy(data + count * itemSize, item, itemSize); count++; size = newSize; } - (void)addNItems: (size_t)nItems fromCArray: (const void*)cArray { size_t newSize, lastPageByte; if (nItems > SIZE_MAX - count || count + nItems > SIZE_MAX / itemSize) @throw [OFOutOfRangeException newWithClass: isa]; lastPageByte = of_pagesize - 1; newSize = ((count + nItems) * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data toSize: newSize]; memcpy(data + count * itemSize, cArray, nItems * itemSize); count += nItems; size = newSize; } - (void)addNItems: (size_t)nItems fromCArray: (const void*)cArray atIndex: (size_t)index { size_t newSize, lastPageByte; if (nItems > SIZE_MAX - count || count + nItems > SIZE_MAX / itemSize) @throw [OFOutOfRangeException newWithClass: isa]; lastPageByte = of_pagesize - 1; newSize = ((count + nItems) * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data toNItems: newSize withSize: itemSize]; memmove(data + (index + nItems) * itemSize, data + index * itemSize, (count - index) * itemSize); memcpy(data + index * itemSize, cArray, nItems * itemSize); count += nItems; size = newSize; } - (void)removeNItems: (size_t)nItems { size_t newSize, lastPageByte; if (nItems > count) @throw [OFOutOfRangeException newWithClass: isa]; count -= nItems; lastPageByte = of_pagesize - 1; newSize = (count * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data toSize: newSize]; size = newSize; } - (void)removeNItems: (size_t)nItems atIndex: (size_t)index { size_t newSize, lastPageByte; if (nItems > count) @throw [OFOutOfRangeException newWithClass: isa]; memmove(data + index * itemSize, data + (index + nItems) * itemSize, (count - index - nItems) * itemSize); count -= nItems; lastPageByte = of_pagesize - 1; newSize = (count * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data toSize: newSize]; size = newSize; } - copy { OFDataArray *copy = [[OFBigDataArray alloc] initWithItemSize: itemSize]; [copy addNItems: count fromCArray: data]; return copy; } @end |
Modified src/OFObject.h from [20ad48203c] to [1c3650ec63].
︙ | ︙ | |||
89 90 91 92 93 94 95 | */ - (id)performSelector: (SEL)selector; /** * Performs the specified selector with the specified object. * * \param selector The selector to perform | | > | | | | | | | | | | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | */ - (id)performSelector: (SEL)selector; /** * Performs the specified selector with the specified object. * * \param selector The selector to perform * \param object The object that is passed to the method specified by the * selector * \return The object returned by the method specified by the selector */ - (id)performSelector: (SEL)selector withObject: (id)object; /** * Performs the specified selector with the specified objects. * * \param selector The selector to perform * \param object The first object that is passed to the method specified by the * selector * \param otherObject The second object that is passed to the method specified * by the selector * \return The object returned by the method specified by the selector */ - (id)performSelector: (SEL)selector withObject: (id)object withObject: (id)otherObject; /** * Checks two objects for equality. * * Classes containing data (like strings, arrays, lists etc.) should reimplement * this! * * \param object The object which should be tested for equality * \return A boolean whether the object is equal to the specified object */ - (BOOL)isEqual: (id)object; /** * Calculates a hash for the object. * * Classes containing data (like strings, arrays, lists etc.) should reimplement * this! * |
︙ | ︙ | |||
440 441 442 443 444 445 446 | * * This protocol is implemented by objects that can be compared. */ @protocol OFComparing /** * Compares the object with another object. * | | | | 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | * * This protocol is implemented by objects that can be compared. */ @protocol OFComparing /** * Compares the object with another object. * * \param object An object to compare the object to * \return The result of the comparison */ - (of_comparison_result_t)compare: (id)object; @end #ifdef __cplusplus extern "C" { #endif extern id objc_getProperty(id, SEL, ptrdiff_t, BOOL); extern void objc_setProperty(id, SEL, ptrdiff_t, id, BOOL, BOOL); extern size_t of_pagesize; #ifdef __cplusplus } #endif |
Modified src/OFObject.m from [59829ea342] to [b8a2ef4dd8].
︙ | ︙ | |||
492 493 494 495 496 497 498 | { id (*imp)(id, SEL) = (id(*)(id, SEL))[self methodForSelector: selector]; return imp(self, selector); } - (id)performSelector: (SEL)selector | | | | | | | 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | { id (*imp)(id, SEL) = (id(*)(id, SEL))[self methodForSelector: selector]; return imp(self, selector); } - (id)performSelector: (SEL)selector withObject: (id)object { id (*imp)(id, SEL, id) = (id(*)(id, SEL, id))[self methodForSelector: selector]; return imp(self, selector, object); } - (id)performSelector: (SEL)selector withObject: (id)object withObject: (id)otherObject { id (*imp)(id, SEL, id, id) = (id(*)(id, SEL, id, id))[self methodForSelector: selector]; return imp(self, selector, object, otherObject); } - (const char*)typeEncodingForSelector: (SEL)selector { #if defined(OF_OBJFW_RUNTIME) const char *ret; |
︙ | ︙ | |||
542 543 544 545 546 547 548 | @throw [OFNotImplementedException newWithClass: isa selector: selector]; return ret; #endif } | | | | 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | @throw [OFNotImplementedException newWithClass: isa selector: selector]; return ret; #endif } - (BOOL)isEqual: (id)object { /* Classes containing data should reimplement this! */ return (self == object); } - (uint32_t)hash { /* Classes containing data should reimplement this! */ return (uint32_t)(uintptr_t)self; } |
︙ | ︙ |