-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequence.cpp
70 lines (55 loc) · 1.15 KB
/
sequence.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
#include "sequence.h"
Sequence::Sequence()
{
}
void Sequence::add(TrafficLight::Light light, std::chrono::milliseconds delay)
{
_sequences.push_back({light, delay});
}
void Sequence::clear()
{
_sequences.clear();
}
void Sequence::restart()
{
_index = 0;
}
bool Sequence::next()
{
++_index;
if (_index >= count()) {
restart();
return false;
}
return true;
}
size_t Sequence::count() const
{
return _sequences.size();
}
TrafficLight::Light Sequence::getLightForIndex(size_t index) const
{
if (index < count()) {
return std::get<0>(_sequences[index]);
}
return TrafficLight::None;
}
TrafficLight::Light Sequence::getCurrentLight() const
{
return getLightForIndex(_index);
}
std::chrono::milliseconds Sequence::getDelayForIndex(size_t index) const
{
if (index < count()) {
return std::get<1>(_sequences[index]);
}
return std::chrono::milliseconds(0);
}
std::chrono::milliseconds Sequence::getCurrentDelay() const
{
return getDelayForIndex(_index);
}
std::tuple<TrafficLight::Light, std::chrono::milliseconds> Sequence::getCurrent() const
{
return _sequences[_index];
}