22 #ifndef UNIQUEITERATOR_H
23 #define UNIQUEITERATOR_H
27 #include <tulip/Iterator.h>
28 #include <tulip/StlIterator.h>
29 #include <tulip/memorypool.h>
39 struct CheckAllFunctor {
40 bool operator()(
const T &) {
67 template <
typename T,
typename CheckFunc = CheckAllFunctor<T>>
68 class 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;
116 template <
typename T,
typename CheckFunc = CheckAllFunctor<T>>
117 class 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) {}
140 template <
typename T,
typename CheckFunc = CheckAllFunctor<T>>
141 inline UniqueIterator<T> *uniqueIterator(Iterator<T> *it, CheckFunc checkFunctor = CheckFunc()) {
142 return new MPUniqueIterator<T, CheckFunc>(it, checkFunctor);
160 template <
typename Container,
typename CheckFunc = CheckAllFunctor<
typename Container::value_type>>
161 typename 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< typename Container::value_type, typename Container::const_iterator > * >::type stlIterator(const Container &stlContainer)
Convenient function for creating a StlIterator from a stl container.