ObjFW  Diff

Differences From Artifact [d93b4c3a6a]:

To Artifact [768eda6eec]:


35
36
37
38
39
40
41
42
43


44
45
46
47
48
49
50
51
52


53
54

55
56
57
58
59


60
61
62


63
64
65
66
67


68
69
70


71
72
73
74
75


76
77
78


79
80
81
82
83


84
85
86
87
88



89
90
91
92
93
94


95
96
97


98
99
100
101
102


103
104
105


106
107
108
109
110


111
112
113
114



115
116
117
118
119
120


121
122
123


124
125
126
127
128


129
130
131
132
133



134
135
136
137
138
139


140
141
142
143
144
145


146
147
148
149
150
151


152
153
154


155
156
157
158
159
160


161
162

163
164
165
166
167


168
169
170
171


172
173
174
175
176
177


178
179
180
181


182
183
184
185
186
187


188
189
190
191


192
193
194
195
196
197


198
199
200
201
202

203
204
205
206
207


208
209
210
211
212

213
214
215
216
217


218
219
220


221
222
223
224
225


226
227
228


229
230
231
232
233


234
235
236
237
238



239
240
241
242
243
244


245
246

247
248
249
250
251


252
253
254
255


256
257
258
259
260
261
262


263
264

265
266
267
268
269


270
271

272
273
274
275
276


277
278
279


280
281
282
283
284


285
286
287


288
289
290
291
292


293
294
295


296
297
298
299
300
301


302
303

304
305
306
307
308


309
310
311


312
313
314
315
316


317
318
319

320
321

322
323
324
325
326


327
328
329
330
331
332
333
334
335
336
337

338
339

340
341
342
343
344
345
346
35
36
37
38
39
40
41


42
43
44
45
46
47
48
49
50


51
52
53

54
55
56
57


58
59
60


61
62
63
64
65


66
67
68


69
70
71
72
73


74
75
76


77
78
79
80
81


82
83
84
85



86
87
88
89
90
91
92


93
94
95


96
97
98
99
100


101
102
103


104
105
106
107
108


109
110
111



112
113
114
115
116
117
118


119
120
121


122
123
124
125
126


127
128
129
130



131
132
133
134
135
136
137


138
139
140
141
142
143


144
145
146
147
148
149


150
151
152


153
154
155
156
157
158


159
160
161

162
163
164
165


166
167
168
169


170
171
172
173
174
175


176
177
178
179


180
181
182
183
184
185


186
187
188
189


190
191
192
193
194
195


196
197
198
199
200
201

202
203
204
205


206
207
208
209
210
211

212
213
214
215


216
217
218


219
220
221
222
223


224
225
226


227
228
229
230
231


232
233
234
235



236
237
238
239
240
241
242


243
244
245

246
247
248
249


250
251
252
253


254
255
256
257
258
259
260


261
262
263

264
265
266
267


268
269
270

271
272
273
274


275
276
277


278
279
280
281
282


283
284
285


286
287
288
289
290


291
292
293


294
295
296
297
298
299


300
301
302

303
304
305
306


307
308
309


310
311
312
313
314


315
316
317
318

319
320

321
322
323
324


325
326
327
328
329
330
331
332
333
334
335
336

337
338

339
340
341
342
343
344
345
346







-
-
+
+







-
-
+
+

-
+



-
-
+
+

-
-
+
+



-
-
+
+

-
-
+
+



-
-
+
+

-
-
+
+



-
-
+
+


-
-
-
+
+
+




-
-
+
+

-
-
+
+



-
-
+
+

-
-
+
+



-
-
+
+

-
-
-
+
+
+




-
-
+
+

-
-
+
+



-
-
+
+


-
-
-
+
+
+




-
-
+
+




-
-
+
+




-
-
+
+

-
-
+
+




-
-
+
+

-
+



-
-
+
+


-
-
+
+




-
-
+
+


-
-
+
+




-
-
+
+


-
-
+
+




-
-
+
+




-
+



-
-
+
+




-
+



-
-
+
+

-
-
+
+



-
-
+
+

-
-
+
+



-
-
+
+


-
-
-
+
+
+




-
-
+
+

-
+



-
-
+
+


-
-
+
+





-
-
+
+

-
+



-
-
+
+

-
+



-
-
+
+

-
-
+
+



-
-
+
+

-
-
+
+



