PolyBoRi
CCuddNavigator.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
16 //*****************************************************************************
17 
18 #ifndef polybori_iterators_CCuddNavigator_h_
19 #define polybori_iterators_CCuddNavigator_h_
20 
21 #include <iterator>
22 
23 // include basic definitions
24 #include <polybori/pbori_defs.h>
25 #include <polybori/common/tags.h>
27 
29 
37 
38 public:
40  typedef DdNode* pointer_type;
41 
43  typedef const pointer_type const_access_type;
44 
47 
50 
53 
56 
59 
61  typedef idx_type value_type;
62 
64  typedef CCuddNavigator self;
65 
67 
69  typedef std::iterator_traits<pointer_type>::difference_type difference_type;
70  typedef void pointer;
71  typedef value_type reference;
73 
75  CCuddNavigator(): pNode(NULL) {}
76 
78  explicit CCuddNavigator(pointer_type ptr): pNode(ptr) {
79  PBORI_ASSERT(isValid());
80  }
81 
83  CCuddNavigator(const self& rhs): pNode(rhs.pNode) {}
84 
87 
89  self& incrementThen(); // inlined below
90 
92  self thenBranch() const { return self(*this).incrementThen(); }
93 
95  self& incrementElse(); // inlined below
96 
98  self elseBranch() const { return self(*this).incrementElse(); }
99 
101  reference operator*() const; // inlined below
102 
104  const_access_type operator->() const { return pNode; }
105 
107  const_access_type getNode() const { return pNode; }
108 
110  hash_type hash() const { return reinterpret_cast<hash_type>(pNode); }
111 
113  bool_type operator==(const self& rhs) const { return (pNode == rhs.pNode); }
114 
116  bool_type operator!=(const self& rhs) const { return (pNode != rhs.pNode); }
117 
119  bool_type isConstant() const; // inlined below
120 
122  bool_type terminalValue() const; // inlined below
123 
125  bool_type isValid() const { return (pNode != NULL); }
126 
128  bool_type isTerminated() const { return isConstant() && terminalValue(); }
129 
131  bool_type isEmpty() const { return isConstant() && !terminalValue(); }
132 
134 
135  bool_type operator<(const self& rhs) const { return (pNode < rhs.pNode); }
136  bool_type operator<=(const self& rhs) const { return (pNode <= rhs.pNode); }
137  bool_type operator>(const self& rhs) const { return (pNode > rhs.pNode); }
138  bool_type operator>=(const self& rhs) const { return (pNode >= rhs.pNode); }
140 
142  void incRef() const { PBORI_ASSERT(isValid()); PBORI_PREFIX(Cudd_Ref)(pNode); }
143 
145  void decRef() const { PBORI_ASSERT(isValid()); PBORI_PREFIX(Cudd_Deref)(pNode); }
146 
148  template <class MgrType>
149  void recursiveDecRef(const MgrType& mgr) const {
150  PBORI_ASSERT(isValid());
151  PBORI_PREFIX(Cudd_RecursiveDerefZdd)(mgr, pNode);
152  }
153 
154 private:
156  pointer_type pNode;
157 };
158 
159 // Inlined member functions
160 
161 // constant pointer access operator
162 inline CCuddNavigator::value_type
164 
165  PBORI_TRACE_FUNC( "CCuddNavigator::operator*() const" );
166  PBORI_ASSERT(isValid());
167  return Cudd_Regular(pNode)->index;
168 }
169 
170 // whether constant node was reached
172 CCuddNavigator::isConstant() const {
173 
174  PBORI_TRACE_FUNC( "CCuddNavigator::isConstant() const" );
175  PBORI_ASSERT(isValid());
176  return Cudd_IsConstant(pNode);
177 }
178 
179 // constant node value
181 CCuddNavigator::terminalValue() const {
182 
183  PBORI_TRACE_FUNC( "CCuddNavigator::terminalValue() const" );
184  PBORI_ASSERT(isConstant());
185  return Cudd_V(pNode);
186 }
187 
188 
189 // increment in then direction
190 inline CCuddNavigator&
191 CCuddNavigator::incrementThen() {
192 
193  PBORI_TRACE_FUNC( "CCuddNavigator::incrementThen()" );
194 
195  PBORI_ASSERT(isValid());
196  pNode = Cudd_T(pNode);
197 
198  return *this;
199 }
200 
201 // increment in else direction
202 inline CCuddNavigator&
203 CCuddNavigator::incrementElse() {
204 
205  PBORI_TRACE_FUNC( "CCuddNavigator::incrementElse()" );
206 
207  PBORI_ASSERT(isValid());
208  pNode = Cudd_E(pNode);
209 
210  return *this;
211 }
212 
213 inline CCuddNavigator
215 
216 #ifndef PBORI_NDEBUG
217  if (ptr == NULL)
218  return CCuddNavigator();
219  else
220 #endif
221  return CCuddNavigator(ptr);
222 }
223 
224 
226 
227 #endif
#define PBORI_PREFIX(name)
Definition: prefix.h:27
CTypes::size_type size_type
Type for indices.
Definition: CCuddNavigator.h:49
#define END_NAMESPACE_PBORI
Finish project's namespace.
Definition: pbori_defs.h:77
navigator_tag iterator_category
Definition: CCuddNavigator.h:68
#define BEGIN_NAMESPACE_PBORI
Start project's namespace.
Definition: pbori_defs.h:74
value_type reference
Definition: CCuddNavigator.h:71
#define Cudd_RecursiveDerefZdd
Definition: prefix_internal.h:149
int deg_type
Type for polynomial degrees (ranges from -1 to maxint)
Definition: pbori_defs.h:222
void incRef() const
Force incrementation of reference count.
Definition: CCuddNavigator.h:142
CCuddNavigator explicit_navigator_cast(CCuddNavigator::pointer_type ptr)
Definition: CCuddNavigator.h:214
CTypes::bool_type bool_type
Type for boolean results.
Definition: CCuddNavigator.h:58
bool_type operator!=(const self &rhs) const
Nonequality test.
Definition: CCuddNavigator.h:116
void decRef() const
Force decrementation of reference count.
Definition: CCuddNavigator.h:145
self elseBranch() const
Increment in else direction.
Definition: CCuddNavigator.h:98
bool_type isEmpty() const
Check whether dead end was reached.
Definition: CCuddNavigator.h:131
std::size_t hash_type
Type for hashing.
Definition: pbori_defs.h:231
CTypes::idx_type idx_type
Type for indices.
Definition: CCuddNavigator.h:46
CCuddNavigator(const self &rhs)
Copy Constructor.
Definition: CCuddNavigator.h:83
const_access_type operator->() const
Constant pointer access operator.
Definition: CCuddNavigator.h:104
bool_type operator==(const self &rhs) const
Equality test.
Definition: CCuddNavigator.h:113
bool_type isTerminated() const
Check whether end of path was reached.
Definition: CCuddNavigator.h:128
void pointer
Definition: CCuddNavigator.h:70
self thenBranch() const
Increment in then direction.
Definition: CCuddNavigator.h:92
#define PBORI_ASSERT(arg)
Definition: pbori_defs.h:118
bool_type operator<(const self &rhs) const
Definition: CCuddNavigator.h:135
idx_type value_type
Return type of dereferencing operator.
Definition: CCuddNavigator.h:61
int idx_type
Type for indices.
Definition: pbori_defs.h:228
CTypes::hash_type hash_type
Type for hashing.
Definition: CCuddNavigator.h:55
bool_type operator>(const self &rhs) const
Definition: CCuddNavigator.h:137
const_access_type getNode() const
Constant pointer access operator.
Definition: CCuddNavigator.h:107
~CCuddNavigator()
Destructor.
Definition: CCuddNavigator.h:86
void recursiveDecRef(const MgrType &mgr) const
Force recursive decrementation of reference count.
Definition: CCuddNavigator.h:149
hash_type hash() const
Constant pointer access operator.
Definition: CCuddNavigator.h:110
bool_type operator>=(const self &rhs) const
Definition: CCuddNavigator.h:138
self & incrementThen()
Increment in then direction.
Definition: CCuddNavigator.h:191
const pointer_type const_access_type
Type for constantly accessing node pointer.
Definition: CCuddNavigator.h:43
CTypes::deg_type deg_type
Type for degrees.
Definition: CCuddNavigator.h:52
#define Cudd_Deref
Definition: prefix_internal.h:160
CCuddNavigator()
Default constructor.
Definition: CCuddNavigator.h:75
std::size_t size_type
Type for lengths, dimensions, etc.
Definition: pbori_defs.h:219
bool_type isValid() const
Check whether *this is not the default iterator self() (NULL pointer)
Definition: CCuddNavigator.h:125
BooleConstant operator*(const BooleConstant &lhs, const BooleConstant &rhs)
Definition: BooleConstant.h:124
This class defines an iterator for navigating through then and else branches of ZDDs.
Definition: CCuddNavigator.h:36
self & incrementElse()
Increment in else direction.
Definition: CCuddNavigator.h:203
bool_type operator<=(const self &rhs) const
Definition: CCuddNavigator.h:136
DdNode * pointer_type
Cudd's node pointer.
Definition: CCuddNavigator.h:40
for iterator_category
Definition: tags.h:60
#define PBORI_TRACE_FUNC(text)
Generate trace function if debugging.
Definition: pbori_defs.h:111
bool bool_type
Type for standard true/false statements.
Definition: pbori_defs.h:216
CCuddNavigator(pointer_type ptr)
Construct from node pointer.
Definition: CCuddNavigator.h:78
std::iterator_traits< pointer_type >::difference_type difference_type
Definition: CCuddNavigator.h:69
#define Cudd_Ref
Definition: prefix_internal.h:157