Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
NSSet(OODeepCopy) Category Reference

Instance Methods

(id) - ooDeepCopyWithSharedObjects: [implementation]
 

Detailed Description

Definition at line 166 of file OODeepCopy.m.

Method Documentation

◆ ooDeepCopyWithSharedObjects:

- (id) ooDeepCopyWithSharedObjects: (NSMutableSet *) objects
implementation

Definition at line 31 of file OODeepCopy.m.

168 :(NSMutableSet *)objects
169{
170 NSUInteger i, count;
171 id *members = NULL;
172 NSSet *result = nil;
173 BOOL tempObjects = NO;
174
175 count = [self count];
176 if (count == 0) return [[NSSet set] retain];
177
178 members = malloc(sizeof *members * count);
179 if (members == NULL)
180 {
181 [NSException raise:NSMallocException format:@"Failed to allocate space for %lu objects in %s.", (unsigned long)count, __PRETTY_FUNCTION__];
182 }
183
184 // Ensure there's an objects set even if passed nil.
185 if (objects == nil)
186 {
187 objects = [[NSMutableSet alloc] init];
188 tempObjects = YES;
189 }
190
191 @try
192 {
193 i = 0;
194 id member = nil;
195 // Deep copy members.
196 foreach (member, self)
197 {
198 members[i] = [member ooDeepCopyWithSharedObjects:objects];
199 i++;
200 }
201
202 // Make NSSet of results.
203 result = [[NSSet alloc] initWithObjects:members count:count];
204 }
205 @finally
206 {
207 // Release objects.
208 for (i = 0; i < count; i++)
209 {
210 [members[i] release];
211 }
212
213 free(members);
214 if (tempObjects) [objects release];
215 }
216
217 // Collections are not reused because comparing them is arbitrarily slow.
218 return result;
219}
unsigned count
return nil

The documentation for this category was generated from the following file: