-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEnumerations.cpp
100 lines (87 loc) · 2.62 KB
/
Enumerations.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "Enumerations.h"
using namespace q2d;
using namespace q2d::enums;
// initialize the mappings from enums to strings
QMap<DocumentEntryType, QString>
q2d::enums::map_DocumentEntryType {
{DocumentEntryType::COMPONENT, "component" },
{DocumentEntryType::PORT, "port"},
{DocumentEntryType::MODULE_INTERFACE, "module_interface" },
{DocumentEntryType::WIRE, "wire" },
{DocumentEntryType::UNDEFINED, "undefined" }
};
QString
q2d::enums::DocumentEntryTypeToString(const DocumentEntryType type) {
if (map_DocumentEntryType.contains(type)) {
return map_DocumentEntryType[type];
} else {
return map_DocumentEntryType[DocumentEntryType::UNDEFINED];
}
}
DocumentEntryType
q2d::enums::StringToDocumentEntryType(const QString string) {
QString lookup = string.trimmed().toLower();
return map_DocumentEntryType.key(lookup, DocumentEntryType::UNDEFINED);
}
int
metamodel::enums::elementTypeToInt(ElementType t) {
return (int)t;
}
metamodel::enums::ElementType
metamodel::enums::intToElementType(int i) {
switch (i) {
case (int)ElementType::CATEGORY :
return ElementType::CATEGORY;
case (int)ElementType::COMPONENT :
return ElementType::COMPONENT;
case (int)ElementType::CONFIG_BIT_GROUP :
return ElementType::CONFIG_BIT_GROUP;
case (int) ElementType::CONFIG_BIT :
return ElementType::CONFIG_BIT;
case (int)ElementType::PORT :
return ElementType::PORT;
case (int) ElementType::FUNCTION:
return ElementType::FUNCTION;
default :
return ElementType::INVALID;
}
}
model::enums::PortDirection
model::enums::StringToPortDirection(const QString string) {
QString copy(string);
copy = copy.trimmed().toLower();
if (copy == "in") {
return PortDirection::IN;
}
if (copy == "inout") {
return PortDirection::IN_OUT;
}
if (copy == "out") {
return PortDirection::OUT;
}
return PortDirection::UNSPECIFIED;
}
QString
model::enums::PortDirectionToString(const PortDirection direction) {
switch (direction) {
case PortDirection::IN :
return "in";
case PortDirection::OUT :
return "out";
case PortDirection::IN_OUT :
return "inout";
default:
return "unspecified";
}
}
model::enums::PortDirection
model::enums::invert(const PortDirection initial) {
switch (initial) {
case PortDirection::IN :
return PortDirection::OUT;
case PortDirection::OUT:
return PortDirection::IN;
default:
return PortDirection::UNSPECIFIED;
}
}