comparison dwt/internal/cocoa/NSArray.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents f565d3a95c0a
children 62202ce0039f
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2007 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * 10 *
11 * Port to the D programming language: 11 * Port to the D programming language:
12 * Jacob Carlborg <jacob.carlborg@gmail.com> 12 * Jacob Carlborg <doob@me.com>
13 *******************************************************************************/ 13 *******************************************************************************/
14 module dwt.internal.cocoa.NSArray; 14 module dwt.internal.cocoa.NSArray;
15 15
16 import dwt.internal.cocoa.id; 16 import dwt.dwthelper.utils;
17 import dwt.internal.cocoa.NSData; 17 import cocoa = dwt.internal.cocoa.id;
18 import dwt.internal.cocoa.NSEnumerator;
19 import dwt.internal.cocoa.NSIndexSet;
20 import dwt.internal.cocoa.NSInteger;
21 import dwt.internal.cocoa.NSObject; 18 import dwt.internal.cocoa.NSObject;
22 import dwt.internal.cocoa.NSPredicate;
23 import dwt.internal.cocoa.NSRange;
24 import dwt.internal.cocoa.NSString;
25 import dwt.internal.cocoa.NSURL;
26 import dwt.internal.cocoa.OS; 19 import dwt.internal.cocoa.OS;
20 import dwt.internal.objc.cocoa.Cocoa;
27 import objc = dwt.internal.objc.runtime; 21 import objc = dwt.internal.objc.runtime;
28 22
29 public class NSArray : NSObject 23 public class NSArray : NSObject {
30 {
31 24
32 public this () 25 public this() {
33 { 26 super();
34 super(); 27 }
35 }
36 28
37 public this (objc.id id) 29 public this(objc.id id) {
38 { 30 super(id);
39 super(id); 31 }
40 }
41 32
42 public void addObserver_forKeyPath_options_context_ (NSObject observer, NSString keyPath, objc.id options, objc.id context) 33 public this(cocoa.id id) {
43 { 34 super(id);
44 OS.objc_msgSend(this.id_, OS.sel_addObserver_1forKeyPath_1options_1context_1, observer !is null ? observer.id_ : null, 35 }
45 keyPath !is null ? keyPath.id_ : null, options, context);
46 }
47 36
48 public void addObserver_toObjectsAtIndexes_forKeyPath_options_context_ (NSObject observer, NSIndexSet indexes, NSString keyPath, objc.id options, 37 public static NSArray array() {
49 objc.id context) 38 objc.id result = OS.objc_msgSend(OS.class_NSArray, OS.sel_array);
50 { 39 return result !is null ? new NSArray(result) : null;
51 OS.objc_msgSend(this.id_, OS.sel_addObserver_1toObjectsAtIndexes_1forKeyPath_1options_1context_1, observer !is null ? observer.id_ : null, 40 }
52 indexes !is null ? indexes.id_ : null, keyPath !is null ? keyPath.id_ : null, options, context);
53 }
54 41
55 public static id array () 42 public static NSArray arrayWithObject(cocoa.id anObject) {
56 { 43 objc.id result = OS.objc_msgSend(OS.class_NSArray, OS.sel_arrayWithObject_, anObject !is null ? anObject.id : null);
57 objc.id result = OS.objc_msgSend(OS.class_NSArray, OS.sel_array); 44 return result !is null ? new NSArray(result) : null;
58 return result !is null ? new id(result) : null; 45 }
59 }
60 46
61 public NSArray arrayByAddingObject (id anObject) 47 public bool containsObject(cocoa.id anObject) {
62 { 48 return OS.objc_msgSend_bool(this.id, OS.sel_containsObject_, anObject !is null ? anObject.id : null);
63 objc.id result = OS.objc_msgSend(this.id_, OS.sel_arrayByAddingObject_1, anObject !is null ? anObject.id_ : null); 49 }
64 return result is this.id_ ? this : (result !is null ? new NSArray(result) : null);
65 }
66 50
67 public NSArray arrayByAddingObjectsFromArray (NSArray otherArray) 51 public NSUInteger count() {
68 { 52 return OS.objc_msgSend(this.id, OS.sel_count);
69 objc.id result = OS.objc_msgSend(this.id_, OS.sel_arrayByAddingObjectsFromArray_1, otherArray !is null ? otherArray.id_ : null); 53 }
70 return result is this.id_ ? this : (result !is null ? new NSArray(result) : null);
71 }
72 54
73 public static id arrayWithArray (NSArray array) 55 public cocoa.id objectAtIndex(NSUInteger index) {
74 { 56 objc.id result = OS.objc_msgSend(this.id, OS.sel_objectAtIndex_, index);
75 objc.id result = OS.objc_msgSend(OS.class_NSArray, OS.sel_arrayWithArray_1, array !is null ? array.id_ : null); 57 return result !is null ? new cocoa.id(result) : null;
76 return result !is null ? new id(result) : null; 58 }
77 }
78
79 public static id arrayWithContentsOfFile (NSString path)
80 {
81 objc.id result = OS.objc_msgSend(OS.class_NSArray, OS.sel_arrayWithContentsOfFile_1, path !is null ? path.id_ : null);
82 return result !is null ? new id(result) : null;
83 }
84
85 public static id arrayWithContentsOfURL (NSURL url)
86 {
87 objc.id result = OS.objc_msgSend(OS.class_NSArray, OS.sel_arrayWithContentsOfURL_1, url !is null ? url.id_ : null);
88 return result !is null ? new id(result) : null;
89 }
90
91 public static id arrayWithObject (id anObject)
92 {
93 objc.id result = OS.objc_msgSend(OS.class_NSArray, OS.sel_arrayWithObject_1, anObject !is null ? anObject.id_ : null);
94 return result !is null ? new id(result) : null;
95 }
96
97 public static id static_arrayWithObjects_ (id arrayWithObjects)
98 {
99 objc.id result = OS.objc_msgSend(OS.class_NSArray, OS.sel_arrayWithObjects_1, arrayWithObjects !is null ? arrayWithObjects.id_ : null);
100 return result !is null ? new id(result) : null;
101 }
102
103 public static id static_arrayWithObjects_count_ (/*const*/objc.id* objects, NSUInteger cnt)
104 {
105 objc.id result = OS.objc_msgSend(OS.class_NSArray, OS.sel_arrayWithObjects_1count_1, objects, cnt);
106 return result !is null ? new id(result) : null;
107 }
108
109 public NSString componentsJoinedByString (NSString separator)
110 {
111 objc.id result = OS.objc_msgSend(this.id_, OS.sel_componentsJoinedByString_1, separator !is null ? separator.id_ : null);
112 return result !is null ? new NSString(result) : null;
113 }
114
115 public bool containsObject (id anObject)
116 {
117 return OS.objc_msgSend(this.id_, OS.sel_containsObject_1, anObject !is null ? anObject.id_ : null) !is null;
118 }
119
120 public NSUInteger count ()
121 {
122 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_count);
123 }
124
125 public NSString description ()
126 {
127 objc.id result = OS.objc_msgSend(this.id_, OS.sel_description);
128 return result !is null ? new NSString(result) : null;
129 }
130
131 public NSString descriptionWithLocale_ (id locale)
132 {
133 objc.id result = OS.objc_msgSend(this.id_, OS.sel_descriptionWithLocale_1, locale !is null ? locale.id_ : null);
134 return result !is null ? new NSString(result) : null;
135 }
136
137 public NSString descriptionWithLocale_indent_ (id locale, objc.id level)
138 {
139 objc.id result = OS.objc_msgSend(this.id_, OS.sel_descriptionWithLocale_1indent_1, locale !is null ? locale.id_ : null, level);
140 return result !is null ? new NSString(result) : null;
141 }
142
143 public NSArray filteredArrayUsingPredicate (NSPredicate predicate)
144 {
145 objc.id result = OS.objc_msgSend(this.id_, OS.sel_filteredArrayUsingPredicate_1, predicate !is null ? predicate.id_ : null);
146 return result is this.id_ ? this : (result !is null ? new NSArray(result) : null);
147 }
148
149 public id firstObjectCommonWithArray (NSArray otherArray)
150 {
151 objc.id result = OS.objc_msgSend(this.id_, OS.sel_firstObjectCommonWithArray_1, otherArray !is null ? otherArray.id_ : null);
152 return result !is null ? new id(result) : null;
153 }
154
155 public void getObjects_ (objc.id objects)
156 {
157 OS.objc_msgSend(this.id_, OS.sel_getObjects_1, objects);
158 }
159
160 public void getObjects_range_ (objc.id objects, NSRange range)
161 {
162 OS.objc_msgSend(this.id_, OS.sel_getObjects_1range_1, objects, range);
163 }
164
165 public NSUInteger indexOfObject_ (id anObject)
166 {
167 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_indexOfObject_1, anObject !is null ? anObject.id_ : null);
168 }
169
170 public NSUInteger indexOfObject_inRange_ (id anObject, NSRange range)
171 {
172 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_indexOfObject_1inRange_1, anObject !is null ? anObject.id_ : null, range);
173 }
174
175 public NSUInteger indexOfObjectIdenticalTo_ (id anObject)
176 {
177 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_indexOfObjectIdenticalTo_1, anObject !is null ? anObject.id_ : null);
178 }
179
180 public NSUInteger indexOfObjectIdenticalTo_inRange_ (id anObject, NSRange range)
181 {
182 return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_indexOfObjectIdenticalTo_1inRange_1, anObject !is null ? anObject.id_ : null, range);
183 }
184
185 public NSArray initWithArray_ (NSArray array)
186 {
187 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithArray_1, array !is null ? array.id_ : null);
188 return result !is null ? this : null;
189 }
190
191 public NSArray initWithArray_copyItems_ (NSArray array, bool flag)
192 {
193 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithArray_1copyItems_1, array !is null ? array.id_ : null, flag);
194 return result !is null ? this : null;
195 }
196
197 public NSArray initWithContentsOfFile (NSString path)
198 {
199 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithContentsOfFile_1, path !is null ? path.id_ : null);
200 return result !is null ? this : null;
201 }
202
203 public NSArray initWithContentsOfURL (NSURL url)
204 {
205 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithContentsOfURL_1, url !is null ? url.id_ : null);
206 return result !is null ? this : null;
207 }
208
209 public NSArray initWithObjects_ (id initWithObjects)
210 {
211 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithObjects_1, initWithObjects !is null ? initWithObjects.id_ : null);
212 return result !is null ? this : null;
213 }
214
215 public NSArray initWithObjects_count_ (/*const*/objc.id* objects, NSUInteger cnt)
216 {
217 objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithObjects_1count_1, objects, cnt);
218 return result !is null ? this : null;
219 }
220
221 public bool isEqualToArray (NSArray otherArray)
222 {
223 return OS.objc_msgSend(this.id_, OS.sel_isEqualToArray_1, otherArray !is null ? otherArray.id_ : null) !is null;
224 }
225
226 public id lastObject ()
227 {
228 objc.id result = OS.objc_msgSend(this.id_, OS.sel_lastObject);
229 return result !is null ? new id(result) : null;
230 }
231
232 public void makeObjectsPerformSelector_ (objc.SEL aSelector)
233 {
234 OS.objc_msgSend(this.id_, OS.sel_makeObjectsPerformSelector_1, aSelector);
235 }
236
237 public void makeObjectsPerformSelector_withObject_ (objc.SEL aSelector, id argument)
238 {
239 OS.objc_msgSend(this.id_, OS.sel_makeObjectsPerformSelector_1withObject_1, aSelector, argument !is null ? argument.id_ : null);
240 }
241
242 public objc.id objectAtIndex (NSUInteger index)
243 {
244 objc.id result = OS.objc_msgSend(this.id_, OS.sel_objectAtIndex_1, index);
245 return result;
246 // return result !is null ? new id(result) : null;
247 }
248
249 public NSEnumerator objectEnumerator ()
250 {
251 objc.id result = OS.objc_msgSend(this.id_, OS.sel_objectEnumerator);
252 return result !is null ? new NSEnumerator(result) : null;
253 }
254
255 public NSArray objectsAtIndexes (NSIndexSet indexes)
256 {
257 objc.id result = OS.objc_msgSend(this.id_, OS.sel_objectsAtIndexes_1, indexes !is null ? indexes.id_ : null);
258 return result is this.id_ ? this : (result !is null ? new NSArray(result) : null);
259 }
260
261 public NSArray pathsMatchingExtensions (NSArray filterTypes)
262 {
263 objc.id result = OS.objc_msgSend(this.id_, OS.sel_pathsMatchingExtensions_1, filterTypes !is null ? filterTypes.id_ : null);
264 return result is this.id_ ? this : (result !is null ? new NSArray(result) : null);
265 }
266
267 public void removeObserver_forKeyPath_ (NSObject observer, NSString keyPath)
268 {
269 OS.objc_msgSend(this.id_, OS.sel_removeObserver_1forKeyPath_1, observer !is null ? observer.id_ : null, keyPath !is null ? keyPath.id_ : null);
270 }
271
272 public void removeObserver_fromObjectsAtIndexes_forKeyPath_ (NSObject observer, NSIndexSet indexes, NSString keyPath)
273 {
274 OS.objc_msgSend(this.id_, OS.sel_removeObserver_1fromObjectsAtIndexes_1forKeyPath_1, observer !is null ? observer.id_ : null,
275 indexes !is null ? indexes.id_ : null, keyPath !is null ? keyPath.id_ : null);
276 }
277
278 public NSEnumerator reverseObjectEnumerator ()
279 {
280 objc.id result = OS.objc_msgSend(this.id_, OS.sel_reverseObjectEnumerator);
281 return result !is null ? new NSEnumerator(result) : null;
282 }
283
284 public void setValue (id value, NSString key)
285 {
286 OS.objc_msgSend(this.id_, OS.sel_setValue_1forKey_1, value !is null ? value.id_ : null, key !is null ? key.id_ : null);
287 }
288
289 public NSData sortedArrayHint ()
290 {
291 objc.id result = OS.objc_msgSend(this.id_, OS.sel_sortedArrayHint);
292 return result !is null ? new NSData(result) : null;
293 }
294
295 public NSArray sortedArrayUsingDescriptors (NSArray sortDescriptors)
296 {
297 objc.id result = OS.objc_msgSend(this.id_, OS.sel_sortedArrayUsingDescriptors_1, sortDescriptors !is null ? sortDescriptors.id_ : null);
298 return result is this.id_ ? this : (result !is null ? new NSArray(result) : null);
299 }
300
301 public NSArray sortedArrayUsingFunction_context_ (objc.id comparator, objc.id context)
302 {
303 objc.id result = OS.objc_msgSend(this.id_, OS.sel_sortedArrayUsingFunction_1context_1, comparator, context);
304 return result is this.id_ ? this : (result !is null ? new NSArray(result) : null);
305 }
306
307 public NSArray sortedArrayUsingFunction_context_hint_ (objc.id comparator, objc.id context, NSData hint)
308 {
309 objc.id result = OS.objc_msgSend(this.id_, OS.sel_sortedArrayUsingFunction_1context_1hint_1, comparator, context,
310 hint !is null ? hint.id_ : null);
311 return result is this.id_ ? this : (result !is null ? new NSArray(result) : null);
312 }
313
314 public NSArray sortedArrayUsingSelector (objc.id comparator)
315 {
316 objc.id result = OS.objc_msgSend(this.id_, OS.sel_sortedArrayUsingSelector_1, comparator);
317 return result is this.id_ ? this : (result !is null ? new NSArray(result) : null);
318 }
319
320 public NSArray subarrayWithRange (NSRange range)
321 {
322 objc.id result = OS.objc_msgSend(this.id_, OS.sel_subarrayWithRange_1, range);
323 return result is this.id_ ? this : (result !is null ? new NSArray(result) : null);
324 }
325
326 public id valueForKey (NSString key)
327 {
328 objc.id result = OS.objc_msgSend(this.id_, OS.sel_valueForKey_1, key !is null ? key.id_ : null);
329 return result !is null ? new id(result) : null;
330 }
331
332 public bool writeToFile (NSString path, bool useAuxiliaryFile)
333 {
334 return OS.objc_msgSend(this.id_, OS.sel_writeToFile_1atomically_1, path !is null ? path.id_ : null, useAuxiliaryFile) !is null;
335 }
336
337 public bool writeToURL (NSURL url, bool atomically)
338 {
339 return OS.objc_msgSend(this.id_, OS.sel_writeToURL_1atomically_1, url !is null ? url.id_ : null, atomically) !is null;
340 }
341 59
342 } 60 }