Mercurial > hg > orthanc-stone
comparison Resources/CodeGeneration/template.in.h.j2 @ 519:17106b29ed6d bgo-commands-codegen
Changed the metadata system for structs. A __handler entry is now required
(with "cpp", "ts" or both: ["cpp","ts"]).
Changed the enumerations to string-based values.
Adapted the integrated wasm test.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 12 Mar 2019 13:11:18 +0100 |
parents | 1dbf2d9ed1e4 |
children | 9e241cef32a4 |
comparison
equal
deleted
inserted
replaced
518:40bb5eb247a5 | 519:17106b29ed6d |
---|---|
230 {% for enum in enums%} | 230 {% for enum in enums%} |
231 enum {{enum['name']}} { | 231 enum {{enum['name']}} { |
232 {% for key in enum['fields']%} {{enum['name']}}_{{key}}, | 232 {% for key in enum['fields']%} {{enum['name']}}_{{key}}, |
233 {%endfor%} }; | 233 {%endfor%} }; |
234 | 234 |
235 inline void _StoneDeserializeValue( | |
236 {{enum['name']}}& destValue, const Json::Value& jsonValue) | |
237 { | |
238 destValue = static_cast<{{enum['name']}}>(jsonValue.asInt64()); | |
239 } | |
240 | |
241 inline Json::Value _StoneSerializeValue(const {{enum['name']}}& value) | |
242 { | |
243 return Json::Value(static_cast<int64_t>(value)); | |
244 } | |
245 | |
246 inline std::string ToString(const {{enum['name']}}& value) | 235 inline std::string ToString(const {{enum['name']}}& value) |
247 { | 236 { |
248 {% for key in enum['fields']%} if( value == {{enum['name']}}_{{key}}) | 237 {% for key in enum['fields']%} if( value == {{enum['name']}}_{{key}}) |
249 { | 238 { |
250 return std::string("{{key}}"); | 239 return std::string("{{key}}"); |
260 inline void FromString({{enum['name']}}& value, std::string strValue) | 249 inline void FromString({{enum['name']}}& value, std::string strValue) |
261 { | 250 { |
262 {% for key in enum['fields']%} if( strValue == std::string("{{key}}") ) | 251 {% for key in enum['fields']%} if( strValue == std::string("{{key}}") ) |
263 { | 252 { |
264 value = {{enum['name']}}_{{key}}; | 253 value = {{enum['name']}}_{{key}}; |
254 return; | |
265 } | 255 } |
266 {%endfor%} | 256 {%endfor%} |
267 std::stringstream ss; | 257 std::stringstream ss; |
268 ss << "String \"" << strValue << "\" cannot be converted to {{enum['name']}}. Possible values are: {% for key in enum['fields']%}{{key}}{% endfor %}"; | 258 ss << "String \"" << strValue << "\" cannot be converted to {{enum['name']}}. Possible values are: {% for key in enum['fields']%}{{key}} {% endfor %}"; |
269 std::string msg = ss.str(); | 259 std::string msg = ss.str(); |
270 throw std::runtime_error(msg); | 260 throw std::runtime_error(msg); |
261 } | |
262 | |
263 | |
264 inline void _StoneDeserializeValue( | |
265 {{enum['name']}}& destValue, const Json::Value& jsonValue) | |
266 { | |
267 FromString(destValue, jsonValue.asString()); | |
268 } | |
269 | |
270 inline Json::Value _StoneSerializeValue(const {{enum['name']}}& value) | |
271 { | |
272 std::string strValue = ToString(value); | |
273 return Json::Value(strValue); | |
271 } | 274 } |
272 | 275 |
273 inline std::ostream& StoneDumpValue(std::ostream& out, const {{enum['name']}}& value, int indent = 0) | 276 inline std::ostream& StoneDumpValue(std::ostream& out, const {{enum['name']}}& value, int indent = 0) |
274 { | 277 { |
275 {% for key in enum['fields']%} if( value == {{enum['name']}}_{{key}}) | 278 {% for key in enum['fields']%} if( value == {{enum['name']}}_{{key}}) |