ObjFW
OFEnumerator.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
21 @class OFArray OF_GENERIC(ObjectType);
22 @class OFEnumerator OF_GENERIC(ObjectType);
23 
29 @protocol OFEnumerating
37 @end
38 
44 @interface OFEnumerator OF_GENERIC(ObjectType): OFObject
45 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
46 # define ObjectType id
47 #endif
48 
53 - (nullable ObjectType)nextObject;
54 
60 - (OFArray OF_GENERIC(ObjectType) *)allObjects;
61 
66 - (void)reset;
67 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
68 # undef ObjectType
69 #endif
70 @end
71 
72 /*
73  * This needs to be exactly like this because it's hard-coded in the compiler.
74  *
75  * We need this bad check to see if we already imported Cocoa, which defines
76  * this as well.
77  */
83 #define of_fast_enumeration_state_t NSFastEnumerationState
84 #ifndef NSINTEGER_DEFINED
85 typedef struct {
87  unsigned long state;
89  id __unsafe_unretained _Nullable *_Nullable itemsPtr;
91  unsigned long *_Nullable mutationsPtr;
93  unsigned long extra[5];
95 #endif
96 
116 - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state
117  objects: (id __unsafe_unretained _Nonnull *_Nonnull)
118  objects
119  count: (int)count;
120 @end
121 
122 OF_ASSUME_NONNULL_END
void reset()
Resets the enumerator, so the next call to nextObject returns the first object again.
Definition: OFEnumerator.m:61
nullable ObjectType nextObject()
Returns the next object or nil if there is none left.
Definition: OFEnumerator.m:40
id __unsafe_unretained _Nullable *_Nullable itemsPtr
Pointer to a C array of objects to return.
Definition: OFEnumerator.h:89
A protocol for getting an enumerator for the object.
Definition: OFEnumerator.h:29
A class which provides methods to enumerate through collections.
Definition: OFEnumerator.h:44
unsigned long state
Arbitrary state information for the enumeration.
Definition: OFEnumerator.h:87
unsigned long *_Nullable mutationsPtr
Arbitrary state information to detect mutations.
Definition: OFEnumerator.h:91
OFEnumerator * objectEnumerator()
Returns an OFEnumerator to enumerate through all objects of the collection.
OFArray * allObjects()
Returns an array of all remaining objects in the collection.
Definition: OFEnumerator.m:45
A protocol for fast enumeration.
Definition: OFEnumerator.h:105
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
State information for fast enumerations.
Definition: OFEnumerator.h:85
An abstract class for storing objects in an array.
Definition: OFArray.h:89