Mercurial > projects > dstep
comparison dstep/foundation/NSError.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.NSError; | |
8 | |
9 import dstep.foundation.NSArray; | |
10 import dstep.foundation.NSDictionary; | |
11 import dstep.foundation.NSObject; | |
12 import dstep.objc.bridge.Bridge; | |
13 import dstep.objc.objc : id; | |
14 | |
15 import bindings = dstep.foundation.NSError_bindings; | |
16 | |
17 const NSString NSCocoaErrorDomain; | |
18 const NSString NSPOSIXErrorDomain; | |
19 const NSString NSOSStatusErrorDomain; | |
20 const NSString NSMachErrorDomain; | |
21 const NSString NSUnderlyingErrorKey; | |
22 const NSString NSLocalizedDescriptionKey; | |
23 const NSString NSLocalizedFailureReasonErrorKey; | |
24 const NSString NSLocalizedRecoverySuggestionErrorKey; | |
25 const NSString NSLocalizedRecoveryOptionsErrorKey; | |
26 const NSString NSRecoveryAttempterErrorKey; | |
27 const NSString NSStringEncodingErrorKey; | |
28 const NSString NSURLErrorKey; | |
29 const NSString NSFilePathErrorKey; | |
30 | |
31 static this () | |
32 { | |
33 NSCocoaErrorDomain = new NSString(bindings.NSCocoaErrorDomain); | |
34 NSPOSIXErrorDomain = new NSString(bindings.NSPOSIXErrorDomain); | |
35 NSOSStatusErrorDomain = new NSString(bindings.NSOSStatusErrorDomain); | |
36 NSMachErrorDomain = new NSString(bindings.NSMachErrorDomain); | |
37 NSUnderlyingErrorKey = new NSString(bindings.NSUnderlyingErrorKey); | |
38 NSLocalizedDescriptionKey = new NSString(bindings.NSLocalizedDescriptionKey); | |
39 NSLocalizedFailureReasonErrorKey = new NSString(bindings.NSLocalizedFailureReasonErrorKey); | |
40 NSLocalizedRecoverySuggestionErrorKey = new NSString(bindings.NSLocalizedRecoverySuggestionErrorKey); | |
41 NSLocalizedRecoveryOptionsErrorKey = new NSString(bindings.NSLocalizedRecoveryOptionsErrorKey); | |
42 NSRecoveryAttempterErrorKey = new NSString(bindings.NSRecoveryAttempterErrorKey); | |
43 NSStringEncodingErrorKey = new NSString(bindings.NSStringEncodingErrorKey); | |
44 NSURLErrorKey = new NSString(bindings.NSURLErrorKey); | |
45 NSFilePathErrorKey = new NSString(bindings.NSFilePathErrorKey); | |
46 } | |
47 | |
48 class NSError : NSObject, INSCopying, INSCoding | |
49 { | |
50 mixin ObjcWrap; | |
51 | |
52 Object initWithDomain (NSString domain, NSInteger code, NSDictionary dict) | |
53 { | |
54 return invokeObjcSelf!(Object, "initWithDomain:code:userInfo:", NSString, NSInteger, NSDictionary)(domain, code, dict); | |
55 } | |
56 | |
57 this (NSString domain, NSInteger code, NSDictionary dict) | |
58 { | |
59 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
60 id result = Bridge.invokeObjcMethod!(id, "initWithDomain:code:userInfo:", NSString, NSInteger, NSDictionary)(objcObject, domain, code, dict); | |
61 | |
62 if (result) | |
63 objcObject = ret; | |
64 | |
65 dObject = this; | |
66 } | |
67 | |
68 static Object errorWithDomain (NSString domain, NSInteger code, NSDictionary dict) | |
69 { | |
70 return invokeObjcSelfClass!(Object, "errorWithDomain:code:userInfo:", NSString, NSInteger, NSDictionary)(domain, code, dict); | |
71 } | |
72 | |
73 NSString domain () | |
74 { | |
75 return invokeObjcSelf!(NSString, "domain"); | |
76 } | |
77 | |
78 NSInteger code () | |
79 { | |
80 return invokeObjcSelf!(NSInteger, "code"); | |
81 } | |
82 | |
83 NSDictionary userInfo () | |
84 { | |
85 return invokeObjcSelf!(NSDictionary, "userInfo"); | |
86 } | |
87 | |
88 NSString localizedDescription () | |
89 { | |
90 return invokeObjcSelf!(NSString, "localizedDescription"); | |
91 } | |
92 | |
93 NSString localizedFailureReason () | |
94 { | |
95 return invokeObjcSelf!(NSString, "localizedFailureReason"); | |
96 } | |
97 | |
98 NSString localizedRecoverySuggestion () | |
99 { | |
100 return invokeObjcSelf!(NSString, "localizedRecoverySuggestion"); | |
101 } | |
102 | |
103 NSArray localizedRecoveryOptions () | |
104 { | |
105 return invokeObjcSelf!(NSArray, "localizedRecoveryOptions"); | |
106 } | |
107 | |
108 Object recoveryAttempter () | |
109 { | |
110 return invokeObjcSelf!(Object, "recoveryAttempter"); | |
111 } | |
112 | |
113 Object copyWithZone (NSZone* zone) | |
114 { | |
115 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); | |
116 } | |
117 | |
118 void encodeWithCoder (NSCoder aCoder) | |
119 { | |
120 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); | |
121 } | |
122 | |
123 Object initWithCoder (NSCoder aDecoder) | |
124 { | |
125 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | |
126 } | |
127 | |
128 this (NSCoder aDecoder) | |
129 { | |
130 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
131 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | |
132 | |
133 if (result) | |
134 objcObject = ret; | |
135 | |
136 dObject = this; | |
137 } | |
138 } | |
139 | |
140 template TNSErrorRecoveryAttempting () | |
141 { | |
142 void attemptRecoveryFromError (NSError error, NSUInteger recoveryOptionIndex, Object delegate_, SEL didRecoverSelector, void* contextInfo); | |
143 bool attemptRecoveryFromError (NSError error, NSUInteger recoveryOptionIndex); | |
144 } | |
145 |