comparison dstep/foundation/NSSet.d @ 14:89f3c3ef1fd2

Added the Foundation framework
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:23:15 +0200
parents
children 19885b43130e
comparison
equal deleted inserted replaced
13:4f583f7e242e 14:89f3c3ef1fd2
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.NSSet;
8
9 import dstep.foundation.NSArray;
10 import dstep.foundation.NSDictionary;
11 import dstep.foundation.NSEnumerator;
12 import dstep.foundation.NSObject;
13 import dstep.foundation.NSString;
14 import dstep.objc.bridge.Bridge;
15 import dstep.objc.objc : id;
16
17 class NSSet : NSObject, INSCopying, INSMutableCopying, INSCoding, INSFastEnumeration
18 {
19 mixin ObjcWrap;
20 mixin TNSSetCreation;
21 mixin TNSExtendedSet;
22 mixin TNSKeyValueObserverRegistration;
23
24 NSUInteger count ()
25 {
26 return invokeObjcSelf!(NSUInteger, "count");
27 }
28
29 Object member (Object object)
30 {
31 return invokeObjcSelf!(Object, "member:", Object)(object);
32 }
33
34 NSEnumerator objectEnumerator ()
35 {
36 return invokeObjcSelf!(NSEnumerator, "objectEnumerator");
37 }
38
39 Object copyWithZone (NSZone* zone)
40 {
41 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
42 }
43
44 Object mutableCopyWithZone (NSZone* zone)
45 {
46 return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone);
47 }
48
49 void encodeWithCoder (NSCoder aCoder)
50 {
51 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
52 }
53
54 Object initWithCoder (NSCoder aDecoder)
55 {
56 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
57 }
58
59 this (NSCoder aDecoder)
60 {
61 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
62 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
63
64 if (result)
65 objcObject = ret;
66
67 dObject = this;
68 }
69
70 NSUInteger countByEnumeratingWithState (NSFastEnumerationState* state, id* stackbuf, NSUInteger len)
71 {
72 return invokeObjcSelf!(NSUInteger, "countByEnumeratingWithState:objects:count:", NSFastEnumerationState*, id*, NSUInteger)(state, stackbuf, len);
73 }
74 }
75
76 class NSMutableSet : NSSet
77 {
78 mixin ObjcWrap;
79 mixin TNSPredicateSupport;
80 mixin TNSMutableSetCreation;
81 mixin TNSExtendedMutableSet;
82
83 void addObject (Object object)
84 {
85 return invokeObjcSelf!(void, "addObject:", Object)(object);
86 }
87
88 void removeObject (Object object)
89 {
90 return invokeObjcSelf!(void, "removeObject:", Object)(object);
91 }
92 }
93
94 class NSCountedSet : NSMutableSet
95 {
96 mixin ObjcWrap;
97
98 Object initWithCapacity (NSUInteger numItems)
99 {
100 return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(numItems);
101 }
102
103 this (NSUInteger numItems)
104 {
105 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
106 id result = Bridge.invokeObjcMethod!(id, "initWithCapacity:", NSUInteger)(objcObject, numItems);
107
108 if (result)
109 objcObject = ret;
110
111 dObject = this;
112 }
113
114 Object initWithArray (NSArray array)
115 {
116 return invokeObjcSelf!(Object, "initWithArray:", NSArray)(array);
117 }
118
119 this (NSArray array)
120 {
121 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
122 id result = Bridge.invokeObjcMethod!(id, "initWithArray:", NSArray)(objcObject, array);
123
124 if (result)
125 objcObject = ret;
126
127 dObject = this;
128 }
129
130 Object initWithSet (NSSet set)
131 {
132 return invokeObjcSelf!(Object, "initWithSet:", NSSet)(set);
133 }
134
135 this (NSSet set)
136 {
137 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
138 id result = Bridge.invokeObjcMethod!(id, "initWithSet:", NSSet)(objcObject, set);
139
140 if (result)
141 objcObject = ret;
142
143 dObject = this;
144 }
145
146 NSUInteger countForObject (Object object)
147 {
148 return invokeObjcSelf!(NSUInteger, "countForObject:", Object)(object);
149 }
150
151 NSEnumerator objectEnumerator ()
152 {
153 return invokeObjcSelf!(NSEnumerator, "objectEnumerator");
154 }
155
156 void addObject (Object object)
157 {
158 return invokeObjcSelf!(void, "addObject:", Object)(object);
159 }
160
161 void removeObject (Object object)
162 {
163 return invokeObjcSelf!(void, "removeObject:", Object)(object);
164 }
165 }
166
167 template TNSSetCreation ()
168 {
169 static Object set ()
170 {
171 return invokeObjcSelfClass!(Object, "set");
172 }
173
174 static Object setWithObject (Object object)
175 {
176 return invokeObjcSelfClass!(Object, "setWithObject:", Object)(object);
177 }
178
179 static Object setWithObjects (id* objects, NSUInteger cnt)
180 {
181 return invokeObjcSelfClass!(Object, "setWithObjects:count:", id*, NSUInteger)(objects, cnt);
182 }
183
184 static Object setWithObjects (Object setWithObjects, ...)
185 {
186 return invokeObjcSelfClass!(Object, "setWithObjects:", Object)(setWithObjects);
187 }
188
189 static Object setWithSet (NSSet set)
190 {
191 return invokeObjcSelfClass!(Object, "setWithSet:", NSSet)(set);
192 }
193
194 static Object setWithArray (NSArray array)
195 {
196 return invokeObjcSelfClass!(Object, "setWithArray:", NSArray)(array);
197 }
198
199 Object initWithObjects (id* objects, NSUInteger cnt)
200 {
201 return invokeObjcSelf!(Object, "initWithObjects:count:", id*, NSUInteger)(objects, cnt);
202 }
203
204 this (id* objects, NSUInteger cnt)
205 {
206 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
207 id result = Bridge.invokeObjcMethod!(id, "initWithObjects:count:", id*, NSUInteger)(objcObject, objects, cnt);
208
209 if (result)
210 objcObject = ret;
211
212 dObject = this;
213 }
214
215 Object initWithObjects (Object initWithObjects, ...)
216 {
217 return invokeObjcSelf!(Object, "initWithObjects:", Object)(initWithObjects);
218 }
219
220 this (Object initWithObjects, ...)
221 {
222 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
223 id result = Bridge.invokeObjcMethod!(id, "initWithObjects:", Object)(objcObject, initWithObjects);
224
225 if (result)
226 objcObject = ret;
227
228 dObject = this;
229 }
230
231 Object initWithSet (NSSet set)
232 {
233 return invokeObjcSelf!(Object, "initWithSet:", NSSet)(set);
234 }
235
236 this (NSSet set)
237 {
238 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
239 id result = Bridge.invokeObjcMethod!(id, "initWithSet:", NSSet)(objcObject, set);
240
241 if (result)
242 objcObject = ret;
243
244 dObject = this;
245 }
246
247 Object initWithSet (NSSet set, bool flag)
248 {
249 return invokeObjcSelf!(Object, "initWithSet:copyItems:", NSSet, bool)(set, flag);
250 }
251
252 this (NSSet set, bool flag)
253 {
254 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
255 id result = Bridge.invokeObjcMethod!(id, "initWithSet:copyItems:", NSSet, bool)(objcObject, set, flag);
256
257 if (result)
258 objcObject = ret;
259
260 dObject = this;
261 }
262
263 Object initWithArray (NSArray array)
264 {
265 return invokeObjcSelf!(Object, "initWithArray:", NSArray)(array);
266 }
267
268 this (NSArray array)
269 {
270 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
271 id result = Bridge.invokeObjcMethod!(id, "initWithArray:", NSArray)(objcObject, array);
272
273 if (result)
274 objcObject = ret;
275
276 dObject = this;
277 }
278 }
279
280 template TNSExtendedSet ()
281 {
282 NSArray allObjects ()
283 {
284 return invokeObjcSelf!(NSArray, "allObjects");
285 }
286
287 Object anyObject ()
288 {
289 return invokeObjcSelf!(Object, "anyObject");
290 }
291
292 bool containsObject (Object anObject)
293 {
294 return invokeObjcSelf!(bool, "containsObject:", Object)(anObject);
295 }
296
297 NSString description ()
298 {
299 return invokeObjcSelf!(NSString, "description");
300 }
301
302 NSString descriptionWithLocale (Object locale)
303 {
304 return invokeObjcSelf!(NSString, "descriptionWithLocale:", Object)(locale);
305 }
306
307 bool intersectsSet (NSSet otherSet)
308 {
309 return invokeObjcSelf!(bool, "intersectsSet:", NSSet)(otherSet);
310 }
311
312 bool isEqualToSet (NSSet otherSet)
313 {
314 return invokeObjcSelf!(bool, "isEqualToSet:", NSSet)(otherSet);
315 }
316
317 bool isSubsetOfSet (NSSet otherSet)
318 {
319 return invokeObjcSelf!(bool, "isSubsetOfSet:", NSSet)(otherSet);
320 }
321
322 void makeObjectsPerformSelector (SEL aSelector)
323 {
324 return invokeObjcSelf!(void, "makeObjectsPerformSelector:", SEL)(aSelector);
325 }
326
327 void makeObjectsPerformSelector (SEL aSelector, Object argument)
328 {
329 return invokeObjcSelf!(void, "makeObjectsPerformSelector:withObject:", SEL, Object)(aSelector, argument);
330 }
331
332 NSSet setByAddingObject (Object anObject)
333 {
334 return invokeObjcSelf!(NSSet, "setByAddingObject:", Object)(anObject);
335 }
336
337 NSSet setByAddingObjectsFromSet (NSSet other)
338 {
339 return invokeObjcSelf!(NSSet, "setByAddingObjectsFromSet:", NSSet)(other);
340 }
341
342 NSSet setByAddingObjectsFromArray (NSArray other)
343 {
344 return invokeObjcSelf!(NSSet, "setByAddingObjectsFromArray:", NSArray)(other);
345 }
346 }
347
348 template TNSMutableSetCreation ()
349 {
350 static Object setWithCapacity (NSUInteger numItems)
351 {
352 return invokeObjcSelfClass!(Object, "setWithCapacity:", NSUInteger)(numItems);
353 }
354
355 Object initWithCapacity (NSUInteger numItems)
356 {
357 return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(numItems);
358 }
359
360 this (NSUInteger numItems)
361 {
362 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
363 id result = Bridge.invokeObjcMethod!(id, "initWithCapacity:", NSUInteger)(objcObject, numItems);
364
365 if (result)
366 objcObject = ret;
367
368 dObject = this;
369 }
370 }
371
372 template TNSExtendedMutableSet ()
373 {
374 void addObjectsFromArray (NSArray array)
375 {
376 return invokeObjcSelf!(void, "addObjectsFromArray:", NSArray)(array);
377 }
378
379 void intersectSet (NSSet otherSet)
380 {
381 return invokeObjcSelf!(void, "intersectSet:", NSSet)(otherSet);
382 }
383
384 void minusSet (NSSet otherSet)
385 {
386 return invokeObjcSelf!(void, "minusSet:", NSSet)(otherSet);
387 }
388
389 void removeAllObjects ()
390 {
391 return invokeObjcSelf!(void, "removeAllObjects");
392 }
393
394 void unionSet (NSSet otherSet)
395 {
396 return invokeObjcSelf!(void, "unionSet:", NSSet)(otherSet);
397 }
398
399 void setSet (NSSet otherSet)
400 {
401 return invokeObjcSelf!(void, "setSet:", NSSet)(otherSet);
402 }
403 }
404