1 // -*- c++ -*- 2 //***************************************************************************** 3 /** @file traits.h 4 * 5 * @author Alexander Dreyer 6 * @date 2006-04-24 7 * 8 * This file defines properties of built-in an polybori types. 9 * 10 * @par Copyright: 11 * (c) 2006-2010 by The PolyBoRi Team 12 * 13 **/ 14 //***************************************************************************** 15 16 #ifndef polybori_common_common_traits_h_ 17 #define polybori_common_common_traits_h_ 18 19 #include <set> 20 #include <vector> 21 22 // include basic definitions 23 #include <polybori/pbori_defs.h> 24 #include <polybori/common/tags.h> 25 26 #include <boost/preprocessor/cat.hpp> 27 #include <boost/preprocessor/seq/for_each.hpp> 28 #include <boost/preprocessor/facilities/expand.hpp> 29 #include <boost/preprocessor/stringize.hpp> 30 31 BEGIN_NAMESPACE_PBORI 32 33 typedef PBORI_PREFIX(DdManager) DdManager; 34 35 /** @class pbori_traits 36 * @brief This class contains property definitions to be used in polybori 37 * classes 38 * 39 **/ 40 template <class ValueType> 41 class pbori_traits { 42 43 public: 44 //------------------------------------------------------------------------- 45 // types for treatment of decision diagrams 46 //------------------------------------------------------------------------- 47 typedef ValueType value_type; 48 49 //------------------------------------------------------------------------- 50 // types for several purposes 51 //------------------------------------------------------------------------- 52 53 /// Type for standard true/false statements 54 typedef typename value_type::bool_type bool_type; 55 56 /// Type for lengths, dimensions, etc. 57 typedef typename value_type::size_type size_type; 58 59 /// Type for integer numbers 60 typedef typename value_type::integer_type integer_type; 61 62 /// Type for indices 63 typedef typename value_type::idx_type idx_type; 64 65 /// Type for comparisons 66 typedef typename value_type::comp_type comp_type; 67 68 /// Type for hashing 69 typedef typename value_type::hash_type hash_type; 70 71 /// Type for out-stream 72 typedef typename value_type::ostream_type ostream_type; 73 74 /// The property whether the equality check is easy 75 typedef typename value_type::easy_equality_property easy_equality_property; 76 }; 77 78 // Built-in types inherit global definitions 79 template <> 80 class pbori_traits<void>: 81 public CTypes, public equality_property<valid_tag> { 82 }; 83 84 template <> 85 class pbori_traits<int>: 86 public CTypes, public equality_property<valid_tag> { 87 }; 88 89 template <> 90 class pbori_traits<unsigned int>: 91 public CTypes, public equality_property<valid_tag> { 92 }; 93 94 template <> 95 class pbori_traits<long int>: 96 public CTypes, public equality_property<valid_tag> { 97 }; 98 99 100 template <class ValueType> 101 class pbori_traits< std::set<ValueType> >: 102 public CTypes, public equality_property<invalid_tag> { 103 }; 104 105 template <class ValueType> 106 class pbori_traits< std::vector<ValueType> >: 107 public CTypes, public equality_property<invalid_tag> { 108 }; 109 110 111 /** @class pbori_binary_traits 112 * @brief This class contains property definitions related to two types 113 * to be used in polybori classes. 114 * 115 **/ 116 template <class FirstType, class SecondType> 117 class pbori_binary_traits; 118 119 template <class OnlyType> 120 class pbori_binary_traits<OnlyType, OnlyType> { 121 public: 122 typedef typename OnlyType::easy_equality_property easy_equality_property; 123 }; 124 125 template <class FirstType, class SecondType> 126 class pbori_binary_traits: 127 public equality_property<invalid_tag>{ 128 }; 129 130 131 132 133 template <class MgrType> 134 struct manager_traits; 135 136 template <class CuddLike> 137 struct manager_traits { 138 139 typedef unsigned long large_size_type; 140 typedef long int refcount_type; 141 142 typedef CTypes::idx_type idx_type; 143 typedef CTypes::size_type size_type; 144 145 typedef DdNode* node_type; 146 typedef DdManager* mgrcore_type; 147 148 typedef node_type (*unary_int_function)(mgrcore_type, int); 149 typedef node_type (*void_function)(mgrcore_type); 150 151 typedef DD_CTFP binary_function; 152 typedef node_type (*binary_int_function)(mgrcore_type, node_type, int); 153 typedef 154 node_type (*ternary_function)(mgrcore_type, node_type, node_type, node_type); 155 156 typedef int (*int_unary_function)(mgrcore_type, node_type); 157 }; 158 159 160 #define PB_DECLARE_CUDD_TYPES(fromspace) \ 161 typedef fromspace::errorfunc_type errorfunc_type; \ 162 typedef fromspace::large_size_type large_size_type; \ 163 typedef fromspace::refcount_type refcount_type; \ 164 typedef fromspace::node_type node_type; \ 165 typedef fromspace::mgrcore_type mgrcore_type; \ 166 typedef fromspace::unary_int_function unary_int_function; \ 167 typedef fromspace::void_function void_function; \ 168 typedef fromspace::binary_function binary_function; \ 169 typedef fromspace::binary_int_function binary_int_function; \ 170 typedef fromspace::ternary_function ternary_function; \ 171 typedef fromspace::int_unary_function int_unary_function; \ 172 typedef fromspace::size_type size_type;\ 173 typedef fromspace::idx_type idx_type; 174 175 176 #define PB_BINARY_FUNC_CALL(count, funcname, arg_pair) \ 177 BOOST_PP_EXPAND(funcname(BOOST_PP_SEQ_HEAD(arg_pair), \ 178 BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_TAIL(arg_pair)))) 179 180 template<unsigned ErrorNumber> 181 struct cudd_error_traits { 182 typedef const char* result_type; 183 184 result_type operator()() const; 185 }; 186 187 188 189 190 #define PB_CUDD_ERROR_TRAITS(errcode, errstr) \ 191 template<> inline cudd_error_traits<errcode>::result_type \ 192 cudd_error_traits<errcode>::operator()() const { \ 193 return BOOST_PP_STRINGIZE(errstr); } 194 195 BOOST_PP_SEQ_FOR_EACH( PB_BINARY_FUNC_CALL, PB_CUDD_ERROR_TRAITS, 196 ((CUDD_MEMORY_OUT)(Out of memory.)) 197 ((CUDD_TOO_MANY_NODES)(Too many nodes.)) 198 ((CUDD_MAX_MEM_EXCEEDED)(Maximum memory exceeded.)) 199 ((CUDD_INVALID_ARG)(Invalid argument.)) 200 ((CUDD_INTERNAL_ERROR)(Internal error.)) 201 ((CUDD_NO_ERROR)(Unexpected error.)) 202 ) 203 204 #undef PB_CUDD_ERROR_TRAITS 205 206 END_NAMESPACE_PBORI 207 208 #endif 209