ObjFW
OFSet.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #ifndef __STDC_LIMIT_MACROS
17 # define __STDC_LIMIT_MACROS
18 #endif
19 #ifndef __STDC_CONSTANT_MACROS
20 # define __STDC_CONSTANT_MACROS
21 #endif
22 
23 #include <stdarg.h>
24 
25 #import "OFObject.h"
26 #import "OFCollection.h"
27 #import "OFSerialization.h"
28 
29 OF_ASSUME_NONNULL_BEGIN
30 
33 @class OFArray OF_GENERIC(ObjectType);
34 
35 #ifdef OF_HAVE_BLOCKS
43 typedef void (^of_set_enumeration_block_t)(id object, bool *stop);
44 
51 typedef bool (^of_set_filter_block_t)(id object);
52 #endif
53 
65 @interface OFSet OF_GENERIC(ObjectType): OFObject <OFCollection, OFCopying,
67 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
68 # define ObjectType id
69 #endif
73 @property (readonly, nonatomic) OFArray OF_GENERIC(ObjectType) *allObjects;
74 
78 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType anyObject;
79 
85 + (instancetype)set;
86 
93 + (instancetype)setWithSet: (OFSet OF_GENERIC(ObjectType) *)set;
94 
101 + (instancetype)setWithArray: (OFArray OF_GENERIC(ObjectType) *)array;
102 
109 + (instancetype)setWithObjects: (ObjectType)firstObject, ...;
110 
118 + (instancetype)setWithObjects: (ObjectType const _Nonnull *_Nonnull)objects
119  count: (size_t)count;
120 
127 - (instancetype)initWithSet: (OFSet OF_GENERIC(ObjectType) *)set;
128 
135 - (instancetype)initWithArray: (OFArray OF_GENERIC(ObjectType) *)array;
136 
143 - (instancetype)initWithObjects: (ObjectType)firstObject, ... OF_SENTINEL;
144 
152 - (instancetype)initWithObjects: (ObjectType const _Nonnull *_Nonnull)objects
153  count: (size_t)count;
154 
163 - (instancetype)initWithObject: (ObjectType)firstObject
164  arguments: (va_list)arguments;
165 
171 - (bool)isSubsetOfSet: (OFSet OF_GENERIC(ObjectType) *)set;
172 
180 - (bool)intersectsSet: (OFSet OF_GENERIC(ObjectType) *)set;
181 
188 - (OFSet OF_GENERIC(ObjectType) *)setBySubtractingSet:
189  (OFSet OF_GENERIC(ObjectType) *)set;
190 
197 - (OFSet OF_GENERIC(ObjectType) *)setByIntersectingWithSet:
198  (OFSet OF_GENERIC(ObjectType) *)set;
199 
206 - (OFSet OF_GENERIC(ObjectType) *)setByAddingSet:
207  (OFSet OF_GENERIC(ObjectType) *)set;
208 
216 - (bool)containsObject: (ObjectType)object;
217 
230 - (nullable id)valueForKey: (OFString *)key;
231 
242 - (void)setValue: (nullable id)value forKey: (OFString *)key;
243 
244 #ifdef OF_HAVE_BLOCKS
250 - (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block;
251 
259 - (OFSet OF_GENERIC(ObjectType) *)filteredSetUsingBlock:
260  (of_set_filter_block_t)block;
261 #endif
262 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
263 # undef ObjectType
264 #endif
265 @end
266 
267 OF_ASSUME_NONNULL_END
268 
269 #import "OFMutableSet.h"
bool(^ of_set_filter_block_t)(id object)
A block for filtering an OFSet.
Definition: OFSet.h:51
void(^ of_set_enumeration_block_t)(id object, bool *stop)
A block for enumerating an OFSet.
Definition: OFSet.h:43
struct objc_object * id
A pointer to any object.
Definition: ObjFWRT.h:90
An abstract class for storing objects in an array.
Definition: OFArray.h:92
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
An abstract class for an unordered set of unique objects.
Definition: OFSet.h:66
instancetype set()
Creates a new set.
Definition: OFSet.m:115
OFArray * allObjects
An array of all objects in the set.
Definition: OFSet.h:73
ObjectType anyObject
An arbitrary object in the set.
Definition: OFSet.h:78
A class for handling strings.
Definition: OFString.h:132
A protocol with methods common for all collections.
Definition: OFCollection.h:25
A protocol for the creation of copies.
Definition: OFObject.h:1187
A protocol for the creation of mutable copies.
Definition: OFObject.h:1208
A protocol for serializing objects.
Definition: OFSerialization.h:29