PolyBoRi
CExpIter.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
14 //*****************************************************************************
15 
16 #ifndef polybori_iterators_CExpIter_h_
17 #define polybori_iterators_CExpIter_h_
18 
19 // include basic definitions
20 #include <polybori/pbori_defs.h>
21 
22 // get stuff for term iteration
23 #include "CTermStack.h"
24 #include "CTermIter.h"
25 
27 
28 
29 template <class ExpType>
31 
32 public:
33  typedef ExpType value_type;
34  typedef const value_type& result_type;
35  typedef typename value_type::size_type size_type;
36 
38  CExpGenerator(): m_result() {}
39 
41  template <class SequenceType>
42  result_type operator()(const SequenceType&) const{
43  return m_result;
44  }
45 
47  void resize(size_type nlen) { m_result.resize(nlen); }
48 
50  void reserve(size_type nlen) { m_result.reserve(nlen); }
51 
53  size_type size() const { return m_result.size(); }
54 
56  template <class Iterator>
57  void append(Iterator start, Iterator finish) {
58  while (start != finish){
59  m_result.push_back(*start);
60  ++start;
61  }
62  }
63 
64 private:
65  value_type m_result;
66 };
67 
68 
69 template <class NaviType, class ExpType>
70 struct pbori_base<CExpIter<NaviType, ExpType> > {
71 
74 };
75 
76 template <class NaviType, class ExpType>
77 class CExpIter :
78  public pbori_base<CExpIter<NaviType, ExpType> >::type {
79 
80 public:
83 
85  typedef typename pbori_base<self>::type base;
86 
88  CExpIter(NaviType navi): base(navi, typename base::term_generator() ) {
89  base::m_getTerm.reserve(base::m_stack.size());
90  base::m_getTerm.append(base::begin(), base::end());
91  }
92 
93 
95  void increment() {
96  PBORI_ASSERT(!base::m_stack.empty());
97  if (base::m_stack.markedOne()) {
98  base::m_stack.clearOne();
99  }
100  else {
101  base::m_stack.next();
102  base::m_getTerm.resize( base::m_stack.size() == 0 ?
103  0:
104  base::m_stack.size() - 1);
105 
106  if (!base::m_stack.empty()) {
107  base::m_stack.followThen();
108  base::m_stack.terminate();
109  }
110  }
111  base::m_getTerm.reserve(base::m_stack.size());
112  base::m_getTerm.append(base::begin() + base::m_getTerm.size(), base::end());
113  }
114 
116  self& operator++() {
117  increment();
118  return *this;
119  }
121  self operator++(int) {
122  self copy(*this);
123  increment();
124  return copy;
125  }
126 };
127 
129 
130 #endif
#define END_NAMESPACE_PBORI
Finish project's namespace.
Definition: pbori_defs.h:77
#define BEGIN_NAMESPACE_PBORI
Start project's namespace.
Definition: pbori_defs.h:74
pbori_base< self >::type base
Get base type.
Definition: CExpIter.h:85
Definition: pbori_func.h:881
ExpType value_type
Definition: CExpIter.h:33
void reserve(size_type nlen)
Prepare space for nlen elements.
Definition: CExpIter.h:50
CTermIter< stack_type, CExpGenerator< ExpType > > type
Definition: CExpIter.h:73
This class defines an iterator for the monomials in a Boolean polynomial.
Definition: CTermIter.h:44
CTermStack< NaviType, std::forward_iterator_tag > stack_type
Definition: CExpIter.h:72
This class defines an iterator for the monomials in a Boolean polynomial.
Definition: CTermStack.h:353
CExpIter(NaviType navi)
Construct iteraor from navigator over decision diagram structure.
Definition: CExpIter.h:88
#define PBORI_ASSERT(arg)
Definition: pbori_defs.h:118
Definition: CExpIter.h:30
result_type operator()(const SequenceType &) const
Return currently stored results.
Definition: CExpIter.h:42
self & operator++()
Prefix incrementation operation.
Definition: CExpIter.h:116
const value_type & result_type
Definition: CExpIter.h:34
self operator++(int)
Postfix incrementation operation.
Definition: CExpIter.h:121
size_type size() const
Get current size.
Definition: CExpIter.h:53
CExpGenerator()
Default constructor.
Definition: CExpIter.h:38
void increment()
Incrementation operation core.
Definition: CExpIter.h:95
value_type::size_type size_type
Definition: CExpIter.h:35
void append(Iterator start, Iterator finish)
Append elements to exponent vector.
Definition: CExpIter.h:57
Definition: BoolePolynomial.h:73
void resize(size_type nlen)
Take the first nlen elements of the exponent vector only.
Definition: CExpIter.h:47