comparison dstep/foundation/NSDecimalNumber.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 7ff919f595d5
children b9de51448c6b
comparison
equal deleted inserted replaced
15:7ff919f595d5 16:19885b43130e
4 * Version: Initial created: Aug 3, 2009 4 * Version: Initial created: Aug 3, 2009
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6 */ 6 */
7 module dstep.foundation.NSDecimalNumber; 7 module dstep.foundation.NSDecimalNumber;
8 8
9 import dstep.foundation.NSCoder;
9 import dstep.foundation.NSDecimal; 10 import dstep.foundation.NSDecimal;
10 import dstep.foundation.NSDictionary; 11 import dstep.foundation.NSDictionary;
12 import dstep.foundation.NSObjCRuntime;
13 import dstep.foundation.NSObject;
11 import dstep.foundation.NSScanner; 14 import dstep.foundation.NSScanner;
15 import dstep.foundation.NSString;
12 import dstep.foundation.NSValue; 16 import dstep.foundation.NSValue;
13 import dstep.objc.bridge.Bridge; 17 import dstep.objc.bridge.Bridge;
14 import dstep.objc.objc : id; 18 import dstep.objc.objc;
15 19
16 import bindings = dstep.foundation.NSDecimalNumber_bindings; 20 import bindings = dstep.foundation.NSDecimalNumber_bindings;
17 21
18 const NSString NSDecimalNumberExactnessException; 22 private
19 const NSString NSDecimalNumberOverflowException; 23 {
20 const NSString NSDecimalNumberUnderflowException; 24 NSString NSDecimalNumberExactnessException_;
21 const NSString NSDecimalNumberDivideByZeroException; 25 NSString NSDecimalNumberOverflowException_;
22 26 NSString NSDecimalNumberUnderflowException_;
23 static this () 27 NSString NSDecimalNumberDivideByZeroException_;
24 { 28 }
25 NSDecimalNumberExactnessException = new NSString(bindings.NSDecimalNumberExactnessException); 29
26 NSDecimalNumberOverflowException = new NSString(bindings.NSDecimalNumberOverflowException); 30 NSString NSDecimalNumberExactnessException ()
27 NSDecimalNumberUnderflowException = new NSString(bindings.NSDecimalNumberUnderflowException); 31 {
28 NSDecimalNumberDivideByZeroException = new NSString(bindings.NSDecimalNumberDivideByZeroException); 32 if (NSDecimalNumberExactnessException_)
29 } 33 return NSDecimalNumberExactnessException_;
34
35 return NSDecimalNumberExactnessException_ = new NSString(bindings.NSDecimalNumberExactnessException);
36 }
37
38 NSString NSDecimalNumberOverflowException ()
39 {
40 if (NSDecimalNumberOverflowException_)
41 return NSDecimalNumberOverflowException_;
42
43 return NSDecimalNumberOverflowException_ = new NSString(bindings.NSDecimalNumberOverflowException);
44 }
45
46 NSString NSDecimalNumberUnderflowException ()
47 {
48 if (NSDecimalNumberUnderflowException_)
49 return NSDecimalNumberUnderflowException_;
50
51 return NSDecimalNumberUnderflowException_ = new NSString(bindings.NSDecimalNumberUnderflowException);
52 }
53
54 NSString NSDecimalNumberDivideByZeroException ()
55 {
56 if (NSDecimalNumberDivideByZeroException_)
57 return NSDecimalNumberDivideByZeroException_;
58
59 return NSDecimalNumberDivideByZeroException_ = new NSString(bindings.NSDecimalNumberDivideByZeroException);
60 }
61
62 const TNSDecimalNumberExtensions = `
63
64 NSDecimal decimalValue ()
65 {
66 return invokeObjcSelf!(NSDecimal, "decimalValue");
67 }
68 `;
69
70 const TNSDecimalNumberScanning = `
71
72 bool scanDecimal (NSDecimal* dcm)
73 {
74 return invokeObjcSelf!(bool, "scanDecimal:", NSDecimal*)(dcm);
75 }
76 `;
30 77
31 class NSDecimalNumber : NSNumber 78 class NSDecimalNumber : NSNumber
32 { 79 {
33 mixin ObjcWrap; 80 mixin (ObjcWrap);
34 81
35 Object initWithMantissa (ulong mantissa, short exponent, bool flag) 82 this ()
36 { 83 {
37 return invokeObjcSelf!(Object, "initWithMantissa:exponent:isNegative:", ulong, short, bool)(mantissa, exponent, flag); 84 super(typeof(this).alloc.init.objcObject);
85 }
86
87 typeof(this) init ()
88 {
89 return invokeObjcSelf!(typeof(this), "init");
90 }
91
92 NSDecimalNumber initWithMantissa (ulong mantissa, short exponent, bool flag)
93 {
94 return invokeObjcSelf!(NSDecimalNumber, "initWithMantissa:exponent:isNegative:", ulong, short, bool)(mantissa, exponent, flag);
38 } 95 }
39 96
40 this (ulong mantissa, short exponent, bool flag) 97 this (ulong mantissa, short exponent, bool flag)
41 { 98 {
42 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 99 super(typeof(this).alloc.initWithMantissa(mantissa, exponent, flag).objcObject);
43 id result = Bridge.invokeObjcMethod!(id, "initWithMantissa:exponent:isNegative:", ulong, short, bool)(objcObject, mantissa, exponent, flag); 100 }
44 101
45 if (result) 102 NSDecimalNumber initWithDecimal (NSDecimal dcm)
46 objcObject = ret; 103 {
47 104 return invokeObjcSelf!(NSDecimalNumber, "initWithDecimal:", NSDecimal)(dcm);
48 dObject = this;
49 }
50
51 Object initWithDecimal (NSDecimal dcm)
52 {
53 return invokeObjcSelf!(Object, "initWithDecimal:", NSDecimal)(dcm);
54 } 105 }
55 106
56 this (NSDecimal dcm) 107 this (NSDecimal dcm)
57 { 108 {
58 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 109 super(typeof(this).alloc.initWithDecimal(dcm).objcObject);
59 id result = Bridge.invokeObjcMethod!(id, "initWithDecimal:", NSDecimal)(objcObject, dcm); 110 }
60 111
61 if (result) 112 NSDecimalNumber initWithString (NSString numberValue)
62 objcObject = ret; 113 {
63 114 return invokeObjcSelf!(NSDecimalNumber, "initWithString:", NSString)(numberValue);
64 dObject = this;
65 }
66
67 Object initWithString (NSString numberValue)
68 {
69 return invokeObjcSelf!(Object, "initWithString:", NSString)(numberValue);
70 } 115 }
71 116
72 this (NSString numberValue) 117 this (NSString numberValue)
73 { 118 {
74 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 119 super(typeof(this).alloc.initWithString(numberValue).objcObject);
75 id result = Bridge.invokeObjcMethod!(id, "initWithString:", NSString)(objcObject, numberValue); 120 }
76 121
77 if (result) 122 NSDecimalNumber initWithString (NSString numberValue, Object locale)
78 objcObject = ret; 123 {
79 124 return invokeObjcSelf!(NSDecimalNumber, "initWithString:locale:", NSString, Object)(numberValue, locale);
80 dObject = this;
81 }
82
83 Object initWithString (NSString numberValue, Object locale)
84 {
85 return invokeObjcSelf!(Object, "initWithString:locale:", NSString, Object)(numberValue, locale);
86 } 125 }
87 126
88 this (NSString numberValue, Object locale) 127 this (NSString numberValue, Object locale)
89 { 128 {
90 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 129 super(typeof(this).alloc.initWithString(numberValue, locale).objcObject);
91 id result = Bridge.invokeObjcMethod!(id, "initWithString:locale:", NSString, Object)(objcObject, numberValue, locale);
92
93 if (result)
94 objcObject = ret;
95
96 dObject = this;
97 } 130 }
98 131
99 NSString descriptionWithLocale (Object locale) 132 NSString descriptionWithLocale (Object locale)
100 { 133 {
101 return invokeObjcSelf!(NSString, "descriptionWithLocale:", Object)(locale); 134 return invokeObjcSelf!(NSString, "descriptionWithLocale:", Object)(locale);
106 return invokeObjcSelf!(NSDecimal, "decimalValue"); 139 return invokeObjcSelf!(NSDecimal, "decimalValue");
107 } 140 }
108 141
109 static NSDecimalNumber decimalNumberWithMantissa (ulong mantissa, short exponent, bool flag) 142 static NSDecimalNumber decimalNumberWithMantissa (ulong mantissa, short exponent, bool flag)
110 { 143 {
111 return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithMantissa:exponent:isNegative:", ulong, short, bool)(mantissa, exponent, flag); 144 return invokeObjcSuperClass!(NSDecimalNumber, "decimalNumberWithMantissa:exponent:isNegative:", ulong, short, bool)(mantissa, exponent, flag);
112 } 145 }
113 146
114 static NSDecimalNumber decimalNumberWithDecimal (NSDecimal dcm) 147 static NSDecimalNumber decimalNumberWithDecimal (NSDecimal dcm)
115 { 148 {
116 return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithDecimal:", NSDecimal)(dcm); 149 return invokeObjcSuperClass!(NSDecimalNumber, "decimalNumberWithDecimal:", NSDecimal)(dcm);
117 } 150 }
118 151
119 static NSDecimalNumber decimalNumberWithString (NSString numberValue) 152 static NSDecimalNumber decimalNumberWithString (NSString numberValue)
120 { 153 {
121 return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithString:", NSString)(numberValue); 154 return invokeObjcSuperClass!(NSDecimalNumber, "decimalNumberWithString:", NSString)(numberValue);
122 } 155 }
123 156
124 static NSDecimalNumber decimalNumberWithString (NSString numberValue, Object locale) 157 static NSDecimalNumber decimalNumberWithString (NSString numberValue, Object locale)
125 { 158 {
126 return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithString:locale:", NSString, Object)(numberValue, locale); 159 return invokeObjcSuperClass!(NSDecimalNumber, "decimalNumberWithString:locale:", NSString, Object)(numberValue, locale);
127 } 160 }
128 161
129 static NSDecimalNumber zero () 162 static NSDecimalNumber zero ()
130 { 163 {
131 return invokeObjcSelfClass!(NSDecimalNumber, "zero"); 164 return invokeObjcSuperClass!(NSDecimalNumber, "zero");
132 } 165 }
133 166
134 static NSDecimalNumber one () 167 static NSDecimalNumber one ()
135 { 168 {
136 return invokeObjcSelfClass!(NSDecimalNumber, "one"); 169 return invokeObjcSuperClass!(NSDecimalNumber, "one");
137 } 170 }
138 171
139 static NSDecimalNumber minimumDecimalNumber () 172 static NSDecimalNumber minimumDecimalNumber ()
140 { 173 {
141 return invokeObjcSelfClass!(NSDecimalNumber, "minimumDecimalNumber"); 174 return invokeObjcSuperClass!(NSDecimalNumber, "minimumDecimalNumber");
142 } 175 }
143 176
144 static NSDecimalNumber maximumDecimalNumber () 177 static NSDecimalNumber maximumDecimalNumber ()
145 { 178 {
146 return invokeObjcSelfClass!(NSDecimalNumber, "maximumDecimalNumber"); 179 return invokeObjcSuperClass!(NSDecimalNumber, "maximumDecimalNumber");
147 } 180 }
148 181
149 static NSDecimalNumber notANumber () 182 static NSDecimalNumber notANumber ()
150 { 183 {
151 return invokeObjcSelfClass!(NSDecimalNumber, "notANumber"); 184 return invokeObjcSuperClass!(NSDecimalNumber, "notANumber");
152 } 185 }
153 186
154 NSDecimalNumber decimalNumberByAdding (NSDecimalNumber decimalNumber) 187 NSDecimalNumber decimalNumberByAdding (NSDecimalNumber decimalNumber)
155 { 188 {
156 id result = invokeObjcSelf!(id, "decimalNumberByAdding:", NSDecimalNumber)(decimalNumber); 189 id result = invokeObjcSelf!(id, "decimalNumberByAdding:", NSDecimalNumber)(decimalNumber);
234 return invokeObjcSelf!(int, "compare:", NSNumber)(decimalNumber); 267 return invokeObjcSelf!(int, "compare:", NSNumber)(decimalNumber);
235 } 268 }
236 269
237 static void setDefaultBehavior (INSDecimalNumberBehaviors behavior) 270 static void setDefaultBehavior (INSDecimalNumberBehaviors behavior)
238 { 271 {
239 return invokeObjcSelfClass!(void, "setDefaultBehavior:", INSDecimalNumberBehaviors)(behavior); 272 return invokeObjcSuperClass!(void, "setDefaultBehavior:", INSDecimalNumberBehaviors)(behavior);
240 } 273 }
241 274
242 static INSDecimalNumberBehaviors defaultBehavior () 275 static INSDecimalNumberBehaviors defaultBehavior ()
243 { 276 {
244 return invokeObjcSelfClass!(INSDecimalNumberBehaviors, "defaultBehavior"); 277 return invokeObjcSuperClass!(INSDecimalNumberBehaviors, "defaultBehavior");
245 } 278 }
246 279
247 char* objCType () 280 char* objCType ()
248 { 281 {
249 return invokeObjcSelf!(char*, "objCType"); 282 return invokeObjcSelf!(char*, "objCType");
255 } 288 }
256 } 289 }
257 290
258 class NSDecimalNumberHandler : NSObject, INSDecimalNumberBehaviors, INSCoding 291 class NSDecimalNumberHandler : NSObject, INSDecimalNumberBehaviors, INSCoding
259 { 292 {
260 mixin ObjcWrap; 293 mixin (ObjcWrap);
294
295 this ()
296 {
297 super(typeof(this).alloc.init.objcObject);
298 }
299
300 typeof(this) init ()
301 {
302 return invokeObjcSelf!(typeof(this), "init");
303 }
261 304
262 static Object defaultDecimalNumberHandler () 305 static Object defaultDecimalNumberHandler ()
263 { 306 {
264 return invokeObjcSelfClass!(Object, "defaultDecimalNumberHandler"); 307 return invokeObjcSuperClass!(Object, "defaultDecimalNumberHandler");
265 } 308 }
266 309
267 Object initWithRoundingMode (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero) 310 Object initWithRoundingMode (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero)
268 { 311 {
269 return invokeObjcSelf!(Object, "initWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:", uint, short, bool, bool, bool, bool)(roundingMode, scale, exact, overflow, underflow, divideByZero); 312 return invokeObjcSelf!(Object, "initWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:", uint, short, bool, bool, bool, bool)(roundingMode, scale, exact, overflow, underflow, divideByZero);
270 } 313 }
271 314
272 this (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero) 315 this (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero)
273 { 316 {
274 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 317 typeof(this).alloc.initWithRoundingMode(roundingMode, scale, exact, overflow, underflow, divideByZero);
275 id result = Bridge.invokeObjcMethod!(id, "initWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:", uint, short, bool, bool, bool, bool)(objcObject, roundingMode, scale, exact, overflow, underflow, divideByZero);
276
277 if (result)
278 objcObject = ret;
279
280 dObject = this;
281 } 318 }
282 319
283 static Object decimalNumberHandlerWithRoundingMode (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero) 320 static Object decimalNumberHandlerWithRoundingMode (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero)
284 { 321 {
285 return invokeObjcSelfClass!(Object, "decimalNumberHandlerWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:", uint, short, bool, bool, bool, bool)(roundingMode, scale, exact, overflow, underflow, divideByZero); 322 return invokeObjcSuperClass!(Object, "decimalNumberHandlerWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:", uint, short, bool, bool, bool, bool)(roundingMode, scale, exact, overflow, underflow, divideByZero);
286 } 323 }
287 324
288 uint roundingMode () 325 uint roundingMode ()
289 { 326 {
290 return invokeObjcSelf!(uint, "roundingMode"); 327 return invokeObjcSelf!(uint, "roundingMode");
310 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); 347 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
311 } 348 }
312 349
313 this (NSCoder aDecoder) 350 this (NSCoder aDecoder)
314 { 351 {
315 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 352 typeof(this).alloc.initWithCoder(aDecoder);
316 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
317
318 if (result)
319 objcObject = ret;
320
321 dObject = this;
322 } 353 }
323 } 354 }
324 355
325 interface INSDecimalNumberBehaviors 356 interface INSDecimalNumberBehaviors
326 { 357 {
327 uint roundingMode (); 358 uint roundingMode ();
328 short scale (); 359 short scale ();
329 NSDecimalNumber exceptionDuringOperation (SEL operation, uint error, NSDecimalNumber leftOperand, NSDecimalNumber rightOperand); 360 NSDecimalNumber exceptionDuringOperation (SEL operation, uint error, NSDecimalNumber leftOperand, NSDecimalNumber rightOperand);
330 } 361 }
331
332 template TNSDecimalNumberExtensions ()
333 {
334 NSDecimal decimalValue ()
335 {
336 return invokeObjcSelf!(NSDecimal, "decimalValue");
337 }
338 }
339
340 template TNSDecimalNumberScanning ()
341 {
342 bool scanDecimal (NSDecimal* dcm)
343 {
344 return invokeObjcSelf!(bool, "scanDecimal:", NSDecimal*)(dcm);
345 }
346 }
347