Mercurial > projects > dstep
comparison dstep/foundation/NSData.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 | 89f3c3ef1fd2 |
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.NSData; | 7 module dstep.foundation.NSData; |
8 | 8 |
9 import dstep.foundation.NSCoder; | |
9 import dstep.foundation.NSError; | 10 import dstep.foundation.NSError; |
11 import dstep.foundation.NSObjCRuntime; | |
10 import dstep.foundation.NSObject; | 12 import dstep.foundation.NSObject; |
11 import dstep.foundation.NSRange; | 13 import dstep.foundation.NSRange; |
12 import dstep.foundation.NSString; | 14 import dstep.foundation.NSString; |
13 import dstep.foundation.NSURL; | 15 import dstep.foundation.NSURL; |
16 import dstep.foundation.NSZone; | |
14 import dstep.objc.bridge.Bridge; | 17 import dstep.objc.bridge.Bridge; |
15 import dstep.objc.objc : id; | 18 import dstep.objc.objc; |
16 | 19 |
17 enum | 20 enum |
18 { | 21 { |
19 NSMappedRead = 1, | 22 NSMappedRead = 1, |
20 NSUncachedRead = 2 | 23 NSUncachedRead = 2 |
23 enum | 26 enum |
24 { | 27 { |
25 NSAtomicWrite = 1 | 28 NSAtomicWrite = 1 |
26 } | 29 } |
27 | 30 |
31 const TNSDataCreation = ` | |
32 | |
33 static Object data () | |
34 { | |
35 return invokeObjcSuperClass!(Object, "data"); | |
36 } | |
37 | |
38 static Object dataWithBytes (void* bytes, NSUInteger length) | |
39 { | |
40 return invokeObjcSuperClass!(Object, "dataWithBytes:length:", void*, NSUInteger)(bytes, length); | |
41 } | |
42 | |
43 static Object dataWithBytesNoCopy (void* bytes, NSUInteger length) | |
44 { | |
45 return invokeObjcSuperClass!(Object, "dataWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); | |
46 } | |
47 | |
48 static Object dataWithBytesNoCopy (void* bytes, NSUInteger length, bool b) | |
49 { | |
50 return invokeObjcSuperClass!(Object, "dataWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(bytes, length, b); | |
51 } | |
52 | |
53 static Object dataWithContentsOfFile (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) | |
54 { | |
55 id error; | |
56 | |
57 if (errorPtr) | |
58 error = new objc_object; | |
59 | |
60 Object result = invokeObjcSuperClass!(Object, "dataWithContentsOfFile:options:error:", NSString, NSUInteger, id*)(path, readOptionsMask, &error); | |
61 | |
62 if (error) | |
63 errorPtr = new NSError(error); | |
64 | |
65 return result; | |
66 } | |
67 | |
68 static Object dataWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) | |
69 { | |
70 id error; | |
71 | |
72 if (errorPtr) | |
73 error = new objc_object; | |
74 | |
75 Object result = invokeObjcSuperClass!(Object, "dataWithContentsOfURL:options:error:", NSURL, NSUInteger, id*)(url, readOptionsMask, &error); | |
76 | |
77 if (error) | |
78 errorPtr = new NSError(error); | |
79 | |
80 return result; | |
81 } | |
82 | |
83 static Object dataWithContentsOfFile (NSString path) | |
84 { | |
85 return invokeObjcSuperClass!(Object, "dataWithContentsOfFile:", NSString)(path); | |
86 } | |
87 | |
88 static Object dataWithContentsOfURL (NSURL url) | |
89 { | |
90 return invokeObjcSuperClass!(Object, "dataWithContentsOfURL:", NSURL)(url); | |
91 } | |
92 | |
93 static Object dataWithContentsOfMappedFile (NSString path) | |
94 { | |
95 return invokeObjcSuperClass!(Object, "dataWithContentsOfMappedFile:", NSString)(path); | |
96 } | |
97 | |
98 Object initWithBytes (void* bytes, NSUInteger length) | |
99 { | |
100 return invokeObjcSelf!(Object, "initWithBytes:length:", void*, NSUInteger)(bytes, length); | |
101 } | |
102 | |
103 this (void* bytes, NSUInteger length) | |
104 { | |
105 typeof(this).alloc.initWithBytes(bytes, length); | |
106 } | |
107 | |
108 Object initWithBytesNoCopy (void* bytes, NSUInteger length) | |
109 { | |
110 return invokeObjcSelf!(Object, "initWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); | |
111 } | |
112 | |
113 this (void* bytes, NSUInteger length) | |
114 { | |
115 typeof(this).alloc.initWithBytesNoCopy(bytes, length); | |
116 } | |
117 | |
118 Object initWithBytesNoCopy (void* bytes, NSUInteger length, bool b) | |
119 { | |
120 return invokeObjcSelf!(Object, "initWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(bytes, length, b); | |
121 } | |
122 | |
123 this (void* bytes, NSUInteger length, bool b) | |
124 { | |
125 typeof(this).alloc.initWithBytesNoCopy(bytes, length, b); | |
126 } | |
127 | |
128 Object initWithContentsOfFile (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) | |
129 { | |
130 id error; | |
131 | |
132 if (errorPtr) | |
133 error = new objc_object; | |
134 | |
135 Object result = invokeObjcSelf!(Object, "initWithContentsOfFile:options:error:", NSString, NSUInteger, id*)(path, readOptionsMask, &error); | |
136 | |
137 if (error) | |
138 errorPtr = new NSError(error); | |
139 | |
140 return result; | |
141 } | |
142 | |
143 this (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) | |
144 { | |
145 typeof(this).alloc.initWithContentsOfFile(path, readOptionsMask, errorPtr); | |
146 } | |
147 | |
148 Object initWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) | |
149 { | |
150 id error; | |
151 | |
152 if (errorPtr) | |
153 error = new objc_object; | |
154 | |
155 Object result = invokeObjcSelf!(Object, "initWithContentsOfURL:options:error:", NSURL, NSUInteger, id*)(url, readOptionsMask, &error); | |
156 | |
157 if (error) | |
158 errorPtr = new NSError(error); | |
159 | |
160 return result; | |
161 } | |
162 | |
163 this (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) | |
164 { | |
165 typeof(this).alloc.initWithContentsOfURL(url, readOptionsMask, errorPtr); | |
166 } | |
167 | |
168 Object initWithContentsOfFile (NSString path) | |
169 { | |
170 return invokeObjcSelf!(Object, "initWithContentsOfFile:", NSString)(path); | |
171 } | |
172 | |
173 this (NSString path) | |
174 { | |
175 typeof(this).alloc.initWithContentsOfFile(path); | |
176 } | |
177 | |
178 Object initWithContentsOfURL (NSURL url) | |
179 { | |
180 return invokeObjcSelf!(Object, "initWithContentsOfURL:", NSURL)(url); | |
181 } | |
182 | |
183 this (NSURL url) | |
184 { | |
185 typeof(this).alloc.initWithContentsOfURL(url); | |
186 } | |
187 | |
188 Object initWithContentsOfMappedFile (NSString path) | |
189 { | |
190 return invokeObjcSelf!(Object, "initWithContentsOfMappedFile:", NSString)(path); | |
191 } | |
192 | |
193 this (NSString path) | |
194 { | |
195 typeof(this).alloc.initWithContentsOfMappedFile(path); | |
196 } | |
197 | |
198 Object initWithData (NSData data) | |
199 { | |
200 return invokeObjcSelf!(Object, "initWithData:", NSData)(data); | |
201 } | |
202 | |
203 this (NSData data) | |
204 { | |
205 typeof(this).alloc.initWithData(data); | |
206 } | |
207 | |
208 static Object dataWithData (NSData data) | |
209 { | |
210 return invokeObjcSuperClass!(Object, "dataWithData:", NSData)(data); | |
211 } | |
212 `; | |
213 | |
214 const TNSMutableDataCreation = ` | |
215 | |
216 static Object dataWithCapacity (NSUInteger aNumItems) | |
217 { | |
218 return invokeObjcSuperClass!(Object, "dataWithCapacity:", NSUInteger)(aNumItems); | |
219 } | |
220 | |
221 static Object dataWithLength (NSUInteger length) | |
222 { | |
223 return invokeObjcSuperClass!(Object, "dataWithLength:", NSUInteger)(length); | |
224 } | |
225 | |
226 Object initWithCapacity (NSUInteger capacity) | |
227 { | |
228 return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(capacity); | |
229 } | |
230 | |
231 this (NSUInteger capacity) | |
232 { | |
233 typeof(this).alloc.initWithCapacity(capacity); | |
234 } | |
235 | |
236 Object initWithLength (NSUInteger length) | |
237 { | |
238 return invokeObjcSelf!(Object, "initWithLength:", NSUInteger)(length); | |
239 } | |
240 | |
241 this (NSUInteger length) | |
242 { | |
243 typeof(this).alloc.initWithLength(length); | |
244 } | |
245 `; | |
246 | |
247 const TNSExtendedMutableData = ` | |
248 | |
249 void appendBytes (void* bytes, NSUInteger length) | |
250 { | |
251 return invokeObjcSelf!(void, "appendBytes:length:", void*, NSUInteger)(bytes, length); | |
252 } | |
253 | |
254 void appendData (NSData other) | |
255 { | |
256 return invokeObjcSelf!(void, "appendData:", NSData)(other); | |
257 } | |
258 | |
259 void increaseLengthBy (NSUInteger extraLength) | |
260 { | |
261 return invokeObjcSelf!(void, "increaseLengthBy:", NSUInteger)(extraLength); | |
262 } | |
263 | |
264 void replaceBytesInRange (NSRange range, void* bytes) | |
265 { | |
266 return invokeObjcSelf!(void, "replaceBytesInRange:withBytes:", NSRange, void*)(range, bytes); | |
267 } | |
268 | |
269 void resetBytesInRange (NSRange range) | |
270 { | |
271 return invokeObjcSelf!(void, "resetBytesInRange:", NSRange)(range); | |
272 } | |
273 | |
274 void setData (NSData data) | |
275 { | |
276 return invokeObjcSelf!(void, "setData:", NSData)(data); | |
277 } | |
278 | |
279 void replaceBytesInRange (NSRange range, void* replacementBytes, NSUInteger replacementLength) | |
280 { | |
281 return invokeObjcSelf!(void, "replaceBytesInRange:withBytes:length:", NSRange, void*, NSUInteger)(range, replacementBytes, replacementLength); | |
282 } | |
283 `; | |
284 | |
285 const TNSExtendedData = ` | |
286 | |
287 NSString description () | |
288 { | |
289 return invokeObjcSelf!(NSString, "description"); | |
290 } | |
291 | |
292 void getBytes (void* buffer) | |
293 { | |
294 return invokeObjcSelf!(void, "getBytes:", void*)(buffer); | |
295 } | |
296 | |
297 void getBytes (void* buffer, NSUInteger length) | |
298 { | |
299 return invokeObjcSelf!(void, "getBytes:length:", void*, NSUInteger)(buffer, length); | |
300 } | |
301 | |
302 void getBytes (void* buffer, NSRange range) | |
303 { | |
304 return invokeObjcSelf!(void, "getBytes:range:", void*, NSRange)(buffer, range); | |
305 } | |
306 | |
307 bool isEqualToData (NSData other) | |
308 { | |
309 return invokeObjcSelf!(bool, "isEqualToData:", NSData)(other); | |
310 } | |
311 | |
312 NSData subdataWithRange (NSRange range) | |
313 { | |
314 return invokeObjcSelf!(NSData, "subdataWithRange:", NSRange)(range); | |
315 } | |
316 | |
317 bool writeToFile (NSString path, bool useAuxiliaryFile) | |
318 { | |
319 return invokeObjcSelf!(bool, "writeToFile:atomically:", NSString, bool)(path, useAuxiliaryFile); | |
320 } | |
321 | |
322 bool writeToURL (NSURL url, bool atomically) | |
323 { | |
324 return invokeObjcSelf!(bool, "writeToURL:atomically:", NSURL, bool)(url, atomically); | |
325 } | |
326 | |
327 bool writeToFile (NSString path, NSUInteger writeOptionsMask, NSError** errorPtr) | |
328 { | |
329 return invokeObjcSelf!(bool, "writeToFile:options:error:", NSString, NSUInteger, NSError**)(path, writeOptionsMask, errorPtr); | |
330 } | |
331 | |
332 bool writeToURL (NSURL url, NSUInteger writeOptionsMask, NSError** errorPtr) | |
333 { | |
334 return invokeObjcSelf!(bool, "writeToURL:options:error:", NSURL, NSUInteger, NSError**)(url, writeOptionsMask, errorPtr); | |
335 } | |
336 `; | |
337 | |
28 class NSData : NSObject, INSCopying, INSMutableCopying, INSCoding | 338 class NSData : NSObject, INSCopying, INSMutableCopying, INSCoding |
29 { | 339 { |
30 mixin ObjcWrap; | 340 mixin (ObjcWrap); |
31 mixin TNSDataCreation; | 341 |
32 mixin TNSExtendedData; | 342 this () |
343 { | |
344 super(typeof(this).alloc.init.objcObject); | |
345 } | |
346 | |
347 typeof(this) init () | |
348 { | |
349 return invokeObjcSelf!(typeof(this), "init"); | |
350 } | |
33 | 351 |
34 NSUInteger length () | 352 NSUInteger length () |
35 { | 353 { |
36 return invokeObjcSelf!(NSUInteger, "length"); | 354 return invokeObjcSelf!(NSUInteger, "length"); |
37 } | 355 } |
61 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | 379 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); |
62 } | 380 } |
63 | 381 |
64 this (NSCoder aDecoder) | 382 this (NSCoder aDecoder) |
65 { | 383 { |
66 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 384 typeof(this).alloc.initWithCoder(aDecoder); |
67 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | 385 } |
68 | 386 |
69 if (result) | 387 // TNSDataCreation |
70 objcObject = ret; | 388 static Object data () |
71 | 389 { |
72 dObject = this; | 390 return invokeObjcSuperClass!(Object, "data"); |
391 } | |
392 | |
393 static Object dataWithBytes (void* bytes, NSUInteger length) | |
394 { | |
395 return invokeObjcSuperClass!(Object, "dataWithBytes:length:", void*, NSUInteger)(bytes, length); | |
396 } | |
397 | |
398 static Object dataWithBytesNoCopy (void* bytes, NSUInteger length) | |
399 { | |
400 return invokeObjcSuperClass!(Object, "dataWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); | |
401 } | |
402 | |
403 static Object dataWithBytesNoCopy (void* bytes, NSUInteger length, bool b) | |
404 { | |
405 return invokeObjcSuperClass!(Object, "dataWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(bytes, length, b); | |
406 } | |
407 | |
408 static Object dataWithContentsOfFile (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) | |
409 { | |
410 id error; | |
411 | |
412 if (errorPtr) | |
413 error = new objc_object; | |
414 | |
415 Object result = invokeObjcSuperClass!(Object, "dataWithContentsOfFile:options:error:", NSString, NSUInteger, id*)(path, readOptionsMask, &error); | |
416 | |
417 if (error) | |
418 errorPtr = new NSError(error); | |
419 | |
420 return result; | |
421 } | |
422 | |
423 static Object dataWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) | |
424 { | |
425 id error; | |
426 | |
427 if (errorPtr) | |
428 error = new objc_object; | |
429 | |
430 Object result = invokeObjcSuperClass!(Object, "dataWithContentsOfURL:options:error:", NSURL, NSUInteger, id*)(url, readOptionsMask, &error); | |
431 | |
432 if (error) | |
433 errorPtr = new NSError(error); | |
434 | |
435 return result; | |
436 } | |
437 | |
438 static Object dataWithContentsOfFile (NSString path) | |
439 { | |
440 return invokeObjcSuperClass!(Object, "dataWithContentsOfFile:", NSString)(path); | |
441 } | |
442 | |
443 static Object dataWithContentsOfURL (NSURL url) | |
444 { | |
445 return invokeObjcSuperClass!(Object, "dataWithContentsOfURL:", NSURL)(url); | |
446 } | |
447 | |
448 static Object dataWithContentsOfMappedFile (NSString path) | |
449 { | |
450 return invokeObjcSuperClass!(Object, "dataWithContentsOfMappedFile:", NSString)(path); | |
451 } | |
452 | |
453 Object initWithBytes (void* bytes, NSUInteger length) | |
454 { | |
455 return invokeObjcSelf!(Object, "initWithBytes:length:", void*, NSUInteger)(bytes, length); | |
456 } | |
457 | |
458 this (void* bytes, NSUInteger length) | |
459 { | |
460 typeof(this).alloc.initWithBytes(bytes, length); | |
461 } | |
462 | |
463 Object initWithBytesNoCopy (void* bytes, NSUInteger length) | |
464 { | |
465 return invokeObjcSelf!(Object, "initWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); | |
466 } | |
467 | |
468 Object initWithBytesNoCopy (void* bytes, NSUInteger length, bool b) | |
469 { | |
470 return invokeObjcSelf!(Object, "initWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(bytes, length, b); | |
471 } | |
472 | |
473 this (void* bytes, NSUInteger length, bool b) | |
474 { | |
475 typeof(this).alloc.initWithBytesNoCopy(bytes, length, b); | |
476 } | |
477 | |
478 Object initWithContentsOfFile (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) | |
479 { | |
480 id error; | |
481 | |
482 if (errorPtr) | |
483 error = new objc_object; | |
484 | |
485 Object result = invokeObjcSelf!(Object, "initWithContentsOfFile:options:error:", NSString, NSUInteger, id*)(path, readOptionsMask, &error); | |
486 | |
487 if (error) | |
488 errorPtr = new NSError(error); | |
489 | |
490 return result; | |
491 } | |
492 | |
493 this (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) | |
494 { | |
495 typeof(this).alloc.initWithContentsOfFile(path, readOptionsMask, errorPtr); | |
496 } | |
497 | |
498 Object initWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) | |
499 { | |
500 id error; | |
501 | |
502 if (errorPtr) | |
503 error = new objc_object; | |
504 | |
505 Object result = invokeObjcSelf!(Object, "initWithContentsOfURL:options:error:", NSURL, NSUInteger, id*)(url, readOptionsMask, &error); | |
506 | |
507 if (error) | |
508 errorPtr = new NSError(error); | |
509 | |
510 return result; | |
511 } | |
512 | |
513 this (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) | |
514 { | |
515 typeof(this).alloc.initWithContentsOfURL(url, readOptionsMask, errorPtr); | |
516 } | |
517 | |
518 Object initWithContentsOfFile (NSString path) | |
519 { | |
520 return invokeObjcSelf!(Object, "initWithContentsOfFile:", NSString)(path); | |
521 } | |
522 | |
523 this (NSString path) | |
524 { | |
525 typeof(this).alloc.initWithContentsOfFile(path); | |
526 } | |
527 | |
528 Object initWithContentsOfURL (NSURL url) | |
529 { | |
530 return invokeObjcSelf!(Object, "initWithContentsOfURL:", NSURL)(url); | |
531 } | |
532 | |
533 this (NSURL url) | |
534 { | |
535 typeof(this).alloc.initWithContentsOfURL(url); | |
536 } | |
537 | |
538 Object initWithContentsOfMappedFile (NSString path) | |
539 { | |
540 return invokeObjcSelf!(Object, "initWithContentsOfMappedFile:", NSString)(path); | |
541 } | |
542 | |
543 Object initWithData (NSData data) | |
544 { | |
545 return invokeObjcSelf!(Object, "initWithData:", NSData)(data); | |
546 } | |
547 | |
548 this (NSData data) | |
549 { | |
550 typeof(this).alloc.initWithData(data); | |
551 } | |
552 | |
553 static Object dataWithData (NSData data) | |
554 { | |
555 return invokeObjcSuperClass!(Object, "dataWithData:", NSData)(data); | |
556 } | |
557 | |
558 // TNSExtendedData | |
559 NSString description () | |
560 { | |
561 return invokeObjcSelf!(NSString, "description"); | |
562 } | |
563 | |
564 void getBytes (void* buffer) | |
565 { | |
566 return invokeObjcSelf!(void, "getBytes:", void*)(buffer); | |
567 } | |
568 | |
569 void getBytes (void* buffer, NSUInteger length) | |
570 { | |
571 return invokeObjcSelf!(void, "getBytes:length:", void*, NSUInteger)(buffer, length); | |
572 } | |
573 | |
574 void getBytes (void* buffer, NSRange range) | |
575 { | |
576 return invokeObjcSelf!(void, "getBytes:range:", void*, NSRange)(buffer, range); | |
577 } | |
578 | |
579 bool isEqualToData (NSData other) | |
580 { | |
581 return invokeObjcSelf!(bool, "isEqualToData:", NSData)(other); | |
582 } | |
583 | |
584 NSData subdataWithRange (NSRange range) | |
585 { | |
586 return invokeObjcSelf!(NSData, "subdataWithRange:", NSRange)(range); | |
587 } | |
588 | |
589 bool writeToFile (NSString path, bool useAuxiliaryFile) | |
590 { | |
591 return invokeObjcSelf!(bool, "writeToFile:atomically:", NSString, bool)(path, useAuxiliaryFile); | |
592 } | |
593 | |
594 bool writeToURL (NSURL url, bool atomically) | |
595 { | |
596 return invokeObjcSelf!(bool, "writeToURL:atomically:", NSURL, bool)(url, atomically); | |
597 } | |
598 | |
599 bool writeToFile (NSString path, NSUInteger writeOptionsMask, NSError** errorPtr) | |
600 { | |
601 return invokeObjcSelf!(bool, "writeToFile:options:error:", NSString, NSUInteger, NSError**)(path, writeOptionsMask, errorPtr); | |
602 } | |
603 | |
604 bool writeToURL (NSURL url, NSUInteger writeOptionsMask, NSError** errorPtr) | |
605 { | |
606 return invokeObjcSelf!(bool, "writeToURL:options:error:", NSURL, NSUInteger, NSError**)(url, writeOptionsMask, errorPtr); | |
73 } | 607 } |
74 } | 608 } |
75 | 609 |
76 class NSMutableData : NSData | 610 class NSMutableData : NSData |
77 { | 611 { |
78 mixin ObjcWrap; | 612 mixin (ObjcWrap); |
79 mixin TNSMutableDataCreation; | 613 |
80 mixin TNSExtendedMutableData; | 614 this () |
615 { | |
616 super(typeof(this).alloc.init.objcObject); | |
617 } | |
618 | |
619 typeof(this) init () | |
620 { | |
621 return invokeObjcSelf!(typeof(this), "init"); | |
622 } | |
81 | 623 |
82 void* mutableBytes () | 624 void* mutableBytes () |
83 { | 625 { |
84 return invokeObjcSelf!(void*, "mutableBytes"); | 626 return invokeObjcSelf!(void*, "mutableBytes"); |
85 } | 627 } |
86 | 628 |
87 void setLength (NSUInteger length) | 629 void setLength (NSUInteger length) |
88 { | 630 { |
89 return invokeObjcSelf!(void, "setLength:", NSUInteger)(length); | 631 return invokeObjcSelf!(void, "setLength:", NSUInteger)(length); |
90 } | 632 } |
633 | |
634 // TNSMutableDataCreation | |
635 static Object dataWithCapacity (NSUInteger aNumItems) | |
636 { | |
637 return invokeObjcSuperClass!(Object, "dataWithCapacity:", NSUInteger)(aNumItems); | |
638 } | |
639 | |
640 static Object dataWithLength (NSUInteger length) | |
641 { | |
642 return invokeObjcSuperClass!(Object, "dataWithLength:", NSUInteger)(length); | |
643 } | |
644 | |
645 Object initWithCapacity (NSUInteger capacity) | |
646 { | |
647 return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(capacity); | |
648 } | |
649 | |
650 Object initWithLength (NSUInteger length) | |
651 { | |
652 return invokeObjcSelf!(Object, "initWithLength:", NSUInteger)(length); | |
653 } | |
654 | |
655 this (NSUInteger length) | |
656 { | |
657 typeof(this).alloc.initWithLength(length); | |
658 } | |
659 | |
660 // TNSExtendedMutableData | |
661 void appendBytes (void* bytes, NSUInteger length) | |
662 { | |
663 return invokeObjcSelf!(void, "appendBytes:length:", void*, NSUInteger)(bytes, length); | |
664 } | |
665 | |
666 void appendData (NSData other) | |
667 { | |
668 return invokeObjcSelf!(void, "appendData:", NSData)(other); | |
669 } | |
670 | |
671 void increaseLengthBy (NSUInteger extraLength) | |
672 { | |
673 return invokeObjcSelf!(void, "increaseLengthBy:", NSUInteger)(extraLength); | |
674 } | |
675 | |
676 void replaceBytesInRange (NSRange range, void* bytes) | |
677 { | |
678 return invokeObjcSelf!(void, "replaceBytesInRange:withBytes:", NSRange, void*)(range, bytes); | |
679 } | |
680 | |
681 void resetBytesInRange (NSRange range) | |
682 { | |
683 return invokeObjcSelf!(void, "resetBytesInRange:", NSRange)(range); | |
684 } | |
685 | |
686 void setData (NSData data) | |
687 { | |
688 return invokeObjcSelf!(void, "setData:", NSData)(data); | |
689 } | |
690 | |
691 void replaceBytesInRange (NSRange range, void* replacementBytes, NSUInteger replacementLength) | |
692 { | |
693 return invokeObjcSelf!(void, "replaceBytesInRange:withBytes:length:", NSRange, void*, NSUInteger)(range, replacementBytes, replacementLength); | |
694 } | |
91 } | 695 } |
92 | |
93 template TNSDataCreation () | |
94 { | |
95 static Object data () | |
96 { | |
97 return invokeObjcSelfClass!(Object, "data"); | |
98 } | |
99 | |
100 static Object dataWithBytes (void* bytes, NSUInteger length) | |
101 { | |
102 return invokeObjcSelfClass!(Object, "dataWithBytes:length:", void*, NSUInteger)(bytes, length); | |
103 } | |
104 | |
105 static Object dataWithBytesNoCopy (void* bytes, NSUInteger length) | |
106 { | |
107 return invokeObjcSelfClass!(Object, "dataWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); | |
108 } | |
109 | |
110 static Object dataWithBytesNoCopy (void* bytes, NSUInteger length, bool b) | |
111 { | |
112 return invokeObjcSelfClass!(Object, "dataWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(bytes, length, b); | |
113 } | |
114 | |
115 static Object dataWithContentsOfFile (NSString path, NSUInteger readOptionsMask, NSError** errorPtr) | |
116 { | |
117 return invokeObjcSelfClass!(Object, "dataWithContentsOfFile:options:error:", NSString, NSUInteger, NSError**)(path, readOptionsMask, errorPtr); | |
118 } | |
119 | |
120 static Object dataWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, NSError** errorPtr) | |
121 { | |
122 return invokeObjcSelfClass!(Object, "dataWithContentsOfURL:options:error:", NSURL, NSUInteger, NSError**)(url, readOptionsMask, errorPtr); | |
123 } | |
124 | |
125 static Object dataWithContentsOfFile (NSString path) | |
126 { | |
127 return invokeObjcSelfClass!(Object, "dataWithContentsOfFile:", NSString)(path); | |
128 } | |
129 | |
130 static Object dataWithContentsOfURL (NSURL url) | |
131 { | |
132 return invokeObjcSelfClass!(Object, "dataWithContentsOfURL:", NSURL)(url); | |
133 } | |
134 | |
135 static Object dataWithContentsOfMappedFile (NSString path) | |
136 { | |
137 return invokeObjcSelfClass!(Object, "dataWithContentsOfMappedFile:", NSString)(path); | |
138 } | |
139 | |
140 Object initWithBytes (void* bytes, NSUInteger length) | |
141 { | |
142 return invokeObjcSelf!(Object, "initWithBytes:length:", void*, NSUInteger)(bytes, length); | |
143 } | |
144 | |
145 this (void* bytes, NSUInteger length) | |
146 { | |
147 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
148 id result = Bridge.invokeObjcMethod!(id, "initWithBytes:length:", void*, NSUInteger)(objcObject, bytes, length); | |
149 | |
150 if (result) | |
151 objcObject = ret; | |
152 | |
153 dObject = this; | |
154 } | |
155 | |
156 Object initWithBytesNoCopy (void* bytes, NSUInteger length) | |
157 { | |
158 return invokeObjcSelf!(Object, "initWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); | |
159 } | |
160 | |
161 this (void* bytes, NSUInteger length) | |
162 { | |
163 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
164 id result = Bridge.invokeObjcMethod!(id, "initWithBytesNoCopy:length:", void*, NSUInteger)(objcObject, bytes, length); | |
165 | |
166 if (result) | |
167 objcObject = ret; | |
168 | |
169 dObject = this; | |
170 } | |
171 | |
172 Object initWithBytesNoCopy (void* bytes, NSUInteger length, bool b) | |
173 { | |
174 return invokeObjcSelf!(Object, "initWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(bytes, length, b); | |
175 } | |
176 | |
177 this (void* bytes, NSUInteger length, bool b) | |
178 { | |
179 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
180 id result = Bridge.invokeObjcMethod!(id, "initWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(objcObject, bytes, length, b); | |
181 | |
182 if (result) | |
183 objcObject = ret; | |
184 | |
185 dObject = this; | |
186 } | |
187 | |
188 Object initWithContentsOfFile (NSString path, NSUInteger readOptionsMask, NSError** errorPtr) | |
189 { | |
190 return invokeObjcSelf!(Object, "initWithContentsOfFile:options:error:", NSString, NSUInteger, NSError**)(path, readOptionsMask, errorPtr); | |
191 } | |
192 | |
193 this (NSString path, NSUInteger readOptionsMask, NSError** errorPtr) | |
194 { | |
195 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
196 id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfFile:options:error:", NSString, NSUInteger, NSError**)(objcObject, path, readOptionsMask, errorPtr); | |
197 | |
198 if (result) | |
199 objcObject = ret; | |
200 | |
201 dObject = this; | |
202 } | |
203 | |
204 Object initWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, NSError** errorPtr) | |
205 { | |
206 return invokeObjcSelf!(Object, "initWithContentsOfURL:options:error:", NSURL, NSUInteger, NSError**)(url, readOptionsMask, errorPtr); | |
207 } | |
208 | |
209 this (NSURL url, NSUInteger readOptionsMask, NSError** errorPtr) | |
210 { | |
211 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
212 id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfURL:options:error:", NSURL, NSUInteger, NSError**)(objcObject, url, readOptionsMask, errorPtr); | |
213 | |
214 if (result) | |
215 objcObject = ret; | |
216 | |
217 dObject = this; | |
218 } | |
219 | |
220 Object initWithContentsOfFile (NSString path) | |
221 { | |
222 return invokeObjcSelf!(Object, "initWithContentsOfFile:", NSString)(path); | |
223 } | |
224 | |
225 this (NSString path) | |
226 { | |
227 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
228 id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfFile:", NSString)(objcObject, path); | |
229 | |
230 if (result) | |
231 objcObject = ret; | |
232 | |
233 dObject = this; | |
234 } | |
235 | |
236 Object initWithContentsOfURL (NSURL url) | |
237 { | |
238 return invokeObjcSelf!(Object, "initWithContentsOfURL:", NSURL)(url); | |
239 } | |
240 | |
241 this (NSURL url) | |
242 { | |
243 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
244 id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfURL:", NSURL)(objcObject, url); | |
245 | |
246 if (result) | |
247 objcObject = ret; | |
248 | |
249 dObject = this; | |
250 } | |
251 | |
252 Object initWithContentsOfMappedFile (NSString path) | |
253 { | |
254 return invokeObjcSelf!(Object, "initWithContentsOfMappedFile:", NSString)(path); | |
255 } | |
256 | |
257 this (NSString path) | |
258 { | |
259 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
260 id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfMappedFile:", NSString)(objcObject, path); | |
261 | |
262 if (result) | |
263 objcObject = ret; | |
264 | |
265 dObject = this; | |
266 } | |
267 | |
268 Object initWithData (NSData data) | |
269 { | |
270 return invokeObjcSelf!(Object, "initWithData:", NSData)(data); | |
271 } | |
272 | |
273 this (NSData data) | |
274 { | |
275 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
276 id result = Bridge.invokeObjcMethod!(id, "initWithData:", NSData)(objcObject, data); | |
277 | |
278 if (result) | |
279 objcObject = ret; | |
280 | |
281 dObject = this; | |
282 } | |
283 | |
284 static Object dataWithData (NSData data) | |
285 { | |
286 return invokeObjcSelfClass!(Object, "dataWithData:", NSData)(data); | |
287 } | |
288 } | |
289 | |
290 template TNSMutableDataCreation () | |
291 { | |
292 static Object dataWithCapacity (NSUInteger aNumItems) | |
293 { | |
294 return invokeObjcSelfClass!(Object, "dataWithCapacity:", NSUInteger)(aNumItems); | |
295 } | |
296 | |
297 static Object dataWithLength (NSUInteger length) | |
298 { | |
299 return invokeObjcSelfClass!(Object, "dataWithLength:", NSUInteger)(length); | |
300 } | |
301 | |
302 Object initWithCapacity (NSUInteger capacity) | |
303 { | |
304 return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(capacity); | |
305 } | |
306 | |
307 this (NSUInteger capacity) | |
308 { | |
309 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
310 id result = Bridge.invokeObjcMethod!(id, "initWithCapacity:", NSUInteger)(objcObject, capacity); | |
311 | |
312 if (result) | |
313 objcObject = ret; | |
314 | |
315 dObject = this; | |
316 } | |
317 | |
318 Object initWithLength (NSUInteger length) | |
319 { | |
320 return invokeObjcSelf!(Object, "initWithLength:", NSUInteger)(length); | |
321 } | |
322 | |
323 this (NSUInteger length) | |
324 { | |
325 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
326 id result = Bridge.invokeObjcMethod!(id, "initWithLength:", NSUInteger)(objcObject, length); | |
327 | |
328 if (result) | |
329 objcObject = ret; | |
330 | |
331 dObject = this; | |
332 } | |
333 } | |
334 | |
335 template TNSExtendedMutableData () | |
336 { | |
337 void appendBytes (void* bytes, NSUInteger length) | |
338 { | |
339 return invokeObjcSelf!(void, "appendBytes:length:", void*, NSUInteger)(bytes, length); | |
340 } | |
341 | |
342 void appendData (NSData other) | |
343 { | |
344 return invokeObjcSelf!(void, "appendData:", NSData)(other); | |
345 } | |
346 | |
347 void increaseLengthBy (NSUInteger extraLength) | |
348 { | |
349 return invokeObjcSelf!(void, "increaseLengthBy:", NSUInteger)(extraLength); | |
350 } | |
351 | |
352 void replaceBytesInRange (NSRange range, void* bytes) | |
353 { | |
354 return invokeObjcSelf!(void, "replaceBytesInRange:withBytes:", NSRange, void*)(range, bytes); | |
355 } | |
356 | |
357 void resetBytesInRange (NSRange range) | |
358 { | |
359 return invokeObjcSelf!(void, "resetBytesInRange:", NSRange)(range); | |
360 } | |
361 | |
362 void setData (NSData data) | |
363 { | |
364 return invokeObjcSelf!(void, "setData:", NSData)(data); | |
365 } | |
366 | |
367 void replaceBytesInRange (NSRange range, void* replacementBytes, NSUInteger replacementLength) | |
368 { | |
369 return invokeObjcSelf!(void, "replaceBytesInRange:withBytes:length:", NSRange, void*, NSUInteger)(range, replacementBytes, replacementLength); | |
370 } | |
371 } | |
372 | |
373 template TNSExtendedData () | |
374 { | |
375 NSString description () | |
376 { | |
377 return invokeObjcSelf!(NSString, "description"); | |
378 } | |
379 | |
380 void getBytes (void* buffer) | |
381 { | |
382 return invokeObjcSelf!(void, "getBytes:", void*)(buffer); | |
383 } | |
384 | |
385 void getBytes (void* buffer, NSUInteger length) | |
386 { | |
387 return invokeObjcSelf!(void, "getBytes:length:", void*, NSUInteger)(buffer, length); | |
388 } | |
389 | |
390 void getBytes (void* buffer, NSRange range) | |
391 { | |
392 return invokeObjcSelf!(void, "getBytes:range:", void*, NSRange)(buffer, range); | |
393 } | |
394 | |
395 bool isEqualToData (NSData other) | |
396 { | |
397 return invokeObjcSelf!(bool, "isEqualToData:", NSData)(other); | |
398 } | |
399 | |
400 NSData subdataWithRange (NSRange range) | |
401 { | |
402 return invokeObjcSelf!(NSData, "subdataWithRange:", NSRange)(range); | |
403 } | |
404 | |
405 bool writeToFile (NSString path, bool useAuxiliaryFile) | |
406 { | |
407 return invokeObjcSelf!(bool, "writeToFile:atomically:", NSString, bool)(path, useAuxiliaryFile); | |
408 } | |
409 | |
410 bool writeToURL (NSURL url, bool atomically) | |
411 { | |
412 return invokeObjcSelf!(bool, "writeToURL:atomically:", NSURL, bool)(url, atomically); | |
413 } | |
414 | |
415 bool writeToFile (NSString path, NSUInteger writeOptionsMask, NSError** errorPtr) | |
416 { | |
417 return invokeObjcSelf!(bool, "writeToFile:options:error:", NSString, NSUInteger, NSError**)(path, writeOptionsMask, errorPtr); | |
418 } | |
419 | |
420 bool writeToURL (NSURL url, NSUInteger writeOptionsMask, NSError** errorPtr) | |
421 { | |
422 return invokeObjcSelf!(bool, "writeToURL:options:error:", NSURL, NSUInteger, NSError**)(url, writeOptionsMask, errorPtr); | |
423 } | |
424 } | |
425 |