Mercurial > projects > dstep
comparison dstep/foundation/NSDecimalNumber.d @ 14:89f3c3ef1fd2
Added the Foundation framework
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:23:15 +0200 |
parents | |
children | 7ff919f595d5 |
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.NSDecimalNumber; | |
8 | |
9 import dstep.foundation.NSDecimal; | |
10 import dstep.foundation.NSDictionary; | |
11 import dstep.foundation.NSScanner; | |
12 import dstep.foundation.NSValue; | |
13 import dstep.objc.bridge.Bridge; | |
14 import dstep.objc.objc : id; | |
15 | |
16 import bindings = dstep.foundation.NSDecimalNumber_bindings; | |
17 | |
18 const NSString NSDecimalNumberExactnessException; | |
19 const NSString NSDecimalNumberOverflowException; | |
20 const NSString NSDecimalNumberUnderflowException; | |
21 const NSString NSDecimalNumberDivideByZeroException; | |
22 | |
23 static this () | |
24 { | |
25 NSDecimalNumberExactnessException = new NSString(bindings.NSDecimalNumberExactnessException); | |
26 NSDecimalNumberOverflowException = new NSString(bindings.NSDecimalNumberOverflowException); | |
27 NSDecimalNumberUnderflowException = new NSString(bindings.NSDecimalNumberUnderflowException); | |
28 NSDecimalNumberDivideByZeroException = new NSString(bindings.NSDecimalNumberDivideByZeroException); | |
29 } | |
30 | |
31 class NSDecimalNumber : NSNumber | |
32 { | |
33 mixin ObjcWrap; | |
34 | |
35 Object initWithMantissa (ulong mantissa, short exponent, bool flag) | |
36 { | |
37 return invokeObjcSelf!(Object, "initWithMantissa:exponent:isNegative:", ulong, short, bool)(mantissa, exponent, flag); | |
38 } | |
39 | |
40 this (ulong mantissa, short exponent, bool flag) | |
41 { | |
42 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
43 id result = Bridge.invokeObjcMethod!(id, "initWithMantissa:exponent:isNegative:", ulong, short, bool)(objcObject, mantissa, exponent, flag); | |
44 | |
45 if (result) | |
46 objcObject = ret; | |
47 | |
48 dObject = this; | |
49 } | |
50 | |
51 Object initWithDecimal (NSDecimal dcm) | |
52 { | |
53 return invokeObjcSelf!(Object, "initWithDecimal:", NSDecimal)(dcm); | |
54 } | |
55 | |
56 this (NSDecimal dcm) | |
57 { | |
58 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
59 id result = Bridge.invokeObjcMethod!(id, "initWithDecimal:", NSDecimal)(objcObject, dcm); | |
60 | |
61 if (result) | |
62 objcObject = ret; | |
63 | |
64 dObject = this; | |
65 } | |
66 | |
67 Object initWithString (NSString numberValue) | |
68 { | |
69 return invokeObjcSelf!(Object, "initWithString:", NSString)(numberValue); | |
70 } | |
71 | |
72 this (NSString numberValue) | |
73 { | |
74 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
75 id result = Bridge.invokeObjcMethod!(id, "initWithString:", NSString)(objcObject, numberValue); | |
76 | |
77 if (result) | |
78 objcObject = ret; | |
79 | |
80 dObject = this; | |
81 } | |
82 | |
83 Object initWithString (NSString numberValue, Object locale) | |
84 { | |
85 return invokeObjcSelf!(Object, "initWithString:locale:", NSString, Object)(numberValue, locale); | |
86 } | |
87 | |
88 this (NSString numberValue, Object locale) | |
89 { | |
90 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
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 } | |
98 | |
99 NSString descriptionWithLocale (Object locale) | |
100 { | |
101 return invokeObjcSelf!(NSString, "descriptionWithLocale:", Object)(locale); | |
102 } | |
103 | |
104 NSDecimal decimalValue () | |
105 { | |
106 return invokeObjcSelf!(NSDecimal, "decimalValue"); | |
107 } | |
108 | |
109 static NSDecimalNumber decimalNumberWithMantissa (ulong mantissa, short exponent, bool flag) | |
110 { | |
111 return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithMantissa:exponent:isNegative:", ulong, short, bool)(mantissa, exponent, flagreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
112 | |
113 static NSDecimalNumber decimalNumberWithDecimal (NSDecimal dcm) | |
114 { | |
115 return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithDecimal:", NSDecimal)(dcmreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
116 | |
117 static NSDecimalNumber decimalNumberWithString (NSString numberValue) | |
118 { | |
119 return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithString:", NSString)(numberValuereturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
120 | |
121 static NSDecimalNumber decimalNumberWithString (NSString numberValue, Object locale) | |
122 { | |
123 return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithString:locale:", NSString, Object)(numberValue, localereturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
124 | |
125 static NSDecimalNumber zero () | |
126 { | |
127 return invokeObjcSelfClass!(NSDecimalNumber, "zero"return result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
128 | |
129 static NSDecimalNumber one () | |
130 { | |
131 return invokeObjcSelfClass!(NSDecimalNumber, "one"return result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
132 | |
133 static NSDecimalNumber minimumDecimalNumber () | |
134 { | |
135 return invokeObjcSelfClass!(NSDecimalNumber, "minimumDecimalNumber"return result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
136 | |
137 static NSDecimalNumber maximumDecimalNumber () | |
138 { | |
139 return invokeObjcSelfClass!(NSDecimalNumber, "maximumDecimalNumber"return result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
140 | |
141 static NSDecimalNumber notANumber () | |
142 { | |
143 return invokeObjcSelfClass!(NSDecimalNumber, "notANumber"return result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
144 | |
145 NSDecimalNumber decimalNumberByAdding (NSDecimalNumber decimalNumber) | |
146 { | |
147 id result = invokeObjcSelf!(id, "decimalNumberByAdding:", NSDecimalNumber)(decimalNumberreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
148 | |
149 NSDecimalNumber decimalNumberByAdding (NSDecimalNumber decimalNumber, INSDecimalNumberBehaviors behavior) | |
150 { | |
151 id result = invokeObjcSelf!(id, "decimalNumberByAdding:withBehavior:", NSDecimalNumber, INSDecimalNumberBehaviors)(decimalNumber, behaviorreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
152 | |
153 NSDecimalNumber decimalNumberBySubtracting (NSDecimalNumber decimalNumber) | |
154 { | |
155 id result = invokeObjcSelf!(id, "decimalNumberBySubtracting:", NSDecimalNumber)(decimalNumberreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
156 | |
157 NSDecimalNumber decimalNumberBySubtracting (NSDecimalNumber decimalNumber, INSDecimalNumberBehaviors behavior) | |
158 { | |
159 id result = invokeObjcSelf!(id, "decimalNumberBySubtracting:withBehavior:", NSDecimalNumber, INSDecimalNumberBehaviors)(decimalNumber, behaviorreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
160 | |
161 NSDecimalNumber decimalNumberByMultiplyingBy (NSDecimalNumber decimalNumber) | |
162 { | |
163 id result = invokeObjcSelf!(id, "decimalNumberByMultiplyingBy:", NSDecimalNumber)(decimalNumberreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
164 | |
165 NSDecimalNumber decimalNumberByMultiplyingBy (NSDecimalNumber decimalNumber, INSDecimalNumberBehaviors behavior) | |
166 { | |
167 id result = invokeObjcSelf!(id, "decimalNumberByMultiplyingBy:withBehavior:", NSDecimalNumber, INSDecimalNumberBehaviors)(decimalNumber, behaviorreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
168 | |
169 NSDecimalNumber decimalNumberByDividingBy (NSDecimalNumber decimalNumber) | |
170 { | |
171 id result = invokeObjcSelf!(id, "decimalNumberByDividingBy:", NSDecimalNumber)(decimalNumberreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
172 | |
173 NSDecimalNumber decimalNumberByDividingBy (NSDecimalNumber decimalNumber, INSDecimalNumberBehaviors behavior) | |
174 { | |
175 id result = invokeObjcSelf!(id, "decimalNumberByDividingBy:withBehavior:", NSDecimalNumber, INSDecimalNumberBehaviors)(decimalNumber, behaviorreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
176 | |
177 NSDecimalNumber decimalNumberByRaisingToPower (NSUInteger power) | |
178 { | |
179 id result = invokeObjcSelf!(id, "decimalNumberByRaisingToPower:", NSUInteger)(powerreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
180 | |
181 NSDecimalNumber decimalNumberByRaisingToPower (NSUInteger power, INSDecimalNumberBehaviors behavior) | |
182 { | |
183 id result = invokeObjcSelf!(id, "decimalNumberByRaisingToPower:withBehavior:", NSUInteger, INSDecimalNumberBehaviors)(power, behaviorreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
184 | |
185 NSDecimalNumber decimalNumberByMultiplyingByPowerOf10 (short power) | |
186 { | |
187 id result = invokeObjcSelf!(id, "decimalNumberByMultiplyingByPowerOf10:", short)(powerreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
188 | |
189 NSDecimalNumber decimalNumberByMultiplyingByPowerOf10 (short power, INSDecimalNumberBehaviors behavior) | |
190 { | |
191 id result = invokeObjcSelf!(id, "decimalNumberByMultiplyingByPowerOf10:withBehavior:", short, INSDecimalNumberBehaviors)(power, behaviorreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
192 | |
193 NSDecimalNumber decimalNumberByRoundingAccordingToBehavior (INSDecimalNumberBehaviors behavior) | |
194 { | |
195 id result = invokeObjcSelf!(id, "decimalNumberByRoundingAccordingToBehavior:", INSDecimalNumberBehaviors)(behaviorreturn result is this.objcObject ? this : (result !is null ? new NSDecimalNumber(result) : null); } | |
196 | |
197 int compare (NSNumber decimalNumber) | |
198 { | |
199 return invokeObjcSelf!(int, "compare:", NSNumber)(decimalNumber); | |
200 } | |
201 | |
202 static void setDefaultBehavior (INSDecimalNumberBehaviors behavior) | |
203 { | |
204 return invokeObjcSelfClass!(void, "setDefaultBehavior:", INSDecimalNumberBehaviors)(behavior); | |
205 } | |
206 | |
207 static INSDecimalNumberBehaviors defaultBehavior () | |
208 { | |
209 return invokeObjcSelfClass!(INSDecimalNumberBehaviors, "defaultBehavior"); | |
210 } | |
211 | |
212 char* objCType () | |
213 { | |
214 return invokeObjcSelf!(char*, "objCType"); | |
215 } | |
216 | |
217 double doubleValue () | |
218 { | |
219 return invokeObjcSelf!(double, "doubleValue"); | |
220 } | |
221 } | |
222 | |
223 class NSDecimalNumberHandler : NSObject, INSDecimalNumberBehaviors, INSCoding | |
224 { | |
225 mixin ObjcWrap; | |
226 | |
227 static Object defaultDecimalNumberHandler () | |
228 { | |
229 return invokeObjcSelfClass!(Object, "defaultDecimalNumberHandler"); | |
230 } | |
231 | |
232 Object initWithRoundingMode (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero) | |
233 { | |
234 return invokeObjcSelf!(Object, "initWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:", uint, short, bool, bool, bool, bool)(roundingMode, scale, exact, overflow, underflow, divideByZero); | |
235 } | |
236 | |
237 this (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero) | |
238 { | |
239 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
240 id result = Bridge.invokeObjcMethod!(id, "initWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:", uint, short, bool, bool, bool, bool)(objcObject, roundingMode, scale, exact, overflow, underflow, divideByZero); | |
241 | |
242 if (result) | |
243 objcObject = ret; | |
244 | |
245 dObject = this; | |
246 } | |
247 | |
248 static Object decimalNumberHandlerWithRoundingMode (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero) | |
249 { | |
250 return invokeObjcSelfClass!(Object, "decimalNumberHandlerWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:", uint, short, bool, bool, bool, bool)(roundingMode, scale, exact, overflow, underflow, divideByZero); | |
251 } | |
252 | |
253 uint roundingMode () | |
254 { | |
255 return invokeObjcSelf!(uint, "roundingMode"); | |
256 } | |
257 | |
258 short scale () | |
259 { | |
260 return invokeObjcSelf!(short, "scale"); | |
261 } | |
262 | |
263 NSDecimalNumber exceptionDuringOperation (SEL operation, uint error, NSDecimalNumber leftOperand, NSDecimalNumber rightOperand) | |
264 { | |
265 return invokeObjcSelf!(NSDecimalNumber, "exceptionDuringOperation:error:leftOperand:rightOperand:", SEL, uint, NSDecimalNumber, NSDecimalNumber)(operation, error, leftOperand, rightOperand); | |
266 } | |
267 | |
268 void encodeWithCoder (NSCoder aCoder) | |
269 { | |
270 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); | |
271 } | |
272 | |
273 Object initWithCoder (NSCoder aDecoder) | |
274 { | |
275 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | |
276 } | |
277 | |
278 this (NSCoder aDecoder) | |
279 { | |
280 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
281 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | |
282 | |
283 if (result) | |
284 objcObject = ret; | |
285 | |
286 dObject = this; | |
287 } | |
288 } | |
289 | |
290 interface INSDecimalNumberBehaviors | |
291 { | |
292 uint roundingMode (); | |
293 short scale (); | |
294 NSDecimalNumber exceptionDuringOperation (SEL operation, uint error, NSDecimalNumber leftOperand, NSDecimalNumber rightOperand); | |
295 } | |
296 | |
297 template TNSDecimalNumberExtensions () | |
298 { | |
299 NSDecimal decimalValue () | |
300 { | |
301 return invokeObjcSelf!(NSDecimal, "decimalValue"); | |
302 } | |
303 } | |
304 | |
305 template TNSDecimalNumberScanning () | |
306 { | |
307 bool scanDecimal (NSDecimal* dcm) | |
308 { | |
309 return invokeObjcSelf!(bool, "scanDecimal:", NSDecimal*)(dcm); | |
310 } | |
311 } | |
312 |