# HG changeset patch # User Sebastien Jodogne # Date 1572098399 -7200 # Node ID 173c7f363d8fda6ce3ac882ca854951ad95f15de # Parent 0f5f9a5eed25ed45626cc70a01bb192eb85e866d DicomMap::RemoveBinaryTags diff -r 0f5f9a5eed25 -r 173c7f363d8f Core/DicomFormat/DicomMap.cpp --- a/Core/DicomFormat/DicomMap.cpp Fri Oct 25 18:09:42 2019 +0200 +++ b/Core/DicomFormat/DicomMap.cpp Sat Oct 26 15:59:59 2019 +0200 @@ -1294,6 +1294,29 @@ } + void DicomMap::RemoveBinaryTags() + { + Map kept; + + for (Map::iterator it = map_.begin(); it != map_.end(); ++it) + { + assert(it->second != NULL); + + if (!it->second->IsBinary() && + !it->second->IsNull()) + { + kept[it->first] = it->second; + } + else + { + delete it->second; + } + } + + map_ = kept; + } + + void DicomMap::Print(FILE* fp) const { DicomArray a(*this); diff -r 0f5f9a5eed25 -r 173c7f363d8f Core/DicomFormat/DicomMap.h --- a/Core/DicomFormat/DicomMap.h Fri Oct 25 18:09:42 2019 +0200 +++ b/Core/DicomFormat/DicomMap.h Sat Oct 26 15:59:59 2019 +0200 @@ -238,6 +238,8 @@ const std::string& defaultValue, bool allowBinary) const; + void RemoveBinaryTags(); + void Print(FILE* fp) const; // For debugging only }; } diff -r 0f5f9a5eed25 -r 173c7f363d8f UnitTestsSources/DicomMapTests.cpp --- a/UnitTestsSources/DicomMapTests.cpp Fri Oct 25 18:09:42 2019 +0200 +++ b/UnitTestsSources/DicomMapTests.cpp Sat Oct 26 15:59:59 2019 +0200 @@ -566,6 +566,24 @@ } +TEST(DicomMap, RemoveBinary) +{ + DicomMap b; + b.SetValue(DICOM_TAG_PATIENT_NAME, "A", false); + b.SetValue(DICOM_TAG_PATIENT_ID, "B", true); + b.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, DicomValue()); // NULL + b.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, DicomValue("C", false)); + b.SetValue(DICOM_TAG_SOP_INSTANCE_UID, DicomValue("D", true)); + + b.RemoveBinaryTags(); + + std::string s; + ASSERT_EQ(2u, b.GetSize()); + ASSERT_TRUE(b.LookupStringValue(s, DICOM_TAG_PATIENT_NAME, false)); ASSERT_EQ("A", s); + ASSERT_TRUE(b.LookupStringValue(s, DICOM_TAG_SERIES_INSTANCE_UID, false)); ASSERT_EQ("C", s); +} + + TEST(DicomWebJson, Multiplicity) {