ObjFW  Diff

Differences From Artifact [de20ae16c5]:

To Artifact [357ef085a2]:


26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51







52
53




54
55
56
57
58
59
60
61
62
63
64
65
66
67


68
69
70
71
72
73
74
75
76
77


78
79
80
81
82
83
84
85
86
87



88
89
90
91
92
93
94
95
96
97
98


99
100
101
102
103
104
105
106
107


108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125
126
127


128
129
130
131
132
133
134
135
136
137
138


139
140
141
142
143
144
145
146
147
148
149
150


151
152
153
154
155
156
157
158
159
160

161
162
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
180
181
182
183











184
185
186
187
188
189
190
191

192
193

194
195
196
197
198
199
200

201
202
203
204
205
206
207

208
209
210
211
212
213
214








215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231

232

233
234
235
236
237
238
239
240
241
242

243
244
245




246
247
248
249
250
251
252
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
85


86
87
88
89
90
91
92
93
94
95


96
97
98
99
100
101
102
103
104
105
106
107


108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135
136
137


138
139
140
141
142
143
144
145
146
147
148


149
150
151
152
153
154
155
156
157
158
159
160


161
162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189
190
191
192
193


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

212
213

214
215
216
217
218
219
220

221
222
223
224
225
226
227

228
229
230
231
232
233
234

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278
279
280
281
282
283
284
285







-
+


















+
+
+
+
+
+
+
-
-
+
+
+
+













-
+
+








-
-
+
+








-
-
+
+
+









-
-
+
+








-
+
+








-
+









-
-
+
+









-
-
+
+










-
-
+
+









-
+









-
+











-
-
+
+
+
+
+
+
+
+
+
+
+







-
+

-
+






-
+






-
+






-
+
+
+
+
+
+
+
+

















+
-
+









-
+



+
+
+
+







#import "OFObject.h"
#import "OFCollection.h"
#import "OFEnumerator.h"
#import "OFSerialization.h"
#import "OFJSONRepresentation.h"
#import "OFMessagePackRepresentation.h"

@class OFArray;
@class OFArray OF_GENERIC(ObjectType);

#ifdef OF_HAVE_BLOCKS
typedef void (^of_dictionary_enumeration_block_t)(id key, id object,
     bool *stop);
typedef bool (^of_dictionary_filter_block_t)(id key, id object);
typedef id (^of_dictionary_map_block_t)(id key, id object);
#endif

/*!
 * @class OFDictionary OFDictionary.h ObjFW/OFDictionary.h
 *
 * @brief An abstract class for storing objects in a dictionary.
 *
 * Keys are copied and thus must conform to the OFCopying protocol.
 *
 * @note Fast enumeration on a dictionary enumerates through the keys of the
 *	 dictionary.
 */
#ifdef OF_HAVE_GENERICS
@interface OFDictionary <KeyType, ObjectType>:
#else
# ifndef DOXYGEN
#  define KeyType id
#  define ObjectType id
# endif
@interface OFDictionary: OFObject <OFCopying, OFMutableCopying, OFCollection,
    OFSerialization, OFJSONRepresentation, OFMessagePackRepresentation>
@interface OFDictionary:
#endif
    OFObject <OFCopying, OFMutableCopying, OFCollection, OFSerialization,
    OFJSONRepresentation, OFMessagePackRepresentation>
/*!
 * @brief Creates a new OFDictionary.
 *
 * @return A new autoreleased OFDictionary
 */
+ (instancetype)dictionary;

/*!
 * @brief Creates a new OFDictionary with the specified dictionary.
 *
 * @param dictionary An OFDictionary
 * @return A new autoreleased OFDictionary
 */
+ (instancetype)dictionaryWithDictionary: (OFDictionary*)dictionary;
+ (instancetype)dictionaryWithDictionary:
   (OFDictionary OF_GENERIC(KeyType, ObjectType)*)dictionary;

/*!
 * @brief Creates a new OFDictionary with the specified key and object.
 *
 * @param key The key
 * @param object The object
 * @return A new autoreleased OFDictionary
 */
+ (instancetype)dictionaryWithObject: (id)object
			      forKey: (id)key;
+ (instancetype)dictionaryWithObject: (ObjectType)object
			      forKey: (KeyType)key;

/*!
 * @brief Creates a new OFDictionary with the specified keys and objects.
 *
 * @param keys An array of keys
 * @param objects An array of objects
 * @return A new autoreleased OFDictionary
 */
+ (instancetype)dictionaryWithObjects: (OFArray*)objects
			      forKeys: (OFArray*)keys;
+ (instancetype)
    dictionaryWithObjects: (OFArray OF_GENERIC(ObjectType)*)objects
		  forKeys: (OFArray OF_GENERIC(KeyType)*)keys;

/*!
 * @brief Creates a new OFDictionary with the specified keys and objects.
 *
 * @param keys An array of keys
 * @param objects An array of objects
 * @param count The number of objects in the arrays
 * @return A new autoreleased OFDictionary
 */
+ (instancetype)dictionaryWithObjects: (id const*)objects
			      forKeys: (id const*)keys
+ (instancetype)dictionaryWithObjects: (ObjectType const*)objects
			      forKeys: (KeyType const*)keys
				count: (size_t)count;

/*!
 * @brief Creates a new OFDictionary with the specified keys objects.
 *
 * @param firstKey The first key
 * @return A new autoreleased OFDictionary
 */
+ (instancetype)dictionaryWithKeysAndObjects: (id)firstKey, ... OF_SENTINEL;
+ (instancetype)dictionaryWithKeysAndObjects: (KeyType)firstKey, ...
    OF_SENTINEL;

/*!
 * @brief Initializes an already allocated OFDictionary with the specified
 *	  OFDictionary.
 *
 * @param dictionary An OFDictionary
 * @return An initialized OFDictionary
 */
