annotate Resources/CodeGeneration/template.in.ts @ 494:fc17251477d6 bgo-commands-codegen

TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
author bgo-osimis
date Sat, 23 Feb 2019 10:18:13 +0100
parents 6fbf2eae7c88
children 6405435480ae
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
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
4 */
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
5
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
6 function StoneCheckSerializedValueType(value: any, typeStr: string)
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
7 {
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
8 StoneCheckSerializedValueTypeGeneric(value);
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
9
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
10 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
11 {
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
12 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
13 `Cannot deserialize type ${value['type']} into ${typeStr}`);
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
14 }
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
15 }
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
16
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
17 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
18 {
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
19 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
20 }
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 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
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 // 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
25 // 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
26 // 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
27 // 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
28 // 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
29 if ( (!('type' in value)) || (!isString(value.type)) )
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
30 {
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
31 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
32 "Cannot deserialize value ('type' key invalid)");
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 }
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
35
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
36 // end of generic methods
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
37 {% 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
38 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
39 {% 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
40 {%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
41 };
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
42 {%endfor%}
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
43
493
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
44 {% for struct in structs%} export class {{struct['name']}} {
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
45 {% for key in struct['fields']%} {{key}}:{{CanonToTs(struct['fields'][key])}};
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
46 {% endfor %}
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
47 constructor() {
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
48 {% for key in struct['fields']%}{% if NeedsTsConstruction(enums,CanonToTs(struct['fields'][key])) %} this.{{key}} = new {{CanonToTs(struct['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
49 {% endif %}{% endfor %} }
493
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
50
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
51 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
52 let container: object = {};
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
53 container['type'] = '{{rWholootName}}.{{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
54 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
55 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
56 }
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
57
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
58 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
59 {
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
60 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
61 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
62 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
63 return result;
493
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
64 }
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
65 }
493
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
66
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
67 {% endfor %}
6fbf2eae7c88 All unit tests pass for generation, including handler and dispatcher
bgo-osimis
parents: 491
diff changeset
68
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
69 export interface IDispatcher {
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 {% 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
71 {% 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
72 };
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
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 /** 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
75 export function StoneDispatchJsonToHandler(
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 jsonValue: any, dispatcher: IDispatcher): 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
77 {
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 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
79 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
80 if (type == "")
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
81 {
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
82 // 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
83 throw new Error("Caught empty type while dispatching");
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
84 }
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
85 {% for struct in structs%} else if (type == "{{rootName}}.{{struct['name']}}")
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
86 {
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
87 let value = jsonValue["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
88 return dispatcher.Handle{{struct['name']}}(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
89 }
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 {% 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
91 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
92 {
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 return false;
491
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
94 }
8e7e151ef472 Unit tests pass for enum generation
bgo-osimis
parents: 490
diff changeset
95 }
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
96
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
97 /** Takes a serialized type and passes this to the dispatcher */
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 export function 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
99 strValue: string, dispatcher: IDispatcher): 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
100 {
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 // 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
102 // 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
103 // 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
104 // 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
105 // 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
106 let jsonValue: any = JSON.parse(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
107 return StoneDispatchJsonToHandler(jsonValue, dispatcher);
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 }