blob: 8e106a62530a01099fd388cf2b68a36f526bcddb (
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
|
// generated file, do not modify!
// {{ dateTime }}
#include "{{ moduleName }}.hpp"
template<> json toJSON<String>(String &v) {
return json(v);
}
template<> json toJSON<Float>(Float &v) {
return json(v);
}
template<> json toJSON<bool>(bool &v) {
return json(v);
}
template<> json toJSON<int>(int &v) {
return json(v);
}
template<> json toJSON<unsigned int>(unsigned int &v) {
return json(v);
}
template<typename any>
json toJSON(std::vector<any> &v) {
json obj = json::array();
for (any i : v) {
obj.push_back(toJSON(i));
}
return obj;
}
template<typename k, typename v>
json toJSON(std::map<k,v> &value) {
return json();
}
{% for t in definitions %}
template<> json toJSON<{{ t.value.dataName }}>({{ t.value.dataName }} &v) {
json obj;
switch (v.tag) { {% for c in t.value.constructors %}
case ::{{ t.value.dataName }}::tag::{{ c.value.name }}:
obj["tag"] = "{{ c.value.name }}";{% if !(c.value.fields | empty) %}
{
auto tv = static_cast<::data::{{ c.value.name }}&>(v);{% for f in c.value.fields %}{% if c.value.fields | hasFieldNames %}
obj["{{ f.value.fieldName }}"] = toJSON(tv.{{ f.value.fieldName }});{% else %}
obj["arg{{ f.index0 }}"] = toJSON(tv._{{ f.index0 }});{% endif %}{% endfor %}
}{% endif %}
break;{% endfor %}
}
return obj;
}
{% endfor %}
{#
{% for c in t.value.constructors %}
json data::{{ c.value.name }}::toJSON() {
return obj;
}
{% endif %}{% endfor %}{% endfor %}
#}
|