| 208 |
204 |
| 209 |
205 |
| 210 /** |
206 /** |
| 211 * Creates an iterator for the specified plain array. |
207 * Creates an iterator for the specified plain array. |
| 212 * |
208 * |
| 213 * The @p array can be @c NULL in which case the iterator will be immediately |
209 * The @p array can be @c NULL, in which case the iterator will be immediately |
| 214 * initialized such that #cxIteratorValid() returns @c false. |
210 * initialized such that #cxIteratorValid() returns @c false. |
| 215 * |
211 * |
| 216 * This iterator yields the addresses of the array elements. |
212 * This iterator yields the addresses of the array elements. |
| 217 * If you want to iterator over an array of pointers, you can |
213 * If you want to iterator over an array of pointers, you can |
| 218 * use cxIteratorPtr() to create an iterator which directly |
214 * use cxIteratorPtr() to create an iterator which directly |
| 219 * yields the stored pointers. |
215 * yields the stored pointers. |
| 220 * |
216 * |
| 221 * @param array a pointer to the array (can be @c NULL) |
|
| 222 * @param elem_size the size of one array element |
|
| 223 * @param elem_count the number of elements in the array |
|
| 224 * @return an iterator for the specified array |
|
| 225 * @see cxIteratorPtr() |
|
| 226 */ |
|
| 227 cx_attr_nodiscard |
|
| 228 cx_attr_export |
|
| 229 CxIterator cxIterator( |
|
| 230 const void *array, |
|
| 231 size_t elem_size, |
|
| 232 size_t elem_count |
|
| 233 ); |
|
| 234 |
|
| 235 /** |
|
| 236 * Creates a mutating iterator for the specified plain array. |
|
| 237 * |
|
| 238 * While the iterator is in use, the array may only be altered by removing |
217 * While the iterator is in use, the array may only be altered by removing |
| 239 * elements through #cxIteratorFlagRemoval(). Every other change to the array |
218 * elements through #cxIteratorFlagRemoval(). Every other change to the array |
| 240 * will bring this iterator to an undefined state. |
219 * will bring this iterator to an undefined state. |
| 241 * |
220 * |
| 242 * When @p remove_keeps_order is set to @c false, removing an element will only |
221 * When @p remove_keeps_order is set to @c false, removing an element will only |
| 243 * move the last element to the position of the removed element, instead of |
222 * move the last element to the position of the removed element, instead of |
| 244 * moving all subsequent elements by one. Usually, when the order of elements is |
223 * moving all subsequent elements by one. Usually, when the order of elements is |
| 245 * not important, this parameter should be set to @c false. |
224 * not important, this parameter should be set to @c false. |
| 246 * |
|
| 247 * The @p array can be @c NULL in which case the iterator will be immediately |
|
| 248 * initialized such that #cxIteratorValid() returns @c false. |
|
| 249 * |
|
| 250 * |
225 * |
| 251 * @param array a pointer to the array (can be @c NULL) |
226 * @param array a pointer to the array (can be @c NULL) |
| 252 * @param elem_size the size of one array element |
227 * @param elem_size the size of one array element |
| 253 * @param elem_count the number of elements in the array |
228 * @param elem_count the number of elements in the array |
| 254 * @param remove_keeps_order @c true if the order of elements must be preserved |
229 * @param remove_keeps_order @c true if the order of elements must be preserved |
| 255 * when removing an element |
230 * when removing an element |
| 256 * @return an iterator for the specified array |
231 * @return an iterator for the specified array |
| |
232 * @see cxIteratorPtr() |
| 257 */ |
233 */ |
| 258 cx_attr_nodiscard |
234 cx_attr_nodiscard |
| 259 cx_attr_export |
235 CX_EXPORT CxIterator cxIterator(const void *array, |
| 260 CxIterator cxMutIterator( |
236 size_t elem_size, size_t elem_count, bool remove_keeps_order); |
| 261 void *array, |
|
| 262 size_t elem_size, |
|
| 263 size_t elem_count, |
|
| 264 bool remove_keeps_order |
|
| 265 ); |
|
| 266 |
237 |
| 267 /** |
238 /** |
| 268 * Creates an iterator for the specified plain pointer array. |
239 * Creates an iterator for the specified plain pointer array. |
| 269 * |
240 * |
| 270 * This iterator assumes that every element in the array is a pointer |
241 * This iterator assumes that every element in the array is a pointer |
| 271 * and yields exactly those pointers during iteration (while in contrast |
242 * and yields exactly those pointers during iteration (on the other |
| 272 * an iterator created with cxIterator() would return the addresses |
243 * hand, an iterator created with cxIterator() would return the |
| 273 * of those pointers within the array). |
244 * addresses of those pointers within the array). |
| 274 * |
245 * |
| 275 * @param array a pointer to the array (can be @c NULL) |
246 * While the iterator is in use, the array may only be altered by removing |
| 276 * @param elem_count the number of elements in the array |
247 * elements through #cxIteratorFlagRemoval(). Every other change to the array |
| 277 * @return an iterator for the specified array |
248 * will bring this iterator to an undefined state. |
| 278 * @see cxIterator() |
249 * |
| 279 */ |
250 * When @p remove_keeps_order is set to @c false, removing an element will only |
| 280 cx_attr_nodiscard |
251 * move the last element to the position of the removed element, instead of |
| 281 cx_attr_export |
252 * moving all subsequent elements by one. Usually, when the order of elements is |
| 282 CxIterator cxIteratorPtr( |
253 * not important, this parameter should be set to @c false. |
| 283 const void *array, |
|
| 284 size_t elem_count |
|
| 285 ); |
|
| 286 |
|
| 287 /** |
|
| 288 * Creates a mutating iterator for the specified plain pointer array. |
|
| 289 * |
|
| 290 * This is the mutating variant of cxIteratorPtr(). See also |
|
| 291 * cxMutIterator(). |
|
| 292 * |
254 * |
| 293 * @param array a pointer to the array (can be @c NULL) |
255 * @param array a pointer to the array (can be @c NULL) |
| 294 * @param elem_count the number of elements in the array |
256 * @param elem_count the number of elements in the array |
| 295 * @param remove_keeps_order @c true if the order of elements must be preserved |
257 * @param remove_keeps_order @c true if the order of elements must be preserved |
| 296 * when removing an element |
258 * when removing an element |
| 297 * @return an iterator for the specified array |
259 * @return an iterator for the specified array |
| 298 * @see cxMutIterator() |
260 * @see cxIterator() |
| 299 * @see cxIteratorPtr() |
|
| 300 */ |
261 */ |
| 301 cx_attr_nodiscard |
262 cx_attr_nodiscard |
| 302 cx_attr_export |
263 CX_EXPORT CxIterator cxIteratorPtr(const void *array, size_t elem_count, |
| 303 CxIterator cxMutIteratorPtr( |
264 bool remove_keeps_order); |
| 304 void *array, |
|
| 305 size_t elem_count, |
|
| 306 bool remove_keeps_order |
|
| 307 ); |
|
| 308 |
265 |
| 309 #ifdef __cplusplus |
266 #ifdef __cplusplus |
| 310 } // extern "C" |
267 } // extern "C" |
| 311 #endif |
268 #endif |
| 312 |
269 |