-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooleanVar.cpp
More file actions
49 lines (45 loc) · 1.03 KB
/
BooleanVar.cpp
File metadata and controls
49 lines (45 loc) · 1.03 KB
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
#include "BooleanVar.h"
BooleanVar::BooleanVar(bool value) : b(value)
{
}
BooleanVar::~BooleanVar(void)
{
}
Variable * BooleanVar::clone(void) const
{
return new BooleanVar(b);
}
std::shared_ptr<Variable> BooleanVar::operate(const std::string& op, std::shared_ptr<Variable> rhs, bool allocate)
{
std::shared_ptr<BooleanVar> vb = std::dynamic_pointer_cast<BooleanVar>(rhs);
if (vb!=0)
{
switch(op.front())
{
case'=':
if (op.back()=='=' && op.size()==2) {
return std::shared_ptr<Variable>(new BooleanVar(b==vb->b));
} else {
b=vb->b;
return *std::shared_ptr<std::shared_ptr<Variable>>(address);
}
case'!':
if (op.back()=='=') {
return std::shared_ptr<Variable>(new BooleanVar(b!=vb->b));
}
case'&':
return std::shared_ptr<Variable>(new BooleanVar(b&&vb->b));
case'|':
return std::shared_ptr<Variable>(new BooleanVar(b||vb->b));
}
}
else
{
if (op.compare("!")==0)
return std::shared_ptr<Variable>(new BooleanVar(!b));
}
if (allocate)
return Variable::operate(op, rhs);
else
return 0;
}