diff Resources/CodeGeneration/template.in.h.j2 @ 543:75664eeacae5 dev

added sets in code generation (not tested yet in TS)
author Alain Mazy <alain@mazy.be>
date Wed, 20 Mar 2019 15:27:04 +0100
parents 9e241cef32a4
children 8432926e9db9
line wrap: on
line diff
--- a/Resources/CodeGeneration/template.in.h.j2	Wed Mar 20 10:11:53 2019 +0100
+++ b/Resources/CodeGeneration/template.in.h.j2	Wed Mar 20 15:27:04 2019 +0100
@@ -13,6 +13,7 @@
 #include <sstream>
 #include <assert.h>
 #include <memory>
+#include <set>
 #include <json/json.h>
 
 //#define STONEGEN_NO_CPP11 1
@@ -199,6 +200,43 @@
     return out;
   }
 
+  /** Throws in case of problem */
+  template<typename T>
+  void _StoneDeserializeValue(
+    std::set<T>& destValue, const Json::Value& jsonValue)
+  {
+    destValue.clear();
+    for (Json::Value::ArrayIndex i = 0; i != jsonValue.size(); i++)
+    {
+      T innerDestValue;
+      _StoneDeserializeValue(innerDestValue, jsonValue[i]);
+      destValue.insert(innerDestValue);
+    }
+  }
+
+  template<typename T>
+  Json::Value _StoneSerializeValue(const std::set<T>& value)
+  {
+    Json::Value result(Json::arrayValue);
+    for (typename std::set<T>::const_iterator it = value.begin(); it != value.end(); ++it)
+    {
+      result.append(_StoneSerializeValue(*it));
+    }
+    return result;
+  }
+
+  template<typename T>
+  std::ostream& StoneDumpValue(std::ostream& out, const std::set<T>& value, size_t indent)
+  {
+    out << MakeIndent(indent) << "[\n";
+    for (typename std::set<T>::const_iterator it = value.begin(); it != value.end(); ++it)
+    {
+      StoneDumpValue(out, *it, indent+2);
+    }
+    out << MakeIndent(indent) << "]\n";
+    return out;
+  }
+
   inline void StoneCheckSerializedValueTypeGeneric(const Json::Value& value)
   {
     if ((!value.isMember("type")) || (!value["type"].isString()))