Line data Source code
1 0 : /* 2 : 3 : OOWeakSet.h 4 : 5 : A mutable set of weak references to objects conforming to OOWeakReferenceSupport. 6 : 7 : Semantics: 8 : * When an object in the set is deallocated, the object is removed from the 9 : set and the set's count drops. There is no notification for this. As such, 10 : there is no such thing as an immutable weak set. 11 : * Objects are uniqued by pointer equality, not isEquals:. 12 : * OOWeakSet is not thread-safe. It not only requires that all operations on 13 : it happen on one thread, but also that objects it's watching are (finally) 14 : released on that thread. 15 : 16 : 17 : LIMITATION: fast enumeration and Oolite's foreach() macro are not supported. 18 : 19 : 20 : Written by Jens Ayton in 2012 for Oolite. 21 : This code is hereby placed in the public domain. 22 : 23 : */ 24 : 25 : #import "OOCocoa.h" 26 : #import "OOWeakReference.h" 27 : 28 : 29 0 : @interface OOWeakSet: NSObject <NSCopying, NSMutableCopying> 30 : { 31 : @private 32 : NSMutableSet *_objects; 33 0 : } 34 : 35 : - (id) init; 36 0 : - (id) initWithCapacity:(NSUInteger)capacity; // As with Foundation collections, capacity is only a hint. 37 0 : 38 : + (instancetype) set; 39 0 : + (instancetype) setWithCapacity:(NSUInteger)capacity; 40 0 : 41 : - (NSUInteger) count; 42 0 : - (BOOL) containsObject:(id<OOWeakReferenceSupport>)object; 43 0 : - (NSEnumerator *) objectEnumerator; 44 0 : 45 : - (void) addObject:(id<OOWeakReferenceSupport>)object; // Unlike NSSet, adding nil fails silently. 46 0 : - (void) removeObject:(id<OOWeakReferenceSupport>)object; // Like NSSet, does not complain if object is not already a member. 47 0 : 48 : - (void) addObjectsByEnumerating:(NSEnumerator *)enumerator; 49 0 : 50 : - (void) makeObjectsPerformSelector:(SEL)selector; 51 0 : - (void) makeObjectsPerformSelector:(SEL)selector withObject:(id)argument; 52 0 : 53 : - (NSArray *) allObjects; 54 0 : 55 : - (void) removeAllObjects; 56 0 : 57 : @end