Mercurial > hg > orthanc-stone
comparison 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 |
comparison
equal
deleted
inserted
replaced
688:8c0b073efda8 | 690:f185cfcb72a0 |
---|---|
180 { | 180 { |
181 out << MakeIndent(indent) << "\"" << value << "\""; | 181 out << MakeIndent(indent) << "\"" << value << "\""; |
182 return out; | 182 return out; |
183 } | 183 } |
184 | 184 |
185 inline std::string ToString(const std::string& str) | |
186 { | |
187 return str; | |
188 } | |
189 | |
190 inline void FromString(std::string& value, std::string strValue) | |
191 { | |
192 value = strValue; | |
193 } | |
194 | |
195 | |
185 /** Throws in case of problem */ | 196 /** Throws in case of problem */ |
186 template<typename TK, typename TV> | 197 template<typename TK, typename TV> |
187 void _StoneDeserializeValue( | 198 void _StoneDeserializeValue( |
188 std::map<TK, TV>& destValue, const Json::Value& jsonValue) | 199 std::map<TK, TV>& destValue, const Json::Value& jsonValue) |
189 { | 200 { |
193 for ( | 204 for ( |
194 Json::Value::const_iterator itr = jsonValue.begin(); | 205 Json::Value::const_iterator itr = jsonValue.begin(); |
195 itr != jsonValue.end(); | 206 itr != jsonValue.end(); |
196 itr++) | 207 itr++) |
197 { | 208 { |
209 std::string strKey; | |
210 _StoneDeserializeValue(strKey, itr.key()); | |
198 TK key; | 211 TK key; |
199 _StoneDeserializeValue(key, itr.key()); | 212 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) |
200 | 213 |
201 TV innerDestValue; | 214 TV innerDestValue; |
202 _StoneDeserializeValue(innerDestValue, *itr); | 215 _StoneDeserializeValue(innerDestValue, *itr); |
203 | 216 |
204 destValue[key] = innerDestValue; | 217 destValue[key] = innerDestValue; |
205 } | 218 } |
206 } | 219 } |
207 } | 220 } |
221 | |
208 template<typename TK, typename TV> | 222 template<typename TK, typename TV> |
209 Json::Value _StoneSerializeValue(const std::map<TK, TV>& value) | 223 Json::Value _StoneSerializeValue(const std::map<TK, TV>& value) |
210 { | 224 { |
211 Json::Value result(Json::objectValue); | 225 Json::Value result(Json::objectValue); |
212 | 226 |
213 for (typename std::map<TK, TV>::const_iterator it = value.cbegin(); | 227 for (typename std::map<TK, TV>::const_iterator it = value.cbegin(); |
214 it != value.cend(); ++it) | 228 it != value.cend(); ++it) |
215 { | 229 { |
216 // it->first it->second | 230 // it->first it->second |
217 result[it->first] = _StoneSerializeValue(it->second); | 231 result[ToString(it->first)] = _StoneSerializeValue(it->second); |
218 } | 232 } |
219 return result; | 233 return result; |
220 } | 234 } |
221 | 235 |
222 template<typename TK, typename TV> | 236 template<typename TK, typename TV> |
237 /** Throws in case of problem */ | 251 /** Throws in case of problem */ |
238 template<typename T> | 252 template<typename T> |
239 void _StoneDeserializeValue( | 253 void _StoneDeserializeValue( |
240 std::vector<T>& destValue, const Json::Value& jsonValue) | 254 std::vector<T>& destValue, const Json::Value& jsonValue) |
241 { | 255 { |
242 if (!jsonValue.isNull()) | 256 if (!jsonValue.isNull() && jsonValue.isArray()) |
243 { | 257 { |
244 destValue.clear(); | 258 destValue.clear(); |
245 destValue.reserve(jsonValue.size()); | 259 destValue.reserve(jsonValue.size()); |
246 for (Json::Value::ArrayIndex i = 0; i != jsonValue.size(); i++) | 260 for (Json::Value::ArrayIndex i = 0; i != jsonValue.size(); i++) |
247 { | 261 { |
279 /** Throws in case of problem */ | 293 /** Throws in case of problem */ |
280 template<typename T> | 294 template<typename T> |
281 void _StoneDeserializeValue( | 295 void _StoneDeserializeValue( |
282 std::set<T>& destValue, const Json::Value& jsonValue) | 296 std::set<T>& destValue, const Json::Value& jsonValue) |
283 { | 297 { |
284 if (!jsonValue.isNull()) | 298 if (!jsonValue.isNull() && jsonValue.isArray()) |
285 { | 299 { |
286 destValue.clear(); | 300 destValue.clear(); |
287 for (Json::Value::ArrayIndex i = 0; i != jsonValue.size(); i++) | 301 for (Json::Value::ArrayIndex i = 0; i != jsonValue.size(); i++) |
288 { | 302 { |
289 T innerDestValue; | 303 T innerDestValue; |