-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathattribute.cpp
More file actions
172 lines (142 loc) · 3.38 KB
/
attribute.cpp
File metadata and controls
172 lines (142 loc) · 3.38 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <ggraph/attribute.hpp>
#include <ggraph/util/strfmt.hpp>
#include <cmath>
#include <unordered_map>
namespace ggraph {
/* attribute */
attribute::~attribute()
{}
bool
attribute::operator==(const attribute & other) const noexcept
{
return name() == other.name();
}
std::string
attribute::debug_string() const
{
return name();
}
/* string attribute */
strattribute::~strattribute()
{}
bool
strattribute::operator==(const attribute & other) const noexcept
{
auto attr = dynamic_cast<const strattribute*>(&other);
return attr && value() == attr->value() && attribute::operator==(other);
}
std::string
strattribute::debug_string() const
{
return name() + ":" + value();
}
std::unique_ptr<attribute>
strattribute::copy() const
{
return std::unique_ptr<attribute>(new strattribute(*this));
}
std::string
strattribute::value_str() const noexcept
{
return value_;
}
/* double attribute */
dblattribute::~dblattribute()
{}
bool
dblattribute::operator==(const attribute & other) const noexcept
{
auto attr = dynamic_cast<const dblattribute*>(&other);
return attr && value() == attr->value() && attribute::operator==(other);
}
std::string
dblattribute::debug_string() const
{
return strfmt(name(), ":", value());
}
std::unique_ptr<attribute>
dblattribute::copy() const
{
return std::unique_ptr<attribute>(new dblattribute(*this));
}
std::string
dblattribute::value_str() const noexcept
{
return std::isnan(value()) ? "0.0" : strfmt(value());
}
/* nodegraphics attribute */
ngsattribute::~ngsattribute()
{}
bool
ngsattribute::operator==(const attribute & other) const noexcept
{
/* FIXME: compare open and closed attribute */
auto a = dynamic_cast<const ngsattribute*>(&other);
return a && attribute::operator==(other);
}
std::string
ngsattribute::debug_string() const
{
/* FIXME: */
return name();
}
std::unique_ptr<attribute>
ngsattribute::copy() const
{
return std::unique_ptr<attribute>(new ngsattribute(*this));
}
static inline std::string
to_str(bool b)
{
return b ? "true" : "false";
}
static inline std::string
color(uint32_t c)
{
static std::unordered_map<size_t, std::string> map({
{0, "0"}, {1, "1"}, {2, "2"}, {3, "3"}
, {4, "4"}, {5, "5"}, {6, "6"}, {7, "7"}
, {8, "8"}, {9, "9"}, {10, "A"}, {11, "B"}
, {12, "C"}, {13, "D"}, {14, "E"}, {15, "F"}
});
std::string s("#");
uint32_t mask = 0x00F00000;
for (size_t n = 0; n < 6; n++) {
uint32_t v = (c & mask) >> ((5-n)*4);
GGRAPH_DEBUG_ASSERT(map.find(v) != map.end());
s += map[v];
mask = mask >> 4;
}
return s;
}
static inline std::string
to_str(const ggraph::graphics & g, bool closed)
{
return "<y:GroupNode>"
+ strfmt("<y:Geometry ",
"height=\"", g.geometry.height,
"\" width=\"", g.geometry.width,
"\"/>")
+ strfmt("<y:Fill ",
"hasColor=\"", to_str(g.fill.has_color),
"\" transparent=\"", to_str(g.fill.transparent),
"\"/>")
+ strfmt("<y:NodeLabel visible=\"", to_str(g.node_label.visible), "\"/>")
+ strfmt("<y:BorderStyle ",
"color=\"", color(g.borderstyle.color),
"\" type=\"", g.borderstyle.type,
"\" width=\"", g.borderstyle.width,
"\"/>")
+ strfmt("<y:Shape type=\"", g.shape.type, "\"/>")
+ strfmt("<y:State closed=\"", to_str(closed), "\"/>")
+ "</y:GroupNode>";
}
std::string
ngsattribute::value_str() const noexcept
{
return "<y:ProxyAutoBoundsNode><y:Realizers active=\"1\">"
+ to_str(open(), false)
+ to_str(closed(), true)
+ "</y:Realizers></y:ProxyAutoBoundsNode>";
}
}