comparison Core/DicomParsing/FromDcmtkBridge.cpp @ 3712:2a170a8f1faf

replacing std::auto_ptr by std::unique_ptr
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 02 Mar 2020 15:32:45 +0100
parents bc25deb40302
children 090022f1b5e1
comparison
equal deleted inserted replaced
3709:1f4910999fe7 3712:2a170a8f1faf
45 # error The macro DCMTK_VERSION_NUMBER must be defined 45 # error The macro DCMTK_VERSION_NUMBER must be defined
46 #endif 46 #endif
47 47
48 #include "FromDcmtkBridge.h" 48 #include "FromDcmtkBridge.h"
49 #include "ToDcmtkBridge.h" 49 #include "ToDcmtkBridge.h"
50 #include "../Compatibility.h"
50 #include "../Logging.h" 51 #include "../Logging.h"
51 #include "../Toolbox.h" 52 #include "../Toolbox.h"
52 #include "../OrthancException.h" 53 #include "../OrthancException.h"
53 54
54 #if ORTHANC_SANDBOXED == 0 55 #if ORTHANC_SANDBOXED == 0
349 350
350 LOG(INFO) << "Registering tag in dictionary: " << tag << " " << (DcmVR(evr).getValidVRName()) << " " 351 LOG(INFO) << "Registering tag in dictionary: " << tag << " " << (DcmVR(evr).getValidVRName()) << " "
351 << name << " (multiplicity: " << minMultiplicity << "-" 352 << name << " (multiplicity: " << minMultiplicity << "-"
352 << (arbitrary ? "n" : boost::lexical_cast<std::string>(maxMultiplicity)) << ")"; 353 << (arbitrary ? "n" : boost::lexical_cast<std::string>(maxMultiplicity)) << ")";
353 354
354 std::auto_ptr<DcmDictEntry> entry; 355 std::unique_ptr<DcmDictEntry> entry;
355 if (privateCreator.empty()) 356 if (privateCreator.empty())
356 { 357 {
357 if (tag.GetGroup() % 2 == 1) 358 if (tag.GetGroup() % 2 == 1)
358 { 359 {
359 char buf[128]; 360 char buf[128];
883 Json::Value& target = PrepareNode(parent, element, format); 884 Json::Value& target = PrepareNode(parent, element, format);
884 885
885 if (element.isLeaf()) 886 if (element.isLeaf())
886 { 887 {
887 // The "0" below lets "LeafValueToJson()" take care of "TooLong" values 888 // The "0" below lets "LeafValueToJson()" take care of "TooLong" values
888 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement 889 std::unique_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement
889 (element, flags, 0, encoding, hasCodeExtensions, ignoreTagLength)); 890 (element, flags, 0, encoding, hasCodeExtensions, ignoreTagLength));
890 891
891 if (ignoreTagLength.find(GetTag(element)) == ignoreTagLength.end()) 892 if (ignoreTagLength.find(GetTag(element)) == ignoreTagLength.end())
892 { 893 {
893 LeafValueToJson(target, *v, format, flags, maxStringLength); 894 LeafValueToJson(target, *v, format, flags, maxStringLength);
1630 const Json::Value& value, 1631 const Json::Value& value,
1631 bool decodeDataUriScheme, 1632 bool decodeDataUriScheme,
1632 Encoding dicomEncoding, 1633 Encoding dicomEncoding,
1633 const std::string& privateCreator) 1634 const std::string& privateCreator)
1634 { 1635 {
1635 std::auto_ptr<DcmElement> element; 1636 std::unique_ptr<DcmElement> element;
1636 1637
1637 switch (value.type()) 1638 switch (value.type())
1638 { 1639 {
1639 case Json::stringValue: 1640 case Json::stringValue:
1640 element.reset(CreateElementForTag(tag, privateCreator)); 1641 element.reset(CreateElementForTag(tag, privateCreator));
1657 DcmSequenceOfItems* sequence = new DcmSequenceOfItems(key); 1658 DcmSequenceOfItems* sequence = new DcmSequenceOfItems(key);
1658 element.reset(sequence); 1659 element.reset(sequence);
1659 1660
1660 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++) 1661 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++)
1661 { 1662 {
1662 std::auto_ptr<DcmItem> item(new DcmItem); 1663 std::unique_ptr<DcmItem> item(new DcmItem);
1663 1664
1664 switch (value[i].type()) 1665 switch (value[i].type())
1665 { 1666 {
1666 case Json::objectValue: 1667 case Json::objectValue:
1667 { 1668 {
1778 bool generateIdentifiers, 1779 bool generateIdentifiers,
1779 bool decodeDataUriScheme, 1780 bool decodeDataUriScheme,
1780 Encoding defaultEncoding, 1781 Encoding defaultEncoding,
1781 const std::string& privateCreator) 1782 const std::string& privateCreator)
1782 { 1783 {
1783 std::auto_ptr<DcmDataset> result(new DcmDataset); 1784 std::unique_ptr<DcmDataset> result(new DcmDataset);
1784 Encoding encoding = ExtractEncoding(json, defaultEncoding); 1785 Encoding encoding = ExtractEncoding(json, defaultEncoding);
1785 1786
1786 SetString(*result, DCM_SpecificCharacterSet, GetDicomSpecificCharacterSet(encoding)); 1787 SetString(*result, DCM_SpecificCharacterSet, GetDicomSpecificCharacterSet(encoding));
1787 1788
1788 const Json::Value::Members tags = json.getMemberNames(); 1789 const Json::Value::Members tags = json.getMemberNames();
1814 hasSopInstanceUid = true; 1815 hasSopInstanceUid = true;
1815 } 1816 }
1816 1817
1817 if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET) 1818 if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET)
1818 { 1819 {
1819 std::auto_ptr<DcmElement> element(FromDcmtkBridge::FromJson(tag, value, decodeDataUriScheme, encoding, privateCreator)); 1820 std::unique_ptr<DcmElement> element(FromDcmtkBridge::FromJson(tag, value, decodeDataUriScheme, encoding, privateCreator));
1820 const DcmTagKey& tag = element->getTag(); 1821 const DcmTagKey& tag = element->getTag();
1821 1822
1822 result->findAndDeleteElement(tag); 1823 result->findAndDeleteElement(tag);
1823 1824
1824 DcmElement* tmp = element.release(); 1825 DcmElement* tmp = element.release();
1866 { 1867 {
1867 is.setBuffer(buffer, size); 1868 is.setBuffer(buffer, size);
1868 } 1869 }
1869 is.setEos(); 1870 is.setEos();
1870 1871
1871 std::auto_ptr<DcmFileFormat> result(new DcmFileFormat); 1872 std::unique_ptr<DcmFileFormat> result(new DcmFileFormat);
1872 1873
1873 result->transferInit(); 1874 result->transferInit();
1874 if (!result->read(is).good()) 1875 if (!result->read(is).good())
1875 { 1876 {
1876 throw OrthancException(ErrorCode_BadFileFormat, 1877 throw OrthancException(ErrorCode_BadFileFormat,