Oolite
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 28 of file OOWeakSet.h.

Method Documentation

◆ addObject:

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

Definition at line 149 of file OOWeakSet.m.

149 :(id<OOWeakReferenceSupport>)object
150{
151 if (object == nil)
152 return;
153 NSAssert([object conformsToProtocol:@protocol(OOWeakReferenceSupport)], @"Attempt to add object to OOWeakSet which does not conform to OOWeakReferenceSupport.");
154
155 OOWeakReference* weakObj = [object weakRetain];
156 [_objects addObject:weakObj];
157 [weakObj release];
158}
return nil

References nil.

Referenced by ShipEntity::addCollisionException:, ShipEntity::addDefenseTarget:, addObjectsByEnumerating:, and allObjects.

Here is the caller graph for this function:

◆ addObjectsByEnumerating:

- (void) addObjectsByEnumerating: (NSEnumerator*) enumerator

Definition at line 167 of file OOWeakSet.m.

167 :(NSEnumerator*)enumerator
168{
169 id object = nil;
170 [self compact];
171 while ((object = [enumerator nextObject])) {
172 [self addObject:object];
173 }
174}

References addObject:, compact, and nil.

Referenced by copyWithZone:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ allObjects

- (NSArray *) allObjects

Definition at line 192 of file OOWeakSet.m.

193{
194 NSMutableArray* result = [NSMutableArray arrayWithCapacity:[_objects count]];
195 OOWeakReference* weakRef = nil;
196 foreach (weakRef, _objects) {
197 id object = [weakRef weakRefUnderlyingObject];
198 if (object != nil)
199 [result addObject:object];
200 }
201
202#ifdef NDEBUG
203 return result;
204#else
205 return [NSArray arrayWithArray:result];
206#endif
207}
NSMutableSet * _objects
Definition OOWeakSet.h:30

References _objects, addObject:, allObjects, nil, and OOWeakReference::weakRefUnderlyingObject.

Referenced by ShipEntity::allDefenseTargets, allObjects, and ShipEntity::collisionExceptions.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compact

- (void) compact
implementation

Provided by category OOWeakSet(OOPrivate).

Definition at line 214 of file OOWeakSet.m.

215{
216 OOWeakReference* weakRef = nil;
217 BOOL compactRequired = NO;
218 foreach (weakRef, _objects) {
219 if ([weakRef weakRefUnderlyingObject] == nil) {
220 compactRequired = YES;
221 break;
222 }
223 }
224
225 if (compactRequired) {
226 NSMutableSet* newObjects = [[NSMutableSet alloc] initWithCapacity:[_objects count]];
227 foreach (weakRef, _objects) {
228 if ([weakRef weakRefUnderlyingObject] != nil) {
229 [newObjects addObject:weakRef];
230 }
231 }
232
233 [_objects release];
234 _objects = newObjects;
235 }
236}

References OOWeakSet(OOPrivate)::compact, and nil.

Referenced by addObjectsByEnumerating:, OOWeakSet(OOPrivate)::compact, containsObject:, copyWithZone:, and count.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ containsObject:

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

Definition at line 135 of file OOWeakSet.m.

135 :(id<OOWeakReferenceSupport>)object
136{
137 [self compact];
138 OOWeakReference* weakObj = [object weakRetain];
139 BOOL result = [_objects containsObject:weakObj];
140 [weakObj release];
141 return result;
142}

References compact.

Referenced by ShipEntity::collisionExceptedFor:, and ShipEntity::isDefenseTarget:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyWithZone:

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

Definition at line 92 of file OOWeakSet.m.

92 :(NSZone*)zone
93{
94 [self compact];
95 OOWeakSet* result = [[OOWeakSet allocWithZone:zone] init];
96 [result addObjectsByEnumerating:[self objectEnumerator]];
97 return result;
98}
void addObjectsByEnumerating:(NSEnumerator *enumerator)
Definition OOWeakSet.m:167

References addObjectsByEnumerating:, compact, and objectEnumerator.

Referenced by mutableCopyWithZone:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ count

- (NSUInteger) count

Definition at line 129 of file OOWeakSet.m.

130{
131 [self compact];
132 return [_objects count];
133}

References compact, and count.

Referenced by count, StationEntity::currentlyInDockingQueues, ShipEntity::defenseTargetCount, and isEqual:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dealloc

- (void) dealloc
implementation

Definition at line 58 of file OOWeakSet.m.

59{
61
62 [super dealloc];
63}
#define DESTROY(x)

References _objects, dealloc, and DESTROY.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ description

- (NSString *) description
implementation

Definition at line 65 of file OOWeakSet.m.

66{
67 NSMutableString* result = [NSMutableString stringWithFormat:@"<%@ %p>{", [self class], self];
68 NSEnumerator* selfEnum = [self objectEnumerator];
69 id object = nil;
70 BOOL first = YES;
71 while ((object = [selfEnum nextObject])) {
72 if (!first)
73 [result appendString:@", "];
74 else
75 first = NO;
76
77 NSString* desc = nil;
78 if ([object respondsToSelector:@selector(shortDescription)])
79 desc = [object shortDescription];
80 else
81 desc = [object description];
82
83 [result appendString:desc];
84 }
85
86 [result appendString:@"}"];
87 return result;
88}

