comparison dstep/foundation/NSException.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
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.NSException; 7 module dstep.foundation.NSException;
8 8
9 import dstep.foundation.NSArray; 9 import dstep.foundation.NSArray;
10 import dstep.foundation.NSAssertionHandler; 10 import dstep.foundation.NSCoder;
11 import dstep.foundation.NSDictionary; 11 import dstep.foundation.NSDictionary;
12 import dstep.foundation.NSObjCRuntime;
12 import dstep.foundation.NSObject; 13 import dstep.foundation.NSObject;
13 import dstep.foundation.NSString; 14 import dstep.foundation.NSString;
15 import dstep.foundation.NSZone;
14 import dstep.objc.bridge.Bridge; 16 import dstep.objc.bridge.Bridge;
15 import dstep.objc.objc : id; 17 import dstep.objc.objc;
16 import dstep.setjmp; 18
17 import dstep.stdarg; 19
18 20
19 import bindings = dstep.foundation.NSException_bindings; 21 import bindings = dstep.foundation.NSException_bindings;
20 22
21 extern (C) 23 extern (C)
22 { 24 {
23 alias void function (id) NSUncaughtExceptionHandler *; 25 alias void function (id) NSUncaughtExceptionHandler;
24 } 26 }
25 27
26 const NSString NSGenericException; 28 private
27 const NSString NSRangeException; 29 {
28 const NSString NSInvalidArgumentException; 30 NSString NSGenericException_;
29 const NSString NSInternalInconsistencyException; 31 NSString NSRangeException_;
30 const NSString NSMallocException; 32 NSString NSInvalidArgumentException_;
31 const NSString NSObjectInaccessibleException; 33 NSString NSInternalInconsistencyException_;
32 const NSString NSObjectNotAvailableException; 34 NSString NSMallocException_;
33 const NSString NSDestinationInvalidException; 35 NSString NSObjectInaccessibleException_;
34 const NSString NSPortTimeoutException; 36 NSString NSObjectNotAvailableException_;
35 const NSString NSInvalidSendPortException; 37 NSString NSDestinationInvalidException_;
36 const NSString NSInvalidReceivePortException; 38 NSString NSPortTimeoutException_;
37 const NSString NSPortSendException; 39 NSString NSInvalidSendPortException_;
38 const NSString NSPortReceiveException; 40 NSString NSInvalidReceivePortException_;
39 const NSString NSOldStyleException; 41 NSString NSPortSendException_;
40 42 NSString NSPortReceiveException_;
41 static this () 43 NSString NSOldStyleException_;
42 { 44 }
43 NSGenericException = new NSString(bindings.NSGenericException); 45
44 NSRangeException = new NSString(bindings.NSRangeException); 46 NSString NSGenericException ()
45 NSInvalidArgumentException = new NSString(bindings.NSInvalidArgumentException); 47 {
46 NSInternalInconsistencyException = new NSString(bindings.NSInternalInconsistencyException); 48 if (NSGenericException_)
47 NSMallocException = new NSString(bindings.NSMallocException); 49 return NSGenericException_;
48 NSObjectInaccessibleException = new NSString(bindings.NSObjectInaccessibleException); 50
49 NSObjectNotAvailableException = new NSString(bindings.NSObjectNotAvailableException); 51 return NSGenericException_ = new NSString(bindings.NSGenericException);
50 NSDestinationInvalidException = new NSString(bindings.NSDestinationInvalidException); 52 }
51 NSPortTimeoutException = new NSString(bindings.NSPortTimeoutException); 53
52 NSInvalidSendPortException = new NSString(bindings.NSInvalidSendPortException); 54 NSString NSRangeException ()
53 NSInvalidReceivePortException = new NSString(bindings.NSInvalidReceivePortException); 55 {
54 NSPortSendException = new NSString(bindings.NSPortSendException); 56 if (NSRangeException_)
55 NSPortReceiveException = new NSString(bindings.NSPortReceiveException); 57 return NSRangeException_;
56 NSOldStyleException = new NSString(bindings.NSOldStyleException); 58
57 } 59 return NSRangeException_ = new NSString(bindings.NSRangeException);
60 }
61
62 NSString NSInvalidArgumentException ()
63 {
64 if (NSInvalidArgumentException_)
65 return NSInvalidArgumentException_;
66
67 return NSInvalidArgumentException_ = new NSString(bindings.NSInvalidArgumentException);
68 }
69
70 NSString NSInternalInconsistencyException ()
71 {
72 if (NSInternalInconsistencyException_)
73 return NSInternalInconsistencyException_;
74
75 return NSInternalInconsistencyException_ = new NSString(bindings.NSInternalInconsistencyException);
76 }
77
78 NSString NSMallocException ()
79 {
80 if (NSMallocException_)
81 return NSMallocException_;
82
83 return NSMallocException_ = new NSString(bindings.NSMallocException);
84 }
85
86 NSString NSObjectInaccessibleException ()
87 {
88 if (NSObjectInaccessibleException_)
89 return NSObjectInaccessibleException_;
90
91 return NSObjectInaccessibleException_ = new NSString(bindings.NSObjectInaccessibleException);
92 }
93
94 NSString NSObjectNotAvailableException ()
95 {
96 if (NSObjectNotAvailableException_)
97 return NSObjectNotAvailableException_;
98
99 return NSObjectNotAvailableException_ = new NSString(bindings.NSObjectNotAvailableException);
100 }
101
102 NSString NSDestinationInvalidException ()
103 {
104 if (NSDestinationInvalidException_)
105 return NSDestinationInvalidException_;
106
107 return NSDestinationInvalidException_ = new NSString(bindings.NSDestinationInvalidException);
108 }
109
110 NSString NSPortTimeoutException ()
111 {
112 if (NSPortTimeoutException_)
113 return NSPortTimeoutException_;
114
115 return NSPortTimeoutException_ = new NSString(bindings.NSPortTimeoutException);
116 }
117
118 NSString NSInvalidSendPortException ()
119 {
120 if (NSInvalidSendPortException_)
121 return NSInvalidSendPortException_;
122
123 return NSInvalidSendPortException_ = new NSString(bindings.NSInvalidSendPortException);
124 }
125
126 NSString NSInvalidReceivePortException ()
127 {
128 if (NSInvalidReceivePortException_)
129 return NSInvalidReceivePortException_;
130
131 return NSInvalidReceivePortException_ = new NSString(bindings.NSInvalidReceivePortException);
132 }
133
134 NSString NSPortSendException ()
135 {
136 if (NSPortSendException_)
137 return NSPortSendException_;
138
139 return NSPortSendException_ = new NSString(bindings.NSPortSendException);
140 }
141
142 NSString NSPortReceiveException ()
143 {
144 if (NSPortReceiveException_)
145 return NSPortReceiveException_;
146
147 return NSPortReceiveException_ = new NSString(bindings.NSPortReceiveException);
148 }
149
150 NSString NSOldStyleException ()
151 {
152 if (NSOldStyleException_)
153 return NSOldStyleException_;
154
155 return NSOldStyleException_ = new NSString(bindings.NSOldStyleException);
156 }
157
158 const TNSExceptionRaisingConveniences = `
159
160 static void raise (NSString name, NSString format, ...)
161 {
162 return invokeObjcSuperClass!(void, "raise:format:", NSString, NSString)(name, format);
163 }
164
165 static void raise (NSString name, NSString format, char* argList)
166 {
167 return invokeObjcSuperClass!(void, "raise:format:arguments:", NSString, NSString, char*)(name, format, argList);
168 }
169 `;
58 170
59 class NSAssertionHandler : NSObject 171 class NSAssertionHandler : NSObject
60 { 172 {
61 mixin ObjcWrap; 173 mixin (ObjcWrap);
174
175 this ()
176 {
177 super(typeof(this).alloc.init.objcObject);
178 }
179
180 typeof(this) init ()
181 {
182 return invokeObjcSelf!(typeof(this), "init");
183 }
62 184
63 static NSAssertionHandler currentHandler () 185 static NSAssertionHandler currentHandler ()
64 { 186 {
65 return invokeObjcSelfClass!(NSAssertionHandler, "currentHandler"); 187 return invokeObjcSuperClass!(NSAssertionHandler, "currentHandler");
66 } 188 }
67 189
68 void handleFailureInMethod (SEL selector, Object object, NSString fileName, NSInteger line, NSString description, ...) 190 void handleFailureInMethod (SEL selector, Object object, NSString fileName, NSInteger line, NSString description, ...)
69 { 191 {
70 return invokeObjcSelf!(void, "handleFailureInMethod:object:file:lineNumber:description:", SEL, Object, NSString, NSInteger, NSString)(selector, object, fileName, line, description); 192 return invokeObjcSelf!(void, "handleFailureInMethod:object:file:lineNumber:description:", SEL, Object, NSString, NSInteger, NSString)(selector, object, fileName, line, description);
76 } 198 }
77 } 199 }
78 200
79 class NSException : NSObject, INSCopying, INSCoding 201 class NSException : NSObject, INSCopying, INSCoding
80 { 202 {
81 mixin ObjcWrap; 203 mixin (ObjcWrap);
82 mixin TNSExceptionRaisingConveniences; 204
205 this ()
206 {
207 super(typeof(this).alloc.init.objcObject);
208 }
209
210 typeof(this) init ()
211 {
212 return invokeObjcSelf!(typeof(this), "init");
213 }
83 214
84 static NSException exceptionWithName (NSString name, NSString reason, NSDictionary userInfo) 215 static NSException exceptionWithName (NSString name, NSString reason, NSDictionary userInfo)
85 { 216 {
86 return invokeObjcSelfClass!(NSException, "exceptionWithName:reason:userInfo:", NSString, NSString, NSDictionary)(name, reason, userInfo); 217 return invokeObjcSuperClass!(NSException, "exceptionWithName:reason:userInfo:", NSString, NSString, NSDictionary)(name, reason, userInfo);
87 } 218 }
88 219
89 Object initWithName (NSString aName, NSString aReason, NSDictionary aUserInfo) 220 Object initWithName (NSString aName, NSString aReason, NSDictionary aUserInfo)
90 { 221 {
91 return invokeObjcSelf!(Object, "initWithName:reason:userInfo:", NSString, NSString, NSDictionary)(aName, aReason, aUserInfo); 222 return invokeObjcSelf!(Object, "initWithName:reason:userInfo:", NSString, NSString, NSDictionary)(aName, aReason, aUserInfo);
92 } 223 }
93 224
94 this (NSString aName, NSString aReason, NSDictionary aUserInfo) 225 this (NSString aName, NSString aReason, NSDictionary aUserInfo)
95 { 226 {
96 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 227 typeof(this).alloc.initWithName(aName, aReason, aUserInfo);
97 id result = Bridge.invokeObjcMethod!(id, "initWithName:reason:userInfo:", NSString, NSString, NSDictionary)(objcObject, aName, aReason, aUserInfo);
98
99 if (result)
100 objcObject = ret;
101
102 dObject = this;
103 } 228 }
104 229
105 NSString name () 230 NSString name ()
106 { 231 {
107 return invokeObjcSelf!(NSString, "name"); 232 return invokeObjcSelf!(NSString, "name");
142 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); 267 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
143 } 268 }
144 269
145 this (NSCoder aDecoder) 270 this (NSCoder aDecoder)
146 { 271 {
147 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 272 typeof(this).alloc.initWithCoder(aDecoder);
148 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); 273 }
149 274
150 if (result) 275 // TNSExceptionRaisingConveniences
151 objcObject = ret;
152
153 dObject = this;
154 }
155 }
156
157 template TNSExceptionRaisingConveniences ()
158 {
159 static void raise (NSString name, NSString format, ...) 276 static void raise (NSString name, NSString format, ...)
160 { 277 {
161 return invokeObjcSelfClass!(void, "raise:format:", NSString, NSString)(name, format); 278 return invokeObjcSuperClass!(void, "raise:format:", NSString, NSString)(name, format);
162 } 279 }
163 280
164 static void raise (NSString name, NSString format, char* argList) 281 static void raise (NSString name, NSString format, char* argList)
165 { 282 {
166 return invokeObjcSelfClass!(void, "raise:format:arguments:", NSString, NSString, char*)(name, format, argList); 283 return invokeObjcSuperClass!(void, "raise:format:arguments:", NSString, NSString, char*)(name, format, argList);
167 } 284 }
168 } 285 }
169 286
170 extern (C) 287 extern (C)
171 { 288 {