Mercurial > hg > orthanc-stone
diff Resources/CodeGeneration/template.in.h.j2 @ 690:f185cfcb72a0 am-dev
CodeGen: tests improvements
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 16 May 2019 19:10:38 +0200 |
parents | 342f3e04bfa9 |
children | 78f4317eb94b |
line wrap: on
line diff
--- a/Resources/CodeGeneration/template.in.h.j2 Thu May 16 17:54:22 2019 +0200 +++ b/Resources/CodeGeneration/template.in.h.j2 Thu May 16 19:10:38 2019 +0200 @@ -182,6 +182,17 @@ return out; } + inline std::string ToString(const std::string& str) + { + return str; + } + + inline void FromString(std::string& value, std::string strValue) + { + value = strValue; + } + + /** Throws in case of problem */ template<typename TK, typename TV> void _StoneDeserializeValue( @@ -195,8 +206,10 @@ itr != jsonValue.end(); itr++) { + std::string strKey; + _StoneDeserializeValue(strKey, itr.key()); TK key; - _StoneDeserializeValue(key, itr.key()); + FromString(key, strKey); // if you have a compile error here, it means that your type is not suitable to be the key of a map (or you should overwrite the FromString/ToString in template.in.h.j2) TV innerDestValue; _StoneDeserializeValue(innerDestValue, *itr); @@ -205,6 +218,7 @@ } } } + template<typename TK, typename TV> Json::Value _StoneSerializeValue(const std::map<TK, TV>& value) { @@ -214,7 +228,7 @@ it != value.cend(); ++it) { // it->first it->second - result[it->first] = _StoneSerializeValue(it->second); + result[ToString(it->first)] = _StoneSerializeValue(it->second); } return result; } @@ -239,7 +253,7 @@ void _StoneDeserializeValue( std::vector<T>& destValue, const Json::Value& jsonValue) { - if (!jsonValue.isNull()) + if (!jsonValue.isNull() && jsonValue.isArray()) { destValue.clear(); destValue.reserve(jsonValue.size()); @@ -281,7 +295,7 @@ void _StoneDeserializeValue( std::set<T>& destValue, const Json::Value& jsonValue) { - if (!jsonValue.isNull()) + if (!jsonValue.isNull() && jsonValue.isArray()) { destValue.clear(); for (Json::Value::ArrayIndex i = 0; i != jsonValue.size(); i++)