PolyBoRi
CRestrictedIter.h
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //*****************************************************************************
00013 //*****************************************************************************
00014 
00015 
00016 // include basic definitions
00017 #include "pbori_defs.h"
00018 #include "pbori_func.h"
00019 
00020 #include "BoolePolynomial.h"
00021 #include "CDelayedTermIter.h"
00022 
00023 #include <algorithm>
00024 
00025 #ifndef CRestrictedIter_h_
00026 #define CRestrictedIter_h_
00027 
00028 BEGIN_NAMESPACE_PBORI
00029 
00030 
00031 template <class Iterator, 
00032           class RestrictOp = 
00033             default_binder2nd< std::less<typename Iterator::value_type> >,
00034           class IsValidTest = constant_binder2nd< std::not_equal_to<Iterator>, 
00035                                                 default_value<Iterator> > >
00036 class CRestrictedIter:
00037   public Iterator {
00038 public:
00039 
00040   typedef Iterator base;
00041   typedef IsValidTest is_valid_type;
00042   typedef RestrictOp restrictop_type;
00043   typedef CRestrictedIter<base, restrictop_type, is_valid_type> self;
00044   typedef typename base::value_type value_type;
00045 
00046   CRestrictedIter(const base& src, 
00047                   const restrictop_type& in_range = restrictop_type(),
00048                   const is_valid_type& is_valid = is_valid_type() ):
00049     base(src), m_in_range(in_range), m_is_valid(is_valid) {
00050     goToValid();
00051   }
00052 
00053 
00054   self& operator++() {
00055     base::operator++();
00056     goToValid();
00057     return *this;
00058   }
00059   self operator++(int) {
00060     self result(*this);
00061     self::operator++();
00062     return result;
00063   }
00064 
00065   void goToValid() {
00066 
00067     while( isValid() && !inRange() ) {
00068       base::operator++();
00069     }
00070   }
00071 
00072   bool isValid() const {
00073     return m_is_valid(*this);
00074   }
00075 
00076   bool inRange() const {
00077     return m_in_range(base::operator*());
00078   }
00079 
00080 private:
00081   restrictop_type m_in_range;
00082   is_valid_type m_is_valid;
00083 };
00084 
00085 
00086 
00087 END_NAMESPACE_PBORI
00088 
00089 #endif