Sat, 23 Aug 2025 07:57:33 +0200
add functions for directly setting a linkbutton's label/uri (GTK)
| 174 | 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 | */ | |
| 28 | /** | |
| 440 | 29 | * @file list.h |
| 30 | * @brief Interface for list implementations. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
| 174 | 34 | */ |
| 35 | ||
| 36 | #ifndef UCX_LIST_H | |
| 37 | #define UCX_LIST_H | |
| 38 | ||
| 39 | #include "common.h" | |
| 40 | #include "collection.h" | |
| 41 | ||
| 42 | #ifdef __cplusplus | |
| 43 | extern "C" { | |
| 44 | #endif | |
| 45 | ||
| 46 | /** | |
| 47 | * List class type. | |
| 48 | */ | |
| 49 | typedef struct cx_list_class_s cx_list_class; | |
| 50 | ||
| 51 | /** | |
| 52 | * Structure for holding the base data of a list. | |
| 53 | */ | |
| 54 | struct cx_list_s { | |
| 440 | 55 | /** |
| 56 | * Common members for collections. | |
| 57 | */ | |
| 324 | 58 | CX_COLLECTION_BASE; |
| 174 | 59 | /** |
| 60 | * The list class definition. | |
| 61 | */ | |
| 324 | 62 | const cx_list_class *cl; |
| 174 | 63 | /** |
| 64 | * The actual implementation in case the list class is delegating. | |
| 65 | */ | |
| 324 | 66 | const cx_list_class *climpl; |
| 174 | 67 | }; |
| 68 | ||
| 69 | /** | |
| 70 | * The class definition for arbitrary lists. | |
| 71 | */ | |
| 72 | struct cx_list_class_s { | |
| 73 | /** | |
| 74 | * Destructor function. | |
| 75 | * | |
| 76 | * Implementations SHALL invoke the content destructor functions if provided | |
| 440 | 77 | * and SHALL deallocate the entire list memory. |
| 174 | 78 | */ |
| 440 | 79 | void (*deallocate)(struct cx_list_s *list); |
| 174 | 80 | |
| 81 | /** | |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
82 | * Member function for inserting a single element. |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
83 | * The data pointer may be @c NULL in which case the function shall only allocate memory. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
84 | * Returns a pointer to the data of the inserted element. |
| 174 | 85 | */ |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
86 | void *(*insert_element)( |
| 174 | 87 | struct cx_list_s *list, |
| 88 | size_t index, | |
| 324 | 89 | const void *data |
| 174 | 90 | ); |
| 91 | ||
| 92 | /** | |
| 93 | * Member function for inserting multiple elements. | |
| 440 | 94 | * |
| 324 | 95 | * @see cx_list_default_insert_array() |
| 174 | 96 | */ |
| 97 | size_t (*insert_array)( | |
| 98 | struct cx_list_s *list, | |
| 99 | size_t index, | |
| 324 | 100 | const void *data, |
| 101 | size_t n | |
| 102 | ); | |
| 103 | ||
| 104 | /** | |
| 105 | * Member function for inserting sorted elements into a sorted list. | |
| 106 | * | |
| 107 | * @see cx_list_default_insert_sorted() | |
| 108 | */ | |
| 109 | size_t (*insert_sorted)( | |
| 110 | struct cx_list_s *list, | |
| 111 | const void *sorted_data, | |
| 174 | 112 | size_t n |
| 113 | ); | |
| 114 | ||
| 115 | /** | |
| 116 | * Member function for inserting an element relative to an iterator position. | |
| 117 | */ | |
| 118 | int (*insert_iter)( | |
| 324 | 119 | struct cx_iterator_s *iter, |
| 120 | const void *elem, | |
| 174 | 121 | int prepend |
| 122 | ); | |
| 123 | ||
| 124 | /** | |
| 440 | 125 | * Member function for removing elements. |
| 126 | * | |
| 127 | * Implementations SHALL check if @p targetbuf is set and copy the elements | |
| 128 | * to the buffer without invoking any destructor. | |
| 129 | * When @p targetbuf is not set, the destructors SHALL be invoked. | |
| 130 | * | |
| 131 | * The function SHALL return the actual number of elements removed, which | |
| 132 | * might be lower than @p num when going out of bounds. | |
| 174 | 133 | */ |
| 440 | 134 | size_t (*remove)( |
| 174 | 135 | struct cx_list_s *list, |
| 440 | 136 | size_t index, |
| 137 | size_t num, | |
| 138 | void *targetbuf | |
| 174 | 139 | ); |
| 140 | ||
| 141 | /** | |
| 142 | * Member function for removing all elements. | |
| 143 | */ | |
| 144 | void (*clear)(struct cx_list_s *list); | |
| 145 | ||
| 146 | /** | |
| 147 | * Member function for swapping two elements. | |
| 440 | 148 | * |
| 324 | 149 | * @see cx_list_default_swap() |
| 174 | 150 | */ |
| 151 | int (*swap)( | |
| 152 | struct cx_list_s *list, | |
| 153 | size_t i, | |
| 154 | size_t j | |
| 155 | ); | |
| 156 | ||
| 157 | /** | |
| 158 | * Member function for element lookup. | |
| 159 | */ | |
| 160 | void *(*at)( | |
| 324 | 161 | const struct cx_list_s *list, |
| 174 | 162 | size_t index |
| 163 | ); | |
| 164 | ||
| 165 | /** | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
166 | * Member function for finding and optionally removing an element. |
| 174 | 167 | */ |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
168 | size_t (*find_remove)( |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
169 | struct cx_list_s *list, |
| 324 | 170 | const void *elem, |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
171 | bool remove |
| 174 | 172 | ); |
| 173 | ||
| 174 | /** | |
| 440 | 175 | * Member function for sorting the list. |
| 176 | * | |
| 324 | 177 | * @see cx_list_default_sort() |
| 174 | 178 | */ |
| 179 | void (*sort)(struct cx_list_s *list); | |
| 180 | ||
| 181 | /** | |
| 324 | 182 | * Optional member function for comparing this list |
| 183 | * to another list of the same type. | |
| 440 | 184 | * If set to @c NULL, comparison won't be optimized. |
| 174 | 185 | */ |
| 440 | 186 | cx_attr_nonnull |
| 174 | 187 | int (*compare)( |
| 324 | 188 | const struct cx_list_s *list, |
| 189 | const struct cx_list_s *other | |
| 174 | 190 | ); |
| 191 | ||
| 192 | /** | |
| 193 | * Member function for reversing the order of the items. | |
| 194 | */ | |
| 195 | void (*reverse)(struct cx_list_s *list); | |
| 196 | ||
| 197 | /** | |
| 198 | * Member function for returning an iterator pointing to the specified index. | |
| 199 | */ | |
| 200 | struct cx_iterator_s (*iterator)( | |
| 324 | 201 | const struct cx_list_s *list, |
| 174 | 202 | size_t index, |
| 203 | bool backward | |
| 204 | ); | |
| 205 | }; | |
| 206 | ||
| 207 | /** | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
208 | * Common type for all list implementations. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
209 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
210 | typedef struct cx_list_s CxList; |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
211 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
212 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
213 | * A shared instance of an empty list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
214 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
215 | * Writing to that list is not allowed. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
216 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
217 | * You can use this is a placeholder for initializing CxList pointers |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
218 | * for which you do not want to reserve memory right from the beginning. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
219 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
220 | cx_attr_export |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
221 | extern CxList *const cxEmptyList; |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
222 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
223 | /** |
| 324 | 224 | * Default implementation of an array insert. |
| 225 | * | |
| 226 | * This function uses the element insert function for each element of the array. | |
| 227 | * | |
| 228 | * Use this in your own list class if you do not want to implement an optimized | |
| 229 | * version for your list. | |
| 230 | * | |
| 231 | * @param list the list | |
| 232 | * @param index the index where to insert the data | |
| 233 | * @param data a pointer to the array of data to insert | |
| 234 | * @param n the number of elements to insert | |
| 235 | * @return the number of elements actually inserted | |
| 236 | */ | |
| 440 | 237 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
238 | cx_attr_export |
| 324 | 239 | size_t cx_list_default_insert_array( |
| 240 | struct cx_list_s *list, | |
| 241 | size_t index, | |
| 242 | const void *data, | |
| 243 | size_t n | |
| 244 | ); | |
| 245 | ||
| 246 | /** | |
| 247 | * Default implementation of a sorted insert. | |
| 248 | * | |
| 249 | * This function uses the array insert function to insert consecutive groups | |
| 250 | * of sorted data. | |
| 251 | * | |
| 440 | 252 | * The source data @em must already be sorted wrt. the list's compare function. |
| 324 | 253 | * |
| 254 | * Use this in your own list class if you do not want to implement an optimized | |
| 255 | * version for your list. | |
| 256 | * | |
| 257 | * @param list the list | |
| 258 | * @param sorted_data a pointer to the array of pre-sorted data to insert | |
| 259 | * @param n the number of elements to insert | |
| 260 | * @return the number of elements actually inserted | |
| 261 | */ | |
| 440 | 262 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
263 | cx_attr_export |
| 324 | 264 | size_t cx_list_default_insert_sorted( |
| 265 | struct cx_list_s *list, | |
| 266 | const void *sorted_data, | |
| 267 | size_t n | |
| 268 | ); | |
| 269 | ||
| 270 | /** | |
| 271 | * Default unoptimized sort implementation. | |
| 272 | * | |
| 273 | * This function will copy all data to an array, sort the array with standard | |
| 274 | * qsort, and then copy the data back to the list memory. | |
| 275 | * | |
| 276 | * Use this in your own list class if you do not want to implement an optimized | |
| 277 | * version for your list. | |
| 278 | * | |
| 279 | * @param list the list that shall be sorted | |
| 280 | */ | |
| 440 | 281 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
282 | cx_attr_export |
| 324 | 283 | void cx_list_default_sort(struct cx_list_s *list); |
| 284 | ||
| 285 | /** | |
| 286 | * Default unoptimized swap implementation. | |
| 287 | * | |
| 288 | * Use this in your own list class if you do not want to implement an optimized | |
| 289 | * version for your list. | |
| 290 | * | |
| 291 | * @param list the list in which to swap | |
| 292 | * @param i index of one element | |
| 293 | * @param j index of the other element | |
| 440 | 294 | * @retval zero success |
| 295 | * @retval non-zero when indices are out of bounds or memory | |
| 324 | 296 | * allocation for the temporary buffer fails |
| 297 | */ | |
| 440 | 298 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
299 | cx_attr_export |
| 324 | 300 | int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j); |
| 301 | ||
| 302 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
303 | * Initializes a list struct. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
304 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
305 | * Only use this function if you are creating your own list implementation. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
306 | * The purpose of this function is to be called in the initialization code |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
307 | * of your list, to set certain members correctly. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
308 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
309 | * This is particularly important when you want your list to support |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
310 | * #CX_STORE_POINTERS as @p elem_size. This function will wrap the list |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
311 | * class accordingly and make sure that you can implement your list as if |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
312 | * it was only storing objects and the wrapper will automatically enable |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
313 | * the feature of storing pointers. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
314 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
315 | * @par Example |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
316 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
317 | * @code |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
318 | * CxList *myCustomListCreate( |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
319 | * const CxAllocator *allocator, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
320 | * cx_compare_func comparator, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
321 | * size_t elem_size |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
322 | * ) { |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
323 | * if (allocator == NULL) { |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
324 | * allocator = cxDefaultAllocator; |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
325 | * } |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
326 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
327 | * MyCustomList *list = cxCalloc(allocator, 1, sizeof(MyCustomList)); |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
328 | * if (list == NULL) return NULL; |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
329 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
330 | * // initialize |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
331 | * cx_list_init((CxList*)list, &my_custom_list_class, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
332 | * allocator, comparator, elem_size); |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
333 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
334 | * // ... some more custom stuff ... |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
335 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
336 | * return (CxList *) list; |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
337 | * } |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
338 | * @endcode |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
339 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
340 | * @param list the list to initialize |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
341 | * @param cl the list class |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
342 | * @param allocator the allocator for the elements |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
343 | * @param comparator a compare function for the elements |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
344 | * @param elem_size the size of one element |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
345 | */ |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
346 | cx_attr_nonnull_arg(1, 2, 3) |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
347 | cx_attr_export |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
348 | void cx_list_init( |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
349 | struct cx_list_s *list, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
350 | struct cx_list_class_s *cl, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
351 | const struct cx_allocator_s *allocator, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
352 | cx_compare_func comparator, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
353 | size_t elem_size |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
354 | ); |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
355 | |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
356 | /** |
| 174 | 357 | * Returns the number of elements currently stored in the list. |
| 358 | * | |
| 359 | * @param list the list | |
| 360 | * @return the number of currently stored elements | |
| 361 | */ | |
| 440 | 362 | cx_attr_nonnull |
| 324 | 363 | static inline size_t cxListSize(const CxList *list) { |
| 364 | return list->collection.size; | |
| 174 | 365 | } |
| 366 | ||
| 367 | /** | |
| 368 | * Adds an item to the end of the list. | |
| 369 | * | |
| 370 | * @param list the list | |
| 371 | * @param elem a pointer to the element to add | |
| 440 | 372 | * @retval zero success |
| 373 | * @retval non-zero memory allocation failure | |
| 174 | 374 | * @see cxListAddArray() |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
375 | * @see cxListEmplace() |
| 174 | 376 | */ |
| 440 | 377 | cx_attr_nonnull |
| 174 | 378 | static inline int cxListAdd( |
| 379 | CxList *list, | |
| 324 | 380 | const void *elem |
| 174 | 381 | ) { |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
382 | list->collection.sorted = false; |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
383 | return list->cl->insert_element(list, list->collection.size, elem) == NULL; |
| 174 | 384 | } |
| 385 | ||
| 386 | /** | |
| 387 | * Adds multiple items to the end of the list. | |
| 388 | * | |
| 389 | * This method is more efficient than invoking cxListAdd() multiple times. | |
| 390 | * | |
| 391 | * If there is not enough memory to add all elements, the returned value is | |
| 440 | 392 | * less than @p n. |
| 174 | 393 | * |
| 440 | 394 | * If this list is storing pointers instead of objects @p array is expected to |
| 174 | 395 | * be an array of pointers. |
| 396 | * | |
| 397 | * @param list the list | |
| 398 | * @param array a pointer to the elements to add | |
| 399 | * @param n the number of elements to add | |
| 400 | * @return the number of added elements | |
| 401 | */ | |
| 440 | 402 | cx_attr_nonnull |
| 174 | 403 | static inline size_t cxListAddArray( |
| 404 | CxList *list, | |
| 324 | 405 | const void *array, |
| 174 | 406 | size_t n |
| 407 | ) { | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
408 | list->collection.sorted = false; |
| 324 | 409 | return list->cl->insert_array(list, list->collection.size, array, n); |
| 174 | 410 | } |
| 411 | ||
| 412 | /** | |
| 413 | * Inserts an item at the specified index. | |
| 414 | * | |
| 440 | 415 | * If @p index equals the list @c size, this is effectively cxListAdd(). |
| 174 | 416 | * |
| 417 | * @param list the list | |
| 418 | * @param index the index the element shall have | |
| 419 | * @param elem a pointer to the element to add | |
| 440 | 420 | * @retval zero success |
| 421 | * @retval non-zero memory allocation failure or the index is out of bounds | |
| 174 | 422 | * @see cxListInsertAfter() |
| 423 | * @see cxListInsertBefore() | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
424 | * @see cxListEmplaceAt() |
| 174 | 425 | */ |
| 440 | 426 | cx_attr_nonnull |
| 174 | 427 | static inline int cxListInsert( |
| 428 | CxList *list, | |
| 429 | size_t index, | |
| 324 | 430 | const void *elem |
| 174 | 431 | ) { |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
432 | list->collection.sorted = false; |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
433 | return list->cl->insert_element(list, index, elem) == NULL; |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
434 | } |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
435 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
436 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
437 | * Allocates memory for an element at the specified index and returns a pointer to that memory. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
438 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
439 | * @remark When the list is storing pointers, this will return a @c void**. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
440 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
441 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
442 | * @param index the index where to emplace the element |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
443 | * @return a pointer to the allocated memory; @c NULL when the operation fails, or the index is out-of-bounds |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
444 | * @see cxListEmplace() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
445 | * @see cxListInsert() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
446 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
447 | cx_attr_nonnull |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
448 | static inline void *cxListEmplaceAt(CxList *list, size_t index) { |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
449 | list->collection.sorted = false; |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
450 | return list->cl->insert_element(list, index, NULL); |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
451 | } |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
452 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
453 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
454 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
455 | * Allocates memory for an element at the end of the list and returns a pointer to that memory. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
456 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
457 | * @remark When the list is storing pointers, this will return a @c void**. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
458 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
459 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
460 | * @return a pointer to the allocated memory; @c NULL when the operation fails, or the index is out-of-bounds |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
461 | * @see cxListEmplaceAt() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
462 | * @see cxListAdd() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
463 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
464 | cx_attr_nonnull |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
465 | static inline void *cxListEmplace(CxList *list) { |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
466 | list->collection.sorted = false; |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
467 | return list->cl->insert_element(list, list->collection.size, NULL); |
| 174 | 468 | } |
| 469 | ||
| 470 | /** | |
| 324 | 471 | * Inserts an item into a sorted list. |
| 472 | * | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
473 | * If the list is not sorted already, the behavior is undefined. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
474 | * |
| 324 | 475 | * @param list the list |
| 476 | * @param elem a pointer to the element to add | |
| 440 | 477 | * @retval zero success |
| 478 | * @retval non-zero memory allocation failure | |
| 324 | 479 | */ |
| 440 | 480 | cx_attr_nonnull |
| 324 | 481 | static inline int cxListInsertSorted( |
| 482 | CxList *list, | |
| 483 | const void *elem | |
| 484 | ) { | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
485 | list->collection.sorted = true; // guaranteed by definition |
| 324 | 486 | const void *data = list->collection.store_pointer ? &elem : elem; |
| 487 | return list->cl->insert_sorted(list, data, 1) == 0; | |
| 488 | } | |
| 489 | ||
| 490 | /** | |
| 174 | 491 | * Inserts multiple items to the list at the specified index. |
| 440 | 492 | * If @p index equals the list size, this is effectively cxListAddArray(). |
| 174 | 493 | * |
| 494 | * This method is usually more efficient than invoking cxListInsert() | |
| 495 | * multiple times. | |
| 496 | * | |
| 497 | * If there is not enough memory to add all elements, the returned value is | |
| 440 | 498 | * less than @p n. |
| 174 | 499 | * |
| 440 | 500 | * If this list is storing pointers instead of objects @p array is expected to |
| 174 | 501 | * be an array of pointers. |
| 502 | * | |
| 503 | * @param list the list | |
| 504 | * @param index the index where to add the elements | |
| 505 | * @param array a pointer to the elements to add | |
| 506 | * @param n the number of elements to add | |
| 507 | * @return the number of added elements | |
| 508 | */ | |
| 440 | 509 | cx_attr_nonnull |
| 174 | 510 | static inline size_t cxListInsertArray( |
| 511 | CxList *list, | |
| 512 | size_t index, | |
| 324 | 513 | const void *array, |
| 174 | 514 | size_t n |
| 515 | ) { | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
516 | list->collection.sorted = false; |
| 174 | 517 | return list->cl->insert_array(list, index, array, n); |
| 518 | } | |
| 519 | ||
| 520 | /** | |
| 324 | 521 | * Inserts a sorted array into a sorted list. |
| 522 | * | |
| 523 | * This method is usually more efficient than inserting each element separately, | |
| 524 | * because consecutive chunks of sorted data are inserted in one pass. | |
| 525 | * | |
| 526 | * If there is not enough memory to add all elements, the returned value is | |
| 440 | 527 | * less than @p n. |
| 324 | 528 | * |
| 440 | 529 | * If this list is storing pointers instead of objects @p array is expected to |
| 324 | 530 | * be an array of pointers. |
| 531 | * | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
532 | * If the list is not sorted already, the behavior is undefined. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
533 | * |
| 324 | 534 | * @param list the list |
| 535 | * @param array a pointer to the elements to add | |
| 536 | * @param n the number of elements to add | |
| 537 | * @return the number of added elements | |
| 538 | */ | |
| 440 | 539 | cx_attr_nonnull |
| 324 | 540 | static inline size_t cxListInsertSortedArray( |
| 541 | CxList *list, | |
| 542 | const void *array, | |
| 543 | size_t n | |
| 544 | ) { | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
545 | list->collection.sorted = true; // guaranteed by definition |
| 324 | 546 | return list->cl->insert_sorted(list, array, n); |
| 547 | } | |
| 548 | ||
| 549 | /** | |
| 174 | 550 | * Inserts an element after the current location of the specified iterator. |
| 551 | * | |
| 552 | * The used iterator remains operational, but all other active iterators should | |
| 553 | * be considered invalidated. | |
| 554 | * | |
| 440 | 555 | * If @p iter is not a list iterator, the behavior is undefined. |
| 556 | * If @p iter is a past-the-end iterator, the new element gets appended to the list. | |
| 174 | 557 | * |
| 558 | * @param iter an iterator | |
| 559 | * @param elem the element to insert | |
| 440 | 560 | * @retval zero success |
| 561 | * @retval non-zero memory allocation failure | |
| 174 | 562 | * @see cxListInsert() |
| 563 | * @see cxListInsertBefore() | |
| 564 | */ | |
| 440 | 565 | cx_attr_nonnull |
| 174 | 566 | static inline int cxListInsertAfter( |
| 324 | 567 | CxIterator *iter, |
| 568 | const void *elem | |
| 174 | 569 | ) { |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
570 | CxList* list = (CxList*)iter->src_handle.m; |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
571 | list->collection.sorted = false; |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
572 | return list->cl->insert_iter(iter, elem, 0); |
| 174 | 573 | } |
| 574 | ||
| 575 | /** | |
| 576 | * Inserts an element before the current location of the specified iterator. | |
| 577 | * | |
| 578 | * The used iterator remains operational, but all other active iterators should | |
| 579 | * be considered invalidated. | |
| 580 | * | |
| 440 | 581 | * If @p iter is not a list iterator, the behavior is undefined. |
| 582 | * If @p iter is a past-the-end iterator, the new element gets appended to the list. | |
| 174 | 583 | * |
| 584 | * @param iter an iterator | |
| 585 | * @param elem the element to insert | |
| 440 | 586 | * @retval zero success |
| 587 | * @retval non-zero memory allocation failure | |
| 174 | 588 | * @see cxListInsert() |
| 589 | * @see cxListInsertAfter() | |
| 590 | */ | |
| 440 | 591 | cx_attr_nonnull |
| 174 | 592 | static inline int cxListInsertBefore( |
| 324 | 593 | CxIterator *iter, |
| 594 | const void *elem | |
| 174 | 595 | ) { |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
596 | CxList* list = (CxList*)iter->src_handle.m; |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
597 | list->collection.sorted = false; |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
598 | return list->cl->insert_iter(iter, elem, 1); |
| 174 | 599 | } |
| 600 | ||
| 601 | /** | |
| 602 | * Removes the element at the specified index. | |
| 603 | * | |
| 604 | * If an element destructor function is specified, it is called before | |
| 605 | * removing the element. | |
| 606 | * | |
| 607 | * @param list the list | |
| 608 | * @param index the index of the element | |
| 440 | 609 | * @retval zero success |
| 610 | * @retval non-zero index out of bounds | |
| 174 | 611 | */ |
| 440 | 612 | cx_attr_nonnull |
| 174 | 613 | static inline int cxListRemove( |
| 614 | CxList *list, | |
| 615 | size_t index | |
| 616 | ) { | |
| 440 | 617 | return list->cl->remove(list, index, 1, NULL) == 0; |
| 618 | } | |
| 619 | ||
| 620 | /** | |
| 621 | * Removes and returns the element at the specified index. | |
| 622 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
623 | * No destructor is called, and instead the element is copied to the |
| 440 | 624 | * @p targetbuf which MUST be large enough to hold the removed element. |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
625 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
| 440 | 626 | * |
| 627 | * @param list the list | |
| 628 | * @param index the index of the element | |
| 629 | * @param targetbuf a buffer where to copy the element | |
| 630 | * @retval zero success | |
| 631 | * @retval non-zero index out of bounds | |
| 632 | */ | |
| 633 | cx_attr_nonnull | |
| 634 | cx_attr_access_w(3) | |
| 635 | static inline int cxListRemoveAndGet( | |
| 636 | CxList *list, | |
| 637 | size_t index, | |
| 638 | void *targetbuf | |
| 639 | ) { | |
| 640 | return list->cl->remove(list, index, 1, targetbuf) == 0; | |
| 641 | } | |
| 642 | ||
| 643 | /** | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
644 | * Removes and returns the first element of the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
645 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
646 | * No destructor is called, and instead the element is copied to the |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
647 | * @p targetbuf which MUST be large enough to hold the removed element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
648 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
649 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
650 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
651 | * @param targetbuf a buffer where to copy the element |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
652 | * @retval zero success |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
653 | * @retval non-zero list is empty |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
654 | * @see cxListPopFront() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
655 | * @see cxListRemoveAndGetLast() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
656 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
657 | cx_attr_nonnull |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
658 | cx_attr_access_w(2) |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
659 | static inline int cxListRemoveAndGetFirst( |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
660 | CxList *list, |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
661 | void *targetbuf |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
662 | ) { |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
663 | return list->cl->remove(list, 0, 1, targetbuf) == 0; |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
664 | } |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
665 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
666 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
667 | * Removes and returns the first element of the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
668 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
669 | * Alias for cxListRemoveAndGetFirst(). |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
670 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
671 | * No destructor is called, and instead the element is copied to the |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
672 | * @p targetbuf which MUST be large enough to hold the removed element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
673 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
674 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
675 | * @param list (@c CxList*) the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
676 | * @param targetbuf (@c void*) a buffer where to copy the element |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
677 | * @retval zero success |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
678 | * @retval non-zero list is empty |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
679 | * @see cxListRemoveAndGetFirst() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
680 | * @see cxListPop() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
681 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
682 | #define cxListPopFront(list, targetbuf) cxListRemoveAndGetFirst((list), (targetbuf)) |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
683 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
684 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
685 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
686 | * Removes and returns the last element of the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
687 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
688 | * No destructor is called, and instead the element is copied to the |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
689 | * @p targetbuf which MUST be large enough to hold the removed element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
690 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
691 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
692 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
693 | * @param targetbuf a buffer where to copy the element |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
694 | * @retval zero success |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
695 | * @retval non-zero list is empty |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
696 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
697 | cx_attr_nonnull |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
698 | cx_attr_access_w(2) |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
699 | static inline int cxListRemoveAndGetLast( |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
700 | CxList *list, |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
701 | void *targetbuf |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
702 | ) { |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
703 | // note: index may wrap - member function will catch that |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
704 | return list->cl->remove(list, list->collection.size - 1, 1, targetbuf) == 0; |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
705 | } |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
706 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
707 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
708 | * Removes and returns the last element of the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
709 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
710 | * Alias for cxListRemoveAndGetLast(). |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
711 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
712 | * No destructor is called, and instead the element is copied to the |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
713 | * @p targetbuf which MUST be large enough to hold the removed element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
714 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
715 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
716 | * @param list (@c CxList*) the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
717 | * @param targetbuf (@c void*) a buffer where to copy the element |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
718 | * @retval zero success |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
719 | * @retval non-zero list is empty |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
720 | * @see cxListRemoveAndGetLast() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
721 | * @see cxListPopFront() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
722 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
723 | #define cxListPop(list, targetbuf) cxListRemoveAndGetLast((list), (targetbuf)) |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
724 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
725 | /** |
| 440 | 726 | * Removes multiple element starting at the specified index. |
| 727 | * | |
| 728 | * If an element destructor function is specified, it is called for each | |
| 729 | * element. It is guaranteed that the destructor is called before removing | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
730 | * the element. However, due to possible optimizations, it is neither guaranteed |
| 440 | 731 | * that the destructors are invoked for all elements before starting to remove |
| 732 | * them, nor that the element is removed immediately after the destructor call | |
| 733 | * before proceeding to the next element. | |
| 734 | * | |
| 735 | * @param list the list | |
| 736 | * @param index the index of the element | |
| 737 | * @param num the number of elements to remove | |
| 738 | * @return the actual number of removed elements | |
| 739 | */ | |
| 740 | cx_attr_nonnull | |
| 741 | static inline size_t cxListRemoveArray( | |
| 742 | CxList *list, | |
| 743 | size_t index, | |
| 744 | size_t num | |
| 745 | ) { | |
| 746 | return list->cl->remove(list, index, num, NULL); | |
| 747 | } | |
| 748 | ||
| 749 | /** | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
750 | * Removes and returns multiple elements starting at the specified index. |
| 440 | 751 | * |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
752 | * No destructor is called, and instead the elements are copied to the |
| 440 | 753 | * @p targetbuf which MUST be large enough to hold all removed elements. |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
754 | * If the list is storing pointers, @p targetbuf is expected to be an array of pointers. |
| 440 | 755 | * |
| 756 | * @param list the list | |
| 757 | * @param index the index of the element | |
| 758 | * @param num the number of elements to remove | |
| 759 | * @param targetbuf a buffer where to copy the elements | |
| 760 | * @return the actual number of removed elements | |
| 761 | */ | |
| 762 | cx_attr_nonnull | |
| 763 | cx_attr_access_w(4) | |
| 764 | static inline size_t cxListRemoveArrayAndGet( | |
| 765 | CxList *list, | |
| 766 | size_t index, | |
| 767 | size_t num, | |
| 768 | void *targetbuf | |
| 769 | ) { | |
| 770 | return list->cl->remove(list, index, num, targetbuf); | |
| 174 | 771 | } |
| 772 | ||
| 773 | /** | |
| 774 | * Removes all elements from this list. | |
| 775 | * | |
| 440 | 776 | * If element destructor functions are specified, they are called for each |
| 174 | 777 | * element before removing them. |
| 778 | * | |
| 779 | * @param list the list | |
| 780 | */ | |
| 440 | 781 | cx_attr_nonnull |
| 174 | 782 | static inline void cxListClear(CxList *list) { |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
783 | list->collection.sorted = true; // empty lists are always sorted |
| 174 | 784 | list->cl->clear(list); |
| 785 | } | |
| 786 | ||
| 787 | /** | |
| 788 | * Swaps two items in the list. | |
| 789 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
790 | * Implementations should only allocate temporary memory for the swap if |
| 174 | 791 | * it is necessary. |
| 792 | * | |
| 793 | * @param list the list | |
| 794 | * @param i the index of the first element | |
| 795 | * @param j the index of the second element | |
| 440 | 796 | * @retval zero success |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
797 | * @retval non-zero one of the indices is out of bounds, |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
798 | * or the swap needed extra memory, but allocation failed |
| 174 | 799 | */ |
| 440 | 800 | cx_attr_nonnull |
| 174 | 801 | static inline int cxListSwap( |
| 802 | CxList *list, | |
| 803 | size_t i, | |
| 804 | size_t j | |
| 805 | ) { | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
806 | list->collection.sorted = false; |
| 174 | 807 | return list->cl->swap(list, i, j); |
| 808 | } | |
| 809 | ||
| 810 | /** | |
| 811 | * Returns a pointer to the element at the specified index. | |
| 812 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
813 | * If the list is storing pointers, returns the pointer stored at the specified index. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
814 | * |
| 174 | 815 | * @param list the list |
| 816 | * @param index the index of the element | |
| 440 | 817 | * @return a pointer to the element or @c NULL if the index is out of bounds |
| 174 | 818 | */ |
| 440 | 819 | cx_attr_nonnull |
| 174 | 820 | static inline void *cxListAt( |
| 440 | 821 | const CxList *list, |
| 174 | 822 | size_t index |
| 823 | ) { | |
| 824 | return list->cl->at(list, index); | |
| 825 | } | |
| 826 | ||
| 827 | /** | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
828 | * Returns a pointer to the first element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
829 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
830 | * If the list is storing pointers, returns the first pointer stored in the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
831 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
832 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
833 | * @return a pointer to the first element or @c NULL if the list is empty |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
834 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
835 | cx_attr_nonnull |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
836 | static inline void *cxListFirst(const CxList *list) { |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
837 | return list->cl->at(list, 0); |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
838 | } |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
839 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
840 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
841 | * Returns a pointer to the last element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
842 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
843 | * If the list is storing pointers, returns the last pointer stored in the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
844 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
845 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
846 | * @return a pointer to the last element or @c NULL if the list is empty |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
847 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
848 | cx_attr_nonnull |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
849 | static inline void *cxListLast(const CxList *list) { |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
850 | return list->cl->at(list, list->collection.size - 1); |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
851 | } |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
852 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
853 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
854 | * Sets the element at the specified index in the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
855 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
856 | * @param list the list to set the element in |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
857 | * @param index the index to set the element at |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
858 | * @param elem element to set |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
859 | * @retval zero on success |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
860 | * @retval non-zero when index is out of bounds |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
861 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
862 | cx_attr_nonnull |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
863 | cx_attr_export |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
864 | int cxListSet( |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
865 | CxList *list, |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
866 | size_t index, |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
867 | const void *elem |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
868 | ); |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
869 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
870 | /** |
| 174 | 871 | * Returns an iterator pointing to the item at the specified index. |
| 872 | * | |
| 873 | * The returned iterator is position-aware. | |
| 874 | * | |
| 875 | * If the index is out of range, a past-the-end iterator will be returned. | |
| 876 | * | |
| 877 | * @param list the list | |
| 878 | * @param index the index where the iterator shall point at | |
| 879 | * @return a new iterator | |
| 880 | */ | |
| 440 | 881 | cx_attr_nonnull |
| 882 | cx_attr_nodiscard | |
| 174 | 883 | static inline CxIterator cxListIteratorAt( |
| 324 | 884 | const CxList *list, |
| 174 | 885 | size_t index |
| 886 | ) { | |
| 887 | return list->cl->iterator(list, index, false); | |
| 888 | } | |
| 889 | ||
| 890 | /** | |
| 891 | * Returns a backwards iterator pointing to the item at the specified index. | |
| 892 | * | |
| 893 | * The returned iterator is position-aware. | |
| 894 | * | |
| 895 | * If the index is out of range, a past-the-end iterator will be returned. | |
| 896 | * | |
| 897 | * @param list the list | |
| 898 | * @param index the index where the iterator shall point at | |
| 899 | * @return a new iterator | |
| 900 | */ | |
| 440 | 901 | cx_attr_nonnull |
| 902 | cx_attr_nodiscard | |
| 174 | 903 | static inline CxIterator cxListBackwardsIteratorAt( |
| 324 | 904 | const CxList *list, |
| 174 | 905 | size_t index |
| 906 | ) { | |
| 907 | return list->cl->iterator(list, index, true); | |
| 908 | } | |
| 909 | ||
| 910 | /** | |
| 911 | * Returns a mutating iterator pointing to the item at the specified index. | |
| 912 | * | |
| 913 | * The returned iterator is position-aware. | |
| 914 | * | |
| 915 | * If the index is out of range, a past-the-end iterator will be returned. | |
| 916 | * | |
| 917 | * @param list the list | |
| 918 | * @param index the index where the iterator shall point at | |
| 919 | * @return a new iterator | |
| 920 | */ | |
| 440 | 921 | cx_attr_nonnull |
| 922 | cx_attr_nodiscard | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
923 | cx_attr_export |
| 324 | 924 | CxIterator cxListMutIteratorAt( |
| 174 | 925 | CxList *list, |
| 926 | size_t index | |
| 927 | ); | |
| 928 | ||
| 929 | /** | |
| 930 | * Returns a mutating backwards iterator pointing to the item at the | |
| 931 | * specified index. | |
| 932 | * | |
| 933 | * The returned iterator is position-aware. | |
| 934 | * | |
| 935 | * If the index is out of range, a past-the-end iterator will be returned. | |
| 936 | * | |
| 937 | * @param list the list | |
| 938 | * @param index the index where the iterator shall point at | |
| 939 | * @return a new iterator | |
| 940 | */ | |
| 440 | 941 | cx_attr_nonnull |
| 942 | cx_attr_nodiscard | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
943 | cx_attr_export |
| 324 | 944 | CxIterator cxListMutBackwardsIteratorAt( |
| 174 | 945 | CxList *list, |
| 946 | size_t index | |
| 947 | ); | |
| 948 | ||
| 949 | /** | |
| 950 | * Returns an iterator pointing to the first item of the list. | |
| 951 | * | |
| 952 | * The returned iterator is position-aware. | |
| 953 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
954 | * If the list is empty or @c NULL, a past-the-end iterator will be returned. |
| 174 | 955 | * |
| 956 | * @param list the list | |
| 957 | * @return a new iterator | |
| 958 | */ | |
| 440 | 959 | cx_attr_nodiscard |
| 324 | 960 | static inline CxIterator cxListIterator(const CxList *list) { |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
961 | if (list == NULL) list = cxEmptyList; |
| 174 | 962 | return list->cl->iterator(list, 0, false); |
| 963 | } | |
| 964 | ||
| 965 | /** | |
| 966 | * Returns a mutating iterator pointing to the first item of the list. | |
| 967 | * | |
| 968 | * The returned iterator is position-aware. | |
| 969 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
970 | * If the list is empty or @c NULL, a past-the-end iterator will be returned. |
| 174 | 971 | * |
| 972 | * @param list the list | |
| 973 | * @return a new iterator | |
| 974 | */ | |
| 440 | 975 | cx_attr_nodiscard |
| 324 | 976 | static inline CxIterator cxListMutIterator(CxList *list) { |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
977 | if (list == NULL) list = cxEmptyList; |
| 174 | 978 | return cxListMutIteratorAt(list, 0); |
| 979 | } | |
| 980 | ||
| 981 | ||
| 982 | /** | |
| 983 | * Returns a backwards iterator pointing to the last item of the list. | |
| 984 | * | |
| 985 | * The returned iterator is position-aware. | |
| 986 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
987 | * If the list is empty or @c NULL, a past-the-end iterator will be returned. |
| 174 | 988 | * |
| 989 | * @param list the list | |
| 990 | * @return a new iterator | |
| 991 | */ | |
| 440 | 992 | cx_attr_nodiscard |
| 324 | 993 | static inline CxIterator cxListBackwardsIterator(const CxList *list) { |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
994 | if (list == NULL) list = cxEmptyList; |
| 324 | 995 | return list->cl->iterator(list, list->collection.size - 1, true); |
| 174 | 996 | } |
| 997 | ||
| 998 | /** | |
| 999 | * Returns a mutating backwards iterator pointing to the last item of the list. | |
| 1000 | * | |
| 1001 | * The returned iterator is position-aware. | |
| 1002 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1003 | * If the list is empty or @c NULL, a past-the-end iterator will be returned. |
| 174 | 1004 | * |
| 1005 | * @param list the list | |
| 1006 | * @return a new iterator | |
| 1007 | */ | |
| 440 | 1008 | cx_attr_nodiscard |
| 324 | 1009 | static inline CxIterator cxListMutBackwardsIterator(CxList *list) { |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1010 | if (list == NULL) list = cxEmptyList; |
| 324 | 1011 | return cxListMutBackwardsIteratorAt(list, list->collection.size - 1); |
| 174 | 1012 | } |
| 1013 | ||
| 1014 | /** | |
| 440 | 1015 | * Returns the index of the first element that equals @p elem. |
| 174 | 1016 | * |
| 1017 | * Determining equality is performed by the list's comparator function. | |
| 1018 | * | |
| 1019 | * @param list the list | |
| 1020 | * @param elem the element to find | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1021 | * @return the index of the element or the size of the list when the element is not found |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1022 | * @see cxListIndexValid() |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1023 | * @see cxListContains() |
| 174 | 1024 | */ |
| 440 | 1025 | cx_attr_nonnull |
| 1026 | cx_attr_nodiscard | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1027 | static inline size_t cxListFind( |
| 324 | 1028 | const CxList *list, |
| 1029 | const void *elem | |
| 174 | 1030 | ) { |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1031 | return list->cl->find_remove((CxList*)list, elem, false); |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1032 | } |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1033 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1034 | /** |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1035 | * Checks, if the list contains the specified element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1036 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1037 | * The elements are compared with the list's comparator function. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1038 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1039 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1040 | * @param elem the element to find |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1041 | * @retval true if the element is contained |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1042 | * @retval false if the element is not contained |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1043 | * @see cxListFind() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1044 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1045 | cx_attr_nonnull |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1046 | cx_attr_nodiscard |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1047 | static inline bool cxListContains( |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1048 | const CxList* list, |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1049 | const void* elem |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1050 | ) { |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1051 | return list->cl->find_remove((CxList*)list, elem, false) < list->collection.size; |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1052 | } |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1053 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1054 | /** |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1055 | * Checks if the specified index is within bounds. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1056 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1057 | * @param list the list |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1058 | * @param index the index |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1059 | * @retval true if the index is within bounds |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1060 | * @retval false if the index is out of bounds |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1061 | */ |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1062 | cx_attr_nonnull |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1063 | cx_attr_nodiscard |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1064 | static inline bool cxListIndexValid(const CxList *list, size_t index) { |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1065 | return index < list->collection.size; |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1066 | } |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1067 | |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1068 | /** |
| 440 | 1069 | * Removes and returns the index of the first element that equals @p elem. |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1070 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1071 | * Determining equality is performed by the list's comparator function. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1072 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1073 | * @param list the list |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1074 | * @param elem the element to find and remove |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1075 | * @return the index of the now removed element or the list size |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1076 | * when the element is not found or could not be removed |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1077 | * @see cxListIndexValid() |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1078 | */ |
| 440 | 1079 | cx_attr_nonnull |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1080 | static inline size_t cxListFindRemove( |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1081 | CxList *list, |
| 324 | 1082 | const void *elem |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1083 | ) { |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
1084 | return list->cl->find_remove(list, elem, true); |
| 174 | 1085 | } |
| 1086 | ||
| 1087 | /** | |
| 440 | 1088 | * Sorts the list. |
| 174 | 1089 | * |
| 440 | 1090 | * @remark The underlying sort algorithm is implementation defined. |
| 174 | 1091 | * |
| 1092 | * @param list the list | |
| 1093 | */ | |
| 440 | 1094 | cx_attr_nonnull |
| 174 | 1095 | static inline void cxListSort(CxList *list) { |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1096 | if (list->collection.sorted) return; |
| 174 | 1097 | list->cl->sort(list); |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1098 | list->collection.sorted = true; |
| 174 | 1099 | } |
| 1100 | ||
| 1101 | /** | |
| 1102 | * Reverses the order of the items. | |
| 1103 | * | |
| 1104 | * @param list the list | |
| 1105 | */ | |
| 440 | 1106 | cx_attr_nonnull |
| 174 | 1107 | static inline void cxListReverse(CxList *list) { |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1108 | // still sorted, but not according to the cmp_func |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1109 | list->collection.sorted = false; |
| 174 | 1110 | list->cl->reverse(list); |
| 1111 | } | |
| 1112 | ||
| 1113 | /** | |
| 1114 | * Compares a list to another list of the same type. | |
| 1115 | * | |
| 1116 | * First, the list sizes are compared. | |
| 1117 | * If they match, the lists are compared element-wise. | |
| 1118 | * | |
| 1119 | * @param list the list | |
| 1120 | * @param other the list to compare to | |
| 440 | 1121 | * @retval zero both lists are equal element wise |
| 1122 | * @retval negative the first list is smaller | |
| 1123 | * or the first non-equal element in the first list is smaller | |
| 1124 | * @retval positive the first list is larger | |
| 1125 | * or the first non-equal element in the first list is larger | |
| 174 | 1126 | */ |
| 440 | 1127 | cx_attr_nonnull |
| 1128 | cx_attr_nodiscard | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1129 | cx_attr_export |
| 174 | 1130 | int cxListCompare( |
| 324 | 1131 | const CxList *list, |
| 1132 | const CxList *other | |
| 174 | 1133 | ); |
| 1134 | ||
| 1135 | /** | |
| 1136 | * Deallocates the memory of the specified list structure. | |
| 1137 | * | |
| 440 | 1138 | * Also calls the content destructor functions for each element, if specified. |
| 174 | 1139 | * |
| 440 | 1140 | * @param list the list which shall be freed |
| 174 | 1141 | */ |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1142 | cx_attr_export |
| 440 | 1143 | void cxListFree(CxList *list); |
| 174 | 1144 | |
| 1145 | ||
| 1146 | #ifdef __cplusplus | |
| 1147 | } // extern "C" | |
| 1148 | #endif | |
| 1149 | ||
| 1150 | #endif // UCX_LIST_H |