Wed, 31 Dec 2025 16:40:12 +0100
update ucx to version 4.0
| 174 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * | |
| 4 | * Copyright 2023 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 collection.h |
| 30 | * @brief Common definitions for various collection implementations. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
| 174 | 34 | */ |
| 35 | ||
| 36 | #ifndef UCX_COLLECTION_H | |
| 37 | #define UCX_COLLECTION_H | |
| 38 | ||
| 39 | #include "allocator.h" | |
| 40 | #include "iterator.h" | |
| 324 | 41 | #include "compare.h" |
| 174 | 42 | |
| 43 | /** | |
| 44 | * Special constant used for creating collections that are storing pointers. | |
| 45 | */ | |
| 46 | #define CX_STORE_POINTERS 0 | |
| 47 | ||
| 48 | /** | |
| 324 | 49 | * Base attributes of a collection. |
| 174 | 50 | */ |
| 324 | 51 | struct cx_collection_s { |
| 52 | /** | |
| 53 | * The allocator to use. | |
| 54 | */ | |
| 55 | const CxAllocator *allocator; | |
| 56 | /** | |
| 57 | * The size of each element. | |
| 58 | */ | |
| 59 | size_t elem_size; | |
| 60 | /** | |
| 61 | * The number of currently stored elements. | |
| 62 | */ | |
| 63 | size_t size; | |
| 64 | /** | |
| 1016 | 65 | * A two-argument comparator function for the elements. |
| 66 | */ | |
| 67 | cx_compare_func simple_cmp; | |
| 68 | /** | |
| 69 | * A three-argument comparator function for the elements. | |
| 70 | * If specified, this function has precedence over the @c simple_cmp function. | |
| 71 | */ | |
| 72 | cx_compare_func2 advanced_cmp; | |
| 73 | /** | |
| 74 | * A pointer to custom data for the @c advanced_cmp function | |
| 75 | */ | |
| 76 | void *cmp_data; | |
| 77 | /** | |
| 324 | 78 | * An optional simple destructor for the collection's elements. |
| 79 | * | |
| 80 | * @attention Read the documentation of the particular collection implementation | |
| 81 | * whether this destructor shall only destroy the contents or also free the memory. | |
| 82 | */ | |
| 83 | cx_destructor_func simple_destructor; | |
| 84 | /** | |
| 85 | * An optional advanced destructor for the collection's elements. | |
| 86 | * | |
| 87 | * @attention Read the documentation of the particular collection implementation | |
| 88 | * whether this destructor shall only destroy the contents or also free the memory. | |
| 89 | */ | |
| 90 | cx_destructor_func2 advanced_destructor; | |
| 91 | /** | |
| 92 | * The pointer to additional data that is passed to the advanced destructor. | |
| 93 | */ | |
| 94 | void *destructor_data; | |
| 95 | /** | |
| 96 | * Indicates if this list is supposed to store pointers | |
| 97 | * instead of copies of the actual objects. | |
| 98 | */ | |
| 99 | bool store_pointer; | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
100 | /** |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
101 | * Indicates if this collection is guaranteed to be sorted. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
102 | * Note that the elements can still be sorted, even when the collection is not aware of that. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
103 | */ |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
104 | bool sorted; |
| 324 | 105 | }; |
| 174 | 106 | |
| 107 | /** | |
| 108 | * Use this macro to declare common members for a collection structure. | |
| 440 | 109 | * |
| 110 | * @par Example Use | |
| 111 | * @code | |
| 112 | * struct MyCustomSet { | |
| 113 | * CX_COLLECTION_BASE; | |
| 114 | * MySetElements *data; | |
| 115 | * } | |
| 116 | * @endcode | |
| 174 | 117 | */ |
| 324 | 118 | #define CX_COLLECTION_BASE struct cx_collection_s collection |
| 119 | ||
| 120 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
121 | * Returns the number of elements currently stored. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
122 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
123 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
124 | * @return (@c size_t) the number of currently stored elements |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
125 | */ |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
126 | #define cxCollectionSize(c) ((c)->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
|
127 | |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
128 | /** |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
129 | * Returns 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
|
130 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
131 | * If #cxCollectionStoresPointers() returns true, this is the size of a pointer. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
132 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
133 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
134 | * @return (@c size_t) the size of one element in bytes |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
135 | */ |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
136 | #define cxCollectionElementSize(c) ((c)->collection.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
|
137 | |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
138 | /** |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
139 | * Indicates whether this collection only stores pointers instead of the actual data. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
140 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
141 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
142 | * @retval true if this collection stores only pointers to data |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
143 | * @retval false if this collection stores the actual element's data |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
144 | */ |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
145 | #define cxCollectionStoresPointers(c) ((c)->collection.store_pointer) |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
146 | |
| 1016 | 147 | |
| 148 | /** | |
| 149 | * Convenience macro for adding indirection to an element if the collection is storing pointers. | |
| 150 | * | |
| 151 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE | |
| 152 | * @param elem the pointer that shall be taken the address from, if the collection is storing pointers | |
| 153 | * @return if the collection is storing pointers, takes the address of @p elem, otherwise returns @p elem | |
| 154 | */ | |
| 155 | #define cx_ref(c, elem) (cxCollectionStoresPointers(c) ? ((void*)&(elem)) : (elem)) | |
| 156 | ||
| 157 | /** | |
| 158 | * Convenience macro for dereferencing an element if the collection is storing pointers. | |
| 159 | * | |
| 160 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE | |
| 161 | * @param elem a pointer to the collection element | |
| 162 | * @return if the collection is storing pointers, dereferences @p elem, otherwise returns @p elem | |
| 163 | */ | |
| 164 | #define cx_deref(c, elem) (cxCollectionStoresPointers(c) ? *((void**)(elem)) : (elem)) | |
| 165 | ||
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
166 | /** |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
167 | * Indicates whether the collection can guarantee that the stored elements are currently sorted. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
168 | * |
| 845 | 169 | * This may return @c false even when the elements are sorted. |
| 170 | * It is totally up to the implementation of the collection when to check if the elements are sorted. | |
| 171 | * It is usually a good practice to establish this property as an invariant that does not need | |
| 172 | * to be re-checked on certain operations. | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
173 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
174 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
175 | * @retval true if the elements are currently sorted wrt. the collection's compare function |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
176 | * @retval false if the order of elements is unknown |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
177 | */ |
| 870 | 178 | #define cxCollectionSorted(c) ((c)->collection.sorted || (c)->collection.size == 0) |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
179 | |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
180 | /** |
| 1016 | 181 | * Sets a simple compare function for a collection. |
| 182 | * | |
| 183 | * Erases a possible advanced compare function. | |
| 184 | * If you want to set both, because you want to access the simple function | |
| 185 | * in your advanced function, you must set the simple function first. | |
| 186 | * | |
| 187 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE | |
| 188 | * @param func (@c cx_compare_func) the compare function | |
| 189 | */ | |
| 190 | #define cxSetCompareFunc(c, func) \ | |
| 191 | (c)->collection.simple_cmp = (cx_compare_func)(func); \ | |
| 192 | (c)->collection.advanced_cmp = NULL | |
| 193 | ||
| 194 | /** | |
| 195 | * Sets an advanced compare function that supports custom data for a collection. | |
| 196 | * | |
| 197 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE | |
| 198 | * @param func (@c cx_compare_func2) the compare function | |
| 199 | * @param data (@c void*) the pointer to custom data that is passed to the compare function | |
| 200 | */ | |
| 201 | #define cxSetAdvancedCompareFunc(c, func, data) \ | |
| 202 | (c)->collection.advanced_cmp = (cx_compare_func2) func; \ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
203 | (c)->collection.cmp_data = data |
| 1016 | 204 | |
| 205 | /** | |
| 206 | * Invokes the simple comparator function for two elements. | |
| 207 | * | |
| 208 | * Usually only used by collection implementations. There should be no need | |
| 209 | * to invoke this macro manually. | |
|
943
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
210 | * |
|
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
211 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE |
| 1016 | 212 | * @param left (@c void*) pointer to data |
| 213 | * @param right (@c void*) pointer to data | |
| 214 | */ | |
| 215 | #define cx_invoke_simple_compare_func(c, left, right) \ | |
| 216 | (c)->collection.simple_cmp(left, right) | |
| 217 | ||
| 218 | /** | |
| 219 | * Invokes the advanced comparator function for two elements. | |
| 220 | * | |
| 221 | * Usually only used by collection implementations. There should be no need | |
| 222 | * to invoke this macro manually. | |
| 223 | * | |
| 224 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE | |
| 225 | * @param left (@c void*) pointer to data | |
| 226 | * @param right (@c void*) pointer to data | |
|
943
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
227 | */ |
| 1016 | 228 | #define cx_invoke_advanced_compare_func(c, left, right) \ |
| 229 | (c)->collection.advanced_cmp(left, right, (c)->collection.cmp_data) | |
| 230 | ||
| 231 | ||
| 232 | /** | |
| 233 | * Invokes the configured comparator function for two elements. | |
| 234 | * | |
| 235 | * Usually only used by collection implementations. There should be no need | |
| 236 | * to invoke this macro manually. | |
| 237 | * | |
| 238 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE | |
| 239 | * @param left (@c void*) pointer to data | |
| 240 | * @param right (@c void*) pointer to data | |
| 241 | */ | |
| 242 | #define cx_invoke_compare_func(c, left, right) \ | |
| 243 | (((c)->collection.advanced_cmp) ? \ | |
| 244 | cx_invoke_advanced_compare_func(c,left,right) : \ | |
| 245 | cx_invoke_simple_compare_func(c,left,right)) | |
|
943
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
246 | |
|
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
247 | /** |
| 324 | 248 | * Sets a simple destructor function for this collection. |
| 249 | * | |
| 440 | 250 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE |
| 1016 | 251 | * @param destr (@c cx_destructor_func) the destructor function |
| 324 | 252 | */ |
| 1016 | 253 | #define cxSetDestructor(c, destr) \ |
| 324 | 254 | (c)->collection.simple_destructor = (cx_destructor_func) destr |
| 255 | ||
| 256 | /** | |
| 1016 | 257 | * Sets an advanced destructor function for this collection. |
| 324 | 258 | * |
| 440 | 259 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE |
| 1016 | 260 | * @param destr (@c cx_destructor_func2) the destructor function |
| 261 | * @param data (@c void*) the additional data the advanced destructor is invoked with | |
| 324 | 262 | */ |
| 1016 | 263 | #define cxSetAdvancedDestructor(c, destr, data) \ |
| 324 | 264 | (c)->collection.advanced_destructor = (cx_destructor_func2) destr; \ |
| 265 | (c)->collection.destructor_data = data | |
| 174 | 266 | |
| 267 | /** | |
| 268 | * Invokes the simple destructor function for a specific element. | |
| 269 | * | |
| 270 | * Usually only used by collection implementations. There should be no need | |
| 271 | * to invoke this macro manually. | |
| 272 | * | |
| 440 | 273 | * When the collection stores pointers, those pointers are directly passed |
| 274 | * to the destructor. Otherwise, a pointer to the element is passed. | |
| 275 | * | |
| 276 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE | |
| 277 | * @param e the element (the type is @c void* or @c void** depending on context) | |
| 174 | 278 | */ |
| 279 | #define cx_invoke_simple_destructor(c, e) \ | |
| 324 | 280 | (c)->collection.simple_destructor((c)->collection.store_pointer ? (*((void **) (e))) : (e)) |
| 174 | 281 | |
| 282 | /** | |
| 283 | * Invokes the advanced destructor function for a specific element. | |
| 284 | * | |
| 285 | * Usually only used by collection implementations. There should be no need | |
| 286 | * to invoke this macro manually. | |
| 287 | * | |
| 440 | 288 | * When the collection stores pointers, those pointers are directly passed |
| 289 | * to the destructor. Otherwise, a pointer to the element is passed. | |
| 290 | * | |
| 291 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE | |
| 292 | * @param e the element (the type is @c void* or @c void** depending on context) | |
| 174 | 293 | */ |
| 294 | #define cx_invoke_advanced_destructor(c, e) \ | |
| 324 | 295 | (c)->collection.advanced_destructor((c)->collection.destructor_data, \ |
| 296 | (c)->collection.store_pointer ? (*((void **) (e))) : (e)) | |
| 174 | 297 | |
| 298 | ||
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
299 | /** |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
300 | * Invokes all available destructor functions for a specific element. |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
301 | * |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
302 | * Usually only used by collection implementations. There should be no need |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
303 | * to invoke this macro manually. |
|
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
304 | * |
| 440 | 305 | * When the collection stores pointers, those pointers are directly passed |
| 306 | * to the destructor. Otherwise, a pointer to the element is passed. | |
| 307 | * | |
| 308 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE | |
| 309 | * @param e the element (the type is @c void* or @c void** depending on context) | |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
310 | */ |
| 174 | 311 | #define cx_invoke_destructor(c, e) \ |
| 324 | 312 | if ((c)->collection.simple_destructor) cx_invoke_simple_destructor(c,e); \ |
| 313 | if ((c)->collection.advanced_destructor) cx_invoke_advanced_destructor(c,e) | |
| 174 | 314 | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
315 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
316 | * Invokes all available destructor functions for a specific element. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
317 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
318 | * Usually only used by collection implementations. There should be no need |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
319 | * to invoke this macro manually. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
320 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
321 | * In contrast to cx_invoke_destructor(), this macro does not automatically |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
322 | * dereference pointers to the elements when cxCollectionStoresPointers() |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
323 | * returns true. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
324 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
325 | * @param c a pointer to a struct that contains #CX_COLLECTION_BASE |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
326 | * @param e pointer to the element |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
327 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
328 | #define cx_invoke_destructor_raw(c, e) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
329 | if ((c)->collection.simple_destructor) (c)->collection.simple_destructor(e); \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
330 | if ((c)->collection.advanced_destructor) (c)->collection.advanced_destructor((c)->collection.destructor_data, e) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
331 | |
| 174 | 332 | |
| 333 | #endif // UCX_COLLECTION_H |