ObjFW
OFList.h
Go to the documentation of this file.
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 #import "OFCollection.h"
18 #import "OFEnumerator.h"
19 
20 OF_ASSUME_NONNULL_BEGIN
21 
24 /*
25  * Make clang's -Wdocumentation shut up about about using @struct on something
26  * it thinks is not a struct. Doxygen requires it this way.
27  */
28 #ifdef __clang__
29 # pragma clang diagnostic push
30 # pragma clang diagnostic ignored "-Wdocumentation"
31 #endif
32 
39 typedef struct _OFListItem *OFListItem;
40 #ifdef __clang__
41 # pragma clang diagnostic pop
42 #endif
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
53 extern OFListItem _Nullable OFListItemNext(OFListItem _Nonnull listItem);
54 
62 extern OFListItem _Nullable OFListItemPrevious(OFListItem _Nonnull listItem);
63 
73 extern id _Nonnull OFListItemObject(OFListItem _Nonnull listItem);
74 #ifdef __cplusplus
75 }
76 #endif
77 
83 @interface OFList OF_GENERIC(ObjectType): OFObject <OFCopying, OFCollection>
84 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
85 # define ObjectType id
86 #endif
87 {
88  OFListItem _Nullable _firstListItem;
89  OFListItem _Nullable _lastListItem;
90  size_t _count;
91  unsigned long _mutations;
92  OF_RESERVE_IVARS(OFList, 4)
93 }
94 
98 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFListItem firstListItem;
99 
106 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType firstObject;
107 
111 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFListItem lastListItem;
112 
119 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType lastObject;
120 
126 + (instancetype)list;
127 
136 - (OFListItem)appendObject: (ObjectType)object;
137 
146 - (OFListItem)prependObject: (ObjectType)object;
147 
158 - (OFListItem)insertObject: (ObjectType)object
159  beforeListItem: (OFListItem)listItem;
160 
171 - (OFListItem)insertObject: (ObjectType)object
172  afterListItem: (OFListItem)listItem;
173 
179 - (void)removeListItem: (OFListItem)listItem;
180 
188 - (bool)containsObject: (ObjectType)object;
189 
197 - (bool)containsObjectIdenticalTo: (ObjectType)object;
198 
202 - (void)removeAllObjects;
203 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
204 # undef ObjectType
205 #endif
206 @end
207 
208 OF_ASSUME_NONNULL_END
The root class for all other classes inside ObjFW.
Definition: OFObject.h:686
id OFListItemObject(OFListItem listItem)
Returns the object of the list item.
Definition: OFList.m:58
OFListItem OFListItemPrevious(OFListItem listItem)
Returns the previous list item of the list item.
Definition: OFList.m:52
A protocol with methods common for all collections.
OFListItem OFListItemNext(OFListItem listItem)
Returns the next list item of the list item.
Definition: OFList.m:46
A class which provides easy to use double-linked lists.
Definition: OFList.h:83
A protocol for the creation of copies.
Definition: OFObject.h:1346
A list item.