ObjFW
OFMutableArray.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
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 _Nonnull (^of_array_replace_block_t)(id object, size_t index);
32 #endif
33 
40 @interface OFMutableArray OF_GENERIC(ObjectType): OFArray OF_GENERIC(ObjectType)
41 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
42 # define ObjectType id
43 #endif
44 
51 + (instancetype)arrayWithCapacity: (size_t)capacity;
52 
60 - initWithCapacity: (size_t)capacity;
61 
67 - (void)addObject: (ObjectType)object;
68 
74 - (void)addObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array;
75 
82 - (void)insertObject: (ObjectType)object
83  atIndex: (size_t)index;
84 
91 - (void)insertObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array
92  atIndex: (size_t)index;
93 
101 - (void)replaceObject: (ObjectType)oldObject
102  withObject: (ObjectType)newObject;
103 
110 - (void)replaceObjectAtIndex: (size_t)index
111  withObject: (ObjectType)object;
112 - (void)setObject: (ObjectType)object
113  atIndexedSubscript: (size_t)index;
114 
122 - (void)replaceObjectIdenticalTo: (ObjectType)oldObject
123  withObject: (ObjectType)newObject;
124 
130 - (void)removeObject: (ObjectType)object;
131 
138 - (void)removeObjectIdenticalTo: (ObjectType)object;
139 
145 - (void)removeObjectAtIndex: (size_t)index;
146 
152 - (void)removeObjectsInRange: (of_range_t)range;
153 
157 - (void)removeLastObject;
158 
162 - (void)removeAllObjects;
163 
164 #ifdef OF_HAVE_BLOCKS
165 
170 - (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block;
171 #endif
172 
179 - (void)exchangeObjectAtIndex: (size_t)index1
180  withObjectAtIndex: (size_t)index2;
181 
185 - (void)sort;
186 
196 - (void)sortWithOptions: (int)options;
197 
201 - (void)reverse;
202 
206 - (void)makeImmutable;
207 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
208 # undef ObjectType
209 #endif
210 @end
211 
212 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:31
void sort()
Sorts the array.
Definition: OFMutableArray.m:373
void removeLastObject()
Removes the last object.
Definition: OFMutableArray.m:327
void reverse()
Reverts the order of the objects in the array.
Definition: OFMutableArray.m:388
A range.
Definition: OFObject.h:66
An abstract class for storing objects in an array.
Definition: OFArray.h:89
void makeImmutable()
Converts the mutable array to an immutable array.
Definition: OFMutableArray.m:400
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:40
void removeAllObjects()
Removes all objects.
Definition: OFMutableArray.m:337