26 @
typedef CPCompoundPredicateType
38 CPCompoundPredicateType _type;
48 - (id)initWithType:(CPCompoundPredicateType)type subpredicates:(CPArray)predicates
55 _predicates = predicates;
66 + (CPPredicate)notPredicateWithSubpredicate:(CPPredicate)predicate
68 return [[
self alloc] initWithType:CPNotPredicateType subpredicates:[CPArray arrayWithObject:predicate]];
76 + (CPPredicate)andPredicateWithSubpredicates:(CPArray)subpredicates
78 return [[
self alloc] initWithType:CPAndPredicateType subpredicates:subpredicates];
86 + (CPPredicate)orPredicateWithSubpredicates:(CPArray)predicates
88 return [[
self alloc] initWithType:CPOrPredicateType subpredicates:predicates];
96 - (CPCompoundPredicateType)compoundPredicateType
105 - (CPArray)subpredicates
110 - (CPPredicate)predicateWithSubstitutionVariables:(
CPDictionary)variables
112 var subp = [CPArray array],
113 count = [subp count],
116 for (; i < count; i++)
118 var p = [subp objectAtIndex:i],
119 sp = [p predicateWithSubstitutionVariables:variables];
130 args = [CPArray array],
131 count = [_predicates count],
135 return @"TRUEPREDICATE";
137 for (; i < count; i++)
139 var subpredicate = [_predicates objectAtIndex:i],
140 precedence = [subpredicate predicateFormat];
142 if ([subpredicate isKindOfClass:[
CPCompoundPredicate class]] && [[subpredicate subpredicates] count]> 1 && [subpredicate compoundPredicateType] != _type)
145 if (precedence != nil)
146 [args addObject:precedence];
155 var count = [args count];
156 for (var j = 1; j < count; j++)
157 result +=
" AND " + [args objectAtIndex:j];
161 var count = [args count];
162 for (var j = 1; j < count; j++)
163 result +=
" OR " + [args objectAtIndex:j];
170 - (BOOL)evaluateWithObject:(
id)object
175 - (BOOL)evaluateWithObject:(
id)object substitutionVariables:(
CPDictionary)variables
178 count = [_predicates count],
184 for (; i < count; i++)
186 var predicate = [_predicates objectAtIndex:i];
190 case CPNotPredicateType:
return ![predicate evaluateWithObject:object substitutionVariables:variables];
193 result = [predicate evaluateWithObject:object substitutionVariables:variables];
195 result = result && [predicate evaluateWithObject:object substitutionVariables:variables];
200 case CPOrPredicateType:
if ([predicate evaluateWithObject:
object substitutionVariables:variables])
211 if (
self === anObject)
214 if (anObject === nil || anObject.isa !==
self.isa || _type !== [anObject compoundPredicateType] || ![_predicates isEqualToArray:[anObject subpredicates]])
229 _predicates = [coder decodeObjectForKey:@"CPCompoundPredicateSubpredicates"];
230 _type = [coder decodeIntForKey:@"CPCompoundPredicateType"];
238 [coder encodeObject:_predicates forKey:@"CPCompoundPredicateSubpredicates"];
239 [coder encodeInt:_type forKey:@"CPCompoundPredicateType"];
A mutable key-value pair collection.
CPCompoundPredicate is a subclass of CPPredicate used to represent logical “gate” operations (AND/O...
An immutable string (collection of characters).
BOOL evaluateWithObject:substitutionVariables:(id object, [substitutionVariables] CPDictionary variables)
Defines methods for use when archiving & restoring (enc/decoding).
id stringWithFormat:(CPString format, [,] ...)