comparison dwt/internal/cocoa/NSNumber.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents f565d3a95c0a
children
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2007 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * 10 *
11 * Port to the D programming language: 11 * Port to the D programming language:
12 * Jacob Carlborg <jacob.carlborg@gmail.com> 12 * Jacob Carlborg <doob@me.com>
13 *******************************************************************************/ 13 *******************************************************************************/
14 module dwt.internal.cocoa.NSNumber; 14 module dwt.internal.cocoa.NSNumber;
15 15
16 import dwt.internal.cocoa.id; 16 import dwt.dwthelper.utils;
17 import dwt.internal.cocoa.NSComparisonResult; 17 import cocoa = dwt.internal.cocoa.id;
18 import dwt.internal.cocoa.NSDecimal; 18 import dwt.internal.cocoa.NSPoint;
19 import dwt.internal.cocoa.NSString; 19 import dwt.internal.cocoa.NSRange;
20 import dwt.internal.cocoa.NSRect;
21 import dwt.internal.cocoa.NSSize;
20 import dwt.internal.cocoa.NSValue; 22 import dwt.internal.cocoa.NSValue;
21 import dwt.internal.cocoa.OS; 23 import dwt.internal.cocoa.OS;
24 import dwt.internal.objc.cocoa.Cocoa;
22 import objc = dwt.internal.objc.runtime; 25 import objc = dwt.internal.objc.runtime;
23 26
24 public class NSNumber : NSValue 27 public class NSNumber : NSValue {
25 {
26 28
27 public this () 29 public this() {
28 { 30 super();
29 super(); 31 }
30 }
31 32
32 public this (objc.id id) 33 public this(objc.id id) {
33 { 34 super(id);
34 super(id); 35 }
35 }
36 36
37 public bool boolValue () 37 public this(cocoa.id id) {
38 { 38 super(id);
39 return OS.objc_msgSend(this.id_, OS.sel_boolValue) !is null; 39 }
40 }
41 40
42 public byte charValue () 41 public int intValue() {
43 { 42 return cast(int)/*64*/OS.objc_msgSend(this.id, OS.sel_intValue);
44 return cast(byte) OS.objc_msgSend(this.id_, OS.sel_charValue); 43 }
45 }
46 44
47 public NSComparisonResult compare (NSNumber otherNumber) 45 public static NSNumber numberWithBool(bool value) {
48 { 46 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithBool_, value);
49 return cast(NSComparisonResult) OS.objc_msgSend(this.id_, OS.sel_compare_1, otherNumber !is null ? otherNumber.id_ : null); 47 return result !is null ? new NSNumber(result) : null;
50 } 48 }
51 49
52 public NSDecimal decimalValue () 50 public static NSNumber numberWithInt(int value) {
53 { 51 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithInt_, value);
54 NSDecimal result; 52 return result !is null ? new NSNumber(result) : null;
55 OS.objc_msgSend_stret(&result, this.id_, OS.sel_decimalValue); 53 }
56 return result;
57 }
58 54
59 public NSString descriptionWithLocale (id locale) 55 public static NSNumber numberWithInteger(NSInteger value) {
60 { 56 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithInteger_, value);
61 objc.id result = OS.objc_msgSend(this.id_, OS.sel_descriptionWithLocale_1, locale !is null ? locale.id_ : null); 57 return result !is null ? new NSNumber(result) : null;
62 return result !is null ? new NSString(result) : null; 58 }
63 }
64 59
65 public double doubleValue () 60 public static NSValue valueWithPoint(NSPoint point) {
66 { 61 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_valueWithPoint_, point);
67 return OS.objc_msgSend_fpret(this.id_, OS.sel_doubleValue); 62 return result !is null ? new NSValue(result) : null;
68 } 63 }
69 64
70 public float floatValue () 65 public static NSValue valueWithRange(NSRange range) {
71 { 66 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_valueWithRange_, range);
72 return cast(float) OS.objc_msgSend_fpret(this.id_, OS.sel_floatValue); 67 return result !is null ? new NSValue(result) : null;
73 } 68 }
74 69
75 public id initWithBool (bool value) 70 public static NSValue valueWithRect(NSRect rect) {
76 { 71 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_valueWithRect_, rect);
77 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithBool_1, value); 72 return result !is null ? new NSValue(result) : null;
78 return result !is null ? new id(result) : null; 73 }
79 }
80 74
81 public id initWithChar (byte value) 75 public static NSValue valueWithSize(NSSize size) {
82 { 76 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_valueWithSize_, size);
83 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithChar_1, value); 77 return result !is null ? new NSValue(result) : null;
84 return result !is null ? new id(result) : null; 78 }
85 }
86
87 public id initWithDouble (double value)
88 {
89 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithDouble_1, value);
90 return result !is null ? new id(result) : null;
91 }
92
93 public id initWithFloat (float value)
94 {
95 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithFloat_1, value);
96 return result !is null ? new id(result) : null;
97 }
98
99 public id initWithInt (int value)
100 {
101 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithInt_1, value);
102 return result !is null ? new id(result) : null;
103 }
104
105 public id initWithInteger (int value)
106 {
107 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithInteger_1, value);
108 return result !is null ? new id(result) : null;
109 }
110
111 public id initWithLong (int value)
112 {
113 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithLong_1, value);
114 return result !is null ? new id(result) : null;
115 }
116
117 public id initWithLongLong (long value)
118 {
119 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithLongLong_1, value);
120 return result !is null ? new id(result) : null;
121 }
122
123 public id initWithShort (short value)
124 {
125 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithShort_1, value);
126 return result !is null ? new id(result) : null;
127 }
128
129 public id initWithUnsignedChar (ubyte value)
130 {
131 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithUnsignedChar_1, value);
132 return result !is null ? new id(result) : null;
133 }
134
135 public id initWithUnsignedInt (uint value)
136 {
137 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithUnsignedInt_1, value);
138 return result !is null ? new id(result) : null;
139 }
140
141 public id initWithUnsignedInteger (uint value)
142 {
143 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithUnsignedInteger_1, value);
144 return result !is null ? new id(result) : null;
145 }
146
147 public id initWithUnsignedLong (uint value)
148 {
149 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithUnsignedLong_1, value);
150 return result !is null ? new id(result) : null;
151 }
152
153 public id initWithUnsignedLongLong (ulong value)
154 {
155 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithUnsignedLongLong_1, value);
156 return result !is null ? new id(result) : null;
157 }
158
159 public id initWithUnsignedShort (ushort value)
160 {
161 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithUnsignedShort_1, value);
162 return result !is null ? new id(result) : null;
163 }
164
165 public int intValue ()
166 {
167 return cast(int)OS.objc_msgSend(this.id_, OS.sel_intValue);
168 }
169
170 public int integerValue ()
171 {
172 return cast(int)OS.objc_msgSend(this.id_, OS.sel_integerValue);
173 }
174
175 public bool isEqualToNumber (NSNumber number)
176 {
177 return OS.objc_msgSend(this.id_, OS.sel_isEqualToNumber_1, number !is null ? number.id_ : null) !is null;
178 }
179
180 public long longLongValue ()
181 {
182 return cast(long) OS.objc_msgSend(this.id_, OS.sel_longLongValue);
183 }
184
185 public int longValue ()
186 {
187 return cast(int)OS.objc_msgSend(this.id_, OS.sel_longValue);
188 }
189
190 public static NSNumber numberWithBool (bool value)
191 {
192 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithBool_1, value);
193 return result !is null ? new NSNumber(result) : null;
194 }
195
196 public static NSNumber numberWithChar (byte value)
197 {
198 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithChar_1, value);
199 return result !is null ? new NSNumber(result) : null;
200 }
201
202 public static NSNumber numberWithDouble (double value)
203 {
204 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithDouble_1, value);
205 return result !is null ? new NSNumber(result) : null;
206 }
207
208 public static NSNumber numberWithFloat (float value)
209 {
210 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithFloat_1, value);
211 return result !is null ? new NSNumber(result) : null;
212 }
213
214 public static NSNumber numberWithInt (int value)
215 {
216 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithInt_1, value);
217 return result !is null ? new NSNumber(result) : null;
218 }
219
220 public static NSNumber numberWithInteger (int value)
221 {
222 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithInteger_1, value);
223 return result !is null ? new NSNumber(result) : null;
224 }
225
226 public static NSNumber numberWithLong (int value)
227 {
228 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithLong_1, value);
229 return result !is null ? new NSNumber(result) : null;
230 }
231
232 public static NSNumber numberWithLongLong (long value)
233 {
234 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithLongLong_1, value);
235 return result !is null ? new NSNumber(result) : null;
236 }
237
238 public static NSNumber numberWithShort (short value)
239 {
240 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithShort_1, value);
241 return result !is null ? new NSNumber(result) : null;
242 }
243
244 public static NSNumber numberWithUnsignedChar (ubyte value)
245 {
246 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithUnsignedChar_1, value);
247 return result !is null ? new NSNumber(result) : null;
248 }
249
250 public static NSNumber numberWithUnsignedInt (uint value)
251 {
252 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithUnsignedInt_1, value);
253 return result !is null ? new NSNumber(result) : null;
254 }
255
256 public static NSNumber numberWithUnsignedInteger (uint value)
257 {
258 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithUnsignedInteger_1, value);
259 return result !is null ? new NSNumber(result) : null;
260 }
261
262 public static NSNumber numberWithUnsignedLong (uint value)
263 {
264 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithUnsignedLong_1, value);
265 return result !is null ? new NSNumber(result) : null;
266 }
267
268 public static NSNumber numberWithUnsignedLongLong (ulong value)
269 {
270 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithUnsignedLongLong_1, value);
271 return result !is null ? new NSNumber(result) : null;
272 }
273
274 public static NSNumber numberWithUnsignedShort (ushort value)
275 {
276 objc.id result = OS.objc_msgSend(OS.class_NSNumber, OS.sel_numberWithUnsignedShort_1, value);
277 return result !is null ? new NSNumber(result) : null;
278 }
279
280 public short shortValue ()
281 {
282 return cast(short) OS.objc_msgSend(this.id_, OS.sel_shortValue);
283 }
284
285 public NSString stringValue ()
286 {
287 objc.id result = OS.objc_msgSend(this.id_, OS.sel_stringValue);
288 return result !is null ? new NSString(result) : null;
289 }
290
291 public ubyte unsignedCharValue ()
292 {
293 return cast(ubyte) OS.objc_msgSend(this.id_, OS.sel_unsignedCharValue);
294 }
295
296 public uint unsignedIntValue ()
297 {
298 return cast(uint)OS.objc_msgSend(this.id_, OS.sel_unsignedIntValue);
299 }
300
301 public uint unsignedIntegerValue ()
302 {
303 return cast(uint)OS.objc_msgSend(this.id_, OS.sel_unsignedIntegerValue);
304 }
305
306 public ulong unsignedLongLongValue ()
307 {
308 return cast(ulong) OS.objc_msgSend(this.id_, OS.sel_unsignedLongLongValue);
309 }
310
311 public uint unsignedLongValue ()
312 {
313 return cast(uint)OS.objc_msgSend(this.id_, OS.sel_unsignedLongValue);
314 }
315
316 public ushort unsignedShortValue ()
317 {
318 return cast(ushort) OS.objc_msgSend(this.id_, OS.sel_unsignedShortValue);
319 }
320 79
321 } 80 }