Mercurial > hg > orthanc
comparison OrthancFramework/Sources/DicomFormat/DicomValue.cpp @ 5044:6fed78e13233
Refactored DicomMap to handle sequences when needed
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 28 Jun 2022 17:45:09 +0200 |
parents | 43e613a7756b |
children | 0ea402b4d901 |
comparison
equal
deleted
inserted
replaced
5043:ec5c203a97ea | 5044:6fed78e13233 |
---|---|
38 } | 38 } |
39 | 39 |
40 | 40 |
41 DicomValue::DicomValue(const DicomValue& other) : | 41 DicomValue::DicomValue(const DicomValue& other) : |
42 type_(other.type_), | 42 type_(other.type_), |
43 content_(other.content_) | 43 content_(other.content_), |
44 sequenceJson_(other.sequenceJson_) | |
44 { | 45 { |
45 } | 46 } |
46 | 47 |
47 | 48 |
48 DicomValue::DicomValue(const std::string& content, | 49 DicomValue::DicomValue(const std::string& content, |
59 type_(isBinary ? Type_Binary : Type_String) | 60 type_(isBinary ? Type_Binary : Type_String) |
60 { | 61 { |
61 content_.assign(data, size); | 62 content_.assign(data, size); |
62 } | 63 } |
63 | 64 |
65 DicomValue::DicomValue(const Json::Value& value) : | |
66 type_(Type_SequenceAsJson), | |
67 sequenceJson_(value) | |
68 { | |
69 } | |
64 | 70 |
65 const std::string& DicomValue::GetContent() const | 71 const std::string& DicomValue::GetContent() const |
66 { | 72 { |
67 if (type_ == Type_Null) | 73 if (type_ == Type_Null || type_ == Type_SequenceAsJson) |
68 { | 74 { |
69 throw OrthancException(ErrorCode_BadParameterType); | 75 throw OrthancException(ErrorCode_BadParameterType); |
70 } | 76 } |
71 else | 77 else |
72 { | 78 { |
73 return content_; | 79 return content_; |
74 } | 80 } |
75 } | 81 } |
76 | 82 |
83 const Json::Value& DicomValue::GetSequenceContent() const | |
84 { | |
85 if (type_ != Type_SequenceAsJson) | |
86 { | |
87 throw OrthancException(ErrorCode_BadParameterType); | |
88 } | |
89 else | |
90 { | |
91 return sequenceJson_; | |
92 } | |
93 } | |
94 | |
95 | |
77 bool DicomValue::IsNull() const | 96 bool DicomValue::IsNull() const |
78 { | 97 { |
79 return type_ == Type_Null; | 98 return type_ == Type_Null; |
80 } | 99 } |
81 | 100 |
82 bool DicomValue::IsBinary() const | 101 bool DicomValue::IsBinary() const |
83 { | 102 { |
84 return type_ == Type_Binary; | 103 return type_ == Type_Binary; |
85 } | 104 } |
86 | 105 |
106 bool DicomValue::IsString() const | |
107 { | |
108 return type_ == Type_String; | |
109 } | |
110 | |
111 bool DicomValue::IsSequence() const | |
112 { | |
113 return type_ == Type_SequenceAsJson; | |
114 } | |
87 | 115 |
88 DicomValue* DicomValue::Clone() const | 116 DicomValue* DicomValue::Clone() const |
89 { | 117 { |
90 return new DicomValue(*this); | 118 return new DicomValue(*this); |
91 } | 119 } |
105 } | 133 } |
106 #endif | 134 #endif |
107 | 135 |
108 bool DicomValue::ParseInteger32(int32_t& result) const | 136 bool DicomValue::ParseInteger32(int32_t& result) const |
109 { | 137 { |
110 if (IsBinary() || | 138 if (!IsString()) |
111 IsNull()) | |
112 { | 139 { |
113 return false; | 140 return false; |
114 } | 141 } |
115 else | 142 else |
116 { | 143 { |
118 } | 145 } |
119 } | 146 } |
120 | 147 |
121 bool DicomValue::ParseInteger64(int64_t& result) const | 148 bool DicomValue::ParseInteger64(int64_t& result) const |
122 { | 149 { |
123 if (IsBinary() || | 150 if (!IsString()) |
124 IsNull()) | |
125 { | 151 { |
126 return false; | 152 return false; |
127 } | 153 } |
128 else | 154 else |
129 { | 155 { |
131 } | 157 } |
132 } | 158 } |
133 | 159 |
134 bool DicomValue::ParseUnsignedInteger32(uint32_t& result) const | 160 bool DicomValue::ParseUnsignedInteger32(uint32_t& result) const |
135 { | 161 { |
136 if (IsBinary() || | 162 if (!IsString()) |
137 IsNull()) | |
138 { | 163 { |
139 return false; | 164 return false; |
140 } | 165 } |
141 else | 166 else |
142 { | 167 { |
144 } | 169 } |
145 } | 170 } |
146 | 171 |
147 bool DicomValue::ParseUnsignedInteger64(uint64_t& result) const | 172 bool DicomValue::ParseUnsignedInteger64(uint64_t& result) const |
148 { | 173 { |
149 if (IsBinary() || | 174 if (!IsString()) |
150 IsNull()) | |
151 { | 175 { |
152 return false; | 176 return false; |
153 } | 177 } |
154 else | 178 else |
155 { | 179 { |
157 } | 181 } |
158 } | 182 } |
159 | 183 |
160 bool DicomValue::ParseFloat(float& result) const | 184 bool DicomValue::ParseFloat(float& result) const |
161 { | 185 { |
162 if (IsBinary() || | 186 if (!IsString()) |
163 IsNull()) | |
164 { | 187 { |
165 return false; | 188 return false; |
166 } | 189 } |
167 else | 190 else |
168 { | 191 { |
170 } | 193 } |
171 } | 194 } |
172 | 195 |
173 bool DicomValue::ParseDouble(double& result) const | 196 bool DicomValue::ParseDouble(double& result) const |
174 { | 197 { |
175 if (IsBinary() || | 198 if (!IsString()) |
176 IsNull()) | |
177 { | 199 { |
178 return false; | 200 return false; |
179 } | 201 } |
180 else | 202 else |
181 { | 203 { |
183 } | 205 } |
184 } | 206 } |
185 | 207 |
186 bool DicomValue::ParseFirstFloat(float& result) const | 208 bool DicomValue::ParseFirstFloat(float& result) const |
187 { | 209 { |
188 if (IsBinary() || | 210 if (!IsString()) |
189 IsNull()) | |
190 { | 211 { |
191 return false; | 212 return false; |
192 } | 213 } |
193 else | 214 else |
194 { | 215 { |
198 | 219 |
199 bool DicomValue::ParseFirstUnsignedInteger(unsigned int& result) const | 220 bool DicomValue::ParseFirstUnsignedInteger(unsigned int& result) const |
200 { | 221 { |
201 uint64_t value; | 222 uint64_t value; |
202 | 223 |
203 if (IsBinary() || | 224 if (!IsString()) |
204 IsNull()) | |
205 { | 225 { |
206 return false; | 226 return false; |
207 } | 227 } |
208 else if (SerializationToolbox::ParseFirstUnsignedInteger64(value, GetContent())) | 228 else if (SerializationToolbox::ParseFirstUnsignedInteger64(value, GetContent())) |
209 { | 229 { |
218 | 238 |
219 bool DicomValue::CopyToString(std::string& result, | 239 bool DicomValue::CopyToString(std::string& result, |
220 bool allowBinary) const | 240 bool allowBinary) const |
221 { | 241 { |
222 if (IsNull()) | 242 if (IsNull()) |
243 { | |
244 return false; | |
245 } | |
246 else if (IsSequence()) | |
223 { | 247 { |
224 return false; | 248 return false; |
225 } | 249 } |
226 else if (IsBinary() && !allowBinary) | 250 else if (IsBinary() && !allowBinary) |
227 { | 251 { |
261 Toolbox::EncodeBase64(base64, content_); | 285 Toolbox::EncodeBase64(base64, content_); |
262 target[KEY_CONTENT] = base64; | 286 target[KEY_CONTENT] = base64; |
263 break; | 287 break; |
264 } | 288 } |
265 | 289 |
290 case Type_SequenceAsJson: | |
291 { | |
292 throw OrthancException(ErrorCode_NotImplemented); | |
293 } | |
294 | |
266 default: | 295 default: |
267 throw OrthancException(ErrorCode_InternalError); | 296 throw OrthancException(ErrorCode_InternalError); |
268 } | 297 } |
269 } | 298 } |
270 | 299 |
287 type_ = Type_Binary; | 316 type_ = Type_Binary; |
288 | 317 |
289 const std::string base64 =SerializationToolbox::ReadString(source, KEY_CONTENT); | 318 const std::string base64 =SerializationToolbox::ReadString(source, KEY_CONTENT); |
290 Toolbox::DecodeBase64(content_, base64); | 319 Toolbox::DecodeBase64(content_, base64); |
291 } | 320 } |
321 else if (type == "Sequence") | |
322 { | |
323 throw OrthancException(ErrorCode_NotImplemented); | |
324 } | |
292 else | 325 else |
293 { | 326 { |
294 throw OrthancException(ErrorCode_BadFileFormat); | 327 throw OrthancException(ErrorCode_BadFileFormat); |
295 } | 328 } |
296 } | 329 } |