Skip to content

Commit

Permalink
Neaten and simplify some code.
Browse files Browse the repository at this point in the history
git-svn-id: svn+voltron://voltron/data/svn/MarcoPolo/trunk@847 a27563e6-5939-db11-9576-004854876331
  • Loading branch information
ds committed Jul 21, 2007
1 parent 0a8e58d commit 0f0fab6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 51 deletions.
4 changes: 0 additions & 4 deletions src/EvidenceSource.h
Expand Up @@ -50,14 +50,11 @@
- (void)stop;

// To be implemented by descendant classes:
// TODO: some of these could be class methods
- (NSString *)name;
- (BOOL)doesRuleMatch:(NSDictionary *)rule;

// Optionally implemented by descendant classes
- (NSArray *)getSuggestions; // NSArray of NSDictionary: keys are type, parameter, description
- (NSArray *)typesOfRulesMatched; // optional; default is [self name]
- (NSString *)getSuggestionLeadText:(NSString *)type; // optional; default is "The presence of"

@end

Expand All @@ -72,7 +69,6 @@
- (EvidenceSource *)sourceWithName:(NSString *)name;
- (void)startOrStopAll;
- (BOOL)ruleMatches:(NSDictionary *)rule;
- (NSArray *)getSuggestionsFromSource:(NSString *)name ofType:(NSString *)type; // type may be nil
- (NSEnumerator *)sourceEnumerator;

// NSMenu delegates (for adding rules)
Expand Down
54 changes: 9 additions & 45 deletions src/EvidenceSource.m
Expand Up @@ -222,15 +222,19 @@ - (void)writeToPanel:(NSDictionary *)dict usingType:(NSString *)type

#pragma mark -

- (void)notImplemented:(NSString *)methodName
- (void)start
{
[NSException raise:@"Abstract Class Exception"
format:[NSString stringWithFormat:@"Error, -%@ not implemented.", methodName]];
[self doesNotRecognizeSelector:_cmd];
}

- (void)stop
{
[self doesNotRecognizeSelector:_cmd];
}

- (NSString *)name
{
[self notImplemented:@"name"];
[self doesNotRecognizeSelector:_cmd];
return nil;
}

Expand All @@ -241,31 +245,10 @@ - (NSArray *)typesOfRulesMatched

- (BOOL)doesRuleMatch:(NSDictionary *)rule
{
[self notImplemented:@"doesRuleMatch"];
[self doesNotRecognizeSelector:_cmd];
return NO;
}

- (NSString *)getSuggestionLeadText:(NSString *)type
{
return NSLocalizedString(@"The presence of", @"In rule-adding dialog");
}

- (NSArray *)getSuggestions
{
[self notImplemented:@"getSuggestions"];
return nil;
}

- (void)start
{
[self notImplemented:@"start"];
}

- (void)stop
{
[self notImplemented:@"stop"];
}

@end

#pragma mark -
Expand Down Expand Up @@ -382,25 +365,6 @@ - (BOOL)ruleMatches:(NSDictionary *)rule
return NO;
}

- (NSArray *)getSuggestionsFromSource:(NSString *)name ofType:(NSString *)type
{
EvidenceSource *src = [self sourceWithName:name];

if (!type)
return [src getSuggestions];

NSMutableArray *suggestions = [NSMutableArray array];
NSArray *s_arr = [src getSuggestions];
NSEnumerator *s_en = [s_arr objectEnumerator];
NSDictionary *s_dict;
while ((s_dict = [s_en nextObject])) {
if ([[s_dict valueForKey:@"type"] isEqualToString:type])
[suggestions addObject:s_dict];
}

return suggestions;
}

- (NSEnumerator *)sourceEnumerator
{
return [sources objectEnumerator];
Expand Down
4 changes: 2 additions & 2 deletions src/GenericEvidenceSource.h
Expand Up @@ -17,7 +17,7 @@
- (id)init;

// Need to be implemented by descendant classes
//- (NSString *)getSuggestionLeadText:(NSString *)type;
//- (NSArray *)getSuggestions;
- (NSString *)getSuggestionLeadText:(NSString *)type;
- (NSArray *)getSuggestions; // returns an NSArray of NSDictionary: keys are type, parameter, description

@end
12 changes: 12 additions & 0 deletions src/GenericEvidenceSource.m
Expand Up @@ -72,4 +72,16 @@ - (void)writeToPanel:(NSDictionary *)dict usingType:(NSString *)type
}
}

- (NSString *)getSuggestionLeadText:(NSString *)type
{
[self doesNotRecognizeSelector:_cmd];
return nil;
}

- (NSArray *)getSuggestions
{
[self doesNotRecognizeSelector:_cmd];
return nil;
}

@end

0 comments on commit 0f0fab6

Please sign in to comment.