Design Pattern Examples
Overview of object-oriented design patterns
Iterator_Iterators.h File Reference

Declaration of the ItemPair structure, along with the iterator functions, Iterator_GetItems(), Iterator_GetKeys(), Iterator_GetValues(), Iterator_NextItem(), Iterator_NextKey(), and Iterator_NextValue(), as used in the Iterator Pattern. More...

#include <stdbool.h>
#include <stddef.h>
Include dependency graph for Iterator_Iterators.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ItemPair
 Represents a key/value pair where the key and value are strings. More...
 
struct  ItemIterator
 Represents an iterator that retrieves whole items. More...
 
struct  KeyIterator
 Represents an iterator that retrieves the key of each item. More...
 
struct  ValueIterator
 Represents an iterator that retrieves the value of each item. More...
 

Macros

#define __ITERATOR_ITERATORS_H__
 

Functions

void Iterator_GetItems (ItemIterator *iterator)
 Retrieve an iterator over the whole items in the internal data structure.
 
void Iterator_GetKeys (KeyIterator *iterator)
 Retrieve an iterator over the keys in the internal data structure.
 
void Iterator_GetValues (ValueIterator *iterator)
 Retrieve an iterator over the values in the internal data structure.
 
bool Iterator_NextItem (ItemIterator *iterator)
 Retrieve the next whole item (ItemPair) from the iterator.
 
bool Iterator_NextKey (KeyIterator *iterator)
 Retrieve the next key (const char*) from the iterator.
 
bool Iterator_NextValue (ValueIterator *iterator)
 Retrieve the next value (const char*) from the iterator.
 

Detailed Description

Declaration of the ItemPair structure, along with the iterator functions, Iterator_GetItems(), Iterator_GetKeys(), Iterator_GetValues(), Iterator_NextItem(), Iterator_NextKey(), and Iterator_NextValue(), as used in the Iterator Pattern.

Definition in file Iterator_Iterators.h.

Macro Definition Documentation

◆ __ITERATOR_ITERATORS_H__

#define __ITERATOR_ITERATORS_H__

Definition at line 10 of file Iterator_Iterators.h.

Function Documentation

◆ Iterator_GetItems()

void Iterator_GetItems ( ItemIterator iterator)

Retrieve an iterator over the whole items in the internal data structure.

Parameters
iteratorPointer to an ItemIterator object to populate with the iterator. Call Iterator_NextItem() to start using the iterator.

Definition at line 32 of file Iterator_Iterators.c.

References ItemIterator::item, ItemIterator::iterator, ItemPair::key, and ItemPair::value.

Referenced by Iterator_Exercise().

◆ Iterator_GetKeys()

void Iterator_GetKeys ( KeyIterator iterator)

Retrieve an iterator over the keys in the internal data structure.

Parameters
iteratorPointer to an KeyIterator object to populate with the iterator. Call Iterator_NextKey() to start using the iterator.

Definition at line 45 of file Iterator_Iterators.c.

References KeyIterator::iterator, and KeyIterator::key.

Referenced by Iterator_Exercise().

◆ Iterator_GetValues()

void Iterator_GetValues ( ValueIterator iterator)

Retrieve an iterator over the values in the internal data structure.

Parameters
iteratorPointer to an ValueIterator object to populate with the iterator. Call Iterator_NextValue() to start using the iterator.

Definition at line 57 of file Iterator_Iterators.c.

References ValueIterator::iterator, and ValueIterator::value.

Referenced by Iterator_Exercise().

◆ Iterator_NextItem()

bool Iterator_NextItem ( ItemIterator iterator)

Retrieve the next whole item (ItemPair) from the iterator.

Parameters
iteratorThe KeyIterator used to get the next item.
Returns
Returns true if an item was retrieved; otherwise, returns false, there are no more items.

Definition at line 69 of file Iterator_Iterators.c.

References _keys, _values, ItemIterator::item, ItemIterator::iterator, ItemPair::key, and ItemPair::value.

Referenced by Iterator_Exercise().

◆ Iterator_NextKey()

bool Iterator_NextKey ( KeyIterator iterator)

Retrieve the next key (const char*) from the iterator.

Parameters
iteratorThe ItemIterator used to get the next key.
Returns
Returns true if a key was retrieved; otherwise, returns false, there are no more keys.

Definition at line 99 of file Iterator_Iterators.c.

References _keys, KeyIterator::iterator, and KeyIterator::key.

Referenced by Iterator_Exercise().

◆ Iterator_NextValue()

bool Iterator_NextValue ( ValueIterator iterator)

Retrieve the next value (const char*) from the iterator.

Parameters
iteratorThe ValueIterator used to get the next value.
Returns
Returns true if a value was retrieved; otherwise, returns false, there are no more values.

Definition at line 127 of file Iterator_Iterators.c.

References _values, ValueIterator::iterator, and ValueIterator::value.

Referenced by Iterator_Exercise().