From 47fb20dd9be861c4bec4ed2ad4ed6cf76c50f0ff Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Wed, 27 Feb 2002 09:25:30 +0000 Subject: [PATCH] More KVC fixes git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@12810 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 1 + Headers/gnustep/base/NSDictionary.h | 6 ++++- Source/NSDictionary.m | 41 +++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 07fa7e209..c573598ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ * Source/GSValue.m: attempt to correct encoding. * Source/NSKeyValueCoding.m: Fix termination of method names with nuls from report by Manuel Guesdon. + * Source/NSDictionary.m: Implement MacOS-X compatible KVC behavior. 2002-02-26 Richard Frith-Macdonald diff --git a/Headers/gnustep/base/NSDictionary.h b/Headers/gnustep/base/NSDictionary.h index cde555b27..ad1406665 100644 --- a/Headers/gnustep/base/NSDictionary.h +++ b/Headers/gnustep/base/NSDictionary.h @@ -67,6 +67,7 @@ - (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxiliaryFile; #ifndef STRICT_OPENSTEP +- (id) valueForKey: (NSString*)key; - (BOOL) writeToURL: (NSURL*)url atomically: (BOOL)useAuxiliaryFile; #endif @end @@ -82,7 +83,10 @@ - (void) removeObjectsForKeys: (NSArray*)keyArray; - (void) setObject: (id)anObject forKey: (id)aKey; // Primitive - (void) setDictionary: (NSDictionary*)otherDictionary; - +#ifndef STRICT_OPENSTEP +- (void) takeStoredValue: (id)value forKey: (NSString*)key; +- (void) takeValue: (id)value forKey: (NSString*)key; +#endif @end #ifndef NO_GNUSTEP diff --git a/Source/NSDictionary.m b/Source/NSDictionary.m index a92ca2487..714671163 100644 --- a/Source/NSDictionary.m +++ b/Source/NSDictionary.m @@ -936,6 +936,14 @@ static NSString *indentStrings[] = { } } +/** + * Default implementation for this class is to return the value stored in + * the dictionary under the specified key, or nil if there is no value. + */ +- (id) valueForKey: (NSString*)key +{ + return [self objectForKey: key]; +} @end @implementation NSMutableDictionary @@ -1096,4 +1104,37 @@ static NSString *indentStrings[] = { [self addEntriesFromDictionary: otherDictionary]; } +/** + * Default implementation for this class is equivalent to the + * -setObject:forKey: method unless value is nil, in which case + * it is equivalent to -removeObjectForKey: + */ +- (void) takeStoredValue: (id)value forKey: (NSString*)key +{ + if (value == nil) + { + [self removeObjectForKey: key]; + } + else + { + [self setObject: value forKey: key]; + } +} + +/** + * Default implementation for this class is equivalent to the + * -setObject:forKey: method unless value is nil, in which case + * it is equivalent to -removeObjectForKey: + */ +- (void) takeValue: (id)value forKey: (NSString*)key +{ + if (value == nil) + { + [self removeObjectForKey: key]; + } + else + { + [self setObject: value forKey: key]; + } +} @end