| 68 * |
68 * |
| 69 * When valid returns false, the behavior of this function is undefined. |
69 * When valid returns false, the behavior of this function is undefined. |
| 70 */ |
70 */ |
| 71 void (*next)(void *); |
71 void (*next)(void *); |
| 72 /** |
72 /** |
| |
73 * Original implementation in case the function needs to be wrapped. |
| |
74 */ |
| |
75 void (*next_impl)(void *); |
| |
76 /** |
| 73 * Indicates whether this iterator may remove elements. |
77 * Indicates whether this iterator may remove elements. |
| 74 */ |
78 */ |
| 75 bool mutating; |
79 bool mutating; |
| 76 /** |
80 /** |
| 77 * Internal flag for removing the current element when advancing. |
81 * Internal flag for removing the current element when advancing. |
| 139 |
143 |
| 140 /** |
144 /** |
| 141 * Iterator type. |
145 * Iterator type. |
| 142 * |
146 * |
| 143 * An iterator points to a certain element in a (possibly unbounded) chain of elements. |
147 * An iterator points to a certain element in a (possibly unbounded) chain of elements. |
| 144 * Iterators that are based on collections (which have a defined "first" element), are supposed |
148 * Iterators that are based on collections (which have a defined "first" element) are supposed |
| 145 * to be "position-aware", which means that they keep track of the current index within the collection. |
149 * to be "position-aware", which means that they keep track of the current index within the collection. |
| 146 * |
150 * |
| 147 * @note Objects that are pointed to by an iterator are always mutable through that iterator. However, |
151 * @note Objects that are pointed to by an iterator are always mutable through that iterator. However, |
| 148 * any concurrent mutation of the collection other than by this iterator makes this iterator invalid, |
152 * any concurrent mutation of the collection other than by this iterator makes this iterator invalid, |
| 149 * and it must not be used anymore. |
153 * and it must not be used anymore. |
| 176 * @param iter the iterator |
180 * @param iter the iterator |
| 177 */ |
181 */ |
| 178 #define cxIteratorNext(iter) (iter).base.next(&iter) |
182 #define cxIteratorNext(iter) (iter).base.next(&iter) |
| 179 |
183 |
| 180 /** |
184 /** |
| 181 * Flags the current element for removal, if this iterator is mutating. |
185 * Flags the current element for removal if this iterator is mutating. |
| 182 * |
186 * |
| 183 * Does nothing for non-mutating iterators. |
187 * Does nothing for non-mutating iterators. |
| 184 * |
188 * |
| 185 * @param iter the iterator |
189 * @param iter the iterator |
| 186 */ |
190 */ |
| 208 |
212 |
| 209 |
213 |
| 210 /** |
214 /** |
| 211 * Creates an iterator for the specified plain array. |
215 * Creates an iterator for the specified plain array. |
| 212 * |
216 * |
| 213 * The @p array can be @c NULL in which case the iterator will be immediately |
217 * The @p array can be @c NULL, in which case the iterator will be immediately |
| 214 * initialized such that #cxIteratorValid() returns @c false. |
218 * initialized such that #cxIteratorValid() returns @c false. |
| 215 * |
219 * |
| 216 * This iterator yields the addresses of the array elements. |
220 * This iterator yields the addresses of the array elements. |
| 217 * If you want to iterator over an array of pointers, you can |
221 * If you want to iterator over an array of pointers, you can |
| 218 * use cxIteratorPtr() to create an iterator which directly |
222 * use cxIteratorPtr() to create an iterator which directly |
| 242 * When @p remove_keeps_order is set to @c false, removing an element will only |
246 * 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 |
247 * 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 |
248 * moving all subsequent elements by one. Usually, when the order of elements is |
| 245 * not important, this parameter should be set to @c false. |
249 * not important, this parameter should be set to @c false. |
| 246 * |
250 * |
| 247 * The @p array can be @c NULL in which case the iterator will be immediately |
251 * The @p array can be @c NULL, in which case the iterator will be immediately |
| 248 * initialized such that #cxIteratorValid() returns @c false. |
252 * initialized such that #cxIteratorValid() returns @c false. |
| 249 * |
253 * |
| 250 * |
254 * |
| 251 * @param array a pointer to the array (can be @c NULL) |
255 * @param array a pointer to the array (can be @c NULL) |
| 252 * @param elem_size the size of one array element |
256 * @param elem_size the size of one array element |
| 266 |
270 |
| 267 /** |
271 /** |
| 268 * Creates an iterator for the specified plain pointer array. |
272 * Creates an iterator for the specified plain pointer array. |
| 269 * |
273 * |
| 270 * This iterator assumes that every element in the array is a pointer |
274 * This iterator assumes that every element in the array is a pointer |
| 271 * and yields exactly those pointers during iteration (while in contrast |
275 * and yields exactly those pointers during iteration (on the other |
| 272 * an iterator created with cxIterator() would return the addresses |
276 * hand, an iterator created with cxIterator() would return the |
| 273 * of those pointers within the array). |
277 * addresses of those pointers within the array). |
| 274 * |
278 * |
| 275 * @param array a pointer to the array (can be @c NULL) |
279 * @param array a pointer to the array (can be @c NULL) |
| 276 * @param elem_count the number of elements in the array |
280 * @param elem_count the number of elements in the array |
| 277 * @return an iterator for the specified array |
281 * @return an iterator for the specified array |
| 278 * @see cxIterator() |
282 * @see cxIterator() |