PolyBoRi
traits.h
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //*****************************************************************************
00014 //*****************************************************************************
00015 
00016 #ifndef polybori_common_common_traits_h_
00017 #define polybori_common_common_traits_h_
00018 
00019 #include <set>
00020 #include <vector>
00021 
00022 // include basic definitions
00023 #include <polybori/pbori_defs.h>
00024 #include <polybori/common/tags.h>
00025 
00026 #include <boost/preprocessor/cat.hpp>
00027 #include <boost/preprocessor/seq/for_each.hpp>
00028 #include <boost/preprocessor/facilities/expand.hpp>
00029 #include <boost/preprocessor/stringize.hpp>
00030 
00031 BEGIN_NAMESPACE_PBORI
00032 
00033 typedef PBORI_PREFIX(DdManager) DdManager;
00034 
00040 template <class ValueType>
00041 class pbori_traits {
00042 
00043 public:
00044   //-------------------------------------------------------------------------
00045   // types for treatment of decision diagrams
00046   //-------------------------------------------------------------------------
00047   typedef ValueType value_type;
00048 
00049   //-------------------------------------------------------------------------
00050   // types for several purposes
00051   //-------------------------------------------------------------------------
00052 
00054   typedef typename value_type::bool_type bool_type;
00055 
00057   typedef typename value_type::size_type size_type;
00058 
00060   typedef typename value_type::integer_type integer_type;
00061 
00063    typedef typename value_type::idx_type idx_type;
00064 
00066   typedef typename value_type::comp_type comp_type;
00067 
00069   typedef typename value_type::hash_type hash_type;
00070 
00072   typedef typename value_type::ostream_type ostream_type;
00073 
00075   typedef typename value_type::easy_equality_property easy_equality_property;
00076 };
00077 
00078 // Built-in types inherit global definitions
00079 template <>
00080 class pbori_traits<void>:
00081   public CTypes, public equality_property<valid_tag> {
00082 };
00083 
00084 template <>
00085 class pbori_traits<int>:
00086   public CTypes, public equality_property<valid_tag> {
00087 };
00088 
00089 template <>
00090 class pbori_traits<unsigned int>:
00091   public CTypes, public equality_property<valid_tag> {
00092 };
00093 
00094 template <>
00095 class pbori_traits<long int>:
00096   public CTypes, public equality_property<valid_tag> {
00097 };
00098 
00099 
00100 template <class ValueType>
00101 class pbori_traits< std::set<ValueType> >:
00102   public CTypes, public equality_property<invalid_tag> {
00103 };
00104 
00105 template <class ValueType>
00106 class pbori_traits< std::vector<ValueType> >:
00107   public CTypes, public equality_property<invalid_tag> {
00108 };
00109 
00110 
00116 template <class FirstType, class SecondType>
00117 class pbori_binary_traits;
00118 
00119 template <class OnlyType>
00120 class pbori_binary_traits<OnlyType, OnlyType> {
00121 public:
00122   typedef typename OnlyType::easy_equality_property easy_equality_property;
00123 };
00124 
00125 template <class FirstType, class SecondType>
00126 class pbori_binary_traits:
00127   public equality_property<invalid_tag>{
00128 };
00129 
00130 
00131 
00132 
00133 template <class MgrType>
00134 struct manager_traits;
00135 
00136 template <class CuddLike>
00137 struct manager_traits {
00138 
00139   typedef unsigned long large_size_type;
00140   typedef long int refcount_type;
00141 
00142   typedef CTypes::idx_type idx_type;
00143   typedef CTypes::size_type size_type;
00144 
00145   typedef DdNode* node_type;
00146   typedef DdManager* mgrcore_type;
00147 
00148   typedef node_type (*unary_int_function)(mgrcore_type, int);
00149   typedef node_type (*void_function)(mgrcore_type);
00150 
00151   typedef DD_CTFP binary_function;
00152   typedef node_type (*binary_int_function)(mgrcore_type, node_type, int);
00153   typedef 
00154   node_type (*ternary_function)(mgrcore_type, node_type, node_type, node_type);
00155 
00156   typedef int (*int_unary_function)(mgrcore_type, node_type);
00157 };
00158 
00159 
00160 #define PB_DECLARE_CUDD_TYPES(fromspace) \
00161   typedef fromspace::errorfunc_type errorfunc_type;           \
00162   typedef fromspace::large_size_type large_size_type;         \
00163   typedef fromspace::refcount_type refcount_type;             \
00164   typedef fromspace::node_type node_type;                     \
00165   typedef fromspace::mgrcore_type mgrcore_type;               \
00166   typedef fromspace::unary_int_function unary_int_function;   \
00167   typedef fromspace::void_function void_function;             \
00168   typedef fromspace::binary_function binary_function;         \
00169   typedef fromspace::binary_int_function binary_int_function; \
00170   typedef fromspace::ternary_function ternary_function;       \
00171   typedef fromspace::int_unary_function int_unary_function;   \
00172   typedef fromspace::size_type size_type;\
00173   typedef fromspace::idx_type idx_type;
00174 
00175 
00176 #define PB_BINARY_FUNC_CALL(count, funcname, arg_pair)                        \
00177   BOOST_PP_EXPAND(funcname(BOOST_PP_SEQ_HEAD(arg_pair),                       \
00178                            BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_TAIL(arg_pair))))
00179 
00180 template<unsigned ErrorNumber>
00181 struct cudd_error_traits {
00182   typedef const char* result_type;
00183 
00184   result_type operator()() const;
00185 };
00186 
00187 
00188 
00189 
00190 #define PB_CUDD_ERROR_TRAITS(errcode, errstr)                                \
00191   template<> inline cudd_error_traits<errcode>::result_type                  \
00192   cudd_error_traits<errcode>::operator()() const {                           \
00193     return BOOST_PP_STRINGIZE(errstr); }
00194 
00195 BOOST_PP_SEQ_FOR_EACH( PB_BINARY_FUNC_CALL, PB_CUDD_ERROR_TRAITS, 
00196                        ((CUDD_MEMORY_OUT)(Out of memory.))
00197                        ((CUDD_TOO_MANY_NODES)(Too many nodes.))
00198                        ((CUDD_MAX_MEM_EXCEEDED)(Maximum memory exceeded.))
00199                        ((CUDD_INVALID_ARG)(Invalid argument.))
00200                        ((CUDD_INTERNAL_ERROR)(Internal error.))
00201                        ((CUDD_NO_ERROR)(Unexpected error.))
00202                        )
00203 
00204 #undef PB_CUDD_ERROR_TRAITS
00205 
00206 END_NAMESPACE_PBORI
00207 
00208 #endif