PolyBoRi
CRestrictedIter.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
33 //*****************************************************************************
34 
35 
36 // include basic definitions
37 #include "pbori_defs.h"
38 #include "pbori_func.h"
39 
40 #include "BoolePolynomial.h"
41 #include "CDelayedTermIter.h"
42 
43 #include <algorithm>
44 
45 #ifndef CRestrictedIter_h_
46 #define CRestrictedIter_h_
47 
49 
50 
51 template <class Iterator,
52  class RestrictOp =
53  default_binder2nd< std::less<typename Iterator::value_type> >,
54  class IsValidTest = constant_binder2nd< std::not_equal_to<Iterator>,
55  default_value<Iterator> > >
57  public Iterator {
58 public:
59 
60  typedef Iterator base;
61  typedef IsValidTest is_valid_type;
62  typedef RestrictOp restrictop_type;
64  typedef typename base::value_type value_type;
65 
66  CRestrictedIter(const base& src,
67  const restrictop_type& in_range = restrictop_type(),
68  const is_valid_type& is_valid = is_valid_type() ):
69  base(src), m_in_range(in_range), m_is_valid(is_valid) {
70  goToValid();
71  }
72 
73 
74  self& operator++() {
75  base::operator++();
76  goToValid();
77  return *this;
78  }
79  self operator++(int) {
80  self result(*this);
81  self::operator++();
82  return result;
83  }
84 
85  void goToValid() {
86 
87  while( isValid() && !inRange() ) {
88  base::operator++();
89  }
90  }
91 
92  bool isValid() const {
93  return m_is_valid(*this);
94  }
95 
96  bool inRange() const {
97  return m_in_range(base::operator*());
98  }
99 
100 private:
101  restrictop_type m_in_range;
102  is_valid_type m_is_valid;
103 };
104 
105 
106 
108 
109 #endif