Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOFilteringEnumerator Class Reference

#include <OOFilteringEnumerator.h>

+ Inheritance diagram for OOFilteringEnumerator:
+ Collaboration diagram for OOFilteringEnumerator:

Instance Methods

(id) - initWithUnderlyingEnumerator:withSelector:takingArgument:argumentValue:
 
(void) - dealloc [implementation]
 
(NSString *) - descriptionComponents [implementation]
 
(NSString *) - shortDescriptionComponents [implementation]
 
(id) - nextObject [implementation]
 

Class Methods

(id) + filterEnumerator:withSelector:
 
(id) + filterEnumerator:withSelector:andArgument:
 

Private Attributes

NSEnumerator * _underlyingEnum
 
SEL _selector
 
id _argument
 
BOOL _takesArgument
 

Detailed Description

Definition at line 57 of file OOFilteringEnumerator.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 33 of file OOFilteringEnumerator.m.

82{
83 [_underlyingEnum release];
84 [_argument release];
85
86 [super dealloc];
87}

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Definition at line 33 of file OOFilteringEnumerator.m.

91{
92 NSString *subDesc = NSStringFromSelector(_selector);
94 {
95 subDesc = [subDesc stringByAppendingString:[_argument shortDescription]];
96 }
97
98 return [NSString stringWithFormat:@"%@ matching %@", [_underlyingEnum shortDescription], subDesc];
99}

◆ filterEnumerator:withSelector:

+ (id) filterEnumerator: (NSEnumerator *) enumerator
withSelector: (SEL) selector 

Definition at line 33 of file OOFilteringEnumerator.m.

38 :(NSEnumerator *)enumerator withSelector:(SEL)selector
39{
40 if (selector == NULL) return [[enumerator retain] autorelease];
41
42 return [[[self alloc] initWithUnderlyingEnumerator:enumerator
43 withSelector:selector
44 takingArgument:NO
45 argumentValue:nil]
46 autorelease];
47}

◆ filterEnumerator:withSelector:andArgument:

+ (id) filterEnumerator: (NSEnumerator *) enumerator
withSelector: (SEL) selector
andArgument: (id) argument 

Definition at line 33 of file OOFilteringEnumerator.m.

50 :(NSEnumerator *)enumerator withSelector:(SEL)selector andArgument:(id)argument
51{
52 if (selector == NULL) return [[enumerator retain] autorelease];
53
54 return [[[self alloc] initWithUnderlyingEnumerator:enumerator
55 withSelector:selector
56 takingArgument:YES
57 argumentValue:argument]
58 autorelease];
59}

◆ initWithUnderlyingEnumerator:withSelector:takingArgument:argumentValue:

- (id) initWithUnderlyingEnumerator: (NSEnumerator *) enumerator
withSelector: (SEL) selector
takingArgument: (BOOL) takesArgument
argumentValue: (id) argument 

Definition at line 33 of file OOFilteringEnumerator.m.

61 :(NSEnumerator *)enumerator
62 withSelector:(SEL)selector
63 takingArgument:(BOOL)takesArgument
64 argumentValue:(id)argument
65{
66 self = [super init];
67 if (self != nil)
68 {
69 _underlyingEnum = [enumerator retain];
70 _selector = selector;
71 _takesArgument = takesArgument;
73 {
74 _argument = [argument retain];
75 }
76 }
77 return self;
78}
return nil

◆ nextObject

- (id) nextObject
implementation

Definition at line 33 of file OOFilteringEnumerator.m.

109{
110 for (;;)
111 {
112 // Get next object
113 id obj = [_underlyingEnum nextObject];
114 BOOL filter;
115
116 if (obj == nil)
117 {
118 // End of enumeration
119 if (_underlyingEnum != nil)
120 {
121 [_underlyingEnum release];
123 [_argument release];
124 _argument = nil;
125 }
126 return nil;
127 }
128
129 // Check against filter
130 IMP predicate = [obj methodForSelector:_selector];
131 if (predicate != NULL)
132 {
133 if (!_takesArgument)
134 {
135 filter = ((BoolReturnMsgSend)predicate)(obj, _selector);
136 }
137 else
138 {
139 filter = ((BoolReturnWithParamMsgSend)predicate)(obj, _selector, _argument);
140 }
141 }
142 else
143 {
144 // Unsupported method
145 filter = NO;
146 }
147
148 // If object passed, return it.
149 if (filter) return obj;
150 }
151}
BOOL(* BoolReturnMsgSend)(id, SEL)
BOOL(* BoolReturnWithParamMsgSend)(id, SEL, id)

◆ shortDescriptionComponents

- (NSString *) shortDescriptionComponents
implementation

Definition at line 33 of file OOFilteringEnumerator.m.

103{
104 return NSStringFromSelector(_selector);
105}

Member Data Documentation

◆ _argument

- (id) _argument
private

Definition at line 62 of file OOFilteringEnumerator.h.

◆ _selector

- (SEL) _selector
private

Definition at line 61 of file OOFilteringEnumerator.h.

◆ _takesArgument

- (BOOL) _takesArgument
private

Definition at line 63 of file OOFilteringEnumerator.h.

◆ _underlyingEnum

- (NSEnumerator*) _underlyingEnum
private

Definition at line 60 of file OOFilteringEnumerator.h.


The documentation for this class was generated from the following files: