ObjFW
OFMutableData.h
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 "OFData.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
21 @class OFString;
22 @class OFURL;
23 
29 @interface OFMutableData: OFData
30 {
31  size_t _capacity;
32 }
33 
39 + (instancetype)data;
40 
48 + (instancetype)dataWithItemSize: (size_t)itemSize;
49 
57 + (instancetype)dataWithCapacity: (size_t)capacity;
58 
67 + (instancetype)dataWithItemSize: (size_t)itemSize
68  capacity: (size_t)capacity;
69 
70 + (instancetype)dataWithItemsNoCopy: (const void *)items
71  count: (size_t)count
72  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
73 + (instancetype)dataWithItemsNoCopy: (const void *)items
74  itemSize: (size_t)itemSize
75  count: (size_t)count
76  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
77 
83 - init;
84 
92 - initWithItemSize: (size_t)itemSize;
93 
102 - initWithCapacity: (size_t)capacity;
103 
113 - initWithItemSize: (size_t)itemSize
114  capacity: (size_t)capacity;
115 
116 - initWithItemsNoCopy: (const void *)items
117  count: (size_t)count
118  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
119 - initWithItemsNoCopy: (const void *)items
120  itemSize: (size_t)itemSize
121  count: (size_t)count
122  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
123 
129 - (void)addItem: (const void *)item;
130 
137 - (void)insertItem: (const void *)item
138  atIndex: (size_t)index;
139 
146 - (void)addItems: (const void *)items
147  count: (size_t)count;
148 
156 - (void)insertItems: (const void *)items
157  atIndex: (size_t)index
158  count: (size_t)count;
159 
165 - (void)removeItemAtIndex: (size_t)index;
166 
172 - (void)removeItemsInRange: (of_range_t)range;
173 
177 - (void)removeLastItem;
178 
182 - (void)removeAllItems;
183 
187 - (void)makeImmutable;
188 @end
189 
190 @interface OFMutableData (MutableRetrieving)
201 - (void *)items OF_RETURNS_INNER_POINTER;
202 
212 - (void *)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER;
213 
222 - (nullable void *)firstItem OF_RETURNS_INNER_POINTER;
223 
232 - (nullable void *)lastItem OF_RETURNS_INNER_POINTER;
233 @end
234 
235 OF_ASSUME_NONNULL_END
void * items()
Returns all items of the OFMutableData as a C array.
nullable void * firstItem()
Returns the first item of the OFMutableData.
void removeLastItem()
Removes the last item.
Definition: OFMutableData.m:249
A class for handling strings.
Definition: OFString.h:114
size_t itemSize
Definition: OFData.h:46
void makeImmutable()
Converts the mutable URL to an immutable URL.
Definition: OFMutableData.m:281
A class for parsing URLs and accessing parts of it.
Definition: OFURL.h:29
instancetype data()
Creates a new OFMutableData with an item size of 1.
Definition: OFMutableData.m:32
id init()
Initializes an already allocated OFMutableData with an item size of 1.
Definition: OFMutableData.m:69
A range.
Definition: OFObject.h:66
nullable void * lastItem()
Returns the last item of the OFMutableData.
A class for storing arbitrary data in an array.
Definition: OFData.h:34
size_t count()
Returns the number of items in the OFData.
Definition: OFData.m:448
void removeAllItems()
Removes all items.
Definition: OFMutableData.m:265
A class for storing and manipulating arbitrary data in an array.
Definition: OFMutableData.h:29