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.NSDictionary;
|
|
8
|
|
9 import dstep.foundation.NSArray;
|
|
10 import dstep.foundation.NSEnumerator;
|
|
11 import dstep.foundation.NSObject;
|
|
12 import dstep.foundation.NSString;
|
|
13 import dstep.foundation.NSURL;
|
|
14 import dstep.objc.bridge.Bridge;
|
|
15 import dstep.objc.objc : id;
|
|
16
|
|
17 class NSMutableDictionary : NSDictionary
|
|
18 {
|
|
19 mixin ObjcWrap;
|
|
20 mixin TNSMutableDictionaryCreation;
|
|
21 mixin TNSExtendedMutableDictionary;
|
|
22
|
|
23 void removeObjectForKey (Object aKey)
|
|
24 {
|
|
25 return invokeObjcSelf!(void, "removeObjectForKey:", Object)(aKey);
|
|
26 }
|
|
27
|
|
28 void setObject (Object anObject, Object aKey)
|
|
29 {
|
|
30 return invokeObjcSelf!(void, "setObject:forKey:", Object, Object)(anObject, aKey);
|
|
31 }
|
|
32 }
|
|
33
|
|
34 class NSDictionary : NSObject, INSCopying, INSMutableCopying, INSCoding, INSFastEnumeration
|
|
35 {
|
|
36 mixin ObjcWrap;
|
|
37 mixin TNSDictionaryCreation;
|
|
38 mixin TNSFileAttributes;
|
|
39 mixin TNSExtendedDictionary;
|
|
40
|
|
41 NSUInteger count ()
|
|
42 {
|
|
43 return invokeObjcSelf!(NSUInteger, "count");
|
|
44 }
|
|
45
|
|
46 Object objectForKey (Object aKey)
|
|
47 {
|
|
48 return invokeObjcSelf!(Object, "objectForKey:", Object)(aKey);
|
|
49 }
|
|
50
|
|
51 NSEnumerator keyEnumerator ()
|
|
52 {
|
|
53 return invokeObjcSelf!(NSEnumerator, "keyEnumerator");
|
|
54 }
|
|
55
|
|
56 Object copyWithZone (NSZone* zone)
|
|
57 {
|
|
58 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
|
|
59 }
|
|
60
|
|
61 Object mutableCopyWithZone (NSZone* zone)
|
|
62 {
|
|
63 return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone);
|
|
64 }
|
|
65
|
|
66 void encodeWithCoder (NSCoder aCoder)
|
|
67 {
|
|
68 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
|
|
69 }
|
|
70
|
|
71 Object initWithCoder (NSCoder aDecoder)
|
|
72 {
|
|
73 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
|
|
74 }
|
|
75
|
|
76 this (NSCoder aDecoder)
|
|
77 {
|
|
78 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
79 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
|
|
80
|
|
81 if (result)
|
|
82 objcObject = ret;
|
|
83
|
|
84 dObject = this;
|
|
85 }
|
|
86
|
|
87 NSUInteger countByEnumeratingWithState (NSFastEnumerationState* state, id* stackbuf, NSUInteger len)
|
|
88 {
|
|
89 return invokeObjcSelf!(NSUInteger, "countByEnumeratingWithState:objects:count:", NSFastEnumerationState*, id*, NSUInteger)(state, stackbuf, len);
|
|
90 }
|
|
91 }
|
|
92
|
|
93 template TNSDictionaryCreation ()
|
|
94 {
|
|
95 static Object dictionary ()
|
|
96 {
|
|
97 return invokeObjcSelfClass!(Object, "dictionary");
|
|
98 }
|
|
99
|
|
100 static Object dictionaryWithObject (Object object, Object key)
|
|
101 {
|
|
102 return invokeObjcSelfClass!(Object, "dictionaryWithObject:forKey:", Object, Object)(object, key);
|
|
103 }
|
|
104
|
|
105 static Object dictionaryWithObjects (id* objects, id* keys, NSUInteger cnt)
|
|
106 {
|
|
107 return invokeObjcSelfClass!(Object, "dictionaryWithObjects:forKeys:count:", id*, id*, NSUInteger)(objects, keys, cnt);
|
|
108 }
|
|
109
|
|
110 static Object dictionaryWithObjectsAndKeys (Object dictionaryWithObjectsAndKeys, ...)
|
|
111 {
|
|
112 return invokeObjcSelfClass!(Object, "dictionaryWithObjectsAndKeys:", Object)(dictionaryWithObjectsAndKeys);
|
|
113 }
|
|
114
|
|
115 static Object dictionaryWithDictionary (NSDictionary dict)
|
|
116 {
|
|
117 return invokeObjcSelfClass!(Object, "dictionaryWithDictionary:", NSDictionary)(dict);
|
|
118 }
|
|
119
|
|
120 static Object dictionaryWithObjects (NSArray objects, NSArray keys)
|
|
121 {
|
|
122 return invokeObjcSelfClass!(Object, "dictionaryWithObjects:forKeys:", NSArray, NSArray)(objects, keys);
|
|
123 }
|
|
124
|
|
125 Object initWithObjects (id* objects, id* keys, NSUInteger cnt)
|
|
126 {
|
|
127 return invokeObjcSelf!(Object, "initWithObjects:forKeys:count:", id*, id*, NSUInteger)(objects, keys, cnt);
|
|
128 }
|
|
129
|
|
130 this (id* objects, id* keys, NSUInteger cnt)
|
|
131 {
|
|
132 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
133 id result = Bridge.invokeObjcMethod!(id, "initWithObjects:forKeys:count:", id*, id*, NSUInteger)(objcObject, objects, keys, cnt);
|
|
134
|
|
135 if (result)
|
|
136 objcObject = ret;
|
|
137
|
|
138 dObject = this;
|
|
139 }
|
|
140
|
|
141 Object initWithObjectsAndKeys (Object initWithObjectsAndKeys, ...)
|
|
142 {
|
|
143 return invokeObjcSelf!(Object, "initWithObjectsAndKeys:", Object)(initWithObjectsAndKeys);
|
|
144 }
|
|
145
|
|
146 this (Object initWithObjectsAndKeys, ...)
|
|
147 {
|
|
148 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
149 id result = Bridge.invokeObjcMethod!(id, "initWithObjectsAndKeys:", Object)(objcObject, initWithObjectsAndKeys);
|
|
150
|
|
151 if (result)
|
|
152 objcObject = ret;
|
|
153
|
|
154 dObject = this;
|
|
155 }
|
|
156
|
|
157 Object initWithDictionary (NSDictionary otherDictionary)
|
|
158 {
|
|
159 return invokeObjcSelf!(Object, "initWithDictionary:", NSDictionary)(otherDictionary);
|
|
160 }
|
|
161
|
|
162 this (NSDictionary otherDictionary)
|
|
163 {
|
|
164 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
165 id result = Bridge.invokeObjcMethod!(id, "initWithDictionary:", NSDictionary)(objcObject, otherDictionary);
|
|
166
|
|
167 if (result)
|
|
168 objcObject = ret;
|
|
169
|
|
170 dObject = this;
|
|
171 }
|
|
172
|
|
173 Object initWithDictionary (NSDictionary otherDictionary, bool flag)
|
|
174 {
|
|
175 return invokeObjcSelf!(Object, "initWithDictionary:copyItems:", NSDictionary, bool)(otherDictionary, flag);
|
|
176 }
|
|
177
|
|
178 this (NSDictionary otherDictionary, bool flag)
|
|
179 {
|
|
180 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
181 id result = Bridge.invokeObjcMethod!(id, "initWithDictionary:copyItems:", NSDictionary, bool)(objcObject, otherDictionary, flag);
|
|
182
|
|
183 if (result)
|
|
184 objcObject = ret;
|
|
185
|
|
186 dObject = this;
|
|
187 }
|
|
188
|
|
189 Object initWithObjects (NSArray objects, NSArray keys)
|
|
190 {
|
|
191 return invokeObjcSelf!(Object, "initWithObjects:forKeys:", NSArray, NSArray)(objects, keys);
|
|
192 }
|
|
193
|
|
194 this (NSArray objects, NSArray keys)
|
|
195 {
|
|
196 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
197 id result = Bridge.invokeObjcMethod!(id, "initWithObjects:forKeys:", NSArray, NSArray)(objcObject, objects, keys);
|
|
198
|
|
199 if (result)
|
|
200 objcObject = ret;
|
|
201
|
|
202 dObject = this;
|
|
203 }
|
|
204
|
|
205 static Object dictionaryWithContentsOfFile (NSString path)
|
|
206 {
|
|
207 return invokeObjcSelfClass!(Object, "dictionaryWithContentsOfFile:", NSString)(path);
|
|
208 }
|
|
209
|
|
210 static Object dictionaryWithContentsOfURL (NSURL url)
|
|
211 {
|
|
212 return invokeObjcSelfClass!(Object, "dictionaryWithContentsOfURL:", NSURL)(url);
|
|
213 }
|
|
214
|
|
215 Object initWithContentsOfFile (NSString path)
|
|
216 {
|
|
217 return invokeObjcSelf!(Object, "initWithContentsOfFile:", NSString)(path);
|
|
218 }
|
|
219
|
|
220 this (NSString path)
|
|
221 {
|
|
222 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
223 id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfFile:", NSString)(objcObject, path);
|
|
224
|
|
225 if (result)
|
|
226 objcObject = ret;
|
|
227
|
|
228 dObject = this;
|
|
229 }
|
|
230
|
|
231 Object initWithContentsOfURL (NSURL url)
|
|
232 {
|
|
233 return invokeObjcSelf!(Object, "initWithContentsOfURL:", NSURL)(url);
|
|
234 }
|
|
235
|
|
236 this (NSURL url)
|
|
237 {
|
|
238 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
239 id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfURL:", NSURL)(objcObject, url);
|
|
240
|
|
241 if (result)
|
|
242 objcObject = ret;
|
|
243
|
|
244 dObject = this;
|
|
245 }
|
|
246 }
|
|
247
|
|
248 template TNSMutableDictionaryCreation ()
|
|
249 {
|
|
250 static Object dictionaryWithCapacity (NSUInteger numItems)
|
|
251 {
|
|
252 return invokeObjcSelfClass!(Object, "dictionaryWithCapacity:", NSUInteger)(numItems);
|
|
253 }
|
|
254
|
|
255 Object initWithCapacity (NSUInteger numItems)
|
|
256 {
|
|
257 return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(numItems);
|
|
258 }
|
|
259
|
|
260 this (NSUInteger numItems)
|
|
261 {
|
|
262 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
263 id result = Bridge.invokeObjcMethod!(id, "initWithCapacity:", NSUInteger)(objcObject, numItems);
|
|
264
|
|
265 if (result)
|
|
266 objcObject = ret;
|
|
267
|
|
268 dObject = this;
|
|
269 }
|
|
270 }
|
|
271
|
|
272 template TNSExtendedMutableDictionary ()
|
|
273 {
|
|
274 void addEntriesFromDictionary (NSDictionary otherDictionary)
|
|
275 {
|
|
276 return invokeObjcSelf!(void, "addEntriesFromDictionary:", NSDictionary)(otherDictionary);
|
|
277 }
|
|
278
|
|
279 void removeAllObjects ()
|
|
280 {
|
|
281 return invokeObjcSelf!(void, "removeAllObjects");
|
|
282 }
|
|
283
|
|
284 void removeObjectsForKeys (NSArray keyArray)
|
|
285 {
|
|
286 return invokeObjcSelf!(void, "removeObjectsForKeys:", NSArray)(keyArray);
|
|
287 }
|
|
288
|
|
289 void setDictionary (NSDictionary otherDictionary)
|
|
290 {
|
|
291 return invokeObjcSelf!(void, "setDictionary:", NSDictionary)(otherDictionary);
|
|
292 }
|
|
293 }
|
|
294
|
|
295 template TNSExtendedDictionary ()
|
|
296 {
|
|
297 NSArray allKeys ()
|
|
298 {
|
|
299 return invokeObjcSelf!(NSArray, "allKeys");
|
|
300 }
|
|
301
|
|
302 NSArray allKeysForObject (Object anObject)
|
|
303 {
|
|
304 return invokeObjcSelf!(NSArray, "allKeysForObject:", Object)(anObject);
|
|
305 }
|
|
306
|
|
307 NSArray allValues ()
|
|
308 {
|
|
309 return invokeObjcSelf!(NSArray, "allValues");
|
|
310 }
|
|
311
|
|
312 NSString description ()
|
|
313 {
|
|
314 return invokeObjcSelf!(NSString, "description");
|
|
315 }
|
|
316
|
|
317 NSString descriptionInStringsFileFormat ()
|
|
318 {
|
|
319 return invokeObjcSelf!(NSString, "descriptionInStringsFileFormat");
|
|
320 }
|
|
321
|
|
322 NSString descriptionWithLocale (Object locale)
|
|
323 {
|
|
324 return invokeObjcSelf!(NSString, "descriptionWithLocale:", Object)(locale);
|
|
325 }
|
|
326
|
|
327 NSString descriptionWithLocale (Object locale, NSUInteger level)
|
|
328 {
|
|
329 return invokeObjcSelf!(NSString, "descriptionWithLocale:indent:", Object, NSUInteger)(locale, level);
|
|
330 }
|
|
331
|
|
332 bool isEqualToDictionary (NSDictionary otherDictionary)
|
|
333 {
|
|
334 return invokeObjcSelf!(bool, "isEqualToDictionary:", NSDictionary)(otherDictionary);
|
|
335 }
|
|
336
|
|
337 NSEnumerator objectEnumerator ()
|
|
338 {
|
|
339 return invokeObjcSelf!(NSEnumerator, "objectEnumerator");
|
|
340 }
|
|
341
|
|
342 NSArray objectsForKeys (NSArray keys, Object marker)
|
|
343 {
|
|
344 return invokeObjcSelf!(NSArray, "objectsForKeys:notFoundMarker:", NSArray, Object)(keys, marker);
|
|
345 }
|
|
346
|
|
347 bool writeToFile (NSString path, bool useAuxiliaryFile)
|
|
348 {
|
|
349 return invokeObjcSelf!(bool, "writeToFile:atomically:", NSString, bool)(path, useAuxiliaryFile);
|
|
350 }
|
|
351
|
|
352 bool writeToURL (NSURL url, bool atomically)
|
|
353 {
|
|
354 return invokeObjcSelf!(bool, "writeToURL:atomically:", NSURL, bool)(url, atomically);
|
|
355 }
|
|
356
|
|
357 NSArray keysSortedByValueUsingSelector (SEL comparator)
|
|
358 {
|
|
359 return invokeObjcSelf!(NSArray, "keysSortedByValueUsingSelector:", SEL)(comparator);
|
|
360 }
|
|
361
|
|
362 void getObjects (id* objects, id* keys)
|
|
363 {
|
|
364 return invokeObjcSelf!(void, "getObjects:andKeys:", id*, id*)(objects, keys);
|
|
365 }
|
|
366 }
|
|
367
|