forked from tierney/compass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bdd_tree.h
84 lines (66 loc) · 1.36 KB
/
bdd_tree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once
#include <map>
#include <string>
#include <vector>
#include "bdd.h"
#include "compass_types.h"
#include "leveldb/db.h"
using std::map;
using std::string;
using std::vector;
namespace compass {
class BDDNode {
public:
BDDNode() : yes(NULL), no(NULL), accept(false), recv_rule_(false) {}
virtual ~BDDNode() {
if (NULL != yes) {
delete yes;
}
if (NULL != no) {
delete no;
}
}
void set_func(const string& func) {
func_.clear();
func_ = func;
}
string func() const {
return func_;
}
void Print() const {
std::cout << " ";
if (yes != NULL) {
yes->Print();
}
std::cout << func_ << std::endl;
if (no) {
no->Print();
}
std::cout << std::endl;
}
BDDNode *yes;
BDDNode *no;
bool accept;
string arg0;
string arg1;
string p2;
private:
bool recv_rule_;
string func_;
};
typedef bool (*PostFunc)(const Post&, const BDDNode&, leveldb::DB*);
typedef map<string, PostFunc> MyMap;
class BDDTree {
public:
BDDTree();
virtual ~BDDTree();
bool Query(const Post& post, vector<string>* receivers);
bool TreeQuery(const Post& post, const BDDNode& node, vector<string>* receivers);
void Parse(bdd root, const map<int, string>& bdd_id_to_meth);
void Print() const;
private:
MyMap name_func_;
BDDNode *root_;
leveldb::DB* db_;
};
} // namespace compass