2
Copyright (C) 2000-2005 SKYRIX Software AG
4
This file is part of SOPE.
6
SOPE is free software; you can redistribute it and/or modify it under
7
the terms of the GNU Lesser General Public License as published by the
8
Free Software Foundation; either version 2, or (at your option) any
11
SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14
License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with SOPE; see the file COPYING. If not, write to the
18
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22
#include "NSArray+enumerator.h"
25
@implementation NSArray(enumerator)
27
- (id)initWithObjectsFromEnumerator:(NSEnumerator *)_enumerator {
28
NSMutableArray *array = nil;
30
array = [[NSMutableArray alloc]
31
initWithObjectsFromEnumerator:_enumerator];
32
self = [self initWithArray:array];
33
[array release]; array = nil;
39
- (NSArray *)mappedArrayUsingSelector:(SEL)_selector {
40
int i, count = [self count];
44
if (_selector == NULL) return self;
46
objAtIndex = [self methodForSelector:@selector(objectAtIndex:)];
48
for (i = 0; i < count; i++) {
49
objects[i] = objAtIndex(self, @selector(objectAtIndex:), i);
50
objects[i] = [objects[i] performSelector:_selector];
51
if (objects[i] == nil)
52
objects[i] = [NSNull null];
55
return [NSArray arrayWithObjects:objects count:count];
57
- (NSArray *)mappedArrayUsingSelector:(SEL)_selector withObject:(id)_object {
58
int i, count = [self count];
62
if (_selector == NULL) return self;
64
objAtIndex = [self methodForSelector:@selector(objectAtIndex:)];
66
for (i = 0; i < count; i++) {
67
objects[i] = [objAtIndex(self, @selector(objectAtIndex:), i)
68
performSelector:_selector withObject:_object];
70
if (objects[i] == nil)
71
objects[i] = [NSNull null];
74
return [NSArray arrayWithObjects:objects count:count];
77
- (NSSet *)mappedSetUsingSelector:(SEL)_selector {
78
return [NSSet setWithArray:[self mappedArrayUsingSelector:_selector]];
80
- (NSSet *)mappedSetUsingSelector:(SEL)_selector withObject:(id)_object {
81
return [NSSet setWithArray:[self mappedArrayUsingSelector:_selector
85
#if !LIB_FOUNDATION_LIBRARY
87
- (NSArray *)map:(SEL)_sel {
88
unsigned int index, count;
92
array = [NSMutableArray arrayWithCapacity:count];
93
for (index = 0; index < count; index++) {
94
[array insertObject:[[self objectAtIndex:index] performSelector:_sel]
100
- (NSArray *)map:(SEL)_sel with:(id)_arg {
101
unsigned int index, count;
104
count = [self count];
105
array = [NSMutableArray arrayWithCapacity:count];
106
for (index = 0; index < count; index++) {
107
[array insertObject:[[self objectAtIndex:index]
108
performSelector:_sel withObject:_arg]
116
@end /* NSArray(enumerator) */
118
@implementation NSMutableArray(enumerator)
120
- (id)initWithObjectsFromEnumerator:(NSEnumerator *)_enumerator {
121
if ((self = [self init])) {
124
while ((obj = [_enumerator nextObject]))
125
[self addObject:obj];
130
@end /* NSMutableArray(enumerator) */
132
void __link_NGExtensions_NSArrayEnumerator() {
133
__link_NGExtensions_NSArrayEnumerator();