blob: 0f17d8524c4a47b2c4231b335398127d64da3f85 (
plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* Renderer.cpp
*
* Created on: Nov 23, 2017
* Author: naopross
*/
#include "AsciiRenderer.h"
#include <memory>
namespace samb {
AsciiRenderer::AsciiRenderer(Structogram& structogram, unsigned int width):
m_structogram(structogram), m_width(width) {}
AsciiRenderer::~AsciiRenderer() {}
void AsciiRenderer::drawPadding(unsigned int amt) {
while (amt--) {
std::cout << " ";
}
}
void AsciiRenderer::drawLine() const {
for (unsigned int i = 0; i < m_width; i++) {
std::cout << "-";
}
std::cout << std::endl;
}
void AsciiRenderer::drawText(std::string text, unsigned int width, std::string before, std::string after) const {
if (width == 0) {
width = m_width;
}
unsigned int textWidth = width - before.length() - after.length();
std::cout << before;
for (unsigned int i = 0; i < text.length(); i++) {
if (i % textWidth == 0) {
std::cout << after << "\n" << before;
}
std::cout << text[i];
}
std::cout << std::endl;
}
void AsciiRenderer::drawDecision(std::string condition, std::string trueText, std::string falseText, unsigned int width) const {
if (width == 0) {
width = m_width -2;
}
std::cout << "|";
// drawPadding(width - condition.length());
}
void AsciiRenderer::render() {
const std::list<Statement>& statements = m_structogram.getStatements();
for (std::list<Statement>::const_iterator it = statements.begin(); it != statements.end(); it++) {
Statement st = *it;
switch (st.type) {
case Statement::Type::PROCESS:
drawLine();
drawText(st.text);
break;
case Statement::Type::DECISION:
drawLine();
break;
case Statement::Type::SWITCH:
break;
case Statement::Type::SCOPE:
break;
case Statement::Type::WHILE:
break;
case Statement::Type::UNTIL:
break;
case Statement::Type::PARALLEL:
break;
}
}
}
} /* namespace samb */
|