src/cx/iterator.h

changeset 850
b2bc48c2b251
parent 829
7d4e31d295af
child 851
adb4e0737c33
equal deleted inserted replaced
849:edb9f875b7f9 850:b2bc48c2b251
125 /** 125 /**
126 * If the iterator is position-aware, contains the index of the element in the underlying collection. 126 * If the iterator is position-aware, contains the index of the element in the underlying collection.
127 * Otherwise, this field is usually uninitialized. 127 * Otherwise, this field is usually uninitialized.
128 */ 128 */
129 size_t index; 129 size_t index;
130
131 /**
132 * The size of an individual element.
133 */
134 size_t elem_size;
135
136 /**
137 * May contain the total number of elements, if known.
138 * Shall be set to \c SIZE_MAX when the total number is unknown during iteration.
139 */
140 size_t elem_count;
130 }; 141 };
131 142
132 /** 143 /**
133 * Mutating iterator value type. 144 * Mutating iterator value type.
134 * 145 *
189 /** 200 /**
190 * If the iterator is position-aware, contains the index of the element in the underlying collection. 201 * If the iterator is position-aware, contains the index of the element in the underlying collection.
191 * Otherwise, this field is usually uninitialized. 202 * Otherwise, this field is usually uninitialized.
192 */ 203 */
193 size_t index; 204 size_t index;
205
206 /**
207 * The size of an individual element.
208 */
209 size_t elem_size;
210
211 /**
212 * May contain the total number of elements, if known.
213 * Shall be set to \c SIZE_MAX when the total number is unknown during iteration.
214 */
215 size_t elem_count;
194 }; 216 };
195 217
196 /** 218 /**
197 * Iterator value type. 219 * Iterator value type.
198 * An iterator points to a certain element in a (possibly unbounded) chain of elements. 220 * An iterator points to a certain element in a (possibly unbounded) chain of elements.
248 * @param iter the iterator 270 * @param iter the iterator
249 */ 271 */
250 #define cx_foreach(type, elem, iter) \ 272 #define cx_foreach(type, elem, iter) \
251 for (type elem; cxIteratorValid(iter) && (elem = (type)cxIteratorCurrent(iter)) != NULL ; cxIteratorNext(iter)) 273 for (type elem; cxIteratorValid(iter) && (elem = (type)cxIteratorCurrent(iter)) != NULL ; cxIteratorNext(iter))
252 274
275
276 /**
277 * Creates an iterator for the specified plain array.
278 *
279 * While the iterator is in use, the array may only be altered by removing
280 * elements through #cxIteratorFlagRemoval(). Every other change to the array
281 * will bring this iterator to an undefined state.
282 *
283 * When \p remove_keeps_order is set to \c false, removing an element will only
284 * move the last element to the position of the removed element, instead of
285 * moving all subsequent elements by one. Usually, when the order of elements is
286 * not important, this parameter should be set to \c false.
287 *
288 * The \p array can be \c NULL in which case the iterator will be immediately
289 * initialized such that #cxIteratorValid() returns \c false.
290 *
291 *
292 * @param array a pointer to the array (can be \c NULL)
293 * @param elem_size the size of one array element
294 * @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
296 * when removing an element
297 * @return an iterator for the specified array
298 */
299 __attribute__((__warn_unused_result__))
300 CxMutIterator cxIterator( // TODO: unify the iterator types
301 void *array,
302 size_t elem_size,
303 size_t elem_count,
304 bool remove_keeps_order
305 );
306
253 #endif // UCX_ITERATOR_H 307 #endif // UCX_ITERATOR_H

mercurial