Oolite
Loading...
Searching...
No Matches
OOOXPVerifierStage.m
Go to the documentation of this file.
1/*
2
3OOOXPVerifierStage.m
4
5
6Copyright (C) 2007-2013 Jens Ayton
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25
26*/
27
28#include <assert.h>
29
31
32#if OO_OXP_VERIFIER_ENABLED
33
34@interface OOOXPVerifierStage (OOPrivate)
35
36- (void)registerDepedent:(OOOXPVerifierStage *)dependent;
37- (void)dependencyCompleted:(OOOXPVerifierStage *)dependency;
38
39@end
40
41
42@implementation OOOXPVerifierStage
43
44- (id)init
45{
46 self = [super init];
47
48 if (self != nil)
49 {
50 _dependencies = [[NSMutableSet alloc] init];
51 _incompleteDependencies = [[NSMutableSet alloc] init];
52 _dependents = [[NSMutableSet alloc] init];
53 _canRun = NO;
54 }
55
56 return self;
57}
58
59
60- (void)dealloc
61{
62 [_dependencies release];
63 [_incompleteDependencies release];
64 [_dependents release];
65
66 [super dealloc];
67}
68
69
70- (id)description
71{
72 return [NSString stringWithFormat:@"<%@ %p>{\"%@\"}", [self class], self, [self name]];
73}
74
75
76- (OOOXPVerifier *)verifier
77{
78 return [[_verifier retain] autorelease];
79}
80
81
82- (BOOL)completed
83{
84 return _hasRun;
85}
86
87
88- (NSString *)name
89{
91 return nil;
92}
93
94
95- (NSSet *)dependencies
96{
97 return nil;
98}
99
100
101- (NSSet *)dependents
102{
103 return nil;
104}
105
106
107- (BOOL)shouldRun
108{
109 return YES;
110}
111
112
113- (void)run
114{
116}
117
118@end
119
120
121@implementation OOOXPVerifierStage (OOInternal)
122
123- (void)setVerifier:(OOOXPVerifier *)verifier
124{
125 _verifier = verifier; // Not retained.
126}
127
128
129- (BOOL)isDependentOf:(OOOXPVerifierStage *)stage
130{
131 OOOXPVerifierStage *directDep = nil;
132
133 if (stage == nil) return NO;
134
135 // Direct dependency check.
136 if ([_dependencies containsObject:stage]) return YES;
137
138 // Recursive dependency check.
139 foreach (directDep, _dependencies)
140 {
141 if ([directDep isDependentOf:stage]) return YES;
142 }
143
144 return NO;
145}
146
147
148- (void)registerDependency:(OOOXPVerifierStage *)dependency
149{
150 [_dependencies addObject:dependency];
151 [_incompleteDependencies addObject:dependency];
152
153 [dependency registerDepedent:self];
154}
155
156
157- (BOOL)canRun
158{
159 return _canRun;
160}
161
162
163- (void)performRun
164{
165 assert(_canRun && !_hasRun);
166
168 @try
169 {
170 [self run];
171 }
172 @catch (NSException *exception)
173 {
174 OOLog(@"verifyOXP.exception", @"***** Exception while running verification stage \"%@\": %@", [self name], exception);
175 }
177
178 _hasRun = YES;
179 _canRun = NO;
180 [_dependents makeObjectsPerformSelector:@selector(dependencyCompleted:) withObject:self];
181}
182
183
184- (void)noteSkipped
185{
186 assert(_canRun && !_hasRun);
187
188 _hasRun = YES;
189 _canRun = NO;
190 [_dependents makeObjectsPerformSelector:@selector(dependencyCompleted:) withObject:self];
191}
192
193
194- (void)dependencyRegistrationComplete
195{
196 _canRun = [_incompleteDependencies count] == 0;
197}
198
199
200- (NSSet *)resolvedDependencies
201{
202 return _dependencies;
203}
204
205
206- (NSSet *)resolvedDependents
207{
208 return _dependents;
209}
210
211@end
212
213
214@implementation OOOXPVerifierStage (OOPrivate)
215
216- (void)registerDepedent:(OOOXPVerifierStage *)dependent
217{
218 assert(![self isDependentOf:dependent]);
219
220 [_dependents addObject:dependent];
221}
222
223
224- (void)dependencyCompleted:(OOOXPVerifierStage *)dependency
225{
226 [_incompleteDependencies removeObject:dependency];
227 if ([_incompleteDependencies count] == 0) _canRun = YES;
228}
229
230@end
231
232#endif //OO_OXP_VERIFIER_ENABLED
void OOLogPushIndent(void)
Definition OOLogging.m:316
void OOLogPopIndent(void)
Definition OOLogging.m:340
#define OOLogGenericSubclassResponsibility()
Definition OOLogging.h:129
#define OOLog(class, format,...)
Definition OOLogging.h:88
unsigned count
return nil
void registerDepedent:(OOOXPVerifierStage *dependent)