-
-
+
+

-
-
+
+




-
-
+
+

-
+



-
-
+
+

-
-
+
+



-
-
+
+


-
+

-
+



-
-
+
+










-
+

-
+







typedef void (^of_array_enumeration_block_t)(id object, size_t index,
    BOOL *stop);
typedef BOOL (^of_array_filter_block_t)(id odject, size_t index);
typedef id (^of_array_map_block_t)(id object, size_t index);
typedef id (^of_array_fold_block_t)(id left, id right);
#endif

/**
 * \brief An abstract class for storing objects in an array.
/*!
 * @brief An abstract class for storing objects in an array.
 */
@interface OFArray: OFObject <OFCopying, OFMutableCopying, OFCollection,
    OFSerialization, OFJSONRepresentation>
#ifdef OF_HAVE_PROPERTIES
@property (readonly) size_t count;
#endif

/**
 * \brief Creates a new OFArray.
/*!
 * @brief Creates a new OFArray.
 *
 * \return A new autoreleased OFArray
 * @return A new autoreleased OFArray
 */
+ (instancetype)array;

/**
 * \brief Creates a new OFArray with the specified object.
/*!
 * @brief Creates a new OFArray with the specified object.
 *
 * \param object An object
 * \return A new autoreleased OFArray
 * @param object An object
 * @return A new autoreleased OFArray
 */
+ (instancetype)arrayWithObject: (id)object;

/**
 * \brief Creates a new OFArray with the specified objects, terminated by nil.
/*!
 * @brief Creates a new OFArray with the specified objects, terminated by nil.
 *
 * \param firstObject The first object in the array
 * \return A new autoreleased OFArray
 * @param firstObject The first object in the array
 * @return A new autoreleased OFArray
 */
+ (instancetype)arrayWithObjects: (id)firstObject, ... OF_SENTINEL;

/**
 * \brief Creates a new OFArray with the objects from the specified array.
/*!
 * @brief Creates a new OFArray with the objects from the specified array.
 *
 * \param array An array
 * \return A new autoreleased OFArray
 * @param array An array
 * @return A new autoreleased OFArray
 */
+ (instancetype)arrayWithArray: (OFArray*)array;

/**
 * \brief Creates a new OFArray with the objects from the specified C array of
/*!
 * @brief Creates a new OFArray with the objects from the specified C array of
 *	  the specified length.
 *
 * \param objects A C array of objects
 * \param length The length of the C array
 * \return A new autoreleased OFArray
 * @param objects A C array of objects
 * @param length The length of the C array
 * @return A new autoreleased OFArray
 */
+ (instancetype)arrayWithObjects: (id const*)objects
			   count: (size_t)count;

/**
 * \brief Initializes an OFArray with the specified object.
/*!
 * @brief Initializes an OFArray with the specified object.
 *
 * \param object An object
 * \return An initialized OFArray
 * @param object An object
 * @return An initialized OFArray
 */
- initWithObject: (id)object;

/**
 * \brief Initializes an OFArray with the specified objects.
/*!
 * @brief Initializes an OFArray with the specified objects.
 *
 * \param firstObject The first object
 * \return An initialized OFArray
 * @param firstObject The first object
 * @return An initialized OFArray
 */
- initWithObjects: (id)firstObject, ... OF_SENTINEL;

/**
 * \brief Initializes an OFArray with the specified object and a va_list.
/*!
 * @brief Initializes an OFArray with the specified object and a va_list.
 *
 * \param firstObject The first object
 * \param arguments A va_list
 * \return An initialized OFArray
 * @param firstObject The first object
 * @param arguments A va_list
 * @return An initialized OFArray
 */
- initWithObject: (id)firstObject
       arguments: (va_list)arguments;

/**
 * \brief Initializes an OFArray with the objects from the specified array.
/*!
 * @brief Initializes an OFArray with the objects from the specified array.
 *
 * \param array An array
 * \return An initialized OFArray
 * @param array An array
 * @return An initialized OFArray
 */
- initWithArray: (OFArray*)array;

/**
 * \brief Initializes an OFArray with the objects from the specified C array of
/*!
 * @brief Initializes an OFArray with the objects from the specified C array of
 *	  the specified length.
 *
 * \param objects A C array of objects
 * \param length The length of the C array
 * \return An initialized OFArray
 * @param objects A C array of objects
 * @param length The length of the C array
 * @return An initialized OFArray
 */
