libboloq
A library to replesent binary functions using Binary Decision Diagram.
 全て クラス 名前空間 関数 型定義 ページ
node.h
1 #pragma once
2 
3 namespace boloq {
4 
8 template<class LT, class IT>
9 class basic_node : public std::enable_shared_from_this<const basic_node<LT, IT>> {
10 private:
12 
13 public:
15  using index_type = IT;
17  using label_type = LT;
19  using node_ptr = std::shared_ptr<const self_type>;
20 
21 private:
22  const index_type _index;
23  const label_type _label;
24 
25  const node_ptr _then_node;
26  const node_ptr _else_node;
27 
28  const node_ptr self() const {
29  return this->shared_from_this();
30  }
31 
32 public:
33 
40  explicit constexpr basic_node(const index_type& i) :
41  _index(i), _label(std::numeric_limits<label_type>::max()),
42  _then_node(nullptr), _else_node(nullptr)
43  {}
44 
50  constexpr basic_node(const index_type& i, const label_type& l, const node_ptr& _then, const node_ptr& _else) :
51  _index(i), _label(l), _then_node(_then), _else_node(_else)
52  {}
53 
57  constexpr const index_type& index() const {return _index;}
58 
64  constexpr const label_type& label() const {return _label;}
65 
69  constexpr bool is_terminal() const {return index() < 2;};
70 
72  const node_ptr then_node() const {
73  if (is_terminal()) return self();
74  return _then_node;
75  }
77  const node_ptr else_node() const {
78  if (is_terminal()) return self();
79  return _else_node;
80  }
81 
85  template<class V>
86  void accept(V& visitor) const {
87  visitor(self());
88  }
89 };
90 
95 
99 struct null_deleter {
101  void operator()(void const *) const {}
102 };
103 
104 }
boloq の名前空間
Definition: boolean_function.h:3
void accept(V &visitor) const
visitorを受理します
Definition: node.h:86
const node_ptr then_node() const
Definition: node.h:72
std::shared_ptr< const self_type > node_ptr
Definition: node.h:19
Definition: boolean_function.h:215
constexpr bool is_terminal() const
このノードが終端かどうかを表します
Definition: node.h:69
constexpr basic_node(const index_type &i, const label_type &l, const node_ptr &_then, const node_ptr &_else)
コンストラクタ
Definition: node.h:50
constexpr basic_node(const index_type &i)
定節点を生成するコンストラクタ
Definition: node.h:40
IT index_type
インデックスを表す型
Definition: node.h:15
const node_ptr else_node() const
Definition: node.h:77
constexpr const index_type & index() const
ノードの内容一意に定まる値を返します
Definition: node.h:57
基本的なノードのクラス
Definition: node.h:9
constexpr const label_type & label() const
ノードのラベルを返します
Definition: node.h:64
LT label_type
ラベルを表す型
Definition: node.h:17