ObjFW
OFList.h
1 /*
2  * Copyright (c) 2008-2021 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 #import "OFSerialization.h"
20 
21 OF_ASSUME_NONNULL_BEGIN
22 
23 typedef struct of_list_object_t of_list_object_t;
34  of_list_object_t *_Nullable next;
38  id __unsafe_unretained object;
39 };
40 
46 @interface OFList OF_GENERIC(ObjectType): OFObject <OFCopying, OFCollection,
48 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
49 # define ObjectType id
50 #endif
51 {
52  of_list_object_t *_Nullable _firstListObject;
53  of_list_object_t *_Nullable _lastListObject;
54  size_t _count;
55  unsigned long _mutations;
56  OF_RESERVE_IVARS(OFList, 4)
57 }
58 
62 @property OF_NULLABLE_PROPERTY (readonly, nonatomic)
63  of_list_object_t *firstListObject;
64 
71 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType firstObject;
72 
76 @property OF_NULLABLE_PROPERTY (readonly, nonatomic)
77  of_list_object_t *lastListObject;
78 
85 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType lastObject;
86 
92 + (instancetype)list;
93 
102 - (of_list_object_t *)appendObject: (ObjectType)object;
103 
112 - (of_list_object_t *)prependObject: (ObjectType)object;
113 
124 - (of_list_object_t *)insertObject: (ObjectType)object
125  beforeListObject: (of_list_object_t *)listObject;
126 
137 - (of_list_object_t *)insertObject: (ObjectType)object
138  afterListObject: (of_list_object_t *)listObject;
139 
145 - (void)removeListObject: (of_list_object_t *)listObject;
146 
154 - (bool)containsObject: (ObjectType)object;
155 
163 - (bool)containsObjectIdenticalTo: (ObjectType)object;
164 
168 - (void)removeAllObjects;
169 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
170 # undef ObjectType
171 #endif
172 @end
173 
174 OF_ASSUME_NONNULL_END
A class which provides easy to use double-linked lists.
Definition: OFList.h:55
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A protocol with methods common for all collections.
Definition: OFCollection.h:25
A protocol for the creation of copies.
Definition: OFObject.h:1187
A protocol for serializing objects.
Definition: OFSerialization.h:29
A list object.
Definition: OFList.h:32
of_list_object_t *_Nullable next
Definition: OFList.h:34
id __unsafe_unretained object
Definition: OFList.h:38
of_list_object_t *_Nullable previous
Definition: OFList.h:36