ObjFW
|
00001 /* 00002 * Copyright (c) 2008, 2009, 2010, 2011 00003 * Jonathan Schleifer <js@webkeks.org> 00004 * 00005 * All rights reserved. 00006 * 00007 * This file is part of ObjFW. It may be distributed under the terms of the 00008 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in 00009 * the packaging of this file. 00010 * 00011 * Alternatively, it may be distributed under the terms of the GNU General 00012 * Public License, either version 2 or 3, which can be found in the file 00013 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this 00014 * file. 00015 */ 00016 00017 #include <stdarg.h> 00018 00019 #import "OFObject.h" 00020 #import "OFCollection.h" 00021 #import "OFEnumerator.h" 00022 00023 @class OFArray; 00024 00025 #ifdef OF_HAVE_BLOCKS 00026 typedef void (^of_dictionary_enumeration_block_t)(id key, id obj, BOOL *stop); 00027 typedef BOOL (^of_dictionary_filter_block_t)(id key, id obj); 00028 typedef id (^of_dictionary_map_block_t)(id key, id obj); 00029 #endif 00030 00031 struct of_dictionary_bucket 00032 { 00033 id <OFCopying> key; 00034 id object; 00035 uint32_t hash; 00036 }; 00037 00041 @interface OFDictionary: OFObject <OFCopying, OFMutableCopying, OFCollection, 00042 OFFastEnumeration> 00043 { 00044 struct of_dictionary_bucket **data; 00045 uint32_t size; 00046 size_t count; 00047 } 00048 00054 + dictionary; 00055 00062 + dictionaryWithDictionary: (OFDictionary*)dict; 00063 00071 + dictionaryWithObject: (id)obj 00072 forKey: (id <OFCopying>)key; 00073 00081 + dictionaryWithObjects: (OFArray*)objs 00082 forKeys: (OFArray*)keys; 00083 00090 + dictionaryWithKeysAndObjects: (id <OFCopying>)key, ...; 00091 00097 - init; 00098 00106 - initWithDictionary: (OFDictionary*)dict; 00107 00116 - initWithObject: (id)obj 00117 forKey: (id <OFCopying>)key; 00118 00127 - initWithObjects: (OFArray*)objs 00128 forKeys: (OFArray*)keys; 00129 00137 - initWithKeysAndObjects: (id <OFCopying>)first, ...; 00138 00147 - initWithKey: (id <OFCopying>)first 00148 argList: (va_list)args; 00149 00159 - (id)objectForKey: (id)key; 00160 00164 - (OFEnumerator*)keyEnumerator; 00165 00166 #ifdef OF_HAVE_BLOCKS 00167 00172 - (void)enumerateKeysAndObjectsUsingBlock: 00173 (of_dictionary_enumeration_block_t)block; 00174 00181 - (OFDictionary*)mappedDictionaryUsingBlock: (of_dictionary_map_block_t)block; 00182 00191 - (OFDictionary*)filteredDictionaryUsingBlock: 00192 (of_dictionary_filter_block_t)block; 00193 #endif 00194 @end 00195 00196 @interface OFDictionaryEnumerator: OFEnumerator 00197 { 00198 OFDictionary *dictionary; 00199 struct of_dictionary_bucket **data; 00200 uint32_t size; 00201 unsigned long mutations; 00202 unsigned long *mutationsPtr; 00203 uint32_t pos; 00204 } 00205 00206 - initWithDictionary: (OFDictionary*)dictionary 00207 data: (struct of_dictionary_bucket**)data 00208 size: (uint32_t)size 00209 mutationsPointer: (unsigned long*)mutationsPtr; 00210 @end 00211 00212 @interface OFDictionaryObjectEnumerator: OFDictionaryEnumerator 00213 @end 00214 00215 @interface OFDictionaryKeyEnumerator: OFDictionaryEnumerator 00216 @end 00217 00218 #import "OFMutableDictionary.h" 00219 00220 #ifdef __cplusplus 00221 extern "C" { 00222 #endif 00223 extern struct of_dictionary_bucket of_dictionary_deleted_bucket; 00224 #ifdef __cplusplus 00225 } 00226 #endif