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
|
* this as well.
*/
/**
* @struct OFFastEnumerationState OFEnumerator.h ObjFW/OFEnumerator.h
*
* @brief State information for fast enumerations.
*/
#define OFFastEnumerationState NSFastEnumerationState
#ifndef NSINTEGER_DEFINED
typedef struct {
/** Arbitrary state information for the enumeration */
unsigned long state;
/** Pointer to a C array of objects to return */
id __unsafe_unretained _Nullable *_Nullable itemsPtr;
/** Arbitrary state information to detect mutations */
unsigned long *_Nullable mutationsPtr;
/** Additional arbitrary state information */
unsigned long extra[5];
} OFFastEnumerationState;
#endif
/**
* @protocol OFFastEnumeration OFEnumerator.h ObjFW/OFEnumerator.h
*
* @brief A protocol for fast enumeration.
*
* The OFFastEnumeration protocol needs to be implemented by all classes
* supporting fast enumeration.
*/
@protocol OFFastEnumeration
/**
* @brief A method which is called by the code produced by the compiler when
* doing a fast enumeration.
*
* @param state Context information for the enumeration
* @param objects A pointer to an array where to put the objects
* @param count The number of objects that can be stored at objects
* @return The number of objects returned in objects or 0 when the enumeration
* finished.
*/
- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state
objects: (id __unsafe_unretained _Nonnull *_Nonnull)
objects
count: (int)count;
@end
/**
* @class OFEnumerator OFEnumerator.h ObjFW/OFEnumerator.h
*
* @brief A class which provides methods to enumerate through collections.
*/
@interface OFEnumerator OF_GENERIC(ObjectType): OFObject <OFFastEnumeration>
#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
# define ObjectType id
#endif
{
OF_RESERVE_IVARS(OFEnumerator, 4)
}
/**
* @brief Returns the next object or `nil` if there is none left.
*
* @return The next object or `nil` if there is none left
*/
- (nullable ObjectType)nextObject;
/**
* @brief Returns an array of all remaining objects in the collection.
*
* @return An array of all remaining objects in the collection.
|
<
<
>
>
>
>
<
<
<
<
>
>
|
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
|
* this as well.
*/
/**
* @struct OFFastEnumerationState OFEnumerator.h ObjFW/OFEnumerator.h
*
* @brief State information for fast enumerations.
*/
typedef struct {
/** Arbitrary state information for the enumeration */
unsigned long state;
/** Pointer to a C array of objects to return */
id __unsafe_unretained _Nullable *_Nullable itemsPtr;
/** Arbitrary state information to detect mutations */
unsigned long *_Nullable mutationsPtr;
/** Additional arbitrary state information */
unsigned long extra[5];
} OFFastEnumerationState;
#ifndef NSINTEGER_DEFINED
typedef OFFastEnumerationState NSFastEnumerationState;
#endif
/**
* @protocol OFFastEnumeration OFEnumerator.h ObjFW/OFEnumerator.h
*
* @brief A protocol for fast enumeration.
*
* The OFFastEnumeration protocol needs to be implemented by all classes
* supporting fast enumeration.
*/
@protocol OFFastEnumeration
/**
* @brief A method which is called by the code produced by the compiler when
* doing a fast enumeration.
*
* @param state Context information for the enumeration
* @param objects A pointer to an array where to put the objects
* @param count The number of objects that can be stored at objects
* @return The number of objects returned in objects or 0 when the enumeration
* finished.
* @throw OFEnumerationMutationException The object was mutated during
* enumeration
*/
- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state
objects: (id __unsafe_unretained _Nonnull *_Nonnull)
objects
count: (int)count;
@end
/**
* @class OFEnumerator OFEnumerator.h ObjFW/OFEnumerator.h
*
* @brief A class which provides methods to enumerate through collections.
*/
@interface OFEnumerator OF_GENERIC(ObjectType): OFObject <OFFastEnumeration>
#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
# define ObjectType id
#endif
/**
* @brief Returns the next object or `nil` if there is none left.
*
* @return The next object or `nil` if there is none left
* @throw OFEnumerationMutationException The object was mutated during
* enumeration
*/
- (nullable ObjectType)nextObject;
/**
* @brief Returns an array of all remaining objects in the collection.
*
* @return An array of all remaining objects in the collection.
|