- initWithDictionary: (OFDictionary*)dictionary;
- initWithDictionary: (OFDictionary OF_GENERIC(KeyType, ObjectType)*)dictionary;

/*!
 * @brief Initializes an already allocated OFDictionary with the specified key
 *	  and object.
 *
 * @param key The key
 * @param object The object
 * @return An initialized OFDictionary
 */
- initWithObject: (id)object
	  forKey: (id)key;
- initWithObject: (ObjectType)object
	  forKey: (KeyType)key;

/*!
 * @brief Initializes an already allocated OFDictionary with the specified keys
 *	  and objects.
 *
 * @param keys An array of keys
 * @param objects An array of objects
 * @return An initialized OFDictionary
 */
- initWithObjects: (OFArray*)objects
	  forKeys: (OFArray*)keys;
- initWithObjects: (OFArray OF_GENERIC(ObjectType)*)objects
	  forKeys: (OFArray OF_GENERIC(KeyType)*)keys;

/*!
 * @brief Initializes an already allocated OFDictionary with the specified keys
 *	  and objects.
 *
 * @param keys An array of keys
 * @param objects An array of objects
 * @param count The number of objects in the arrays
 * @return An initialized OFDictionary
 */
- initWithObjects: (id const*)objects
	  forKeys: (id const*)keys
- initWithObjects: (ObjectType const*)objects
	  forKeys: (KeyType const*)keys
	    count: (size_t)count;

/*!
 * @brief Initializes an already allocated OFDictionary with the specified keys
 *	  and objects.
 *
 * @param firstKey The first key
 * @return An initialized OFDictionary
 */
- initWithKeysAndObjects: (id)firstKey, ... OF_SENTINEL;
- initWithKeysAndObjects: (KeyType)firstKey, ... OF_SENTINEL;

/*!
 * @brief Initializes an already allocated OFDictionary with the specified key
 *	  and va_list.
 *
 * @param firstKey The first key
 * @param arguments A va_list of the other arguments
 * @return An initialized OFDictionary
 */
- initWithKey: (id)firstKey
- initWithKey: (KeyType)firstKey
    arguments: (va_list)arguments;

/*!
 * @brief Returns the object for the given key or nil if the key was not found.
 *
 * @warning The returned object is *not* retained and autoreleased for
 *	    performance reasons!
 *
 * @param key The key whose object should be returned
 * @return The object for the given key or nil if the key was not found
 */
- (id)objectForKey: (id)key;
- (id)objectForKeyedSubscript: (id)key;
- (ObjectType)objectForKey: (KeyType)key;
- (ObjectType)objectForKeyedSubscript: (KeyType)key;

/*!
 * @brief Checks whether the dictionary contains an object equal to the
 *	  specified object.
 *
 * @param object The object which is checked for being in the dictionary
 * @return A boolean whether the dictionary contains the specified object
 */
- (bool)containsObject: (ObjectType)object;

/*!
 * @brief Checks whether the dictionary contains an object with the specified
 *	  address.
 *
 * @param object The object which is checked for being in the dictionary
 * @return A boolean whether the dictionary contains an object with the
 *	   specified address.
 *	   specified address
 */
- (bool)containsObjectIdenticalTo: (id)object;
- (bool)containsObjectIdenticalTo: (ObjectType)object;

/*!
 * @brief Returns an array of all keys.
 *
 * @return An array of all keys
 */
- (OFArray*)allKeys;
- (OFArray OF_GENERIC(KeyType)*)allKeys;

/*!
 * @brief Returns an array of all objects.
 *
 * @return An array of all objects
 */
- (OFArray*)allObjects;
- (OFArray OF_GENERIC(ObjectType)*)allObjects;

/*!
 * @brief Returns an OFEnumerator to enumerate through the dictionary's keys.
 *
 * @return An OFEnumerator to enumerate through the dictionary's keys
 */
- (OFEnumerator*)keyEnumerator;
- (OFEnumerator OF_GENERIC(KeyType)*)keyEnumerator;

/*!
 * @brief Returns an OFEnumerator to enumerate through the dictionary's objects.
 *
 * @return An OFEnumerator to enumerate through the dictionary's objects
 */
- (OFEnumerator OF_GENERIC(ObjectType)*)objectEnumerator;

#ifdef OF_HAVE_BLOCKS
/*!
 * @brief Executes a block for each key / object pair.
 *
 * @param block The block to execute for each key / object pair.
 */
- (void)enumerateKeysAndObjectsUsingBlock:
    (of_dictionary_enumeration_block_t)block;

/*!
 * @brief Creates a new dictionary, mapping each object using the specified
 *	  block.
 *
 * @param block A block which maps an object for each object
 * @return A new autoreleased OFDictionary
 */
- (OFDictionary OF_GENERIC(KeyType, id)*)mappedDictionaryUsingBlock:
- (OFDictionary*)mappedDictionaryUsingBlock: (of_dictionary_map_block_t)block;
    (of_dictionary_map_block_t)block;

/*!
 * @brief Creates a new dictionary, only containing the objects for which the
 *	  block returns true.
 *
 * @param block A block which determines if the object should be in the new
 *		dictionary
 * @return A new autoreleased OFDictionary
 */
- (OFDictionary*)filteredDictionaryUsingBlock:
- (OFDictionary OF_GENERIC(KeyType, ObjectType)*)filteredDictionaryUsingBlock:
    (of_dictionary_filter_block_t)block;
#endif
@end
#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
# undef KeyType
# undef ObjectType
#endif

#import "OFMutableDictionary.h"

#ifndef NSINTEGER_DEFINED
/* Required for dictionary literals to work */
@compatibility_alias NSDictionary OFDictionary;
#endif