Files
cappuccino/Foundation/CPPredicate/CPExpression_aggregate.j
T
cacaodev ca289e081e CPPredicate parsing support:
"($)path.($)variable"
 "SUBQUERY(collection, $x,$x = 2)"
 "sum:(arg1, ...)"
 "FUNCTION(target, selector, arg1, ...)
 "object[expression]"
 "set UNION|INTERSECT|MINUS otherset"
Fixed a bug where CPExpression_set was evaluating to an expression instead of a set.
Replaced parsing exceptions with a generic function indicating where it failed.
2010-11-07 17:56:22 +01:00

93 lines
2.0 KiB
Plaintext

@import "CPExpression.j"
@import "CPArray.j"
@import "CPString.j"
@implementation CPExpression_aggregate : CPExpression
{
CPArray _aggregate;
}
- (id)initWithAggregate:(CPArray)collection
{
[super initWithExpressionType:CPAggregateExpressionType];
_aggregate = collection;
return self;
}
- (BOOL)isEqual:(id)object
{
if (self == object)
return YES;
if (object.isa != self.isa || [object expressionType] != [self expressionType] || ![[object collection] isEqual:[self collection]])
return NO;
return YES;
}
- (id)collection
{
return _aggregate;
}
- (id)expressionValueWithObject:(id)object context:(CPDictionary)context
{
var eval_array = [CPArray array],
collection = [_aggregate objectEnumerator],
exp;
while (exp = [collection nextObject])
{
var eval = [exp expressionValueWithObject:object context:context];
[eval_array addObject:eval];
}
return eval_array;
}
- (CPString)description
{
var i,
count = [_aggregate count],
result = "{";
for (i = 0; i < count; i++)
result = result + [CPString stringWithFormat:@"%s%s", [[_aggregate objectAtIndex:i] description], (i + 1 < count) ? @", " : @""];
result = result + "}";
return result;
}
- (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables
{
var subst_array = [CPArray array],
count = [_aggregate count],
i;
for (i = 0; i < count; i++)
[subst_array addObject:[[_aggregate objectAtIndex:i] _expressionWithSubstitutionVariables:variables]];
return [CPExpression expressionForAggregate:subst_array];
}
@end
var CPCollectionKey = @"CPCollection";
@implementation CPExpression_aggregate (CPCoding)
- (id)initWithCoder:(CPCoder)coder
{
var collection = [coder decodeObjectForKey:CPCollectionKey];
return [self initWithAggregate:collection];
}
- (void)encodeWithCoder:(CPCoder)coder
{
[coder encodeObject:_aggregate forKey:CPCollectionKey];
}
@end