11#ifndef __ITERATOR_CLASS_H__
12#define __ITERATOR_CLASS_H__
17#include "helpers/stringlist.h"
71 template <
typename TItemType>
89 virtual bool Next(TItemType& item) = 0;
116 template <
typename TItemType>
146 _items =
new TItemType[numItems];
147 std::copy(items, items + numItems,
_items);
166 bool retrieved_item =
true;
174 retrieved_item =
false;
176 return retrieved_item;
205 std::shared_ptr<IIterator<ItemPair>>
GetItems();
212 std::shared_ptr<IIterator<std::string>>
GetKeys();
219 std::shared_ptr<IIterator<std::string>>
GetValues();
Represents a key/value pair where the key and value are strings.
ItemPair(std::string key, std::string value)
Constructor.
ItemPair()
Default Constructor.
Represents a container that offers up two kinds of iterators for the hardcoded contents,...
std::shared_ptr< IIterator< std::string > > GetKeys()
Retrieve an iterator over the "key" part of the data, where the data returned from the iterator is a ...
std::shared_ptr< IIterator< ItemPair > > GetItems()
Retrieve an iterator over the data that returns an ItemPair object containing both key and value for ...
std::shared_ptr< IIterator< std::string > > GetValues()
Retrieve an iterator over the "value" part of the data, where the data returned from the iterator is ...
Represents an iterator for a container by implementing the IIterator interface.
size_t _numItems
The number of items in the array of items.
TItemType * _items
The array of items to iterate over.
bool Next(TItemType &item)
Fetches the next item in the iteration, if any.
size_t _index
The index into the _items array to the next item.
Iterator(TItemType *items, size_t numItems)
Constructor.
void Reset() override
Reset the iterator to the beginning.
The namespace containing all Design Pattern Examples implemented in C++.
Represents an iterator for some type. This is a forward-only iterator in that it can only start at 0 ...
virtual void Reset()=0
Start iteration from beginning of container.
virtual ~IIterator()
Virtual destructor so this struct can be used as an interface.
virtual bool Next(TItemType &item)=0
Retrieve the next item from the container.