ObjFW  Diff

Differences From Artifact [d4b85d6121]:

To Artifact [30955b0805]:


37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51







-
+







	while (**typeEncoding >= '0' && **typeEncoding <= '9')
		(*typeEncoding)++;

	return ret;
}

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

	if (typeEncoding == NULL) {
		size_t keyLength;
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95







-
+







	case '@':
	case '#':
		ret = [self performSelector: selector];
		break;
#define CASE(encoding, type, method)					  \
	case encoding:							  \
		{							  \
			type (*getter)(id, SEL) = (type(*)(id, SEL))	  \
			type (*getter)(id, SEL) = (type (*)(id, SEL))	  \
			    [self methodForSelector: selector];		  \
			ret = [OFNumber method getter(self, selector)]; \
		}							  \
		break;
	CASE('B', bool, numberWithBool:)
	CASE('c', char, numberWithChar:)
	CASE('s', short, numberWithShort:)
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125

126
127
128
129
130
131
132
111
112
113
114
115
116
117

118
119
120
121
122
123
124

125
126
127
128
129
130
131
132







-
+






-
+







	if (nextType(&typeEncoding) != '@' || nextType(&typeEncoding) != ':' ||
	    *typeEncoding != 0)
		return [self valueForUndefinedKey: key];

	return ret;
}

- (id)valueForUndefinedKey: (OFString*)key
- (id)valueForUndefinedKey: (OFString *)key
{
	@throw [OFUndefinedKeyException exceptionWithObject: self
							key: key];
}

- (void)setValue: (id)value
	  forKey: (OFString*)key
	  forKey: (OFString *)key
{
	size_t keyLength;
	char *name;
	SEL selector;
	const char *typeEncoding;
	char valueType;

174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197







-
+








-
+







		return;
	}

	switch (valueType) {
	case '@':
	case '#':
		{
			void (*setter)(id, SEL, id) = (void(*)(id, SEL, id))
			void (*setter)(id, SEL, id) = (void (*)(id, SEL, id))
			    [self methodForSelector: selector];
			setter(self, selector, value);
		}
		break;
#define CASE(encoding, type, method) \
	case encoding:						\
		{						\
			void (*setter)(id, SEL, type) =		\
			    (void(*)(id, SEL, type))		\
			    (void (*)(id, SEL, type))		\
			    [self methodForSelector: selector];	\
			setter(self, selector, [value method]);	\
		}						\
		break;
	CASE('B', bool, boolValue)
	CASE('c', char, charValue)
	CASE('s', short, shortValue)
210
211
212
213
214
215
216
217

218
219
220
221
222
223
224

225
226
227
228
210
211
212
213
214
215
216

217
218
219
220
221
222
223

224
225
226
227
228







-
+






-
+




		[self    setValue: value
		  forUndefinedKey: key];
		return;
	}
}

-  (void)setValue: (id)value
  forUndefinedKey: (OFString*)key
  forUndefinedKey: (OFString *)key
{
	@throw [OFUndefinedKeyException exceptionWithObject: self
							key: key
						      value: value];
}

- (void)setNilValueForKey: (OFString*)key
- (void)setNilValueForKey: (OFString *)key
{
	@throw [OFInvalidArgumentException exception];
}
@end