ObjFW
OFEnumerator.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3  * Jonathan Schleifer <js@webkeks.org>
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 #ifndef DOXYGEN
22 @class OFEnumerator OF_GENERIC(ObjectType);
23 @class OFArray OF_GENERIC(ObjectType);
24 #endif
25 
31 @protocol OFEnumerating
39 @end
40 
46 #ifdef OF_HAVE_GENERICS
47 @interface OFEnumerator <ObjectType>: OFObject
48 #else
49 # ifndef DOXYGEN
50 # define ObjectType id
51 # endif
53 #endif
54 
59 - (nullable ObjectType)nextObject;
60 
66 - (OFArray OF_GENERIC(ObjectType)*)allObjects;
67 
72 - (void)reset;
73 @end
74 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
75 # undef ObjectType
76 #endif
77 
78 /*
79  * This needs to be exactly like this because it's hardcoded in the compiler.
80  *
81  * We need this bad check to see if we already imported Cocoa, which defines
82  * this as well.
83  */
89 #define of_fast_enumeration_state_t NSFastEnumerationState
90 #ifndef NSINTEGER_DEFINED
91 typedef struct {
93  unsigned long state;
95  id __unsafe_unretained OF_NULLABLE *OF_NULLABLE itemsPtr;
97  unsigned long *OF_NULLABLE mutationsPtr;
99  unsigned long extra[5];
101 #endif
102 
122 - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
123  objects: (id __unsafe_unretained OF_NONNULL
124  *OF_NONNULL)objects
125  count: (int)count;
126 @end
127 
128 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:95
A protocol for fast enumeration.
Definition: OFEnumerator.h:111
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
unsigned long *OF_NULLABLE mutationsPtr
Arbitrary state information to detect mutations.
Definition: OFEnumerator.h:97
void reset()
Resets the enumerator, so the next call to nextObject returns the first object again.
Definition: OFEnumerator.m:61
unsigned long state
Arbitrary state information for the enumeration.
Definition: OFEnumerator.h:93
id __unsafe_unretained OF_NULLABLE *OF_NULLABLE itemsPtr
Pointer to a C array of objects to return.
Definition: OFEnumerator.h:95
OFArray OF_GENERIC(ObjectType allObjects()
Returns an array of all remaining objects in the collection.
Definition: OFEnumerator.m:45
A protocol for getting an enumerator for the object.
Definition: OFEnumerator.h:31
State information for fast enumerations.
Definition: OFEnumerator.h:91
nullable ObjectType nextObject()
Returns the next object or nil if there is none left.
Definition: OFEnumerator.m:40
A class which provides methods to enumerate through collections.
Definition: OFEnumerator.h:52
OFEnumerator * objectEnumerator()
Returns an OFEnumerator to enumerate through all objects of the collection.