ObjFW
OFMutableData.h
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 "OFData.h"
21 
22 OF_ASSUME_NONNULL_BEGIN
23 
24 @class OFIndexSet;
25 
31 @interface OFMutableData: OFData
40 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *mutableItems
41  OF_RETURNS_INNER_POINTER;
42 
46 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *mutableFirstItem
47  OF_RETURNS_INNER_POINTER;
48 
52 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *mutableLastItem
53  OF_RETURNS_INNER_POINTER;
54 
62 + (instancetype)dataWithCapacity: (size_t)capacity;
63 
72 + (instancetype)dataWithItemSize: (size_t)itemSize capacity: (size_t)capacity;
73 
82 - (instancetype)initWithCapacity: (size_t)capacity;
83 
93 - (instancetype)initWithItemSize: (size_t)itemSize capacity: (size_t)capacity;
94 
104 - (void *)mutableItemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER;
105 
111 - (void)addItem: (const void *)item;
112 
119 - (void)insertItem: (const void *)item atIndex: (size_t)index;
120 
127 - (void)addItems: (const void *)items count: (size_t)count;
128 
136 - (void)insertItems: (const void *)items
137  atIndex: (size_t)index
138  count: (size_t)count;
139 
147 - (void)insertItems: (const void *)items atIndexes: (OFIndexSet *)indexes;
148 
155 - (void)increaseCountBy: (size_t)count;
156 
162 - (void)removeItemAtIndex: (size_t)index;
163 
169 - (void)removeItemsInRange: (OFRange)range;
170 
176 - (void)removeItemsAtIndexes: (OFIndexSet *)indexes;
177 
181 - (void)removeLastItem;
182 
186 - (void)removeAllItems;
187 
191 - (void)makeImmutable;
192 @end
193 
194 OF_ASSUME_NONNULL_END
A class for storing arbitrary data in an array.
Definition: OFData.h:46
A class storing a set of indexes as sorted ranges.
Definition: OFIndexSet.h:31
A class for storing and manipulating arbitrary data in an array.
Definition: OFMutableData.h:32
void removeAllItems()
Removes all items.
Definition: OFMutableData.m:319
void * mutableItems
All items of the OFMutableData as a C array.
Definition: OFMutableData.h:41
void makeImmutable()
Converts the mutable data to an immutable data.
Definition: OFMutableData.m:331
void removeLastItem()
Removes the last item.
Definition: OFMutableData.m:309
void * mutableFirstItem
The first item of the OFMutableData or NULL.
Definition: OFMutableData.h:47
void * mutableLastItem
The last item of the OFMutableData or NULL.
Definition: OFMutableData.h:53
A range.
Definition: OFObject.h:116