Mercurial > hg > orthanc
comparison Core/DicomParsing/ParsedDicomFile.cpp @ 2846:d386abc18133
simplification in SplitStudyJob, fix possible memory leak
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 28 Sep 2018 18:36:20 +0200 |
parents | 9a0c6a046cc2 |
children | f3c1eda54e47 |
comparison
equal
deleted
inserted
replaced
2845:218e2c864d1d | 2846:d386abc18133 |
---|---|
942 | 942 |
943 | 943 |
944 void ParsedDicomFile::CreateFromDicomMap(const DicomMap& source, | 944 void ParsedDicomFile::CreateFromDicomMap(const DicomMap& source, |
945 Encoding defaultEncoding) | 945 Encoding defaultEncoding) |
946 { | 946 { |
947 try | 947 pimpl_->file_.reset(new DcmFileFormat); |
948 { | 948 |
949 pimpl_->file_.reset(new DcmFileFormat); | 949 const DicomValue* tmp = source.TestAndGetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET); |
950 | 950 |
951 const DicomValue* tmp = source.TestAndGetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET); | 951 if (tmp == NULL) |
952 | 952 { |
953 if (tmp == NULL) | 953 SetEncoding(defaultEncoding); |
954 { | 954 } |
955 SetEncoding(defaultEncoding); | 955 else if (tmp->IsBinary()) |
956 } | 956 { |
957 else if (tmp->IsBinary()) | 957 LOG(ERROR) << "Invalid binary string in the SpecificCharacterSet (0008,0005) tag"; |
958 { | 958 throw OrthancException(ErrorCode_ParameterOutOfRange); |
959 LOG(ERROR) << "Invalid binary string in the SpecificCharacterSet (0008,0005) tag"; | 959 } |
960 else if (tmp->IsNull() || | |
961 tmp->GetContent().empty()) | |
962 { | |
963 SetEncoding(defaultEncoding); | |
964 } | |
965 else | |
966 { | |
967 Encoding encoding; | |
968 | |
969 if (GetDicomEncoding(encoding, tmp->GetContent().c_str())) | |
970 { | |
971 SetEncoding(encoding); | |
972 } | |
973 else | |
974 { | |
975 LOG(ERROR) << "Unsupported value for the SpecificCharacterSet (0008,0005) tag: \"" | |
976 << tmp->GetContent() << "\""; | |
960 throw OrthancException(ErrorCode_ParameterOutOfRange); | 977 throw OrthancException(ErrorCode_ParameterOutOfRange); |
961 } | 978 } |
962 else if (tmp->IsNull() || | 979 } |
963 tmp->GetContent().empty()) | 980 |
964 { | 981 for (DicomMap::Map::const_iterator |
965 SetEncoding(defaultEncoding); | 982 it = source.map_.begin(); it != source.map_.end(); ++it) |
966 } | 983 { |
967 else | 984 if (it->first != DICOM_TAG_SPECIFIC_CHARACTER_SET && |
968 { | 985 !it->second->IsNull()) |
969 Encoding encoding; | 986 { |
970 | 987 ReplacePlainString(it->first, it->second->GetContent()); |
971 if (GetDicomEncoding(encoding, tmp->GetContent().c_str())) | 988 } |
972 { | |
973 SetEncoding(encoding); | |
974 } | |
975 else | |
976 { | |
977 LOG(ERROR) << "Unsupported value for the SpecificCharacterSet (0008,0005) tag: \"" | |
978 << tmp->GetContent() << "\""; | |
979 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
980 } | |
981 } | |
982 | |
983 for (DicomMap::Map::const_iterator | |
984 it = source.map_.begin(); it != source.map_.end(); ++it) | |
985 { | |
986 if (it->first != DICOM_TAG_SPECIFIC_CHARACTER_SET && | |
987 !it->second->IsNull()) | |
988 { | |
989 ReplacePlainString(it->first, it->second->GetContent()); | |
990 } | |
991 } | |
992 } | |
993 catch (OrthancException&) | |
994 { | |
995 // Manually delete the PImpl to avoid a memory leak due to | |
996 // throwing the exception in the constructor | |
997 delete pimpl_; | |
998 pimpl_ = NULL; | |
999 throw; | |
1000 } | 989 } |
1001 } | 990 } |
1002 | 991 |
1003 | 992 |
1004 ParsedDicomFile::ParsedDicomFile(const DicomMap& map, | 993 ParsedDicomFile::ParsedDicomFile(const DicomMap& map, |
1056 | 1045 |
1057 | 1046 |
1058 ParsedDicomFile::ParsedDicomFile(DcmFileFormat& dicom) : pimpl_(new PImpl) | 1047 ParsedDicomFile::ParsedDicomFile(DcmFileFormat& dicom) : pimpl_(new PImpl) |
1059 { | 1048 { |
1060 pimpl_->file_.reset(new DcmFileFormat(dicom)); | 1049 pimpl_->file_.reset(new DcmFileFormat(dicom)); |
1061 } | |
1062 | |
1063 | |
1064 ParsedDicomFile::~ParsedDicomFile() | |
1065 { | |
1066 delete pimpl_; | |
1067 } | 1050 } |
1068 | 1051 |
1069 | 1052 |
1070 DcmFileFormat& ParsedDicomFile::GetDcmtkObject() const | 1053 DcmFileFormat& ParsedDicomFile::GetDcmtkObject() const |
1071 { | 1054 { |