OpenScap iterators concept. More...
Defines | |
#define | OSCAP_FOREACH_GENERIC(itype, vtype, val, init_val, code) |
Iterate over an array, given an iterator. | |
#define | OSCAP_FOREACH(type, val, init_val, code) OSCAP_FOREACH_GENERIC(type, struct type *, val, init_val, code) |
Iterate over an array, given an iterator. | |
#define | OSCAP_FOREACH_STR(val, init_val, code) OSCAP_FOREACH_GENERIC(oscap_string, const char *, val, init_val, code) |
Iterate over an array of strings, given an iterator. |
OpenScap iterators concept.
Any iterator name takes a form of struct OBJECT_iterator
, where OBJECT
is a name of particular datatype the iterator iterates over.
Each iterator type defines several manipulation functions, namely:
OBJECT_iterator_has_more
- returns true if there is anything left to iterate overOBJECT_iterator_next
- returns next item in the collectionOBJECT_iterator_free
- destroys the iteratorYou can also use OSCAP_FOREACH convience macro.
#define OSCAP_FOREACH | ( | type, | |||
val, | |||||
init_val, | |||||
code | ) | OSCAP_FOREACH_GENERIC(type, struct type *, val, init_val, code) |
Iterate over an array, given an iterator.
type | type of array elements (w/o the struct keyword) | |
val | name of an variable the member will be sequentially stored in | |
init_val | initial member value (i.e. an iterator pointing to the start element) | |
code | code to be executed for each element the iterator hits |
#define OSCAP_FOREACH_GENERIC | ( | itype, | |||
vtype, | |||||
val, | |||||
init_val, | |||||
code | ) |
{ \ struct itype##_iterator *val##_iter = (init_val); \ vtype val; \ while (itype##_iterator_has_more(val##_iter)) { \ val = itype##_iterator_next(val##_iter); \ code \ } \ itype##_iterator_free(val##_iter); \ }
Iterate over an array, given an iterator.
Execute code for each array member stored in val.
#define OSCAP_FOREACH_STR | ( | val, | |||
init_val, | |||||
code | ) | OSCAP_FOREACH_GENERIC(oscap_string, const char *, val, init_val, code) |
Iterate over an array of strings, given an iterator.
val | name of an variable the string will be sequentially stored in | |
init_val | initial member value (i.e. an iterator pointing to the start element) | |
code | code to be executed for each string the iterator hits |