- initWithObjects: (id const*)objects
	    count: (size_t)count;

/**
 * \brief Returns a specified object of the array.
/*!
 * @brief Returns a specified object of the array.
 *
 * The returned object is <i>not</i> retained and autoreleased for performance
 * reasons!
 *
 * \param index The number of the object to return
 * \return The specified object of the OFArray
 * @param index The number of the object to return
 * @return The specified object of the OFArray
 */
- (id)objectAtIndex: (size_t)index;
- (id)objectAtIndexedSubscript: (size_t)index;

/**
 * \brief Copies the objects at the specified range to the specified buffer.
/*!
 * @brief Copies the objects at the specified range to the specified buffer.
 *
 * \param buffer The buffer to copy the objects to
 * \param range The range to copy
 * @param buffer The buffer to copy the objects to
 * @param range The range to copy
 */
- (void)getObjects: (__unsafe_unretained id*)buffer
	   inRange: (of_range_t)range;

/**
 * \brief Returns the objects of the array as a C array.
/*!
 * @brief Returns the objects of the array as a C array.
 *
 * \return The objects of the array as a C array
 * @return The objects of the array as a C array
 */
- (id*)objects;

/**
 * \brief Returns the index of the first object that is equivalent to the
/*!
 * @brief Returns the index of the first object that is equivalent to the
 *	  specified object or OF_NOT_FOUND if it was not found.
 *
 * \param object The object whose index is returned
 * \return The index of the first object equivalent to the specified object
 * @param object The object whose index is returned
 * @return The index of the first object equivalent to the specified object
 *	   or OF_NOT_FOUND if it was not found
 */
- (size_t)indexOfObject: (id)object;

/**
 * \brief Returns the index of the first object that has the same address as the
/*!
 * @brief Returns the index of the first object that has the same address as the
 *	  specified object or OF_NOT_FOUND if it was not found.
 *
 * \param object The object whose index is returned
 * \return The index of the first object that has the same aaddress as
 * @param object The object whose index is returned
 * @return The index of the first object that has the same aaddress as
 *	   the specified object or OF_NOT_FOUND if it was not found
 */
- (size_t)indexOfObjectIdenticalTo: (id)object;

/**
 * \brief Checks whether the array contains an object with the specified
/*!
 * @brief Checks whether the array contains an object with the specified
 *	  address.
 *
 * \param object The object which is checked for being in the array
 * \return A boolean whether the array contains an object with the specified
 * @param object The object which is checked for being in the array
 * @return A boolean whether the array contains an object with the specified
 *	   address.
 */
- (BOOL)containsObjectIdenticalTo: (id)object;

/**
 * \brief Returns the first object of the array or nil.
/*!
 * @brief Returns the first object of the array or nil.
 *
 * The returned object is <i>not</i> retained and autoreleased for performance
 * reasons!
 *
 * \return The first object of the array or nil
 * @return The first object of the array or nil
 */
- (id)firstObject;

/**
 * \brief Returns the last object of the array or nil.
/*!
 * @brief Returns the last object of the array or nil.
 *
 * The returned object is <i>not</i> retained and autoreleased for performance
 * reasons!
 *
 * \return The last object of the array or nil
 * @return The last object of the array or nil
 */
- (id)lastObject;

/**
 * \brief Returns the objects in the specified range as a new OFArray.
/*!
 * @brief Returns the objects in the specified range as a new OFArray.
 *
 * \param range The range for the subarray
 * \return The subarray as a new autoreleased OFArray
 * @param range The range for the subarray
 * @return The subarray as a new autoreleased OFArray
 */
- (OFArray*)objectsInRange: (of_range_t)range;

/**
 * \brief Creates a string by joining all objects of the array.
/*!
 * @brief Creates a string by joining all objects of the array.
 *
 * \param separator The string with which the objects should be joined
 * \return A string containing all objects joined by the separator
 * @param separator The string with which the objects should be joined
 * @return A string containing all objects joined by the separator
 */
- (OFString*)componentsJoinedByString: (OFString*)separator;

/**
 * \brief Creates a string by calling the selector on all objects of the array
/*!
 * @brief Creates a string by calling the selector on all objects of the array
 *	  and joining the strings returned by calling the selector.
 *
 * \param separator The string with which the objects should be joined
 * \param selector The selector to perform on the objects
 * \return A string containing all objects joined by the separator
 * @param separator The string with which the objects should be joined
 * @param selector The selector to perform on the objects
 * @return A string containing all objects joined by the separator
 */
- (OFString*)componentsJoinedByString: (OFString*)separator
			usingSelector: (SEL)selector;

/**
 * \brief Performs the specified selector on all objects in the array.
/*!
 * @brief Performs the specified selector on all objects in the array.
 *
 * \param selector The selector to perform on all objects in the array
 * @param selector The selector to perform on all objects in the array
 */
- (void)makeObjectsPerformSelector: (SEL)selector;

/**
 * \brief Performs the specified selector on all objects in the array with the
/*!
 * @brief Performs the specified selector on all objects in the array with the
 *	  specified object.
 *
 * \param selector The selector to perform on all objects in the array
 * \param object The object to perform the selector with on all objects in the
 * @param selector The selector to perform on all objects in the array
 * @param object The object to perform the selector with on all objects in the
 *	      array
 */
- (void)makeObjectsPerformSelector: (SEL)selector
			withObject: (id)object;

/**
 * \brief Returns a sorted copy of the array.
/*!
 * @brief Returns a sorted copy of the array.
 *
 * \return A sorted copy of the array
 * @return A sorted copy of the array
 */
- (OFArray*)sortedArray;

/**
 * \brief Returns a copy of the array with the order reversed.
/*!
 * @brief Returns a copy of the array with the order reversed.
 *
 * \return A copy of the array with the order reversed
 * @return A copy of the array with the order reversed
 */
- (OFArray*)reversedArray;

/**
 * \brief Creates a new array with the specified object added.
/*!
 * @brief Creates a new array with the specified object added.
 *
 * \param object The object to add
 * \return A new array with the specified object added
 * @param object The object to add
 * @return A new array with the specified object added
 */
- (OFArray*)arrayByAddingObject: (id)object;

/**
 * \brief Creates a new array with the objects from the specified array added.
/*!
 * @brief Creates a new array with the objects from the specified array added.
 *
 * \param array The array with objects to add
 * \return A new array with the objects from the specified array added
 * @param array The array with objects to add
 * @return A new array with the objects from the specified array added
 */
- (OFArray*)arrayByAddingObjectsFromArray: (OFArray*)array;

/**
 * \brief Creates a new array with the specified object removed.
/*!
 * @brief Creates a new array with the specified object removed.
 *
 * \param object The object to remove
 * \return A new array with the specified object removed
 * @param object The object to remove
 * @return A new array with the specified object removed
 */
- (OFArray*)arrayByRemovingObject: (id)object;

#ifdef OF_HAVE_BLOCKS
/**
 * \brief Executes a block for each object.
/*!
 * @brief Executes a block for each object.
 *
 * \param block The block to execute for each object
 * @param block The block to execute for each object
 */
- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block;

/**
 * \brief Creates a new array, mapping each object using the specified block.
/*!
 * @brief Creates a new array, mapping each object using the specified block.
 *
 * \param block A block which maps an object for each object
 * \return A new, autoreleased OFArray
 * @param block A block which maps an object for each object
 * @return A new, autoreleased OFArray
 */
- (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block;

/**
 * \brief Creates a new array, only containing the objects for which the block
/*!
 * @brief Creates a new array, only containing the objects for which the block
 *	  returns YES.
 *
 * \param block A block which determines if the object should be in the new
 * @param block A block which determines if the object should be in the new
 *		array
 * \return A new, autoreleased OFArray
 * @return A new, autoreleased OFArray
 */
- (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block;

/**
 * \brief Folds the array to a single object using the specified block.
/*!
 * @brief Folds the array to a single object using the specified block.
 *
 * If the array is empty, it will return nil.
 *
 * If there is only one object in the array, that object will be returned and
 * the block will not be invoked.
 *
 * If there are at least two objects, the block is invoked for each object
 * except the first, where left is always to what the array has already been
 * folded and right what should be added to left.
 *
 * \param block A block which folds two objects into one, which is called for
 * @param block A block which folds two objects into one, which is called for
 *		all objects except the first
 * \return The array folded to a single object
 * @return The array folded to a single object
 */
- (id)foldUsingBlock: (of_array_fold_block_t)block;
#endif
@end

@interface OFArrayEnumerator: OFEnumerator
{