2 Copyright (C) 2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "EOQualifier+CoreData.h"
23 #include "NSPredicate+EO.h"
24 #include "NSExpression+EO.h"
28 CoreData / Foundation EOF
30 NSComparisonPredicate EOKeyValueQualifier / EOKeyComparisonQualifier
31 NSCompoundPredicate EOAndQualifier / EOOrQualifier / EONotQualifier
36 - variable EOQualifierVariable
41 EOQualifierOperatorEqual;
42 EOQualifierOperatorNotEqual;
43 EOQualifierOperatorLessThan;
44 EOQualifierOperatorGreaterThan;
45 EOQualifierOperatorLessThanOrEqualTo;
46 EOQualifierOperatorGreaterThanOrEqualTo;
47 EOQualifierOperatorContains;
48 EOQualifierOperatorLike;
49 EOQualifierOperatorCaseInsensitiveLike;
52 @implementation EOQualifier(CoreData)
54 + (NSPredicateOperatorType)predicateOperatorTypeForEOSelector:(SEL)_sel {
55 if (SEL_EQ(_sel, EOQualifierOperatorEqual))
56 return NSEqualToPredicateOperatorType;
57 if (SEL_EQ(_sel, EOQualifierOperatorNotEqual))
58 return NSNotEqualToPredicateOperatorType;
60 if (SEL_EQ(_sel, EOQualifierOperatorLessThan))
61 return NSLessThanPredicateOperatorType;
62 if (SEL_EQ(_sel, EOQualifierOperatorGreaterThan))
63 return NSGreaterThanPredicateOperatorType;
65 if (SEL_EQ(_sel, EOQualifierOperatorLessThanOrEqualTo))
66 return NSLessThanOrEqualToPredicateOperatorType;
67 if (SEL_EQ(_sel, EOQualifierOperatorGreaterThanOrEqualTo))
68 return NSGreaterThanOrEqualToPredicateOperatorType;
70 if (SEL_EQ(_sel, EOQualifierOperatorContains))
71 return NSInPredicateOperatorType;
73 if (SEL_EQ(_sel, EOQualifierOperatorLike) ||
74 SEL_EQ(_sel, EOQualifierOperatorCaseInsensitiveLike))
75 return NSLikePredicateOperatorType;
77 return NSCustomSelectorPredicateOperatorType;
80 + (SEL)eoSelectorForForComparisonPredicate:(NSComparisonPredicate *)_p {
87 hasOpt = [_p options] != 0 ? YES : NO;
89 // TODO: need to check options
91 switch ([_p predicateOperatorType]) {
92 case NSCustomSelectorPredicateOperatorType:
93 sel = hasOpt ? NULL : [_p customSelector];
96 case NSLessThanPredicateOperatorType:
97 sel = hasOpt ? NULL : EOQualifierOperatorLessThan; break;
98 case NSLessThanOrEqualToPredicateOperatorType:
99 sel = hasOpt ? NULL : EOQualifierOperatorLessThanOrEqualTo; break;
100 case NSGreaterThanPredicateOperatorType:
101 sel = hasOpt ? NULL : EOQualifierOperatorGreaterThan; break;
102 case NSGreaterThanOrEqualToPredicateOperatorType:
103 sel = hasOpt ? NULL : EOQualifierOperatorGreaterThanOrEqualTo; break;
105 case NSEqualToPredicateOperatorType:
106 sel = hasOpt ? NULL : EOQualifierOperatorEqual; break;
107 case NSNotEqualToPredicateOperatorType:
108 sel = hasOpt ? NULL : EOQualifierOperatorNotEqual; break;
110 case NSLikePredicateOperatorType:
111 sel = ([_p options] == NSCaseInsensitivePredicateOption)
112 ? EOQualifierOperatorCaseInsensitiveLike
113 : (hasOpt ? NULL : EOQualifierOperatorLike);
116 case NSInPredicateOperatorType:
117 // TODO: for arrays: containsObject:, for strings: containsString:
118 sel = hasOpt ? NULL : EOQualifierOperatorContains; break;
120 case NSBeginsWithPredicateOperatorType:
121 sel = hasOpt ? NULL : @selector(hasPrefix:); break;
122 case NSEndsWithPredicateOperatorType:
123 sel = hasOpt ? NULL : @selector(hasSuffix:); break;
125 /* unsupported predicates */
126 case NSMatchesPredicateOperatorType:
134 NSLog(@"ERROR(%s): cannot map NSComparisonPredicate to "
135 @"EOQualifier selector: %@",
136 __PRETTY_FUNCTION__, _p);
141 + (EOQualifier *)qualifierForPredicate:(NSPredicate *)_predicate {
142 if (_predicate == nil)
145 if ([_predicate respondsToSelector:@selector(asQualifier)])
146 return [_predicate asQualifier];
148 NSLog(@"ERROR(%s): cannot convert NSPredicate class %@!",
150 NSStringFromClass([self class]));
154 - (EOQualifier *)asQualifier {
158 - (NSPredicate *)asPredicate {
159 NSLog(@"TODO(%s): implement me for class %@!", __PRETTY_FUNCTION__,
160 NSStringFromClass([self class]));
164 - (NSExpression *)asExpression {
169 /* CoreData compatibility */
171 + (NSPredicate *)andPredicateWithSubpredicates:(NSArray *)_sub {
172 return [NSCompoundPredicate andPredicateWithSubpredicates:
173 [_sub valueForKey:@"asPredicate"]];
176 + (NSPredicate *)orPredicateWithSubpredicates:(NSArray *)_sub {
177 return [NSCompoundPredicate orPredicateWithSubpredicates:
178 [_sub valueForKey:@"asPredicate"]];
181 + (NSPredicate *)notPredicateWithSubpredicate:(id)_predicate {
182 return [NSCompoundPredicate notPredicateWithSubpredicate:
183 [_predicate asPredicate]];
186 @end /* EOQualifier(CoreData) */