diff options
Diffstat (limited to 'templates/data.cpp.ede')
-rw-r--r-- | templates/data.cpp.ede | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/templates/data.cpp.ede b/templates/data.cpp.ede new file mode 100644 index 0000000..8e106a6 --- /dev/null +++ b/templates/data.cpp.ede | |||
@@ -0,0 +1,63 @@ | |||
1 | // generated file, do not modify! | ||
2 | // {{ dateTime }} | ||
3 | |||
4 | #include "{{ moduleName }}.hpp" | ||
5 | |||
6 | template<> json toJSON<String>(String &v) { | ||
7 | return json(v); | ||
8 | } | ||
9 | |||
10 | template<> json toJSON<Float>(Float &v) { | ||
11 | return json(v); | ||
12 | } | ||
13 | |||
14 | template<> json toJSON<bool>(bool &v) { | ||
15 | return json(v); | ||
16 | } | ||
17 | |||
18 | template<> json toJSON<int>(int &v) { | ||
19 | return json(v); | ||
20 | } | ||
21 | |||
22 | template<> json toJSON<unsigned int>(unsigned int &v) { | ||
23 | return json(v); | ||
24 | } | ||
25 | |||
26 | template<typename any> | ||
27 | json toJSON(std::vector<any> &v) { | ||
28 | json obj = json::array(); | ||
29 | for (any i : v) { | ||
30 | obj.push_back(toJSON(i)); | ||
31 | } | ||
32 | return obj; | ||
33 | } | ||
34 | |||
35 | template<typename k, typename v> | ||
36 | json toJSON(std::map<k,v> &value) { | ||
37 | return json(); | ||
38 | } | ||
39 | |||
40 | {% for t in definitions %} | ||
41 | template<> json toJSON<{{ t.value.dataName }}>({{ t.value.dataName }} &v) { | ||
42 | json obj; | ||
43 | switch (v.tag) { {% for c in t.value.constructors %} | ||
44 | case ::{{ t.value.dataName }}::tag::{{ c.value.name }}: | ||
45 | obj["tag"] = "{{ c.value.name }}";{% if !(c.value.fields | empty) %} | ||
46 | { | ||
47 | auto tv = static_cast<::data::{{ c.value.name }}&>(v);{% for f in c.value.fields %}{% if c.value.fields | hasFieldNames %} | ||
48 | obj["{{ f.value.fieldName }}"] = toJSON(tv.{{ f.value.fieldName }});{% else %} | ||
49 | obj["arg{{ f.index0 }}"] = toJSON(tv._{{ f.index0 }});{% endif %}{% endfor %} | ||
50 | }{% endif %} | ||
51 | break;{% endfor %} | ||
52 | } | ||
53 | return obj; | ||
54 | } | ||
55 | {% endfor %} | ||
56 | |||
57 | {# | ||
58 | {% for c in t.value.constructors %} | ||
59 | json data::{{ c.value.name }}::toJSON() { | ||
60 | return obj; | ||
61 | } | ||
62 | {% endif %}{% endfor %}{% endfor %} | ||
63 | #} \ No newline at end of file | ||