00001 // -*- c++ -*- 00002 //***************************************************************************** 00030 //***************************************************************************** 00031 00032 00033 // include basic definitions 00034 #include "pbori_defs.h" 00035 #include "pbori_func.h" 00036 00037 #include "BoolePolynomial.h" 00038 #include "CDelayedTermIter.h" 00039 00040 #include <algorithm> 00041 00042 #ifndef CRestrictedIter_h_ 00043 #define CRestrictedIter_h_ 00044 00045 BEGIN_NAMESPACE_PBORI 00046 00047 00048 template <class Iterator, 00049 class RestrictOp = 00050 default_binder2nd< std::less<typename Iterator::value_type> >, 00051 class IsValidTest = constant_binder2nd< std::not_equal_to<Iterator>, 00052 default_value<Iterator> > > 00053 class CRestrictedIter: 00054 public Iterator { 00055 public: 00056 00057 typedef Iterator base; 00058 typedef IsValidTest is_valid_type; 00059 typedef RestrictOp restrictop_type; 00060 typedef CRestrictedIter<base, restrictop_type, is_valid_type> self; 00061 typedef typename base::value_type value_type; 00062 00063 CRestrictedIter(const base& src, 00064 const restrictop_type& in_range = restrictop_type(), 00065 const is_valid_type& is_valid = is_valid_type() ): 00066 base(src), m_in_range(in_range), m_is_valid(is_valid) { 00067 goToValid(); 00068 } 00069 00070 00071 self& operator++() { 00072 base::operator++(); 00073 goToValid(); 00074 return *this; 00075 } 00076 self operator++(int) { 00077 self result(*this); 00078 self::operator++(); 00079 return result; 00080 } 00081 00082 void goToValid() { 00083 00084 while( isValid() && !inRange() ) { 00085 base::operator++(); 00086 } 00087 } 00088 00089 bool isValid() const { 00090 return m_is_valid(*this); 00091 } 00092 00093 bool inRange() const { 00094 return m_in_range(base::operator*()); 00095 } 00096 00097 private: 00098 restrictop_type m_in_range; 00099 is_valid_type m_is_valid; 00100 }; 00101 00102 00103 00104 END_NAMESPACE_PBORI 00105 00106 #endif