From 5c20fc7f91fbfb735423f065119d57160c757a10 Mon Sep 17 00:00:00 2001 From: helge Date: Thu, 4 Aug 2005 02:15:25 +0000 Subject: [PATCH] added key/value archiving to NSExpression git-svn-id: http://svn.opengroupware.org/SOPE/trunk@967 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-core/EOCoreData/ChangeLog | 2 + sope-core/EOCoreData/NSExpression+EO.h | 2 +- sope-core/EOCoreData/NSExpression+EO.m | 51 ++++++++++++++++++++++++++ sope-core/EOCoreData/Version | 2 +- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/sope-core/EOCoreData/ChangeLog b/sope-core/EOCoreData/ChangeLog index 1bd10581..b91af797 100644 --- a/sope-core/EOCoreData/ChangeLog +++ b/sope-core/EOCoreData/ChangeLog @@ -1,5 +1,7 @@ 2005-08-04 Helge Hess + * NSExpression+EO.m: added EOKeyValueArchiving (v4.5.4) + * NSPredicate+EO.m: added EOKeyValueArchiving to NSComparisonPredicate (v4.5.3) diff --git a/sope-core/EOCoreData/NSExpression+EO.h b/sope-core/EOCoreData/NSExpression+EO.h index 8cf46283..3e87478b 100644 --- a/sope-core/EOCoreData/NSExpression+EO.h +++ b/sope-core/EOCoreData/NSExpression+EO.h @@ -33,7 +33,7 @@ @class NSExpression; @class EOQualifier; -@interface NSExpression(EO) +@interface NSExpression(EOCoreData) < EOKeyValueArchiving > - (NSPredicate *)asPredicate; - (NSExpression *)asExpression; diff --git a/sope-core/EOCoreData/NSExpression+EO.m b/sope-core/EOCoreData/NSExpression+EO.m index 3f7b3b40..ada802c6 100644 --- a/sope-core/EOCoreData/NSExpression+EO.m +++ b/sope-core/EOCoreData/NSExpression+EO.m @@ -31,4 +31,55 @@ return self; } +/* key/value archiving */ + +- (id)initWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_unarchiver { + id tmp; + + [self release]; self = nil; + + if ((tmp = [_unarchiver decodeObjectForKey:@"constantValue"]) != nil) + return [[NSExpression expressionForConstantValue:tmp] retain]; + + if ((tmp = [_unarchiver decodeObjectForKey:@"keyPath"]) != nil) + return [[NSExpression expressionForKeyPath:tmp] retain]; + + if ((tmp = [_unarchiver decodeObjectForKey:@"variable"]) != nil) + return [[NSExpression expressionForVariable:tmp] retain]; + + if ((tmp = [_unarchiver decodeObjectForKey:@"function"]) != nil) { + NSArray *args; + + args = [_unarchiver decodeObjectForKey:@"arguments"]; + return [[NSExpression expressionForFunction:tmp arguments:args] retain]; + } + + return [[NSExpression expressionForEvaluatedObject] retain]; +} + +- (void)encodeWithKeyValueArchiver:(EOKeyValueArchiver *)_archiver { + switch ([self expressionType]) { + case NSConstantValueExpressionType: + [_archiver encodeObject:[self constantValue] forKey:@"constantValue"]; + return; + case NSEvaluatedObjectExpressionType: + /* encode no marker */ + return; + case NSVariableExpressionType: + [_archiver encodeObject:[self variable] forKey:@"variable"]; + return; + case NSKeyPathExpressionType: + [_archiver encodeObject:[self keyPath] forKey:@"keyPath"]; + return; + case NSFunctionExpressionType: + [_archiver encodeObject:[self function] forKey:@"function"]; + [_archiver encodeObject:[self arguments] forKey:@"arguments"]; + return; + + default: + NSLog(@"WARNING(%s): could not encode NSExpression: %@!", + __PRETTY_FUNCTION__, self); + } +} + @end /* NSPredicate(EOCoreData) */ diff --git a/sope-core/EOCoreData/Version b/sope-core/EOCoreData/Version index 81d0f5a4..9d93031b 100644 --- a/sope-core/EOCoreData/Version +++ b/sope-core/EOCoreData/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=3 +SUBMINOR_VERSION:=4 -- 2.39.5