Tue, 07 Feb 2023 20:08:45 +0100
fix code not compiling under windows+mingw
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 | */ |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
68 | cx_list_class const *cl; |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
69 | /** |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
70 | * The actual implementation in case the list class is delegating. |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
71 | */ |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
72 | cx_list_class const *climpl; |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
73 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
74 | * The allocator to use. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
75 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
76 | CxAllocator const *allocator; |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
77 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
78 | * The comparator function for the elements. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
79 | */ |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
80 | CxListComparator cmpfunc; |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
81 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
82 | * The size of each element (payload only). |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
83 | */ |
401
e6a8f7fb0c45
copy list items when they are added to the list
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
84 | size_t itemsize; |
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 the list (number of currently stored elements). |
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 size; |
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 capacity of the list (maximum number of 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 capacity; |
528
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
93 | union { |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
94 | /** |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
95 | * An optional simple destructor for the list contents that admits the free() interface. |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
96 | * |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
97 | * @remark Set content_destructor_type to #CX_DESTRUCTOR_SIMPLE. |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
98 | * |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
99 | * @attention Read the documentation of the particular list implementation |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
100 | * whether this destructor shall only destroy the contents or also free the memory. |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
101 | */ |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
102 | cx_destructor_func simple_destructor; |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
103 | /** |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
104 | * An optional advanced destructor for the list contents providing additional data. |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
105 | * |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
106 | * @remark Set content_destructor_type to #CX_DESTRUCTOR_ADVANCED. |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
107 | * |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
108 | * @attention Read the documentation of the particular list implementation |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
109 | * whether this destructor shall only destroy the contents or also free the memory. |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
110 | */ |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
111 | cx_advanced_destructor advanced_destructor; |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
112 | }; |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
113 | /** |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
114 | * The type of destructor to use. |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
115 | */ |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
116 | enum cx_destructor_type content_destructor_type; |
435
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
415
diff
changeset
|
117 | }; |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
118 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
119 | /** |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
120 | * The class definition for arbitrary lists. |
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 | struct cx_list_class_s { |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
123 | /** |
524 | 124 | * Destructor function. |
125 | */ | |
126 | void (*destructor)(struct cx_list_s *list); | |
127 | ||
128 | /** | |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
129 | * Member function for inserting a single elements. |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
130 | * Implementors SHOULD see to performant implementations for corner cases. |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
131 | */ |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
132 | int (*insert_element)( |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
133 | struct cx_list_s *list, |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
134 | size_t index, |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
135 | void const *data |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
136 | ); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
137 | |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
138 | /** |
638
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
139 | * Member function for inserting multiple elements. |
640
55cc3b373c5e
simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
140 | * Implementors SHOULD see to performant implementations for corner cases. |
638
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
141 | */ |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
142 | size_t (*insert_array)( |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
143 | struct cx_list_s *list, |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
144 | size_t index, |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
145 | void const *data, |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
146 | size_t n |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
147 | ); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
148 | |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
149 | /** |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
150 | * 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
|
151 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
152 | int (*insert_iter)( |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
153 | struct cx_mut_iterator_s *iter, |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
154 | void const *elem, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
155 | int prepend |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
156 | ); |
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 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
159 | * Member function for removing an element. |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
160 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
161 | int (*remove)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
162 | struct cx_list_s *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
163 | size_t index |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
164 | ); |
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 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
167 | * Member function for element lookup. |
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 | void *(*at)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
170 | struct cx_list_s const *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
171 | size_t index |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
172 | ); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
173 | |
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 | * Member function for finding an element. |
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 | size_t (*find)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
178 | struct cx_list_s const *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
179 | void const *elem |
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 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
183 | * 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
|
184 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
185 | void (*sort)(struct cx_list_s *list); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
186 | |
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 | * 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
|
189 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
190 | int (*compare)( |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
191 | struct cx_list_s const *list, |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
192 | struct cx_list_s const *other |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
193 | ); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
194 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
195 | /** |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
196 | * 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
|
197 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
198 | void (*reverse)(struct cx_list_s *list); |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
199 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
200 | /** |
640
55cc3b373c5e
simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
201 | * Member function for returning an iterator pointing to the specified index. |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
202 | */ |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
203 | struct cx_iterator_s (*iterator)( |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
204 | struct cx_list_s const *list, |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
205 | size_t index |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
206 | ); |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
207 | }; |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
208 | |
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
209 | /** |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
210 | * Common type for all list implementations. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
211 | */ |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
212 | 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
|
213 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
214 | /** |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
215 | * Advises the list to store copies of the objects (default mode of operation). |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
216 | * |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
217 | * Retrieving objects from this list will yield pointers to the copies stored |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
218 | * within this list. |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
219 | * |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
220 | * @param list the list |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
221 | * @see cxListStorePointers() |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
222 | */ |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
223 | __attribute__((__nonnull__)) |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
224 | void cxListStoreObjects(CxList *list); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
225 | |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
226 | /** |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
227 | * Advises the list to only store pointers to the objects. |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
228 | * |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
229 | * Retrieving objects from this list will yield the original pointers stored. |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
230 | * |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
231 | * @note This function forcibly sets the element size to the size of a pointer. |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
232 | * Invoking this function on a non-empty list that already stores copies of |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
233 | * objects is undefined. |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
234 | * |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
235 | * @param list the list |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
236 | * @see cxListStoreObjects() |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
237 | */ |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
238 | __attribute__((__nonnull__)) |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
239 | void cxListStorePointers(CxList *list); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
240 | |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
241 | /** |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
242 | * Returns true, if this list is storing pointers instead of the actual data. |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
243 | * |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
244 | * @param list |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
245 | * @return |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
246 | * @see cxListStorePointers() |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
247 | */ |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
248 | __attribute__((__nonnull__)) |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
249 | bool cxListIsStoringPointers(CxList *list); |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
250 | |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
251 | /** |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
252 | * 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
|
253 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
254 | * @param list the list |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
255 | * @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
|
256 | * @return zero on success, non-zero on memory allocation failure |
629
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
257 | * @see cxListAddArray() |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
258 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
259 | __attribute__((__nonnull__)) |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
260 | static inline int cxListAdd( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
261 | CxList *list, |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
262 | void const *elem |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
263 | ) { |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
264 | return list->cl->insert_element(list, list->size, elem); |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
265 | } |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
266 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
267 | /** |
629
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
268 | * Adds multiple items to the end of the list. |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
269 | * |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
270 | * This method is more efficient than invoking cxListAdd() multiple times. |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
271 | * |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
272 | * If there is not enough memory to add all elements, the returned value is |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
273 | * less than \p n. |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
274 | * |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
275 | * If this list is storing pointers instead of objects \p array is expected to |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
276 | * be an array of pointers. |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
277 | * |
629
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
278 | * @param list the list |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
279 | * @param array a pointer to the elements to add |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
280 | * @param n the number of elements to add |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
281 | * @return the number of added elements |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
282 | */ |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
283 | __attribute__((__nonnull__)) |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
284 | static inline size_t cxListAddArray( |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
285 | CxList *list, |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
286 | void const *array, |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
287 | size_t n |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
288 | ) { |
640
55cc3b373c5e
simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
289 | return list->cl->insert_array(list, list->size, array, n); |
629
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
290 | } |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
291 | |
6c81ee4f11ad
#224 add cxListAddArray()
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
292 | /** |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
293 | * Inserts an item at the specified index. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
294 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
295 | * 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
|
296 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
297 | * @param list the list |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
298 | * @param index the index the element shall have |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
299 | * @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
|
300 | * @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
|
301 | * or when the index is out of bounds |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
302 | * @see cxListInsertAfter() |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
303 | * @see cxListInsertBefore() |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
304 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
305 | __attribute__((__nonnull__)) |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
306 | static inline int cxListInsert( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
307 | CxList *list, |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
308 | size_t index, |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
309 | void const *elem |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
310 | ) { |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
311 | return list->cl->insert_element(list, index, elem); |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
312 | } |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
313 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
314 | /** |
638
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
315 | * Inserts multiple items to the list at the specified index. |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
316 | * If \p index equals the list size, this is effectively cxListAddArray(). |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
317 | * |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
318 | * This method is usually more efficient than invoking cxListInsert() |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
319 | * multiple times. |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
320 | * |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
321 | * If there is not enough memory to add all elements, the returned value is |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
322 | * less than \p n. |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
323 | * |
641
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
324 | * If this list is storing pointers instead of objects \p array is expected to |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
325 | * be an array of pointers. |
d402fead3386
add new pointer list wrapper - resolves #234
Mike Becker <universe@uap-core.de>
parents:
640
diff
changeset
|
326 | * |
638
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
327 | * @param list the list |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
328 | * @param index the index where to add the elements |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
329 | * @param array a pointer to the elements to add |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
330 | * @param n the number of elements to add |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
331 | * @return the number of added elements |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
332 | */ |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
333 | __attribute__((__nonnull__)) |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
334 | static inline size_t cxListInsertArray( |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
335 | CxList *list, |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
336 | size_t index, |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
337 | void const *array, |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
338 | size_t n |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
339 | ) { |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
340 | return list->cl->insert_array(list, index, array, n); |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
341 | } |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
342 | |
eafb45eefc51
add cxListInsertArray() - fixes #224
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
343 | /** |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
344 | * 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
|
345 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
346 | * 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
|
347 | * be considered invalidated. |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
348 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
349 | * 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
|
350 | * 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
|
351 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
352 | * @param iter an iterator |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
353 | * @param elem the element to insert |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
354 | * @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
|
355 | * @see cxListInsert() |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
356 | * @see cxListInsertBefore() |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
357 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
358 | __attribute__((__nonnull__)) |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
359 | static inline int cxListInsertAfter( |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
360 | CxMutIterator *iter, |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
361 | void const *elem |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
362 | ) { |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
363 | 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
|
364 | } |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
365 | |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
366 | /** |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
367 | * 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
|
368 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
369 | * 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
|
370 | * be considered invalidated. |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
371 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
372 | * 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
|
373 | * 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
|
374 | * |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
375 | * @param iter an iterator |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
376 | * @param elem the element to insert |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
377 | * @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
|
378 | * @see cxListInsert() |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
379 | * @see cxListInsertAfter() |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
380 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
381 | __attribute__((__nonnull__)) |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
382 | static inline int cxListInsertBefore( |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
383 | CxMutIterator *iter, |
499
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
384 | void const *elem |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
385 | ) { |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
386 | 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
|
387 | } |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
388 | |
3dc9075df822
add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents:
495
diff
changeset
|
389 | /** |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
390 | * Removes the element at the specified index. |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
391 | * @param list the list |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
392 | * @param index the index of the element |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
393 | * @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
|
394 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
395 | __attribute__((__nonnull__)) |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
396 | static inline int cxListRemove( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
397 | CxList *list, |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
398 | size_t index |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
399 | ) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
400 | 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
|
401 | } |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
402 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
403 | /** |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
404 | * 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
|
405 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
406 | * @param list the list |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
407 | * @param index the index of the element |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
408 | * @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
|
409 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
410 | __attribute__((__nonnull__)) |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
411 | static inline void *cxListAt( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
412 | CxList *list, |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
413 | size_t index |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
414 | ) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
415 | 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
|
416 | } |
439
9a5adedd6de6
add high-level function cxListAt()
Mike Becker <universe@uap-core.de>
parents:
438
diff
changeset
|
417 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
418 | /** |
494
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
419 | * 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
|
420 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
421 | * The returned iterator is position-aware. |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
422 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
423 | * 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
|
424 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
425 | * @param list the list |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
426 | * @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
|
427 | * @return a new iterator |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
428 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
429 | __attribute__((__nonnull__, __warn_unused_result__)) |
494
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
430 | static inline CxIterator cxListIterator( |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
431 | CxList const *list, |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
432 | size_t index |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
433 | ) { |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
434 | return list->cl->iterator(list, index); |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
435 | } |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
436 | |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
437 | /** |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
438 | * Returns a mutating iterator pointing to the item at the specified index. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
439 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
440 | * The returned iterator is position-aware. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
441 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
442 | * If the index is out of range, a past-the-end iterator will be returned. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
443 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
444 | * @param list the list |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
445 | * @param index the index where the iterator shall point at |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
446 | * @return a new iterator |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
447 | */ |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
448 | __attribute__((__nonnull__, __warn_unused_result__)) |
640
55cc3b373c5e
simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
449 | CxMutIterator cxListMutIterator( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
450 | CxList *list, |
494
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
451 | size_t index |
640
55cc3b373c5e
simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
452 | ); |
494
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
453 | |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
454 | /** |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
455 | * 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
|
456 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
457 | * The returned iterator is position-aware. |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
458 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
459 | * 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
|
460 | * |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
461 | * @param list the list |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
462 | * @return a new iterator |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
463 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
464 | __attribute__((__nonnull__, __warn_unused_result__)) |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
465 | static inline CxIterator cxListBegin(CxList const *list) { |
494
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
466 | return list->cl->iterator(list, 0); |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
467 | } |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
468 | |
6ce8cfa10a96
add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents:
490
diff
changeset
|
469 | /** |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
470 | * Returns a mutating iterator pointing to the first item of the list. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
471 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
472 | * The returned iterator is position-aware. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
473 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
474 | * If the list is empty, a past-the-end iterator will be returned. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
475 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
476 | * @param list the list |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
477 | * @return a new iterator |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
478 | */ |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
479 | __attribute__((__nonnull__, __warn_unused_result__)) |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
480 | static inline CxMutIterator cxListBeginMut(CxList *list) { |
640
55cc3b373c5e
simplify list class - fixes #236
Mike Becker <universe@uap-core.de>
parents:
638
diff
changeset
|
481 | return cxListMutIterator(list, 0); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
482 | } |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
483 | |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
629
diff
changeset
|
484 | /** |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
485 | * 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
|
486 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
487 | * 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
|
488 | * |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
489 | * @param list the list |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
490 | * @param elem the element to find |
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
491 | * @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
|
492 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
493 | __attribute__((__nonnull__)) |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
494 | static inline size_t cxListFind( |
621
646e38efc7bc
missing const in cxListFind
Mike Becker <universe@uap-core.de>
parents:
618
diff
changeset
|
495 | CxList const *list, |
489
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
496 | void const *elem |
af6be1e123aa
add some const qualifiers
Mike Becker <universe@uap-core.de>
parents:
488
diff
changeset
|
497 | ) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
498 | 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
|
499 | } |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
393
diff
changeset
|
500 | |
464
7fafc95968fc
add documentation for list.h
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
501 | /** |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
502 | * 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
|
503 | * |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
504 | * \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
|
505 | * |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
464
diff
changeset
|
506 | * @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
|
507 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
508 | __attribute__((__nonnull__)) |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
509 | 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
|
510 | 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
|
511 | } |
404 | 512 | |
488
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
513 | /** |
490 | 514 | * Reverses the order of the items. |
515 | * | |
516 | * @param list the list | |
517 | */ | |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
518 | __attribute__((__nonnull__)) |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
499
diff
changeset
|
519 | static inline void cxListReverse(CxList *list) { |
490 | 520 | list->cl->reverse(list); |
521 | } | |
522 | ||
523 | /** | |
488
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
524 | * 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
|
525 | * |
618
1f5a8f6f3015
#219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents:
528
diff
changeset
|
526 | * First, the list sizes are compared. |
1f5a8f6f3015
#219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents:
528
diff
changeset
|
527 | * If they match, the lists are compared element-wise. |
488
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
528 | * |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
529 | * @param list the list |
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
530 | * @param other the list to compare to |
618
1f5a8f6f3015
#219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents:
528
diff
changeset
|
531 | * @return zero, if both lists are equal element wise, |
1f5a8f6f3015
#219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents:
528
diff
changeset
|
532 | * negative if the first list is smaller, positive if the first list is larger |
488
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
533 | */ |
508
8aea65ae1eaf
#168 - add attributes and const
Mike Becker <universe@uap-core.de>
parents:
505
diff
changeset
|
534 | __attribute__((__nonnull__)) |
618
1f5a8f6f3015
#219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents:
528
diff
changeset
|
535 | int cxListCompare( |
1f5a8f6f3015
#219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents:
528
diff
changeset
|
536 | CxList const *list, |
1f5a8f6f3015
#219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents:
528
diff
changeset
|
537 | CxList const *other |
1f5a8f6f3015
#219 array list: implement compare
Mike Becker <universe@uap-core.de>
parents:
528
diff
changeset
|
538 | ); |
488
9138acaa494b
add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
539 | |
503
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
540 | /** |
528
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
541 | * Deallocates the memory of the specified list structure. |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
542 | * |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
543 | * Also calls content a destructor function, depending on the configuration |
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
544 | * in CxList.content_destructor_type. |
503
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
545 | * |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
546 | * 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
|
547 | * |
528
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
548 | * @param list the list which shall be destroyed |
503
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
549 | */ |
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
550 | __attribute__((__nonnull__)) |
528
4fbfac557df8
#179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents:
526
diff
changeset
|
551 | void cxListDestroy(CxList *list); |
503
a89857072ace
add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
552 | |
415 | 553 | #ifdef __cplusplus |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
621
diff
changeset
|
554 | } // extern "C" |
415 | 555 | #endif |
556 | ||
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
621
diff
changeset
|
557 | #endif // UCX_LIST_H |