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

Instance Methods

(id) - ooDeepCopyWithSharedObjects: [implementation]

Detailed Description

Definition at line 203 of file OODeepCopy.m.

Method Documentation

◆ ooDeepCopyWithSharedObjects:

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

Definition at line 205 of file OODeepCopy.m.

205 :(NSMutableSet*)objects
206{
207 NSUInteger i, count;
208 id* keys = NULL;
209 id* values = NULL;
210 NSDictionary* result = nil;
211 BOOL tempObjects = NO;
212
213 count = [self count];
214 if (count == 0)
215 return [[NSDictionary dictionary] retain];
216
217 keys = malloc(sizeof *keys * count);
218 values = malloc(sizeof *values * count);
219 if (keys == NULL || values == NULL) {
220 free(keys);
221 free(values);
222 [NSException raise:NSMallocException format:@"Failed to allocate space for %zu objects in %s.", count, __PRETTY_FUNCTION__];
223 }
224
225 // Ensure there's an objects set even if passed nil.
226 if (objects == nil) {
227 objects = [[NSMutableSet alloc] init];
228 tempObjects = YES;
229 }
230
231 @try {
232 i = 0;
233 id key = nil;
234 // Deep copy members.
235 foreachkey(key, self)
236 {
237 keys[i] = [key ooDeepCopyWithSharedObjects:objects];
238 values[i] = [[self objectForKey:key] ooDeepCopyWithSharedObjects:objects];
239 i++;
240 }
241
242 // Make NSDictionary of results.
243 result = [[NSDictionary alloc] initWithObjects:values forKeys:keys count:count];
244 }
245 @finally {
246 // Release objects.
247 for (i = 0; i < count; i++) {
248 [keys[i] release];
249 [values[i] release];
250 }
251
252 free(keys);
253 free(values);
254 if (tempObjects)
255 [objects release];
256 }
257
258 // Collections are not reused because comparing them is arbitrarily slow.
259 return result;
260}
#define foreachkey(VAR, DICT)
unsigned count
return nil

References count, foreachkey, and nil.


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