ObjFW
OFSet.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 #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 @interface OFSet OF_GENERIC(ObjectType): OFObject <OFCollection, OFCopying,
65 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
66 # define ObjectType id
67 #endif
68 
73 + (instancetype)set;
74 
81 + (instancetype)setWithSet: (OFSet OF_GENERIC(ObjectType) *)set;
82 
89 + (instancetype)setWithArray: (OFArray OF_GENERIC(ObjectType) *)array;
90 
97 + (instancetype)setWithObjects: (ObjectType)firstObject, ...;
98 
106 + (instancetype)setWithObjects: (ObjectType const _Nonnull *_Nonnull)objects
107  count: (size_t)count;
108 
115 - initWithSet: (OFSet OF_GENERIC(ObjectType) *)set;
116 
123 - initWithArray: (OFArray OF_GENERIC(ObjectType) *)array;
124 
131 - initWithObjects: (ObjectType)firstObject, ...;
132 
140 - initWithObjects: (ObjectType const _Nonnull *_Nonnull)objects
141  count: (size_t)count;
142 
151 - initWithObject: (ObjectType)firstObject
152  arguments: (va_list)arguments;
153 
159 - (bool)isSubsetOfSet: (OFSet OF_GENERIC(ObjectType) *)set;
160 
168 - (bool)intersectsSet: (OFSet OF_GENERIC(ObjectType) *)set;
169 
176 - (OFSet OF_GENERIC(ObjectType) *)setBySubtractingSet:
177  (OFSet OF_GENERIC(ObjectType) *)set;
178 
185 - (OFSet OF_GENERIC(ObjectType) *)setByIntersectingWithSet:
186  (OFSet OF_GENERIC(ObjectType) *)set;
187 
194 - (OFSet OF_GENERIC(ObjectType) *)setByAddingSet:
195  (OFSet OF_GENERIC(ObjectType) *)set;
196 
202 - (OFArray OF_GENERIC(ObjectType) *)allObjects;
203 
209 - (nullable ObjectType)anyObject;
210 
218 - (bool)containsObject: (ObjectType)object;
219 
233 - (nullable id)valueForKey: (OFString *)key;
234 
248 - (void)setValue: (id)value
249  forKey: (OFString *)key;
250 
256 - (OFEnumerator OF_GENERIC(ObjectType) *)objectEnumerator;
257 
258 #ifdef OF_HAVE_BLOCKS
259 
264 - (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block;
265 
273 - (OFSet OF_GENERIC(ObjectType) *)filteredSetUsingBlock:
274  (of_set_filter_block_t)block;
275 #endif
276 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
277 # undef ObjectType
278 #endif
279 @end
280 
281 OF_ASSUME_NONNULL_END
282 
283 #import "OFMutableSet.h"
An abstract class for an unordered set of unique objects.
Definition: OFSet.h:63
A protocol for the creation of mutable copies.
Definition: OFObject.h:935
OFArray * allObjects()
Returns an array of all objects in the set.
Definition: OFSet.m:433
A class for handling strings.
Definition: OFString.h:114
instancetype set()
Creates a new set.
Definition: OFSet.m:118
A class which provides methods to enumerate through collections.
Definition: OFEnumerator.h:44
OFEnumerator * objectEnumerator()
Returns an OFEnumerator to enumerate through all objects of the set.
Definition: OFSet.m:267
A protocol with methods common for all collections.
bool(^ of_set_filter_block_t)(id object)
A block for filtering an OFSet.
Definition: OFSet.h:52
A protocol for the creation of copies.
Definition: OFObject.h:914
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
void(^ of_set_enumeration_block_t)(id object, bool *stop)
A block for enumerating an OFSet.
Definition: OFSet.h:44
An abstract class for storing objects in an array.
Definition: OFArray.h:89
nullable ObjectType anyObject()
Returns an arbitrary object in the set.
Definition: OFSet.m:442
A protocol for serializing objects.
Definition: OFSerialization.h:30