References description, nil, and objectEnumerator.

Referenced by description.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init

- (id) init

Definition at line 31 of file OOWeakSet.m.

32{
33 return [self initWithCapacity:0];
34}

References init, and initWithCapacity:.

Referenced by init, and initWithCapacity:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithCapacity:

- (id) initWithCapacity: (NSUInteger) capacity

Definition at line 36 of file OOWeakSet.m.

36 :(NSUInteger)capacity
37{
38 if ((self = [super init])) {
39 _objects = [[NSMutableSet alloc] initWithCapacity:capacity];
40 if (_objects == NULL) {
41 [self release];
42 return nil;
43 }
44 }
45 return self;
46}

References _objects, init, and nil.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEqual:

- (BOOL) isEqual: (id) other
implementation

Definition at line 105 of file OOWeakSet.m.

105 :(id)other
106{
107 if (![other isKindOfClass:[OOWeakSet class]])
108 return NO;
109 if ([self count] != [other count])
110 return NO;
111
112 BOOL result = YES;
113 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
114 NSEnumerator* selfEnum = [self objectEnumerator];
115 id object = nil;
116 while ((object = [selfEnum nextObject])) {
117 if (![other containsObject:object]) {
118 result = NO;
119 break;
120 }
121 }
122 DESTROY(pool);
123
124 return result;
125}
NSUInteger count()
Definition OOWeakSet.m:129

References count, DESTROY, nil, and objectEnumerator.

Here is the call graph for this function:

◆ makeObjectsPerformSelector:

- (void) makeObjectsPerformSelector: (SEL) selector

Definition at line 176 of file OOWeakSet.m.

176 :(SEL)selector
177{
178 OOWeakReference* weakRef = nil;
179 foreach (weakRef, _objects) {
180 [[weakRef weakRefUnderlyingObject] performSelector:selector];
181 }
182}

References _objects, nil, and OOWeakReference::weakRefUnderlyingObject.

Here is the call graph for this function:

◆ makeObjectsPerformSelector:withObject:

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

Definition at line 184 of file OOWeakSet.m.

184 :(SEL)selector withObject:(id)argument
185{
186 OOWeakReference* weakRef = nil;
187 foreach (weakRef, _objects) {
188 [[weakRef weakRefUnderlyingObject] performSelector:selector withObject:argument];
189 }
190}

References _objects, nil, and OOWeakReference::weakRefUnderlyingObject.

Referenced by StationEntity::abortAllDockings.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mutableCopyWithZone:

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

Definition at line 100 of file OOWeakSet.m.

100 :(NSZone*)zone
101{
102 return [self copyWithZone:zone];
103}

References copyWithZone:.

Here is the call graph for this function:

◆ objectEnumerator

- (NSEnumerator *) objectEnumerator

Definition at line 144 of file OOWeakSet.m.

145{
147}
instancetype enumeratorWithCollection:(id collection)
Definition OOWeakSet.m:256

References OOWeakRefUnpackingEnumerator::enumeratorWithCollection:, and objectEnumerator.

Referenced by StationEntity::autoDockShipsOnHold, copyWithZone:, ShipEntity::defenseTargetEnumerator, description, StationEntity::dumpSelfState, isEqual:, objectEnumerator, and ShipEntity::realAlertCondition.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeAllObjects

- (void) removeAllObjects

Definition at line 209 of file OOWeakSet.m.

210{
211 [_objects removeAllObjects];
212}

References removeAllObjects.

Referenced by StationEntity::abortAllDockings, StationEntity::autoDockShipsOnHold, StationEntity::clear, ShipEntity::removeAllDefenseTargets, and removeAllObjects.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeObject:

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

Definition at line 160 of file OOWeakSet.m.

160 :(id<OOWeakReferenceSupport>)object
161{
162 OOWeakReference* weakObj = [object weakRetain];
163 [_objects removeObject:weakObj];
164 [weakObj release];
165}

Referenced by StationEntity::abortDockingForShip:, StationEntity::dockingInstructionsForShip:, ShipEntity::removeCollisionException:, and ShipEntity::removeDefenseTarget:.

Here is the caller graph for this function:

◆ set

+ (instancetype) set

Definition at line 48 of file OOWeakSet.m.

49{
50 return [[[self alloc] init] autorelease];
51}

References set.

Referenced by set.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setWithCapacity:

+ (instancetype) setWithCapacity: (NSUInteger) capacity

Definition at line 53 of file OOWeakSet.m.

53 :(NSUInteger)capacity
54{
55 return [[[self alloc] initWithCapacity:capacity] autorelease];
56}

Member Data Documentation

◆ _objects

- (NSMutableSet*) _objects
private

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