14
|
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.NSData;
|
|
8
|
|
9 import dstep.foundation.NSError;
|
|
10 import dstep.foundation.NSObject;
|
|
11 import dstep.foundation.NSRange;
|
|
12 import dstep.foundation.NSString;
|
|
13 import dstep.foundation.NSURL;
|
|
14 import dstep.objc.bridge.Bridge;
|
|
15 import dstep.objc.objc : id;
|
|
16
|
|
17 enum
|
|
18 {
|
|
19 NSMappedRead = 1,
|
|
20 NSUncachedRead = 2
|
|
21 }
|
|
22
|
|
23 enum
|
|
24 {
|
|
25 NSAtomicWrite = 1
|
|
26 }
|
|
27
|
|
28 class NSData : NSObject, INSCopying, INSMutableCopying, INSCoding
|
|
29 {
|
|
30 mixin ObjcWrap;
|
|
31 mixin TNSDataCreation;
|
|
32 mixin TNSExtendedData;
|
|
33
|
|
34 NSUInteger length ()
|
|
35 {
|
|
36 return invokeObjcSelf!(NSUInteger, "length");
|
|
37 }
|
|
38
|
|
39 void* bytes ()
|
|
40 {
|
|
41 return invokeObjcSelf!(void*, "bytes");
|
|
42 }
|
|
43
|
|
44 Object copyWithZone (NSZone* zone)
|
|
45 {
|
|
46 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
|
|
47 }
|
|
48
|
|
49 Object mutableCopyWithZone (NSZone* zone)
|
|
50 {
|
|
51 return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone);
|
|
52 }
|
|
53
|
|
54 void encodeWithCoder (NSCoder aCoder)
|
|
55 {
|
|
56 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
|
|
57 }
|
|
58
|
|
59 Object initWithCoder (NSCoder aDecoder)
|
|
60 {
|
|
61 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
|
|
62 }
|
|
63
|
|
64 this (NSCoder aDecoder)
|
|
65 {
|
|
66 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
67 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
|
|
68
|
|
69 if (result)
|
|
70 objcObject = ret;
|
|
71
|
|
72 dObject = this;
|
|
73 }
|
|
74 }
|
|
75
|
|
76 class NSMutableData : NSData
|
|
77 {
|
|
78 mixin ObjcWrap;
|
|
79 mixin TNSMutableDataCreation;
|
|
80 mixin TNSExtendedMutableData;
|
|
81
|
|
82 void* mutableBytes ()
|
|
83 {
|
|
84 return invokeObjcSelf!(void*, "mutableBytes");
|
|
85 }
|
|
86
|
|
87 void setLength (NSUInteger length)
|
|
88 {
|
|
89 return invokeObjcSelf!(void, "setLength:", NSUInteger)(length);
|
|
90 }
|
|
91 }
|
|
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
|