Mercurial > hg > orthanc-stone
changeset 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 | b336dfa71f12 |
children | 11510f92cc38 |
files | Resources/CodeGeneration/stonegentool.py Resources/CodeGeneration/template.in.h.j2 |
diffstat | 2 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Resources/CodeGeneration/stonegentool.py Wed Mar 20 10:11:53 2019 +0100 +++ b/Resources/CodeGeneration/stonegentool.py Wed Mar 20 15:27:04 2019 +0100 @@ -82,6 +82,7 @@ retVal = canonicalTypename retVal = retVal.replace("map", "std::map") retVal = retVal.replace("vector", "std::vector") + retVal = retVal.replace("set", "std::set") retVal = retVal.replace("string", "std::string") retVal = retVal.replace("int32", "int32_t") retVal = retVal.replace("float32", "float") @@ -98,6 +99,7 @@ retVal = canonicalTypename retVal = retVal.replace("map", "Map") retVal = retVal.replace("vector", "Array") + retVal = retVal.replace("set", "Set") retVal = retVal.replace("int32", "number") retVal = retVal.replace("float32", "number") retVal = retVal.replace("float64", "number")
--- 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()))