-
Notifications
You must be signed in to change notification settings - Fork 0
/
Class.cpp
79 lines (70 loc) · 1.98 KB
/
Class.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Created by hegedus on 2017.12.14..
//
#include "Class.h"
Class::Class() {
name = "";
fields = std::list<Field>{};
methods = std::list<Function>{};
}
Class::Class(std::string name, std::list<Field> attribs, std::list<Function> methods, std::string type) :
name{name}, fields{attribs}, methods{methods}, type{type} {
isAbstrack = true;
if(methods.empty()) {
isAbstrack = false;
} else {
for(auto f : methods) {
if(!f.isVirtual) {
isAbstrack = false;
break;
}
}
}
}
Class::Class(std::string name, std::list<Field> attribs, std::list<Function> methods) :
name{name}, fields{attribs}, methods{methods} {
isAbstrack = true;
if(methods.empty()) {
isAbstrack = false;
} else {
for(auto f : methods) {
if(!f.isVirtual) {
isAbstrack = false;
break;
}
}
}
}
void Class::write(std::string &str) {
std::string opener = "\t" + name + " [\n";
std::string label_open = "\t\tlabel = <{";
std::string type_final;
if(!type.empty()) {
type_final = "<<" + type + ">><BR ALIGN=\"LEFT\"/>";
}
std::string label;
if(isAbstrack) {
label = type_final + "<I>" + name + "</I>" + "|";
} else {
label = type_final + name + "|";
}
for(auto iterator = fields.begin(); iterator != fields.end(); ++iterator) {
label += iterator.operator*().write();
}
label += "|";
for(auto iterator = methods.begin(); iterator != methods.end(); ++iterator) {
label += iterator.operator*().write();
}
std::string label_close = "}>\n\t";
std::string closer = "]\n\n";
str += (opener + label_open + label + label_close + closer);
}
std::string Class::getName() {
return name;
}
void Class::addField(Field field) {
fields.push_back(field);
}
void Class::addFunction(Function function) {
methods.push_back(function);
}