~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-core/NGExtensions/FdExt.subproj/NSArray+enumerator.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2000-2005 SKYRIX Software AG
 
3
 
 
4
  This file is part of SOPE.
 
5
 
 
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
 
9
  later version.
 
10
 
 
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.
 
15
 
 
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
 
19
  02111-1307, USA.
 
20
*/
 
21
 
 
22
#include "NSArray+enumerator.h"
 
23
#include "common.h"
 
24
 
 
25
@implementation NSArray(enumerator)
 
26
 
 
27
- (id)initWithObjectsFromEnumerator:(NSEnumerator *)_enumerator {
 
28
  NSMutableArray *array = nil;
 
29
  
 
30
  array = [[NSMutableArray alloc]
 
31
                           initWithObjectsFromEnumerator:_enumerator];
 
32
  self = [self initWithArray:array];
 
33
  [array release]; array = nil;
 
34
  return self;
 
35
}
 
36
 
 
37
/* mapping */
 
38
 
 
39
- (NSArray *)mappedArrayUsingSelector:(SEL)_selector {
 
40
  int i, count = [self count];
 
41
  id  objects[count];
 
42
  IMP objAtIndex;
 
43
  
 
44
  if (_selector == NULL) return self;
 
45
 
 
46
  objAtIndex = [self methodForSelector:@selector(objectAtIndex:)];
 
47
 
 
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];
 
53
  }
 
54
 
 
55
  return [NSArray arrayWithObjects:objects count:count];
 
56
}
 
57
- (NSArray *)mappedArrayUsingSelector:(SEL)_selector withObject:(id)_object {
 
58
  int i, count = [self count];
 
59
  id  objects[count];
 
60
  IMP objAtIndex;
 
61
  
 
62
  if (_selector == NULL) return self;
 
63
 
 
64
  objAtIndex = [self methodForSelector:@selector(objectAtIndex:)];
 
65
 
 
66
  for (i = 0; i < count; i++) {
 
67
    objects[i] = [objAtIndex(self, @selector(objectAtIndex:), i)
 
68
                            performSelector:_selector withObject:_object];
 
69
 
 
70
    if (objects[i] == nil)
 
71
      objects[i] = [NSNull null];
 
72
  }
 
73
 
 
74
  return [NSArray arrayWithObjects:objects count:count];
 
75
}
 
76
 
 
77
- (NSSet *)mappedSetUsingSelector:(SEL)_selector {
 
78
  return [NSSet setWithArray:[self mappedArrayUsingSelector:_selector]];
 
79
}
 
80
- (NSSet *)mappedSetUsingSelector:(SEL)_selector withObject:(id)_object {
 
81
  return [NSSet setWithArray:[self mappedArrayUsingSelector:_selector
 
82
                                   withObject:_object]];
 
83
}
 
84
 
 
85
#if !LIB_FOUNDATION_LIBRARY
 
86
 
 
87
- (NSArray *)map:(SEL)_sel {
 
88
  unsigned int index, count;
 
89
  id array;
 
90
  
 
91
  count = [self count];
 
92
  array = [NSMutableArray arrayWithCapacity:count];
 
93
  for (index = 0; index < count; index++) {
 
94
    [array insertObject:[[self objectAtIndex:index] performSelector:_sel]
 
95
           atIndex:index];
 
96
  }
 
97
  return array;
 
98
}
 
99
 
 
100
- (NSArray *)map:(SEL)_sel with:(id)_arg {
 
101
  unsigned int index, count;
 
102
  id array;
 
103
  
 
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]
 
109
           atIndex:index];
 
110
  }
 
111
  return array;
 
112
}
 
113
 
 
114
#endif
 
115
 
 
116
@end /* NSArray(enumerator) */
 
117
 
 
118
@implementation NSMutableArray(enumerator) 
 
119
 
 
120
- (id)initWithObjectsFromEnumerator:(NSEnumerator *)_enumerator {
 
121
  if ((self = [self init])) {
 
122
    id obj = nil;
 
123
     
 
124
    while ((obj = [_enumerator nextObject]))
 
125
      [self addObject:obj];
 
126
  }
 
127
  return self;
 
128
}
 
129
 
 
130
@end /* NSMutableArray(enumerator)  */
 
131
 
 
132
void __link_NGExtensions_NSArrayEnumerator() {
 
133
  __link_NGExtensions_NSArrayEnumerator();
 
134
}