From: helge Date: Thu, 4 Aug 2005 14:38:22 +0000 (+0000) Subject: added new rule engine method X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22c028b51caaf36d5047e3569ba7a333147e0fd3;p=sope added new rule engine method minor improv in NSPredicate unarchiving git-svn-id: http://svn.opengroupware.org/SOPE/trunk@969 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-core/EOCoreData/ChangeLog b/sope-core/EOCoreData/ChangeLog index b91af797..27c2ab7b 100644 --- a/sope-core/EOCoreData/ChangeLog +++ b/sope-core/EOCoreData/ChangeLog @@ -1,3 +1,8 @@ +2005-08-04 Helge Hess + + * NSPredicate+EO.m: also check 'selectorName' key during unarchiving + (v4.5.5) + 2005-08-04 Helge Hess * NSExpression+EO.m: added EOKeyValueArchiving (v4.5.4) diff --git a/sope-core/EOCoreData/NSPredicate+EO.m b/sope-core/EOCoreData/NSPredicate+EO.m index 4d9ecbe2..6b616ac8 100644 --- a/sope-core/EOCoreData/NSPredicate+EO.m +++ b/sope-core/EOCoreData/NSPredicate+EO.m @@ -151,10 +151,15 @@ /* custom selector */ - selName = [_unarchiver decodeObjectForKey:@"selector"]; + if ((selName = [_unarchiver decodeObjectForKey:@"selectorName"]) != nil) { + if (![selName hasSuffix:@":"]) + selName = [selName stringByAppendingString:@":"]; + } + else + selName = [_unarchiver decodeObjectForKey:@"selector"]; if ([selName length] > 0) { return [self initWithLeftExpression:left rightExpression:right - customSelector:NSSelectorFromString(selName)]; + customSelector:selName ? NSSelectorFromString(selName):NULL]; } /* modifier */ diff --git a/sope-core/EOCoreData/Version b/sope-core/EOCoreData/Version index 9d93031b..d1646130 100644 --- a/sope-core/EOCoreData/Version +++ b/sope-core/EOCoreData/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=4 +SUBMINOR_VERSION:=5 diff --git a/sope-core/NGExtensions/ChangeLog b/sope-core/NGExtensions/ChangeLog index 5fd5e6c8..6b0ead9b 100644 --- a/sope-core/NGExtensions/ChangeLog +++ b/sope-core/NGExtensions/ChangeLog @@ -1,3 +1,9 @@ +2005-08-04 Helge Hess + + * NGRuleEngine.subproj/NGRuleContext.m: added new method + -allPossibleValuesForKey: to calculate all possible values for a + given key, not just the first matching one (v4.5.169) + 2005-08-04 Helge Hess * EOFilterDataSource.m, EOCompoundDataSource.m: code cleanups diff --git a/sope-core/NGExtensions/NGExtensions/NGRuleContext.h b/sope-core/NGExtensions/NGExtensions/NGRuleContext.h index 0be61d81..e33ad31a 100644 --- a/sope-core/NGExtensions/NGExtensions/NGRuleContext.h +++ b/sope-core/NGExtensions/NGExtensions/NGRuleContext.h @@ -67,6 +67,7 @@ - (id)valueForKey:(NSString *)_key; - (id)inferredValueForKey:(NSString *)_key; +- (NSArray *)allPossibleValuesForKey:(NSString *)_key; - (NSArray *)valuesForKeyPath:(NSString *)_kp takingSuccessiveValues:(NSArray *)_values diff --git a/sope-core/NGExtensions/NGRuleEngine.subproj/NGRuleContext.m b/sope-core/NGExtensions/NGRuleEngine.subproj/NGRuleContext.m index 7bf6e7c0..9d39fffb 100644 --- a/sope-core/NGExtensions/NGRuleEngine.subproj/NGRuleContext.m +++ b/sope-core/NGExtensions/NGRuleEngine.subproj/NGRuleContext.m @@ -119,15 +119,52 @@ return nil; } +- (NSArray *)allPossibleValuesForKey:(NSString *)_key { + NSMutableArray *values; + NSArray *rules; + unsigned i, count; + + if (self->debugOn) + [self debugWithFormat:@"calculate all values for key: '%@'", _key]; + + /* select candidates */ + rules = [[self model] candidateRulesForKey:_key]; + if (self->debugOn) + [self debugWithFormat:@" candidate rules: %@", rules]; + + values = [NSMutableArray arrayWithCapacity:16]; + + /* check qualifiers */ + for (i = 0, count = [rules count]; i < count; i++) { + NGRule *rule; + + rule = [rules objectAtIndex:i]; + if ([(id)[rule qualifier] evaluateWithObject:self]){ + id v; + + if (self->debugOn) + [self debugWithFormat:@" rule %i matches: %@", i, rule]; + + v = [[rule action] fireInContext:self]; + [values addObject:(v ? v : [NSNull null])]; + } + } + if (self->debugOn) + [self debugWithFormat:@" %d rules matched.", [values count]]; + return values; +} + - (id)valueForKey:(NSString *)_key { id v; + + // TODO: add rule cache? /* look for constants */ - if ((v = [self->storedValues objectForKey:_key])) + if ((v = [self->storedValues objectForKey:_key]) != nil) return v; /* look into rule system */ - if ((v = [self inferredValueForKey:_key])) + if ((v = [self inferredValueForKey:_key]) != nil) return v; return nil; diff --git a/sope-core/NGExtensions/Version b/sope-core/NGExtensions/Version index 406c7817..5eee82ff 100644 --- a/sope-core/NGExtensions/Version +++ b/sope-core/NGExtensions/Version @@ -1,6 +1,6 @@ # version -SUBMINOR_VERSION:=168 +SUBMINOR_VERSION:=169 # v4.3.115 requires libFoundation v1.0.59 # v4.2.72 requires libEOControl v4.2.39