ObjFW
OFSet.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2024 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 
28 OF_ASSUME_NONNULL_BEGIN
29 
32 @class OFArray OF_GENERIC(ObjectType);
33 
34 #ifdef OF_HAVE_BLOCKS
35 
42 typedef void (^OFSetEnumerationBlock)(id object, bool *stop);
43 
50 typedef bool (^OFSetFilterBlock)(id object);
51 #endif
52 
64 @interface OFSet OF_GENERIC(ObjectType): OFObject <OFCollection, OFCopying,
66 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
67 # define ObjectType id
68 #endif
69 
72 @property (readonly, nonatomic) OFArray OF_GENERIC(ObjectType) *allObjects;
73 
77 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType anyObject;
78 
84 + (instancetype)set;
85 
92 + (instancetype)setWithSet: (OFSet OF_GENERIC(ObjectType) *)set;
93 
100 + (instancetype)setWithArray: (OFArray OF_GENERIC(ObjectType) *)array;
101 
108 + (instancetype)setWithObjects: (ObjectType)firstObject, ...;
109 
117 + (instancetype)setWithObjects: (ObjectType const _Nonnull *_Nonnull)objects
118  count: (size_t)count;
119 
125 - (instancetype)init OF_DESIGNATED_INITIALIZER;
126 
133 - (instancetype)initWithSet: (OFSet OF_GENERIC(ObjectType) *)set;
134 
141 - (instancetype)initWithArray: (OFArray OF_GENERIC(ObjectType) *)array;
142 
149 - (instancetype)initWithObjects: (ObjectType)firstObject, ... OF_SENTINEL;
150 
159 - (instancetype)initWithObject: (ObjectType)firstObject
160  arguments: (va_list)arguments;
161 
169 - (instancetype)initWithObjects: (ObjectType const _Nonnull *_Nonnull)objects
170  count: (size_t)count OF_DESIGNATED_INITIALIZER;
171 
177 - (OFEnumerator OF_GENERIC(ObjectType) *)objectEnumerator;
178 
184 - (bool)isSubsetOfSet: (OFSet OF_GENERIC(ObjectType) *)set;
185 
193 - (bool)intersectsSet: (OFSet OF_GENERIC(ObjectType) *)set;
194 
201 - (OFSet OF_GENERIC(ObjectType) *)setByAddingObjectsFromSet:
202  (OFSet OF_GENERIC(ObjectType) *)set;
203 
211 - (bool)containsObject: (ObjectType)object;
212 
225 - (nullable id)valueForKey: (OFString *)key;
226 
237 - (void)setValue: (nullable id)value forKey: (OFString *)key;
238 
239 #ifdef OF_HAVE_BLOCKS
240 
245 - (void)enumerateObjectsUsingBlock: (OFSetEnumerationBlock)block;
246 
254 - (OFSet OF_GENERIC(ObjectType) *)
255  filteredSetUsingBlock: (OFSetFilterBlock)block;
256 #endif
257 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
258 # undef ObjectType
259 #endif
260 @end
261 
262 OF_ASSUME_NONNULL_END
263 
264 #import "OFMutableSet.h"
OFEnumerator * objectEnumerator()
Returns an OFEnumerator to enumerate through all objects of the set.
Definition: OFSet.m:308
An abstract class for storing objects in an array.
Definition: OFArray.h:103
The root class for all other classes inside ObjFW.
Definition: OFObject.h:686
A class for handling strings.
Definition: OFString.h:134
void(^ OFSetEnumerationBlock)(id object, bool *stop)
A block for enumerating an OFSet.
Definition: OFSet.h:42
OFArray * allObjects
An array of all objects in the set.
Definition: OFSet.h:72
A protocol with methods common for all collections.
An abstract class for an unordered set of unique objects.
Definition: OFSet.h:64
instancetype init()
Initializes an already allocated set to be empty.
Definition: OFSet.m:136
instancetype set()
Creates a new set.
Definition: OFSet.m:102
A protocol for the creation of mutable copies.
Definition: OFObject.h:1367
A protocol for the creation of copies.
Definition: OFObject.h:1346
bool(^ OFSetFilterBlock)(id object)
A block for filtering an OFSet.
Definition: OFSet.h:50
ObjectType anyObject
An arbitrary object in the set.
Definition: OFSet.h:77
A class which provides methods to enumerate through collections.
Definition: OFEnumerator.h:99