annotate Resources/CodeGeneration/template.in.ts @ 507:ce49eae4c887 bgo-commands-codegen

Codegen + Warning fixes
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 01 Mar 2019 16:18:38 +0100
parents 6405435480ae
children 7105a0bad250
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
1 /*
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
2 1 2 3 4 5 6 7
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
3 12345678901234567890123456789012345678901234567890123456789012345678901234567890
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
4
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
5 Generated on {{currentDatetime}} by stonegentool
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
6
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
7 */
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
8
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
9 function StoneCheckSerializedValueType(value: any, typeStr: string)
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
10 {
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
11 StoneCheckSerializedValueTypeGeneric(value);
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
12
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
13 if (value['type'] != typeStr)
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
14 {
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
15 throw new Error(
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
16 `Cannot deserialize type ${value['type']} into ${typeStr}`);
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
17 }
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
18 }
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
19
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
20 function isString(val: any) :boolean
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
21 {
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
22 return ((typeof val === 'string') || (val instanceof String));
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
23 }
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
24
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
25 function StoneCheckSerializedValueTypeGeneric(value: any)
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
26 {
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
27 // console.//log("+-------------------------------------------------+");
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
28 // console.//log("| StoneCheckSerializedValueTypeGeneric |");
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
29 // console.//log("+-------------------------------------------------+");
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
30 // console.//log("value = ");
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
31 // console.//log(value);
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
32 if ( (!('type' in value)) || (!isString(value.type)) )
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
33 {
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
34 throw new Error(
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
35 "Cannot deserialize value ('type' key invalid)");
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
36 }
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
37 }
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
38
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
39 // end of generic methods
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
40 {% for enum in enums%}
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
41 export enum {{enum['name']}} {
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
42 {% for key in enum['fields']%}{{key}},
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
43 {%endfor%}
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
44 };
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
45 {%endfor%}
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
46
493
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
47 {% for struct in structs%} export class {{struct['name']}} {
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
48 {% if struct %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
49 {% if struct['fields'] %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
50 {% for key in struct['fields']%}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
51 {{key}}:{{CanonToTs(struct['fields'][key])}};
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
52 {% endfor %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
53 {% endif %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
54 {% endif %}
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
55 constructor() {
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
56 {% if struct %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
57 {% if struct['fields'] %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
58 {% for key in struct['fields']%}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
59 {% if NeedsTsConstruction(enums,CanonToTs(struct['fields'][key])) %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
60 this.{{key}} = new {{CanonToTs(struct['fields'][key])}}();
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
61 {% endif %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
62 {% endfor %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
63 {% endif %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
64 {% endif %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
65 }
493
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
66
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
67 public StoneSerialize(): string {
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
68 let container: object = {};
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
69 container['type'] = '{{rootName}}.{{struct['name']}}';
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
70 container['value'] = this;
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
71 return JSON.stringify(container);
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
72 }
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
73
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
74 public static StoneDeserialize(valueStr: string) : {{struct['name']}}
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
75 {
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
76 let value: any = JSON.parse(valueStr);
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
77 StoneCheckSerializedValueType(value, '{{rootName}}.{{struct['name']}}');
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
78 let result: {{struct['name']}} = value['value'] as {{struct['name']}};
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
79 return result;
493
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
80 }
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
81 }
493
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
82
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
83 {% endfor %}
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
84
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
85 export interface IHandler {
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
86 {% for struct in structs%} Handle{{struct['name']}}(value: {{struct['name']}}): boolean;
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
87 {% endfor %}
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
88 };
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
89
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
90 /** Service function for StoneDispatchToHandler */
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
91 export function StoneDispatchJsonToHandler(
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
92 jsonValue: any, handler: IHandler): boolean
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
93 {
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
94 StoneCheckSerializedValueTypeGeneric(jsonValue);
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
95 let type: string = jsonValue["type"];
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
96 if (type == "")
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
97 {
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
98 // this should never ever happen
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
99 throw new Error("Caught empty type while dispatching");
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
100 }
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
101 {% for struct in structs%} else if (type == "{{rootName}}.{{struct['name']}}")
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
102 {
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
103 let value = jsonValue["value"] as {{struct['name']}};
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
104 return handler.Handle{{struct['name']}}(value);
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
105 }
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
106 {% endfor %}
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
107 else
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
108 {
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
109 return false;
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
110 }
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
111 }
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
112
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
113 /** Takes a serialized type and passes this to the handler */
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
114 export function StoneDispatchToHandler(
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
115 strValue: string, handler: IHandler): boolean
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
116 {
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
117 // console.//log("+------------------------------------------------+");
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
118 // console.//log("| StoneDispatchToHandler |");
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
119 // console.//log("+------------------------------------------------+");
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
120 // console.//log("strValue = ");
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
121 // console.//log(strValue);
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
122 let jsonValue: any = JSON.parse(strValue)
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
123 return StoneDispatchJsonToHandler(jsonValue, handler);
494
fc17251477d6 TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents: 493
diff changeset
124 }