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