-
Notifications
You must be signed in to change notification settings - Fork 0
/
CeilingFanMediumCommand.hpp
51 lines (46 loc) · 1013 Bytes
/
CeilingFanMediumCommand.hpp
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
#ifndef CEILING_FAN_MEDIUM_COMMAND_H
#define CEILING_FAN_MEDIUM_COMMAND_H
#include "Command.hpp"
#include "CeilingFan.hpp"
#include <string>
class CeilingFanMediumCommand : public Command
{
public:
CeilingFanMediumCommand(CeilingFan *cf) : ceilingFan(cf) { }
void execute() override;
void undo() override;
std::string getClassName() const override { return className; }
private:
CeilingFan *ceilingFan;
CeilingFan::Speed prevSpeed;
std::string className = "CeilingFanMediumCommand";
};
inline
void
CeilingFanMediumCommand::execute()
{
prevSpeed = ceilingFan->getSpeed();
ceilingFan->medium();
}
inline
void
CeilingFanMediumCommand::undo()
{
switch (prevSpeed) {
case CeilingFan::Speed::HIGH:
ceilingFan->high();
break;
case CeilingFan::Speed::MEDIUM:
ceilingFan->medium();
break;
case CeilingFan::Speed::LOW:
ceilingFan->low();
break;
case CeilingFan::Speed::OFF:
ceilingFan->off();
break;
default:
break;
}
}
#endif /* CEILING_FAN_MEDIUM_COMMAN_H */