ObjFW
OFMutableArray.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
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 #import "OFArray.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
23 #ifdef OF_HAVE_BLOCKS
24 
31 typedef id OF_NONNULL (^of_array_replace_block_t)(id object, size_t index);
32 #endif
33 
40 #ifdef OF_HAVE_GENERICS
41 @interface OFMutableArray <ObjectType>: OFArray <ObjectType>
42 #else
43 # ifndef DOXYGEN
44 # define ObjectType id
45 # endif
47 #endif
48 
55 + (instancetype)arrayWithCapacity: (size_t)capacity;
56 
64 - initWithCapacity: (size_t)capacity;
65 
71 - (void)addObject: (ObjectType)object;
72 
78 - (void)addObjectsFromArray: (OFArray OF_GENERIC(ObjectType)*)array;
79 
86 - (void)insertObject: (ObjectType)object
87  atIndex: (size_t)index;
88 
95 - (void)insertObjectsFromArray: (OFArray OF_GENERIC(ObjectType)*)array
96  atIndex: (size_t)index;
97 
105 - (void)replaceObject: (ObjectType)oldObject
106  withObject: (ObjectType)newObject;
107 
114 - (void)replaceObjectAtIndex: (size_t)index
115  withObject: (ObjectType)object;
116 - (void)setObject: (ObjectType)object
117  atIndexedSubscript: (size_t)index;
118 
126 - (void)replaceObjectIdenticalTo: (ObjectType)oldObject
127  withObject: (ObjectType)newObject;
128 
134 - (void)removeObject: (ObjectType)object;
135 
142 - (void)removeObjectIdenticalTo: (ObjectType)object;
143 
149 - (void)removeObjectAtIndex: (size_t)index;
150 
156 - (void)removeObjectsInRange: (of_range_t)range;
157 
161 - (void)removeLastObject;
162 
166 - (void)removeAllObjects;
167 
168 #ifdef OF_HAVE_BLOCKS
169 
174 - (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block;
175 #endif
176 
183 - (void)exchangeObjectAtIndex: (size_t)index1
184  withObjectAtIndex: (size_t)index2;
185 
189 - (void)sort;
190 
200 - (void)sortWithOptions: (int)options;
201 
205 - (void)reverse;
206 
210 - (void)makeImmutable;
211 @end
212 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
213 # undef ObjectType
214 #endif
215 
216 OF_ASSUME_NONNULL_END
instancetype array()
Creates a new OFArray.
Definition: OFArray.m:133
An abstract class for storing objects in an array.
Definition: OFArray.h:95
void makeImmutable()
Converts the mutable array to an immutable array.
Definition: OFMutableArray.m:414
void removeAllObjects()
Removes all objects.
Definition: OFMutableArray.m:351
void removeLastObject()
Removes the last object.
Definition: OFMutableArray.m:341
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:46
void sort()
Sorts the array.
Definition: OFMutableArray.m:387
void reverse()
Reverts the order of the objects in the array.
Definition: OFMutableArray.m:402
id OF_NONNULL(^ of_array_replace_block_t)(id object, size_t index)
A block for replacing values in an OFMutableArray.
Definition: OFMutableArray.h:31