60- (void) setPerformCleanup:(BOOL)flag;
65@interface OOShipGroup (Private)
67- (BOOL) resizeTo:(NSUInteger)newCapacity;
86- (id) initWithName:(NSString *)name
88 if ((
self = [super
init]))
86- (id) initWithName:(NSString *)name {
…}
105+ (instancetype) groupWithName:(NSString *)name
107 return [[[
self alloc] initWithName:name] autorelease];
105+ (instancetype) groupWithName:(NSString *)name {
…}
111+ (instancetype) groupWithName:(NSString *)name leader:(
ShipEntity *)leader
111+ (instancetype) groupWithName:(NSString *)name leader:(
ShipEntity *)leader {
…}
123 for (i = 0; i < _count; i++)
136 NSString *desc = [
NSString stringWithFormat:@"%llu ships", (unsigned long long)_count];
139 desc = [
NSString stringWithFormat:@"\"%@\", %@", [
self name], desc];
143 desc = [
NSString stringWithFormat:@"%@, leader: %@", desc, [[
self leader] shortDescription]];
155- (void) setName:(NSString *)name
162 _name = [name retain];
155- (void) setName:(NSString *)name {
…}
219#if OOLITE_FAST_ENUMERATION
223 NSUInteger
count = 0;
224 NSArray *result =
nil;
226 if (_count == 0)
return [
NSArray array];
228 objects = malloc(
sizeof *objects * _count);
229 for (
id ship in
self)
231 objects[count++] = ship;
234 result = [
NSArray arrayWithObjects:objects count:count];
244 NSUInteger
count = 0;
245 NSArray *result =
nil;
248 if (_count == 0)
return [
NSArray array];
251 objects = malloc(
sizeof *objects * _count);
252 for (
id ship in
self)
256 objects[count++] = ship;
260 result = [
NSArray arrayWithObjects:objects count:count];
271 for (containedShip in
self)
273 if ([ship isEqual:containedShip])
282- (NSArray *) memberArray
284 return [[
self objectEnumerator] allObjects];
288- (NSArray *) memberArrayExcludingLeader
291 NSUInteger
count = 0;
292 NSArray *result =
nil;
293 NSEnumerator *shipEnum =
nil;
294 ShipEntity *ship =
nil;
295 ShipEntity *leader =
nil;
297 if (_count == 0)
return [NSArray array];
298 leader = [
self leader];
299 if (leader ==
nil)
return [
self memberArray];
301 objects = malloc(
sizeof *objects * _count);
302 for (shipEnum = [
self objectEnumerator]; (ship = [shipEnum nextObject]); )
306 objects[count++] = ship;
310 result = [NSArray arrayWithObjects:objects count:count];
317- (BOOL) containsShip:(ShipEntity *)ship
319 OOShipGroupEnumerator *shipEnum =
nil;
320 ShipEntity *containedShip =
nil;
323 shipEnum = (OOShipGroupEnumerator *)[
self objectEnumerator];
325 while ((containedShip = [shipEnum nextObject]))
327 if ([ship isEqual:containedShip])
346 if ([
self containsShip:ship])
return YES;
349 if (_count == _capacity)
353 if (![
self resizeTo:_capacity + 1])
379 while ((containedShip = [shipEnum nextObject]))
381 if ([ship isEqual:containedShip])
405 NSEnumerator *memberEnum =
nil;
406 NSUInteger result = 0;
411 while ([memberEnum nextObject] !=
nil) result++;
414 assert(result == _count);
422 if (_count == 0)
return YES;
428- (BOOL) resizeTo:(NSUInteger)newCapacity
432 if (newCapacity < _count)
return NO;
434 temp = realloc(_members, newCapacity *
sizeof *_members);
435 if (temp == NULL)
return NO;
438 _capacity = newCapacity;
428- (BOOL) resizeTo:(NSUInteger)newCapacity {
…}
445 NSUInteger newCapacity = _capacity;
451 newCapacity = _count + 1;
456 if (_capacity > _count * 2)
458 newCapacity = OORoundUpToPowerOf2_NS(_count);
463 if (newCapacity != _capacity) [
self resizeTo:newCapacity];
479 BOOL cleanupNeeded = NO;
483 [
NSException raise:NSGenericException format:@"Collection <OOShipGroup: %p> was mutated while being enumerated.", group];
486 while (enumerator->
_index < group->_count)
514#if OOLITE_FAST_ENUMERATION
515- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(
id *)stackbuf count:(NSUInteger)len
517 NSUInteger srcIndex, dstIndex = 0;
519 BOOL cleanupNeeded = NO;
521 srcIndex = state->state;
522 while (srcIndex < _count && dstIndex < len)
537 if (cleanupNeeded) [
self cleanUp];
539 state->state = srcIndex;
540 state->itemsPtr = stackbuf;
515- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(
id *)stackbuf count:(NSUInteger)len {
…}
565 assert(group !=
nil);
567 if ((
self = [super init]))
598- (void) setPerformCleanup:(BOOL)flag
598- (void) setPerformCleanup:(BOOL)flag {
…}
static id ShipGroupIterate(OOShipGroupEnumerator *enumerator)
void setPerformCleanup:(BOOL flag)
void setName:(NSString *name)
BOOL addShip:(ShipEntity *ship)
OOWeakReference ** _members
id initWithName:(NSString *name)
void setLeader:(ShipEntity *leader)
NSEnumerator * mutationSafeEnumerator()
instancetype groupWithName:(NSString *name)
BOOL resizeTo:(NSUInteger newCapacity)
NSEnumerator * objectEnumerator()
BOOL suppressClangStuff()
NSString * descriptionComponents()
< NSFastEnumeration > unsigned long _updateCount
NSArray * memberArrayExcludingLeader()
struct JSObject * _jsSelf
static id ShipGroupIterate(OOShipGroupEnumerator *enumerator)
NSSet * membersExcludingLeader()
OOWeakReference * _leader
id weakRefUnderlyingObject()
void setGroup:(OOShipGroup *group)
void setOwner:(Entity *who_owns_entity)