diff Plugins/Samples/Common/DicomDatasetReader.cpp @ 2240:df47c45694ed

improvement
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Dec 2016 17:50:51 +0100
parents 4f0a9a61d905
children a3a65de1840f
line wrap: on
line diff
--- a/Plugins/Samples/Common/DicomDatasetReader.cpp	Fri Dec 16 17:01:33 2016 +0100
+++ b/Plugins/Samples/Common/DicomDatasetReader.cpp	Fri Dec 16 17:50:51 2016 +0100
@@ -104,8 +104,9 @@
 
 
   template <typename T>
-  static T GetValueInternal(const IDicomDataset& dataset,
-                            const DicomPath& path)
+  static bool GetValueInternal(T& target,
+                               const IDicomDataset& dataset,
+                               const DicomPath& path)
   {
     try
     {
@@ -113,11 +114,12 @@
 
       if (dataset.GetStringValue(s, path))
       {
-        return boost::lexical_cast<T>(StripSpaces(s));
+        target = boost::lexical_cast<T>(StripSpaces(s));
+        return true;
       }
       else
       {
-        ORTHANC_PLUGINS_THROW_EXCEPTION(InexistentTag);
+        return false;
       }
     }
     catch (boost::bad_lexical_cast&)
@@ -127,19 +129,26 @@
   }
 
 
-  int DicomDatasetReader::GetIntegerValue(const DicomPath& path) const
+  bool DicomDatasetReader::GetIntegerValue(int& target,
+                                           const DicomPath& path) const
   {
-    return GetValueInternal<int>(dataset_, path);
+    return GetValueInternal<int>(target, dataset_, path);
   }
 
 
-  unsigned int DicomDatasetReader::GetUnsignedIntegerValue(const DicomPath& path) const
+  bool DicomDatasetReader::GetUnsignedIntegerValue(unsigned int& target,
+                                                   const DicomPath& path) const
   {
-    int value = GetIntegerValue(path);
-    
-    if (value >= 0)
+    int value;
+
+    if (!GetIntegerValue(value, path))
     {
-      return static_cast<unsigned int>(value);
+      return false;
+    }
+    else if (value >= 0)
+    {
+      target = static_cast<unsigned int>(value);
+      return true;
     }
     else
     {
@@ -148,14 +157,16 @@
   }
 
 
-  float DicomDatasetReader::GetFloatValue(const DicomPath& path) const
+  bool DicomDatasetReader::GetFloatValue(float& target,
+                                         const DicomPath& path) const
   {
-    return GetValueInternal<float>(dataset_, path);
+    return GetValueInternal<float>(target, dataset_, path);
   }
 
 
-  double DicomDatasetReader::GetDoubleValue(const DicomPath& path) const
+  bool DicomDatasetReader::GetDoubleValue(double& target,
+                                          const DicomPath& path) const
   {
-    return GetValueInternal<double>(dataset_, path);
+    return GetValueInternal<double>(target, dataset_, path);
   }
 }