Mercurial > hg > orthanc-databases
comparison Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp @ 272:c7dc70a0a477
upgrade to Orthanc SDK 1.9.2
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 22 Apr 2021 14:09:46 +0200 |
parents | 3236894320d6 |
children | 64bf8914f02e |
comparison
equal
deleted
inserted
replaced
271:6b18d3fbee82 | 272:c7dc70a0a477 |
---|---|
311 return CheckHttp(OrthancPluginRestApiPut(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); | 311 return CheckHttp(OrthancPluginRestApiPut(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 | 315 |
316 static bool ReadJsonInternal(Json::Value& target, | |
317 const void* buffer, | |
318 size_t size, | |
319 bool collectComments) | |
320 { | |
321 #if JSONCPP_USE_DEPRECATED == 1 | |
322 Json::Reader reader; | |
323 return reader.parse(reinterpret_cast<const char*>(buffer), | |
324 reinterpret_cast<const char*>(buffer) + size, target, collectComments); | |
325 #else | |
326 Json::CharReaderBuilder builder; | |
327 builder.settings_["collectComments"] = collectComments; | |
328 | |
329 const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); | |
330 assert(reader.get() != NULL); | |
331 | |
332 JSONCPP_STRING err; | |
333 if (reader->parse(reinterpret_cast<const char*>(buffer), | |
334 reinterpret_cast<const char*>(buffer) + size, &target, &err)) | |
335 { | |
336 return true; | |
337 } | |
338 else | |
339 { | |
340 LogError("Cannot parse JSON: " + std::string(err)); | |
341 return false; | |
342 } | |
343 #endif | |
344 } | |
345 | |
346 | |
316 bool ReadJson(Json::Value& target, | 347 bool ReadJson(Json::Value& target, |
317 const std::string& source) | 348 const std::string& source) |
318 { | 349 { |
319 return ReadJson(target, source.empty() ? NULL : source.c_str(), source.size()); | 350 return ReadJson(target, source.empty() ? NULL : source.c_str(), source.size()); |
320 } | 351 } |
322 | 353 |
323 bool ReadJson(Json::Value& target, | 354 bool ReadJson(Json::Value& target, |
324 const void* buffer, | 355 const void* buffer, |
325 size_t size) | 356 size_t size) |
326 { | 357 { |
327 #if JSONCPP_USE_DEPRECATED == 1 | 358 return ReadJsonInternal(target, buffer, size, true); |
328 Json::Reader reader; | |
329 return reader.parse(reinterpret_cast<const char*>(buffer), | |
330 reinterpret_cast<const char*>(buffer) + size, target); | |
331 #else | |
332 Json::CharReaderBuilder builder; | |
333 const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); | |
334 assert(reader.get() != NULL); | |
335 JSONCPP_STRING err; | |
336 if (reader->parse(reinterpret_cast<const char*>(buffer), | |
337 reinterpret_cast<const char*>(buffer) + size, &target, &err)) | |
338 { | |
339 return true; | |
340 } | |
341 else | |
342 { | |
343 LogError("Cannot parse JSON: " + err); | |
344 return false; | |
345 } | |
346 #endif | |
347 } | 359 } |
348 | 360 |
361 | |
362 bool ReadJsonWithoutComments(Json::Value& target, | |
363 const std::string& source) | |
364 { | |
365 return ReadJsonWithoutComments(target, source.empty() ? NULL : source.c_str(), source.size()); | |
366 } | |
367 | |
368 | |
369 bool ReadJsonWithoutComments(Json::Value& target, | |
370 const void* buffer, | |
371 size_t size) | |
372 { | |
373 return ReadJsonInternal(target, buffer, size, false); | |
374 } | |
375 | |
349 | 376 |
350 void WriteFastJson(std::string& target, | 377 void WriteFastJson(std::string& target, |
351 const Json::Value& source) | 378 const Json::Value& source) |
352 { | 379 { |
353 #if JSONCPP_USE_DEPRECATED == 1 | 380 #if JSONCPP_USE_DEPRECATED == 1 |