ObjFW
OFEnumerator.h
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 
18 OF_ASSUME_NONNULL_BEGIN
19 
20 @class OFArray OF_GENERIC(ObjectType);
21 @class OFEnumerator OF_GENERIC(ObjectType);
22 
28 @protocol OFEnumerating
36 @end
37 
38 /*
39  * This needs to be exactly like this because it's hard-coded in the compiler.
40  *
41  * We need this bad check to see if we already imported Cocoa, which defines
42  * this as well.
43  */
49 #define of_fast_enumeration_state_t NSFastEnumerationState
50 #ifndef NSINTEGER_DEFINED
51 typedef struct {
53  unsigned long state;
55  id __unsafe_unretained _Nullable *_Nullable itemsPtr;
57  unsigned long *_Nullable mutationsPtr;
59  unsigned long extra[5];
61 #endif
62 
82 - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state
83  objects: (id __unsafe_unretained _Nonnull *_Nonnull)
84  objects
85  count: (int)count;
86 @end
87 
93 @interface OFEnumerator OF_GENERIC(ObjectType): OFObject <OFFastEnumeration>
94 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
95 # define ObjectType id
96 #endif
97 {
98  OF_RESERVE_IVARS(OFEnumerator, 4)
99 }
100 
106 - (nullable ObjectType)nextObject;
107 
113 - (OFArray OF_GENERIC(ObjectType) *)allObjects;
114 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
115 # undef ObjectType
116 #endif
117 @end
118 
119 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:92
A class which provides methods to enumerate through collections.
Definition: OFEnumerator.h:101
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A protocol for getting an enumerator for the object.
Definition: OFEnumerator.h:28
OFEnumerator * objectEnumerator()
Returns an OFEnumerator to enumerate through all objects of the collection.
A protocol for fast enumeration.
Definition: OFEnumerator.h:71
State information for fast enumerations.
Definition: OFEnumerator.h:51
unsigned long state
Definition: OFEnumerator.h:53