![]() |
ucx
UAP Common Extensions
|
Interface for iterator implementations. More...
#include "common.h"Go to the source code of this file.
Data Structures | |
| struct | cx_iterator_base_s |
| Common data for all iterators. More... | |
| struct | cx_iterator_s |
| Internal iterator struct - use CxIterator. More... | |
Macros | |
| #define | CX_ITERATOR_BASE struct cx_iterator_base_s base |
| Declares base attributes for an iterator. | |
| #define | cxIteratorValid(iter) |
| Checks if the iterator points to valid data. | |
| #define | cxIteratorCurrent(iter) |
| Returns a pointer to the current element. | |
| #define | cxIteratorNext(iter) |
| Advances the iterator to the next element. | |
| #define | cxIteratorFlagRemoval(iter) |
| Flags the current element for removal if the iterator allows it. | |
| #define | cxIteratorRef(iter) |
| Obtains a reference to an arbitrary iterator. | |
| #define | cx_foreach(type, elem, iter) |
| Loops over an iterator. | |
Typedefs | |
| typedef struct cx_iterator_base_s | CxIteratorBase |
| Convenience type definition for the base structure of an iterator. | |
| typedef struct cx_iterator_s | CxIterator |
| Iterator type. | |
Functions | |
| CxIterator | cxIterator (const void *array, size_t elem_size, size_t elem_count, bool remove_keeps_order) |
| Creates an iterator for the specified plain array. | |
| CxIterator | cxIteratorPtr (const void *array, size_t elem_count, bool remove_keeps_order) |
| Creates an iterator for the specified plain pointer array. | |
Interface for iterator implementations.
| #define cx_foreach | ( | type, | |
| elem, | |||
| iter ) |
Loops over an iterator.
| type | the type of the elements |
| elem | the name of the iteration variable |
| iter | the iterator |
| #define CX_ITERATOR_BASE struct cx_iterator_base_s base |
Declares base attributes for an iterator.
Must be the first member of an iterator structure.
| #define cxIteratorCurrent | ( | iter | ) |
Returns a pointer to the current element.
The behavior is undefined if this iterator is invalid.
| iter | the iterator |
| #define cxIteratorFlagRemoval | ( | iter | ) |
Flags the current element for removal if the iterator allows it.
| iter | the iterator |
true if removal is allowed, false otherwise | #define cxIteratorNext | ( | iter | ) |
Advances the iterator to the next element.
| iter | the iterator |
| #define cxIteratorRef | ( | iter | ) |
Obtains a reference to an arbitrary iterator.
This is useful for APIs that expect some iterator as an argument.
| iter | the iterator |
struct cx_iterator_base_s*) a pointer to the iterator | #define cxIteratorValid | ( | iter | ) |
Checks if the iterator points to valid data.
| iter | the iterator |
| true | if the iterator points to valid data |
| false | if the iterator already moved past the end |
| typedef struct cx_iterator_s CxIterator |
Iterator type.
An iterator points to a certain element in a (possibly unbounded) chain of elements. Iterators that are based on collections (which have a defined "first" element) are supposed to be "position-aware", which means that they keep track of the current index within the collection.
| typedef struct cx_iterator_base_s CxIteratorBase |
Convenience type definition for the base structure of an iterator.
| CxIterator cxIterator | ( | const void * | array, |
| size_t | elem_size, | ||
| size_t | elem_count, | ||
| bool | remove_keeps_order ) |
Creates an iterator for the specified plain array.
The array can be NULL, in which case the iterator will be immediately initialized such that cxIteratorValid() returns false.
This iterator yields the addresses of the array elements. If you want to iterator over an array of pointers, you can use cxIteratorPtr() to create an iterator which directly yields the stored pointers.
While the iterator is in use, the array may only be altered by removing elements through cxIteratorFlagRemoval(). Every other change to the array will bring this iterator to an undefined state.
When remove_keeps_order is set to false, removing an element will only move the last element to the position of the removed element, instead of moving all subsequent elements by one. Usually, when the order of elements is not important, this parameter should be set to false.
| array | a pointer to the array (can be NULL) |
| elem_size | the size of one array element |
| elem_count | the number of elements in the array |
| remove_keeps_order | true if the order of elements must be preserved when removing an element |
| CxIterator cxIteratorPtr | ( | const void * | array, |
| size_t | elem_count, | ||
| bool | remove_keeps_order ) |
Creates an iterator for the specified plain pointer array.
This iterator assumes that every element in the array is a pointer and yields exactly those pointers during iteration (on the other hand, an iterator created with cxIterator() would return the addresses of those pointers within the array).
While the iterator is in use, the array may only be altered by removing elements through cxIteratorFlagRemoval(). Every other change to the array will bring this iterator to an undefined state.
When remove_keeps_order is set to false, removing an element will only move the last element to the position of the removed element, instead of moving all subsequent elements by one. Usually, when the order of elements is not important, this parameter should be set to false.
| array | a pointer to the array (can be NULL) |
| elem_count | the number of elements in the array |
| remove_keeps_order | true if the order of elements must be preserved when removing an element |