PolyBoRi
traits.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
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 
32 
34 
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 
54  typedef typename value_type::bool_type bool_type;
55 
57  typedef typename value_type::size_type size_type;
58 
60  typedef typename value_type::integer_type integer_type;
61 
63  typedef typename value_type::idx_type idx_type;
64 
66  typedef typename value_type::comp_type comp_type;
67 
69  typedef typename value_type::hash_type hash_type;
70 
72  typedef typename value_type::ostream_type ostream_type;
73 
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 
116 template <class FirstType, class SecondType>
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>
135 
136 template <class CuddLike>
137 struct manager_traits {
138 
139  typedef unsigned long large_size_type;
140  typedef long int refcount_type;
141 
144 
145  typedef DdNode* node_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
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>
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 
207 
208 #endif