Mercurial > projects > dstep
comparison dstep/foundation/NSURL.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 |
---|---|
4 * Version: Initial created: Aug 3, 2009 | 4 * Version: Initial created: Aug 3, 2009 |
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.NSURL; | 7 module dstep.foundation.NSURL; |
8 | 8 |
9 import dstep.foundation.NSCoder; | |
9 import dstep.foundation.NSData; | 10 import dstep.foundation.NSData; |
10 import dstep.foundation.NSDictionary; | 11 import dstep.foundation.NSDictionary; |
11 import dstep.foundation.NSNumber; | |
12 import dstep.foundation.NSObject; | 12 import dstep.foundation.NSObject; |
13 import dstep.foundation.NSString; | 13 import dstep.foundation.NSString; |
14 import dstep.foundation.NSURLHandle; | 14 import dstep.foundation.NSURLHandle; |
15 import dstep.foundation.NSValue; | |
16 import dstep.foundation.NSZone; | |
15 import dstep.objc.bridge.Bridge; | 17 import dstep.objc.bridge.Bridge; |
16 import dstep.objc.objc : id; | 18 import dstep.objc.objc; |
19 | |
20 | |
17 | 21 |
18 import bindings = dstep.foundation.NSURL_bindings; | 22 import bindings = dstep.foundation.NSURL_bindings; |
19 | 23 |
20 NSString NSURLFileScheme; | 24 private NSString NSURLFileScheme_; |
21 | 25 |
22 static this () | 26 NSString NSURLFileScheme () |
23 { | 27 { |
24 NSURLFileScheme = new NSString(bindings.NSURLFileScheme); | 28 if (NSURLFileScheme_) |
29 return NSURLFileScheme_; | |
30 | |
31 return NSURLFileScheme_ = new NSString(bindings.NSURLFileScheme); | |
25 } | 32 } |
26 | 33 |
27 class NSURL : NSObject, INSCoding, INSCopying, INSURLHandleClient | 34 class NSURL : NSObject, INSCoding, INSCopying, INSURLHandleClient |
28 { | 35 { |
29 mixin ObjcWrap; | 36 mixin (ObjcWrap); |
30 mixin TNSURLLoading; | 37 |
38 this () | |
39 { | |
40 super(typeof(this).alloc.init.objcObject); | |
41 } | |
42 | |
43 typeof(this) init () | |
44 { | |
45 return invokeObjcSelf!(typeof(this), "init"); | |
46 } | |
31 | 47 |
32 Object initWithScheme (NSString scheme, NSString host, NSString path) | 48 Object initWithScheme (NSString scheme, NSString host, NSString path) |
33 { | 49 { |
34 return invokeObjcSelf!(Object, "initWithScheme:host:path:", NSString, NSString, NSString)(scheme, host, path); | 50 return invokeObjcSelf!(Object, "initWithScheme:host:path:", NSString, NSString, NSString)(scheme, host, path); |
35 } | 51 } |
36 | 52 |
37 this (NSString scheme, NSString host, NSString path) | 53 this (NSString scheme, NSString host, NSString path) |
38 { | 54 { |
39 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 55 typeof(this).alloc.initWithScheme(scheme, host, path); |
40 id result = Bridge.invokeObjcMethod!(id, "initWithScheme:host:path:", NSString, NSString, NSString)(objcObject, scheme, host, path); | |
41 | |
42 if (result) | |
43 objcObject = ret; | |
44 | |
45 dObject = this; | |
46 } | 56 } |
47 | 57 |
48 Object initFileURLWithPath (NSString path, bool isDir) | 58 Object initFileURLWithPath (NSString path, bool isDir) |
49 { | 59 { |
50 return invokeObjcSelf!(Object, "initFileURLWithPath:isDirectory:", NSString, bool)(path, isDir); | 60 return invokeObjcSelf!(Object, "initFileURLWithPath:isDirectory:", NSString, bool)(path, isDir); |
51 } | 61 } |
52 | 62 |
53 this (NSString path, bool isDir) | 63 this (NSString path, bool isDir) |
54 { | 64 { |
55 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 65 typeof(this).alloc.initFileURLWithPath(path, isDir); |
56 id result = Bridge.invokeObjcMethod!(id, "initFileURLWithPath:isDirectory:", NSString, bool)(objcObject, path, isDir); | |
57 | |
58 if (result) | |
59 objcObject = ret; | |
60 | |
61 dObject = this; | |
62 } | 66 } |
63 | 67 |
64 Object initFileURLWithPath (NSString path) | 68 Object initFileURLWithPath (NSString path) |
65 { | 69 { |
66 return invokeObjcSelf!(Object, "initFileURLWithPath:", NSString)(path); | 70 return invokeObjcSelf!(Object, "initFileURLWithPath:", NSString)(path); |
67 } | 71 } |
68 | 72 |
69 this (NSString path) | |
70 { | |
71 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
72 id result = Bridge.invokeObjcMethod!(id, "initFileURLWithPath:", NSString)(objcObject, path); | |
73 | |
74 if (result) | |
75 objcObject = ret; | |
76 | |
77 dObject = this; | |
78 } | |
79 | |
80 static Object fileURLWithPath (NSString path, bool isDir) | 73 static Object fileURLWithPath (NSString path, bool isDir) |
81 { | 74 { |
82 return invokeObjcSelfClass!(Object, "fileURLWithPath:isDirectory:", NSString, bool)(path, isDir); | 75 return invokeObjcSuperClass!(Object, "fileURLWithPath:isDirectory:", NSString, bool)(path, isDir); |
83 } | 76 } |
84 | 77 |
85 static Object fileURLWithPath (NSString path) | 78 static Object fileURLWithPath (NSString path) |
86 { | 79 { |
87 return invokeObjcSelfClass!(Object, "fileURLWithPath:", NSString)(path); | 80 return invokeObjcSuperClass!(Object, "fileURLWithPath:", NSString)(path); |
88 } | 81 } |
89 | 82 |
90 Object initWithString (NSString URLString) | 83 Object initWithString (NSString URLString) |
91 { | 84 { |
92 return invokeObjcSelf!(Object, "initWithString:", NSString)(URLString); | 85 return invokeObjcSelf!(Object, "initWithString:", NSString)(URLString); |
93 } | 86 } |
94 | 87 |
95 this (NSString URLString) | 88 this (NSString URLString) |
96 { | 89 { |
97 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 90 typeof(this).alloc.initWithString(URLString); |
98 id result = Bridge.invokeObjcMethod!(id, "initWithString:", NSString)(objcObject, URLString); | |
99 | |
100 if (result) | |
101 objcObject = ret; | |
102 | |
103 dObject = this; | |
104 } | 91 } |
105 | 92 |
106 Object initWithString (NSString URLString, NSURL baseURL) | 93 Object initWithString (NSString URLString, NSURL baseURL) |
107 { | 94 { |
108 return invokeObjcSelf!(Object, "initWithString:relativeToURL:", NSString, NSURL)(URLString, baseURL); | 95 return invokeObjcSelf!(Object, "initWithString:relativeToURL:", NSString, NSURL)(URLString, baseURL); |
109 } | 96 } |
110 | 97 |
111 this (NSString URLString, NSURL baseURL) | 98 this (NSString URLString, NSURL baseURL) |
112 { | 99 { |
113 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 100 typeof(this).alloc.initWithString(URLString, baseURL); |
114 id result = Bridge.invokeObjcMethod!(id, "initWithString:relativeToURL:", NSString, NSURL)(objcObject, URLString, baseURL); | |
115 | |
116 if (result) | |
117 objcObject = ret; | |
118 | |
119 dObject = this; | |
120 } | 101 } |
121 | 102 |
122 static Object URLWithString (NSString URLString) | 103 static Object URLWithString (NSString URLString) |
123 { | 104 { |
124 return invokeObjcSelfClass!(Object, "URLWithString:", NSString)(URLString); | 105 return invokeObjcSuperClass!(Object, "URLWithString:", NSString)(URLString); |
125 } | 106 } |
126 | 107 |
127 static Object URLWithString (NSString URLString, NSURL baseURL) | 108 static Object URLWithString (NSString URLString, NSURL baseURL) |
128 { | 109 { |
129 return invokeObjcSelfClass!(Object, "URLWithString:relativeToURL:", NSString, NSURL)(URLString, baseURL); | 110 return invokeObjcSuperClass!(Object, "URLWithString:relativeToURL:", NSString, NSURL)(URLString, baseURL); |
130 } | 111 } |
131 | 112 |
132 NSString absoluteString () | 113 NSString absoluteString () |
133 { | 114 { |
134 return invokeObjcSelf!(NSString, "absoluteString"); | 115 return invokeObjcSelf!(NSString, "absoluteString"); |
227 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | 208 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); |
228 } | 209 } |
229 | 210 |
230 this (NSCoder aDecoder) | 211 this (NSCoder aDecoder) |
231 { | 212 { |
232 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 213 typeof(this).alloc.initWithCoder(aDecoder); |
233 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | |
234 | |
235 if (result) | |
236 objcObject = ret; | |
237 | |
238 dObject = this; | |
239 } | 214 } |
240 | 215 |
241 Object copyWithZone (NSZone* zone) | 216 Object copyWithZone (NSZone* zone) |
242 { | 217 { |
243 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); | 218 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); |
265 | 240 |
266 void URLHandle (NSURLHandle sender, NSString reason) | 241 void URLHandle (NSURLHandle sender, NSString reason) |
267 { | 242 { |
268 return invokeObjcSelf!(void, "URLHandle:resourceDidFailLoadingWithReason:", NSURLHandle, NSString)(sender, reason); | 243 return invokeObjcSelf!(void, "URLHandle:resourceDidFailLoadingWithReason:", NSURLHandle, NSString)(sender, reason); |
269 } | 244 } |
245 | |
246 // TNSURLLoading | |
247 NSData resourceDataUsingCache (bool shouldUseCache) | |
248 { | |
249 return invokeObjcSelf!(NSData, "resourceDataUsingCache:", bool)(shouldUseCache); | |
250 } | |
251 | |
252 void loadResourceDataNotifyingClient (Object client, bool shouldUseCache) | |
253 { | |
254 return invokeObjcSelf!(void, "loadResourceDataNotifyingClient:usingCache:", Object, bool)(client, shouldUseCache); | |
255 } | |
256 | |
257 Object propertyForKey (NSString propertyKey) | |
258 { | |
259 return invokeObjcSelf!(Object, "propertyForKey:", NSString)(propertyKey); | |
260 } | |
261 | |
262 bool setResourceData (NSData data) | |
263 { | |
264 return invokeObjcSelf!(bool, "setResourceData:", NSData)(data); | |
265 } | |
266 | |
267 bool setProperty (Object property, NSString propertyKey) | |
268 { | |
269 return invokeObjcSelf!(bool, "setProperty:forKey:", Object, NSString)(property, propertyKey); | |
270 } | |
271 | |
272 NSURLHandle URLHandleUsingCache (bool shouldUseCache) | |
273 { | |
274 return invokeObjcSelf!(NSURLHandle, "URLHandleUsingCache:", bool)(shouldUseCache); | |
275 } | |
270 } | 276 } |
271 | 277 |
272 template TNSURLLoading () | 278 const TNSURLLoading = ` |
273 { | 279 |
274 NSData resourceDataUsingCache (bool shouldUseCache) | 280 NSData resourceDataUsingCache (bool shouldUseCache) |
275 { | 281 { |
276 return invokeObjcSelf!(NSData, "resourceDataUsingCache:", bool)(shouldUseCache); | 282 return invokeObjcSelf!(NSData, "resourceDataUsingCache:", bool)(shouldUseCache); |
277 } | 283 } |
278 | 284 |
298 | 304 |
299 NSURLHandle URLHandleUsingCache (bool shouldUseCache) | 305 NSURLHandle URLHandleUsingCache (bool shouldUseCache) |
300 { | 306 { |
301 return invokeObjcSelf!(NSURLHandle, "URLHandleUsingCache:", bool)(shouldUseCache); | 307 return invokeObjcSelf!(NSURLHandle, "URLHandleUsingCache:", bool)(shouldUseCache); |
302 } | 308 } |
303 } | 309 `; |
304 | 310 |
305 template TNSURLClient () | 311 const TNSURLClient = ` |
306 { | 312 |
307 void URL (NSURL sender, NSData newBytes); | 313 void URL (NSURL sender, NSData newBytes) |
308 void URLResourceDidFinishLoading (NSURL sender); | 314 { |
309 void URLResourceDidCancelLoading (NSURL sender); | 315 return invokeObjcSelf!(void, "URL:resourceDataDidBecomeAvailable:", NSURL, NSData)(sender, newBytes); |
310 void URL (NSURL sender, NSString reason); | 316 } |
311 } | 317 |
312 | 318 void URLResourceDidFinishLoading (NSURL sender) |
313 template TNSURLUtilities () | 319 { |
314 { | 320 return invokeObjcSelf!(void, "URLResourceDidFinishLoading:", NSURL)(sender); |
321 } | |
322 | |
323 void URLResourceDidCancelLoading (NSURL sender) | |
324 { | |
325 return invokeObjcSelf!(void, "URLResourceDidCancelLoading:", NSURL)(sender); | |
326 } | |
327 | |
328 void URL (NSURL sender, NSString reason) | |
329 { | |
330 return invokeObjcSelf!(void, "URL:resourceDidFailLoadingWithReason:", NSURL, NSString)(sender, reason); | |
331 } | |
332 | |
333 //mixin ObjcBindMethod!(URL, "URL:resourceDataDidBecomeAvailable:"); | |
334 //mixin ObjcBindMethod!(URLResourceDidFinishLoading, "URLResourceDidFinishLoading:"); | |
335 //mixin ObjcBindMethod!(URLResourceDidCancelLoading, "URLResourceDidCancelLoading:"); | |
336 //mixin ObjcBindMethod!(URL, "URL:resourceDidFailLoadingWithReason:"); | |
337 `; | |
338 | |
339 const TNSURLUtilities = ` | |
340 | |
315 NSString stringByAddingPercentEscapesUsingEncoding (uint enc) | 341 NSString stringByAddingPercentEscapesUsingEncoding (uint enc) |
316 { | 342 { |
317 return invokeObjcSelf!(NSString, "stringByAddingPercentEscapesUsingEncoding:", uint)(enc); | 343 return invokeObjcSelf!(NSString, "stringByAddingPercentEscapesUsingEncoding:", uint)(enc); |
318 } | 344 } |
319 | 345 |
320 NSString stringByReplacingPercentEscapesUsingEncoding (uint enc) | 346 NSString stringByReplacingPercentEscapesUsingEncoding (uint enc) |
321 { | 347 { |
322 return invokeObjcSelf!(NSString, "stringByReplacingPercentEscapesUsingEncoding:", uint)(enc); | 348 return invokeObjcSelf!(NSString, "stringByReplacingPercentEscapesUsingEncoding:", uint)(enc); |
323 } | 349 } |
324 } | 350 `; |
325 |