ObjFW
Loading...
Searching...
No Matches
OFEnumerator.h
1/*
2 * Copyright (c) 2008-2025 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#import "OFObject.h"
21
22OF_ASSUME_NONNULL_BEGIN
23
24@class OFArray OF_GENERIC(ObjectType);
25@class OFEnumerator OF_GENERIC(ObjectType);
26
36@protocol OFEnumeration
43- (OFEnumerator *)objectEnumerator;
44@end
45
46/*
47 * This needs to be exactly like this because it's hard-coded in the compiler.
48 *
49 * We need this bad check to see if we already imported Cocoa, which defines
50 * this as well.
51 */
57typedef struct {
59 unsigned long state;
61 id __unsafe_unretained _Nullable *_Nullable itemsPtr;
63 unsigned long *_Nullable mutationsPtr;
65 unsigned long extra[5];
67#ifdef NSINTEGER_DEFINED
68# define OFFastEnumerationState NSFastEnumerationState
69#else
71#endif
72
81@protocol OFFastEnumeration
94- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state
95 objects: (id __unsafe_unretained _Nonnull *_Nonnull)
96 objects
97 count: (int)count;
98@end
99
105@interface OFEnumerator OF_GENERIC(ObjectType): OFObject <OFFastEnumeration>
106#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
107# define ObjectType id
108#endif
116- (nullable ObjectType)nextObject;
117
123- (OFArray OF_GENERIC(ObjectType) *)allObjects;
124#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
125# undef ObjectType
126#endif
127@end
128
129OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition OFArray.h:109
A class which provides methods to enumerate through collections.
Definition OFEnumerator.h:105
nullable ObjectType nextObject()
Returns the next object or nil if there is none left.
Definition OFEnumerator.m:43
OFArray * allObjects()
Returns an array of all remaining objects in the collection.
Definition OFEnumerator.m:48
The root class for all other classes inside ObjFW.
Definition OFObject.h:692
A protocol for fast enumeration.
Definition OFEnumerator.h:81
State information for fast enumerations.
Definition OFEnumerator.h:57
id __unsafe_unretained * itemsPtr
Definition OFEnumerator.h:61
unsigned long state
Definition OFEnumerator.h:59
unsigned long * mutationsPtr
Definition OFEnumerator.h:63