KVC updates

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20828 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-03-02 11:46:21 +00:00
parent c5b59c788c
commit 826de16ee7
6 changed files with 453 additions and 88 deletions

View file

@ -28,7 +28,9 @@
#include <Foundation/NSObject.h>
@class NSArray;
@class NSMutableArray;
@class NSDictionary;
@class NSError;
@class NSString;
#ifndef STRICT_OPENSTEP
@ -66,24 +68,92 @@ GS_EXPORT NSString* const NSUnknownKeyException;
+ (BOOL) useStoredAccessor;
/**
* Invoked when -valueForKey: / -storedValueForKey: are called with a key,
* which can't be associated with an accessor method or instance variable.
* Subclasses may override this method to add custom handling. NSObject
* raises an NSUnknownKeyException, with a userInfo dictionary containing
* NSTargetObjectUserInfoKey with the receiver an NSUnknownUserInfoKey with
* the supplied key entries.
* Returns a dictionary built from values obtained for the specified keys.<br />
* By default this is derived by calling -valueForKey: for each key.
* Any nil values obtained are represented by an [NSNull] instance.
*/
- (NSDictionary*) dictionaryWithValuesForKeys: (NSArray*)keys;
/**
* Deprecated ... use -valueForUndefinedKey: instead.
*/
- (id) handleQueryWithUnboundKey: (NSString*)aKey;
/**
* Invoked when -takeValue:forKey: / -takeStoredValue:forKey: are called with
* Deprecated, use -setValue:forUndefinedKey: instead.
*/
- (void) handleTakeValue: (id)anObject forUnboundKey: (NSString*)aKey;
/**
* <strong>Not implemented</strong> ... I don't know what this method
* is good for ... do we need to copy MacOS-X and implement it?
*/
- (NSMutableArray*) mutableArrayValueForKey: (NSString*)aKey;
/**
* <strong>Not implemented</strong> ... I don't know what this method
* is good for ... do we need to copy MacOS-X and implement it?
*/
- (NSMutableArray*) mutableArrayValueForKeyPath: (NSString*)aKey;
/**
* This method is invoked by the NSKeyValueCoding mechanism when an attempt
* is made to set an null value for a scalar attribute. This implementation
* raises an NSInvalidArgument exception. Subclasses my override this method
* to do custom handling. (E.g. setting the value to the equivalent of 0.)
*/
- (void) setNilValueForKey: (NSString*)aKey;
/**
* Sets the value if the attribute associated with the key in the receiver.
* The object is converted to a scalar attribute where applicable (and
* -setNilValueForKey: is caalled if a nil value is supplied).
* Tries to use a standard accessor of the form setKey: where 'Key' is the
* supplied argument with the first letter convertyed to uppercase.<br />
* If the receiver's class allows +accessInstanceVariablesDirectly
* it continues with instance variables:
* <list>
* <item>_key</item>
* <item>_isKey</item>
* <item>key</item>
* <item>isKey</item>
* </list>
* Invokes -setValue:forUndefinedKey: if no accessor mechanism can be found
* and raises NSInvalidArgumentException if the accesor method doesn't take
* exactly one argument or the type is unsupported (e.g. structs).
* If the receiver expects a scalar value and the value supplied
* is the NSNull instance or nil, this method invokes
* -setNilValueForKey: .
*/
- (void) setValue: (id)anObject forKey: (NSString*)aKey;
/**
* Retrieves the object returned by invoking -valueForKey:
* on the receiver with the first key component supplied by the key path.
* Then invokes -setValue:forKeyPath: recursively on the
* returned object with rest of the key path.
* The key components are delimated by '.'.
* If the key path doesn't contain any '.', this method simply
* invokes -setValue:forKey:.
*/
- (void) setValue: (id)anObject forKeyPath: (NSString*)aKey;
/**
* Invoked when -setValue:forKey: / -takeStoredValue:forKey: are called with
* a key which can't be associated with an accessor method or instance
* variable. Subclasses may override this method to add custom handling.
* NSObject raises an NSUnknownKeyException, with a userInfo dictionary
* containing NSTargetObjectUserInfoKey with the receiver an
* NSUnknownUserInfoKey with the supplied key entries.
* NSUnknownUserInfoKey with the supplied key entries.<br />
* Called when the key passed to -setValue:forKey: cannot be used.
*/
- (void) handleTakeValue: (id)anObject forUnboundKey: (NSString*)aKey;
- (void) setValue: (id)anObject forUndefinedKey: (NSString*)aKey;
/**
* Uses -setValue:forKey: to place the values from aDictionary in the
* receiver.
*/
- (void) setValuesForKeysWithDictionary: (NSDictionary*)aDictionary;
/**
* Returns the value associated with the supplied key as an object.
@ -108,7 +178,7 @@ GS_EXPORT NSString* const NSUnknownKeyException;
* <item>getKey</item>
* <item>key</item>
* </list>
* Invokes -handleQueryWithUnboundKey: if no accessor mechanism can be
* Invokes -handleTakeValue:forUnboundKey: if no accessor mechanism can be
* found and raises NSInvalidArgumentException if the accesor method takes
* takes any arguments or the type is unsupported (e.g. structs).
*/
@ -173,7 +243,8 @@ GS_EXPORT NSString* const NSUnknownKeyException;
* exactly one argument or the type is unsupported (e.g. structs).
* If the receiver expects a scalar value and the value supplied
* is the NSNull instance or nil, this method invokes
* -unableToSetNilForKey: .
* -unableToSetNilForKey: .<br />
* Deprecated ... use -setValue:forKey: instead.
*/
- (void) takeValue: (id)anObject forKey: (NSString*)aKey;
@ -184,44 +255,67 @@ GS_EXPORT NSString* const NSUnknownKeyException;
* returned object with rest of the key path.
* The key components are delimated by '.'.
* If the key path doesn't contain any '.', this method simply
* invokes -takeValue:forKey:.
* invokes -takeValue:forKey:.<br />
* Deprecated ... use -setValue:forKeyPath: instead.
*/
- (void) takeValue: (id)anObject forKeyPath: (NSString*)aKey;
/**
* Iterates over the dictionary invoking -takeValue:forKey:
* on the receiver for each key-value pair, converting NSNull to nil.
* on the receiver for each key-value pair, converting NSNull to nil.<br />
* Deprecated ... use -setValuesForKeysWithDictionary: instead.
*/
- (void) takeValuesFromDictionary: (NSDictionary*)aDictionary;
/**
* This method is invoked by the NSKeyValueCoding mechanism when an attempt
* is made to set an null value for a scalar attribute. This implementation
* raises an NSInvalidArgument exception. Subclasses my override this method
* to do custom handling. (E.g. setting the value to the equivalent of 0.)
* Deprecated ... use -setNilValueForKey: instead.
*/
- (void) unableToSetNilForKey: (NSString*)aKey;
/**
* Returns a boolean indicating whether the object pointed to by aValue
* is valid for settting as an attribute of the receiver using the name
* aKey. On success (YES response) it may return a new value to be used
* in aValue. On failure (NO response) it may return an error in anError.<br />
* The method works by calling a method of the receiver whose name is of
* the form validateKey:error: if the receiver has implemented such a
* method, otherwise it simply returns YES.
*/
- (BOOL) validateValue: (id*)aValue
forKey: (NSString*)aKey
error: (NSError**)anError;
/**
* Returns the result of calling -validateValue:forKey:error: on the receiver
* using aPath to determine the key value in the same manner as the
* -valueForKeyPath: method.
*/
- (BOOL) validateValue: (id*)aValue
forKeyPath: (NSString*)aKey
error: (NSError**)anError;
/**
* Returns the value associated with the supplied key as an object.
* Scalar attributes are converted to corresponding objects.
* The value-NSKeyValueCoding use the public accessors
* in favor of the private ones.
* Scalar attributes are converted to corresponding objects.<br />
* The search order is:<br/>
* Accessor methods:
* <list>
* <item>getKey</item>
* <item>key</item>
* </list>
* If the receiver's class allows +accessInstanceVariablesDirectly
* it continues with private accessors:
* <list>
* <item>_getKey</item>
* <item>_key</item>
* </list>
* If the receiver's class allows +accessInstanceVariablesDirectly
* it continues with instance variables:
* and then instance variables:
* <list>
* <item>key</item>
* <item>_key</item>
* </list>
* Invokes -handleQueryWithUnboundKey:
* Invokes -setValue:forUndefinedKey:
* if no accessor mechanism can be found
* and raises NSInvalidArgumentException if the accesor method takes
* any arguments or the type is unsupported (e.g. structs).
@ -238,6 +332,16 @@ GS_EXPORT NSString* const NSUnknownKeyException;
*/
- (id) valueForKeyPath: (NSString*)aKey;
/**
* Invoked when -valueForKey: / -storedValueForKey: are called with a key,
* which can't be associated with an accessor method or instance variable.
* Subclasses may override this method to add custom handling. NSObject
* raises an NSUnknownKeyException, with a userInfo dictionary containing
* NSTargetObjectUserInfoKey with the receiver an NSUnknownUserInfoKey with
* the supplied key entries.<br />
*/
- (id) valueForUndefinedKey: (NSString*)aKey;
/**
* Iterates over the array sending the receiver -valueForKey:
* for each object in the array and inserting the result in a dictionary.