-
Notifications
You must be signed in to change notification settings - Fork 1
/
Table.cpp
57 lines (48 loc) · 909 Bytes
/
Table.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
#include "Table.hpp"
Table::Table(int n, float speed) : amount(n), speedRatio(speed)
{
prepareForks();
preparePhilosophers();
}
void Table::prepareForks()
{
for (size_t i = 0; i < amount; i++)
{
forksV.push_back(new Fork(i, i));
}
}
void Table::preparePhilosophers()
{
for (size_t i = 0; i < amount; i++)
{
std::string name = "Philosopher ";
name += std::to_string(i);
philosophersV.push_back(new Philosopher(i, name, setup, forksV.at(i), forksV.at((i + 1) % amount), speedRatio));
}
}
void Table::dinnerStart()
{
isDinner = true;
setup.talk.letEveryoneKnow();
}
void Table::dinnerStop()
{
setup.setStatus(true);
isDinner = false;
}
std::vector<Fork *> &Table::getForks()
{
return forksV;
}
std::vector<Philosopher *> &Table::getPhilosophers()
{
return philosophersV;
}
const TableSetup &Table::getSetup()
{
return setup;
}
bool Table::getIsDinner() const
{
return isDinner;
}