-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStructureChart.hpp
128 lines (112 loc) · 2.79 KB
/
StructureChart.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef STRUCTURECHART_HPP
#define STRUCTURECHART_HPP
#include "ChartsBase.hpp"
#include <string>
#include <map>
#include <memory>
#include <vector>
class Declaration
{
private:
std::string varName;
std::string type;
public:
Declaration(std::string pVarName, std::string pType): varName(pVarName), type(pType)
{
}
std::string getType(){return type;}
std::string getVarName(){return varName;}
};
class Block
{
public:
virtual ~Block()
{
}
};
class BlockSequence
{
private:
std::vector<std::unique_ptr<Block>> blocks;
public:
BlockSequence() = default;
BlockSequence(BlockSequence&&) = default;
std::vector<std::unique_ptr<Block>>& getBlocks(){return blocks;}
//void pushbackBlock(std::unique_ptr<Block>& block){blocks.push_back(block);}
//void emplaceBackBlock(std::unique_ptr<Block>& block){blocks.emplace_back(block);}
};
class SimpleBlock : public Block
{
private:
std::string command;
public:
SimpleBlock(std::string command)
: command(command)
{
}
std::string getCommand(){return command;}
};
class IfElseBlock : public Block
{
private:
std::string condition;
BlockSequence yes;
BlockSequence no;
public:
IfElseBlock(std::string condition, BlockSequence& yes, BlockSequence& no)
: condition(condition)
, yes(std::move(yes))
, no(std::move(no))
{
}
std::string getCondition(){return condition;}
BlockSequence& getYes(){return yes;}
BlockSequence& getNo(){return no;}
};
class SwitchBlock : public Block
{
private:
std::string expression;
std::map<std::string, BlockSequence> sequences; // Empty string: else
public:
SwitchBlock(std::string expression, std::map<std::string, BlockSequence>& sequences)
:expression(expression), sequences(std::move(sequences))
{
}
std::string getExpression(){return expression;}
std::map<std::string, BlockSequence>& getSequences(){return sequences;}
};
class LoopBlock : public Block
{
private:
std::string condition;
BlockSequence body;
bool headControlled;
public:
LoopBlock(std::string condition, BlockSequence& body, bool headControlled)
: condition(condition)
, body(std::move(body))
, headControlled(headControlled)
{
}
std::string getCondition(){return condition;}
BlockSequence& getBody(){return body;}
bool getHeadcontrolled(){return headControlled;}
};
class StructureChart
{
private:
std::string headline;
std::vector<Declaration> declarations;
BlockSequence root;
public:
StructureChart() = default;
StructureChart(std::string headline, std::vector<Declaration>&& declarations, BlockSequence root)
: headline(headline), declarations(std::move(declarations)), root(std::move(root))
{
}
std::string getHeadline(){return headline;}
std::vector<Declaration>& getDeclarations(){return declarations;}
BlockSequence& getRoot(){return root;}
};
#endif