Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
NSArray(OODeepCopy) Category Reference

Instance Methods

(id) - ooDeepCopyWithSharedObjects: [implementation]
 

Detailed Description

Definition at line 110 of file OODeepCopy.m.

Method Documentation

◆ ooDeepCopyWithSharedObjects:

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

Definition at line 31 of file OODeepCopy.m.

112 :(NSMutableSet *)objects
113{
114 NSUInteger i, count;
115 id *members = NULL;
116 NSArray *result = nil;
117 BOOL tempObjects = NO;
118
119 count = [self count];
120 if (count == 0) return [[NSArray array] retain];
121
122 members = calloc(sizeof *members, count);
123 if (members == NULL)
124 {
125 [NSException raise:NSMallocException format:@"Failed to allocate space for %lu objects in %s.", (unsigned long)count, __PRETTY_FUNCTION__];
126 }
127
128 // Ensure there's an objects set even if passed nil.
129 if (objects == nil)
130 {
131 objects = [[NSMutableSet alloc] init];
132 tempObjects = YES;
133 }
134
135 [self getObjects:members];
136 @try
137 {
138 // Deep copy members.
139 for (i = 0; i < count; i++)
140 {
141 members[i] = [members[i] ooDeepCopyWithSharedObjects:objects];
142 }
143
144 // Make NSArray of results.
145 result = [[NSArray alloc] initWithObjects:members count:count];
146 }
147 @finally
148 {
149 // Release objects.
150 for (i = 0; i < count; i++)
151 {
152 [members[i] release];
153 }
154
155 free(members);
156 if (tempObjects) [objects release];
157 }
158
159 // Collections are not reused because comparing them is arbitrarily slow.
160 return result;
161}
unsigned count
return nil

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