34 printf(
"\nIterator Exercise\n");
39 printf(
" Iterating over keys only:\n");
44 printf(
" %s\n", keyIterator.
key);
47 printf(
" Iterating over values only:\n");
52 printf(
" %s\n", valueIterator.
value);
55 printf(
" Iterating over all items:\n");
void Iterator_Exercise(void)
Example of using the Iterator Pattern.
void Iterator_GetItems(ItemIterator *iterator)
Retrieve an iterator over the whole items in the internal data structure.
void Iterator_GetValues(ValueIterator *iterator)
Retrieve an iterator over the values in the internal data structure.
void Iterator_GetKeys(KeyIterator *iterator)
Retrieve an iterator over the keys in the internal data structure.
bool Iterator_NextValue(ValueIterator *iterator)
Retrieve the next value (const char*) from the iterator.
bool Iterator_NextKey(KeyIterator *iterator)
Retrieve the next key (const char*) from the iterator.
bool Iterator_NextItem(ItemIterator *iterator)
Retrieve the next whole item (ItemPair) from the iterator.
Declaration of the ItemPair structure, along with the iterator functions, Iterator_GetItems(),...
Declaration of the Iterator_Exercise() function as used in the Iterator Pattern.
Represents an iterator that retrieves whole items.
ItemPair item
The key/value pair pointed to by this iterator. item.key and item.value are NULL if Iterator_NextItem...
const char * value
The value part of the item.
const char * key
The key part of the item.
Represents an iterator that retrieves the key of each item.
const char * key
The key pointed to by this iterator. key is NULL if Iterator_NextKey() has not yet been called or the...
Represents an iterator that retrieves the value of each item.
const char * value
The value pointed to by this iterator. value is NULL if Iterator_NextValue() has not yet been called ...