ObjFW
OFList.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3  * Jonathan Schleifer <js@webkeks.org>
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;
39  id __unsafe_unretained object;
40 };
41 
47 #ifdef OF_HAVE_GENERICS
48 @interface OFList <ObjectType>:
49 #else
50 # ifndef DOXYGEN
51 # define ObjectType id
52 # endif
53 @interface OFList:
54 #endif
56 {
57  of_list_object_t *_firstListObject;
58  of_list_object_t *_lastListObject;
59  size_t _count;
60  unsigned long _mutations;
61 }
62 
63 #ifdef OF_HAVE_PROPERTIES
64 @property OF_NULLABLE_PROPERTY (readonly) of_list_object_t *firstListObject;
65 @property OF_NULLABLE_PROPERTY (readonly) of_list_object_t *lastListObject;
66 #endif
67 
73 + (instancetype)list;
74 
80 - (nullable of_list_object_t*)firstListObject;
81 
87 - (nullable of_list_object_t*)lastListObject;
88 
97 - (of_list_object_t*)appendObject: (ObjectType)object;
98 
107 - (of_list_object_t*)prependObject: (ObjectType)object;
108 
119 - (of_list_object_t*)insertObject: (ObjectType)object
120  beforeListObject: (of_list_object_t*)listObject;
121 
132 - (of_list_object_t*)insertObject: (ObjectType)object
133  afterListObject: (of_list_object_t*)listObject;
134 
140 - (void)removeListObject: (of_list_object_t*)listObject;
141 
149 - (bool)containsObject: (nullable ObjectType)object;
150 
158 - (bool)containsObjectIdenticalTo: (nullable ObjectType)object;
159 
165 - (OFEnumerator OF_GENERIC(ObjectType)*)objectEnumerator;
166 
175 - (nullable ObjectType)firstObject;
176 
185 - (nullable ObjectType)lastObject;
186 
190 - (void)removeAllObjects;
191 @end
192 #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
193 # undef ObjectType
194 #endif
195 
196 @interface OFListEnumerator: OFEnumerator
197 {
198  OFList *_list;
199  of_list_object_t *_current;
200  unsigned long _mutations;
201  unsigned long *_mutationsPtr;
202 }
203 
204 - initWithList: (OFList*)list
205  mutationsPointer: (unsigned long*)mutationsPtr;
206 @end
207 
208 OF_ASSUME_NONNULL_END
A protocol for serializing objects.
Definition: OFSerialization.h:30
nullable ObjectType firstObject()
Returns the first object of the list or nil.
Definition: OFList.m:200
OFEnumerator OF_GENERIC(ObjectType objectEnumerator()
Returns an OFEnumerator to enumerate through all objects of the list.
Definition: OFList.m:412
nullable of_list_object_t * lastListObject()
Returns the last list object of the list.
Definition: OFList.m:83
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
void removeAllObjects()
Removes all objects from the list.
Definition: OFList.m:268
A protocol with methods common for all collections.
Definition: OFCollection.h:26
of_list_object_t * previous
A pointer to the previous list object in the list.
Definition: OFList.h:37
nullable of_list_object_t * firstListObject()
Returns the first list object of the list.
Definition: OFList.m:78
A list object.
Definition: OFList.h:33
A class which provides easy to use double-linked lists.
Definition: OFList.h:53
A protocol for the creation of copies.
Definition: OFObject.h:896
nullable ObjectType lastObject()
Returns the last object of the list or nil.
Definition: OFList.m:205
instancetype list()
Creates a new OFList.
Definition: OFList.m:31
of_list_object_t * next
A pointer to the next list object in the list.
Definition: OFList.h:35
A class which provides methods to enumerate through collections.
Definition: OFEnumerator.h:52
id __unsafe_unretained object
The object for the list object.
Definition: OFList.h:39