-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCondition.hpp
More file actions
85 lines (70 loc) · 1.73 KB
/
Condition.hpp
File metadata and controls
85 lines (70 loc) · 1.73 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
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
85
// Condition Class for Task Planner
// Author : Prateek Parmeshwar
#pragma once
using namespace std;
class Condition
{
private:
string predicate;
list<string> args;
bool truth;
public:
Condition(string pred, list<string> args, bool truth)
{
this->predicate = pred;
this->truth = truth;
for (string ar : args)
{
this->args.push_back(ar);
}
}
string get_predicate() const
{
return this->predicate;
}
list<string> get_args() const
{
return this->args;
}
bool get_truth() const
{
return this->truth;
}
friend ostream& operator<<(ostream& os, const Condition& cond)
{
os << cond.toString() << " ";
return os;
}
bool operator==(const Condition& rhs) const // fixed
{
if (this->predicate != rhs.predicate || this->args.size() != rhs.args.size())
return false;
auto lhs_it = this->args.begin();
auto rhs_it = rhs.args.begin();
while (lhs_it != this->args.end() && rhs_it != rhs.args.end())
{
if (*lhs_it != *rhs_it)
return false;
++lhs_it;
++rhs_it;
}
if (this->truth != rhs.get_truth())
return false;
return true;
}
string toString() const
{
string temp = "";
if (!this->truth)
temp += "!";
temp += this->predicate;
temp += "(";
for (string l : this->args)
{
temp += l + ",";
}
temp = temp.substr(0, temp.length() - 1);
temp += ")";
return temp;
}
};