22#ifndef UNIQUEITERATOR_H
23#define UNIQUEITERATOR_H
27#include <tulip/Iterator.h>
28#include <tulip/StlIterator.h>
29#include <tulip/memorypool.h>
39struct CheckAllFunctor {
40 bool operator()(
const T &) {
67template <
typename T,
typename CheckFunc = CheckAllFunctor<T>>
68class UniqueIterator :
public Iterator<T> {
70 UniqueIterator(Iterator<T> *it, CheckFunc checkFunctor = CheckFunc())
71 : _it(it), _checkFunctor(checkFunctor) {
85 inline bool hasNext() {
92 while (_it->hasNext()) {
95 if (_checkFunctor(curVal)) {
96 if (_flag.find(curVal) == _flag.end()) {
113 CheckFunc _checkFunctor;
116template <
typename T,
typename CheckFunc = CheckAllFunctor<T>>
117class MPUniqueIterator :
public UniqueIterator<T, CheckFunc>,
118 public MemoryPool<MPUniqueIterator<T, CheckFunc>> {
120 MPUniqueIterator(Iterator<T> *it, CheckFunc checkFunctor = CheckFunc())
121 : UniqueIterator<T, CheckFunc>(it, checkFunctor) {}
140template <
typename T,
typename CheckFunc = CheckAllFunctor<T>>
141inline UniqueIterator<T> *uniqueIterator(Iterator<T> *it, CheckFunc checkFunctor = CheckFunc()) {
142 return new MPUniqueIterator<T, CheckFunc>(it, checkFunctor);
160template <
typename Container,
typename CheckFunc = CheckAllFunctor<
typename Container::value_type>>
161typename std::enable_if<has_const_iterator<Container>::value,
162 UniqueIterator<typename Container::value_type, CheckFunc>
163 *>::type
inline uniqueIterator(
const Container &stlContainer,
164 CheckFunc checkFunctor = CheckFunc()) {
165 return new MPUniqueIterator<typename Container::value_type, CheckFunc>(
stlIterator(stlContainer),
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.