Oolite
Loading...
Searching...
No Matches
NSSet(OODeepCopy) Category Reference

Instance Methods

(id) - ooDeepCopyWithSharedObjects: [implementation]

Detailed Description

Definition at line 150 of file OODeepCopy.m.

Method Documentation

◆ ooDeepCopyWithSharedObjects:

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

Definition at line 152 of file OODeepCopy.m.

152 :(NSMutableSet*)objects
153{
154 NSUInteger i, count;
155 id* members = NULL;
156 NSSet* result = nil;
157 BOOL tempObjects = NO;
158
159 count = [self count];
160 if (count == 0)
161 return [[NSSet set] retain];
162
163 members = malloc(sizeof *members * count);
164 if (members == NULL) {
165 [NSException raise:NSMallocException format:@"Failed to allocate space for %zu objects in %s.", count, __PRETTY_FUNCTION__];
166 }
167
168 // Ensure there's an objects set even if passed nil.
169 if (objects == nil) {
170 objects = [[NSMutableSet alloc] init];
171 tempObjects = YES;
172 }
173
174 @try {
175 i = 0;
176 id member = nil;
177 // Deep copy members.
178 foreach (member, self) {
179 members[i] = [member ooDeepCopyWithSharedObjects:objects];
180 i++;
181 }
182
183 // Make NSSet of results.
184 result = [[NSSet alloc] initWithObjects:members count:count];
185 }
186 @finally {
187 // Release objects.
188 for (i = 0; i < count; i++) {
189 [members[i] release];
190 }
191
192 free(members);
193 if (tempObjects)
194 [objects release];
195 }
196
197 // Collections are not reused because comparing them is arbitrarily slow.
198 return result;
199}
unsigned count
return nil

References count, and nil.


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