changeset 4982:40fd2a485a84

fix build for older compilers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 25 Apr 2022 18:25:46 +0200
parents d0c34145320c
children 63bf8fb86dae
files OrthancFramework/Sources/DicomFormat/DicomMap.cpp OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp OrthancFramework/UnitTestsSources/ToolboxTests.cpp OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp
diffstat 4 files changed, 142 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/DicomMap.cpp	Mon Apr 25 17:32:58 2022 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomMap.cpp	Mon Apr 25 18:25:46 2022 +0200
@@ -168,9 +168,22 @@
 
     // we keep many "copies" of the same data to guarantee quick access to organized data
     // and avoid rebuilding it all the time.
-    std::map<ResourceType, std::map<DicomTag, std::string> > mainDicomTagsByTag_;
-    std::map<ResourceType, std::map<std::string, DicomTag2> > mainDicomTagsByName_;
-    std::map<ResourceType, std::set<DicomTag> > mainDicomTagsByLevel_;
+    std::map<DicomTag, std::string>  patientsMainDicomTagsByTag_;
+    std::map<std::string, DicomTag2> patientsMainDicomTagsByName_;
+    std::set<DicomTag>               patientsMainDicomTagsByLevel_;
+
+    std::map<DicomTag, std::string>  studiesMainDicomTagsByTag_;
+    std::map<std::string, DicomTag2> studiesMainDicomTagsByName_;
+    std::set<DicomTag>               studiesMainDicomTagsByLevel_;
+
+    std::map<DicomTag, std::string>  seriesMainDicomTagsByTag_;
+    std::map<std::string, DicomTag2> seriesMainDicomTagsByName_;
+    std::set<DicomTag>               seriesMainDicomTagsByLevel_;
+
+    std::map<DicomTag, std::string>  instancesMainDicomTagsByTag_;
+    std::map<std::string, DicomTag2> instancesMainDicomTagsByName_;
+    std::set<DicomTag>               instancesMainDicomTagsByLevel_;
+
     std::set<DicomTag> allMainDicomTags_;
 
     std::map<ResourceType, std::string> signatures_;
