ObjFW
OFSet.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 #ifndef __STDC_LIMIT_MACROS
18 # define __STDC_LIMIT_MACROS
19 #endif
20 #ifndef __STDC_CONSTANT_MACROS
21 # define __STDC_CONSTANT_MACROS
22 #endif
23 
24 #include <stdarg.h>
25 
26 #import "OFObject.h"
27 #import "OFCollection.h"
28 #import "OFSerialization.h"
29 
30 OF_ASSUME_NONNULL_BEGIN
31 
34 @class OFArray OF_GENERIC(ObjectType);
35 
36 #ifdef OF_HAVE_BLOCKS
37 
44 typedef void (^of_set_enumeration_block_t)(id object, bool *stop);
45 
52 typedef bool (^of_set_filter_block_t)(id object);
53 #endif
54 
63 #ifdef OF_HAVE_GENERICS
64 @interface OFSet <ObjectType>:
65 #else
66 # ifndef DOXYGEN
67 # define ObjectType id
68 # endif
69 @interface OFSet:
70 #endif
77 + (instancetype)set;
78 
85 + (instancetype)setWithSet: (OFSet OF_GENERIC(ObjectType)*)set;
86 
93 + (instancetype)setWithArray: (OFArray OF_GENERIC(ObjectType)*)array;
94 
101 + (instancetype)setWithObjects: (ObjectType)firstObject, ...;
102 
110 + (instancetype)setWithObjects: (ObjectType const OF_NONNULL *OF_NONNULL)objects
111  count: (size_t)count;
112 
119 - initWithSet: (OFSet OF_GENERIC(ObjectType)*)set;
120 
127 - initWithArray: (OFArray OF_GENERIC(ObjectType)*)array;
128 
135 - initWithObjects: (ObjectType)firstObject, ...;
136 
144 - initWithObjects: (ObjectType const OF_NONNULL *OF_NONNULL)objects
145  count: (size_t)count;
146 
155 - initWithObject: (ObjectType)firstObject
156  arguments: (va_list)arguments;
157 
163 - (bool)isSubsetOfSet: (OFSet OF_GENERIC(ObjectType)*)set;
164 
172 - (bool)intersectsSet: (OFSet OF_GENERIC(ObjectType)*)set;
173 
180 - (OFSet OF_GENERIC(ObjectType)*)setBySubtractingSet:
181  (OFSet OF_GENERIC(ObjectType)*)set;
182 
189 - (OFSet OF_GENERIC(ObjectType)*)setByIntersectingWithSet:
190  (OFSet OF_GENERIC(ObjectType)*)set;
191 
198 - (OFSet OF_GENERIC(ObjectType)*)setByAddingSet:
199  (OFSet OF_GENERIC(ObjectType)*)set;
200 
206 - (OFArray OF_GENERIC(ObjectType)*)allObjects;
207 
213 - (ObjectType)anyObject;
214 
222 - (bool)containsObject: (nullable ObjectType)object;
223 
229 - (OFEnumerator OF_GENERIC(ObjectType)*)objectEnumerator;
230 
231 #ifdef OF_HAVE_BLOCKS
232 
237 - (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block;
238 
246 - (OFSet OF_GENERIC(ObjectType)*)filteredSetUsingBlock:
247  (of_set_filter_block_t)block;
248 #endif
249 @end
250 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
251 # undef ObjectType
252 #endif
253 
254 OF_ASSUME_NONNULL_END
255 
256 #import "OFMutableSet.h"
void(^ of_set_enumeration_block_t)(id object, bool *stop)
A block for enumerating an OFSet.
Definition: OFSet.h:44
A protocol for serializing objects.
Definition: OFSerialization.h:30
bool(^ of_set_filter_block_t)(id object)
A block for filtering an OFSet.
Definition: OFSet.h:52
OFEnumerator OF_GENERIC(ObjectType objectEnumerator()
Returns an OFEnumerator to enumerate through all objects of the set.
Definition: OFSet.m:221
An abstract class for storing objects in an array.
Definition: OFArray.h:95
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
size_t count()
Returns the number of objects in the collection.
A protocol with methods common for all collections.
Definition: OFCollection.h:26
An abstract class for an unordered set of unique objects.
Definition: OFSet.h:69
instancetype set()
Creates a new set.
Definition: OFSet.m:120
A protocol for the creation of mutable copies.
Definition: OFObject.h:917
A protocol for the creation of copies.
Definition: OFObject.h:896
ObjectType anyObject()
Returns an arbitrary object in the set.
Definition: OFSet.m:425
OFArray OF_GENERIC(ObjectType allObjects()
Returns an array of all objects in the set.
Definition: OFSet.m:416