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

Implementation of the iterator functions, Iterator_GetItems(), Iterator_GetKeys(), Iterator_GetValues(), Iterator_NextItem(), Iterator_NextKey(), and Iterator_NextValue(), as used in the Iterator Pattern. More...

#include "Iterator_Iterators.h"
#include <stdlib.h>
Include dependency graph for Iterator_Iterators.c:

Go to the source code of this file.

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.
 

Variables

static const char * _keys [] = { "One" , "Two" , "Three" }
 A list of keys as example data. The number of keys must match the number of values in the _values list.
 
static const char * _values [] = { "Value 1", "Value 2", "Value 3" }
 A list of values as example data. The number of values must match the number of keys in the _keys list.
 

Detailed Description

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().

Variable Documentation

◆ _keys

const char* _keys[] = { "One" , "Two" , "Three" }
static

A list of keys as example data. The number of keys must match the number of values in the _values list.

Definition at line 17 of file Iterator_Iterators.c.

Referenced by IteratorContainer_Class::GetItems(), IteratorContainer_Class::GetKeys(), Iterator_NextItem(), and Iterator_NextKey().

◆ _values

const char* _values[] = { "Value 1", "Value 2", "Value 3" }
static

A list of values as example data. The number of values must match the number of keys in the _keys list.

Definition at line 23 of file Iterator_Iterators.c.

Referenced by IteratorContainer_Class::GetItems(), IteratorContainer_Class::GetValues(), Iterator_NextItem(), and Iterator_NextValue().