Mercurial > hg > orthanc-wsi
diff Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.cpp @ 87:3d83d34cd4db
sync, optimizations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 16 Dec 2016 16:44:14 +0100 |
parents | 319b8c45c231 |
children | 61e629ce7c94 |
line wrap: on
line diff
--- a/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.cpp Fri Dec 16 14:55:19 2016 +0100 +++ b/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.cpp Fri Dec 16 16:44:14 2016 +0100 @@ -68,20 +68,31 @@ } - DicomDatasetReader::DicomDatasetReader(IDicomDataset* dataset) : // takes ownership + DicomDatasetReader::DicomDatasetReader(const IDicomDataset& dataset) : dataset_(dataset) { - if (dataset == NULL) + } + + + std::string DicomDatasetReader::GetStringValue(const DicomPath& path, + const std::string& defaultValue) const + { + std::string s; + if (dataset_.GetStringValue(s, path)) { - ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); + return s; + } + else + { + return defaultValue; } } - + std::string DicomDatasetReader::GetMandatoryStringValue(const DicomPath& path) const { std::string s; - if (dataset_->GetStringValue(s, path)) + if (dataset_.GetStringValue(s, path)) { return s; } @@ -92,12 +103,22 @@ } - int DicomDatasetReader::GetIntegerValue(const DicomPath& path) + template <typename T> + static T GetValueInternal(const IDicomDataset& dataset, + const DicomPath& path) { try { - std::string s = StripSpaces(GetMandatoryStringValue(path)); - return boost::lexical_cast<int>(s); + std::string s; + + if (dataset.GetStringValue(s, path)) + { + return boost::lexical_cast<T>(StripSpaces(s)); + } + else + { + ORTHANC_PLUGINS_THROW_EXCEPTION(InexistentTag); + } } catch (boost::bad_lexical_cast&) { @@ -106,10 +127,16 @@ } - unsigned int DicomDatasetReader::GetUnsignedIntegerValue(const DicomPath& path) + int DicomDatasetReader::GetIntegerValue(const DicomPath& path) const + { + return GetValueInternal<int>(dataset_, path); + } + + + unsigned int DicomDatasetReader::GetUnsignedIntegerValue(const DicomPath& path) const { int value = GetIntegerValue(path); - + if (value >= 0) { return static_cast<unsigned int>(value); @@ -119,4 +146,16 @@ ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); } } + + + float DicomDatasetReader::GetFloatValue(const DicomPath& path) const + { + return GetValueInternal<float>(dataset_, path); + } + + + double DicomDatasetReader::GetDoubleValue(const DicomPath& path) const + { + return GetValueInternal<double>(dataset_, path); + } }