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.NSArray;
|
|
8
|
|
9 import dstep.foundation.NSData;
|
|
10 import dstep.foundation.NSEnumerator;
|
|
11 import dstep.foundation.NSIndexSet;
|
|
12 import dstep.foundation.NSObject;
|
|
13 import dstep.foundation.NSRange;
|
|
14 import dstep.foundation.NSString;
|
|
15 import dstep.foundation.NSURL;
|
|
16 import dstep.objc.bridge.Bridge;
|
|
17 import dstep.objc.objc : id;
|
|
18
|
|
19 class NSMutableArray : NSArray
|
|
20 {
|
|
21 mixin ObjcWrap;
|
|
22 mixin TNSExtendedMutableArray;
|
|
23 mixin TNSMutableArrayCreation;
|
|
24
|
|
25 void addObject (Object anObject)
|
|
26 {
|
|
27 return invokeObjcSelf!(void, "addObject:", Object)(anObject);
|
|
28 }
|
|
29
|
|
30 void insertObject (Object anObject, NSUInteger index)
|
|
31 {
|
|
32 return invokeObjcSelf!(void, "insertObject:atIndex:", Object, NSUInteger)(anObject, index);
|
|
33 }
|
|
34
|
|
35 void removeLastObject ()
|
|
36 {
|
|
37 return invokeObjcSelf!(void, "removeLastObject");
|
|
38 }
|
|
39
|
|
40 void removeObjectAtIndex (NSUInteger index)
|
|
41 {
|
|
42 return invokeObjcSelf!(void, "removeObjectAtIndex:", NSUInteger)(index);
|
|
43 }
|
|
44
|
|
45 void replaceObjectAtIndex (NSUInteger index, Object anObject)
|
|
46 {
|
|
47 return invokeObjcSelf!(void, "replaceObjectAtIndex:withObject:", NSUInteger, Object)(index, anObject);
|
|
48 }
|
|
49 }
|
|
50
|
|
51 class NSArray : NSObject, INSCopying, INSMutableCopying, INSCoding, INSFastEnumeration
|
|
52 {
|
|
53 mixin ObjcWrap;
|
|
54 mixin TNSArrayCreation;
|
|
55 mixin TNSExtendedArray;
|
|
56 mixin TNSSortDescriptorSorting;
|
|
57 mixin TNSArrayPathExtensions;
|
|
58
|
|
59 NSUInteger count ()
|
|
60 {
|
|
61 return invokeObjcSelf!(NSUInteger, "count");
|
|
62 }
|
|
63
|
|
64 Object objectAtIndex (NSUInteger index)
|
|
65 {
|
|
66 return invokeObjcSelf!(Object, "objectAtIndex:", NSUInteger)(index);
|
|
67 }
|
|
68
|
|
69 Object copyWithZone (NSZone* zone)
|
|
70 {
|
|
71 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
|
|
72 }
|
|
73
|
|
74 Object mutableCopyWithZone (NSZone* zone)
|
|
75 {
|
|
76 return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone);
|
|
77 }
|
|
78
|
|
79 void encodeWithCoder (NSCoder aCoder)
|
|
80 {
|
|
81 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
|
|
82 }
|
|
83
|
|
84 Object initWithCoder (NSCoder aDecoder)
|
|
85 {
|
|
86 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
|
|
87 }
|
|
88
|
|
89 this (NSCoder aDecoder)
|
|
90 {
|
|
91 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
92 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
|
|
93
|
|
94 if (result)
|
|
95 objcObject = ret;
|
|
96
|
|
97 dObject = this;
|
|
98 }
|
|
99
|
|
100 NSUInteger countByEnumeratingWithState (NSFastEnumerationState* state, id* stackbuf, NSUInteger len)
|
|
101 {
|
|
102 return invokeObjcSelf!(NSUInteger, "countByEnumeratingWithState:objects:count:", NSFastEnumerationState*, id*, NSUInteger)(state, stackbuf, len);
|
|
103 }
|
|
104 }
|
|
105
|
|
106 template TNSArrayCreation ()
|
|
107 {
|
|
108 static Object array ()
|
|
109 {
|
|
110 return invokeObjcSelfClass!(Object, "array");
|
|
111 }
|
|
112
|
|
113 static Object arrayWithObject (Object anObject)
|
|
114 {
|
|
115 return invokeObjcSelfClass!(Object, "arrayWithObject:", Object)(anObject);
|
|
116 }
|
|
117
|
|
118 static Object arrayWithObjects (id* objects, NSUInteger cnt)
|
|
119 {
|
|
120 return invokeObjcSelfClass!(Object, "arrayWithObjects:count:", id*, NSUInteger)(objects, cnt);
|
|
121 }
|
|
122
|
|
123 static Object arrayWithObjects (Object arrayWithObjects, ...)
|
|
124 {
|
|
125 return invokeObjcSelfClass!(Object, "arrayWithObjects:", Object)(arrayWithObjects);
|
|
126 }
|
|
127
|
|
128 static Object arrayWithArray (NSArray array)
|
|
129 {
|
|
130 return invokeObjcSelfClass!(Object, "arrayWithArray:", NSArray)(array);
|
|
131 }
|
|
132
|
|
133 Object initWithObjects (id* objects, NSUInteger cnt)
|
|
134 {
|
|
135 return invokeObjcSelf!(Object, "initWithObjects:count:", id*, NSUInteger)(objects, cnt);
|
|
136 }
|
|
137
|
|
138 this (id* objects, NSUInteger cnt)
|
|
139 {
|
|
140 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
141 id result = Bridge.invokeObjcMethod!(id, "initWithObjects:count:", id*, NSUInteger)(objcObject, objects, cnt);
|
|
142
|
|
143 if (result)
|
|
144 objcObject = ret;
|
|
145
|
|
146 dObject = this;
|
|
147 }
|
|
148
|
|
149 Object initWithObjects (Object initWithObjects, ...)
|
|
150 {
|
|
151 return invokeObjcSelf!(Object, "initWithObjects:", Object)(initWithObjects);
|
|
152 }
|
|
153
|
|
154 this (Object initWithObjects, ...)
|
|
155 {
|
|
156 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
157 id result = Bridge.invokeObjcMethod!(id, "initWithObjects:", Object)(objcObject, initWithObjects);
|
|
158
|
|
159 if (result)
|
|
160 objcObject = ret;
|
|
161
|
|
162 dObject = this;
|
|
163 }
|
|
164
|
|
165 Object initWithArray (NSArray array)
|
|
166 {
|
|
167 return invokeObjcSelf!(Object, "initWithArray:", NSArray)(array);
|
|
168 }
|
|
169
|
|
170 this (NSArray array)
|
|
171 {
|
|
172 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
173 id result = Bridge.invokeObjcMethod!(id, "initWithArray:", NSArray)(objcObject, array);
|
|
174
|
|
175 if (result)
|
|
176 objcObject = ret;
|
|
177
|
|
178 dObject = this;
|
|
179 }
|
|
180
|
|
181 Object initWithArray (NSArray array, bool flag)
|
|
182 {
|
|
183 return invokeObjcSelf!(Object, "initWithArray:copyItems:", NSArray, bool)(array, flag);
|
|
184 }
|
|
185
|
|
186 this (NSArray array, bool flag)
|
|
187 {
|
|
188 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
189 id result = Bridge.invokeObjcMethod!(id, "initWithArray:copyItems:", NSArray, bool)(objcObject, array, flag);
|
|
190
|
|
191 if (result)
|
|
192 objcObject = ret;
|
|
193
|
|
194 dObject = this;
|
|
195 }
|
|
196
|
|
197 static Object arrayWithContentsOfFile (NSString path)
|
|
198 {
|
|
199 return invokeObjcSelfClass!(Object, "arrayWithContentsOfFile:", NSString)(path);
|
|
200 }
|
|
201
|
|
202 static Object arrayWithContentsOfURL (NSURL url)
|
|
203 {
|
|
204 return invokeObjcSelfClass!(Object, "arrayWithContentsOfURL:", NSURL)(url);
|
|
205 }
|
|
206
|
|
207 Object initWithContentsOfFile (NSString path)
|
|
208 {
|
|
209 return invokeObjcSelf!(Object, "initWithContentsOfFile:", NSString)(path);
|
|
210 }
|
|
211
|
|
212 this (NSString path)
|
|
213 {
|
|
214 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
215 id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfFile:", NSString)(objcObject, path);
|
|
216
|
|
217 if (result)
|
|
218 objcObject = ret;
|
|
219
|
|
220 dObject = this;
|
|
221 }
|
|
222
|
|
223 Object initWithContentsOfURL (NSURL url)
|
|
224 {
|
|
225 return invokeObjcSelf!(Object, "initWithContentsOfURL:", NSURL)(url);
|
|
226 }
|
|
227
|
|
228 this (NSURL url)
|
|
229 {
|
|
230 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
231 id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfURL:", NSURL)(objcObject, url);
|
|
232
|
|
233 if (result)
|
|
234 objcObject = ret;
|
|
235
|
|
236 dObject = this;
|
|
237 }
|
|
238 }
|
|
239
|
|
240 template TNSExtendedArray ()
|
|
241 {
|
|
242 NSArray arrayByAddingObject (Object anObject)
|
|
243 {
|
|
244 return invokeObjcSelf!(NSArray, "arrayByAddingObject:", Object)(anObject);
|
|
245 }
|
|
246
|
|
247 NSArray arrayByAddingObjectsFromArray (NSArray otherArray)
|
|
248 {
|
|
249 return invokeObjcSelf!(NSArray, "arrayByAddingObjectsFromArray:", NSArray)(otherArray);
|
|
250 }
|
|
251
|
|
252 NSString componentsJoinedByString (NSString separator)
|
|
253 {
|
|
254 return invokeObjcSelf!(NSString, "componentsJoinedByString:", NSString)(separator);
|
|
255 }
|
|
256
|
|
257 bool containsObject (Object anObject)
|
|
258 {
|
|
259 return invokeObjcSelf!(bool, "containsObject:", Object)(anObject);
|
|
260 }
|
|
261
|
|
262 NSString description ()
|
|
263 {
|
|
264 return invokeObjcSelf!(NSString, "description");
|
|
265 }
|
|
266
|
|
267 NSString descriptionWithLocale (Object locale)
|
|
268 {
|
|
269 return invokeObjcSelf!(NSString, "descriptionWithLocale:", Object)(locale);
|
|
270 }
|
|
271
|
|
272 NSString descriptionWithLocale (Object locale, NSUInteger level)
|
|
273 {
|
|
274 return invokeObjcSelf!(NSString, "descriptionWithLocale:indent:", Object, NSUInteger)(locale, level);
|
|
275 }
|
|
276
|
|
277 Object firstObjectCommonWithArray (NSArray otherArray)
|
|
278 {
|
|
279 return invokeObjcSelf!(Object, "firstObjectCommonWithArray:", NSArray)(otherArray);
|
|
280 }
|
|
281
|
|
282 void getObjects (id* objects)
|
|
283 {
|
|
284 return invokeObjcSelf!(void, "getObjects:", id*)(objects);
|
|
285 }
|
|
286
|
|
287 void getObjects (id* objects, NSRange range)
|
|
288 {
|
|
289 return invokeObjcSelf!(void, "getObjects:range:", id*, NSRange)(objects, range);
|
|
290 }
|
|
291
|
|
292 NSUInteger indexOfObject (Object anObject)
|
|
293 {
|
|
294 return invokeObjcSelf!(NSUInteger, "indexOfObject:", Object)(anObject);
|
|
295 }
|
|
296
|
|
297 NSUInteger indexOfObject (Object anObject, NSRange range)
|
|
298 {
|
|
299 return invokeObjcSelf!(NSUInteger, "indexOfObject:inRange:", Object, NSRange)(anObject, range);
|
|
300 }
|
|
301
|
|
302 NSUInteger indexOfObjectIdenticalTo (Object anObject)
|
|
303 {
|
|
304 return invokeObjcSelf!(NSUInteger, "indexOfObjectIdenticalTo:", Object)(anObject);
|
|
305 }
|
|
306
|
|
307 NSUInteger indexOfObjectIdenticalTo (Object anObject, NSRange range)
|
|
308 {
|
|
309 return invokeObjcSelf!(NSUInteger, "indexOfObjectIdenticalTo:inRange:", Object, NSRange)(anObject, range);
|
|
310 }
|
|
311
|
|
312 bool isEqualToArray (NSArray otherArray)
|
|
313 {
|
|
314 return invokeObjcSelf!(bool, "isEqualToArray:", NSArray)(otherArray);
|
|
315 }
|
|
316
|
|
317 Object lastObject ()
|
|
318 {
|
|
319 return invokeObjcSelf!(Object, "lastObject");
|
|
320 }
|
|
321
|
|
322 NSEnumerator objectEnumerator ()
|
|
323 {
|
|
324 return invokeObjcSelf!(NSEnumerator, "objectEnumerator");
|
|
325 }
|
|
326
|
|
327 NSEnumerator reverseObjectEnumerator ()
|
|
328 {
|
|
329 return invokeObjcSelf!(NSEnumerator, "reverseObjectEnumerator");
|
|
330 }
|
|
331
|
|
332 NSData sortedArrayHint ()
|
|
333 {
|
|
334 return invokeObjcSelf!(NSData, "sortedArrayHint");
|
|
335 }
|
|
336
|
|
337 NSArray sortedArrayUsingFunction (NSInteger *id, id, void* comparator, void* context)
|
|
338 {
|
|
339 return invokeObjcSelf!(NSArray, "sortedArrayUsingFunction:context:", NSInteger *id, id, void*, void*)(comparator, context);
|
|
340 }
|
|
341
|
|
342 NSArray sortedArrayUsingFunction (NSInteger *id, id, void* comparator, void* context, NSData hint)
|
|
343 {
|
|
344 return invokeObjcSelf!(NSArray, "sortedArrayUsingFunction:context:hint:", NSInteger *id, id, void*, void*, NSData)(comparator, context, hint);
|
|
345 }
|
|
346
|
|
347 NSArray sortedArrayUsingSelector (SEL comparator)
|
|
348 {
|
|
349 return invokeObjcSelf!(NSArray, "sortedArrayUsingSelector:", SEL)(comparator);
|
|
350 }
|
|
351
|
|
352 NSArray subarrayWithRange (NSRange range)
|
|
353 {
|
|
354 return invokeObjcSelf!(NSArray, "subarrayWithRange:", NSRange)(range);
|
|
355 }
|
|
356
|
|
357 bool writeToFile (NSString path, bool useAuxiliaryFile)
|
|
358 {
|
|
359 return invokeObjcSelf!(bool, "writeToFile:atomically:", NSString, bool)(path, useAuxiliaryFile);
|
|
360 }
|
|
361
|
|
362 bool writeToURL (NSURL url, bool atomically)
|
|
363 {
|
|
364 return invokeObjcSelf!(bool, "writeToURL:atomically:", NSURL, bool)(url, atomically);
|
|
365 }
|
|
366
|
|
367 void makeObjectsPerformSelector (SEL aSelector)
|
|
368 {
|
|
369 return invokeObjcSelf!(void, "makeObjectsPerformSelector:", SEL)(aSelector);
|
|
370 }
|
|
371
|
|
372 void makeObjectsPerformSelector (SEL aSelector, Object argument)
|
|
373 {
|
|
374 return invokeObjcSelf!(void, "makeObjectsPerformSelector:withObject:", SEL, Object)(aSelector, argument);
|
|
375 }
|
|
376
|
|
377 NSArray objectsAtIndexes (NSIndexSet indexes)
|
|
378 {
|
|
379 return invokeObjcSelf!(NSArray, "objectsAtIndexes:", NSIndexSet)(indexes);
|
|
380 }
|
|
381 }
|
|
382
|
|
383 template TNSExtendedMutableArray ()
|
|
384 {
|
|
385 void addObjectsFromArray (NSArray otherArray)
|
|
386 {
|
|
387 return invokeObjcSelf!(void, "addObjectsFromArray:", NSArray)(otherArray);
|
|
388 }
|
|
389
|
|
390 void exchangeObjectAtIndex (NSUInteger idx1, NSUInteger idx2)
|
|
391 {
|
|
392 return invokeObjcSelf!(void, "exchangeObjectAtIndex:withObjectAtIndex:", NSUInteger, NSUInteger)(idx1, idx2);
|
|
393 }
|
|
394
|
|
395 void removeAllObjects ()
|
|
396 {
|
|
397 return invokeObjcSelf!(void, "removeAllObjects");
|
|
398 }
|
|
399
|
|
400 void removeObject (Object anObject, NSRange range)
|
|
401 {
|
|
402 return invokeObjcSelf!(void, "removeObject:inRange:", Object, NSRange)(anObject, range);
|
|
403 }
|
|
404
|
|
405 void removeObject (Object anObject)
|
|
406 {
|
|
407 return invokeObjcSelf!(void, "removeObject:", Object)(anObject);
|
|
408 }
|
|
409
|
|
410 void removeObjectIdenticalTo (Object anObject, NSRange range)
|
|
411 {
|
|
412 return invokeObjcSelf!(void, "removeObjectIdenticalTo:inRange:", Object, NSRange)(anObject, range);
|
|
413 }
|
|
414
|
|
415 void removeObjectIdenticalTo (Object anObject)
|
|
416 {
|
|
417 return invokeObjcSelf!(void, "removeObjectIdenticalTo:", Object)(anObject);
|
|
418 }
|
|
419
|
|
420 void removeObjectsFromIndices (NSUInteger* indices, NSUInteger cnt)
|
|
421 {
|
|
422 return invokeObjcSelf!(void, "removeObjectsFromIndices:numIndices:", NSUInteger*, NSUInteger)(indices, cnt);
|
|
423 }
|
|
424
|
|
425 void removeObjectsInArray (NSArray otherArray)
|
|
426 {
|
|
427 return invokeObjcSelf!(void, "removeObjectsInArray:", NSArray)(otherArray);
|
|
428 }
|
|
429
|
|
430 void removeObjectsInRange (NSRange range)
|
|
431 {
|
|
432 return invokeObjcSelf!(void, "removeObjectsInRange:", NSRange)(range);
|
|
433 }
|
|
434
|
|
435 void replaceObjectsInRange (NSRange range, NSArray otherArray, NSRange otherRange)
|
|
436 {
|
|
437 return invokeObjcSelf!(void, "replaceObjectsInRange:withObjectsFromArray:range:", NSRange, NSArray, NSRange)(range, otherArray, otherRange);
|
|
438 }
|
|
439
|
|
440 void replaceObjectsInRange (NSRange range, NSArray otherArray)
|
|
441 {
|
|
442 return invokeObjcSelf!(void, "replaceObjectsInRange:withObjectsFromArray:", NSRange, NSArray)(range, otherArray);
|
|
443 }
|
|
444
|
|
445 void setArray (NSArray otherArray)
|
|
446 {
|
|
447 return invokeObjcSelf!(void, "setArray:", NSArray)(otherArray);
|
|
448 }
|
|
449
|
|
450 void sortUsingFunction (NSInteger *id, id, void* compare, void* context)
|
|
451 {
|
|
452 return invokeObjcSelf!(void, "sortUsingFunction:context:", NSInteger *id, id, void*, void*)(compare, context);
|
|
453 }
|
|
454
|
|
455 void sortUsingSelector (SEL comparator)
|
|
456 {
|
|
457 return invokeObjcSelf!(void, "sortUsingSelector:", SEL)(comparator);
|
|
458 }
|
|
459
|
|
460 void insertObjects (NSArray objects, NSIndexSet indexes)
|
|
461 {
|
|
462 return invokeObjcSelf!(void, "insertObjects:atIndexes:", NSArray, NSIndexSet)(objects, indexes);
|
|
463 }
|
|
464
|
|
465 void removeObjectsAtIndexes (NSIndexSet indexes)
|
|
466 {
|
|
467 return invokeObjcSelf!(void, "removeObjectsAtIndexes:", NSIndexSet)(indexes);
|
|
468 }
|
|
469
|
|
470 void replaceObjectsAtIndexes (NSIndexSet indexes, NSArray objects)
|
|
471 {
|
|
472 return invokeObjcSelf!(void, "replaceObjectsAtIndexes:withObjects:", NSIndexSet, NSArray)(indexes, objects);
|
|
473 }
|
|
474 }
|
|
475
|
|
476 template TNSMutableArrayCreation ()
|
|
477 {
|
|
478 static Object arrayWithCapacity (NSUInteger numItems)
|
|
479 {
|
|
480 return invokeObjcSelfClass!(Object, "arrayWithCapacity:", NSUInteger)(numItems);
|
|
481 }
|
|
482
|
|
483 Object initWithCapacity (NSUInteger numItems)
|
|
484 {
|
|
485 return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(numItems);
|
|
486 }
|
|
487
|
|
488 this (NSUInteger numItems)
|
|
489 {
|
|
490 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
491 id result = Bridge.invokeObjcMethod!(id, "initWithCapacity:", NSUInteger)(objcObject, numItems);
|
|
492
|
|
493 if (result)
|
|
494 objcObject = ret;
|
|
495
|
|
496 dObject = this;
|
|
497 }
|
|
498 }
|
|
499
|