ObjFW
OFList.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 #import "OFCollection.h"
19 #import "OFEnumerator.h"
20 #import "OFSerialization.h"
21 
22 OF_ASSUME_NONNULL_BEGIN
23 
24 typedef struct of_list_object_t of_list_object_t;
35  of_list_object_t *_Nullable next;
39  id __unsafe_unretained object;
40 };
41 
47 @interface OFList OF_GENERIC(ObjectType): OFObject <OFCopying, OFCollection,
49 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
50 # define ObjectType id
51 #endif
52 {
53  of_list_object_t *_Nullable _firstListObject;
54  of_list_object_t *_Nullable _lastListObject;
55  size_t _count;
56  unsigned long _mutations;
57 }
58 
62 @property OF_NULLABLE_PROPERTY (readonly, nonatomic)
63  of_list_object_t *firstListObject;
64 
68 @property OF_NULLABLE_PROPERTY (readonly, nonatomic)
69  of_list_object_t *lastListObject;
70 
76 + (instancetype)list;
77 
86 - (of_list_object_t *)appendObject: (ObjectType)object;
87 
96 - (of_list_object_t *)prependObject: (ObjectType)object;
97 
108 - (of_list_object_t *)insertObject: (ObjectType)object
109  beforeListObject: (of_list_object_t *)listObject;
110 
121 - (of_list_object_t *)insertObject: (ObjectType)object
122  afterListObject: (of_list_object_t *)listObject;
123 
129 - (void)removeListObject: (of_list_object_t *)listObject;
130 
138 - (bool)containsObject: (ObjectType)object;
139 
147 - (bool)containsObjectIdenticalTo: (ObjectType)object;
148 
154 - (OFEnumerator OF_GENERIC(ObjectType) *)objectEnumerator;
155 
164 - (nullable ObjectType)firstObject;
165 
174 - (nullable ObjectType)lastObject;
175 
179 - (void)removeAllObjects;
180 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
181 # undef ObjectType
182 #endif
183 @end
184 
185 @interface OFListEnumerator: OFEnumerator
186 {
187  OFList *_list;
188  of_list_object_t *_Nullable _current;
189  unsigned long _mutations;
190  unsigned long *_Nullable _mutationsPtr;
191 }
192 
193 - initWithList: (OFList *)list
194  mutationsPointer: (unsigned long *)mutationsPtr;
195 @end
196 
197 OF_ASSUME_NONNULL_END
A class which provides methods to enumerate through collections.
Definition: OFEnumerator.h:44
A protocol with methods common for all collections.
A protocol for the creation of copies.
Definition: OFObject.h:914
A list object.
Definition: OFList.h:33
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
of_list_object_t *_Nullable previous
Definition: OFList.h:37
A protocol for serializing objects.
Definition: OFSerialization.h:30
of_list_object_t *_Nullable next
Definition: OFList.h:35
id __unsafe_unretained object
Definition: OFList.h:39
A class which provides easy to use double-linked lists.
Definition: OFList.h:47