-
Notifications
You must be signed in to change notification settings - Fork 0
/
InteractiveInterface.cpp
63 lines (51 loc) · 1.31 KB
/
InteractiveInterface.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
#include "InteractiveInterface.h"
std::string InstructionsBoxModel::restoreItem()
{
std::string res;
if (rotationsQueue.size())
{
addItemFront(InstructionsSanitizer::toStringNotation(rotationsQueue.back()));
res.push_back(rotationsQueue.back());
rotationsQueue.pop_back();
}
return res;
}
std::string InstructionsBoxModel::popItem()
{
auto res = Base::popItem();
if (res.size())
rotationsQueue.push_back(InstructionsSanitizer::toCharNotation(res));
return res;
}
void InstructionsBoxModel::clearItems()
{
Base::clearItems();
rotationsQueue.clear();
}
bool InstructionsBoxModel::isEmpty()
{
return Base::isEmpty() && !rotationsQueue.size();
}
char InstructionsSanitizer::toCharNotation(const std::string & in)
{
if (in.size() == 1)
return in[0];
else if (in.size() == 2)
return std::tolower(in[0]);
else
throw std::runtime_error("Incorrect input");
}
std::string InstructionsSanitizer::toStringNotation(char r)
{
if (r <= 'Z')
return std::string(1, r);
else
return std::string(1, std::toupper(r)) + '\'';
}
char InstructionsSanitizer::reverseChar(char r)
{
if (r <= 'Z')
return r + 32;
else
return r - 32;
}