changeset 682:e8b83fe55a33 am-dev

added support for float + map<TK, TV> instead of only map<string, T>
author Alain Mazy <alain@mazy.be>
date Thu, 16 May 2019 15:04:41 +0200
parents 077f28e3ea3d
children 0d42bda615a8
files Resources/CodeGeneration/template.in.h.j2
diffstat 1 files changed, 25 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/CodeGeneration/template.in.h.j2	Thu May 16 10:46:35 2019 +0200
+++ b/Resources/CodeGeneration/template.in.h.j2	Thu May 16 15:04:41 2019 +0200
@@ -109,6 +109,21 @@
   }
 
   /** Throws in case of problem */
+  inline void _StoneDeserializeValue(float& destValue, const Json::Value& jsonValue)
+  {
+    if (!jsonValue.isNull())
+    {
+      destValue = jsonValue.asFloat();
+    }
+  }
+
+  inline Json::Value _StoneSerializeValue(float value)
+  {
+    Json::Value result(value);
+    return result;
+  }
+
+  /** Throws in case of problem */
   inline void _StoneDeserializeValue(bool& destValue, const Json::Value& jsonValue)
   {
     if (!jsonValue.isNull())
@@ -168,9 +183,9 @@
   }
 
   /** Throws in case of problem */
-  template<typename T>
+  template<typename TK, typename TV>
   void _StoneDeserializeValue(
-    std::map<std::string, T>& destValue, const Json::Value& jsonValue)
+    std::map<TK, TV>& destValue, const Json::Value& jsonValue)
   {
     if (!jsonValue.isNull())
     {
@@ -180,23 +195,22 @@
         itr != jsonValue.end();
         itr++)
       {
-        std::string key;
+        TK key;
         _StoneDeserializeValue(key, itr.key());
 
-        T innerDestValue;
+        TV innerDestValue;
         _StoneDeserializeValue(innerDestValue, *itr);
 
         destValue[key] = innerDestValue;
       }
     }
   }
-
-  template<typename T>
-  Json::Value _StoneSerializeValue(const std::map<std::string,T>& value)
+  template<typename TK, typename TV>
+  Json::Value _StoneSerializeValue(const std::map<TK, TV>& value)
   {
     Json::Value result(Json::objectValue);
 
-    for (typename std::map<std::string, T>::const_iterator it = value.cbegin();
+    for (typename std::map<TK, TV>::const_iterator it = value.cbegin();
       it != value.cend(); ++it)
     {
       // it->first it->second
@@ -205,11 +219,11 @@
     return result;
   }
 
-  template<typename T>
-  std::ostream& StoneDumpValue(std::ostream& out, const std::map<std::string,T>& value, size_t indent)
+  template<typename TK, typename TV>
+  std::ostream& StoneDumpValue(std::ostream& out, const std::map<TK, TV>& value, size_t indent)
   {
     out << MakeIndent(indent) << "{\n";
-    for (typename std::map<std::string, T>::const_iterator it = value.cbegin();
+    for (typename std::map<TK, TV>::const_iterator it = value.cbegin();
       it != value.cend(); ++it)
     {
       out << MakeIndent(indent+2) << "\"" << it->first << "\" : ";