ObjFW
Loading...
Searching...
No Matches
OFMutableArray.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This file is part of ObjFW. It may be distributed under the terms of the
7 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8 * the packaging of this file.
9 *
10 * Alternatively, it may be distributed under the terms of the GNU General
11 * Public License, either version 2 or 3, which can be found in the file
12 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13 * file.
14 */
15
16#import "OFArray.h"
17
18OF_ASSUME_NONNULL_BEGIN
19
22#ifdef OF_HAVE_BLOCKS
30typedef id _Nonnull (^OFArrayReplaceBlock)(id object, size_t index);
31#endif
32
43@interface OFMutableArray OF_GENERIC(ObjectType): OFArray OF_GENERIC(ObjectType)
44#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
45# define ObjectType id
46#endif
54+ (instancetype)arrayWithCapacity: (size_t)capacity;
55
61- (instancetype)init OF_DESIGNATED_INITIALIZER;
62
70- (instancetype)initWithCapacity: (size_t)capacity OF_DESIGNATED_INITIALIZER;
71
77- (void)addObject: (ObjectType)object;
78
84- (void)addObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array;
85
92- (void)insertObject: (ObjectType)object atIndex: (size_t)index;
93
100- (void)insertObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array
101 atIndex: (size_t)index;
102
110- (void)replaceObject: (ObjectType)oldObject withObject: (ObjectType)newObject;
111
118- (void)replaceObjectAtIndex: (size_t)index withObject: (ObjectType)object;
119
130- (void)setObject: (ObjectType)object atIndexedSubscript: (size_t)index;
131
139- (void)replaceObjectIdenticalTo: (ObjectType)oldObject
140 withObject: (ObjectType)newObject;
141
147- (void)removeObject: (ObjectType)object;
148
155- (void)removeObjectIdenticalTo: (ObjectType)object;
156
162- (void)removeObjectAtIndex: (size_t)index;
163
169- (void)removeObjectsInRange: (OFRange)range;
170
174- (void)removeLastObject;
175
179- (void)removeAllObjects;
180
181#ifdef OF_HAVE_BLOCKS
187- (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block;
188#endif
189
196- (void)exchangeObjectAtIndex: (size_t)index1 withObjectAtIndex: (size_t)index2;
197
201- (void)sort;
202
210- (void)sortUsingSelector: (SEL)selector options: (OFArraySortOptions)options;
211
219- (void)sortUsingFunction: (OFCompareFunction)compare
220 context: (nullable void *)context
221 options: (OFArraySortOptions)options;
222
223#ifdef OF_HAVE_BLOCKS
230- (void)sortUsingComparator: (OFComparator)comparator
231 options: (OFArraySortOptions)options;
232#endif
233
237- (void)reverse;
238
242- (void)makeImmutable;
243#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
244# undef ObjectType
245#endif
246@end
247
248OF_ASSUME_NONNULL_END
OFArraySortOptions
Options for sorting an array.
Definition OFArray.h:52
id(^ OFArrayReplaceBlock)(id object, size_t index)
A block for replacing values in an OFMutableArray.
Definition OFMutableArray.h:30
OFComparisonResult(^ OFComparator)(id left, id right)
A comparator to compare two objects.
Definition OFObject.h:82
OFComparisonResult(* OFCompareFunction)(id left, id right, void *context)
A function to compare two objects.
Definition OFObject.h:71
An abstract class for storing objects in an array.
Definition OFArray.h:105
An abstract class for storing, adding and removing objects in an array.
Definition OFMutableArray.h:44
void removeLastObject()
Removes the last object.
Definition OFMutableArray.m:306
void makeImmutable()
Converts the mutable array to an immutable array.
Definition OFMutableArray.m:420
void removeAllObjects()
Removes all objects.
Definition OFMutableArray.m:316
instancetype init()
Initializes an OFMutableArray with no objects.
Definition OFMutableArray.m:160
void sort()
Sorts the array in ascending order.
Definition OFMutableArray.m:348
void reverse()
Reverts the order of the objects in the array.
Definition OFMutableArray.m:409
A range.
Definition OFObject.h:106