@@ -183,9 +196,22 @@
 
     void ResetDefaultMainDicomTags()
     {
-      mainDicomTagsByTag_.clear();
-      mainDicomTagsByName_.clear();
-      mainDicomTagsByLevel_.clear();
+      patientsMainDicomTagsByTag_.clear();
+      patientsMainDicomTagsByName_.clear();
+      patientsMainDicomTagsByLevel_.clear();
+
+      studiesMainDicomTagsByTag_.clear();
+      studiesMainDicomTagsByName_.clear();
+      studiesMainDicomTagsByLevel_.clear();
+
+      seriesMainDicomTagsByTag_.clear();
+      seriesMainDicomTagsByName_.clear();
+      seriesMainDicomTagsByLevel_.clear();
+
+      instancesMainDicomTagsByTag_.clear();
+      instancesMainDicomTagsByName_.clear();
+      instancesMainDicomTagsByLevel_.clear();
+
       allMainDicomTags_.clear();
 
       // by default, initialize with the previous static list (up to 1.10.0)
@@ -216,8 +242,6 @@
 
     void LoadDefaultMainDicomTags(ResourceType level)
     {
-      assert(mainDicomTagsByTag_.find(level) == mainDicomTagsByTag_.end());
-
       const MainDicomTag* tags = NULL;
       size_t size;
 
@@ -257,6 +281,69 @@
 
     }
 
+    std::map<DicomTag, std::string>& GetMainDicomTags(ResourceType level)
+    {
+      switch (level)
+      {
+        case ResourceType_Patient:
+          return patientsMainDicomTagsByTag_;
+
+        case ResourceType_Study:
+          return studiesMainDicomTagsByTag_;
+
+        case ResourceType_Series:
+          return seriesMainDicomTagsByTag_;
+
+        case ResourceType_Instance:
+          return instancesMainDicomTagsByTag_;
+
+        default:
+          throw OrthancException(ErrorCode_InternalError);
+      }
+    }
+
+    std::map<std::string, DicomTag2>& GetMainDicomTagsByName(ResourceType level)
+    {
+      switch (level)
+      {
+        case ResourceType_Patient:
+          return patientsMainDicomTagsByName_;
+
+        case ResourceType_Study:
+          return studiesMainDicomTagsByName_;
+
+        case ResourceType_Series:
+          return seriesMainDicomTagsByName_;
+
+        case ResourceType_Instance:
+          return instancesMainDicomTagsByName_;
+
+        default:
+          throw OrthancException(ErrorCode_InternalError);
+      }
+    }
+
+    std::set<DicomTag>& GetMainDicomTagsByLevel(ResourceType level)
+    {
+      switch (level)
+      {
+        case ResourceType_Patient:
+          return patientsMainDicomTagsByLevel_;
+
+        case ResourceType_Study:
+          return studiesMainDicomTagsByLevel_;
+
+        case ResourceType_Series:
+          return seriesMainDicomTagsByLevel_;
+
+        case ResourceType_Instance:
+          return instancesMainDicomTagsByLevel_;
+
+        default:
+          throw OrthancException(ErrorCode_InternalError);
+      }
+    }
+
   public:
     // Singleton pattern
     static MainDicomTagsConfiguration& GetInstance()
@@ -267,44 +354,26 @@
 
     void AddMainDicomTag(const DicomTag& tag, const std::string& name, ResourceType level)
     {
-      if (mainDicomTagsByTag_[level].find(tag) != mainDicomTagsByTag_[level].end())
+      std::map<DicomTag, std::string>& byTag = GetMainDicomTags(level);
+      std::map<std::string, DicomTag2>& byName = GetMainDicomTagsByName(level);
+      
+      if (byTag.find(tag) != byTag.end())
       {
         throw OrthancException(ErrorCode_MainDicomTagsMultiplyDefined, tag.Format() + " is already defined");
       }
 
-      if (mainDicomTagsByName_[level].find(name) != mainDicomTagsByName_[level].end())
+      if (byName.find(name) != byName.end())
       {
         throw OrthancException(ErrorCode_MainDicomTagsMultiplyDefined, name + " is already defined");
       }
 
-      mainDicomTagsByTag_[level][tag] = name;
-      mainDicomTagsByName_[level][name] = DicomTag2(tag);
-      mainDicomTagsByLevel_[level].insert(tag);
+      byTag[tag] = name;
+      byName[name] = DicomTag2(tag);
+      GetMainDicomTagsByLevel(level).insert(tag);
       allMainDicomTags_.insert(tag);
       signatures_[level] = ComputeSignature(GetMainDicomTagsByLevel(level));
     }
 
-    const std::map<DicomTag, std::string>& GetMainDicomTags(ResourceType level) const
-    {
-      assert(mainDicomTagsByTag_.find(level) != mainDicomTagsByTag_.end());
-
-      return mainDicomTagsByTag_.at(level);
-    }
-
-    const std::map<std::string, DicomTag2>& GetMainDicomTagsByName(ResourceType level) const
-    {
-      assert(mainDicomTagsByName_.find(level) != mainDicomTagsByName_.end());
-
-      return mainDicomTagsByName_.at(level);
-    }
-
-    const std::set<DicomTag>& GetMainDicomTagsByLevel(ResourceType level) const
-    {
-      assert(mainDicomTagsByLevel_.find(level) != mainDicomTagsByLevel_.end());
-
-      return mainDicomTagsByLevel_.at(level);
-    }
-
     const std::set<DicomTag>& GetAllMainDicomTags() const
     {
       return allMainDicomTags_;
--- a/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Mon Apr 25 17:32:58 2022 +0200
+++ b/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Mon Apr 25 18:25:46 2022 +0200
@@ -380,7 +380,7 @@
     std::set<DicomTag> result;
     FromDcmtkBridge::ParseListOfTags(result, source);
 
-    ASSERT_EQ(0, result.size());
+    ASSERT_EQ(0u, result.size());
   }
 
   {// invalid tag
@@ -396,7 +396,7 @@
     
     FromDcmtkBridge::ParseListOfTags(result, source);
 
-    ASSERT_EQ(1, result.size());
+    ASSERT_EQ(1u, result.size());
   }
 
   {// Json
--- a/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Mon Apr 25 17:32:58 2022 +0200
+++ b/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Mon Apr 25 18:25:46 2022 +0200
@@ -218,7 +218,7 @@
     std::set<int> missings;
 
     ASSERT_TRUE(Toolbox::IsSetInSet<int>(needles, haystack));
-    ASSERT_EQ(0, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
+    ASSERT_EQ(0u, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
   }
 
   {
@@ -228,7 +228,7 @@
 
     haystack.insert(5);
     ASSERT_TRUE(Toolbox::IsSetInSet<int>(needles, haystack));
-    ASSERT_EQ(0, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
+    ASSERT_EQ(0u, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
   }
 
   {
@@ -239,7 +239,7 @@
     needles.insert(5);
     haystack.insert(5);
     ASSERT_TRUE(Toolbox::IsSetInSet<int>(needles, haystack));
-    ASSERT_EQ(0, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
+    ASSERT_EQ(0u, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
   }
 
   {
@@ -250,7 +250,7 @@
     needles.insert(5);
     
     ASSERT_FALSE(Toolbox::IsSetInSet<int>(needles, haystack));
-    ASSERT_EQ(1, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
+    ASSERT_EQ(1u, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
     ASSERT_TRUE(missings.count(5) == 1);
   }
 
@@ -262,7 +262,7 @@
     needles.insert(6);
     haystack.insert(5);
     ASSERT_FALSE(Toolbox::IsSetInSet<int>(needles, haystack));
-    ASSERT_EQ(1, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
+    ASSERT_EQ(1u, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
     ASSERT_TRUE(missings.count(6) == 1);
   }
 
@@ -276,7 +276,7 @@
     haystack.insert(5);
     haystack.insert(6);
     ASSERT_TRUE(Toolbox::IsSetInSet<int>(needles, haystack));
-    ASSERT_EQ(0, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
+    ASSERT_EQ(0u, Toolbox::GetMissingsFromSet<int>(missings, needles, haystack));
   }
 }
 
@@ -321,4 +321,4 @@
     Toolbox::JoinStrings(result, source, "\\");
     ASSERT_EQ("1\\2", result);
   }
-}
\ No newline at end of file
+}
--- a/OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp	Mon Apr 25 17:32:58 2022 +0200
+++ b/OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp	Mon Apr 25 18:25:46 2022 +0200
@@ -36,7 +36,7 @@
 
 static int globalPropertyId_ = 0;
 static bool force_ = false;
-static uint throttleDelay_ = 0;
+static unsigned int throttleDelay_ = 0;
 static std::unique_ptr<boost::thread> workerThread_;
 static bool workerThreadShouldStop_ = false;
 static bool triggerOnStorageCompressionChange_ = true;
@@ -156,7 +156,10 @@
 struct DbConfiguration
 {
   std::string orthancVersion;
-  std::map<OrthancPluginResourceType, std::string> mainDicomTagsSignature;
+  std::string patientsMainDicomTagsSignature;
+  std::string studiesMainDicomTagsSignature;
+  std::string seriesMainDicomTagsSignature;
+  std::string instancesMainDicomTagsSignature;
   bool storageCompressionEnabled;
 
   DbConfiguration()
@@ -166,13 +169,16 @@
 
   bool IsDefined() const
   {
-    return !orthancVersion.empty() && mainDicomTagsSignature.size() == 4;
+    return !orthancVersion.empty();
   }
 
   void Clear()
   {
     orthancVersion.clear();
-    mainDicomTagsSignature.clear();
+    patientsMainDicomTagsSignature.clear();
+    studiesMainDicomTagsSignature.clear();
+    seriesMainDicomTagsSignature.clear();
+    instancesMainDicomTagsSignature.clear();
   }
 
   void ToJson(Json::Value& target)
@@ -188,10 +194,10 @@
       target = Json::objectValue;
 
       // default main dicom tags signature are the one from Orthanc 1.4.2 (last time the list was changed):
-      signatures["Patient"] = mainDicomTagsSignature[OrthancPluginResourceType_Patient];
-      signatures["Study"] = mainDicomTagsSignature[OrthancPluginResourceType_Study];
-      signatures["Series"] = mainDicomTagsSignature[OrthancPluginResourceType_Series];
-      signatures["Instance"] = mainDicomTagsSignature[OrthancPluginResourceType_Instance];
+      signatures["Patient"] = patientsMainDicomTagsSignature;
+      signatures["Study"] = studiesMainDicomTagsSignature;
+      signatures["Series"] = seriesMainDicomTagsSignature;
+      signatures["Instance"] = instancesMainDicomTagsSignature;
 
       target["MainDicomTagsSignature"] = signatures;
       target["OrthancVersion"] = orthancVersion;
@@ -206,10 +212,10 @@
       orthancVersion = source["OrthancVersion"].asString();
 
       const Json::Value& signatures = source["MainDicomTagsSignature"];
-      mainDicomTagsSignature[OrthancPluginResourceType_Patient] = signatures["Patient"].asString();
-      mainDicomTagsSignature[OrthancPluginResourceType_Study] = signatures["Study"].asString();
-      mainDicomTagsSignature[OrthancPluginResourceType_Series] = signatures["Series"].asString();
-      mainDicomTagsSignature[OrthancPluginResourceType_Instance] = signatures["Instance"].asString();
+      patientsMainDicomTagsSignature = signatures["Patient"].asString();
+      studiesMainDicomTagsSignature = signatures["Study"].asString();
+      seriesMainDicomTagsSignature = signatures["Series"].asString();
+      instancesMainDicomTagsSignature = signatures["Instance"].asString();
 
       storageCompressionEnabled = source["StorageCompressionEnabled"].asBool();
     }
@@ -283,10 +289,10 @@
     pluginStatus.currentlyProcessingConfiguration.orthancVersion = "1.9.0"; // when we don't know, we assume some files were stored with Orthanc 1.9.0 (last version saving the dicom-as-json files)
 
     // default main dicom tags signature are the one from Orthanc 1.4.2 (last time the list was changed):
-    pluginStatus.currentlyProcessingConfiguration.mainDicomTagsSignature[OrthancPluginResourceType_Patient] = "0010,0010;0010,0020;0010,0030;0010,0040;0010,1000";
-    pluginStatus.currentlyProcessingConfiguration.mainDicomTagsSignature[OrthancPluginResourceType_Study] = "0008,0020;0008,0030;0008,0050;0008,0080;0008,0090;0008,1030;0020,000d;0020,0010;0032,1032;0032,1060";
-    pluginStatus.currentlyProcessingConfiguration.mainDicomTagsSignature[OrthancPluginResourceType_Series] = "0008,0021;0008,0031;0008,0060;0008,0070;0008,1010;0008,103e;0008,1070;0018,0010;0018,0015;0018,0024;0018,1030;0018,1090;0018,1400;0020,000e;0020,0011;0020,0037;0020,0105;0020,1002;0040,0254;0054,0081;0054,0101;0054,1000";
-    pluginStatus.currentlyProcessingConfiguration.mainDicomTagsSignature[OrthancPluginResourceType_Instance] = "0008,0012;0008,0013;0008,0018;0020,0012;0020,0013;0020,0032;0020,0037;0020,0100;0020,4000;0028,0008;0054,1330"; 
+    pluginStatus.currentlyProcessingConfiguration.patientsMainDicomTagsSignature = "0010,0010;0010,0020;0010,0030;0010,0040;0010,1000";
+    pluginStatus.currentlyProcessingConfiguration.studiesMainDicomTagsSignature = "0008,0020;0008,0030;0008,0050;0008,0080;0008,0090;0008,1030;0020,000d;0020,0010;0032,1032;0032,1060";
+    pluginStatus.currentlyProcessingConfiguration.seriesMainDicomTagsSignature = "0008,0021;0008,0031;0008,0060;0008,0070;0008,1010;0008,103e;0008,1070;0018,0010;0018,0015;0018,0024;0018,1030;0018,1090;0018,1400;0020,000e;0020,0011;0020,0037;0020,0105;0020,1002;0040,0254;0054,0081;0054,0101;0054,1000";
+    pluginStatus.currentlyProcessingConfiguration.instancesMainDicomTagsSignature = "0008,0012;0008,0013;0008,0018;0020,0012;0020,0013;0020,0032;0020,0037;0020,0100;0020,4000;0028,0008;0054,1330"; 
   }
 }
 
@@ -310,10 +316,10 @@
   Json::Value systemInfo;
 
   OrthancPlugins::RestApiGet(systemInfo, "/system", false);
-  configuration.mainDicomTagsSignature[OrthancPluginResourceType_Patient] = systemInfo["MainDicomTags"]["Patient"].asString();
-  configuration.mainDicomTagsSignature[OrthancPluginResourceType_Study] = systemInfo["MainDicomTags"]["Study"].asString();
-  configuration.mainDicomTagsSignature[OrthancPluginResourceType_Series] = systemInfo["MainDicomTags"]["Series"].asString();
-  configuration.mainDicomTagsSignature[OrthancPluginResourceType_Instance] = systemInfo["MainDicomTags"]["Instance"].asString();
+  configuration.patientsMainDicomTagsSignature = systemInfo["MainDicomTags"]["Patient"].asString();
+  configuration.studiesMainDicomTagsSignature = systemInfo["MainDicomTags"]["Study"].asString();
+  configuration.seriesMainDicomTagsSignature = systemInfo["MainDicomTags"]["Series"].asString();
+  configuration.instancesMainDicomTagsSignature = systemInfo["MainDicomTags"]["Instance"].asString();
   configuration.storageCompressionEnabled = systemInfo["StorageCompression"].asBool();
 
   configuration.orthancVersion = OrthancPlugins::GetGlobalContext()->orthancVersion;
@@ -327,8 +333,6 @@
   }
 
   const char* lastVersion = last.orthancVersion.c_str();
-  const std::map<OrthancPluginResourceType, std::string>& lastTags = last.mainDicomTagsSignature;
-  const std::map<OrthancPluginResourceType, std::string>& currentTags = current.mainDicomTagsSignature;
   bool needsProcessing = false;
 
   if (!OrthancPlugins::CheckMinimalVersion(lastVersion, 1, 9, 1))
@@ -344,7 +348,7 @@
     }
   }
 
-  if (lastTags.at(OrthancPluginResourceType_Patient) != currentTags.at(OrthancPluginResourceType_Patient))
+  if (last.patientsMainDicomTagsSignature != current.patientsMainDicomTagsSignature)
   {
     if (triggerOnMainDicomTagsChange_)
     {
@@ -357,7 +361,7 @@
     }
   }
 
-  if (lastTags.at(OrthancPluginResourceType_Study) != currentTags.at(OrthancPluginResourceType_Study))
+  if (last.studiesMainDicomTagsSignature != current.studiesMainDicomTagsSignature)
   {
     if (triggerOnMainDicomTagsChange_)
     {
@@ -370,7 +374,7 @@
     }
   }
 
-  if (lastTags.at(OrthancPluginResourceType_Series) != currentTags.at(OrthancPluginResourceType_Series))
+  if (last.seriesMainDicomTagsSignature != current.seriesMainDicomTagsSignature)
   {
     if (triggerOnMainDicomTagsChange_)
     {
@@ -383,7 +387,7 @@
     }
   }
 
-  if (lastTags.at(OrthancPluginResourceType_Instance) != currentTags.at(OrthancPluginResourceType_Instance))
+  if (last.instancesMainDicomTagsSignature != current.instancesMainDicomTagsSignature)
   {
     if (triggerOnMainDicomTagsChange_)
     {