Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
2239:15637de71fee | 2240:df47c45694ed |
---|---|
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 template <typename T> | 106 template <typename T> |
107 static T GetValueInternal(const IDicomDataset& dataset, | 107 static bool GetValueInternal(T& target, |
108 const DicomPath& path) | 108 const IDicomDataset& dataset, |
109 const DicomPath& path) | |
109 { | 110 { |
110 try | 111 try |
111 { | 112 { |
112 std::string s; | 113 std::string s; |
113 | 114 |
114 if (dataset.GetStringValue(s, path)) | 115 if (dataset.GetStringValue(s, path)) |
115 { | 116 { |
116 return boost::lexical_cast<T>(StripSpaces(s)); | 117 target = boost::lexical_cast<T>(StripSpaces(s)); |
118 return true; | |
117 } | 119 } |
118 else | 120 else |
119 { | 121 { |
120 ORTHANC_PLUGINS_THROW_EXCEPTION(InexistentTag); | 122 return false; |
121 } | 123 } |
122 } | 124 } |
123 catch (boost::bad_lexical_cast&) | 125 catch (boost::bad_lexical_cast&) |
124 { | 126 { |
125 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | 127 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
126 } | 128 } |
127 } | 129 } |
128 | 130 |
129 | 131 |
130 int DicomDatasetReader::GetIntegerValue(const DicomPath& path) const | 132 bool DicomDatasetReader::GetIntegerValue(int& target, |
133 const DicomPath& path) const | |
131 { | 134 { |
132 return GetValueInternal<int>(dataset_, path); | 135 return GetValueInternal<int>(target, dataset_, path); |
133 } | 136 } |
134 | 137 |
135 | 138 |
136 unsigned int DicomDatasetReader::GetUnsignedIntegerValue(const DicomPath& path) const | 139 bool DicomDatasetReader::GetUnsignedIntegerValue(unsigned int& target, |
140 const DicomPath& path) const | |
137 { | 141 { |
138 int value = GetIntegerValue(path); | 142 int value; |
139 | 143 |
140 if (value >= 0) | 144 if (!GetIntegerValue(value, path)) |
141 { | 145 { |
142 return static_cast<unsigned int>(value); | 146 return false; |
147 } | |
148 else if (value >= 0) | |
149 { | |
150 target = static_cast<unsigned int>(value); | |
151 return true; | |
143 } | 152 } |
144 else | 153 else |
145 { | 154 { |
146 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | 155 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); |
147 } | 156 } |
148 } | 157 } |
149 | 158 |
150 | 159 |
151 float DicomDatasetReader::GetFloatValue(const DicomPath& path) const | 160 bool DicomDatasetReader::GetFloatValue(float& target, |
161 const DicomPath& path) const | |
152 { | 162 { |
153 return GetValueInternal<float>(dataset_, path); | 163 return GetValueInternal<float>(target, dataset_, path); |
154 } | 164 } |
155 | 165 |
156 | 166 |
157 double DicomDatasetReader::GetDoubleValue(const DicomPath& path) const | 167 bool DicomDatasetReader::GetDoubleValue(double& target, |
168 const DicomPath& path) const | |
158 { | 169 { |
159 return GetValueInternal<double>(dataset_, path); | 170 return GetValueInternal<double>(target, dataset_, path); |
160 } | 171 } |
161 } | 172 } |