-
Notifications
You must be signed in to change notification settings - Fork 1
/
AMStandardEnumerator.m
59 lines (47 loc) · 1.24 KB
/
AMStandardEnumerator.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// AMStandardEnumerator.m
//
// Created by Andreas on Mon Aug 04 2003.
// Copyright (c) 2003 Andreas Mayer. All rights reserved.
//
// 2007-10-26 Sean McBride
// - made code 64 bit and garbage collection clean
#import "AMSDKCompatibility.h"
#import "AMStandardEnumerator.h"
@implementation AMStandardEnumerator
// Designated initializer
- (id)initWithCollection:(id)theCollection countSelector:(SEL)theCountSelector objectAtIndexSelector:(SEL)theObjectSelector
{
self = [super init];
if (self) {
collection = [theCollection retain];
countSelector = theCountSelector;
count = (CountMethod)[collection methodForSelector:countSelector];
nextObjectSelector = theObjectSelector;
nextObject = (NextObjectMethod)[collection methodForSelector:nextObjectSelector];
position = 0;
}
return self;
}
#ifndef __OBJC_GC__
- (void)dealloc
{
[collection release];
[super dealloc];
}
#endif
- (id)nextObject
{
if (position >= count(collection, countSelector))
return nil;
return (nextObject(collection, nextObjectSelector, position++));
}
- (NSArray *)allObjects
{
NSMutableArray *result = [[[NSMutableArray alloc] init] autorelease];
id object;
while ((object = [self nextObject]) != nil)
[result addObject:object];
return result;
}
@end