Fri, 15 Apr 2022 21:28:51 +0200
add googletest framework
390 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
439
diff
changeset
|
28 | /** |
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
439
diff
changeset
|
29 | * \file list.h |
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
439
diff
changeset
|
30 | * \brief Interface for list implementations. |
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
439
diff
changeset
|
31 | * \author Mike Becker |
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
439
diff
changeset
|
32 | * \author Olaf Wintermann |
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
439
diff
changeset
|
33 | * \version 3.0 |
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
439
diff
changeset
|
34 | * \copyright 2-Clause BSD License |
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
439
diff
changeset
|
35 | */ |
390 | 36 | |
37 | #ifndef UCX_LIST_H | |
38 | #define UCX_LIST_H | |
39 | ||
484
9e6900b1cf9d
add common.h include to all other header files
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
40 | #include "common.h" |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
41 | #include "allocator.h" |
494
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
42 | #include "iterator.h" |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
43 | |
415 | 44 | #ifdef __cplusplus |
45 | extern "C" { | |
46 | #endif | |
47 | ||
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
48 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
49 | * A comparator function comparing two list elements. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
50 | */ |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
51 | typedef int(*CxListComparator)( |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
52 | void const *left, |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
53 | void const *right |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
54 | ); |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
55 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
56 | /** |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
57 | * List class type. |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
58 | */ |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
59 | typedef struct cx_list_class_s cx_list_class; |
435
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
415
diff
changeset
|
60 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
61 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
62 | * Structure for holding the base data of a list. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
63 | */ |
435
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
415
diff
changeset
|
64 | struct cx_list_s { |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
65 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
66 | * The list class definition. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
67 | */ |
435
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
415
diff
changeset
|
68 | cx_list_class *cl; |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
69 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
70 | * The allocator to use. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
71 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
72 | CxAllocator const *allocator; |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
73 | /** |
503
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
74 | * A mandatory destructor for the list structure. |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
75 | */ |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
76 | cx_destructor_func list_destructor; |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
77 | /** |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
78 | * An optional destructor for the list contents. |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
79 | */ |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
80 | cx_destructor_func content_destructor; |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
81 | /** |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
82 | * The comparator function for the elements. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
83 | */ |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
84 | CxListComparator cmpfunc; |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
85 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
86 | * The size of each element (payload only). |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
87 | */ |
401
e6a8f7fb0c45
copy list items when they are added to the list
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
88 | size_t itemsize; |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
89 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
90 | * The size of the list (number of currently stored elements). |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
91 | */ |
401
e6a8f7fb0c45
copy list items when they are added to the list
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
92 | size_t size; |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
93 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
94 | * The capacity of the list (maximum number of elements). |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
95 | */ |
401
e6a8f7fb0c45
copy list items when they are added to the list
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
96 | size_t capacity; |
503
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
97 | /** |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
98 | * Flag indicating whether cxListDestroy() shall free the list structure, |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
99 | * even if cx_list_s.list_destructor did not do that. |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
100 | */ |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
101 | bool autofree; |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
102 | /** |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
103 | * Flag indicating whether cxListDestroy() shall free each list element, |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
104 | * even if cx_list_s.content_destructor did not do that. |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
105 | */ |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
106 | bool autofree_contents; |
435
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
415
diff
changeset
|
107 | }; |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
108 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
109 | /** |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
110 | * The class definition for arbitrary lists. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
111 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
112 | struct cx_list_class_s { |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
113 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
114 | * Member function for adding an element. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
115 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
116 | int (*add)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
117 | struct cx_list_s *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
118 | void const *elem |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
119 | ); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
120 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
121 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
122 | * Member function for inserting an element. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
123 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
124 | int (*insert)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
125 | struct cx_list_s *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
126 | size_t index, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
127 | void const *elem |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
128 | ); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
129 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
130 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
131 | * Member function for inserting an element relative to an iterator position. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
132 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
133 | int (*insert_iter)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
134 | struct cx_iterator_s *iter, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
135 | void const *elem, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
136 | int prepend |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
137 | ); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
138 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
139 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
140 | * Member function for removing an element. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
141 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
142 | int (*remove)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
143 | struct cx_list_s *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
144 | size_t index |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
145 | ); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
146 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
147 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
148 | * Member function for element lookup. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
149 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
150 | void *(*at)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
151 | struct cx_list_s const *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
152 | size_t index |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
153 | ); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
154 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
155 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
156 | * Member function for finding an element. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
157 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
158 | size_t (*find)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
159 | struct cx_list_s const *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
160 | void const *elem |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
161 | ); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
162 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
163 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
164 | * Member function for sorting the list in place. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
165 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
166 | void (*sort)(struct cx_list_s *list); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
167 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
168 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
169 | * Member function for comparing this list to another list of the same type. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
170 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
171 | int (*compare)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
172 | struct cx_list_s const *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
173 | struct cx_list_s const *other |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
174 | ); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
175 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
176 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
177 | * Member function for reversing the order of the items. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
178 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
179 | void (*reverse)(struct cx_list_s *list); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
180 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
181 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
182 | * Returns an iterator pointing to the specified index. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
183 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
184 | struct cx_iterator_s (*iterator)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
185 | struct cx_list_s *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
186 | size_t index |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
187 | ); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
188 | }; |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
189 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
190 | /** |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
191 | * Common type for all list implementations. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
192 | */ |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
193 | typedef struct cx_list_s CxList; |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
194 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
195 | /** |
505
03e9151bea32
fix typo in documentation
Mike Becker <universe@uap-core.de>
parents:
504
diff
changeset
|
196 | * Convenience function to configure the memory management for this list. |
03e9151bea32
fix typo in documentation
Mike Becker <universe@uap-core.de>
parents:
504
diff
changeset
|
197 | * |
504
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
198 | * @param list the list to configure |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
199 | * @param list_destructor an alternative list destructor to use (if \c NULL, the current destructor remains unchanged) |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
200 | * @param content_destructor the content destructor to use (if \c NULL, no content destructor is used) |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
201 | * @param list_autofree a flag indicating, if the list allocator shall free the list, if the destructor did not do that |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
202 | * @param content_autofree a flag indicating, if the list allocator shall free an element, |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
203 | * if the content destructor did not do that or no content destructor exists |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
204 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
205 | __attribute__((__nonnull__(1))) |
504
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
206 | static inline void cxListMemoryMgmt( |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
207 | CxList *list, |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
208 | cx_destructor_func list_destructor, |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
209 | cx_destructor_func content_destructor, |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
210 | bool list_autofree, |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
211 | bool content_autofree |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
212 | ) { |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
213 | if (list_destructor != NULL) list->list_destructor = list_destructor; |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
214 | list->content_destructor = content_destructor; |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
215 | list->autofree = list_autofree; |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
216 | list->autofree_contents = content_autofree; |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
217 | } |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
218 | |
aaf89ce0cbf6
add convenience function to configure list memory management
Mike Becker <universe@uap-core.de>
parents:
503
diff
changeset
|
219 | /** |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
220 | * Adds an item to the end of the list. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
221 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
222 | * @param list the list |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
223 | * @param elem a pointer to the element to add |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
224 | * @return zero on success, non-zero on memory allocation failure |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
225 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
226 | __attribute__((__nonnull__)) |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
227 | static inline int cxListAdd( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
228 | CxList *list, |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
229 | void const *elem |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
230 | ) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
231 | return list->cl->add(list, elem); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
232 | } |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
233 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
234 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
235 | * Inserts an item at the specified index. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
236 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
237 | * If \p index equals the list \c size, this is effectively cxListAdd(). |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
238 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
239 | * @param list the list |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
240 | * @param index the index the element shall have |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
241 | * @param elem a pointer to the element to add |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
242 | * @return zero on success, non-zero on memory allocation failure |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
243 | * or when the index is out of bounds |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
244 | * @see cxListInsertAfter() |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
245 | * @see cxListInsertBefore() |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
246 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
247 | __attribute__((__nonnull__)) |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
248 | static inline int cxListInsert( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
249 | CxList *list, |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
250 | size_t index, |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
251 | void const *elem |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
252 | ) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
253 | return list->cl->insert(list, index, elem); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
254 | } |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
255 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
256 | /** |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
257 | * Inserts an element after the current location of the specified iterator. |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
258 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
259 | * The used iterator remains operational, but all other active iterators should |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
260 | * be considered invalidated. |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
261 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
262 | * If \p iter is not a list iterator, the behavior is undefined. |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
263 | * If \p iter is a past-the-end iterator, the new element gets appended to the list. |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
264 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
265 | * @param iter an iterator |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
266 | * @param elem the element to insert |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
267 | * @return zero on success, non-zero on memory allocation failure |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
268 | * @see cxListInsert() |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
269 | * @see cxListInsertBefore() |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
270 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
271 | __attribute__((__nonnull__)) |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
272 | static inline int cxListInsertAfter( |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
273 | CxIterator *iter, |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
274 | void const *elem |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
275 | ) { |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
276 | return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0); |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
277 | } |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
278 | |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
279 | /** |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
280 | * Inserts an element before the current location of the specified iterator. |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
281 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
282 | * The used iterator remains operational, but all other active iterators should |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
283 | * be considered invalidated. |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
284 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
285 | * If \p iter is not a list iterator, the behavior is undefined. |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
286 | * If \p iter is a past-the-end iterator, the new element gets appended to the list. |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
287 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
288 | * @param iter an iterator |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
289 | * @param elem the element to insert |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
290 | * @return zero on success, non-zero on memory allocation failure |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
291 | * @see cxListInsert() |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
292 | * @see cxListInsertAfter() |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
293 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
294 | __attribute__((__nonnull__)) |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
295 | static inline int cxListInsertBefore( |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
296 | CxIterator *iter, |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
297 | void const *elem |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
298 | ) { |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
299 | return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1); |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
300 | } |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
301 | |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
302 | /** |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
303 | * Removes the element at the specified index. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
304 | * @param list the list |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
305 | * @param index the index of the element |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
306 | * @return zero on success, non-zero if the index is out of bounds |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
307 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
308 | __attribute__((__nonnull__)) |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
309 | static inline int cxListRemove( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
310 | CxList *list, |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
311 | size_t index |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
312 | ) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
313 | return list->cl->remove(list, index); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
314 | } |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
315 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
316 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
317 | * Returns a pointer to the element at the specified index. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
318 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
319 | * @param list the list |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
320 | * @param index the index of the element |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
321 | * @return a pointer to the element or \c NULL if the index is out of bounds |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
322 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
323 | __attribute__((__nonnull__)) |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
324 | static inline void *cxListAt( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
325 | CxList *list, |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
326 | size_t index |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
327 | ) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
328 | return list->cl->at(list, index); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
329 | } |
439
9a5adedd6de6
add high-level function cxListAt()
Mike Becker <universe@uap-core.de>
parents:
438
diff
changeset
|
330 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
331 | /** |
494
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
332 | * Returns an iterator pointing to the item at the specified index. |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
333 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
334 | * The returned iterator is position-aware. |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
335 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
336 | * If the index is out of range, a past-the-end iterator will be returned. |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
337 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
338 | * @param list the list |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
339 | * @param index the index where the iterator shall point at |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
340 | * @return a new iterator |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
341 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
342 | __attribute__((__nonnull__, __warn_unused_result__)) |
494
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
343 | static inline CxIterator cxListIterator( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
344 | CxList *list, |
494
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
345 | size_t index |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
346 | ) { |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
347 | return list->cl->iterator(list, index); |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
348 | } |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
349 | |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
350 | /** |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
351 | * Returns an iterator pointing to the first item of the list. |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
352 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
353 | * The returned iterator is position-aware. |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
354 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
355 | * If the list is empty, a past-the-end iterator will be returned. |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
356 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
357 | * @param list the list |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
358 | * @return a new iterator |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
359 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
360 | __attribute__((__nonnull__, __warn_unused_result__)) |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
361 | static inline CxIterator cxListBegin(CxList *list) { |
494
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
362 | return list->cl->iterator(list, 0); |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
363 | } |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
364 | |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
365 | /** |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
366 | * Returns the index of the first element that equals \p elem. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
367 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
368 | * Determining equality is performed by the list's comparator function. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
369 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
370 | * @param list the list |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
371 | * @param elem the element to find |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
372 | * @return the index of the element or \c (size+1) if the element is not found |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
373 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
374 | __attribute__((__nonnull__)) |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
375 | static inline size_t cxListFind( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
376 | CxList *list, |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
377 | void const *elem |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
378 | ) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
379 | return list->cl->find(list, elem); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
380 | } |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
381 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
382 | /** |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
383 | * Sorts the list in place. |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
384 | * |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
385 | * \remark The underlying sort algorithm is implementation defined. |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
386 | * |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
387 | * @param list the list |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
388 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
389 | __attribute__((__nonnull__)) |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
390 | static inline void cxListSort(CxList *list) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
391 | list->cl->sort(list); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
392 | } |
404 | 393 | |
488
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
394 | /** |
490 | 395 | * Reverses the order of the items. |
396 | * | |
397 | * @param list the list | |
398 | */ | |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
399 | __attribute__((__nonnull__)) |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
400 | static inline void cxListReverse(CxList *list) { |
490 | 401 | list->cl->reverse(list); |
402 | } | |
403 | ||
404 | /** | |
488
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
405 | * Compares a list to another list of the same type. |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
406 | * |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
407 | * First, the list sizes are compared. If they match, the lists are compared element-wise. |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
408 | * |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
409 | * @param list the list |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
410 | * @param other the list to compare to |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
411 | * @return zero, if both lists are equal element wise, negative if the first list is smaller, zero if the first list is larger |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
412 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
413 | __attribute__((__nonnull__)) |
488
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
414 | static inline int cxListCompare( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
415 | CxList *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
416 | CxList *other |
488
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
417 | ) { |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
418 | return list->cl->compare(list, other); |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
419 | } |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
420 | |
503
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
421 | /** |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
422 | * Calls the list's destructor function for every element. |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
423 | * If CxList.autofree_content is \c true, the elements are automatically free'd |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
424 | * unless the content destructor function did not already do that. |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
425 | * Similarly, if CxList.autofree is \c true, the list structure is free'd, unless |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
426 | * the list destructor function did not already do that. |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
427 | * |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
428 | * This function itself is a destructor function for the CxList. |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
429 | * |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
430 | * @param list the list which contents shall be destroyed |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
431 | * @return \p list if the list structure has not been free'd during the process |
503
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
432 | */ |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
433 | __attribute__((__nonnull__)) |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
434 | CxList *cxListDestroy(CxList *list); |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
435 | |
415 | 436 | #ifdef __cplusplus |
437 | } /* extern "C" */ | |
438 | #endif | |
439 | ||
393 | 440 | #endif /* UCX_LIST_H */ |