diff OrthancFramework/Sources/DicomFormat/DicomPath.cpp @ 4735:e17fdc43ef6c

optimized version of DicomPath::IsMatch()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 05 Jul 2021 17:03:46 +0200
parents 13efc0967cea
children 7053502fbf97
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/DicomPath.cpp	Mon Jul 05 16:12:10 2021 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomPath.cpp	Mon Jul 05 17:03:46 2021 +0200
@@ -372,4 +372,42 @@
       }
     }
   }
+
+
+  bool DicomPath::IsMatch(const DicomPath& pattern,
+                          const std::vector<Orthanc::DicomTag>& prefixTags,
+                          const std::vector<size_t>& prefixIndexes,
+                          const DicomTag& finalTag)
+  {
+    if (prefixTags.size() != prefixIndexes.size())
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+    
+    if (prefixTags.size() < pattern.GetPrefixLength())
+    {
+      return false;
+    }
+    else
+    {
+      for (size_t i = 0; i < pattern.GetPrefixLength(); i++)
+      {
+        if (prefixTags[i] != pattern.GetPrefixTag(i) ||
+            (!pattern.IsPrefixUniversal(i) &&
+             prefixIndexes[i] != pattern.GetPrefixIndex(i)))
+        {
+          return false;
+        }
+      }
+
+      if (prefixTags.size() == pattern.GetPrefixLength())
+      {
+        return (finalTag == pattern.GetFinalTag());
+      }
+      else
+      {
+        return (prefixTags[pattern.GetPrefixLength()] == pattern.GetFinalTag());
+      }
+    }
+  }    
 }