diff 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
line wrap: on
line diff
--- a/Resources/CodeGeneration/template.in.h.j2	Tue Mar 12 09:19:06 2019 +0100
+++ b/Resources/CodeGeneration/template.in.h.j2	Tue Mar 12 13:11:18 2019 +0100
@@ -232,17 +232,6 @@
 {% for key in enum['fields']%}    {{enum['name']}}_{{key}},
 {%endfor%}  };
 
-  inline void _StoneDeserializeValue(
-    {{enum['name']}}& destValue, const Json::Value& jsonValue)
-  {
-    destValue = static_cast<{{enum['name']}}>(jsonValue.asInt64());
-  }
-
-  inline Json::Value _StoneSerializeValue(const {{enum['name']}}& value)
-  {
-    return Json::Value(static_cast<int64_t>(value));
-  }
-
   inline std::string ToString(const {{enum['name']}}& value)
   {
 {% for key in enum['fields']%}    if( value == {{enum['name']}}_{{key}})
@@ -262,14 +251,28 @@
 {% for key in enum['fields']%}    if( strValue == std::string("{{key}}") )
     {
       value = {{enum['name']}}_{{key}};
+      return;
     }
 {%endfor%}
     std::stringstream ss;
-    ss << "String \"" << strValue << "\" cannot be converted to {{enum['name']}}. Possible values are: {% for key in enum['fields']%}{{key}}{% endfor %}";
+    ss << "String \"" << strValue << "\" cannot be converted to {{enum['name']}}. Possible values are: {% for key in enum['fields']%}{{key}} {% endfor %}";
     std::string msg = ss.str();
     throw std::runtime_error(msg);
   }
 
+
+  inline void _StoneDeserializeValue(
+    {{enum['name']}}& destValue, const Json::Value& jsonValue)
+  {
+    FromString(destValue, jsonValue.asString());
+  }
+
+  inline Json::Value _StoneSerializeValue(const {{enum['name']}}& value)
+  {
+    std::string strValue = ToString(value);
+    return Json::Value(strValue);
+  }
+
   inline std::ostream& StoneDumpValue(std::ostream& out, const {{enum['name']}}& value, int indent = 0)
   {
 {% for key in enum['fields']%}    if( value == {{enum['name']}}_{{key}})