PolyBoRi
|
00001 // -*- c++ -*- 00002 //***************************************************************************** 00162 //***************************************************************************** 00163 00164 # include <cstddef> 00165 00166 // load cudd's c++ interface 00167 # include <cuddObj.hh> 00168 00169 #ifndef pbori_defs_h_ 00170 #define pbori_defs_h_ 00171 00173 #ifdef __GNUC__ 00174 #define LIKELY(expression) (__builtin_expect(!!(expression), 1)) 00175 #define UNLIKELY(expression) (__builtin_expect(!!(expression), 0)) 00176 #else 00177 #define LIKELY(expression) (expression) 00178 #define UNLIKELY(expression) (expression) 00179 #endif 00180 00182 #define PBORINAME polybori 00183 00185 #ifndef PBORI_NO_DEVELOPER 00186 # define PBORI_DEVELOPER 00187 #endif 00188 00189 #ifndef PBORI_NO_NAMESPACES 00190 00192 # define BEGIN_NAMESPACE_PBORI namespace PBORINAME { 00193 00195 # define END_NAMESPACE_PBORI } // end of namespace 00196 00198 # define USING_NAMESPACE_PBORI using namespace PBORINAME; 00199 00201 # define PBORI PBORINAME 00202 00204 # define USING_PBORI using PBORI 00205 00207 # define PBORI_BEGIN_NAMESPACE( sub_space ) namespace sub_space { 00208 00210 # define PBORI_END_NAMESPACE } 00211 00212 #else 00213 00214 # define BEGIN_NAMESPACE_PBORI 00215 # define END_NAMESPACE_PBORI 00216 # define USING_NAMESPACE_PBORI 00217 # define PBORI 00218 # define USING_PBORI 00219 # define PBORI_BEGIN_NAMESPACE( sub_space ) 00220 # define PBORI_END_NAMESPACE 00221 00222 #endif // PBORI_NO_NAMESPACES 00223 00225 #ifdef PBORI_DEBUG_TRACE 00226 # include <iostream> 00227 # define PBORI_TRACE_FUNC(text) std::cerr << text << std::endl; 00228 #else 00229 # define PBORI_TRACE_FUNC(text) 00230 #endif 00231 00233 #ifndef PBORI_NO_STDSTREAMS 00234 00235 # include <iostream> 00236 # define PBORI_OSTREAM std::ostream 00237 00238 #else 00239 00240 BEGIN_NAMESPACE_PBORI 00241 00243 struct PBORI_OSTREAM {}; 00244 00245 template <class StreamedType> 00246 PBORI_OSTREAM& 00247 operator<<(PBORI_OSTREAM& dummy, const StreamedType&) { 00248 return dummy; 00249 }; 00250 END_NAMESPACE_PBORI 00251 00252 #endif // of #ifndef PBORI_NO_STDSTREAMS 00253 00255 #ifndef PBORI_NO_BOOST_PTR 00256 00257 # include <boost/shared_ptr.hpp> 00258 # define PBORI_SHARED_PTR(Type) boost::shared_ptr<Type> 00259 00260 BEGIN_NAMESPACE_PBORI 00261 00262 // Clean second pointer 00263 template <class ValueType> 00264 void 00265 pbori_shared_ptr_postclean( const PBORI_SHARED_PTR(ValueType)&, 00266 const PBORI_SHARED_PTR(ValueType)& ){ 00267 // nothing needed for boost::shared_ptr 00268 } 00269 END_NAMESPACE_PBORI 00270 00271 #else 00272 00273 BEGIN_NAMESPACE_PBORI 00282 template <class ValueType> 00283 class pbori_shared_ptr { 00284 public: 00285 00287 typedef ValueType value_type; 00288 00290 typedef pbori_shared_ptr<value_type> self; 00291 00294 pbori_shared_ptr(value_type* pRhs = NULL): 00295 pVal(pRhs), is_shared(pRhs == NULL) {} 00296 00298 pbori_shared_ptr(const self& rhs): 00299 pVal(rhs.pVal), is_shared(true) {} 00300 00302 ~pbori_shared_ptr(){ if (!is_shared) delete pVal; } 00303 00305 self& operator=(const self& rhs) { 00306 pVal = rhs.pVal; is_shared = true; 00307 return *this; 00308 } 00309 00311 00312 value_type* operator->(){ return pVal; } 00313 const value_type* operator->() const { return pVal; } 00314 value_type& operator*(){ return *pVal; } 00315 const value_type& operator*() const { return *pVal; } 00316 bool operator==(const self& rhs) const { return (pVal==rhs.pVal); } 00317 operator bool() const { return pVal != NULL; } 00319 00321 bool unique() const { return !is_shared; } 00322 00323 protected: 00325 value_type* pVal; 00326 00328 bool is_shared; 00329 }; 00330 END_NAMESPACE_PBORI 00331 00332 # define PBORI_SHARED_PTR(Type) PBORI::pbori_shared_ptr<Type> 00333 00334 BEGIN_NAMESPACE_PBORI 00335 // Clean second pointer 00336 template <class ValueType> 00337 void 00338 pbori_shared_ptr_postclean( const PBORI_SHARED_PTR(ValueType)& lhs, 00339 PBORI_SHARED_PTR(ValueType)& rhs ){ 00340 if( lhs.unique() && (lhs == rhs) ) 00341 rhs = PBORI_SHARED_PTR(ValueType)(); 00342 } 00343 END_NAMESPACE_PBORI 00344 00345 00346 #endif // of #ifndef PBORI_NO_BOOST_PTR 00347 00348 00349 BEGIN_NAMESPACE_PBORI 00350 00352 template <class DDType> 00353 class CDDInterface; 00354 00356 template <class ManType> 00357 class CDDManager; 00358 00364 struct COrderEnums { 00366 enum ordercodes { 00367 lp, 00368 dlex, 00369 dp_asc, 00370 block_dlex, 00371 block_dp_asc 00372 }; 00373 }; 00374 00380 struct CErrorEnums { 00382 enum errorcodes { 00383 alright = 0, 00384 failed, 00385 no_ring, 00386 invalid, 00387 out_of_bounds, 00388 io_error, 00389 monomial_zero, 00390 illegal_on_zero, 00391 division_by_zero, 00392 invalid_ite, 00393 not_implemented, 00394 00395 last_error 00396 }; 00397 }; 00398 00404 struct CCompareEnums { 00406 enum comparecodes { 00407 less_than = -1, 00408 equality = 0, 00409 greater_than = +1, 00410 less_or_equal_max = 0, 00411 greater_or_equal_min = 0 00412 }; 00413 00414 enum { max_idx = CUDD_MAXINDEX }; 00415 }; 00416 00421 struct CAuxTypes { 00422 //------------------------------------------------------------------------- 00423 // types for several purposes 00424 //------------------------------------------------------------------------- 00425 00427 typedef bool bool_type; 00428 00430 typedef unsigned int size_type; 00432 typedef int deg_type; 00433 00435 typedef int integer_type; 00436 00438 typedef int idx_type; 00439 00441 typedef std::size_t hash_type; 00442 00444 typedef unsigned int errornum_type; 00445 00447 typedef int comp_type; 00448 00450 typedef int ordercode_type; 00451 00453 typedef const char* errortext_type; 00454 00456 typedef PBORI_OSTREAM ostream_type; 00457 00459 typedef const char* vartext_type; 00460 }; 00461 00462 class CCuddZDD; 00463 class CCuddInterface; 00464 00465 00474 struct CTypes: 00475 public COrderEnums, public CErrorEnums, public CCompareEnums, 00476 public CAuxTypes { 00477 //------------------------------------------------------------------------- 00478 // types for treatment of decision diagrams 00479 //------------------------------------------------------------------------- 00480 00482 00483 typedef COrderEnums orderenums_type; 00484 typedef CErrorEnums errorenums_type; 00485 typedef CCompareEnums compenums_type; 00486 typedef CAuxTypes auxtypes_type; 00488 00490 typedef CCuddZDD dd_base; 00491 // typedef ZDD dd_base; 00492 00494 typedef CDDInterface<dd_base> dd_type; 00495 00497 typedef ZDDvector ddvector_type; 00498 00500 typedef CCuddInterface manager_base; 00501 00503 typedef CDDManager<manager_base> manager_type; 00504 00506 typedef CDDManager<manager_base&> manager_reference; 00507 00509 typedef PBORI_SHARED_PTR(manager_type) manager_ptr; 00510 00512 static idx_type max_index() { return CCompareEnums::max_idx; } 00513 }; 00514 00515 END_NAMESPACE_PBORI 00516 00517 #ifdef PBORI_DEVELOPER 00518 # define PBORI_NOT_IMPLEMENTED \ 00519 throw PBORI::PBoRiError(PBORI::CTypes::not_implemented); 00520 #else 00521 # define PBORI_NOT_IMPLEMENTED 00522 #endif 00523 00524 // Set default addition method 00525 #if defined(PBORI_ADD_BY_ITE) || defined(PBORI_ADD_BY_OR) \ 00526 || defined(PBORI_ADD_BY_UNION) || defined(PBORI_ADD_BY_EXTRA_XOR) \ 00527 || defined(PBORI_ADD_BY_XOR) 00528 #else 00529 # define PBORI_ADD_BY_XOR 00530 #endif 00531 00532 00533 // Set default union-xor method 00534 #ifdef PBORI_ADD_BY_XOR 00535 # define PBORI_LOWLEVEL_XOR 00536 #endif 00537 00538 // Set default method for getting all used variables 00539 #if defined(PBORI_USEDVARS_BY_IDX) || defined(PBORI_USEDVARS_BY_TRANSFORM) \ 00540 || defined(PBORI_USEDVARS_HIGHLEVEL)|| defined(PBORI_USEDVARS_BY_SUPPORT)\ 00541 || defined(PBORI_USEDVARS_EXTRA) 00542 #else 00543 # define PBORI_USEDVARS_BY_IDX 00544 //PBORI_USEDVARS_EXTRA 00545 #endif 00546 00547 #endif // of #ifndef pbori_defs_h_