]> err.no Git - sope/blob - sope-core/NGExtensions/FdExt.subproj/NSEnumerator+misc.m
fixed a compilation issue
[sope] / sope-core / NGExtensions / FdExt.subproj / NSEnumerator+misc.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 "NSEnumerator+misc.h"
23 #import <Foundation/Foundation.h>
24 #import <EOControl/EOQualifier.h>
25 #include "common.h"
26
27 @interface _NGFilterEnumerator : NSEnumerator
28 {
29   NSEnumerator *source;
30 }
31
32 + (NSEnumerator *)filterEnumeratorWithSource:(NSEnumerator *)_e;
33
34 - (NSEnumerator *)source;
35
36 @end
37
38 @interface _NGQualifierFilterEnumerator : _NGFilterEnumerator
39 {
40   EOQualifier *q;
41 }
42 - (void)setQualifier:(EOQualifier *)_q;
43 - (EOQualifier *)qualifier;
44 @end
45
46 @interface _NGSelFilterEnumerator : _NGFilterEnumerator
47 {
48   SEL  sel;
49   id   arg;
50 }
51 - (void)setSelector:(SEL)_s;
52 - (SEL)selector;
53 - (void)setArgument:(id)_arg;
54 - (id)argument;
55 @end
56
57 @implementation NSEnumerator(misc)
58
59 - (NSEnumerator *)filterWithQualifier:(EOQualifier *)_qualifier {
60   id e;
61   
62   e = [_NGQualifierFilterEnumerator filterEnumeratorWithSource:self];
63   [e setQualifier:_qualifier];
64   return e;
65 }
66 - (NSEnumerator *)filterWithQualifierString:(NSString *)_s {
67   EOQualifier *q;
68   
69   q = [EOQualifier qualifierWithQualifierFormat:_s];
70   return [self filterWithQualifier:q];
71 }
72
73 - (NSEnumerator *)filterWithSelector:(SEL)_selector withObject:(id)_argument {
74   id e;
75   
76   e = [_NGSelFilterEnumerator filterEnumeratorWithSource:self];
77   [e setSelector:_selector];
78   [e setArgument:_argument];
79   return e;
80 }
81
82 @end /* NSEnumerator(misc) */
83
84 @implementation _NGFilterEnumerator
85
86 - (id)initWithSource:(NSEnumerator *)_e {
87   self->source = [_e retain];
88   return self;
89 }
90 - (void)dealloc {
91   [self->source release];
92   [super dealloc];
93 }
94
95 + (NSEnumerator *)filterEnumeratorWithSource:(NSEnumerator *)_e {
96   return [[(_NGFilterEnumerator *)[self alloc] initWithSource:_e] autorelease];
97 }
98
99 - (NSEnumerator *)source {
100   return self->source;
101 }
102
103 - (id)nextObject {
104   return [self->source nextObject];
105 }
106
107 @end /* _NGFilterEnumerator */
108
109 @implementation _NGQualifierFilterEnumerator
110
111 - (void)dealloc {
112   [self->q release];
113   [super dealloc];
114 }
115
116 - (void)setQualifier:(EOQualifier *)_q {
117   ASSIGN(self->q, _q);
118 }
119 - (EOQualifier *)qualifier {
120   return self->q;
121 }
122
123 - (id)nextObject {
124   while (YES) {
125     id obj;
126     
127     if ((obj = [self->source nextObject]) == nil)
128       return nil;
129     if (self->q == nil)
130       return obj;
131
132     if ([(id<EOQualifierEvaluation>)self->q evaluateWithObject:obj])
133       return obj;
134   }
135 }
136
137 @end /* _NGQualifierFilterEnumerator */
138
139 @implementation _NGSelFilterEnumerator
140
141 - (void)dealloc {
142   [self->arg release];
143   [super dealloc];
144 }
145
146 - (void)setSelector:(SEL)_s {
147   self->sel = _s;
148 }
149 - (SEL)selector {
150   return self->sel;
151 }
152
153 - (void)setArgument:(id)_arg {
154   ASSIGN(self->arg, _arg);
155 }
156 - (id)argument {
157   return self->arg;
158 }
159
160 - (id)nextObject {
161   while (YES) {
162     id obj;
163     BOOL (*m)(id,SEL,id);
164     
165     if ((obj = [self->source nextObject]) == nil)
166       return nil;
167     
168     if ((m = (void *)[obj methodForSelector:self->sel]) == NULL)
169       continue;
170
171     if (m(obj, self->sel, self->arg))
172       return obj;
173   }
174 }
175
176 @end /* _NGSelFilterEnumerator */