Oolite
Loading...
Searching...
No Matches
OOExcludeObjectEnumerator.m
Go to the documentation of this file.
1/*
2
3OOExcludeObjectEnumerator.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
27
28@implementation OOExcludeObjectEnumerator
29
30- (id)initWithEnumerator:(NSEnumerator*)enumerator
31 excludingObject:(id)object
32{
33 if ((self = [super init])) {
34 _enumerator = [enumerator retain];
35 _excludeObject = [object retain];
36 }
37
38 return self;
39}
40
41- (void)dealloc
42{
43 [_enumerator release];
44 [_excludeObject release];
45
46 [super dealloc];
47}
48
49+ (id)enumeratorWithEnumerator:(NSEnumerator*)enumerator
50 excludingObject:(id)object
51{
52 if (object == nil)
53 return enumerator;
54 if (enumerator == nil)
55 return nil;
56
57 return [[[self alloc] initWithEnumerator:enumerator excludingObject:object] autorelease];
58}
59
61{
62 id result = nil;
63 do {
64 result = [_enumerator nextObject];
65 } while (result == _excludeObject && result != nil);
66
67 return result;
68}
69
70@end
71
72@implementation NSEnumerator (OOExcludingObject)
73
74- (id)ooExcludingObject:(id)object
75{
77}
78
79@end
return nil
id enumeratorWithEnumerator:excludingObject:(NSEnumerator *enumerator,[excludingObject] id object)