forked from PLLUG-Community-C-Qt-Roadmap/CPPQT-MenuForCafe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintmenuvisitor.cpp
More file actions
55 lines (42 loc) · 924 Bytes
/
Copy pathprintmenuvisitor.cpp
File metadata and controls
55 lines (42 loc) · 924 Bytes
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
#include "printmenuvisitor.h"
#include <iostream>
#include "menuitem.h"
#include "menusection.h"
PrintMenuVisitor::PrintMenuVisitor()
: mLevel{}
{
}
void PrintMenuVisitor::visit(MenuItem *item)
{
levelUp();
std::cout << indent() << item->name() << " - $$$ " << item->price() << std::endl;
levelDown();
}
std::string PrintMenuVisitor::indent() const
{
std::string rIndent;
for (int i = 0; i < mLevel; ++i)
{
rIndent.append(" ");
}
return rIndent;
}
void PrintMenuVisitor::visit(MenuSection *section)
{
levelUp();
std::cout << indent() << "[" << section->name() << "]" << std::endl;
for (int index = 0; index < section->size(); ++index)
{
auto nextElement = section->at(index);
nextElement->apply(this);
}
levelDown();
}
void PrintMenuVisitor::levelUp()
{
mLevel++;
}
void PrintMenuVisitor::levelDown()
{
mLevel--;
}