Mercurial > projects > dstep
comparison dstep/foundation/NSValue.d @ 14:89f3c3ef1fd2
Added the Foundation framework
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:23:15 +0200 |
parents | |
children | 19885b43130e |
comparison
equal
deleted
inserted
replaced
13:4f583f7e242e | 14:89f3c3ef1fd2 |
---|---|
1 /** | |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Aug 3, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.foundation.NSValue; | |
8 | |
9 import dstep.foundation.NSDictionary; | |
10 import dstep.foundation.NSObject; | |
11 import dstep.foundation.NSString; | |
12 import dstep.objc.bridge.Bridge; | |
13 import dstep.objc.objc : id; | |
14 | |
15 class NSNumber : NSValue | |
16 { | |
17 mixin ObjcWrap; | |
18 mixin TNSDecimalNumberExtensions; | |
19 mixin TNSNumberCreation; | |
20 | |
21 byte charValue () | |
22 { | |
23 return invokeObjcSelf!(byte, "charValue"); | |
24 } | |
25 | |
26 ubyte unsignedCharValue () | |
27 { | |
28 return invokeObjcSelf!(ubyte, "unsignedCharValue"); | |
29 } | |
30 | |
31 short shortValue () | |
32 { | |
33 return invokeObjcSelf!(short, "shortValue"); | |
34 } | |
35 | |
36 ushort unsignedShortValue () | |
37 { | |
38 return invokeObjcSelf!(ushort, "unsignedShortValue"); | |
39 } | |
40 | |
41 int intValue () | |
42 { | |
43 return invokeObjcSelf!(int, "intValue"); | |
44 } | |
45 | |
46 uint unsignedIntValue () | |
47 { | |
48 return invokeObjcSelf!(uint, "unsignedIntValue"); | |
49 } | |
50 | |
51 int longValue () | |
52 { | |
53 return invokeObjcSelf!(int, "longValue"); | |
54 } | |
55 | |
56 uint unsignedLongValue () | |
57 { | |
58 return invokeObjcSelf!(uint, "unsignedLongValue"); | |
59 } | |
60 | |
61 long longLongValue () | |
62 { | |
63 return invokeObjcSelf!(long, "longLongValue"); | |
64 } | |
65 | |
66 ulong unsignedLongLongValue () | |
67 { | |
68 return invokeObjcSelf!(ulong, "unsignedLongLongValue"); | |
69 } | |
70 | |
71 float floatValue () | |
72 { | |
73 return invokeObjcSelf!(float, "floatValue"); | |
74 } | |
75 | |
76 double doubleValue () | |
77 { | |
78 return invokeObjcSelf!(double, "doubleValue"); | |
79 } | |
80 | |
81 bool boolValue () | |
82 { | |
83 return invokeObjcSelf!(bool, "boolValue"); | |
84 } | |
85 | |
86 NSInteger integerValue () | |
87 { | |
88 return invokeObjcSelf!(NSInteger, "integerValue"); | |
89 } | |
90 | |
91 NSUInteger unsignedIntegerValue () | |
92 { | |
93 return invokeObjcSelf!(NSUInteger, "unsignedIntegerValue"); | |
94 } | |
95 | |
96 NSString stringValue () | |
97 { | |
98 return invokeObjcSelf!(NSString, "stringValue"); | |
99 } | |
100 | |
101 int compare (NSNumber otherNumber) | |
102 { | |
103 return invokeObjcSelf!(int, "compare:", NSNumber)(otherNumber); | |
104 } | |
105 | |
106 bool isEqualToNumber (NSNumber number) | |
107 { | |
108 return invokeObjcSelf!(bool, "isEqualToNumber:", NSNumber)(number); | |
109 } | |
110 | |
111 NSString descriptionWithLocale (Object locale) | |
112 { | |
113 return invokeObjcSelf!(NSString, "descriptionWithLocale:", Object)(locale); | |
114 } | |
115 } | |
116 | |
117 class NSValue : NSObject, INSCopying, INSCoding | |
118 { | |
119 mixin ObjcWrap; | |
120 mixin TNSValueGeometryExtensions; | |
121 mixin TNSValueCreation; | |
122 mixin TNSValueRangeExtensions; | |
123 mixin TNSValueExtensionMethods; | |
124 | |
125 void getValue (void* value) | |
126 { | |
127 return invokeObjcSelf!(void, "getValue:", void*)(value); | |
128 } | |
129 | |
130 char* objCType () | |
131 { | |
132 return invokeObjcSelf!(char*, "objCType"); | |
133 } | |
134 | |
135 Object copyWithZone (NSZone* zone) | |
136 { | |
137 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); | |
138 } | |
139 | |
140 void encodeWithCoder (NSCoder aCoder) | |
141 { | |
142 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); | |
143 } | |
144 | |
145 Object initWithCoder (NSCoder aDecoder) | |
146 { | |
147 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | |
148 } | |
149 | |
150 this (NSCoder aDecoder) | |
151 { | |
152 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
153 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | |
154 | |
155 if (result) | |
156 objcObject = ret; | |
157 | |
158 dObject = this; | |
159 } | |
160 } | |
161 | |
162 template TNSNumberCreation () | |
163 { | |
164 Object initWithChar (byte value) | |
165 { | |
166 return invokeObjcSelf!(Object, "initWithChar:", byte)(value); | |
167 } | |
168 | |
169 this (byte value) | |
170 { | |
171 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
172 id result = Bridge.invokeObjcMethod!(id, "initWithChar:", byte)(objcObject, value); | |
173 | |
174 if (result) | |
175 objcObject = ret; | |
176 | |
177 dObject = this; | |
178 } | |
179 | |
180 Object initWithUnsignedChar (ubyte value) | |
181 { | |
182 return invokeObjcSelf!(Object, "initWithUnsignedChar:", ubyte)(value); | |
183 } | |
184 | |
185 this (ubyte value) | |
186 { | |
187 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
188 id result = Bridge.invokeObjcMethod!(id, "initWithUnsignedChar:", ubyte)(objcObject, value); | |
189 | |
190 if (result) | |
191 objcObject = ret; | |
192 | |
193 dObject = this; | |
194 } | |
195 | |
196 Object initWithShort (short value) | |
197 { | |
198 return invokeObjcSelf!(Object, "initWithShort:", short)(value); | |
199 } | |
200 | |
201 this (short value) | |
202 { | |
203 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
204 id result = Bridge.invokeObjcMethod!(id, "initWithShort:", short)(objcObject, value); | |
205 | |
206 if (result) | |
207 objcObject = ret; | |
208 | |
209 dObject = this; | |
210 } | |
211 | |
212 Object initWithUnsignedShort (ushort value) | |
213 { | |
214 return invokeObjcSelf!(Object, "initWithUnsignedShort:", ushort)(value); | |
215 } | |
216 | |
217 this (ushort value) | |
218 { | |
219 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
220 id result = Bridge.invokeObjcMethod!(id, "initWithUnsignedShort:", ushort)(objcObject, value); | |
221 | |
222 if (result) | |
223 objcObject = ret; | |
224 | |
225 dObject = this; | |
226 } | |
227 | |
228 Object initWithInt (int value) | |
229 { | |
230 return invokeObjcSelf!(Object, "initWithInt:", int)(value); | |
231 } | |
232 | |
233 this (int value) | |
234 { | |
235 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
236 id result = Bridge.invokeObjcMethod!(id, "initWithInt:", int)(objcObject, value); | |
237 | |
238 if (result) | |
239 objcObject = ret; | |
240 | |
241 dObject = this; | |
242 } | |
243 | |
244 Object initWithUnsignedInt (uint value) | |
245 { | |
246 return invokeObjcSelf!(Object, "initWithUnsignedInt:", uint)(value); | |
247 } | |
248 | |
249 this (uint value) | |
250 { | |
251 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
252 id result = Bridge.invokeObjcMethod!(id, "initWithUnsignedInt:", uint)(objcObject, value); | |
253 | |
254 if (result) | |
255 objcObject = ret; | |
256 | |
257 dObject = this; | |
258 } | |
259 | |
260 Object initWithLong (int value) | |
261 { | |
262 return invokeObjcSelf!(Object, "initWithLong:", int)(value); | |
263 } | |
264 | |
265 this (int value) | |
266 { | |
267 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
268 id result = Bridge.invokeObjcMethod!(id, "initWithLong:", int)(objcObject, value); | |
269 | |
270 if (result) | |
271 objcObject = ret; | |
272 | |
273 dObject = this; | |
274 } | |
275 | |
276 Object initWithUnsignedLong (uint value) | |
277 { | |
278 return invokeObjcSelf!(Object, "initWithUnsignedLong:", uint)(value); | |
279 } | |
280 | |
281 this (uint value) | |
282 { | |
283 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
284 id result = Bridge.invokeObjcMethod!(id, "initWithUnsignedLong:", uint)(objcObject, value); | |
285 | |
286 if (result) | |
287 objcObject = ret; | |
288 | |
289 dObject = this; | |
290 } | |
291 | |
292 Object initWithLongLong (long value) | |
293 { | |
294 return invokeObjcSelf!(Object, "initWithLongLong:", long)(value); | |
295 } | |
296 | |
297 this (long value) | |
298 { | |
299 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
300 id result = Bridge.invokeObjcMethod!(id, "initWithLongLong:", long)(objcObject, value); | |
301 | |
302 if (result) | |
303 objcObject = ret; | |
304 | |
305 dObject = this; | |
306 } | |
307 | |
308 Object initWithUnsignedLongLong (ulong value) | |
309 { | |
310 return invokeObjcSelf!(Object, "initWithUnsignedLongLong:", ulong)(value); | |
311 } | |
312 | |
313 this (ulong value) | |
314 { | |
315 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
316 id result = Bridge.invokeObjcMethod!(id, "initWithUnsignedLongLong:", ulong)(objcObject, value); | |
317 | |
318 if (result) | |
319 objcObject = ret; | |
320 | |
321 dObject = this; | |
322 } | |
323 | |
324 Object initWithFloat (float value) | |
325 { | |
326 return invokeObjcSelf!(Object, "initWithFloat:", float)(value); | |
327 } | |
328 | |
329 this (float value) | |
330 { | |
331 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
332 id result = Bridge.invokeObjcMethod!(id, "initWithFloat:", float)(objcObject, value); | |
333 | |
334 if (result) | |
335 objcObject = ret; | |
336 | |
337 dObject = this; | |
338 } | |
339 | |
340 Object initWithDouble (double value) | |
341 { | |
342 return invokeObjcSelf!(Object, "initWithDouble:", double)(value); | |
343 } | |
344 | |
345 this (double value) | |
346 { | |
347 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
348 id result = Bridge.invokeObjcMethod!(id, "initWithDouble:", double)(objcObject, value); | |
349 | |
350 if (result) | |
351 objcObject = ret; | |
352 | |
353 dObject = this; | |
354 } | |
355 | |
356 Object initWithBool (bool value) | |
357 { | |
358 return invokeObjcSelf!(Object, "initWithBool:", bool)(value); | |
359 } | |
360 | |
361 this (bool value) | |
362 { | |
363 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
364 id result = Bridge.invokeObjcMethod!(id, "initWithBool:", bool)(objcObject, value); | |
365 | |
366 if (result) | |
367 objcObject = ret; | |
368 | |
369 dObject = this; | |
370 } | |
371 | |
372 Object initWithInteger (NSInteger value) | |
373 { | |
374 return invokeObjcSelf!(Object, "initWithInteger:", NSInteger)(value); | |
375 } | |
376 | |
377 this (NSInteger value) | |
378 { | |
379 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
380 id result = Bridge.invokeObjcMethod!(id, "initWithInteger:", NSInteger)(objcObject, value); | |
381 | |
382 if (result) | |
383 objcObject = ret; | |
384 | |
385 dObject = this; | |
386 } | |
387 | |
388 Object initWithUnsignedInteger (NSUInteger value) | |
389 { | |
390 return invokeObjcSelf!(Object, "initWithUnsignedInteger:", NSUInteger)(value); | |
391 } | |
392 | |
393 this (NSUInteger value) | |
394 { | |
395 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
396 id result = Bridge.invokeObjcMethod!(id, "initWithUnsignedInteger:", NSUInteger)(objcObject, value); | |
397 | |
398 if (result) | |
399 objcObject = ret; | |
400 | |
401 dObject = this; | |
402 } | |
403 | |
404 static NSNumber numberWithChar (byte value) | |
405 { | |
406 return invokeObjcSelfClass!(NSNumber, "numberWithChar:", byte)(value); | |
407 } | |
408 | |
409 static NSNumber numberWithUnsignedChar (ubyte value) | |
410 { | |
411 return invokeObjcSelfClass!(NSNumber, "numberWithUnsignedChar:", ubyte)(value); | |
412 } | |
413 | |
414 static NSNumber numberWithShort (short value) | |
415 { | |
416 return invokeObjcSelfClass!(NSNumber, "numberWithShort:", short)(value); | |
417 } | |
418 | |
419 static NSNumber numberWithUnsignedShort (ushort value) | |
420 { | |
421 return invokeObjcSelfClass!(NSNumber, "numberWithUnsignedShort:", ushort)(value); | |
422 } | |
423 | |
424 static NSNumber numberWithInt (int value) | |
425 { | |
426 return invokeObjcSelfClass!(NSNumber, "numberWithInt:", int)(value); | |
427 } | |
428 | |
429 static NSNumber numberWithUnsignedInt (uint value) | |
430 { | |
431 return invokeObjcSelfClass!(NSNumber, "numberWithUnsignedInt:", uint)(value); | |
432 } | |
433 | |
434 static NSNumber numberWithLong (int value) | |
435 { | |
436 return invokeObjcSelfClass!(NSNumber, "numberWithLong:", int)(value); | |
437 } | |
438 | |
439 static NSNumber numberWithUnsignedLong (uint value) | |
440 { | |
441 return invokeObjcSelfClass!(NSNumber, "numberWithUnsignedLong:", uint)(value); | |
442 } | |
443 | |
444 static NSNumber numberWithLongLong (long value) | |
445 { | |
446 return invokeObjcSelfClass!(NSNumber, "numberWithLongLong:", long)(value); | |
447 } | |
448 | |
449 static NSNumber numberWithUnsignedLongLong (ulong value) | |
450 { | |
451 return invokeObjcSelfClass!(NSNumber, "numberWithUnsignedLongLong:", ulong)(value); | |
452 } | |
453 | |
454 static NSNumber numberWithFloat (float value) | |
455 { | |
456 return invokeObjcSelfClass!(NSNumber, "numberWithFloat:", float)(value); | |
457 } | |
458 | |
459 static NSNumber numberWithDouble (double value) | |
460 { | |
461 return invokeObjcSelfClass!(NSNumber, "numberWithDouble:", double)(value); | |
462 } | |
463 | |
464 static NSNumber numberWithBool (bool value) | |
465 { | |
466 return invokeObjcSelfClass!(NSNumber, "numberWithBool:", bool)(value); | |
467 } | |
468 | |
469 static NSNumber numberWithInteger (NSInteger value) | |
470 { | |
471 return invokeObjcSelfClass!(NSNumber, "numberWithInteger:", NSInteger)(value); | |
472 } | |
473 | |
474 static NSNumber numberWithUnsignedInteger (NSUInteger value) | |
475 { | |
476 return invokeObjcSelfClass!(NSNumber, "numberWithUnsignedInteger:", NSUInteger)(value); | |
477 } | |
478 } | |
479 | |
480 template TNSValueCreation () | |
481 { | |
482 Object initWithBytes (void* value, char* type) | |
483 { | |
484 return invokeObjcSelf!(Object, "initWithBytes:objCType:", void*, char*)(value, type); | |
485 } | |
486 | |
487 this (void* value, char* type) | |
488 { | |
489 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
490 id result = Bridge.invokeObjcMethod!(id, "initWithBytes:objCType:", void*, char*)(objcObject, value, type); | |
491 | |
492 if (result) | |
493 objcObject = ret; | |
494 | |
495 dObject = this; | |
496 } | |
497 | |
498 static NSValue valueWithBytes (void* value, char* type) | |
499 { | |
500 return invokeObjcSelfClass!(NSValue, "valueWithBytes:objCType:", void*, char*)(value, type); | |
501 } | |
502 | |
503 static NSValue value (void* value, char* type) | |
504 { | |
505 return invokeObjcSelfClass!(NSValue, "value:withObjCType:", void*, char*)(value, type); | |
506 } | |
507 } | |
508 | |
509 template TNSValueExtensionMethods () | |
510 { | |
511 static NSValue valueWithNonretainedObject (Object anObject) | |
512 { | |
513 return invokeObjcSelfClass!(NSValue, "valueWithNonretainedObject:", Object)(anObject); | |
514 } | |
515 | |
516 Object nonretainedObjectValue () | |
517 { | |
518 return invokeObjcSelf!(Object, "nonretainedObjectValue"); | |
519 } | |
520 | |
521 static NSValue valueWithPointer (void* pointer) | |
522 { | |
523 return invokeObjcSelfClass!(NSValue, "valueWithPointer:", void*)(pointer); | |
524 } | |
525 | |
526 void* pointerValue () | |
527 { | |
528 return invokeObjcSelf!(void*, "pointerValue"); | |
529 } | |
530 | |
531 bool isEqualToValue (NSValue value) | |
532 { | |
533 return invokeObjcSelf!(bool, "isEqualToValue:", NSValue)(value); | |
534 } | |
535 } | |
536 |