Iterator for as_orderedmap.
To use the iterator, you can either initialize a stack allocated variable, use as_orderedmap_iterator_init()
:
const as_orderedmap * map
AS_EXTERN as_orderedmap_iterator * as_orderedmap_iterator_init(as_orderedmap_iterator *it, const as_orderedmap *map)
Or you can create a new heap allocated variable using as_orderedmap_iterator_new()
:
AS_EXTERN as_orderedmap_iterator * as_orderedmap_iterator_new(const as_orderedmap *map)
To iterate, use as_orderedmap_iterator_has_next()
and as_orderedmap_iterator_next()
:
}
AS_EXTERN const as_val * as_orderedmap_iterator_next(as_orderedmap_iterator *it)
AS_EXTERN bool as_orderedmap_iterator_has_next(const as_orderedmap_iterator *it)
When you are finished using the iterator, then you should release the iterator and associated resources:
AS_EXTERN void as_orderedmap_iterator_destroy(as_orderedmap_iterator *it)
The as_orderedmap_iterator
is a subtype of as_iterator
. This allows you to alternatively use as_iterator
functions, by typecasting as_orderedmap_iterator
to as_iterator
.
}
static const as_val * as_iterator_next(as_iterator *iterator)
AS_EXTERN void as_iterator_destroy(as_iterator *iterator)
static bool as_iterator_has_next(const as_iterator *iterator)
Each of the as_iterator
functions proxy to the as_orderedmap_iterator
functions. So, calling as_iterator_destroy()
is equivalent to calling as_orderedmap_iterator_destroy()
.
Notes:
as_orderedmap_iterator_next() returns an as_pair pointer. The as_pair contains the key and value pointers of the current map element. This one as_pair "container" is re-used for all the iterations, i.e. the contents will be overwritten and are only valid until the next iteration.
Definition at line 181 of file as_orderedmap.h.