PolyBoRi
pbori_defs.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
159 //*****************************************************************************
160 
161 # include <cstddef>
162 
163 // load cudd's c++ interface
164 # include <cuddObj.hh>
165 
166 #ifndef pbori_defs_h_
167 #define pbori_defs_h_
168 
170 #ifdef __GNUC__
171 #define LIKELY(expression) (__builtin_expect(!!(expression), 1))
172 #define UNLIKELY(expression) (__builtin_expect(!!(expression), 0))
173 #else
174 #define LIKELY(expression) (expression)
175 #define UNLIKELY(expression) (expression)
176 #endif
177 
179 #define PBORINAME polybori
180 
182 #ifndef PBORI_NO_DEVELOPER
183 # define PBORI_DEVELOPER
184 #endif
185 
186 #ifndef PBORI_NO_NAMESPACES
187 
189 # define BEGIN_NAMESPACE_PBORI namespace PBORINAME {
190 
192 # define END_NAMESPACE_PBORI } // end of namespace
193 
195 # define USING_NAMESPACE_PBORI using namespace PBORINAME;
196 
198 # define PBORI PBORINAME
199 
201 # define USING_PBORI using PBORI
202 
204 # define PBORI_BEGIN_NAMESPACE( sub_space ) namespace sub_space {
205 
207 # define PBORI_END_NAMESPACE }
208 
209 #else
210 
211 # define BEGIN_NAMESPACE_PBORI
212 # define END_NAMESPACE_PBORI
213 # define USING_NAMESPACE_PBORI
214 # define PBORI
215 # define USING_PBORI
216 # define PBORI_BEGIN_NAMESPACE( sub_space )
217 # define PBORI_END_NAMESPACE
218 
219 #endif // PBORI_NO_NAMESPACES
220 
222 #ifdef PBORI_DEBUG_TRACE
223 # include <iostream>
224 # define PBORI_TRACE_FUNC(text) std::cerr << text << std::endl;
225 #else
226 # define PBORI_TRACE_FUNC(text)
227 #endif
228 
230 #ifndef PBORI_NO_STDSTREAMS
231 
232 # include <iostream>
233 # define PBORI_OSTREAM std::ostream
234 
235 #else
236 
238 
240 struct PBORI_OSTREAM {};
241 
242 template <class StreamedType>
244 operator<<(PBORI_OSTREAM& dummy, const StreamedType&) {
245  return dummy;
246 };
248 
249 #endif // of #ifndef PBORI_NO_STDSTREAMS
250 
252 #ifndef PBORI_NO_BOOST_PTR
253 
254 # include <boost/shared_ptr.hpp>
255 # define PBORI_SHARED_PTR(Type) boost::shared_ptr<Type>
256 
258 
259 // Clean second pointer
260 template <class ValueType>
261 void
263  const PBORI_SHARED_PTR(ValueType)& ){
264  // nothing needed for boost::shared_ptr
265 }
267 
268 #else
269 
279 template <class ValueType>
280 class pbori_shared_ptr {
281 public:
282 
284  typedef ValueType value_type;
285 
287  typedef pbori_shared_ptr<value_type> self;
288 
291  pbori_shared_ptr(value_type* pRhs = NULL):
292  pVal(pRhs), is_shared(pRhs == NULL) {}
293 
295  pbori_shared_ptr(const self& rhs):
296  pVal(rhs.pVal), is_shared(true) {}
297 
299  ~pbori_shared_ptr(){ if (!is_shared) delete pVal; }
300 
302  self& operator=(const self& rhs) {
303  pVal = rhs.pVal; is_shared = true;
304  return *this;
305  }
306 
308 
309  value_type* operator->(){ return pVal; }
310  const value_type* operator->() const { return pVal; }
311  value_type& operator*(){ return *pVal; }
312  const value_type& operator*() const { return *pVal; }
313  bool operator==(const self& rhs) const { return (pVal==rhs.pVal); }
314  operator bool() const { return pVal != NULL; }
316 
318  bool unique() const { return !is_shared; }
319 
320 protected:
322  value_type* pVal;
323 
325  bool is_shared;
326 };
328 
329 # define PBORI_SHARED_PTR(Type) PBORI::pbori_shared_ptr<Type>
330 
332 // Clean second pointer
333 template <class ValueType>
334 void
335 pbori_shared_ptr_postclean( const PBORI_SHARED_PTR(ValueType)& lhs,
336  PBORI_SHARED_PTR(ValueType)& rhs ){
337  if( lhs.unique() && (lhs == rhs) )
338  rhs = PBORI_SHARED_PTR(ValueType)();
339 }
341 
342 
343 #endif // of #ifndef PBORI_NO_BOOST_PTR
344 
345 
347 
349 template <class DDType>
350 class CDDInterface;
351 
353 template <class ManType>
354 class CDDManager;
355 
361 struct COrderEnums {
363  enum ordercodes {
364  lp,
368  block_dp_asc
369  };
370 };
371 
377 struct CErrorEnums {
379  enum errorcodes {
380  alright = 0,
391 
392  last_error
393  };
394 };
395 
404  less_than = -1,
405  equality = 0,
406  greater_than = +1,
407  less_or_equal_max = 0,
408  greater_or_equal_min = 0
409  };
410 
411  enum { max_idx = CUDD_MAXINDEX };
412 };
413 
418 struct CAuxTypes {
419  //-------------------------------------------------------------------------
420  // types for several purposes
421  //-------------------------------------------------------------------------
422 
424  typedef bool bool_type;
425 
427  typedef unsigned int size_type;
428 
430  typedef int integer_type;
431 
433  typedef int idx_type;
434 
436  typedef std::size_t hash_type;
437 
439  typedef unsigned int errornum_type;
440 
442  typedef int comp_type;
443 
445  typedef int ordercode_type;
446 
448  typedef const char* errortext_type;
449 
452 
454  typedef const char* vartext_type;
455 };
456 
457 class CCuddZDD;
458 class CCuddInterface;
459 
460 
469 struct CTypes:
470  public COrderEnums, public CErrorEnums, public CCompareEnums,
471  public CAuxTypes {
472  //-------------------------------------------------------------------------
473  // types for treatment of decision diagrams
474  //-------------------------------------------------------------------------
475 
477 
483 
485  typedef CCuddZDD dd_base;
486  // typedef ZDD dd_base;
487 
490 
492  typedef ZDDvector ddvector_type;
493 
496 
499 
502 
505 
507  static idx_type max_index() { return CCompareEnums::max_idx; }
508 };
509 
511 
512 #ifdef PBORI_DEVELOPER
513 # define PBORI_NOT_IMPLEMENTED \
514  throw PBORI::PBoRiError(PBORI::CTypes::not_implemented);
515 #else
516 # define PBORI_NOT_IMPLEMENTED
517 #endif
518 
519 // Set default addition method
520 #if defined(PBORI_ADD_BY_ITE) || defined(PBORI_ADD_BY_OR) \
521  || defined(PBORI_ADD_BY_UNION) || defined(PBORI_ADD_BY_EXTRA_XOR) \
522  || defined(PBORI_ADD_BY_XOR)
523 #else
524 # define PBORI_ADD_BY_XOR
525 #endif
526 
527 
528 // Set default union-xor method
529 #ifdef PBORI_ADD_BY_XOR
530 # define PBORI_LOWLEVEL_XOR
531 #endif
532 
533 // Set default method for getting all used variables
534 #if defined(PBORI_USEDVARS_BY_IDX) || defined(PBORI_USEDVARS_BY_TRANSFORM) \
535  || defined(PBORI_USEDVARS_HIGHLEVEL)|| defined(PBORI_USEDVARS_BY_SUPPORT)\
536  || defined(PBORI_USEDVARS_EXTRA)
537 #else
538 # define PBORI_USEDVARS_BY_IDX
539 //PBORI_USEDVARS_EXTRA
540 #endif
541 
542 #endif // of #ifndef pbori_defs_h_