comparison dstep/foundation/NSBundle.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
10 import dstep.foundation.NSDictionary; 10 import dstep.foundation.NSDictionary;
11 import dstep.foundation.NSError; 11 import dstep.foundation.NSError;
12 import dstep.foundation.NSObject; 12 import dstep.foundation.NSObject;
13 import dstep.foundation.NSString; 13 import dstep.foundation.NSString;
14 import dstep.objc.bridge.Bridge; 14 import dstep.objc.bridge.Bridge;
15 import dstep.objc.objc : id; 15 import dstep.objc.objc;
16
17
16 18
17 import bindings = dstep.foundation.NSBundle_bindings; 19 import bindings = dstep.foundation.NSBundle_bindings;
18 20
19 const NSString NSBundleDidLoadNotification; 21 private
20 const NSString NSLoadedClasses; 22 {
23 NSString NSBundleDidLoadNotification_;
24 NSString NSLoadedClasses_;
25 }
26
27 NSString NSBundleDidLoadNotification ()
28 {
29 if (NSBundleDidLoadNotification_)
30 return NSBundleDidLoadNotification_;
31
32 return NSBundleDidLoadNotification_ = new NSString(bindings.NSBundleDidLoadNotification);
33 }
34
35 NSString NSLoadedClasses ()
36 {
37 if (NSLoadedClasses_)
38 return NSLoadedClasses_;
39
40 return NSLoadedClasses_ = new NSString(bindings.NSLoadedClasses);
41 }
21 42
22 enum 43 enum
23 { 44 {
24 NSBundleExecutableArchitectureI386 = 0x00000007, 45 NSBundleExecutableArchitectureI386 = 0x00000007,
25 NSBundleExecutableArchitecturePPC = 0x00000012, 46 NSBundleExecutableArchitecturePPC = 0x00000012,
26 NSBundleExecutableArchitectureX86_64 = 0x01000007, 47 NSBundleExecutableArchitectureX86_64 = 0x01000007,
27 NSBundleExecutableArchitecturePPC64 = 0x01000012 48 NSBundleExecutableArchitecturePPC64 = 0x01000012
28 } 49 }
29 50
30 static this ()
31 {
32 NSBundleDidLoadNotification = new NSString(bindings.NSBundleDidLoadNotification);
33 NSLoadedClasses = new NSString(bindings.NSLoadedClasses);
34 }
35
36 class NSBundle : NSObject 51 class NSBundle : NSObject
37 { 52 {
38 mixin ObjcWrap; 53 mixin (ObjcWrap);
54
55 this ()
56 {
57 super(typeof(this).alloc.init.objcObject);
58 }
59
60 typeof(this) init ()
61 {
62 return invokeObjcSelf!(typeof(this), "init");
63 }
39 64
40 static NSBundle mainBundle () 65 static NSBundle mainBundle ()
41 { 66 {
42 return invokeObjcSelfClass!(NSBundle, "mainBundle"); 67 return invokeObjcSuperClass!(NSBundle, "mainBundle");
43 } 68 }
44 69
45 static NSBundle bundleWithPath (NSString path) 70 static NSBundle bundleWithPath (NSString path)
46 { 71 {
47 return invokeObjcSelfClass!(NSBundle, "bundleWithPath:", NSString)(path); 72 return invokeObjcSuperClass!(NSBundle, "bundleWithPath:", NSString)(path);
48 } 73 }
49 74
50 Object initWithPath (NSString path) 75 Object initWithPath (NSString path)
51 { 76 {
52 return invokeObjcSelf!(Object, "initWithPath:", NSString)(path); 77 return invokeObjcSelf!(Object, "initWithPath:", NSString)(path);
53 } 78 }
54 79
55 this (NSString path) 80 this (NSString path)
56 { 81 {
57 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 82 typeof(this).alloc.initWithPath(path);
58 id result = Bridge.invokeObjcMethod!(id, "initWithPath:", NSString)(objcObject, path);
59
60 if (result)
61 objcObject = ret;
62
63 dObject = this;
64 } 83 }
65 84
66 static NSBundle bundleForClass (Class aClass) 85 static NSBundle bundleForClass (Class aClass)
67 { 86 {
68 return invokeObjcSelfClass!(NSBundle, "bundleForClass:", Class)(aClass); 87 return invokeObjcSuperClass!(NSBundle, "bundleForClass:", Class)(aClass);
69 } 88 }
70 89
71 static NSBundle bundleWithIdentifier (NSString identifier) 90 static NSBundle bundleWithIdentifier (NSString identifier)
72 { 91 {
73 return invokeObjcSelfClass!(NSBundle, "bundleWithIdentifier:", NSString)(identifier); 92 return invokeObjcSuperClass!(NSBundle, "bundleWithIdentifier:", NSString)(identifier);
74 } 93 }
75 94
76 static NSArray allBundles () 95 static NSArray allBundles ()
77 { 96 {
78 return invokeObjcSelfClass!(NSArray, "allBundles"); 97 return invokeObjcSuperClass!(NSArray, "allBundles");
79 } 98 }
80 99
81 static NSArray allFrameworks () 100 static NSArray allFrameworks ()
82 { 101 {
83 return invokeObjcSelfClass!(NSArray, "allFrameworks"); 102 return invokeObjcSuperClass!(NSArray, "allFrameworks");
84 } 103 }
85 104
86 bool load () 105 bool load ()
87 { 106 {
88 return invokeObjcSelf!(bool, "load"); 107 return invokeObjcSelf!(bool, "load");
96 bool unload () 115 bool unload ()
97 { 116 {
98 return invokeObjcSelf!(bool, "unload"); 117 return invokeObjcSelf!(bool, "unload");
99 } 118 }
100 119
101 bool preflightAndReturnError (NSError** error) 120 bool preflightAndReturnError (ref NSError error)
102 { 121 {
103 return invokeObjcSelf!(bool, "preflightAndReturnError:", NSError**)(error); 122 id err;
104 } 123
105 124 if (error)
106 bool loadAndReturnError (NSError** error) 125 err = new objc_object;
107 { 126
108 return invokeObjcSelf!(bool, "loadAndReturnError:", NSError**)(error); 127 bool result = invokeObjcSelf!(bool, "preflightAndReturnError:", id*)(&err);
128
129 if (err)
130 error = new NSError(err);
131
132 return result;
133 }
134
135 bool loadAndReturnError (ref NSError error)
136 {
137 id err;
138
139 if (error)
140 err = new objc_object;
141
142 bool result = invokeObjcSelf!(bool, "loadAndReturnError:", id*)(&err);
143
144 if (err)
145 error = new NSError(err);
146
147 return result;
109 } 148 }
110 149
111 NSString bundlePath () 150 NSString bundlePath ()
112 { 151 {
113 return invokeObjcSelf!(NSString, "bundlePath"); 152 return invokeObjcSelf!(NSString, "bundlePath");
163 return invokeObjcSelf!(Class, "principalClass"); 202 return invokeObjcSelf!(Class, "principalClass");
164 } 203 }
165 204
166 static NSString pathForResource (NSString name, NSString ext, NSString bundlePath) 205 static NSString pathForResource (NSString name, NSString ext, NSString bundlePath)
167 { 206 {
168 return invokeObjcSelfClass!(NSString, "pathForResource:ofType:inDirectory:", NSString, NSString, NSString)(name, ext, bundlePath); 207 return invokeObjcSuperClass!(NSString, "pathForResource:ofType:inDirectory:", NSString, NSString, NSString)(name, ext, bundlePath);
169 } 208 }
170 209
171 NSString pathForResource (NSString name, NSString ext) 210 NSString pathForResource (NSString name, NSString ext)
172 { 211 {
173 return invokeObjcSelf!(NSString, "pathForResource:ofType:", NSString, NSString)(name, ext); 212 return invokeObjcSelf!(NSString, "pathForResource:ofType:", NSString, NSString)(name, ext);
183 return invokeObjcSelf!(NSString, "pathForResource:ofType:inDirectory:forLocalization:", NSString, NSString, NSString, NSString)(name, ext, subpath, localizationName); 222 return invokeObjcSelf!(NSString, "pathForResource:ofType:inDirectory:forLocalization:", NSString, NSString, NSString, NSString)(name, ext, subpath, localizationName);
184 } 223 }
185 224
186 static NSArray pathsForResourcesOfType (NSString ext, NSString bundlePath) 225 static NSArray pathsForResourcesOfType (NSString ext, NSString bundlePath)
187 { 226 {
188 return invokeObjcSelfClass!(NSArray, "pathsForResourcesOfType:inDirectory:", NSString, NSString)(ext, bundlePath); 227 return invokeObjcSuperClass!(NSArray, "pathsForResourcesOfType:inDirectory:", NSString, NSString)(ext, bundlePath);
189 } 228 }
190 229
191 NSArray pathsForResourcesOfType (NSString ext, NSString subpath) 230 NSArray pathsForResourcesOfType (NSString ext, NSString subpath)
192 { 231 {
193 return invokeObjcSelf!(NSArray, "pathsForResourcesOfType:inDirectory:", NSString, NSString)(ext, subpath); 232 return invokeObjcSelf!(NSArray, "pathsForResourcesOfType:inDirectory:", NSString, NSString)(ext, subpath);
233 return invokeObjcSelf!(NSString, "developmentLocalization"); 272 return invokeObjcSelf!(NSString, "developmentLocalization");
234 } 273 }
235 274
236 static NSArray preferredLocalizationsFromArray (NSArray localizationsArray) 275 static NSArray preferredLocalizationsFromArray (NSArray localizationsArray)
237 { 276 {
238 return invokeObjcSelfClass!(NSArray, "preferredLocalizationsFromArray:", NSArray)(localizationsArray); 277 return invokeObjcSuperClass!(NSArray, "preferredLocalizationsFromArray:", NSArray)(localizationsArray);
239 } 278 }
240 279
241 static NSArray preferredLocalizationsFromArray (NSArray localizationsArray, NSArray preferencesArray) 280 static NSArray preferredLocalizationsFromArray (NSArray localizationsArray, NSArray preferencesArray)
242 { 281 {
243 return invokeObjcSelfClass!(NSArray, "preferredLocalizationsFromArray:forPreferences:", NSArray, NSArray)(localizationsArray, preferencesArray); 282 return invokeObjcSuperClass!(NSArray, "preferredLocalizationsFromArray:forPreferences:", NSArray, NSArray)(localizationsArray, preferencesArray);
244 } 283 }
245 284
246 NSArray executableArchitectures () 285 NSArray executableArchitectures ()
247 { 286 {
248 return invokeObjcSelf!(NSArray, "executableArchitectures"); 287 return invokeObjcSelf!(NSArray, "executableArchitectures");