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 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
18OF_ASSUME_NONNULL_BEGIN
19
20@class OFArray OF_GENERIC(ObjectType);
21@class OFEnumerator OF_GENERIC(ObjectType);
22
32@protocol OFEnumeration
39- (OFEnumerator *)objectEnumerator;
40@end
41
42/*
43 * This needs to be exactly like this because it's hard-coded in the compiler.
44 *
45 * We need this bad check to see if we already imported Cocoa, which defines
46 * this as well.
47 */
53typedef struct {
55 unsigned long state;
57 id __unsafe_unretained _Nullable *_Nullable itemsPtr;
59 unsigned long *_Nullable mutationsPtr;
61 unsigned long extra[5];
63#ifndef NSINTEGER_DEFINED
65#endif
66
75@protocol OFFastEnumeration
88- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state
89 objects: (id __unsafe_unretained _Nonnull *_Nonnull)
90 objects
91 count: (int)count;
92@end
93
99@interface OFEnumerator OF_GENERIC(ObjectType): OFObject <OFFastEnumeration>
100#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
101# define ObjectType id
102#endif
110- (nullable ObjectType)nextObject;
111
117- (OFArray OF_GENERIC(ObjectType) *)allObjects;
118#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
119# undef ObjectType
120#endif
121@end
122
123OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition OFArray.h:105
A class which provides methods to enumerate through collections.
Definition OFEnumerator.h:99
nullable ObjectType nextObject()
Returns the next object or nil if there is none left.
Definition OFEnumerator.m:39
OFArray * allObjects()
Returns an array of all remaining objects in the collection.
Definition OFEnumerator.m:44
The root class for all other classes inside ObjFW.
Definition OFObject.h:688
A protocol for fast enumeration.
Definition OFEnumerator.h:75
State information for fast enumerations.
Definition OFEnumerator.h:53
id __unsafe_unretained * itemsPtr
Definition OFEnumerator.h:57
unsigned long state
Definition OFEnumerator.h:55
unsigned long * mutationsPtr
Definition OFEnumerator.h:59