ObjFW  Check-in [10fbb20fd6]

Overview
Comment:Key Value Coding: Add fallback to isFoo
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 10fbb20fd6e457db23a2892bc4fcec0dbc9c88c7486af3da7679edd824e07604
User & Date: js on 2016-06-05 16:00:07
Other Links: manifest | tags
Context
2016-06-05
16:04
Key Value Coding: Make sure free is always called check-in: 49ed0fa5ec user: js tags: trunk
16:00
Key Value Coding: Add fallback to isFoo check-in: 10fbb20fd6 user: js tags: trunk
15:51
Key Value Coding: Add -[setNilValueForKey:] check-in: 7bb4cae9db user: js tags: trunk
Changes

Modified src/OFObject+KeyValueCoding.m from [08642a6afa] to [f4fafd457a].

44
45
46
47
48
49
50
51




52





















53
54
55
56
57
58
59
@implementation OFObject (KeyValueCoding)
- (id)valueForKey: (OFString*)key
{
	SEL selector = sel_registerName([key UTF8String]);
	const char *typeEncoding = [self typeEncodingForSelector: selector];
	id ret;

	if (typeEncoding == NULL)




		return [self valueForUndefinedKey: key];






















	switch (nextType(&typeEncoding)) {
	case '@':
	case '#':
		ret = [self performSelector: selector];
		break;
#define CASE(encoding, type, method)					  \







|
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
@implementation OFObject (KeyValueCoding)
- (id)valueForKey: (OFString*)key
{
	SEL selector = sel_registerName([key UTF8String]);
	const char *typeEncoding = [self typeEncodingForSelector: selector];
	id ret;

	if (typeEncoding == NULL) {
		size_t keyLength;
		char *name;

		if ((keyLength = [key UTF8StringLength]) < 1)
			return [self valueForUndefinedKey: key];

		if ((name = malloc(keyLength + 3)) == NULL)
			@throw [OFOutOfMemoryException
			    exceptionWithRequestedSize: keyLength + 3];

		memcpy(name, "is", 2);
		memcpy(name + 2, [key UTF8String], keyLength);
		name[keyLength + 2] = '\0';

		name[2] = toupper(name[2]);

		selector = sel_registerName(name);

		free(name);

		typeEncoding = [self typeEncodingForSelector: selector];

		if (typeEncoding == NULL ||
		    *typeEncoding == '@' || *typeEncoding == '#')
			return [self valueForUndefinedKey: key];
	}

	switch (nextType(&typeEncoding)) {
	case '@':
	case '#':
		ret = [self performSelector: selector];
		break;
#define CASE(encoding, type, method)					  \

Modified tests/OFObjectTests.m from [e6767683b4] to [00f82faeb0].

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
	unsigned long long _unsignedLongLongValue;
	float _floatValue;
	double _doubleValue;
}

@property (retain) id objectValue;
@property Class classValue;
@property bool boolValue;
@property char charValue;
@property short shortValue;
@property int intValue;
@property long longValue;
@property long long longLongValue;
@property unsigned char unsignedCharValue;
@property unsigned short unsignedShortValue;







|







52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
	unsigned long long _unsignedLongLongValue;
	float _floatValue;
	double _doubleValue;
}

@property (retain) id objectValue;
@property Class classValue;
@property (getter=isBoolValue) bool boolValue;
@property char charValue;
@property short shortValue;
@property int intValue;
@property long longValue;
@property long long longLongValue;
@property unsigned char unsignedCharValue;
@property unsigned short unsignedShortValue;
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
		   forKey: @"unsignedLongValue"]) &&
	    R([m setValue: [OFNumber numberWithUnsignedLongLong: 100]
		   forKey: @"unsignedLongLongValue"]) &&
	    R([m setValue: [OFNumber numberWithFloat: 110]
		   forKey: @"floatValue"]) &&
	    R([m setValue: [OFNumber numberWithDouble: 120]
		   forKey: @"doubleValue"]) &&
	    [m boolValue] == 0 &&
	    [m charValue] == 10 &&
	    [m shortValue] == 20 &&
	    [m intValue] == 30 &&
	    [m longValue] == 40 &&
	    [m longLongValue] == 50 &&
	    [m unsignedCharValue] == 60 &&
	    [m unsignedShortValue] == 70 &&







|







238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
		   forKey: @"unsignedLongValue"]) &&
	    R([m setValue: [OFNumber numberWithUnsignedLongLong: 100]
		   forKey: @"unsignedLongLongValue"]) &&
	    R([m setValue: [OFNumber numberWithFloat: 110]
		   forKey: @"floatValue"]) &&
	    R([m setValue: [OFNumber numberWithDouble: 120]
		   forKey: @"doubleValue"]) &&
	    [m isBoolValue] == 0 &&
	    [m charValue] == 10 &&
	    [m shortValue] == 20 &&
	    [m intValue] == 30 &&
	    [m longValue] == 40 &&
	    [m longLongValue] == 50 &&
	    [m unsignedCharValue] == 60 &&
	    [m unsignedShortValue] == 70 &&