PolyBoRi
pbori_traits.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
57 //*****************************************************************************
58 
59 #include <set>
60 #include <vector>
61 
62 // include basic definitions
63 #include "pbori_defs.h"
64 #include "pbori_tags.h"
65 // #include "CCuddInterface.h"
66 
67 #include <boost/preprocessor/cat.hpp>
68 #include <boost/preprocessor/seq/for_each.hpp>
69 #include <boost/preprocessor/facilities/expand.hpp>
70 #include <boost/preprocessor/stringize.hpp>
71 
72 #ifndef pbori_traits_h_
73 #define pbori_traits_h_
74 
76 
82 template <class ValueType>
83 class pbori_traits {
84 
85 public:
86  //-------------------------------------------------------------------------
87  // types for treatment of decision diagrams
88  //-------------------------------------------------------------------------
89  typedef ValueType value_type;
90 
92  typedef typename value_type::dd_type dd_type;
93 
94 // /// Manage variables to be used by polynomials over Boolean ring
95 // typedef typename value_type::manager_type manager_type;
96 
97 // /// Reference to decision diagramm manager
98 // typedef typename value_type::manager_reference manager_reference;
99 
100 // /// Define shared pointer to decision diagram manager
101 // typedef typename value_type::manager_ptr manager_ptr;
102 
103  //-------------------------------------------------------------------------
104  // types for several purposes
105  //-------------------------------------------------------------------------
106 
108  typedef typename value_type::bool_type bool_type;
109 
111  typedef typename value_type::size_type size_type;
112 
114  typedef typename value_type::integer_type integer_type;
115 
117  typedef typename value_type::idx_type idx_type;
118 
120  typedef typename value_type::comp_type comp_type;
121 
123  typedef typename value_type::hash_type hash_type;
124 
126  typedef typename value_type::ostream_type ostream_type;
127 
129  typedef typename value_type::easy_equality_property easy_equality_property;
130 };
131 
132 // Built-in types inherit global definitions
133 template <>
134 class pbori_traits<void>:
135  public CTypes, public equality_property<valid_tag> {
136 };
137 
138 template <>
139 class pbori_traits<int>:
140  public CTypes, public equality_property<valid_tag> {
141 };
142 
143 template <>
144 class pbori_traits<unsigned int>:
145  public CTypes, public equality_property<valid_tag> {
146 };
147 
148 template <>
149 class pbori_traits<long int>:
150  public CTypes, public equality_property<valid_tag> {
151 };
152 
153 
154 template <class ValueType>
155 class pbori_traits< std::set<ValueType> >:
156  public CTypes, public equality_property<invalid_tag> {
157 };
158 
159 template <class ValueType>
160 class pbori_traits< std::vector<ValueType> >:
161  public CTypes, public equality_property<invalid_tag> {
162 };
163 
164 
170 template <class FirstType, class SecondType>
171 class pbori_binary_traits;
172 
173 template <class OnlyType>
174 class pbori_binary_traits<OnlyType, OnlyType> {
175 public:
176  typedef typename OnlyType::easy_equality_property easy_equality_property;
177 };
178 
179 template <class FirstType, class SecondType>
181  public equality_property<invalid_tag>{
182 };
183 
184 
185 
186 
187 template <class MgrType>
188 struct manager_traits;
189 
190 template <>
191 struct manager_traits<Cudd> {
192  typedef ZDD dd_base;
193  typedef Cudd* core_type;
194  typedef Cudd& tmp_ref;
195 };
196 
197 template <>
198 struct manager_traits<Cudd*> :
199  public manager_traits<Cudd> {
200 };
201 
202 template <>
203 struct manager_traits<DdManager*> :
204  public manager_traits<Cudd> {
205 };
206 
207 template <class CuddLike>
209  typedef typename CuddLike::dd_type dd_base;
210  typedef typename CuddLike::mgrcore_ptr core_type;
211  typedef typename CuddLike::tmp_ref tmp_ref;
212 
213  typedef unsigned long large_size_type;
214  typedef long int refcount_type;
215 
218 
219  typedef DdNode* node_type;
220  typedef DdManager* mgrcore_type;
221 
222  typedef PFC errorfunc_type;
223  typedef node_type (*unary_int_function)(mgrcore_type, int);
224  typedef node_type (*void_function)(mgrcore_type);
225 
226  typedef DD_CTFP binary_function;
227  typedef node_type (*binary_int_function)(mgrcore_type, node_type, int);
228  typedef
230 
231  typedef int (*int_unary_function)(mgrcore_type, node_type);
232 };
233 
234 template <class CuddLike>
235 struct mgrcore_traits;
236 
237 template<>
238 struct mgrcore_traits<Cudd> {
239 
240  typedef unsigned long large_size_type;
241  typedef long int refcount_type;
242 
245 
246  typedef DdNode* node_type;
247  typedef DdManager* mgrcore_type;
248 
249  typedef PFC errorfunc_type;
250  typedef node_type (*unary_int_function)(mgrcore_type, int);
251  typedef node_type (*void_function)(mgrcore_type);
252 
253  typedef DD_CTFP binary_function;
254  typedef node_type (*binary_int_function)(mgrcore_type, node_type, int);
255  typedef
257 
258  typedef int (*int_unary_function)(mgrcore_type, node_type);
259 };
260 
261 #define PB_DECLARE_CUDD_TYPES(fromspace) \
262  typedef fromspace::errorfunc_type errorfunc_type; \
263  typedef fromspace::large_size_type large_size_type; \
264  typedef fromspace::refcount_type refcount_type; \
265  typedef fromspace::node_type node_type; \
266  typedef fromspace::mgrcore_type mgrcore_type; \
267  typedef fromspace::unary_int_function unary_int_function; \
268  typedef fromspace::void_function void_function; \
269  typedef fromspace::binary_function binary_function; \
270  typedef fromspace::binary_int_function binary_int_function; \
271  typedef fromspace::ternary_function ternary_function; \
272  typedef fromspace::int_unary_function int_unary_function; \
273  typedef fromspace::size_type size_type;\
274  typedef fromspace::idx_type idx_type;
275 
276 // template <>
277 // struct manager_traits<CCuddInterface::mgrcore_ptr> :
278 // public manager_traits<CCuddInterface> {
279 // };
280 
281 
282 template <class ZDDType>
283 struct zdd_traits;
284 
285 template <>
286 struct zdd_traits<ZDD> {
287  typedef Cudd manager_base;
288 };
289 
290 template <>
291 struct zdd_traits<CCuddZDD> {
293 };
294 
295 
296 #define PB_BINARY_FUNC_CALL(count, funcname, arg_pair) \
297  BOOST_PP_EXPAND(funcname(BOOST_PP_SEQ_HEAD(arg_pair), \
298  BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_TAIL(arg_pair))))
299 
300 template<unsigned ErrorNumber>
302  typedef const char* result_type;
303 
304  result_type operator()() const;
305 };
306 
307 
308 
309 
310 #define PB_CUDD_ERROR_TRAITS(errcode, errstr) \
311  template<> inline cudd_error_traits<errcode>::result_type \
312  cudd_error_traits<errcode>::operator()() const { \
313  return BOOST_PP_STRINGIZE(errstr); }
314 
315 BOOST_PP_SEQ_FOR_EACH( PB_BINARY_FUNC_CALL, PB_CUDD_ERROR_TRAITS,
316  ((CUDD_MEMORY_OUT)(Out of memory.))
317  ((CUDD_TOO_MANY_NODES)(Too many nodes.))
318  ((CUDD_MAX_MEM_EXCEEDED)(Maximum memory exceeded.))
319  ((CUDD_INVALID_ARG)(Invalid argument.))
320  ((CUDD_INTERNAL_ERROR)(Internal error.))
321  ((CUDD_NO_ERROR)(Unexpected error.))
322  )
323 
324 #undef PB_CUDD_ERROR_TRAITS
325 
327 
328 #endif