changeset 2240:df47c45694ed

improvement
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Dec 2016 17:50:51 +0100
parents 15637de71fee
children eb363ec95d86
files Plugins/Samples/Common/DicomDatasetReader.cpp Plugins/Samples/Common/DicomDatasetReader.h
diffstat 2 files changed, 34 insertions(+), 19 deletions(-) [+]
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);
   }
 }
--- a/Plugins/Samples/Common/DicomDatasetReader.h	Fri Dec 16 17:01:33 2016 +0100
+++ b/Plugins/Samples/Common/DicomDatasetReader.h	Fri Dec 16 17:50:51 2016 +0100
@@ -57,12 +57,16 @@
 
     std::string GetMandatoryStringValue(const DicomPath& path) const;
 
-    int GetIntegerValue(const DicomPath& path) const;
+    bool GetIntegerValue(int& target,
+                         const DicomPath& path) const;
 
-    unsigned int GetUnsignedIntegerValue(const DicomPath& path) const;
+    bool GetUnsignedIntegerValue(unsigned int& target,
+                                 const DicomPath& path) const;
 
-    float GetFloatValue(const DicomPath& path) const;
+    bool GetFloatValue(float& target,
+                       const DicomPath& path) const;
 
-    double GetDoubleValue(const DicomPath& path) const;
+    bool GetDoubleValue(double& target,
+                        const DicomPath& path) const;
   };
 }