Differences From Artifact [30955b0805]:
- File
src/OFObject+KeyValueCoding.m
— part of check-in
[4af49a13c3]
at
2017-05-07 20:10:13
on branch trunk
— Small code style change
Casts are now written like types in variable declarations. (user: js, size: 5677) [annotate] [blame] [check-ins using]
To Artifact [621aa06394]:
- File src/OFObject+KeyValueCoding.m — part of check-in [55f1b21ae7] at 2017-09-09 22:03:52 on branch trunk — Replace type encodings with OFMethodSignature (user: js, size: 5749) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include "config.h" #include <stdlib.h> #import "OFObject.h" #import "OFObject+KeyValueCoding.h" #import "OFString.h" #import "OFNumber.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFUndefinedKeyException.h" int _OFObject_KeyValueCoding_reference; | > < < < < < < < < < < < > | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include "config.h" #include <stdlib.h> #import "OFObject.h" #import "OFObject+KeyValueCoding.h" #import "OFMethodSignature.h" #import "OFString.h" #import "OFNumber.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFUndefinedKeyException.h" int _OFObject_KeyValueCoding_reference; @implementation OFObject (KeyValueCoding) - (id)valueForKey: (OFString *)key { SEL selector = sel_registerName([key UTF8String]); OFMethodSignature *methodSignature = [self methodSignatureForSelector: selector]; id ret; if (methodSignature == nil) { size_t keyLength; char *name; if ((keyLength = [key UTF8StringLength]) < 1) return [self valueForUndefinedKey: key]; if ((name = malloc(keyLength + 3)) == NULL) |
︙ | ︙ | |||
66 67 68 69 70 71 72 | name[2] = of_ascii_toupper(name[2]); selector = sel_registerName(name); } @finally { free(name); } | | | > | > > > | | | > > > > > > | 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 85 86 87 88 | name[2] = of_ascii_toupper(name[2]); selector = sel_registerName(name); } @finally { free(name); } methodSignature = [self methodSignatureForSelector: selector]; if (methodSignature == NULL) return [self valueForUndefinedKey: key]; switch (*[methodSignature methodReturnType]) { case '@': case '#': return [self valueForUndefinedKey: key]; } } if ([methodSignature numberOfArguments] != 2 || *[methodSignature argumentTypeAtIndex: 0] != '@' || *[methodSignature argumentTypeAtIndex: 1] != ':') return [self valueForUndefinedKey: key]; switch (*[methodSignature methodReturnType]) { case '@': case '#': ret = [self performSelector: selector]; break; #define CASE(encoding, type, method) \ case encoding: \ { \ |
︙ | ︙ | |||
104 105 106 107 108 109 110 | CASE('f', float, numberWithFloat:) CASE('d', double, numberWithDouble:) #undef CASE default: return [self valueForUndefinedKey: key]; } | < < < < > | < | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | CASE('f', float, numberWithFloat:) CASE('d', double, numberWithDouble:) #undef CASE default: return [self valueForUndefinedKey: key]; } return ret; } - (id)valueForUndefinedKey: (OFString *)key { @throw [OFUndefinedKeyException exceptionWithObject: self key: key]; } - (void)setValue: (id)value forKey: (OFString *)key { size_t keyLength; char *name; SEL selector; OFMethodSignature *methodSignature; const char *valueType; if ((keyLength = [key UTF8StringLength]) < 1) { [self setValue: value forUndefinedKey: key]; return; } |
︙ | ︙ | |||
148 149 150 151 152 153 154 | name[3] = of_ascii_toupper(name[3]); selector = sel_registerName(name); } @finally { free(name); } | | > > | | > < | < < < < | | < | | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | name[3] = of_ascii_toupper(name[3]); selector = sel_registerName(name); } @finally { free(name); } methodSignature = [self methodSignatureForSelector: selector]; if (methodSignature == nil || [methodSignature numberOfArguments] != 3 || *[methodSignature methodReturnType] != 'v' || *[methodSignature argumentTypeAtIndex: 0] != '@' || *[methodSignature argumentTypeAtIndex: 1] != ':') { [self setValue: value forUndefinedKey: key]; return; } valueType = [methodSignature argumentTypeAtIndex: 2]; if (*valueType != '@' && *valueType != '#' && value == nil) { [self setNilValueForKey: key]; return; } switch (*valueType) { case '@': case '#': { void (*setter)(id, SEL, id) = (void (*)(id, SEL, id)) [self methodForSelector: selector]; setter(self, selector, value); } |
︙ | ︙ |