ITER
[COMMON]

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.
#define OSCAP_FOR_GENERIC(itype, vtype, val, init_val)
 Iterate over an array, given an iterator.
#define OSCAP_FOR(type, val, init_val)   OSCAP_FOR_GENERIC(type, struct type *, val, init_val)
 Iterate over an array, given an iterator.
#define OSCAP_FOR_STR(val, init_val)   OSCAP_FOR_GENERIC(oscap_string, const char *, val, init_val)
 Iterate over an array of strings, given an iterator.

Detailed Description

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:

You can also use OSCAP_FOREACH convience macro.


Define Documentation

#define OSCAP_FOR ( type,
val,
init_val   )     OSCAP_FOR_GENERIC(type, struct type *, val, init_val)

Iterate over an array, given an iterator.

Parameters:
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)
See also:
OSCAP_FOR_GENERIC
#define OSCAP_FOR_GENERIC ( itype,
vtype,
val,
init_val   ) 
Value:
vtype val = NULL; struct itype##_iterator *val##_iter = (init_val); \
    while (itype##_iterator_has_more(val##_iter)                        \
            ? (val = itype##_iterator_next(val##_iter), true)           \
            : (itype##_iterator_free(val##_iter), val##_iter = NULL, false))

Iterate over an array, given an iterator.

It is generally not safe to use break, return or goto inside the loop (iterator wouldn't be properly freed otherwise). Two variables, named VAL and VAL_iter (substitute VAL for actual macro argument) will be added to current variable scope. You can free the iterator explicitly after previous unusual escape from the loop (e.g. using break).

Parameters:
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
#define OSCAP_FOR_STR ( val,
init_val   )     OSCAP_FOR_GENERIC(oscap_string, const char *, val, init_val)

Iterate over an array of strings, given an iterator.

Parameters:
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)
See also:
OSCAP_FOR_GENERIC
#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.

Parameters:
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
See also:
OSCAP_FOREACH_GENERIC
#define OSCAP_FOREACH_GENERIC ( itype,
vtype,
val,
init_val,
code   ) 
Value:
{                                                            \
        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. It is NOT safe to use return or goto inside of the code, the iterator would not be freed properly.

#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.

Parameters:
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
See also:
OSCAP_FOREACH_GENERIC

Generated on 14 Jul 2010 for Open SCAP Library by  doxygen 1.6.1