2000-11-27 22:26:08 +00:00
|
|
|
|
2002-02-25 07:05:58 +00:00
|
|
|
/* Interface for NSKeyValueCoding for GNUStep
|
2000-11-27 22:26:08 +00:00
|
|
|
Copyright (C) 2000 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
|
|
|
Date: 2000
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
2006-03-08 11:28:59 +00:00
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02111 USA.
|
2000-11-27 22:26:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __NSKeyValueCoding_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
#define __NSKeyValueCoding_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
|
|
|
|
#include <Foundation/NSObject.h>
|
|
|
|
|
|
|
|
@class NSArray;
|
2005-03-02 11:46:21 +00:00
|
|
|
@class NSMutableArray;
|
2000-11-27 22:26:08 +00:00
|
|
|
@class NSDictionary;
|
2005-03-02 11:46:21 +00:00
|
|
|
@class NSError;
|
2000-11-27 22:26:08 +00:00
|
|
|
@class NSString;
|
|
|
|
|
2002-02-12 12:37:12 +00:00
|
|
|
#ifndef STRICT_OPENSTEP
|
2000-11-27 22:26:08 +00:00
|
|
|
|
2004-09-19 23:24:36 +00:00
|
|
|
/** An exception for an unknown key in [NSObject(NSKeyValueCoding)]. */
|
2005-06-22 09:09:40 +00:00
|
|
|
GS_EXPORT NSString* const NSUndefinedKeyException;
|
2003-03-23 07:06:27 +00:00
|
|
|
|
2004-09-19 23:24:36 +00:00
|
|
|
/**
|
|
|
|
* <p>This describes an informal protocol for <em>key-value coding</em>, a
|
|
|
|
* mechanism whereby the fields of an object may be accessed and set using
|
|
|
|
* generic methods in conjunction with string keys rather than field-specific
|
|
|
|
* methods. Key-based access loses compile-time validity checking, but can be
|
|
|
|
* convenient in certain kinds of situations.</p>
|
|
|
|
*
|
|
|
|
* <p>The basic methods are implemented as a category of the [NSObject] class,
|
|
|
|
* but other classes override those default implementations to perform more
|
|
|
|
* specific operations.</p>
|
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
@interface NSObject (NSKeyValueCoding)
|
|
|
|
|
2004-09-19 23:24:36 +00:00
|
|
|
/**
|
|
|
|
* Controls whether the NSKeyValueCoding methods may attempt to
|
|
|
|
* access instance variables directly.
|
|
|
|
* NSObject's implementation returns YES.
|
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
+ (BOOL) accessInstanceVariablesDirectly;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Controls whether -storedValueForKey: and -takeStoredValue:forKey: may use
|
|
|
|
* the stored accessor mechanism. If not the calls get redirected to
|
|
|
|
* -valueForKey: and -takeValue:forKey: effectively changing the search order
|
|
|
|
* of private/public accessor methods and instance variables.
|
|
|
|
* NSObject's implementation returns YES.
|
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
+ (BOOL) useStoredAccessor;
|
|
|
|
|
2004-09-19 23:24:36 +00:00
|
|
|
/**
|
2005-03-02 11:46:21 +00:00
|
|
|
* 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.
|
2004-09-19 23:24:36 +00:00
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
- (id) handleQueryWithUnboundKey: (NSString*)aKey;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
|
|
|
/**
|
2005-03-02 11:46:21 +00:00
|
|
|
* 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
|
2005-11-06 13:53:40 +00:00
|
|
|
* -setNilValueForKey: is called if a nil value is supplied).
|
2005-03-02 11:46:21 +00:00
|
|
|
* Tries to use a standard accessor of the form setKey: where 'Key' is the
|
2005-11-06 13:53:40 +00:00
|
|
|
* supplied argument with the first letter converted to uppercase.<br />
|
2005-03-02 11:46:21 +00:00
|
|
|
* 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
|
2005-11-06 13:53:40 +00:00
|
|
|
* and raises NSInvalidArgumentException if the accessor method doesn't take
|
2005-03-02 11:46:21 +00:00
|
|
|
* 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.
|
2005-11-06 13:53:40 +00:00
|
|
|
* The key components are delimited by '.'.
|
2005-03-02 11:46:21 +00:00
|
|
|
* 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
|
2004-09-19 23:24:36 +00:00
|
|
|
* a key which can't be associated with an accessor method or instance
|
|
|
|
* variable. Subclasses may override this method to add custom handling.
|
2005-06-22 09:09:40 +00:00
|
|
|
* NSObject raises an NSUndefinedKeyException, with a userInfo dictionary
|
2004-09-19 23:24:36 +00:00
|
|
|
* containing NSTargetObjectUserInfoKey with the receiver an
|
2005-03-02 11:46:21 +00:00
|
|
|
* NSUnknownUserInfoKey with the supplied key entries.<br />
|
|
|
|
* Called when the key passed to -setValue:forKey: cannot be used.
|
2004-09-19 23:24:36 +00:00
|
|
|
*/
|
2005-03-02 11:46:21 +00:00
|
|
|
- (void) setValue: (id)anObject forUndefinedKey: (NSString*)aKey;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uses -setValue:forKey: to place the values from aDictionary in the
|
|
|
|
* receiver.
|
|
|
|
*/
|
|
|
|
- (void) setValuesForKeysWithDictionary: (NSDictionary*)aDictionary;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the value associated with the supplied key as an object.
|
|
|
|
* Scalar attributes are converted to corresponding objects.
|
|
|
|
* Uses private accessors in favor of the public ones, if the receiver's
|
|
|
|
* class allows +useStoredAccessor. Otherwise this method invokes
|
|
|
|
* -valueForKey:.
|
|
|
|
* The search order is:<br/>
|
|
|
|
* Private accessor methods:
|
|
|
|
* <list>
|
|
|
|
* <item>_getKey</item>
|
|
|
|
* <item>_key</item>
|
|
|
|
* </list>
|
|
|
|
* If the receiver's class allows +accessInstanceVariablesDirectly
|
|
|
|
* it continues with instance variables:
|
|
|
|
* <list>
|
|
|
|
* <item>_key</item>
|
|
|
|
* <item>key</item>
|
|
|
|
* </list>
|
|
|
|
* Public accessor methods:
|
|
|
|
* <list>
|
|
|
|
* <item>getKey</item>
|
|
|
|
* <item>key</item>
|
|
|
|
* </list>
|
2005-03-02 11:46:21 +00:00
|
|
|
* Invokes -handleTakeValue:forUnboundKey: if no accessor mechanism can be
|
2005-11-06 13:53:40 +00:00
|
|
|
* found and raises NSInvalidArgumentException if the accessor method takes
|
2004-09-19 23:24:36 +00:00
|
|
|
* takes any arguments or the type is unsupported (e.g. structs).
|
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
- (id) storedValueForKey: (NSString*)aKey;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the value associated with the supplied in the receiver.
|
|
|
|
* The object is converted to the scalar attribute where applicable.
|
|
|
|
* Uses the private accessors in favor of the public ones, if the
|
|
|
|
* receiver's class allows +useStoredAccessor .
|
|
|
|
* Otherwise this method invokes -takeValue:forKey: .
|
|
|
|
* The search order is:<br/>
|
|
|
|
* Private accessor methods:
|
|
|
|
* <list>
|
|
|
|
* <item>_setKey:</item>
|
|
|
|
* </list>
|
|
|
|
* If the receiver's class allows accessInstanceVariablesDirectly
|
|
|
|
* it continues with instance variables:
|
|
|
|
* <list>
|
|
|
|
* <item>_key</item>
|
|
|
|
* <item>key</item>
|
|
|
|
* </list>
|
|
|
|
* Public accessor methods:
|
|
|
|
* <list>
|
|
|
|
* <item>setKey:</item>
|
|
|
|
* </list>
|
|
|
|
* Invokes -handleTakeValue:forUnboundKey:
|
|
|
|
* if no accessor mechanism can be found
|
2005-11-06 13:53:40 +00:00
|
|
|
* and raises NSInvalidArgumentException if the accessor method doesn't take
|
2004-09-19 23:24:36 +00:00
|
|
|
* 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: .
|
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
- (void) takeStoredValue: (id)anObject forKey: (NSString*)aKey;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterates over the dictionary invoking -takeStoredValue:forKey:
|
|
|
|
* on the receiver for each key-value pair, converting NSNull to nil.
|
|
|
|
*/
|
2003-02-19 14:42:07 +00:00
|
|
|
- (void) takeStoredValuesFromDictionary: (NSDictionary*)aDictionary;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the value if the attribute associated with the key in the receiver.
|
|
|
|
* The object is converted to a scalar attribute where applicable.
|
|
|
|
* Uses the public accessors in favor of the private ones.
|
|
|
|
* The search order is:<br/>
|
|
|
|
* Accessor methods:
|
|
|
|
* <list>
|
|
|
|
* <item>setKey:</item>
|
|
|
|
* <item>_setKey:</item>
|
|
|
|
* </list>
|
|
|
|
* If the receiver's class allows +accessInstanceVariablesDirectly
|
|
|
|
* it continues with instance variables:
|
|
|
|
* <list>
|
|
|
|
* <item>key</item>
|
|
|
|
* <item>_key</item>
|
|
|
|
* </list>
|
|
|
|
* Invokes -handleTakeValue:forUnboundKey:
|
|
|
|
* if no accessor mechanism can be found
|
2005-11-06 13:53:40 +00:00
|
|
|
* and raises NSInvalidArgumentException if the accessor method doesn't take
|
2004-09-19 23:24:36 +00:00
|
|
|
* 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
|
2005-03-02 11:46:21 +00:00
|
|
|
* -unableToSetNilForKey: .<br />
|
|
|
|
* Deprecated ... use -setValue:forKey: instead.
|
2004-09-19 23:24:36 +00:00
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
- (void) takeValue: (id)anObject forKey: (NSString*)aKey;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the object returned by invoking -valueForKey:
|
|
|
|
* on the receiver with the first key component supplied by the key path.
|
|
|
|
* Then invokes -takeValue:forKeyPath: recursively on the
|
|
|
|
* returned object with rest of the key path.
|
2005-11-06 13:53:40 +00:00
|
|
|
* The key components are delimited by '.'.
|
2004-09-19 23:24:36 +00:00
|
|
|
* If the key path doesn't contain any '.', this method simply
|
2005-03-02 11:46:21 +00:00
|
|
|
* invokes -takeValue:forKey:.<br />
|
|
|
|
* Deprecated ... use -setValue:forKeyPath: instead.
|
2004-09-19 23:24:36 +00:00
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
- (void) takeValue: (id)anObject forKeyPath: (NSString*)aKey;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterates over the dictionary invoking -takeValue:forKey:
|
2005-03-02 11:46:21 +00:00
|
|
|
* on the receiver for each key-value pair, converting NSNull to nil.<br />
|
|
|
|
* Deprecated ... use -setValuesForKeysWithDictionary: instead.
|
2004-09-19 23:24:36 +00:00
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
- (void) takeValuesFromDictionary: (NSDictionary*)aDictionary;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
|
|
|
/**
|
2005-03-02 11:46:21 +00:00
|
|
|
* Deprecated ... use -setNilValueForKey: instead.
|
2004-09-19 23:24:36 +00:00
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
- (void) unableToSetNilForKey: (NSString*)aKey;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
2005-03-02 11:46:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a boolean indicating whether the object pointed to by aValue
|
2005-11-06 13:53:40 +00:00
|
|
|
* is valid for setting as an attribute of the receiver using the name
|
2005-03-02 11:46:21 +00:00
|
|
|
* 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;
|
|
|
|
|
2004-09-19 23:24:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the value associated with the supplied key as an object.
|
2005-03-02 11:46:21 +00:00
|
|
|
* Scalar attributes are converted to corresponding objects.<br />
|
2004-09-19 23:24:36 +00:00
|
|
|
* The search order is:<br/>
|
|
|
|
* Accessor methods:
|
|
|
|
* <list>
|
|
|
|
* <item>getKey</item>
|
|
|
|
* <item>key</item>
|
2005-03-02 11:46:21 +00:00
|
|
|
* </list>
|
|
|
|
* If the receiver's class allows +accessInstanceVariablesDirectly
|
|
|
|
* it continues with private accessors:
|
|
|
|
* <list>
|
2004-09-19 23:24:36 +00:00
|
|
|
* <item>_getKey</item>
|
|
|
|
* <item>_key</item>
|
|
|
|
* </list>
|
2005-03-02 11:46:21 +00:00
|
|
|
* and then instance variables:
|
2004-09-19 23:24:36 +00:00
|
|
|
* <list>
|
|
|
|
* <item>key</item>
|
|
|
|
* <item>_key</item>
|
|
|
|
* </list>
|
2005-03-02 11:46:21 +00:00
|
|
|
* Invokes -setValue:forUndefinedKey:
|
2004-09-19 23:24:36 +00:00
|
|
|
* if no accessor mechanism can be found
|
2005-11-06 13:53:40 +00:00
|
|
|
* and raises NSInvalidArgumentException if the accessor method takes
|
2004-09-19 23:24:36 +00:00
|
|
|
* any arguments or the type is unsupported (e.g. structs).
|
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
- (id) valueForKey: (NSString*)aKey;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
|
|
|
/**
|
2005-11-06 13:53:40 +00:00
|
|
|
* Returns the object returned by invoking -valueForKeyPath:
|
2004-09-19 23:24:36 +00:00
|
|
|
* recursively on the object returned by invoking -valueForKey:
|
|
|
|
* on the receiver with the first key component supplied by the key path.
|
2005-11-06 13:53:40 +00:00
|
|
|
* The key components are delimited by '.'.
|
2004-09-19 23:24:36 +00:00
|
|
|
* If the key path doesn't contain any '.', this method simply
|
|
|
|
* invokes -valueForKey: .
|
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
- (id) valueForKeyPath: (NSString*)aKey;
|
2004-09-19 23:24:36 +00:00
|
|
|
|
2005-03-02 11:46:21 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2005-06-22 09:09:40 +00:00
|
|
|
* raises an NSUndefinedKeyException, with a userInfo dictionary containing
|
2005-03-02 11:46:21 +00:00
|
|
|
* NSTargetObjectUserInfoKey with the receiver an NSUnknownUserInfoKey with
|
|
|
|
* the supplied key entries.<br />
|
|
|
|
*/
|
|
|
|
- (id) valueForUndefinedKey: (NSString*)aKey;
|
|
|
|
|
2004-09-19 23:24:36 +00:00
|
|
|
/**
|
|
|
|
* Iterates over the array sending the receiver -valueForKey:
|
|
|
|
* for each object in the array and inserting the result in a dictionary.
|
|
|
|
* All nil values returned by -valueForKey: are replaced by the
|
|
|
|
* NSNull instance in the dictionary.
|
|
|
|
*/
|
2000-11-27 22:26:08 +00:00
|
|
|
- (NSDictionary*) valuesForKeys: (NSArray*)keys;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
#endif
|
2002-02-12 12:37:12 +00:00
|
|
|
#endif
|
2000-11-27 22:26:08 +00:00
|
|
|
|