Overview
Comment: | Add -[enumerateObjectsUsingBlock:] and -[filteredSetUsingBlock:]. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
3e6766ac10666ee706a9b91a069b896c |
User & Date: | js on 2011-07-21 23:56:09 |
Other Links: | manifest | tags |
Context
2011-07-22
| ||
00:00 | Include OFSet in ObjFW.h. check-in: ac598c5ec3 user: js tags: trunk | |
2011-07-21
| ||
23:56 | Add -[enumerateObjectsUsingBlock:] and -[filteredSetUsingBlock:]. check-in: 3e6766ac10 user: js tags: trunk | |
22:01 | Add -[reduceUsingBlock:] to OFArray. check-in: 03e89edb42 user: js tags: trunk | |
Changes
Modified src/OFArray.m from [fa2031559e] to [55a42ad5b8].
︙ | ︙ | |||
409 410 411 412 413 414 415 | [pool releaseObjects]; } append(ret, @selector(appendString:), [cArray[i] description]); [pool release]; /* | | | | 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | [pool releaseObjects]; } append(ret, @selector(appendString:), [cArray[i] description]); [pool release]; /* * Class swizzle the array to be immutable. We declared the return type * to be OFArray*, 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 |
︙ | ︙ | |||
491 492 493 494 495 496 497 | } [pool release]; [ret autorelease]; /* | | | | 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | } [pool release]; [ret autorelease]; /* * Class swizzle the array to be immutable. We declared the return type * to be OFArray*, 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; } - (OFXMLElement*)XMLElementBySerializing |
︙ | ︙ |
Modified src/OFSet.h from [1df2b6e5f6] to [ccc5bd9784].
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #import "OFObject.h" #import "OFCollection.h" @class OFMutableDictionary; @class OFArray; /** * \brief An unordered set of unique objects. */ @interface OFSet: OFObject <OFCollection, OFCopying, OFMutableCopying> { OFMutableDictionary *dictionary; } | > > > > > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #import "OFObject.h" #import "OFCollection.h" @class OFMutableDictionary; @class OFArray; #ifdef OF_HAVE_BLOCKS typedef void (^of_set_enumeration_block_t)(id object, BOOL *stop); typedef BOOL (^of_set_filter_block_t)(id object); #endif /** * \brief An unordered set of unique objects. */ @interface OFSet: OFObject <OFCollection, OFCopying, OFMutableCopying> { OFMutableDictionary *dictionary; } |
︙ | ︙ | |||
107 108 109 110 111 112 113 114 115 116 | * \brief Returns whether the receiver and the specified set have at least one * object in common. * * \return Whether the receiver and the specified set have at least one object * in common */ - (BOOL)intersectsSet: (OFSet*)set; @end #import "OFMutableSet.h" | > > > > > > > > > > > > > > > > > > | 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 | * \brief Returns whether the receiver and the specified set have at least one * object in common. * * \return Whether the receiver and the specified set have at least one object * in common */ - (BOOL)intersectsSet: (OFSet*)set; #ifdef OF_HAVE_BLOCKS /** * \brief Executes a block for each object. * * \param block The block to execute for each object */ - (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block; /** * \brief Returns a new set, only containing the objects for which the block * returns YES. * * \param block A block which determines if the object should be in the new set * \return A new, autoreleased OFSet */ - (OFSet*)filteredSetUsingBlock: (of_set_filter_block_t)block; #endif @end #import "OFMutableSet.h" |
Modified src/OFSet.m from [a5a149b673] to [89818a2387].
︙ | ︙ | |||
303 304 305 306 307 308 309 310 | } objects[i] = object; } return count; } @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 335 336 337 338 339 | } objects[i] = object; } return count; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block { [dictionary enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, BOOL *stop) { block(key, stop); }]; } - (OFSet*)filteredSetUsingBlock: (of_set_filter_block_t)block { OFMutableSet *ret = [OFMutableSet set]; [dictionary enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, BOOL *stop) { if (block(key)) [ret addObject: key]; }]; /* * Class swizzle the set to be immutable. We declared the return type * to be OFSet*, so it can't be modified anyway. But not swizzling it * would create a real copy each time -[copy] is called. */ ret->isa = [OFSet class]; return ret; } #endif @end |