Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOWeakSet Class Reference

#include <OOWeakSet.h>

+ Inheritance diagram for OOWeakSet:
+ Collaboration diagram for OOWeakSet:

Instance Methods

(id) - init
 
(id) - initWithCapacity:
 
(NSUInteger) - count
 
(BOOL) - containsObject:
 
(NSEnumerator *) - objectEnumerator
 
(void) - addObject:
 
(void) - removeObject:
 
(void) - addObjectsByEnumerating:
 
(void) - makeObjectsPerformSelector:
 
(void) - makeObjectsPerformSelector:withObject:
 
(NSArray *) - allObjects
 
(void) - removeAllObjects
 
(void) - dealloc [implementation]
 
(NSString *) - description [implementation]
 
(id) - copyWithZone: [implementation]
 
(id) - mutableCopyWithZone: [implementation]
 
(BOOL) - isEqual: [implementation]
 
(void) - compact [implementation]
 

Class Methods

(instancetype) + set
 
(instancetype) + setWithCapacity:
 

Private Attributes

NSMutableSet * _objects
 

Detailed Description

Definition at line 29 of file OOWeakSet.h.

Method Documentation

◆ addObject:

- (void) addObject: (id<OOWeakReferenceSupport>) object

Definition at line 17 of file OOWeakSet.m.

165 :(id<OOWeakReferenceSupport>)object
166{
167 if (object == nil) return;
168 NSAssert([object conformsToProtocol:@protocol(OOWeakReferenceSupport)], @"Attempt to add object to OOWeakSet which does not conform to OOWeakReferenceSupport.");
169
170 OOWeakReference *weakObj = [object weakRetain];
171 [_objects addObject:weakObj];
172 [weakObj release];
173}
return nil

◆ addObjectsByEnumerating:

- (void) addObjectsByEnumerating: (NSEnumerator *) enumerator

Definition at line 17 of file OOWeakSet.m.

184 :(NSEnumerator *)enumerator
185{
186 id object = nil;
187 [self compact];
188 while ((object = [enumerator nextObject]))
189 {
190 [self addObject:object];
191 }
192}

◆ allObjects

- (NSArray *) allObjects

Definition at line 17 of file OOWeakSet.m.

216{
217 NSMutableArray *result = [NSMutableArray arrayWithCapacity:[_objects count]];
218 OOWeakReference *weakRef = nil;
219 foreach (weakRef, _objects)
220 {
221 id object = [weakRef weakRefUnderlyingObject];
222 if (object != nil) [result addObject:object];
223 }
224
225#ifdef NDEBUG
226 return result;
227#else
228 return [NSArray arrayWithArray:result];
229#endif
230}
NSMutableSet * _objects
Definition OOWeakSet.h:33

◆ compact

- (void) compact
implementation

Provided by category OOWeakSet(OOPrivate).

Definition at line 17 of file OOWeakSet.m.

240{
241 OOWeakReference *weakRef = nil;
242 BOOL compactRequired = NO;
243 foreach (weakRef, _objects)
244 {
245 if ([weakRef weakRefUnderlyingObject] == nil)
246 {
247 compactRequired = YES;
248 break;
249 }
250 }
251
252 if (compactRequired)
253 {
254 NSMutableSet *newObjects = [[NSMutableSet alloc] initWithCapacity:[_objects count]];
255 foreach (weakRef, _objects)
256 {
257 if ([weakRef weakRefUnderlyingObject] != nil)
258 {
259 [newObjects addObject:weakRef];
260 }
261 }
262
263 [_objects release];
264 _objects = newObjects;
265 }
266}

◆ containsObject:

- (BOOL) containsObject: (id<OOWeakReferenceSupport>) object

Definition at line 17 of file OOWeakSet.m.

149 :(id<OOWeakReferenceSupport>)object
150{
151 [self compact];
152 OOWeakReference *weakObj = [object weakRetain];
153 BOOL result = [_objects containsObject:weakObj];
154 [weakObj release];
155 return result;
156}

◆ copyWithZone:

- (id) copyWithZone: (NSZone *) zone
implementation

Definition at line 17 of file OOWeakSet.m.

102 :(NSZone *)zone
103{
104 [self compact];
105 OOWeakSet *result = [[OOWeakSet allocWithZone:zone] init];
106 [result addObjectsByEnumerating:[self objectEnumerator]];
107 return result;
108}
void addObjectsByEnumerating:(NSEnumerator *enumerator)
Definition OOWeakSet.m:184

◆ count

- (NSUInteger) count

Definition at line 17 of file OOWeakSet.m.

143{
144 [self compact];
145 return [_objects count];
146}

