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 #import <Foundation/NSExpression.h>
25 @implementation NSExpression(EOCoreData)
27 - (NSPredicate *)asPredicate {
30 - (NSExpression *)asExpression {
34 /* key/value archiving */
36 - (id)initWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_unarchiver {
39 [self release]; self = nil;
41 if ((tmp = [_unarchiver decodeObjectForKey:@"constantValue"]) != nil)
42 return [[NSExpression expressionForConstantValue:tmp] retain];
44 if ((tmp = [_unarchiver decodeObjectForKey:@"keyPath"]) != nil)
45 return [[NSExpression expressionForKeyPath:tmp] retain];
47 if ((tmp = [_unarchiver decodeObjectForKey:@"variable"]) != nil)
48 return [[NSExpression expressionForVariable:tmp] retain];
50 if ((tmp = [_unarchiver decodeObjectForKey:@"function"]) != nil) {
53 args = [_unarchiver decodeObjectForKey:@"arguments"];
54 return [[NSExpression expressionForFunction:tmp arguments:args] retain];
57 return [[NSExpression expressionForEvaluatedObject] retain];
60 - (void)encodeWithKeyValueArchiver:(EOKeyValueArchiver *)_archiver {
61 switch ([self expressionType]) {
62 case NSConstantValueExpressionType:
63 [_archiver encodeObject:[self constantValue] forKey:@"constantValue"];
65 case NSEvaluatedObjectExpressionType:
66 /* encode no marker */
68 case NSVariableExpressionType:
69 [_archiver encodeObject:[self variable] forKey:@"variable"];
71 case NSKeyPathExpressionType:
72 [_archiver encodeObject:[self keyPath] forKey:@"keyPath"];
74 case NSFunctionExpressionType:
75 [_archiver encodeObject:[self function] forKey:@"function"];
76 [_archiver encodeObject:[self arguments] forKey:@"arguments"];
80 NSLog(@"WARNING(%s): could not encode NSExpression: %@!",
81 __PRETTY_FUNCTION__, self);
85 @end /* NSPredicate(EOCoreData) */