ObjFW
OFDataArray.h
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 "OFObject.h"
18 #import "OFSerialization.h"
19 #import "OFMessagePackRepresentation.h"
20 
21 OF_ASSUME_NONNULL_BEGIN
22 
23 @class OFString;
24 @class OFURL;
25 
39 {
40  uint8_t *_items;
41  size_t _count, _itemSize, _capacity;
42 }
43 
44 #ifdef OF_HAVE_PROPERTIES
45 @property (readonly) void *items;
46 @property (readonly) size_t count;
47 @property (readonly) size_t itemSize;
48 #endif
49 
55 + (instancetype)dataArray;
56 
64 + (instancetype)dataArrayWithItemSize: (size_t)itemSize;
65 
73 + (instancetype)dataArrayWithCapacity: (size_t)capacity;
74 
83 + (instancetype)dataArrayWithItemSize: (size_t)itemSize
84  capacity: (size_t)capacity;
85 
86 #ifdef OF_HAVE_FILES
87 
94 + (instancetype)dataArrayWithContentsOfFile: (OFString*)path;
95 #endif
96 
97 #if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
98 
105 + (instancetype)dataArrayWithContentsOfURL: (OFURL*)URL;
106 #endif
107 
115 + (instancetype)dataArrayWithStringRepresentation: (OFString*)string;
116 
124 + (instancetype)dataArrayWithBase64EncodedString: (OFString*)string;
125 
133 - initWithItemSize: (size_t)itemSize;
134 
142 - initWithCapacity: (size_t)capacity;
143 
153 - initWithItemSize: (size_t)itemSize
154  capacity: (size_t)capacity;
155 
156 #ifdef OF_HAVE_FILES
157 
164 - initWithContentsOfFile: (OFString*)path;
165 #endif
166 
167 #if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
168 
175 - initWithContentsOfURL: (OFURL*)URL;
176 #endif
177 
185 - initWithStringRepresentation: (OFString*)string;
186 
194 - initWithBase64EncodedString: (OFString*)string;
195 
201 - (size_t)count;
202 
208 - (size_t)itemSize;
209 
220 - (void*)items OF_RETURNS_INNER_POINTER;
221 
228 - (void*)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER;
229 
235 - (nullable void*)firstItem OF_RETURNS_INNER_POINTER;
236 
242 - (nullable void*)lastItem OF_RETURNS_INNER_POINTER;
243 
249 - (void)addItem: (const void*)item;
250 
257 - (void)insertItem: (const void*)item
258  atIndex: (size_t)index;
259 
266 - (void)addItems: (const void*)items
267  count: (size_t)count;
268 
276 - (void)insertItems: (const void*)items
277  atIndex: (size_t)index
278  count: (size_t)count;
279 
285 - (void)removeItemAtIndex: (size_t)index;
286 
292 - (void)removeItemsInRange: (of_range_t)range;
293 
297 - (void)removeLastItem;
298 
302 - (void)removeAllItems;
303 
312 - (OFString*)stringRepresentation;
313 
319 - (OFString*)stringByBase64Encoding;
320 
321 #ifdef OF_HAVE_FILES
322 
327 - (void)writeToFile: (OFString*)path;
328 #endif
329 @end
330 
331 OF_ASSUME_NONNULL_END
332 
333 #import "OFDataArray+Hashing.h"
334 #import "OFDataArray+MessagePackValue.h"
A class for handling strings.
Definition: OFString.h:91
A class for parsing URLs and accessing parts of it.
Definition: OFURL.h:29
A protocol implemented by classes that support encoding to a MessagePack representation.
Definition: OFMessagePackRepresentation.h:30
A protocol for the creation of copies.
Definition: OFObject.h:896
A class for storing arbitrary data in an array.
Definition: OFDataArray.h:37
A protocol for comparing objects.
Definition: OFObject.h:933
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
A range.
Definition: OFObject.h:65
A protocol for serializing objects.
Definition: OFSerialization.h:30