◆ dealloc

- (void) dealloc
implementation

Definition at line 17 of file OOWeakSet.m.

70{
72
73 [super dealloc];
74}
#define DESTROY(x)
Definition OOCocoa.h:77

◆ description

- (NSString *) description
implementation

Definition at line 17 of file OOWeakSet.m.

78{
79 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p>{", [self class], self];
80 NSEnumerator *selfEnum = [self objectEnumerator];
81 id object = nil;
82 BOOL first = YES;
83 while ((object = [selfEnum nextObject]))
84 {
85 if (!first) [result appendString:@", "];
86 else first = NO;
87
88 NSString *desc = nil;
89 if ([object respondsToSelector:@selector(shortDescription)]) desc = [object shortDescription];
90 else desc = [object description];
91
92 [result appendString:desc];
93 }
94
95 [result appendString:@"}"];
96 return result;
97}

◆ init

- (id) init

Definition at line 17 of file OOWeakSet.m.

37{
38 return [self initWithCapacity:0];
39}

◆ initWithCapacity:

- (id) initWithCapacity: (NSUInteger) capacity

Definition at line 17 of file OOWeakSet.m.

42 :(NSUInteger)capacity
43{
44 if ((self = [super init]))
45 {
46 _objects = [[NSMutableSet alloc] initWithCapacity:capacity];
47 if (_objects == NULL)
48 {
49 [self release];
50 return nil;
51 }
52 }
53 return self;
54}

◆ isEqual:

- (BOOL) isEqual: (id) other
implementation

Definition at line 17 of file OOWeakSet.m.

117 :(id)other
118{
119 if (![other isKindOfClass:[OOWeakSet class]]) return NO;
120 if ([self count] != [other count]) return NO;
121
122 BOOL result = YES;
123 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
124 NSEnumerator *selfEnum = [self objectEnumerator];
125 id object = nil;
126 while ((object = [selfEnum nextObject]))
127 {
128 if (![other containsObject:object])
129 {
130 result = NO;
131 break;
132 }
133 }
134 DESTROY(pool);
135
136 return result;
137}
NSUInteger count()
Definition OOWeakSet.m:142

◆ makeObjectsPerformSelector:

- (void) makeObjectsPerformSelector: (SEL) selector

Definition at line 17 of file OOWeakSet.m.

195 :(SEL)selector
196{
197 OOWeakReference *weakRef = nil;
198 foreach (weakRef, _objects)
199 {
200 [[weakRef weakRefUnderlyingObject] performSelector:selector];
201 }
202}

◆ makeObjectsPerformSelector:withObject:

- (void) makeObjectsPerformSelector: (SEL) selector
withObject: (id) argument 

Definition at line 17 of file OOWeakSet.m.

205 :(SEL)selector withObject:(id)argument
206{
207 OOWeakReference *weakRef = nil;
208 foreach (weakRef, _objects)
209 {
210 [[weakRef weakRefUnderlyingObject] performSelector:selector withObject:argument];
211 }
212}

◆ mutableCopyWithZone:

- (id) mutableCopyWithZone: (NSZone *) zone
implementation

Definition at line 17 of file OOWeakSet.m.

111 :(NSZone *)zone
112{
113 return [self copyWithZone:zone];
114}

◆ objectEnumerator

- (NSEnumerator *) objectEnumerator

Definition at line 17 of file OOWeakSet.m.

160{
162}
instancetype enumeratorWithCollection:(id collection)
Definition OOWeakSet.m:290

◆ removeAllObjects

- (void) removeAllObjects

Definition at line 17 of file OOWeakSet.m.

234{
235 [_objects removeAllObjects];
236}

◆ removeObject:

- (void) removeObject: (id<OOWeakReferenceSupport>) object

Definition at line 17 of file OOWeakSet.m.

176 :(id<OOWeakReferenceSupport>)object
177{
178 OOWeakReference *weakObj = [object weakRetain];
179 [_objects removeObject:weakObj];
180 [weakObj release];
181}

◆ set

+ (instancetype) set

Definition at line 17 of file OOWeakSet.m.

58{
59 return [[[self alloc] init] autorelease];
60}

◆ setWithCapacity:

+ (instancetype) setWithCapacity: (NSUInteger) capacity

Definition at line 17 of file OOWeakSet.m.

63 :(NSUInteger)capacity
64{
65 return [[[self alloc] initWithCapacity:capacity] autorelease];
66}

Member Data Documentation

◆ _objects

- (NSMutableSet*) _objects
private

Definition at line 33 of file OOWeakSet.h.


The documentation for this class was generated from the following files: