ObjFW
Loading...
Searching...
No Matches
OFMutableArray.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2026 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#import "OFArray.h"
21
22OF_ASSUME_NONNULL_BEGIN
23
24@class OFIndexSet;
25
27
28#ifdef OF_HAVE_BLOCKS
36typedef id _Nonnull (^OFArrayReplaceBlock)(id object, size_t index);
37#endif
38
49@interface OFMutableArray OF_GENERIC(ObjectType): OFArray OF_GENERIC(ObjectType)
50#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
51# define ObjectType id
52#endif
60+ (instancetype)arrayWithCapacity: (size_t)capacity;
61
67- (instancetype)init OF_DESIGNATED_INITIALIZER;
68
76- (instancetype)initWithCapacity: (size_t)capacity OF_DESIGNATED_INITIALIZER;
77
83- (void)addObject: (ObjectType)object;
84
90- (void)addObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array;
91
98- (void)insertObject: (ObjectType)object atIndex: (size_t)index;
99
106- (void)insertObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array
107 atIndex: (size_t)index;
108
116- (void)insertObjects: (OFArray OF_GENERIC(ObjectType) *)array
117 atIndexes: (OFIndexSet *)indexes;
118
126- (void)replaceObject: (ObjectType)oldObject withObject: (ObjectType)newObject;
127
134- (void)replaceObjectAtIndex: (size_t)index withObject: (ObjectType)object;
135
143- (void)replaceObjectsInRange: (OFRange)range
144 withObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)objects;
145
153- (void)replaceObjectsAtIndexes: (OFIndexSet *)indexes
154 withObjects: (OFArray OF_GENERIC(ObjectType) *)objects;
155
166- (void)setObject: (ObjectType)object atIndexedSubscript: (size_t)index;
167
175- (void)replaceObjectIdenticalTo: (ObjectType)oldObject
176 withObject: (ObjectType)newObject;
177
183- (void)removeObject: (ObjectType)object;
184
191- (void)removeObjectIdenticalTo: (ObjectType)object;
192
198- (void)removeObjectAtIndex: (size_t)index;
199
205- (void)removeObjectsInRange: (OFRange)range;
206
212- (void)removeObjectsAtIndexes: (OFIndexSet *)indexes;
213
217- (void)removeLastObject;
218
222- (void)removeAllObjects;
223
224#ifdef OF_HAVE_BLOCKS
230- (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block;
231#endif
232
239- (void)exchangeObjectAtIndex: (size_t)index1 withObjectAtIndex: (size_t)index2;
240
244- (void)sort;
245
253- (void)sortUsingSelector: (SEL)selector options: (OFArraySortOptions)options;
254
262- (void)sortUsingFunction: (OFCompareFunction)compare
263 context: (nullable void *)context
264 options: (OFArraySortOptions)options;
265
266#ifdef OF_HAVE_BLOCKS
273- (void)sortUsingComparator: (OFComparator)comparator
274 options: (OFArraySortOptions)options;
275#endif
276
280- (void)reverse;
281
285- (void)makeImmutable;
286#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
287# undef ObjectType
288#endif
289@end
290
291OF_ASSUME_NONNULL_END
OFArraySortOptions
Options for sorting an array.
Definition OFArray.h:57
id(^ OFArrayReplaceBlock)(id object, size_t index)
A block for replacing values in an OFMutableArray.
Definition OFMutableArray.h:36
OFComparisonResult(^ OFComparator)(id left, id right)
A comparator to compare two objects.
Definition OFObject.h:92
OFComparisonResult(* OFCompareFunction)(id left, id right, void *context)
A function to compare two objects.
Definition OFObject.h:81
An abstract class for storing objects in an array.
Definition OFArray.h:110
A class storing a set of indexes as sorted ranges.
Definition OFIndexSet.h:31
An abstract class for storing, adding and removing objects in an array.
Definition OFMutableArray.h:50
void removeLastObject()
Removes the last object.
Definition OFMutableArray.m:380
void makeImmutable()
Converts the mutable array to an immutable array.
Definition OFMutableArray.m:494
void removeAllObjects()
Removes all objects.
Definition OFMutableArray.m:390
instancetype init()
Initializes an OFMutableArray with no objects.
Definition OFMutableArray.m:168
void sort()
Sorts the array in ascending order.
Definition OFMutableArray.m:422
void reverse()
Reverts the order of the objects in the array.
Definition OFMutableArray.m:483
A range.
Definition OFObject.h:116