Oolite
Loading...
Searching...
No Matches
OOShipGroup.h
Go to the documentation of this file.
1/*
2OOShipGroup.h
3
4A weak-referencing, mutable set of ships. Not thread safe.
5
6
7Oolite
8Copyright (C) 2004-2013 Giles C Williams and contributors
9
10This program is free software; you can redistribute it and/or
11modify it under the terms of the GNU General Public License
12as published by the Free Software Foundation; either version 2
13of the License, or (at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23MA 02110-1301, USA.
24
25*/
26
27#import "OOFoundation.h"
28#import "OOWeakReference.h"
29
30#if OOJS_QUICKJS
31#include <quickjs.h>
32#endif
33
34@class ShipEntity;
35
36@interface OOShipGroup : OOWeakRefObject <NSFastEnumeration> {
37@private
38 NSUInteger _count, _capacity;
39 unsigned long _updateCount;
42 NSString* _name;
43
44#if OOJS_QUICKJS
45 JSValue _jsSelf; // Zero-filled (not an object) until created; test with JS_IsObject().
46#else
47 struct JSObject* _jsSelf;
48#endif
49}
50
51- (id)init;
52- (id)initWithName:(NSString*)name;
53+ (instancetype)groupWithName:(NSString*)name;
54+ (instancetype)groupWithName:(NSString*)name leader:(ShipEntity*)leader;
55
56- (NSString*)name;
57- (void)setName:(NSString*)name;
58
59- (ShipEntity*)leader;
60- (void)setLeader:(ShipEntity*)leader;
61
62- (NSEnumerator*)objectEnumerator;
63- (NSEnumerator*)mutationSafeEnumerator; // Enumerate over contents at time this is called, even if actual group is mutated.
64
65- (NSSet*)members;
66- (NSArray*)memberArray; // arbitrary order
67- (NSSet*)membersExcludingLeader;
68- (NSArray*)memberArrayExcludingLeader; // arbitrary order
69
70- (BOOL)containsShip:(ShipEntity*)ship;
71- (BOOL)addShip:(ShipEntity*)ship;
72- (BOOL)removeShip:(ShipEntity*)ship;
73
74- (NSUInteger)count; // NOTE: this is O(n).
75- (BOOL)isEmpty;
76
77@end
unsigned count
NSString * _name
Definition OOShipGroup.h:42
OOWeakReference ** _members
Definition OOShipGroup.h:40
unsigned long _updateCount
Definition OOShipGroup.h:39
NSUInteger _count
Definition OOShipGroup.h:38
struct JSObject * _jsSelf
Definition OOShipGroup.h:47
OOWeakReference * _leader
Definition OOShipGroup.h:41
NSUInteger _capacity
Definition OOShipGroup.h:38