20#ifndef TULIP_STLITERATOR_H
21#define TULIP_STLITERATOR_H
26#include <tulip/Iterator.h>
27#include <tulip/memorypool.h>
43template <
typename T,
typename ITERATOR>
45 StlIterator(
const ITERATOR &startIt,
const ITERATOR &endIt) : it(startIt), itEnd(endIt) {}
59template <
typename T,
typename ITERATOR>
60struct MPStlIterator :
public StlIterator<T, ITERATOR>,
61 public MemoryPool<MPStlIterator<T, ITERATOR>> {
62 MPStlIterator(
const ITERATOR &startIt,
const ITERATOR &endIt)
63 : StlIterator<T, ITERATOR>(startIt, endIt) {}
69struct has_const_iterator {
72 static char test(
typename C::const_iterator *);
77 enum { value =
sizeof(test<T>(0)) ==
sizeof(
char) };
91template <
typename Container>
92typename std::enable_if<
93 has_const_iterator<Container>::value,
94 StlIterator<typename Container::value_type, typename Container::const_iterator>
96 return new MPStlIterator<typename Container::value_type, typename Container::const_iterator>(
97 stlContainer.begin(), stlContainer.end());
101template <
typename KEY,
typename VALUE>
102struct StlMapIterator :
public Iterator<std::pair<KEY, VALUE>> {
103 StlMapIterator(
typename std::map<KEY, VALUE>::const_iterator startIt,
104 typename std::map<KEY, VALUE>::const_iterator endIt)
105 : it(startIt), itEnd(endIt) {}
107 std::pair<KEY, VALUE> next() {
108 std::pair<KEY, VALUE> tmp = *it;
114 return (itEnd != it);
118 typename std::map<KEY, VALUE>::const_iterator it, itEnd;
121template <
typename KEY,
typename VALUE>
123 StlMapKeyIterator(
typename std::map<KEY, VALUE>::const_iterator startIt,
124 typename std::map<KEY, VALUE>::const_iterator endIt)
125 : it(startIt), itEnd(endIt) {}
128 const KEY tmp = it->first;
138 typename std::map<KEY, VALUE>::const_iterator it, itEnd;
std::enable_if< has_const_iterator< Container >::value, StlIterator< typenameContainer::value_type, typenameContainer::const_iterator > * >::type stlIterator(const Container &stlContainer)
Convenient function for creating a StlIterator from a stl container.
Interface for Tulip iterators. Allows basic iteration operations only.
StlIterator wraps a stl iterator.
bool hasNext()
Tells if the sequence is at its end.
T next()
Moves the Iterator on the next element.