TdZdd  1.1
A top-down/breadth-first decision diagram manipulation framework
DdEval.hpp
1 /*
2  * TdZdd: a Top-down/Breadth-first Decision Diagram Manipulation Framework
3  * by Hiroaki Iwashita <iwashita@erato.ist.hokudai.ac.jp>
4  * Copyright (c) 2014 ERATO MINATO Project
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #include <cassert>
28 #include <iostream>
29 
30 namespace tdzdd {
31 
38 template<typename T, int ARITY>
39 class DdValues {
40  T const* value[ARITY];
41  int level[ARITY];
42 
43 public:
49  T const& get(int b) const {
50  assert(0 <= b && b < ARITY);
51  return *value[b];
52  }
53 
59  int getLevel(int b) const {
60  assert(0 <= b && b < ARITY);
61  return level[b];
62  }
63 
64  void setReference(int b, T const& v) {
65  assert(0 <= b && b < ARITY);
66  value[b] = &v;
67  }
68 
69  void setLevel(int b, int i) {
70  assert(0 <= b && b < ARITY);
71  level[b] = i;
72  }
73 
74  friend std::ostream& operator<<(std::ostream& os, DdValues const& o) {
75  os << "(";
76  for (int b = 0; b < ARITY; ++b) {
77  if (b != 0) os << ",";
78  os << o.value(b) << "@" << o.level(b);
79  }
80  return os << ")";
81  }
82 };
83 
101 template<typename E, typename T, typename R = T>
102 class DdEval {
103 public:
104  E& entity() {
105  return *static_cast<E*>(this);
106  }
107 
108  E const& entity() const {
109  return *static_cast<E const*>(this);
110  }
111 
116  bool isThreadSafe() const {
117  return true;
118  }
119 
124  bool showMessages() const {
125  return false;
126  }
127 
132  void initialize(int level) {
133  }
134 
140  R getValue(T const& v) {
141  return R(v);
142  }
143 
148  void destructLevel(int i) {
149  }
150 };
151 
152 } // namespace tdzdd
bool showMessages() const
Declares preference to show messages.
Definition: DdEval.hpp:124
void destructLevel(int i)
Destructs i-th level of data storage.
Definition: DdEval.hpp:148
R getValue(T const &v)
Makes a result value.
Definition: DdEval.hpp:140
bool isThreadSafe() const
Declares thread-safety.
Definition: DdEval.hpp:116
void initialize(int level)
Initialization.
Definition: DdEval.hpp:132
int getLevel(int b) const
Returns the level of the b-th child.
Definition: DdEval.hpp:59
Collection of child node values/levels for DdEval::evalNode function interface.
Definition: DdEval.hpp:39
Base class of DD evaluators.
Definition: DdEval.hpp:102