# HG changeset patch # User Sebastien Jodogne # Date 1481907051 -3600 # Node ID df47c45694edde17d84743181833edcac50713d4 # Parent 15637de71feeeda31b598851f61cf72f9f889f1f improvement diff -r 15637de71fee -r df47c45694ed Plugins/Samples/Common/DicomDatasetReader.cpp --- 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 - 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(StripSpaces(s)); + target = boost::lexical_cast(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(dataset_, path); + return GetValueInternal(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(value); + return false; + } + else if (value >= 0) + { + target = static_cast(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(dataset_, path); + return GetValueInternal(target, dataset_, path); } - double DicomDatasetReader::GetDoubleValue(const DicomPath& path) const + bool DicomDatasetReader::GetDoubleValue(double& target, + const DicomPath& path) const { - return GetValueInternal(dataset_, path); + return GetValueInternal(target, dataset_, path); } } diff -r 15637de71fee -r df47c45694ed Plugins/Samples/Common/DicomDatasetReader.h --- 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; }; }