changeset 6476:a85d8643792e pixel-anon

DicomModification::SetDicomIdentifierGenerator() takes the ownership
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 22 Nov 2025 12:29:36 +0100
parents 3f855c1e43c4
children b168eb544b0c
files OrthancFramework/Sources/DicomParsing/DicomModification.cpp OrthancFramework/Sources/DicomParsing/DicomModification.h
diffstat 2 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/DicomModification.cpp	Sat Nov 22 12:25:29 2025 +0100
+++ b/OrthancFramework/Sources/DicomParsing/DicomModification.cpp	Sat Nov 22 12:29:36 2025 +0100
@@ -471,7 +471,7 @@
 
     if (previous == uidMap_.end())
     {
-      if (identifierGenerator_ == NULL)
+      if (identifierGenerator_.get() == NULL)
       {
         mapped = FromDcmtkBridge::GenerateUniqueIdentifier(level);
       }
@@ -541,9 +541,8 @@
     keepSeriesInstanceUid_(false),
     keepSopInstanceUid_(false),
     updateReferencedRelationships_(true),
-    isAnonymization_(false),
-    //privateCreator_("PrivateCreator"),
-    identifierGenerator_(NULL)
+    isAnonymization_(false)
+    //privateCreator_("PrivateCreator")
   {
   }
 
@@ -965,6 +964,11 @@
            ResourceType_Study + 1 == ResourceType_Series &&
            ResourceType_Series + 1 == ResourceType_Instance);
 
+    if (toModify.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+
     if (IsRemoved(DICOM_TAG_PATIENT_ID) ||
         IsRemoved(DICOM_TAG_STUDY_INSTANCE_UID) ||
         IsRemoved(DICOM_TAG_SERIES_INSTANCE_UID) ||
@@ -1469,9 +1473,16 @@
     // }
   }
 
-  void DicomModification::SetDicomIdentifierGenerator(DicomModification::IDicomIdentifierGenerator &generator)
+  void DicomModification::SetDicomIdentifierGenerator(DicomModification::IDicomIdentifierGenerator* generator)
   {
-    identifierGenerator_ = &generator;
+    if (generator == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    else
+    {
+      identifierGenerator_.reset(generator);
+    }
   }
 
 
@@ -1651,8 +1662,7 @@
   }
 
   
-  DicomModification::DicomModification(const Json::Value& serialized) :
-    identifierGenerator_(NULL)
+  DicomModification::DicomModification(const Json::Value& serialized)
   {
     removePrivateTags_ = SerializationToolbox::ReadBoolean(serialized, REMOVE_PRIVATE_TAGS);
     level_ = StringToResourceType(SerializationToolbox::ReadString(serialized, LEVEL).c_str());
--- a/OrthancFramework/Sources/DicomParsing/DicomModification.h	Sat Nov 22 12:25:29 2025 +0100
+++ b/OrthancFramework/Sources/DicomParsing/DicomModification.h	Sat Nov 22 12:29:36 2025 +0100
@@ -158,7 +158,7 @@
     DicomMap currentSource_;
     std::string privateCreator_;
 
-    IDicomIdentifierGenerator* identifierGenerator_;
+    std::unique_ptr<IDicomIdentifierGenerator> identifierGenerator_;
 
     // New in Orthanc 1.9.4
     SetOfTags            uids_;
@@ -265,7 +265,7 @@
     void ParseAnonymizationRequest(bool& patientNameOverridden /* out */,
                                    const Json::Value& request);
 
-    void SetDicomIdentifierGenerator(IDicomIdentifierGenerator& generator);
+    void SetDicomIdentifierGenerator(IDicomIdentifierGenerator* generator /* takes ownership */);
 
     void Serialize(Json::Value& value) const;