ObjFW
Loading...
Searching...
No Matches
OFEnumerator.h
1/*
2 * Copyright (c) 2008-2024 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#ifndef NSINTEGER_DEFINED
69#endif
70
79@protocol OFFastEnumeration
92- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state
93 objects: (id __unsafe_unretained _Nonnull *_Nonnull)
94 objects
95 count: (int)count;
96@end
97
103@interface OFEnumerator OF_GENERIC(ObjectType): OFObject <OFFastEnumeration>
104#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
105# define ObjectType id
106#endif
114- (nullable ObjectType)nextObject;
115
121- (OFArray OF_GENERIC(ObjectType) *)allObjects;
122#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
123# undef ObjectType
124#endif
125@end
126
127OF_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:103
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:79
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