]> err.no Git - sope/blob - sope-core/NGExtensions/FdExt.subproj/NSSet+enumerator.m
fixed a compilation issue
[sope] / sope-core / NGExtensions / FdExt.subproj / NSSet+enumerator.m
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 #import "common.h"
23 #import "NSSet+enumerator.h"
24
25 @implementation NSSet(enumerator)
26
27 - (id)initWithObjectsFromEnumerator:(NSEnumerator *)_enumerator {
28   NSMutableSet *set = nil;
29
30   set = [[NSMutableSet alloc] initWithObjectsFromEnumerator:_enumerator];
31   self = [self initWithSet:set];
32   [set release]; set = nil;
33   return self;
34 }
35
36 // mapping
37
38 - (NSArray *)mappedArrayUsingSelector:(SEL)_selector {
39   NSArray *array = nil;
40   NSSet   *set   = nil;
41
42   set = [self mappedSetUsingSelector:_selector];
43   if (set) {
44     array = [[NSArray allocWithZone:[self zone]]
45                       initWithObjectsFromEnumerator:[set objectEnumerator]];
46   }
47   set = nil;
48   return [array autorelease];
49 }
50 - (NSArray *)mappedArrayUsingSelector:(SEL)_selector withObject:(id)_object {
51   NSArray *array = nil;
52   NSSet   *set   = nil;
53
54   set = [self mappedSetUsingSelector:_selector withObject:_object];
55   if (set) {
56     array = [[NSArray allocWithZone:[self zone]]
57                       initWithObjectsFromEnumerator:[set objectEnumerator]];
58   }
59   set = nil;
60   return [array autorelease];
61 }
62
63 - (NSSet *)mappedSetUsingSelector:(SEL)_selector {
64   NSMutableSet *set   = [NSMutableSet setWithCapacity:[self count]];
65   NSEnumerator *e     = [self objectEnumerator];
66   id           object = nil;
67
68   while ((object = [e nextObject])) {
69     object = [object performSelector:_selector];
70
71     [set addObject:object ? object : [NSNull null]];
72   }
73   return set;
74 }
75 - (NSSet *)mappedSetUsingSelector:(SEL)_selector withObject:(id)_object {
76   NSMutableSet *set = [NSMutableSet setWithCapacity:[self count]];
77   NSEnumerator *e     = [self objectEnumerator];
78   id           object = nil;
79
80   while ((object = [e nextObject])) {
81     object = [object performSelector:_selector withObject:_object];
82
83     [set addObject:object ? object : [NSNull null]];
84   }
85   return set;
86 }
87
88 @end
89
90 @implementation NSMutableSet(enumerator) 
91
92 - (id)initWithObjectsFromEnumerator:(NSEnumerator *)_enumerator {
93   if ((self = [self init])) {
94     id obj = nil;
95      
96     while ((obj = [_enumerator nextObject]))
97       [self addObject:obj];
98   }
99   return self;
100 }
101
102 @end
103
104 void __link_NGExtensions_NSSetEnumerator() {
105   __link_NGExtensions_NSSetEnumerator();
106 }