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 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 #import "OFCollection.h"
22 #import "OFEnumerator.h"
23 
24 OF_ASSUME_NONNULL_BEGIN
25 
28 /*
29  * Make clang's -Wdocumentation shut up about about using @struct on something
30  * it thinks is not a struct. Doxygen requires it this way.
31  */
32 #ifdef __clang__
33 # pragma clang diagnostic push
34 # pragma clang diagnostic ignored "-Wdocumentation"
35 #endif
36 
43 typedef struct _OFListItem *OFListItem;
44 #ifdef __clang__
45 # pragma clang diagnostic pop
46 #endif
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
57 extern OFListItem _Nullable OFListItemNext(OFListItem _Nonnull listItem);
58 
66 extern OFListItem _Nullable OFListItemPrevious(OFListItem _Nonnull listItem);
67 
77 extern id _Nonnull OFListItemObject(OFListItem _Nonnull listItem);
78 #ifdef __cplusplus
79 }
80 #endif
81 
87 @interface OFList OF_GENERIC(ObjectType): OFObject <OFCopying, OFCollection>
88 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
89 # define ObjectType id
90 #endif
91 {
92  OFListItem _Nullable _firstListItem;
93  OFListItem _Nullable _lastListItem;
94  size_t _count;
95  unsigned long _mutations;
96  OF_RESERVE_IVARS(OFList, 4)
97 }
98 
102 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFListItem firstListItem;
103 
110 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType firstObject;
111 
115 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFListItem lastListItem;
116 
123 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType lastObject;
124 
130 + (instancetype)list;
131 
140 - (OFListItem)appendObject: (ObjectType)object;
141 
150 - (OFListItem)prependObject: (ObjectType)object;
151 
162 - (OFListItem)insertObject: (ObjectType)object
163  beforeListItem: (OFListItem)listItem;
164 
175 - (OFListItem)insertObject: (ObjectType)object
176  afterListItem: (OFListItem)listItem;
177 
183 - (void)removeListItem: (OFListItem)listItem;
184 
192 - (bool)containsObject: (ObjectType)object;
193 
201 - (bool)containsObjectIdenticalTo: (ObjectType)object;
202 
206 - (void)removeAllObjects;
207 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
208 # undef ObjectType
209 #endif
210 @end
211 
212 OF_ASSUME_NONNULL_END
The root class for all other classes inside ObjFW.
Definition: OFObject.h:690
id OFListItemObject(OFListItem listItem)
Returns the object of the list item.
Definition: OFList.m:61
OFListItem OFListItemPrevious(OFListItem listItem)
Returns the previous list item of the list item.
Definition: OFList.m:55
A protocol with methods common for all collections.
OFListItem OFListItemNext(OFListItem listItem)
Returns the next list item of the list item.
Definition: OFList.m:49
A class which provides easy to use double-linked lists.
Definition: OFList.h:87
A protocol for the creation of copies.
Definition: OFObject.h:1350
A list item.