Index: Doxyfile ================================================================== --- Doxyfile +++ Doxyfile @@ -4,19 +4,20 @@ FILE_PATTERNS = *.h *.m HTML_OUTPUT = . GENERATE_LATEX = NO HIDE_UNDOC_CLASSES = YES HIDE_UNDOC_MEMBERS = YES -PREDEFINED = OF_HAVE_BLOCKS \ +PREDEFINED = DOXYGEN \ + OF_HAVE_BLOCKS \ OF_HAVE_FILES \ OF_HAVE_OPTIONAL_PROTOCOLS \ OF_HAVE_PROPERTIES \ OF_HAVE_SOCKETS \ OF_HAVE_THREADS \ OF_METHOD_NORETURN \ OF_NO_RETURN \ - OF_NO_RETURN_FUNC + OF_NO_RETURN_FUNC \ OF_SENTINEL \ OF_REQUIRES_SUPER \ OF_RETURNS_RETAINED \ OF_RETURNS_NOT_RETAINED \ OF_RETURNS_INNER_POINTER \ Index: src/OFApplication.h ================================================================== --- src/OFApplication.h +++ src/OFApplication.h @@ -15,14 +15,16 @@ */ #import "OFObject.h" @class OFString; -@class OFArray; -@class OFDictionary; -@class OFMutableArray; -@class OFMutableDictionary; +#ifndef DOXYGEN +@class OFArray OF_GENERIC(ObjectType); +@class OFDictionary OF_GENERIC(KeyType, ObjectType); +@class OFMutableArray OF_GENERIC(ObjectType); +@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); +#endif #define OF_APPLICATION_DELEGATE(cls) \ int \ main(int argc, char *argv[]) \ { \ @@ -110,12 +112,12 @@ * @ref OFApplicationDelegate::applicationDidFinishLaunching. */ @interface OFApplication: OFObject { OFString *_programName; - OFArray *_arguments; - OFDictionary *_environment; + OFArray OF_GENERIC(OFString*) *_arguments; + OFDictionary OF_GENERIC(OFString*, OFString*) *_environment; int *_argc; char ***_argv; @public id _delegate; void (*_SIGINTHandler)(id, SEL); @@ -126,12 +128,13 @@ #endif } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy, nonatomic) OFString *programName; -@property (readonly, copy, nonatomic) OFArray *arguments; -@property (readonly, copy, nonatomic) OFDictionary *environment; +@property (readonly, copy, nonatomic) OFArray OF_GENERIC(OFString*) *arguments; +@property (readonly, copy, nonatomic) + OFDictionary OF_GENERIC(OFString*, OFString*) *environment; @property (assign) id delegate; #endif /*! * @brief Returns the only OFApplication instance in the application. @@ -150,18 +153,18 @@ /*! * @brief Returns the arguments passed to the application. * * @return The arguments passed to the application */ -+ (OFArray*)arguments; ++ (OFArray OF_GENERIC(OFString*)*)arguments; /*! * @brief Returns the environment of the application. * * @return The environment of the application */ -+ (OFDictionary*)environment; ++ (OFDictionary OF_GENERIC(OFString*, OFString*)*)environment; /*! * @brief Terminates the application with the EXIT_SUCCESS status. */ + (void)terminate OF_NO_RETURN; @@ -192,18 +195,18 @@ /*! * @brief Returns the arguments passed to the application. * * @return The arguments passed to the application */ -- (OFArray*)arguments; +- (OFArray OF_GENERIC(OFString*)*)arguments; /*! * @brief Returns the environment of the application. * * @return The environment of the application */ -- (OFDictionary*)environment; +- (OFDictionary OF_GENERIC(OFString*, OFString*)*)environment; /*! * @brief Returns the delegate of the application. * * @return The delegate of the application Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -82,12 +82,20 @@ /*! * @class OFArray OFArray.h ObjFW/OFArray.h * * @brief An abstract class for storing objects in an array. */ -@interface OFArray: OFObject +#ifdef OF_HAVE_GENERICS +@interface OFArray : +#else +# ifndef DOXYGEN +# define ObjectType id +# endif +@interface OFArray: +#endif + OFObject #ifdef OF_HAVE_PROPERTIES @property (readonly) size_t count; #endif /*! @@ -101,82 +109,82 @@ * @brief Creates a new OFArray with the specified object. * * @param object An object * @return A new autoreleased OFArray */ -+ (instancetype)arrayWithObject: (id)object; ++ (instancetype)arrayWithObject: (ObjectType)object; /*! * @brief Creates a new OFArray with the specified objects, terminated by nil. * * @param firstObject The first object in the array * @return A new autoreleased OFArray */ -+ (instancetype)arrayWithObjects: (id)firstObject, ... OF_SENTINEL; ++ (instancetype)arrayWithObjects: (ObjectType)firstObject, ... OF_SENTINEL; /*! * @brief Creates a new OFArray with the objects from the specified array. * * @param array An array * @return A new autoreleased OFArray */ -+ (instancetype)arrayWithArray: (OFArray*)array; ++ (instancetype)arrayWithArray: (OFArray OF_GENERIC(ObjectType)*)array; /*! * @brief Creates a new OFArray with the objects from the specified C array of * the specified length. * * @param objects A C array of objects * @param count The length of the C array * @return A new autoreleased OFArray */ -+ (instancetype)arrayWithObjects: (id const*)objects ++ (instancetype)arrayWithObjects: (ObjectType const*)objects count: (size_t)count; /*! * @brief Initializes an OFArray with the specified object. * * @param object An object * @return An initialized OFArray */ -- initWithObject: (id)object; +- initWithObject: (ObjectType)object; /*! * @brief Initializes an OFArray with the specified objects. * * @param firstObject The first object * @return An initialized OFArray */ -- initWithObjects: (id)firstObject, ... OF_SENTINEL; +- initWithObjects: (ObjectType)firstObject, ... OF_SENTINEL; /*! * @brief Initializes an OFArray with the specified object and a va_list. * * @param firstObject The first object * @param arguments A va_list * @return An initialized OFArray */ -- initWithObject: (id)firstObject +- initWithObject: (ObjectType)firstObject arguments: (va_list)arguments; /*! * @brief Initializes an OFArray with the objects from the specified array. * * @param array An array * @return An initialized OFArray */ -- initWithArray: (OFArray*)array; +- initWithArray: (OFArray OF_GENERIC(ObjectType)*)array; /*! * @brief Initializes an OFArray with the objects from the specified C array of * the specified length. * * @param objects A C array of objects * @param count The length of the C array * @return An initialized OFArray */ -- initWithObjects: (id const*)objects +- initWithObjects: (ObjectType const*)objects count: (size_t)count; /*! * @brief Returns the object at the specified index in the array. * @@ -184,86 +192,95 @@ * performance reasons! * * @param index The index of the object to return * @return The object at the specified index in the array */ -- (id)objectAtIndex: (size_t)index; -- (id)objectAtIndexedSubscript: (size_t)index; +- (ObjectType)objectAtIndex: (size_t)index; +- (ObjectType)objectAtIndexedSubscript: (size_t)index; /*! * @brief Copies the objects at the specified range to the specified buffer. * * @param buffer The buffer to copy the objects to * @param range The range to copy */ -- (void)getObjects: (__unsafe_unretained id*)buffer +- (void)getObjects: (__unsafe_unretained ObjectType*)buffer inRange: (of_range_t)range; /*! * @brief Returns the objects of the array as a C array. * * @return The objects of the array as a C array */ -- (id const*)objects; +- (ObjectType const*)objects; /*! * @brief Returns the index of the first object that is equivalent to the * specified object or `OF_NOT_FOUND` if it was not found. * * @param object The object whose index is returned * @return The index of the first object equivalent to the specified object * or `OF_NOT_FOUND` if it was not found */ -- (size_t)indexOfObject: (id)object; +- (size_t)indexOfObject: (ObjectType)object; /*! * @brief Returns the index of the first object that has the same address as the * specified object or `OF_NOT_FOUND` if it was not found. * * @param object The object whose index is returned * @return The index of the first object that has the same aaddress as * the specified object or `OF_NOT_FOUND` if it was not found */ -- (size_t)indexOfObjectIdenticalTo: (id)object; +- (size_t)indexOfObjectIdenticalTo: (ObjectType)object; + +/*! + * @brief Checks whether the array contains an object equal to the specified + * object. + * + * @param object The object which is checked for being in the array + * @return A boolean whether the array contains the specified object + */ +- (bool)containsObject: (ObjectType)object; /*! * @brief Checks whether the array contains an object with the specified * address. * * @param object The object which is checked for being in the array * @return A boolean whether the array contains an object with the specified - * address. + * address */ -- (bool)containsObjectIdenticalTo: (id)object; +- (bool)containsObjectIdenticalTo: (ObjectType)object; /*! * @brief Returns the first object of the array or nil. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! * * @return The first object of the array or nil */ -- (id)firstObject; +- (ObjectType)firstObject; /*! * @brief Returns the last object of the array or nil. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! * * @return The last object of the array or nil */ -- (id)lastObject; +- (ObjectType)lastObject; /*! * @brief Returns the objects in the specified range as a new OFArray. * * @param range The range for the subarray * @return The subarray as a new autoreleased OFArray */ -- (OFArray*)objectsInRange: (of_range_t)range; +- (OFArray OF_GENERIC(ObjectType)*)objectsInRange: (of_range_t)range; /*! * @brief Creates a string by joining all objects of the array. * * @param separator The string with which the objects should be joined @@ -334,11 +351,11 @@ /*! * @brief Returns a sorted copy of the array. * * @return A sorted copy of the array */ -- (OFArray*)sortedArray; +- (OFArray OF_GENERIC(ObjectType)*)sortedArray; /*! * @brief Returns a sorted copy of the array. * * @param options The options to use when sorting the array.@n @@ -346,42 +363,51 @@ * Value | Description * ---------------------------|------------------------- * `OF_ARRAY_SORT_DESCENDING` | Sort in descending order * @return A sorted copy of the array */ -- (OFArray*)sortedArrayWithOptions: (int)options; +- (OFArray OF_GENERIC(ObjectType)*)sortedArrayWithOptions: (int)options; /*! * @brief Returns a copy of the array with the order reversed. * * @return A copy of the array with the order reversed */ -- (OFArray*)reversedArray; +- (OFArray OF_GENERIC(ObjectType)*)reversedArray; /*! * @brief Creates a new array with the specified object added. * * @param object The object to add * @return A new array with the specified object added */ -- (OFArray*)arrayByAddingObject: (id)object; +- (OFArray OF_GENERIC(ObjectType)*)arrayByAddingObject: (ObjectType)object; /*! * @brief Creates a new array with the objects from the specified array added. * * @param array The array with objects to add * @return A new array with the objects from the specified array added */ -- (OFArray*)arrayByAddingObjectsFromArray: (OFArray*)array; +- (OFArray OF_GENERIC(ObjectType)*)arrayByAddingObjectsFromArray: + (OFArray OF_GENERIC(ObjectType)*)array; /*! * @brief Creates a new array with the specified object removed. * * @param object The object to remove * @return A new array with the specified object removed */ -- (OFArray*)arrayByRemovingObject: (id)object; +- (OFArray OF_GENERIC(ObjectType)*)arrayByRemovingObject: (ObjectType)object; + +/*! + * @brief Returns an OFEnumerator to enumerate through all objects of the + * array. + * + * @returns An OFEnumerator to enumerate through all objects of the array + */ +- (OFEnumerator OF_GENERIC(ObjectType)*)objectEnumerator; #ifdef OF_HAVE_BLOCKS /*! * @brief Executes a block for each object. * @@ -403,11 +429,12 @@ * * @param block A block which determines if the object should be in the new * array * @return A new, autoreleased OFArray */ -- (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block; +- (OFArray OF_GENERIC(ObjectType)*)filteredArrayUsingBlock: + (of_array_filter_block_t)block; /*! * @brief Folds the array to a single object using the specified block. * * If the array is empty, it will return nil. @@ -424,10 +451,13 @@ * @return The array folded to a single object */ - (id)foldUsingBlock: (of_array_fold_block_t)block; #endif @end +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# undef ObjectType +#endif @interface OFArrayEnumerator: OFEnumerator { OFArray *_array; size_t _count; Index: src/OFCountedSet.h ================================================================== --- src/OFCountedSet.h +++ src/OFCountedSet.h @@ -35,17 +35,24 @@ * @class OFCountedSet OFCountedSet.h ObjFW/OFCountedSet.h * * @brief An abstract class for a mutable unordered set of objects, counting how * often it contains an object. */ +#ifdef OF_HAVE_GENERICS +@interface OFCountedSet : OFMutableSet +#else +# ifndef DOXYGEN +# define ObjectType id +# endif @interface OFCountedSet: OFMutableSet +#endif /*! * @brief Returns how often the object is in the set. * * @return How often the object is in the set */ -- (size_t)countForObject: (id)object; +- (size_t)countForObject: (ObjectType)object; #ifdef OF_HAVE_BLOCKS /*! * @brief Executes a block for each object in the set. * @@ -53,5 +60,8 @@ */ - (void)enumerateObjectsAndCountUsingBlock: (of_counted_set_enumeration_block_t)block; #endif @end +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# undef ObjectType +#endif Index: src/OFDictionary.h ================================================================== --- src/OFDictionary.h +++ src/OFDictionary.h @@ -28,11 +28,11 @@ #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); @@ -47,12 +47,21 @@ * Keys are copied and thus must conform to the OFCopying protocol. * * @note Fast enumeration on a dictionary enumerates through the keys of the * dictionary. */ -@interface OFDictionary: OFObject +#ifdef OF_HAVE_GENERICS +@interface OFDictionary : +#else +# ifndef DOXYGEN +# define KeyType id +# define ObjectType id +# endif +@interface OFDictionary: +#endif + OFObject /*! * @brief Creates a new OFDictionary. * * @return A new autoreleased OFDictionary */ @@ -62,82 +71,85 @@ * @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. * @@ -144,32 +156,32 @@ * @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. * @@ -177,43 +189,59 @@ * 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. * @@ -227,26 +255,31 @@ * block. * * @param block A block which maps an object for each object * @return A new autoreleased OFDictionary */ -- (OFDictionary*)mappedDictionaryUsingBlock: (of_dictionary_map_block_t)block; +- (OFDictionary OF_GENERIC(KeyType, id)*)mappedDictionaryUsingBlock: + (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 Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -410,16 +410,16 @@ objc_autoreleasePoolPop(pool); return ret; } -- (OFEnumerator*)objectEnumerator +- (OFEnumerator*)keyEnumerator { OF_UNRECOGNIZED_SELECTOR } -- (OFEnumerator*)keyEnumerator +- (OFEnumerator*)objectEnumerator { OF_UNRECOGNIZED_SELECTOR } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state Index: src/OFEnumerator.h ================================================================== --- src/OFEnumerator.h +++ src/OFEnumerator.h @@ -14,12 +14,14 @@ * file. */ #import "OFObject.h" -@class OFEnumerator; -@class OFArray; +#ifndef DOXYGEN +@class OFEnumerator OF_GENERIC(ObjectType); +@class OFArray OF_GENERIC(ObjectType); +#endif /*! * @protocol OFEnumerating OFEnumerator.h ObjFW/OFEnumerator.h * * @brief A protocol for getting an enumerator for the object. @@ -37,31 +39,41 @@ /*! * @class OFEnumerator OFEnumerator.h ObjFW/OFEnumerator.h * * @brief A class which provides methods to enumerate through collections. */ +#ifdef OF_HAVE_GENERICS +@interface OFEnumerator : OFObject +#else +# ifndef DOXYGEN +# define ObjectType id +# endif @interface OFEnumerator: OFObject +#endif /*! * @brief Returns the next object. * * @return The next object */ -- (id)nextObject; +- (ObjectType)nextObject; /*! * @brief Returns an array of all remaining objects in the collection. * * @return An array of all remaining objects in the collection */ -- (OFArray*)allObjects; +- (OFArray OF_GENERIC(ObjectType)*)allObjects; /*! * @brief Resets the enumerator, so the next call to nextObject returns the * first object again. */ - (void)reset; @end +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# undef ObjectType +#endif /* * This needs to be exactly like this because it's hardcoded in the compiler. * * We need this bad check to see if we already imported Cocoa, which defines Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -24,11 +24,11 @@ #include #include #import "OFSeekableStream.h" -@class OFArray; +@class OFArray OF_GENERIC(ObjectType); @class OFDate; #if defined(_WIN32) typedef struct __stat64 of_stat_t; #elif defined(OF_HAVE_OFF64_T) @@ -137,11 +137,11 @@ * @note `.` and `..` are not part of the returned array. * * @param path The path to the directory whose items should be returned * @return An array of OFStrings with the items in the specified directory */ -+ (OFArray*)contentsOfDirectoryAtPath: (OFString*)path; ++ (OFArray OF_GENERIC(OFString*)*)contentsOfDirectoryAtPath: (OFString*)path; /*! * @brief Changes the current working directory. * * @param path The new directory to change to Index: src/OFHTTPClient.h ================================================================== --- src/OFHTTPClient.h +++ src/OFHTTPClient.h @@ -23,11 +23,11 @@ @class OFHTTPClient; @class OFHTTPRequest; @class OFHTTPResponse; @class OFURL; @class OFTCPSocket; -@class OFDictionary; +@class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFDataArray; /*! * @protocol OFHTTPClientDelegate OFHTTPClient.h ObjFW/OFHTTPClient.h * @@ -61,11 +61,11 @@ * @param statusCode The status code received * @param request The request for which the headers and status code have been * received */ - (void)client: (OFHTTPClient*)client - didReceiveHeaders: (OFDictionary*)headers + didReceiveHeaders: (OFDictionary OF_GENERIC(OFString*, OFString*)*)headers statusCode: (int)statusCode request: (OFHTTPRequest*)request; /*! * @brief A callback which is called when an OFHTTPClient wants to follow a Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -20,11 +20,11 @@ #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif @class OFURL; -@class OFDictionary; +@class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFDataArray; @class OFString; /*! @file */ @@ -71,20 +71,20 @@ @interface OFHTTPRequest: OFObject { OFURL *_URL; of_http_request_method_t _method; of_http_request_protocol_version_t _protocolVersion; - OFDictionary *_headers; + OFDictionary OF_GENERIC(OFString*, OFString*) *_headers; OFDataArray *_body; OFString *_remoteAddress; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFURL *URL; @property of_http_request_method_t method; @property of_http_request_protocol_version_t protocolVersion; -@property (copy) OFDictionary *headers; +@property (copy) OFDictionary OF_GENERIC(OFString*, OFString*) *headers; @property (retain) OFDataArray *body; @property (copy) OFString *remoteAddress; #endif /*! @@ -170,18 +170,18 @@ /*! * @brief Sets a dictionary with headers for the HTTP request. * * @param headers A dictionary with headers for the HTTP request */ -- (void)setHeaders: (OFDictionary*)headers; +- (void)setHeaders: (OFDictionary OF_GENERIC(OFString*, OFString*)*)headers; /*! * @brief Returns a dictionary with headers for the HTTP request. * * @return A dictionary with headers for the HTTP request. */ -- (OFDictionary*)headers; +- (OFDictionary OF_GENERIC(OFString*, OFString*)*)headers; /*! * @brief Sets the entity body of the HTTP request. * * @param body The entity body of the HTTP request Index: src/OFHTTPResponse.h ================================================================== --- src/OFHTTPResponse.h +++ src/OFHTTPResponse.h @@ -15,11 +15,11 @@ */ #import "OFStream.h" #import "OFHTTPRequest.h" -@class OFDictionary; +@class OFDictionary OF_GENERIC(KeyType, ObjectType); /*! * @class OFHTTPResponse OFHTTPResponse.h ObjFW/OFHTTPResponse.h * * @brief A class for representing an HTTP request reply as a stream. @@ -26,17 +26,17 @@ */ @interface OFHTTPResponse: OFStream { of_http_request_protocol_version_t _protocolVersion; short _statusCode; - OFDictionary *_headers; + OFDictionary OF_GENERIC(OFString*, OFString*) *_headers; } #ifdef OF_HAVE_PROPERTIES @property of_http_request_protocol_version_t protocolVersion; @property short statusCode; -@property (copy) OFDictionary *headers; +@property (copy) OFDictionary OF_GENERIC(OFString*, OFString*) *headers; #endif /*! * @brief Sets the protocol version of the HTTP request reply. * @@ -83,18 +83,18 @@ /*! * @brief Returns the headers of the reply to the HTTP request. * * @return The headers of the reply to the HTTP request */ -- (OFDictionary*)headers; +- (OFDictionary OF_GENERIC(OFString*, OFString*)*)headers; /*! * @brief Returns the headers of the reply to the HTTP request. * * @param headers The headers of the reply to the HTTP request */ -- (void)setHeaders: (OFDictionary*)headers; +- (void)setHeaders: (OFDictionary OF_GENERIC(OFString*, OFString*)*)headers; /*! * @brief Returns the reply as a string, trying to detect the encoding. * * @return The reply as a string Index: src/OFINICategory.h ================================================================== --- src/OFINICategory.h +++ src/OFINICategory.h @@ -15,12 +15,14 @@ */ #import "OFObject.h" @class OFString; -@class OFArray; -@class OFMutableArray; +#ifndef DOXYGEN +@class OFArray OF_GENERIC(ObjectType); +@class OFMutableArray OF_GENERIC(ObjectType); +#endif /*! * @class OFINICategory OFINICategory.h ObjFW/OFINICategory.h * * @brief A class for representing a category of an INI file. @@ -145,11 +147,11 @@ * * @param key The multi-key for which the array should be returned * @return The array for the specified key, or an empty array if it does not * exist */ -- (OFArray*)arrayForKey: (OFString*)key; +- (OFArray OF_GENERIC(OFString*)*)arrayForKey: (OFString*)key; /*! * @brief Sets the value of the specified key to the specified string. * * If the specified key is a multi-key (see @ref arrayForKey:), the value of @@ -219,11 +221,11 @@ * See also @ref arrayForKey: for more information about multi-keys. * * @param array The array of strings to which the multi-key should be set * @param key The multi-key for which the new values should be set */ -- (void)setArray: (OFArray*)array +- (void)setArray: (OFArray OF_GENERIC(OFString*)*)array forKey: (OFString*)key; /*! * @brief Removes the value for the specified key * Index: src/OFINIFile.h ================================================================== --- src/OFINIFile.h +++ src/OFINIFile.h @@ -16,20 +16,20 @@ #import "OFObject.h" #import "OFString.h" #import "OFINICategory.h" -@class OFMutableArray; +@class OFMutableArray OF_GENERIC(ObjectType); /*! * @class OFINIFile OFINIFile.h ObjFW/OFINIFile.h * * @brief A class for reading, creating and modifying INI files. */ @interface OFINIFile: OFObject { - OFMutableArray *_categories; + OFMutableArray OF_GENERIC(OFINICategory*) *_categories; } /*! * @brief Creates a new OFINIFile with the contents of the specified file. * Index: src/OFIntrospection.h ================================================================== --- src/OFIntrospection.h +++ src/OFIntrospection.h @@ -15,12 +15,14 @@ */ #import "OFObject.h" @class OFString; -@class OFArray; -@class OFMutableArray; +#ifndef DOXYGEN +@class OFArray OF_GENERIC(ObjectType); +@class OFMutableArray OF_GENERIC(ObjectType); +#endif enum { OF_PROPERTY_READONLY = 0x01, OF_PROPERTY_ASSIGN = 0x04, OF_PROPERTY_READWRITE = 0x08, @@ -179,21 +181,22 @@ * * @brief A class for introspecting classes. */ @interface OFIntrospection: OFObject { - OFMutableArray *_classMethods; - OFMutableArray *_instanceMethods; - OFMutableArray *_properties; - OFMutableArray *_instanceVariables; + OFMutableArray OF_GENERIC(OFMethod*) *_classMethods; + OFMutableArray OF_GENERIC(OFMethod*) *_instanceMethods; + OFMutableArray OF_GENERIC(OFProperty*) *_properties; + OFMutableArray OF_GENERIC(OFInstanceVariable*) *_instanceVariables; } #ifdef OF_HAVE_PROPERTIES -@property (readonly, copy) OFArray *classMethods; -@property (readonly, copy) OFArray *instanceMethods; -@property (readonly, copy) OFArray *properties; -@property (readonly, copy) OFArray *instanceVariables; +@property (readonly, copy) OFArray OF_GENERIC(OFMethod*) *classMethods; +@property (readonly, copy) OFArray OF_GENERIC(OFMethod*) *instanceMethods; +@property (readonly, copy) OFArray OF_GENERIC(OFProperty*) *properties; +@property (readonly, copy) + OFArray OF_GENERIC(OFInstanceVariable*) *instanceVariables; #endif /*! * @brief Creates a new introspection for the specified class. * @@ -212,18 +215,18 @@ /*! * @brief Returns the class methods of the class. * * @return An array of objects of class @ref OFMethod */ -- (OFArray*)classMethods; +- (OFArray OF_GENERIC(OFMethod*)*)classMethods; /*! * @brief Returns the instance methods of the class. * * @return An array of objects of class @ref OFMethod */ -- (OFArray*)instanceMethods; +- (OFArray OF_GENERIC(OFMethod*)*)instanceMethods; /*! * @brief Returns the properties of the class. * * @warning **Do not rely on this, as this behaves differently depending on the @@ -243,16 +246,16 @@ * @warning GCC does not emit any data for property introspection for the GNU * ABI. * * @return An array of objects of class @ref OFProperty */ -- (OFArray*)properties; +- (OFArray OF_GENERIC(OFProperty*)*)properties; /*! * @brief Returns the instance variables of the class. * * @return An array of objects of class @ref OFInstanceVariable */ -- (OFArray*)instanceVariables; +- (OFArray OF_GENERIC(OFInstanceVariable*)*)instanceVariables; /* TODO: protocols */ @end Index: src/OFKernelEventObserver.h ================================================================== --- src/OFKernelEventObserver.h +++ src/OFKernelEventObserver.h @@ -16,12 +16,12 @@ #import "OFObject.h" #import "socket.h" -@class OFMutableArray; -@class OFMutableDictionary; +@class OFMutableArray OF_GENERIC(ObjectType); +@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFDataArray; #ifdef OF_HAVE_THREADS @class OFMutex; #endif @class OFDate; @@ -106,12 +106,14 @@ * * @note Currently, Win32 can only observe TCP and UDP sockets! */ @interface OFKernelEventObserver: OFObject { - OFMutableArray *_readObjects; - OFMutableArray *_writeObjects; + OFMutableArray OF_GENERIC(id ) + *_readObjects; + OFMutableArray OF_GENERIC(id ) + *_writeObjects; OFMutableArray *_queue; OFDataArray *_queueActions; id _delegate; #ifdef OF_HAVE_PIPE int _cancelFD[2]; Index: src/OFKernelEventObserver_kqueue.h ================================================================== --- src/OFKernelEventObserver_kqueue.h +++ src/OFKernelEventObserver_kqueue.h @@ -15,14 +15,14 @@ */ #import "OFKernelEventObserver.h" @class OFDataArray; -@class OFMutableArray; +@class OFMutableArray OF_GENERIC(ObjectType); @interface OFKernelEventObserver_kqueue: OFKernelEventObserver { int _kernelQueue; OFDataArray *_changeList; OFMutableArray *_removedArray; } @end Index: src/OFList.h ================================================================== --- src/OFList.h +++ src/OFList.h @@ -40,11 +40,19 @@ /*! * @class OFList OFList.h ObjFW/OFList.h * * @brief A class which provides easy to use double-linked lists. */ -@interface OFList: OFObject +#ifdef OF_HAVE_GENERICS +@interface OFList : +#else +# ifndef DOXYGEN +# define ObjectType id +# endif +@interface OFList: +#endif + OFObject { of_list_object_t *_firstListObject; of_list_object_t *_lastListObject; size_t _count; unsigned long _mutations; @@ -82,21 +90,21 @@ * @param object The object to append * @return An of_list_object_t, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its of_list_object_t. */ -- (of_list_object_t*)appendObject: (id)object; +- (of_list_object_t*)appendObject: (ObjectType)object; /*! * @brief Prepends an object to the list. * * @param object The object to prepend * @return An of_list_object_t, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its of_list_object_t. */ -- (of_list_object_t*)prependObject: (id)object; +- (of_list_object_t*)prependObject: (ObjectType)object; /*! * @brief Inserts an object before another list object. * * @param object The object to insert @@ -104,11 +112,11 @@ * be inserted * @return An of_list_object_t, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its of_list_object_t. */ -- (of_list_object_t*)insertObject: (id)object +- (of_list_object_t*)insertObject: (ObjectType)object beforeListObject: (of_list_object_t*)listObject; /*! * @brief Inserts an object after another list object. * @@ -117,54 +125,73 @@ * inserted * @return An of_list_object_t, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its of_list_object_t. */ -- (of_list_object_t*)insertObject: (id)object +- (of_list_object_t*)insertObject: (ObjectType)object afterListObject: (of_list_object_t*)listObject; /*! * @brief Removes the object with the specified list object from the list. * * @param listObject The list object returned by append / prepend */ - (void)removeListObject: (of_list_object_t*)listObject; +/*! + * @brief Checks whether the list contains an object equal to the specified + * object. + * + * @param object The object which is checked for being in the list + * @return A boolean whether the list contains the specified object + */ +- (bool)containsObject: (ObjectType)object; + /*! * @brief Checks whether the list contains an object with the specified address. * * @param object The object which is checked for being in the list * @return A boolean whether the list contains an object with the specified - * address. + * address + */ +- (bool)containsObjectIdenticalTo: (ObjectType)object; + +/*! + * @brief Returns an OFEnumerator to enumerate through all objects of the list. + * + * @returns An OFEnumerator to enumerate through all objects of the list */ -- (bool)containsObjectIdenticalTo: (id)object; +- (OFEnumerator OF_GENERIC(ObjectType)*)objectEnumerator; /*! * @brief Returns the first object of the list or nil. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! * * @return The first object of the list or nil */ -- (id)firstObject; +- (ObjectType)firstObject; /*! * @brief Returns the last object of the list or nil. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! * * @return The last object of the list or nil */ -- (id)lastObject; +- (ObjectType)lastObject; /*! * @brief Removes all objects from the list. */ - (void)removeAllObjects; @end +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# undef ObjectType +#endif @interface OFListEnumerator: OFEnumerator { OFList *_list; of_list_object_t *_current; Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -33,11 +33,18 @@ * @class OFMutableArray OFArray.h ObjFW/OFArray.h * * @brief An abstract class for storing, adding and removing objects in an * array. */ +#ifdef OF_HAVE_GENERICS +@interface OFMutableArray : OFArray +#else +# ifndef DOXYGEN +# define ObjectType id +# endif @interface OFMutableArray: OFArray +#endif /*! * @brief Creates a new OFMutableArray with enough memory to hold the specified * number of objects. * * @param capacity The initial capacity for the OFMutableArray @@ -57,82 +64,82 @@ /*! * @brief Adds an object to the end of the array. * * @param object An object to add */ -- (void)addObject: (id)object; +- (void)addObject: (ObjectType)object; /*! * @brief Adds the objects from the specified OFArray to the end of the array. * * @param array An array of objects to add */ -- (void)addObjectsFromArray: (OFArray*)array; +- (void)addObjectsFromArray: (OFArray OF_GENERIC(ObjectType)*)array; /*! * @brief Inserts an object to the OFArray at the specified index. * * @param object An object to add * @param index The index where the object should be inserted */ -- (void)insertObject: (id)object +- (void)insertObject: (ObjectType)object atIndex: (size_t)index; /*! * @brief Inserts the objects from the specified OFArray at the specified index. * * @param array An array of objects * @param index The index where the objects should be inserted */ -- (void)insertObjectsFromArray: (OFArray*)array +- (void)insertObjectsFromArray: (OFArray OF_GENERIC(ObjectType)*)array atIndex: (size_t)index; /*! * @brief Replaces the first object equivalent to the specified object with the * other specified object. * * @param oldObject The object to replace * @param newObject The replacement object */ -- (void)replaceObject: (id)oldObject - withObject: (id)newObject; +- (void)replaceObject: (ObjectType)oldObject + withObject: (ObjectType)newObject; /*! * @brief Replaces the object at the specified index with the specified object. * * @param index The index of the object to replace * @param object The replacement object */ - (void)replaceObjectAtIndex: (size_t)index - withObject: (id)object; -- (void)setObject: (id)object + withObject: (ObjectType)object; +- (void)setObject: (ObjectType)object atIndexedSubscript: (size_t)index; /*! * @brief Replaces the first object that has the same address as the specified * object with the other specified object. * * @param oldObject The object to replace * @param newObject The replacement object */ -- (void)replaceObjectIdenticalTo: (id)oldObject - withObject: (id)newObject; +- (void)replaceObjectIdenticalTo: (ObjectType)oldObject + withObject: (ObjectType)newObject; /*! * @brief Removes the first object equivalent to the specified object. * * @param object The object to remove */ -- (void)removeObject: (id)object; +- (void)removeObject: (ObjectType)object; /*! * @brief Removes the first object that has the same address as the specified * object. * * @param object The object to remove */ -- (void)removeObjectIdenticalTo: (id)object; +- (void)removeObjectIdenticalTo: (ObjectType)object; /*! * @brief Removes the object at the specified index. * * @param index The index of the object to remove @@ -198,5 +205,8 @@ /*! * @brief Converts the mutable array to an immutable array. */ - (void)makeImmutable; @end +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# undef ObjectType +#endif Index: src/OFMutableDictionary.h ================================================================== --- src/OFMutableDictionary.h +++ src/OFMutableDictionary.h @@ -32,11 +32,20 @@ /*! * @class OFMutableDictionary OFDictionary.h ObjFW/OFDictionary.h * * @brief An abstract class for storing and changing objects in a dictionary. */ +#ifdef OF_HAVE_GENERICS +@interface OFMutableDictionary : + OFDictionary +#else +# ifndef DOXYGEN +# define KeyType id +# define ObjectType id +# endif @interface OFMutableDictionary: OFDictionary +#endif /*! * @brief Creates a new OFMutableDictionary with enough memory to hold the * specified number of objects. * * @param capacity The initial capacity for the OFMutableDictionary @@ -59,21 +68,21 @@ * A key can be any object that conforms to the OFCopying protocol. * * @param key The key to set * @param object The object to set the key to */ -- (void)setObject: (id)object - forKey: (id)key; -- (void)setObject: (id)object - forKeyedSubscript: (id)key; +- (void)setObject: (ObjectType)object + forKey: (KeyType)key; +- (void)setObject: (ObjectType)object + forKeyedSubscript: (KeyType)key; /*! * @brief Removes the object for the specified key from the dictionary. * * @param key The key whose object should be removed */ -- (void)removeObjectForKey: (id)key; +- (void)removeObjectForKey: (KeyType)key; /*! * @brief Removes all objects. */ - (void)removeAllObjects; @@ -90,5 +99,9 @@ /*! * @brief Converts the mutable dictionary to an immutable dictionary. */ - (void)makeImmutable; @end +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# undef KeyType +# undef ObjectType +#endif Index: src/OFMutableSet.h ================================================================== --- src/OFMutableSet.h +++ src/OFMutableSet.h @@ -19,47 +19,57 @@ /*! * @class OFMutableSet OFSet.h ObjFW/OFSet.h * * @brief An abstract class for a mutable unordered set of unique objects. */ +#ifdef OF_HAVE_GENERICS +@interface OFMutableSet : OFSet +#else +# ifndef DOXYGEN +# define ObjectType id +# endif @interface OFMutableSet: OFSet +#endif /*! * @brief Adds the specified object to the set. * * @param object The object to add to the set */ -- (void)addObject: (id)object; +- (void)addObject: (ObjectType)object; /*! * @brief Removes the specified object from the set. * * @param object The object to remove from the set */ -- (void)removeObject: (id)object; +- (void)removeObject: (ObjectType)object; /*! * @brief Removes all objects from the receiver which are in the specified set. * * @param set The set whose objects will be removed from the receiver */ -- (void)minusSet: (OFSet*)set; +- (void)minusSet: (OFSet OF_GENERIC(ObjectType)*)set; /*! * @brief Removes all objects from the receiver which are not in the specified * set. * * @param set The set to intersect with */ -- (void)intersectSet: (OFSet*)set; +- (void)intersectSet: (OFSet OF_GENERIC(ObjectType)*)set; /*! * @brief Creates a union of the receiver and the specified set. * * @param set The set to create the union with */ -- (void)unionSet: (OFSet*)set; +- (void)unionSet: (OFSet OF_GENERIC(ObjectType)*)set; /*! * @brief Converts the mutable set to an immutable set. */ - (void)makeImmutable; @end +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# undef ObjectType +#endif Index: src/OFOptionsParser.h ================================================================== --- src/OFOptionsParser.h +++ src/OFOptionsParser.h @@ -23,11 +23,11 @@ * @brief A class for parsing the program options specified on the command line. */ @interface OFOptionsParser: OFObject { of_unichar_t *_options; - OFArray *_arguments; + OFArray OF_GENERIC(OFString*) *_arguments; size_t _index, _subIndex; of_unichar_t _lastOption; OFString *_argument; bool _done; } @@ -87,7 +87,7 @@ /*! * @brief Returns the arguments following the last option. * * @return The arguments following the last option */ -- (OFArray*)remainingArguments; +- (OFArray OF_GENERIC(OFString*)*)remainingArguments; @end Index: src/OFProcess.h ================================================================== --- src/OFProcess.h +++ src/OFProcess.h @@ -28,12 +28,12 @@ #ifdef _WIN32 # include #endif -@class OFArray; -@class OFDictionary; +@class OFArray OF_GENERIC(ObjectType); +@class OFDictionary OF_GENERIC(KeyType, ObjectType); /*! * @class OFProcess OFProcess.h ObjFW/OFProcess.h * * @brief A class for stream-like communication with a newly created process. @@ -68,11 +68,11 @@ * search path specified in PATH is used. * @param arguments The arguments to pass to the program, or nil * @return A new, autoreleased OFProcess. */ + (instancetype)processWithProgram: (OFString*)program - arguments: (OFArray*)arguments; + arguments: (OFArray OF_GENERIC(OFString*)*)arguments; /*! * @brief Creates a new OFProcess with the specified program, program name and * arguments and invokes the program. * @@ -83,11 +83,11 @@ * @param arguments The arguments to pass to the program, or nil * @return A new, autoreleased OFProcess. */ + (instancetype)processWithProgram: (OFString*)program programName: (OFString*)programName - arguments: (OFArray*)arguments; + arguments: (OFArray OF_GENERIC(OFString*)*)arguments; /*! * @brief Creates a new OFProcess with the specified program, program name, * arguments and environment and invokes the program. * @@ -103,12 +103,13 @@ * first, copy it, modify it and then pass it. * @return A new, autoreleased OFProcess. */ + (instancetype)processWithProgram: (OFString*)program programName: (OFString*)programName - arguments: (OFArray*)arguments - environment: (OFDictionary*)environment; + arguments: (OFArray OF_GENERIC(OFString*)*)arguments + environment: (OFDictionary OF_GENERIC(OFString*, + OFString*)*)environment; /*! * @brief Initializes an already allocated OFProcess with the specified program * and invokes the program. * @@ -126,11 +127,11 @@ * search path specified in PATH is used. * @param arguments The arguments to pass to the program, or nil * @return An initialized OFProcess. */ - initWithProgram: (OFString*)program - arguments: (OFArray*)arguments; + arguments: (OFArray OF_GENERIC(OFString*)*)arguments; /*! * @brief Initializes an already allocated OFProcess with the specified program, * program name and arguments and invokes the program. * @@ -141,11 +142,11 @@ * @param arguments The arguments to pass to the program, or nil * @return An initialized OFProcess. */ - initWithProgram: (OFString*)program programName: (OFString*)programName - arguments: (OFArray*)arguments; + arguments: (OFArray OF_GENERIC(OFString*)*)arguments; /*! * @brief Initializes an already allocated OFProcess with the specified program, * program name, arguments and environment and invokes the program. * @@ -161,12 +162,12 @@ * first, copy it, modify it and then pass it. * @return An initialized OFProcess. */ - initWithProgram: (OFString*)program programName: (OFString*)programName - arguments: (OFArray*)arguments - environment: (OFDictionary*)environment; + arguments: (OFArray OF_GENERIC(OFString*)*)arguments + environment: (OFDictionary OF_GENERIC(OFString*, OFString*)*)environment; /*! * @brief Closes the write direction of the process. * * This method needs to be called for some programs before data can be read, Index: src/OFRunLoop.h ================================================================== --- src/OFRunLoop.h +++ src/OFRunLoop.h @@ -17,19 +17,19 @@ #import "OFObject.h" #ifdef OF_HAVE_SOCKETS # import "OFTCPSocket.h" #endif -@class OFSortedList; +@class OFSortedList OF_GENERIC(ObjectType); #ifdef OF_HAVE_THREADS @class OFMutex; @class OFCondition; #endif #ifdef OF_HAVE_SOCKETS @class OFKernelEventObserver; #endif -@class OFMutableDictionary; +@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFTimer; /*! * @class OFRunLoop OFRunLoop.h ObjFW/OFRunLoop.h * Index: src/OFSet.h ================================================================== --- src/OFSet.h +++ src/OFSet.h @@ -27,11 +27,11 @@ #import "OFCollection.h" #import "OFSerialization.h" /*! @file */ -@class OFArray; +@class OFArray OF_GENERIC(ObjectType); #ifdef OF_HAVE_BLOCKS /*! * @brief A block for enumerating an OFSet. * @@ -56,12 +56,19 @@ * @brief An abstract class for an unordered set of unique objects. * * @warning Do not mutate objects that are in a set! Changing the hash of * objects in a set breaks the internal representation of the set! */ -@interface OFSet: OFObject +#ifdef OF_HAVE_GENERICS +@interface OFSet : +#else +# ifndef DOXYGEN +# define ObjectType id +# endif +@interface OFSet: +#endif + OFObject /*! * @brief Creates a new set. * * @return A new, autoreleased set */ @@ -71,70 +78,70 @@ * @brief Creates a new set with the specified set. * * @param set The set to initialize the set with * @return A new, autoreleased set with the specified set */ -+ (instancetype)setWithSet: (OFSet*)set; ++ (instancetype)setWithSet: (OFSet OF_GENERIC(ObjectType)*)set; /*! * @brief Creates a new set with the specified array. * * @param array The array to initialize the set with * @return A new, autoreleased set with the specified array */ -+ (instancetype)setWithArray: (OFArray*)array; ++ (instancetype)setWithArray: (OFArray OF_GENERIC(ObjectType)*)array; /*! * @brief Creates a new set with the specified objects. * * @param firstObject The first object for the set * @return A new, autoreleased set with the specified objects */ -+ (instancetype)setWithObjects: (id)firstObject, ...; ++ (instancetype)setWithObjects: (ObjectType)firstObject, ...; /*! * @brief Creates a new set with the specified objects. * * @param objects An array of objects for the set * @param count The number of objects in the specified array * @return A new, autoreleased set with the specified objects */ -+ (instancetype)setWithObjects: (id const*)objects ++ (instancetype)setWithObjects: (ObjectType const*)objects count: (size_t)count; /*! * @brief Initializes an already allocated set with the specified set. * * @param set The set to initialize the set with * @return An initialized set with the specified set */ -- initWithSet: (OFSet*)set; +- initWithSet: (OFSet OF_GENERIC(ObjectType)*)set; /*! * @brief Initializes an already allocated set with the specified array. * * @param array The array to initialize the set with * @return An initialized set with the specified array */ -- initWithArray: (OFArray*)array; +- initWithArray: (OFArray OF_GENERIC(ObjectType)*)array; /*! * @brief Initializes an already allocated set with the specified objects. * * @param firstObject The first object for the set * @return An initialized set with the specified objects */ -- initWithObjects: (id)firstObject, ...; +- initWithObjects: (ObjectType)firstObject, ...; /*! * @brief Initializes an already allocated set with the specified objects. * * @param objects An array of objects for the set * @param count The number of objects in the specified array * @return An initialized set with the specified objects */ -- initWithObjects: (id const*)objects +- initWithObjects: (ObjectType const*)objects count: (size_t)count; /*! * @brief Initializes an already allocated set with the specified object and * va_list. @@ -141,66 +148,85 @@ * * @param firstObject The first object for the set * @param arguments A va_list with the other objects * @return An initialized set with the specified object and va_list */ -- initWithObject: (id)firstObject +- initWithObject: (ObjectType)firstObject arguments: (va_list)arguments; /*! * @brief Returns whether the receiver is a subset of the specified set. * * @return Whether the receiver is a subset of the specified set */ -- (bool)isSubsetOfSet: (OFSet*)set; +- (bool)isSubsetOfSet: (OFSet OF_GENERIC(ObjectType)*)set; /*! * @brief Returns whether the receiver and the specified set have at least one * object in common. * * @return Whether the receiver and the specified set have at least one object * in common */ -- (bool)intersectsSet: (OFSet*)set; +- (bool)intersectsSet: (OFSet OF_GENERIC(ObjectType)*)set; /*! * @brief Creates a new set which contains the objects which are in the * receiver, but not in the specified set. * * @param set The set whose objects will not be in the new set */ -- (OFSet*)setBySubtractingSet: (OFSet*)set; +- (OFSet OF_GENERIC(ObjectType)*)setBySubtractingSet: + (OFSet OF_GENERIC(ObjectType)*)set; /*! * @brief Creates a new set by creating the intersection of the receiver and * the specified set. * * @param set The set to intersect with */ -- (OFSet*)setByIntersectingWithSet: (OFSet*)set; +- (OFSet OF_GENERIC(ObjectType)*)setByIntersectingWithSet: + (OFSet OF_GENERIC(ObjectType)*)set; /*! * @brief Creates a new set by creating the union of the receiver and the * specified set. * * @param set The set to create the union with */ -- (OFSet*)setByAddingSet: (OFSet*)set; +- (OFSet OF_GENERIC(ObjectType)*)setByAddingSet: + (OFSet OF_GENERIC(ObjectType)*)set; /*! * @brief Returns an array of all objects in the set. * * @return An array of all objects in the set */ -- (OFArray*)allObjects; +- (OFArray OF_GENERIC(ObjectType)*)allObjects; /*! * @brief Returns an arbitrary object in the set. * * @return An arbitrary object in the set */ -- (id)anyObject; +- (ObjectType)anyObject; + +/*! + * @brief Checks whether the set contains an object equal to the specified + * object. + * + * @param object The object which is checked for being in the set + * @return A boolean whether the set contains the specified object + */ +- (bool)containsObject: (ObjectType)object; + +/*! + * @brief Returns an OFEnumerator to enumerate through all objects of the set. + * + * @returns An OFEnumerator to enumerate through all objects of the set + */ +- (OFEnumerator OF_GENERIC(ObjectType)*)objectEnumerator; #ifdef OF_HAVE_BLOCKS /*! * @brief Executes a block for each object in the set. * @@ -213,10 +239,14 @@ * returns true. * * @param block A block which determines if the object should be in the new set * @return A new, autoreleased OFSet */ -- (OFSet*)filteredSetUsingBlock: (of_set_filter_block_t)block; +- (OFSet OF_GENERIC(ObjectType)*)filteredSetUsingBlock: + (of_set_filter_block_t)block; #endif @end +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# undef ObjectType +#endif #import "OFMutableSet.h" Index: src/OFSettings.h ================================================================== --- src/OFSettings.h +++ src/OFSettings.h @@ -15,11 +15,11 @@ */ #import "OFObject.h" @class OFString; -@class OFArray; +@class OFArray OF_GENERIC(ObjectType); /*! * @class OFSettings OFSettings.h ObjFW/OFSettings.h * * Paths are delimited by dots, for example `category.subcategory.key`. @@ -117,11 +117,11 @@ * @brief Sets the specified path to the specified array of strings. * * @param array The array of strings to set * @param path The path to store the array of strings at */ -- (void)setArray: (OFArray*)array +- (void)setArray: (OFArray OF_GENERIC(OFString*)*)array forPath: (OFString*)path; /*! * @brief Returns the string for the specified path, or nil if the path does * not exist. @@ -191,11 +191,11 @@ * array if the path does not exist. * * @param path The path for which the array of strings should be returned * @return The array of strings of the specified path */ -- (OFArray*)arrayForPath: (OFString*)path; +- (OFArray OF_GENERIC(OFString*)*)arrayForPath: (OFString*)path; /*! * @brief Removes the value for the specified path. * * @param path The path for which the value should be removed Index: src/OFSortedList.h ================================================================== --- src/OFSortedList.h +++ src/OFSortedList.h @@ -22,14 +22,24 @@ * @brief A class which provides easy to use sorted double-linked lists. * * @warning Because the list is sorted, all methods inserting an object at a * specific place are unavailable, even though they exist in OFList! */ +#ifdef OF_HAVE_GENERICS +@interface OFSortedList : OFList +#else +# ifndef DOXYGEN +# define ObjectType id +# endif @interface OFSortedList: OFList +#endif /*! * @brief Inserts the object to the list while keeping the list sorted. * * @param object The object to insert * @return The list object for the object just added */ -- (of_list_object_t*)insertObject: (id )object; +- (of_list_object_t*)insertObject: (ObjectType )object; @end +#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) +# undef ObjectType +#endif Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -76,11 +76,11 @@ * enumeration */ typedef void (^of_string_line_enumeration_block_t)(OFString *line, bool *stop); #endif -@class OFArray; +@class OFArray OF_GENERIC(ObjectType); @class OFURL; /*! * @class OFString OFString.h ObjFW/OFString.h * @@ -324,11 +324,11 @@ * @brief Creates a path from the specified path components. * * @param components An array of components for the path * @return A new autoreleased OFString */ -+ (OFString*)pathWithComponents: (OFArray*)components; ++ (OFString*)pathWithComponents: (OFArray OF_GENERIC(OFString*)*)components; /*! * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string. * @@ -881,11 +881,12 @@ * @brief Separates an OFString into an OFArray of OFStrings. * * @param delimiter The delimiter for separating * @return An autoreleased OFArray with the separated string */ -- (OFArray*)componentsSeparatedByString: (OFString*)delimiter; +- (OFArray OF_GENERIC(OFString*)*)componentsSeparatedByString: + (OFString*)delimiter; /*! * @brief Separates an OFString into an OFArray of OFStrings. * * @param delimiter The delimiter for separating @@ -894,19 +895,20 @@ * Value | Description * -----------------------|---------------------- * `OF_STRING_SKIP_EMPTY` | Skip empty components * @return An autoreleased OFArray with the separated string */ -- (OFArray*)componentsSeparatedByString: (OFString*)delimiter - options: (int)options; +- (OFArray OF_GENERIC(OFString*)*) + componentsSeparatedByString: (OFString*)delimiter + options: (int)options; /*! * @brief Returns the components of the path. * * @return The components of the path */ -- (OFArray*)pathComponents; +- (OFArray OF_GENERIC(OFString*)*)pathComponents; /*! * @brief Returns the last component of the path. * * @return The last component of the path Index: src/OFTLSSocket.h ================================================================== --- src/OFTLSSocket.h +++ src/OFTLSSocket.h @@ -15,11 +15,11 @@ */ #import "objfw-defs.h" @class OFString; -@class OFDictionary; +@class OFDictionary OF_GENERIC(KeyType, ObjectType); @protocol OFTLSSocket; /*! * @protocol OFTLSSocketDelegate OFTLSSocket.h ObjFW/OFTLSSocket.h * Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -22,11 +22,11 @@ /*! @file */ @class OFDate; @class OFRunLoop; -@class OFMutableDictionary; +@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); #if defined(OF_HAVE_THREADS) && defined(OF_HAVE_BLOCKS) /*! * @brief A block to be executed in a new thread. * Index: src/OFThreadPool.h ================================================================== --- src/OFThreadPool.h +++ src/OFThreadPool.h @@ -23,12 +23,14 @@ * @brief A block for a job which should be executed in a thread pool. */ typedef void (^of_thread_pool_block_t)(void); #endif -@class OFMutableArray; -@class OFList; +#ifndef DOXYGEN +@class OFMutableArray OF_GENERIC(ObjectType); +@class OFList OF_GENERIC(ObjectType); +#endif @class OFCondition; @class OFThreadPoolJob; /*! * @class OFThreadPool OFThreadPool.h ObjFW/OFThreadPool.h Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -15,14 +15,16 @@ */ #import "OFXMLNode.h" @class OFString; -@class OFArray; @class OFMutableString; -@class OFMutableArray; -@class OFMutableDictionary; +#ifndef DOXYGEN +@class OFArray OF_GENERIC(ObjectType); +@class OFMutableArray OF_GENERIC(ObjectType); +@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); +#endif @class OFXMLAttribute; /*! * @class OFXMLElement OFXMLElement.h ObjFW/OFXMLElement.h * @@ -29,13 +31,13 @@ * @brief A class which stores an XML element. */ @interface OFXMLElement: OFXMLNode { OFString *_name, *_namespace, *_defaultNamespace; - OFMutableArray *_attributes; - OFMutableDictionary *_namespaces; - OFMutableArray *_children; + OFMutableArray OF_GENERIC(OFXMLAttribute*) *_attributes; + OFMutableDictionary OF_GENERIC(OFString*, OFString*) *_namespaces; + OFMutableArray OF_GENERIC(OFXMLNode*) *_children; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFString *name; # ifdef __cplusplus @@ -42,12 +44,12 @@ @property (copy, getter=namespace, setter=setNamespace:) OFString *namespace_; # else @property (copy) OFString *namespace; # endif @property (copy) OFString *defaultNamespace; -@property (readonly, copy) OFArray *attributes; -@property (copy) OFArray *children; +@property (readonly, copy) OFArray OF_GENERIC(OFXMLAttribute*) *attributes; +@property (copy) OFArray OF_GENERIC(OFXMLNode*) *children; #endif /*! * @brief Creates a new XML element with the specified name. * @@ -227,25 +229,25 @@ /*! * @brief Returns an OFArray with the attributes of the element. * * @return An OFArray with the attributes of the element */ -- (OFArray*)attributes; +- (OFArray OF_GENERIC(OFXMLAttribute*)*)attributes; /*! * @brief Removes all children and adds the children from the specified array. * * @param children The new children to add */ -- (void)setChildren: (OFArray*)children; +- (void)setChildren: (OFArray OF_GENERIC(OFXMLNode*)*)children; /*! * @brief Returns an array of OFXMLNodes with all children of the element. * * @return An array of OFXMLNodes with all children of the element */ -- (OFArray*)children; +- (OFArray OF_GENERIC(OFXMLNode*)*)children; /*! * @brief Adds the specified attribute. * * If an attribute with the same name and namespace already exists, it is not @@ -362,11 +364,11 @@ * @brief Inserts the specified children at the specified index. * * @param children An array of OFXMLNodes which are added as children * @param index The index where the child is added */ -- (void)insertChildren: (OFArray*)children +- (void)insertChildren: (OFArray OF_GENERIC(OFXMLNode*)*)children atIndex: (size_t)index; /*! * @brief Removes the first child that is equal to the specified OFXMLNode. * @@ -403,18 +405,19 @@ /*! * @brief Returns all children that are elements. * * @return All children that are elements */ -- (OFArray*)elements; +- (OFArray OF_GENERIC(OFXMLElement*)*)elements; /*! * @brief Returns all children that have the specified namespace. * * @return All children that have the specified namespace */ -- (OFArray*)elementsForNamespace: (OFString*)elementNS; +- (OFArray OF_GENERIC(OFXMLElement*)*)elementsForNamespace: + (OFString*)elementNS; /*! * @brief Returns the first child element with the specified name. * * @param elementName The name of the element @@ -426,11 +429,11 @@ * @brief Returns the child elements with the specified name. * * @param elementName The name of the elements * @return The child elements with the specified name */ -- (OFArray*)elementsForName: (OFString*)elementName; +- (OFArray OF_GENERIC(OFXMLElement*)*)elementsForName: (OFString*)elementName; /*! * @brief Returns the first child element with the specified name and namespace. * * @param elementName The name of the element @@ -445,10 +448,10 @@ * * @param elementName The name of the elements * @param elementNS The namespace of the elements * @return The child elements with the specified name and namespace */ -- (OFArray*)elementsForName: (OFString*)elementName - namespace: (OFString*)elementNS; +- (OFArray OF_GENERIC(OFXMLElement*)*)elementsForName: (OFString*)elementName + namespace: (OFString*)elementNS; @end #import "OFXMLElement+Serialization.h" Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -418,11 +418,11 @@ } - (OFString*)stringValue { OFMutableString *ret; - OFXMLElement *const *objects; + OFXMLNode *const *objects; size_t i, count = [_children count]; if (count == 0) return @""; @@ -590,11 +590,11 @@ objc_autoreleasePoolPop(pool2); } /* Childen */ if (_children != nil) { - OFXMLElement *const *childrenObjects = [_children objects]; + OFXMLNode *const *childrenObjects = [_children objects]; size_t childrenCount = [_children count]; OFDataArray *tmp = [OFDataArray dataArray]; bool indent; if (indentation > 0) { @@ -618,11 +618,11 @@ if (ind) [tmp addItem: "\n"]; if ([childrenObjects[j] isKindOfClass: [OFXMLElement class]]) - child = [childrenObjects[j] + child = [(OFXMLElement*)childrenObjects[j] OF_XMLStringWithParent: self namespaces: allNamespaces indentation: ind level: level + 1]; else @@ -1008,76 +1008,88 @@ namespace: elementNS] firstObject]; } - (OFArray*)elements { - OFMutableArray *ret = [OFMutableArray array]; - OFXMLElement *const *objects = [_children objects]; + OFMutableArray OF_GENERIC(OFXMLElement*) *ret = [OFMutableArray array]; + OFXMLNode *const *objects = [_children objects]; size_t i, count = [_children count]; for (i = 0; i < count; i++) if ([objects[i] isKindOfClass: [OFXMLElement class]]) - [ret addObject: objects[i]]; + [ret addObject: (OFXMLElement*)objects[i]]; [ret makeImmutable]; return ret; } - (OFArray*)elementsForName: (OFString*)elementName { - OFMutableArray *ret = [OFMutableArray array]; - OFXMLElement *const *objects = [_children objects]; + OFMutableArray OF_GENERIC(OFXMLElement*) *ret = [OFMutableArray array]; + OFXMLNode *const *objects = [_children objects]; size_t i, count = [_children count]; - for (i = 0; i < count; i++) - if ([objects[i] isKindOfClass: [OFXMLElement class]] && - objects[i]->_namespace == nil && - [objects[i]->_name isEqual: elementName]) - [ret addObject: objects[i]]; + for (i = 0; i < count; i++) { + if ([objects[i] isKindOfClass: [OFXMLElement class]]) { + OFXMLElement *element = (OFXMLElement*)objects[i]; + + if (element->_namespace == nil && + [element->_name isEqual: elementName]) + [ret addObject: element]; + } + } [ret makeImmutable]; return ret; } - (OFArray*)elementsForNamespace: (OFString*)elementNS { - OFMutableArray *ret = [OFMutableArray array]; - OFXMLElement *const *objects = [_children objects]; + OFMutableArray OF_GENERIC(OFXMLElement*) *ret = [OFMutableArray array]; + OFXMLNode *const *objects = [_children objects]; size_t i, count = [_children count]; - for (i = 0; i < count; i++) - if ([objects[i] isKindOfClass: [OFXMLElement class]] && - objects[i]->_name != nil && - [objects[i]->_namespace isEqual: elementNS]) - [ret addObject: objects[i]]; + for (i = 0; i < count; i++) { + if ([objects[i] isKindOfClass: [OFXMLElement class]]) { + OFXMLElement *element = (OFXMLElement*)objects[i]; + + if (element->_name != nil && + [element->_namespace isEqual: elementNS]) + [ret addObject: element]; + } + } [ret makeImmutable]; return ret; } - (OFArray*)elementsForName: (OFString*)elementName namespace: (OFString*)elementNS { - OFMutableArray *ret; - OFXMLElement *const *objects; + OFMutableArray OF_GENERIC(OFXMLElement*) *ret; + OFXMLNode *const *objects; size_t i, count; if (elementNS == nil) return [self elementsForName: elementName]; ret = [OFMutableArray array]; objects = [_children objects]; count = [_children count]; - for (i = 0; i < count; i++) - if ([objects[i] isKindOfClass: [OFXMLElement class]] && - [objects[i]->_namespace isEqual: elementNS] && - [objects[i]->_name isEqual: elementName]) - [ret addObject: objects[i]]; + for (i = 0; i < count; i++) { + if ([objects[i] isKindOfClass: [OFXMLElement class]]) { + OFXMLElement *element = (OFXMLElement*)objects[i]; + + if ([element->_namespace isEqual: elementNS] && + [element->_name isEqual: elementName]) + [ret addObject: element]; + } + } [ret makeImmutable]; return ret; } Index: src/OFXMLElementBuilder.h ================================================================== --- src/OFXMLElementBuilder.h +++ src/OFXMLElementBuilder.h @@ -15,11 +15,11 @@ */ #import "OFObject.h" #import "OFXMLParser.h" -@class OFMutableArray; +@class OFMutableArray OF_GENERIC(ObjectType); @class OFXMLElement; @class OFXMLElementBuilder; /*! * @protocol OFXMLElementBuilderDelegate @@ -104,11 +104,11 @@ * first parsing stuff using the OFXMLParser with another delegate and then * setting the OFXMLElementBuilder as delegate for the parser. */ @interface OFXMLElementBuilder: OFObject { - OFMutableArray *_stack; + OFMutableArray OF_GENERIC(OFXMLElement*) *_stack; id _delegate; } #ifdef OF_HAVE_PROPERTIES @property (assign) id delegate; Index: src/OFXMLParser.h ================================================================== --- src/OFXMLParser.h +++ src/OFXMLParser.h @@ -17,12 +17,15 @@ #import "OFObject.h" #import "OFString.h" #import "OFXMLAttribute.h" @class OFXMLParser; -@class OFArray; -@class OFMutableArray; +#ifndef DOXYGEN +@class OFArray OF_GENERIC(ObjectType); +@class OFMutableArray OF_GENERIC(ObjectType); +@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); +#endif @class OFDataArray; @class OFStream; /*! * @protocol OFXMLParserDelegate OFXMLParser.h ObjFW/OFXMLParser.h @@ -56,11 +59,11 @@ */ - (void)parser: (OFXMLParser*)parser didStartElement: (OFString*)name prefix: (OFString*)prefix namespace: (OFString*)ns - attributes: (OFArray*)attributes; + attributes: (OFArray OF_GENERIC(OFXMLAttribute*)*)attributes; /*! * @brief This callback is called when the XML parser found the end of a tag. * * @param parser The parser which found the end of a tag @@ -155,14 +158,17 @@ } _state; size_t _i, _last; const char *_data; OFDataArray *_buffer; OFString *_name, *_prefix; - OFMutableArray *_namespaces, *_attributes; + OFMutableArray + OF_GENERIC(OFMutableDictionary OF_GENERIC(OFString*, OFString*)*) + *_namespaces; + OFMutableArray OF_GENERIC(OFXMLAttribute*) *_attributes; OFString *_attributeName, *_attributePrefix; char _delimiter; - OFMutableArray *_previous; + OFMutableArray OF_GENERIC(OFString*) *_previous; size_t _level; bool _acceptProlog; size_t _lineNumber; bool _lastCarriageReturn, _finishedParsing; of_string_encoding_t _encoding; Index: src/OFZIPArchive.h ================================================================== --- src/OFZIPArchive.h +++ src/OFZIPArchive.h @@ -14,14 +14,17 @@ * file. */ #import "OFObject.h" #import "OFString.h" +#import "OFZIPArchiveEntry.h" -@class OFArray; -@class OFMutableArray; -@class OFMutableDictionary; +#ifndef DOXYGEN +@class OFArray OF_GENERIC(ObjectType); +@class OFMutableArray OF_GENERIC(ObjectType); +@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); +#endif @class OFSeekableStream; @class OFStream; /*! * @class OFZIPArchive OFZIPArchive.h ObjFW/OFZIPArchive.h @@ -33,18 +36,19 @@ OFSeekableStream *_stream; uint32_t _diskNumber, _centralDirectoryDisk; uint64_t _centralDirectoryEntriesInDisk, _centralDirectoryEntries; uint64_t _centralDirectorySize, _centralDirectoryOffset; OFString *_archiveComment; - OFMutableArray *_entries; - OFMutableDictionary *_pathToEntryMap; + OFMutableArray OF_GENERIC(OFZIPArchiveEntry*) *_entries; + OFMutableDictionary OF_GENERIC(OFString*, OFZIPArchiveEntry*) + *_pathToEntryMap; OFStream *_lastReturnedStream; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy) OFString *archiveComment; -@property (readonly, copy) OFArray *entries; +@property (readonly, copy) OFArray OF_GENERIC(OFZIPArchiveEntry*) *entries; #endif /*! * @brief Creates a new OFZIPArchive object with the specified seekable stream. * @@ -87,11 +91,11 @@ * directory, which does not need to be the order in which the actual files are * stored. * * @return The entries of the central directory of the archive as an array */ -- (OFArray*)entries; +- (OFArray OF_GENERIC(OFZIPArchiveEntry*)*)entries; /*! * @brief Returns the archive comment. * * @return The archive comment Index: src/exceptions/OFException.h ================================================================== --- src/exceptions/OFException.h +++ src/exceptions/OFException.h @@ -15,12 +15,14 @@ */ #import "OFObject.h" @class OFString; -@class OFArray; -@class OFMutableArray; +#ifndef DOXYGEN +@class OFArray OF_GENERIC(ObjectType); +@class OFMutableArray OF_GENERIC(ObjectType); +#endif #define OF_BACKTRACE_SIZE 32 #if defined(_WIN32) && defined(OF_HAVE_SOCKETS) # ifndef EADDRINUSE Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -126,18 +126,10 @@ #ifndef __has_attribute # define __has_attribute(x) 0 #endif -#if !__has_feature(objc_instancetype) -# define instancetype id -#endif - -#if __has_feature(blocks) -# define OF_HAVE_BLOCKS -#endif - #if __has_feature(objc_bool) # undef YES # define YES __objc_yes # undef NO # define NO __objc_no @@ -146,10 +138,43 @@ # define true ((bool)1) # undef false # define false ((bool)0) # endif #endif + +#if !__has_feature(objc_instancetype) +# define instancetype id +#endif + +#if __has_feature(blocks) +# define OF_HAVE_BLOCKS +#endif + +#if __has_feature(objc_arc) +# define OF_RETURNS_RETAINED __attribute__((__ns_returns_retained__)) +# define OF_RETURNS_NOT_RETAINED __attribute__((__ns_returns_not_retained__)) +# define OF_RETURNS_INNER_POINTER \ + __attribute__((__objc_returns_inner_pointer__)) +# define OF_CONSUMED __attribute__((__ns_consumed__)) +# define OF_WEAK_UNAVAILABLE __attribute__((__objc_arc_weak_unavailable__)) +#else +# define OF_RETURNS_RETAINED +# define OF_RETURNS_NOT_RETAINED +# define OF_RETURNS_INNER_POINTER +# define OF_CONSUMED +# define OF_WEAK_UNAVAILABLE +# define __unsafe_unretained +# define __bridge +# define __autoreleasing +#endif + +#if __has_feature(objc_generics) +# define OF_HAVE_GENERICS +# define OF_GENERIC(...) <__VA_ARGS__> +#else +# define OF_GENERIC(...) +#endif #if defined(__clang__) || __GCC_VERSION__ >= 405 # define OF_UNREACHABLE __builtin_unreachable(); #else # define OF_UNREACHABLE abort(); @@ -256,28 +281,10 @@ # endif # endif # endif #endif -#if __has_feature(objc_arc) -# define OF_RETURNS_RETAINED __attribute__((__ns_returns_retained__)) -# define OF_RETURNS_NOT_RETAINED __attribute__((__ns_returns_not_retained__)) -# define OF_RETURNS_INNER_POINTER \ - __attribute__((__objc_returns_inner_pointer__)) -# define OF_CONSUMED __attribute__((__ns_consumed__)) -# define OF_WEAK_UNAVAILABLE __attribute__((__objc_arc_weak_unavailable__)) -#else -# define OF_RETURNS_RETAINED -# define OF_RETURNS_NOT_RETAINED -# define OF_RETURNS_INNER_POINTER -# define OF_CONSUMED -# define OF_WEAK_UNAVAILABLE -# define __unsafe_unretained -# define __bridge -# define __autoreleasing -#endif - #define OF_RETAIN_COUNT_MAX UINT_MAX #define OF_NOT_FOUND SIZE_MAX #if !defined(_WIN32) && !defined(__DJGPP__) # define OF_PATH_DELIMITER '/'