Mercurial > projects > dstep
comparison dstep/foundation/NSKeyValueCoding.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | 89f3c3ef1fd2 |
children |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
10 import dstep.foundation.NSDictionary; | 10 import dstep.foundation.NSDictionary; |
11 import dstep.foundation.NSError; | 11 import dstep.foundation.NSError; |
12 import dstep.foundation.NSSet; | 12 import dstep.foundation.NSSet; |
13 import dstep.foundation.NSString; | 13 import dstep.foundation.NSString; |
14 import dstep.objc.bridge.Bridge; | 14 import dstep.objc.bridge.Bridge; |
15 import dstep.objc.objc : id; | 15 import dstep.objc.objc; |
16 | |
17 | |
16 | 18 |
17 import bindings = dstep.foundation.NSKeyValueCoding_bindings; | 19 import bindings = dstep.foundation.NSKeyValueCoding_bindings; |
18 | 20 |
19 const NSString NSUndefinedKeyException; | 21 private |
20 const NSString NSAverageKeyValueOperator; | 22 { |
21 const NSString NSCountKeyValueOperator; | 23 NSString NSUndefinedKeyException_; |
22 const NSString NSDistinctUnionOfArraysKeyValueOperator; | 24 NSString NSAverageKeyValueOperator_; |
23 const NSString NSDistinctUnionOfObjectsKeyValueOperator; | 25 NSString NSCountKeyValueOperator_; |
24 const NSString NSDistinctUnionOfSetsKeyValueOperator; | 26 NSString NSDistinctUnionOfArraysKeyValueOperator_; |
25 const NSString NSMaximumKeyValueOperator; | 27 NSString NSDistinctUnionOfObjectsKeyValueOperator_; |
26 const NSString NSMinimumKeyValueOperator; | 28 NSString NSDistinctUnionOfSetsKeyValueOperator_; |
27 const NSString NSSumKeyValueOperator; | 29 NSString NSMaximumKeyValueOperator_; |
28 const NSString NSUnionOfArraysKeyValueOperator; | 30 NSString NSMinimumKeyValueOperator_; |
29 const NSString NSUnionOfObjectsKeyValueOperator; | 31 NSString NSSumKeyValueOperator_; |
30 const NSString NSUnionOfSetsKeyValueOperator; | 32 NSString NSUnionOfArraysKeyValueOperator_; |
31 | 33 NSString NSUnionOfObjectsKeyValueOperator_; |
32 static this () | 34 NSString NSUnionOfSetsKeyValueOperator_; |
33 { | 35 } |
34 NSUndefinedKeyException = new NSString(bindings.NSUndefinedKeyException); | 36 |
35 NSAverageKeyValueOperator = new NSString(bindings.NSAverageKeyValueOperator); | 37 NSString NSUndefinedKeyException () |
36 NSCountKeyValueOperator = new NSString(bindings.NSCountKeyValueOperator); | 38 { |
37 NSDistinctUnionOfArraysKeyValueOperator = new NSString(bindings.NSDistinctUnionOfArraysKeyValueOperator); | 39 if (NSUndefinedKeyException_) |
38 NSDistinctUnionOfObjectsKeyValueOperator = new NSString(bindings.NSDistinctUnionOfObjectsKeyValueOperator); | 40 return NSUndefinedKeyException_; |
39 NSDistinctUnionOfSetsKeyValueOperator = new NSString(bindings.NSDistinctUnionOfSetsKeyValueOperator); | 41 |
40 NSMaximumKeyValueOperator = new NSString(bindings.NSMaximumKeyValueOperator); | 42 return NSUndefinedKeyException_ = new NSString(bindings.NSUndefinedKeyException); |
41 NSMinimumKeyValueOperator = new NSString(bindings.NSMinimumKeyValueOperator); | 43 } |
42 NSSumKeyValueOperator = new NSString(bindings.NSSumKeyValueOperator); | 44 |
43 NSUnionOfArraysKeyValueOperator = new NSString(bindings.NSUnionOfArraysKeyValueOperator); | 45 NSString NSAverageKeyValueOperator () |
44 NSUnionOfObjectsKeyValueOperator = new NSString(bindings.NSUnionOfObjectsKeyValueOperator); | 46 { |
45 NSUnionOfSetsKeyValueOperator = new NSString(bindings.NSUnionOfSetsKeyValueOperator); | 47 if (NSAverageKeyValueOperator_) |
46 } | 48 return NSAverageKeyValueOperator_; |
47 | 49 |
48 template TNSDeprecatedKeyValueCoding () | 50 return NSAverageKeyValueOperator_ = new NSString(bindings.NSAverageKeyValueOperator); |
49 { | 51 } |
50 static bool useStoredAccessor (); | 52 |
51 Object storedValueForKey (NSString key); | 53 NSString NSCountKeyValueOperator () |
52 void takeStoredValue (Object value, NSString key); | 54 { |
53 void takeValue (Object value, NSString key); | 55 if (NSCountKeyValueOperator_) |
54 void takeValue (Object value, NSString keyPath); | 56 return NSCountKeyValueOperator_; |
55 Object handleQueryWithUnboundKey (NSString key); | 57 |
56 void handleTakeValue (Object value, NSString key); | 58 return NSCountKeyValueOperator_ = new NSString(bindings.NSCountKeyValueOperator); |
57 void unableToSetNilForKey (NSString key); | 59 } |
58 NSDictionary valuesForKeys (NSArray keys); | 60 |
59 void takeValuesFromDictionary (NSDictionary properties); | 61 NSString NSDistinctUnionOfArraysKeyValueOperator () |
60 } | 62 { |
61 | 63 if (NSDistinctUnionOfArraysKeyValueOperator_) |
62 template TNSKeyValueCoding () | 64 return NSDistinctUnionOfArraysKeyValueOperator_; |
63 { | 65 |
64 static bool accessInstanceVariablesDirectly (); | 66 return NSDistinctUnionOfArraysKeyValueOperator_ = new NSString(bindings.NSDistinctUnionOfArraysKeyValueOperator); |
65 Object valueForKey (NSString key); | 67 } |
66 void setValue (Object value, NSString key); | 68 |
67 bool validateValue (id* ioValue, NSString inKey, NSError** outError); | 69 NSString NSDistinctUnionOfObjectsKeyValueOperator () |
68 NSMutableArray mutableArrayValueForKey (NSString key); | 70 { |
69 NSMutableSet mutableSetValueForKey (NSString key); | 71 if (NSDistinctUnionOfObjectsKeyValueOperator_) |
70 Object valueForKeyPath (NSString keyPath); | 72 return NSDistinctUnionOfObjectsKeyValueOperator_; |
71 void setValue (Object value, NSString keyPath); | 73 |
72 bool validateValue (id* ioValue, NSString inKeyPath, NSError** outError); | 74 return NSDistinctUnionOfObjectsKeyValueOperator_ = new NSString(bindings.NSDistinctUnionOfObjectsKeyValueOperator); |
73 NSMutableArray mutableArrayValueForKeyPath (NSString keyPath); | 75 } |
74 NSMutableSet mutableSetValueForKeyPath (NSString keyPath); | 76 |
75 Object valueForUndefinedKey (NSString key); | 77 NSString NSDistinctUnionOfSetsKeyValueOperator () |
76 void setValue (Object value, NSString key); | 78 { |
77 void setNilValueForKey (NSString key); | 79 if (NSDistinctUnionOfSetsKeyValueOperator_) |
78 NSDictionary dictionaryWithValuesForKeys (NSArray keys); | 80 return NSDistinctUnionOfSetsKeyValueOperator_; |
79 void setValuesForKeysWithDictionary (NSDictionary keyedValues); | 81 |
80 } | 82 return NSDistinctUnionOfSetsKeyValueOperator_ = new NSString(bindings.NSDistinctUnionOfSetsKeyValueOperator); |
81 | 83 } |
84 | |
85 NSString NSMaximumKeyValueOperator () | |
86 { | |
87 if (NSMaximumKeyValueOperator_) | |
88 return NSMaximumKeyValueOperator_; | |
89 | |
90 return NSMaximumKeyValueOperator_ = new NSString(bindings.NSMaximumKeyValueOperator); | |
91 } | |
92 | |
93 NSString NSMinimumKeyValueOperator () | |
94 { | |
95 if (NSMinimumKeyValueOperator_) | |
96 return NSMinimumKeyValueOperator_; | |
97 | |
98 return NSMinimumKeyValueOperator_ = new NSString(bindings.NSMinimumKeyValueOperator); | |
99 } | |
100 | |
101 NSString NSSumKeyValueOperator () | |
102 { | |
103 if (NSSumKeyValueOperator_) | |
104 return NSSumKeyValueOperator_; | |
105 | |
106 return NSSumKeyValueOperator_ = new NSString(bindings.NSSumKeyValueOperator); | |
107 } | |
108 | |
109 NSString NSUnionOfArraysKeyValueOperator () | |
110 { | |
111 if (NSUnionOfArraysKeyValueOperator_) | |
112 return NSUnionOfArraysKeyValueOperator_; | |
113 | |
114 return NSUnionOfArraysKeyValueOperator_ = new NSString(bindings.NSUnionOfArraysKeyValueOperator); | |
115 } | |
116 | |
117 NSString NSUnionOfObjectsKeyValueOperator () | |
118 { | |
119 if (NSUnionOfObjectsKeyValueOperator_) | |
120 return NSUnionOfObjectsKeyValueOperator_; | |
121 | |
122 return NSUnionOfObjectsKeyValueOperator_ = new NSString(bindings.NSUnionOfObjectsKeyValueOperator); | |
123 } | |
124 | |
125 NSString NSUnionOfSetsKeyValueOperator () | |
126 { | |
127 if (NSUnionOfSetsKeyValueOperator_) | |
128 return NSUnionOfSetsKeyValueOperator_; | |
129 | |
130 return NSUnionOfSetsKeyValueOperator_ = new NSString(bindings.NSUnionOfSetsKeyValueOperator); | |
131 } | |
132 | |
133 const TNSDeprecatedKeyValueCoding = ` | |
134 | |
135 static bool useStoredAccessor () | |
136 { | |
137 return invokeObjcSelfClass!(bool, "useStoredAccessor"); | |
138 } | |
139 | |
140 Object storedValueForKey (NSString key) | |
141 { | |
142 return invokeObjcSelf!(Object, "storedValueForKey:", NSString)(key); | |
143 } | |
144 | |
145 void takeStoredValue (Object value, NSString key) | |
146 { | |
147 return invokeObjcSelf!(void, "takeStoredValue:forKey:", Object, NSString)(value, key); | |
148 } | |
149 | |
150 void takeValue (Object value, NSString key) | |
151 { | |
152 return invokeObjcSelf!(void, "takeValue:forKey:", Object, NSString)(value, key); | |
153 } | |
154 | |
155 void takeValue_forKeyPath (Object value, NSString keyPath) | |
156 { | |
157 return invokeObjcSelf!(void, "takeValue:forKeyPath:", Object, NSString)(value, keyPath); | |
158 } | |
159 | |
160 Object handleQueryWithUnboundKey (NSString key) | |
161 { | |
162 return invokeObjcSelf!(Object, "handleQueryWithUnboundKey:", NSString)(key); | |
163 } | |
164 | |
165 void handleTakeValue (Object value, NSString key) | |
166 { | |
167 return invokeObjcSelf!(void, "handleTakeValue:forUnboundKey:", Object, NSString)(value, key); | |
168 } | |
169 | |
170 void unableToSetNilForKey (NSString key) | |
171 { | |
172 return invokeObjcSelf!(void, "unableToSetNilForKey:", NSString)(key); | |
173 } | |
174 | |
175 NSDictionary valuesForKeys (NSArray keys) | |
176 { | |
177 return invokeObjcSelf!(NSDictionary, "valuesForKeys:", NSArray)(keys); | |
178 } | |
179 | |
180 void takeValuesFromDictionary (NSDictionary properties) | |
181 { | |
182 return invokeObjcSelf!(void, "takeValuesFromDictionary:", NSDictionary)(properties); | |
183 } | |
184 | |
185 //mixin ObjcBindClassMethod!(useStoredAccessor, "useStoredAccessor"); | |
186 //mixin ObjcBindMethod!(storedValueForKey, "storedValueForKey:"); | |
187 //mixin ObjcBindMethod!(takeStoredValue, "takeStoredValue:forKey:"); | |
188 //mixin ObjcBindMethod!(takeValue, "takeValue:forKey"); | |
189 //mixin ObjcBindMethod!(takeValue_forKeyPath, "takeValue:forKeyPath:"); | |
190 //mixin ObjcBindMethod!(handleQueryWithUnboundKey, "handleQueryWithUnboundKey:"); | |
191 //mixin ObjcBindMethod!(handleTakeValue, "handleTakeValue:forUnboundKey:"); | |
192 //mixin ObjcBindMethod!(unableToSetNilForKey, "unableToSetNilForKey:"); | |
193 //mixin ObjcBindMethod!(valuesForKeys, "valuesForKeys:"); | |
194 //mixin ObjcBindMethod!(takeValuesFromDictionary, "takeValuesFromDictionary:"); | |
195 `; | |
196 | |
197 const TNSKeyValueCoding = ` | |
198 | |
199 static bool accessInstanceVariablesDirectly () | |
200 { | |
201 return invokeObjcSelfClass!(bool, "accessInstanceVariablesDirectly"); | |
202 } | |
203 | |
204 Object valueForKey (NSString key) | |
205 { | |
206 return invokeObjcSelf!(Object, "valueForKey:", NSString)(key); | |
207 } | |
208 | |
209 void setValue (Object value, NSString key) | |
210 { | |
211 return invokeObjcSelf!(void, "setValue:forKey:", Object, NSString)(value, key); | |
212 } | |
213 | |
214 bool validateValue (id* ioValue, NSString inKey, ref NSError outError) | |
215 { | |
216 id error; | |
217 | |
218 if (outError) | |
219 error = new objc_object; | |
220 | |
221 bool result = invokeObjcSelf!(bool, "validateValue:forKey:error:", id*, NSString, id*)(ioValue, inKey, &error); | |
222 | |
223 if (error) | |
224 outError = new NSError(error); | |
225 | |
226 return result; | |
227 } | |
228 | |
229 NSMutableArray mutableArrayValueForKey (NSString key) | |
230 { | |
231 return invokeObjcSelf!(NSMutableArray, "mutableArrayValueForKey:", NSString)(key); | |
232 } | |
233 | |
234 NSMutableSet mutableSetValueForKey (NSString key) | |
235 { | |
236 return invokeObjcSelf!(NSMutableSet, "mutableSetValueForKey:", NSString)(key); | |
237 } | |
238 | |
239 Object valueForKeyPath (NSString keyPath) | |
240 { | |
241 return invokeObjcSelf!(Object, "valueForKeyPath:", NSString)(keyPath); | |
242 } | |
243 | |
244 void setValue_forKeyPath (Object value, NSString keyPath) | |
245 { | |
246 return invokeObjcSelf!(void, "setValue:forKeyPath:", Object, NSString)(value, keyPath); | |
247 } | |
248 | |
249 bool validateValue_forKeyPath_error (id* ioValue, NSString inKeyPath, ref NSError outError) | |
250 { | |
251 id error; | |
252 | |
253 if (outError) | |
254 error = new objc_object; | |
255 | |
256 bool result = invokeObjcSelf!(bool, "validateValue:forKeyPath:error:", id*, NSString, id*)(ioValue, inKeyPath, &error); | |
257 | |
258 if (error) | |
259 outError = new NSError(error); | |
260 | |
261 return result; | |
262 } | |
263 | |
264 NSMutableArray mutableArrayValueForKeyPath (NSString keyPath) | |
265 { | |
266 return invokeObjcSelf!(NSMutableArray, "mutableArrayValueForKeyPath:", NSString)(keyPath); | |
267 } | |
268 | |
269 NSMutableSet mutableSetValueForKeyPath (NSString keyPath) | |
270 { | |
271 return invokeObjcSelf!(NSMutableSet, "mutableSetValueForKeyPath:", NSString)(keyPath); | |
272 } | |
273 | |
274 Object valueForUndefinedKey (NSString key) | |
275 { | |
276 return invokeObjcSelf!(Object, "valueForUndefinedKey:", NSString)(key); | |
277 } | |
278 | |
279 void setValue_forUndefinedKey (Object value, NSString key) | |
280 { | |
281 return invokeObjcSelf!(void, "setValue:forUndefinedKey:", Object, NSString)(value, key); | |
282 } | |
283 | |
284 void setNilValueForKey (NSString key) | |
285 { | |
286 return invokeObjcSelf!(void, "setNilValueForKey:", NSString)(key); | |
287 } | |
288 | |
289 NSDictionary dictionaryWithValuesForKeys (NSArray keys) | |
290 { | |
291 return invokeObjcSelf!(NSDictionary, "dictionaryWithValuesForKeys:", NSArray)(keys); | |
292 } | |
293 | |
294 void setValuesForKeysWithDictionary (NSDictionary keyedValues) | |
295 { | |
296 return invokeObjcSelf!(void, "setValuesForKeysWithDictionary:", NSDictionary)(keyedValues); | |
297 } | |
298 | |
299 //mixin ObjcBindClassMethod!(accessInstanceVariablesDirectly, bool, "accessInstanceVariablesDirectly"); | |
300 //mixin ObjcBindMethod!(setValue, void, "setValue:forKey:", Object, NSString); | |
301 ////mixin ObjcBindMethod!(validateValue, bool, "validateValue:forKey:error:", id*, NSString, NSError*); | |
302 //mixin ObjcBindMethod!(mutableArrayValueForKey, NSMutableArray, "mutableArrayValueForKey:", NSString); | |
303 //mixin ObjcBindMethod!(mutableSetValueForKey, NSMutableSet, "mutableSetValueForKey:", NSString); | |
304 //mixin ObjcBindMethod!(valueForKeyPath, Object, "valueForKeyPath:", NSString); | |
305 //mixin ObjcBindMethod!(setValue_forKeyPath, void, "setValue:forKeyPath:", Object, NSString); | |
306 ////mixin ObjcBindMethod!(validateValue_forKeyPath_error, "validateValue:forKeyPath:error:"); | |
307 //mixin ObjcBindMethod!(mutableArrayValueForKeyPath, NSMutableArray, "mutableArrayValueForKeyPath:", NSString); | |
308 //mixin ObjcBindMethod!(mutableSetValueForKeyPath, NSMutableSet, "mutableSetValueForKeyPath:", NSString); | |
309 //mixin ObjcBindMethod!(valueForUndefinedKey, Object, "valueForUndefinedKey:", NSString); | |
310 //mixin ObjcBindMethod!(setValue_forUndefinedKey, void, "setValue:forUndefinedKey:", Object, NSString); | |
311 //mixin ObjcBindMethod!(setNilValueForKey, void, "setNilValueForKey:", NSString); | |
312 //mixin ObjcBindMethod!(dictionaryWithValuesForKeys, NSDictionary, "dictionaryWithValuesForKeys:", NSArray); | |
313 //mixin ObjcBindMethod!(setValuesForKeysWithDictionary, void, "setValuesForKeysWithDictionary:", NSDictionary); | |
314 `; |