Oolite
Loading...
Searching...
No Matches
OOWeakSet.h
Go to the documentation of this file.
1/*
2
3OOWeakSet.h
4
5A mutable set of weak references to objects conforming to OOWeakReferenceSupport.
6
7Semantics:
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
17LIMITATION: fast enumeration and Oolite's foreach() macro are not supported.
18
19
20Written by Jens Ayton in 2012 for Oolite.
21This code is hereby placed in the public domain.
22
23*/
24
25#import "OOFoundation.h"
26#import "OOWeakReference.h"
27
28@interface OOWeakSet : NSObject <NSCopying, NSMutableCopying> {
29@private
30 NSMutableSet* _objects;
31}
32
33- (id)init;
34- (id)initWithCapacity:(NSUInteger)capacity; // As with Foundation collections, capacity is only a hint.
35
36+ (instancetype)set;
37+ (instancetype)setWithCapacity:(NSUInteger)capacity;
38
39- (NSUInteger)count;
40- (BOOL)containsObject:(id<OOWeakReferenceSupport>)object;
41- (NSEnumerator*)objectEnumerator;
42
43- (void)addObject:(id<OOWeakReferenceSupport>)object; // Unlike NSSet, adding nil fails silently.
44- (void)removeObject:(id<OOWeakReferenceSupport>)object; // Like NSSet, does not complain if object is not already a member.
45
46- (void)addObjectsByEnumerating:(NSEnumerator*)enumerator;
47
48- (void)makeObjectsPerformSelector:(SEL)selector;
49- (void)makeObjectsPerformSelector:(SEL)selector withObject:(id)argument;
50
51- (NSArray*)allObjects;
52
53- (void)removeAllObjects;
54
55@end
unsigned count
NSMutableSet * _objects
Definition OOWeakSet.h:30