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