Mercurial > hg > orthanc
comparison Core/SerializationToolbox.cpp @ 2845:218e2c864d1d
serialization of SplitStudyJob
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 28 Sep 2018 17:59:44 +0200 |
parents | 47d812308d63 |
children | 10c610e80b15 |
comparison
equal
deleted
inserted
replaced
2844:99863d6245b2 | 2845:218e2c864d1d |
---|---|
194 } | 194 } |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 | 198 |
199 void ReadMapOfStrings(std::map<std::string, std::string>& target, | |
200 const Json::Value& value, | |
201 const std::string& field) | |
202 { | |
203 if (value.type() != Json::objectValue || | |
204 !value.isMember(field.c_str()) || | |
205 value[field.c_str()].type() != Json::objectValue) | |
206 { | |
207 throw OrthancException(ErrorCode_BadFileFormat); | |
208 } | |
209 | |
210 const Json::Value& source = value[field.c_str()]; | |
211 | |
212 target.clear(); | |
213 | |
214 Json::Value::Members members = source.getMemberNames(); | |
215 | |
216 for (size_t i = 0; i < members.size(); i++) | |
217 { | |
218 const Json::Value& tmp = source[members[i]]; | |
219 | |
220 if (tmp.type() != Json::stringValue) | |
221 { | |
222 throw OrthancException(ErrorCode_BadFileFormat); | |
223 } | |
224 else | |
225 { | |
226 target[members[i]] = tmp.asString(); | |
227 } | |
228 } | |
229 } | |
230 | |
231 | |
232 void ReadMapOfTags(std::map<DicomTag, std::string>& target, | |
233 const Json::Value& value, | |
234 const std::string& field) | |
235 { | |
236 if (value.type() != Json::objectValue || | |
237 !value.isMember(field.c_str()) || | |
238 value[field.c_str()].type() != Json::objectValue) | |
239 { | |
240 throw OrthancException(ErrorCode_BadFileFormat); | |
241 } | |
242 | |
243 const Json::Value& source = value[field.c_str()]; | |
244 | |
245 target.clear(); | |
246 | |
247 Json::Value::Members members = source.getMemberNames(); | |
248 | |
249 for (size_t i = 0; i < members.size(); i++) | |
250 { | |
251 const Json::Value& tmp = source[members[i]]; | |
252 | |
253 DicomTag tag(0, 0); | |
254 | |
255 if (!DicomTag::ParseHexadecimal(tag, members[i].c_str()) || | |
256 tmp.type() != Json::stringValue) | |
257 { | |
258 throw OrthancException(ErrorCode_BadFileFormat); | |
259 } | |
260 else | |
261 { | |
262 target[tag] = tmp.asString(); | |
263 } | |
264 } | |
265 } | |
266 | |
267 | |
199 void WriteArrayOfStrings(Json::Value& target, | 268 void WriteArrayOfStrings(Json::Value& target, |
200 const std::vector<std::string>& values, | 269 const std::vector<std::string>& values, |
201 const std::string& field) | 270 const std::string& field) |
202 { | 271 { |
203 if (target.type() != Json::objectValue || | 272 if (target.type() != Json::objectValue || |
256 it != tags.end(); ++it) | 325 it != tags.end(); ++it) |
257 { | 326 { |
258 value.append(it->Format()); | 327 value.append(it->Format()); |
259 } | 328 } |
260 } | 329 } |
330 | |
331 | |
332 void WriteMapOfStrings(Json::Value& target, | |
333 const std::map<std::string, std::string>& values, | |
334 const std::string& field) | |
335 { | |
336 if (target.type() != Json::objectValue || | |
337 target.isMember(field.c_str())) | |
338 { | |
339 throw OrthancException(ErrorCode_BadFileFormat); | |
340 } | |
341 | |
342 Json::Value& value = target[field]; | |
343 | |
344 value = Json::objectValue; | |
345 | |
346 for (std::map<std::string, std::string>::const_iterator | |
347 it = values.begin(); it != values.end(); ++it) | |
348 { | |
349 value[it->first] = it->second; | |
350 } | |
351 } | |
352 | |
353 | |
354 void WriteMapOfTags(Json::Value& target, | |
355 const std::map<DicomTag, std::string>& values, | |
356 const std::string& field) | |
357 { | |
358 if (target.type() != Json::objectValue || | |
359 target.isMember(field.c_str())) | |
360 { | |
361 throw OrthancException(ErrorCode_BadFileFormat); | |
362 } | |
363 | |
364 Json::Value& value = target[field]; | |
365 | |
366 value = Json::objectValue; | |
367 | |
368 for (std::map<DicomTag, std::string>::const_iterator | |
369 it = values.begin(); it != values.end(); ++it) | |
370 { | |
371 value[it->first.Format()] = it->second; | |
372 } | |
373 } | |
261 } | 374 } |
262 } | 375 } |