Mercurial > hg > orthanc-stone
comparison Resources/CodeGeneration/template.in.ts @ 513:dea3787a8f4b bgo-commands-codegen
Added support for struct metadata, to disable/enable handler support in Typescript or C++
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 11 Mar 2019 13:02:46 +0100 |
parents | 7105a0bad250 |
children |
comparison
equal
deleted
inserted
replaced
510:97a16b694321 | 513:dea3787a8f4b |
---|---|
64 StoneCheckSerializedValueType(value, '{{rootName}}.{{struct['name']}}'); | 64 StoneCheckSerializedValueType(value, '{{rootName}}.{{struct['name']}}'); |
65 let result: {{struct['name']}} = value['value'] as {{struct['name']}}; | 65 let result: {{struct['name']}} = value['value'] as {{struct['name']}}; |
66 return result; | 66 return result; |
67 } | 67 } |
68 } | 68 } |
69 | |
70 {% endfor %} | 69 {% endfor %} |
71 | |
72 export interface IHandler { | 70 export interface IHandler { |
73 {% for struct in structs%} Handle{{struct['name']}}(value: {{struct['name']}}): boolean; | 71 {% for struct in structs%}{% if struct['__meta__'].handleInTypescript %} Handle{{struct['name']}}(value: {{struct['name']}}): boolean; |
74 {% endfor %} | 72 {% endif %}{% endfor %}}; |
75 }; | |
76 | 73 |
77 /** Service function for StoneDispatchToHandler */ | 74 /** Service function for StoneDispatchToHandler */ |
78 export function StoneDispatchJsonToHandler( | 75 export function StoneDispatchJsonToHandler( |
79 jsonValue: any, handler: IHandler): boolean | 76 jsonValue: any, handler: IHandler): boolean |
80 { | 77 { |
83 if (type == "") | 80 if (type == "") |
84 { | 81 { |
85 // this should never ever happen | 82 // this should never ever happen |
86 throw new Error("Caught empty type while dispatching"); | 83 throw new Error("Caught empty type while dispatching"); |
87 } | 84 } |
88 {% for struct in structs%} else if (type == "{{rootName}}.{{struct['name']}}") | 85 {% for struct in structs%}{% if struct['__meta__'].handleInTypescript %} else if (type == "{{rootName}}.{{struct['name']}}") |
89 { | 86 { |
90 let value = jsonValue["value"] as {{struct['name']}}; | 87 let value = jsonValue["value"] as {{struct['name']}}; |
91 return handler.Handle{{struct['name']}}(value); | 88 return handler.Handle{{struct['name']}}(value); |
92 } | 89 } |
93 {% endfor %} | 90 {% endif %}{% endfor %} else |
94 else | |
95 { | 91 { |
96 return false; | 92 return false; |
97 } | 93 } |
98 } | 94 } |
99 | 95 |