-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFloor.cpp
82 lines (68 loc) · 1.45 KB
/
Floor.cpp
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
#include <sstream>
#include "Floor.hpp"
using namespace std;
Floor::Floor(int i) {
this->id = i;
// down & up button are false
buttons.push_back(false);
buttons.push_back(false);
}
vector<Person> Floor::filter(Dir dir) {
vector<Person> ppl;
for (auto p2: persons) {
if (p2.dir() == dir) {
ppl.push_back(p2);
}
}
return ppl;
}
void Floor::AddPerson(Person p) {
persons.push_back(p);
if (p.src > p.dest) {
PressDown();
} else {
PressUp();
}
printf("new person %d arriving on floor %d, dest=%d\n", p.id, this->id, p.dest);
}
// eg. "FLOOR 1, persons 0, up 0, down 0"
string Floor::toString() {
stringstream ss;
ss << "FLOOR " << id << ", ";
// need to access parent
int count = Container::persons.size();
// add person count
ss << "persons " << count << ", ";
// up or down count?
ss << "up " << (this->UpPressed()) << ", ";
ss << "down " << (this->DownPressed());
return ss.str();
}
// from run()
void Floor::summary() {
for (auto p: persons) {
printf("on floor %d: ", id);
p.print();
}
}
// is it pressed? and press
bool Floor::UpPressed() {
return Pressed(0);
}
void Floor::PressUp() {
Press(0);
}
// is it pressed? and press
bool Floor::DownPressed() {
return Pressed(1);
}
void Floor::PressDown() {
Press(1);
}
// remove press
void Floor::ClearUp() {
Reset(0);
}
void Floor::ClearDown() {
Reset(1);
}