ObjFW
 All Classes Functions Variables
OFArray.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #ifndef __STDC_LIMIT_MACROS
18 # define __STDC_LIMIT_MACROS
19 #endif
20 #ifndef __STDC_CONSTANT_MACROS
21 # define __STDC_CONSTANT_MACROS
22 #endif
23 
24 #include <stdarg.h>
25 
26 #import "OFObject.h"
27 #import "OFCollection.h"
28 #import "OFEnumerator.h"
29 #import "OFSerialization.h"
30 #import "OFJSONRepresentation.h"
31 
32 @class OFString;
33 
34 #ifdef OF_HAVE_BLOCKS
35 typedef void (^of_array_enumeration_block_t)(id object, size_t index,
36  BOOL *stop);
37 typedef BOOL (^of_array_filter_block_t)(id odject, size_t index);
38 typedef id (^of_array_map_block_t)(id object, size_t index);
39 typedef id (^of_array_fold_block_t)(id left, id right);
40 #endif
41 
47 #ifdef OF_HAVE_PROPERTIES
48 @property (readonly) size_t count;
49 #endif
50 
56 + (instancetype)array;
57 
64 + (instancetype)arrayWithObject: (id)object;
65 
72 + (instancetype)arrayWithObjects: (id)firstObject, ... OF_SENTINEL;
73 
80 + (instancetype)arrayWithArray: (OFArray*)array;
81 
90 + (instancetype)arrayWithObjects: (id const*)objects
91  count: (size_t)count;
92 
99 - initWithObject: (id)object;
100 
107 - initWithObjects: (id)firstObject, ... OF_SENTINEL;
108 
116 - initWithObject: (id)firstObject
117  arguments: (va_list)arguments;
118 
125 - initWithArray: (OFArray*)array;
126 
135 - initWithObjects: (id const*)objects
136  count: (size_t)count;
137 
147 - (id)objectAtIndex: (size_t)index;
148 - (id)objectAtIndexedSubscript: (size_t)index;
149 
156 - (void)getObjects: (__unsafe_unretained id*)buffer
157  inRange: (of_range_t)range;
158 
164 - (id*)objects;
165 
174 - (size_t)indexOfObject: (id)object;
175 
184 - (size_t)indexOfObjectIdenticalTo: (id)object;
185 
194 - (BOOL)containsObjectIdenticalTo: (id)object;
195 
204 - (id)firstObject;
205 
214 - (id)lastObject;
215 
222 - (OFArray*)objectsInRange: (of_range_t)range;
223 
230 - (OFString*)componentsJoinedByString: (OFString*)separator;
231 
240 - (OFString*)componentsJoinedByString: (OFString*)separator
241  usingSelector: (SEL)selector;
242 
248 - (void)makeObjectsPerformSelector: (SEL)selector;
249 
258 - (void)makeObjectsPerformSelector: (SEL)selector
259  withObject: (id)object;
260 
266 - (OFArray*)sortedArray;
267 
274 
281 - (OFArray*)arrayByAddingObject: (id)object;
282 
289 - (OFArray*)arrayByAddingObjectsFromArray: (OFArray*)array;
290 
297 - (OFArray*)arrayByRemovingObject: (id)object;
298 
299 #ifdef OF_HAVE_BLOCKS
300 
305 - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block;
306 
313 - (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block;
314 
323 - (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block;
324 
341 - (id)foldUsingBlock: (of_array_fold_block_t)block;
342 #endif
343 @end
344 
345 @interface OFArrayEnumerator: OFEnumerator
346 {
347  OFArray *array;
348  size_t count;
349  unsigned long mutations;
350  unsigned long *mutationsPtr;
351  size_t position;
352 }
353 
354 - initWithArray: (OFArray*)data
355  mutationsPtr: (unsigned long*)mutationsPtr;
356 @end
357 
358 #import "OFMutableArray.h"
359 
360 #ifndef NSINTEGER_DEFINED
361 /* Required for array literals to work */
362 @compatibility_alias NSArray OFArray;
363 #endif