+2005-10-03 Helge Hess <helge.hess@opengroupware.org>
+
+ * improved qualifier=>predicate conversion support (v4.5.10)
+
2005-08-23 Helge Hess <helge.hess@opengroupware.org>
* v4.5.9
}
- (NSPredicate *)asPredicate {
- NSLog(@"TODO(%s): implement me for class %@!", __PRETTY_FUNCTION__,
- NSStringFromClass([self class]));
- return nil;
+ NSExpression *lhs, *rhs;
+ id tmp;
+
+ tmp = [self leftKey];
+ lhs = [tmp isKindOfClass:[EOQualifierVariable class]]
+ ? [NSExpression expressionForVariable:[(EOQualifierVariable *)tmp key]]
+ : [NSExpression expressionForKeyPath:tmp];
+
+ tmp = [self rightKey];
+ rhs = [tmp isKindOfClass:[EOQualifierVariable class]]
+ ? [NSExpression expressionForVariable:[(EOQualifierVariable *)tmp key]]
+ : [NSExpression expressionForKeyPath:tmp];
+
+ return [self predicateWithLeftExpression:lhs rightExpression:rhs
+ eoSelector:[self selector]];
}
/* CoreData compatibility */
}
- (NSPredicate *)asPredicate {
- NSLog(@"TODO(%s): implement me for class %@!", __PRETTY_FUNCTION__,
- NSStringFromClass([self class]));
- return nil;
+ /*
+ EOKeyValueQualifier has a key/value path expression on the left side
+ and a constant value expression on the right side.
+ */
+ NSExpression *lhs, *rhs;
+ id tmp;
+
+ tmp = [self key];
+ lhs = [tmp isKindOfClass:[EOQualifierVariable class]]
+ ? [NSExpression expressionForVariable:[(EOQualifierVariable *)tmp key]]
+ : [NSExpression expressionForKeyPath:tmp];
+
+ tmp = [self value];
+ rhs = [tmp isKindOfClass:[EOQualifierVariable class]]
+ ? [NSExpression expressionForVariable:[(EOQualifierVariable *)tmp key]]
+ : [NSExpression expressionForConstantValue:tmp];
+
+ return [self predicateWithLeftExpression:lhs rightExpression:rhs
+ eoSelector:[self selector]];
}
/* CoreData compatibility */
+ (SEL)eoSelectorForForComparisonPredicate:(NSComparisonPredicate *)_p;
+ (NSPredicateOperatorType)predicateOperatorTypeForEOSelector:(SEL)_sel;
+- (NSPredicate *)predicateWithLeftExpression:(NSExpression *)_lhs
+ rightExpression:(NSExpression *)_rhs
+ eoSelector:(SEL)_selector;
+
/* CoreData compatibility */
+ (NSPredicate *)andPredicateWithSubpredicates:(NSArray *)_sub;
return sel;
}
+- (NSPredicate *)predicateWithLeftExpression:(NSExpression *)_lhs
+ rightExpression:(NSExpression *)_rhs
+ eoSelector:(SEL)_selector
+{
+ // TODO: create non-custom predicate if possible
+ NSComparisonPredicateModifier pmod;
+ NSPredicateOperatorType ptype;
+ unsigned popts;
+
+ if (_selector == NULL) {
+ NSLog(@"ERROR(0x%08X/%@): missing selector for predicate construction: %@",
+ self, NSStringFromClass([self class]), self);
+ return nil;
+ }
+
+ ptype = [EOQualifier predicateOperatorTypeForEOSelector:_selector];
+
+ if (ptype == NSCustomSelectorPredicateOperatorType) {
+ return [NSComparisonPredicate predicateWithLeftExpression:_lhs
+ rightExpression:_rhs
+ customSelector:_selector];
+ }
+
+ pmod = NSDirectPredicateModifier;
+ popts = 0;
+
+ if (SEL_EQ(_selector, EOQualifierOperatorCaseInsensitiveLike))
+ popts = NSCaseInsensitivePredicateOption;
+
+ return [NSComparisonPredicate predicateWithLeftExpression:_lhs
+ rightExpression:_rhs
+ modifier:pmod type:ptype options:popts];
+}
+
+ (EOQualifier *)qualifierForPredicate:(NSPredicate *)_predicate {
if (_predicate == nil)
return nil;
[_predicate asPredicate]];
}
+- (NSPredicate *)predicateWithSubstitutionVariables:(NSDictionary *)_vars {
+ return [[self asPredicate] predicateWithSubstitutionVariables:_vars];
+}
+
+- (NSString *)predicateFormat {
+ return [[self asPredicate] predicateFormat];
+}
+
@end /* EOQualifier(CoreData) */
# version file
-SUBMINOR_VERSION:=9
+SUBMINOR_VERSION:=10