ObjFW
OFMutableArray.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2021 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 
18 OF_ASSUME_NONNULL_BEGIN
19 
22 #ifdef OF_HAVE_BLOCKS
30 typedef id _Nonnull (^of_array_replace_block_t)(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 
63 - (instancetype)initWithCapacity: (size_t)capacity;
64 
70 - (void)addObject: (ObjectType)object;
71 
77 - (void)addObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array;
78 
85 - (void)insertObject: (ObjectType)object atIndex: (size_t)index;
86 
93 - (void)insertObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array
94  atIndex: (size_t)index;
95 
103 - (void)replaceObject: (ObjectType)oldObject withObject: (ObjectType)newObject;
104 
111 - (void)replaceObjectAtIndex: (size_t)index withObject: (ObjectType)object;
112 
123 - (void)setObject: (ObjectType)object atIndexedSubscript: (size_t)index;
124 
132 - (void)replaceObjectIdenticalTo: (ObjectType)oldObject
133  withObject: (ObjectType)newObject;
134 
140 - (void)removeObject: (ObjectType)object;
141 
148 - (void)removeObjectIdenticalTo: (ObjectType)object;
149 
155 - (void)removeObjectAtIndex: (size_t)index;
156 
162 - (void)removeObjectsInRange: (of_range_t)range;
163 
167 - (void)removeLastObject;
168 
172 - (void)removeAllObjects;
173 
174 #ifdef OF_HAVE_BLOCKS
180 - (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block;
181 #endif
182 
189 - (void)exchangeObjectAtIndex: (size_t)index1 withObjectAtIndex: (size_t)index2;
190 
194 - (void)sort;
195 
207 - (void)sortUsingSelector: (SEL)selector options: (int)options;
208 
209 #ifdef OF_HAVE_BLOCKS
220 - (void)sortUsingComparator: (of_comparator_t)comparator options: (int)options;
221 #endif
222 
226 - (void)reverse;
227 
231 - (void)makeImmutable;
232 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
233 # undef ObjectType
234 #endif
235 @end
236 
237 OF_ASSUME_NONNULL_END
id _Nonnull(^ of_array_replace_block_t)(id object, size_t index)
A block for replacing values in an OFMutableArray.
Definition: OFMutableArray.h:30
of_comparison_result_t(^ of_comparator_t)(id _Nonnull left, id _Nonnull right)
A comparator to compare two objects.
Definition: OFObject.h:74
An abstract class for storing objects in an array.
Definition: OFArray.h:92
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:371
void makeImmutable()
Converts the mutable array to an immutable array.
Definition: OFMutableArray.m:452
void removeAllObjects()
Removes all objects.
Definition: OFMutableArray.m:381
void sort()
Sorts the array in ascending order.
Definition: OFMutableArray.m:413
void reverse()
Reverts the order of the objects in the array.
Definition: OFMutableArray.m:441
A range.
Definition: OFObject.h:93