@@ -33,14 +33,29 @@ /** @file */ @class OFString; -enum { - OF_ARRAY_SKIP_EMPTY = 1, - OF_ARRAY_SORT_DESCENDING = 2 -}; +/** + * @brief Options for joining the objects of an array. + * + * This is a bit mask. + */ +typedef enum { + /** Skip empty components */ + OFArraySkipEmptyComponents = 1 +} OFArrayJoinOptions; + +/** + * @brief Options for sorting an array. + * + * This is a bit mask. + */ +typedef enum { + /** Sort the array descending */ + OFArraySortDescending = 1 +} OFArraySortOptions; #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating an OFArray. * @@ -47,39 +62,38 @@ * @param object The current object * @param index The index of the current object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ -typedef void (^of_array_enumeration_block_t)(id object, size_t index, - bool *stop); +typedef void (^OFArrayEnumerationBlock)(id object, size_t index, bool *stop); /** * @brief A block for filtering an OFArray. * * @param object The object to inspect * @param index The index of the object to inspect * @return Whether the object should be in the filtered array */ -typedef bool (^of_array_filter_block_t)(id object, size_t index); +typedef bool (^OFArrayFilterBlock)(id object, size_t index); /** * @brief A block for mapping objects to objects in an OFArray. * * @param object The object to map * @param index The index of the object to map * @return The object to map to */ -typedef id _Nonnull (^of_array_map_block_t)(id object, size_t index); +typedef id _Nonnull (^OFArrayMapBlock)(id object, size_t index); /** * @brief A block for folding an OFArray. * * @param left The object to which the object has been folded so far * @param right The object that should be added to the left object * @return The left and right side folded into one object */ -typedef id _Nullable (^of_array_fold_block_t)(id _Nullable left, id right); +typedef id _Nullable (^OFArrayFoldBlock)(id _Nullable left, id right); #endif /** * @class OFArray OFArray.h ObjFW/OFArray.h * @@ -215,10 +229,17 @@ * @return An initialized OFArray */ - (instancetype)initWithObjects: (ObjectType const _Nonnull *_Nonnull)objects count: (size_t)count; +/** + * @brief Returns an OFEnumerator to enumerate through all objects of the array. + * + * @return An OFEnumerator to enumerate through all objects of the array + */ +- (OFEnumerator OF_GENERIC(ObjectType) *)objectEnumerator; + /** * @brief Returns the object at the specified index in the array. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! @@ -252,39 +273,38 @@ * @note A @ref OFNull value is translated to nil! * * @param value The value for the specified key * @param key The key of the value to set */ -- (void)setValue: (nullable id)value - forKey: (OFString *)key; +- (void)setValue: (nullable id)value forKey: (OFString *)key; /** * @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: (ObjectType __unsafe_unretained _Nonnull *_Nonnull)buffer - inRange: (of_range_t)range; + inRange: (OFRange)range; /** * @brief Returns the index of the first object that is equivalent to the - * specified object or `OF_NOT_FOUND` if it was not found. + * specified object or `OFNotFound` 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 + * or `OFNotFound` if it was not found */ - (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. + * specified object or `OFNotFound` if it was not found. * * @param object The object whose index is returned * @return The index of the first object that has the same address as - * the specified object or `OF_NOT_FOUND` if it was not found + * the specified object or `OFNotFound` if it was not found */ - (size_t)indexOfObjectIdenticalTo: (ObjectType)object; /** * @brief Checks whether the array contains an object equal to the specified @@ -309,11 +329,11 @@ * @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 OF_GENERIC(ObjectType) *)objectsInRange: (of_range_t)range; +- (OFArray OF_GENERIC(ObjectType) *)objectsInRange: (OFRange)range; /** * @brief Creates a string by joining all objects of the array. * * @param separator The string with which the objects should be joined @@ -323,19 +343,15 @@ /** * @brief Creates a string by joining all objects of the array. * * @param separator The string with which the objects should be joined - * @param options Options according to which the objects should be joined.@n - * Possible values are: - * Value | Description - * ----------------------|---------------------- - * `OF_ARRAY_SKIP_EMPTY` | Skip empty components + * @param options Options according to which the objects should be joined * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator - options: (int)options; + options: (OFArrayJoinOptions)options; /** * @brief Creates a string by calling the selector on all objects of the array * and joining the strings returned by calling the selector. * @@ -350,20 +366,16 @@ * @brief Creates a string by calling the selector on all objects of the array * and joining the strings returned by calling the selector. * * @param separator The string with which the objects should be joined * @param selector The selector to perform on the objects - * @param options Options according to which the objects should be joined.@n - * Possible values are: - * Value | Description - * ----------------------|---------------------- - * `OF_ARRAY_SKIP_EMPTY` | Skip empty components + * @param options Options according to which the objects should be joined * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector - options: (int)options; + options: (OFArrayJoinOptions)options; /** * @brief Performs the specified selector on all objects in the array. * * @param selector The selector to perform on all objects in the array @@ -385,36 +397,29 @@ * @brief Returns a copy of the array sorted using the specified selector and * options. * * @param selector The selector to use to sort the array. It's signature * should be the same as that of -[compare:]. - * @param options The options to use when sorting the array.@n - * Possible values are: - * Value | Description - * ---------------------------|------------------------- - * `OF_ARRAY_SORT_DESCENDING` | Sort in descending order + * @param options The options to use when sorting the array * @return A sorted copy of the array */ -- (OFArray OF_GENERIC(ObjectType) *)sortedArrayUsingSelector: (SEL)selector - options: (int)options; +- (OFArray OF_GENERIC(ObjectType) *) + sortedArrayUsingSelector: (SEL)selector + options: (OFArraySortOptions)options; #ifdef OF_HAVE_BLOCKS /** * @brief Returns a copy of the array sorted using the specified selector and * options. * * @param comparator The comparator to use to sort the array - * @param options The options to use when sorting the array.@n - * Possible values are: - * Value | Description - * ---------------------------|------------------------- - * `OF_ARRAY_SORT_DESCENDING` | Sort in descending order + * @param options The options to use when sorting the array * @return A sorted copy of the array */ - (OFArray OF_GENERIC(ObjectType) *) - sortedArrayUsingComparator: (of_comparator_t)comparator - options: (int)options; + sortedArrayUsingComparator: (OFComparator)comparator + options: (OFArraySortOptions)options; #endif /** * @brief Creates a new array with the specified object added. * @@ -444,19 +449,19 @@ /** * @brief Executes a block for each object. * * @param block The block to execute for each object */ -- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block; +- (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block; /** * @brief Creates a new array, mapping each object using the specified block. * * @param block A block which maps an object for each object * @return A new, autoreleased OFArray */ -- (OFArray *)mappedArrayUsingBlock: (of_array_map_block_t)block; +- (OFArray *)mappedArrayUsingBlock: (OFArrayMapBlock)block; /** * @brief Creates a new array, only containing the objects for which the block * returns true. * @@ -463,11 +468,11 @@ * @param block A block which determines if the object should be in the new * array * @return A new, autoreleased OFArray */ - (OFArray OF_GENERIC(ObjectType) *)filteredArrayUsingBlock: - (of_array_filter_block_t)block; + (OFArrayFilterBlock)block; /** * @brief Folds the array to a single object using the specified block. * * If the array is empty, it will return `nil`. @@ -481,11 +486,11 @@ * * @param block A block which folds two objects into one, which is called for * all objects except the first * @return The array folded to a single object */ -- (nullable id)foldUsingBlock: (of_array_fold_block_t)block; +- (nullable id)foldUsingBlock: (OFArrayFoldBlock)block; #endif #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end