aimstil  5.0.5
ConditionalIterator.h
Go to the documentation of this file.
1 #ifndef TIL_CONDITIONAL_ITERATOR_H
2 #define TIL_CONDITIONAL_ITERATOR_H
3 
4 // includes from TIL library
5 #include "til/til_common.h"
6 
7 // namespace
8 namespace til
9 {
21 
22  template < class TIterator, class BoolFunctor >
23  class ConditionalIterator : public TIterator
24  {
25  public: // constructors & destructor
26 
28  ConditionalIterator(const typename TIterator::TImage &im, const BoolFunctor &boolFunctor = BoolFunctor()) : TIterator(im), m_boolFunctor(boolFunctor) {};
29 
31  ConditionalIterator(typename TIterator::TImage &im, const BoolFunctor &boolFunctor = BoolFunctor()) : TIterator(im), m_boolFunctor(boolFunctor) {};
32 
33  public: // functions
34 
38  bool next()
39  {
40  do
41  {
42  // iterate if you can, but stop if you gotta stop!
43  if (!this->TIterator::next()) return false;
44  }
45  // Not a positive point? Then iterate again
46  while (!m_boolFunctor((*this)));
47 
48  // Okay, we found a positive point, and we are not at the end
49  return true;
50  }
51 
52  private:
53  BoolFunctor m_boolFunctor;
54  };
55 }
56 
57 #endif
58 
ConditionalIterator(typename TIterator::TImage &im, const BoolFunctor &boolFunctor=BoolFunctor())
Constructor for non-const iterators.
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
General macros, definitions and functions.
Conditional iterator for images.
ConditionalIterator(const typename TIterator::TImage &im, const BoolFunctor &boolFunctor=BoolFunctor())
Constructor for const iterators.
bool next()
Go to the next element if possible.