Mercurial > hg > orthanc
annotate Core/DicomFormat/DicomValue.cpp @ 3853:ba53d51ffa9a
leaving bitbucket
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 20 Apr 2020 18:13:31 +0200 |
parents | a9ce35d67c3c |
children |
rev | line source |
---|---|
1738
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1738
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3519
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
1738
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 **/ |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "../PrecompiledHeaders.h" |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "DicomValue.h" |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 #include "../OrthancException.h" |
2863
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
38 #include "../SerializationToolbox.h" |
1738
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 #include "../Toolbox.h" |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
2410
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
41 #include <boost/lexical_cast.hpp> |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
42 |
1738
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 namespace Orthanc |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 { |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 DicomValue::DicomValue(const DicomValue& other) : |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 type_(other.type_), |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 content_(other.content_) |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 { |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 } |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 DicomValue::DicomValue(const std::string& content, |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 bool isBinary) : |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 type_(isBinary ? Type_Binary : Type_String), |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 content_(content) |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 { |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 } |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 DicomValue::DicomValue(const char* data, |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 size_t size, |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 bool isBinary) : |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 type_(isBinary ? Type_Binary : Type_String) |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 { |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 content_.assign(data, size); |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 } |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 const std::string& DicomValue::GetContent() const |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 { |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 if (type_ == Type_Null) |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 { |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 throw OrthancException(ErrorCode_BadParameterType); |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 } |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 else |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 { |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 return content_; |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 } |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 } |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 DicomValue* DicomValue::Clone() const |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 { |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 return new DicomValue(*this); |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 } |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 |
2139 | 88 #if ORTHANC_ENABLE_BASE64 == 1 |
1738
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 void DicomValue::FormatDataUriScheme(std::string& target, |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 const std::string& mime) const |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 { |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 Toolbox::EncodeBase64(target, GetContent()); |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 target.insert(0, "data:" + mime + ";base64,"); |
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 } |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1738
diff
changeset
|
95 #endif |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1738
diff
changeset
|
96 |
3519
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
97 // same as ParseValue but in case the value actually contains a sequence, |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
98 // it will return the first value |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
99 // this has been introduced to support invalid "width/height" DICOM tags in some US |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
100 // images where the width is stored as "800\0" ! |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
101 template <typename T, |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
102 bool allowSigned> |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
103 static bool ParseFirstValue(T& result, |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
104 const DicomValue& source) |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
105 { |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
106 if (source.IsBinary() || |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
107 source.IsNull()) |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
108 { |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
109 return false; |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
110 } |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
111 |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
112 try |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
113 { |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
114 std::string value = Toolbox::StripSpaces(source.GetContent()); |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
115 if (value.empty()) |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
116 { |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
117 return false; |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
118 } |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
119 |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
120 if (!allowSigned && |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
121 value[0] == '-') |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
122 { |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
123 return false; |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
124 } |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
125 |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
126 if (value.find("\\") == std::string::npos) |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
127 { |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
128 result = boost::lexical_cast<T>(value); |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
129 return true; |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
130 } |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
131 else |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
132 { |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
133 std::vector<std::string> tokens; |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
134 Toolbox::TokenizeString(tokens, value, '\\'); |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
135 |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
136 if (tokens.size() >= 1) |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
137 { |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
138 result = boost::lexical_cast<T>(tokens[0]); |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
139 return true; |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
140 } |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
141 |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
142 return false; |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
143 } |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
144 } |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
145 catch (boost::bad_lexical_cast&) |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
146 { |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
147 return false; |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
148 } |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
149 } |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
150 |
2410
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
151 |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
152 template <typename T, |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
153 bool allowSigned> |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
154 static bool ParseValue(T& result, |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
155 const DicomValue& source) |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
156 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
157 if (source.IsBinary() || |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
158 source.IsNull()) |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
159 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
160 return false; |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
161 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
162 |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
163 try |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
164 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
165 std::string value = Toolbox::StripSpaces(source.GetContent()); |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
166 if (value.empty()) |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
167 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
168 return false; |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
169 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
170 |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
171 if (!allowSigned && |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
172 value[0] == '-') |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
173 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
174 return false; |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
175 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
176 |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
177 result = boost::lexical_cast<T>(value); |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
178 return true; |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
179 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
180 catch (boost::bad_lexical_cast&) |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
181 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
182 return false; |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
183 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
184 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
185 |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
186 bool DicomValue::ParseInteger32(int32_t& result) const |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
187 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
188 int64_t tmp; |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
189 if (ParseValue<int64_t, true>(tmp, *this)) |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
190 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
191 result = static_cast<int32_t>(tmp); |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
192 return (tmp == static_cast<int64_t>(result)); // Check no overflow occurs |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
193 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
194 else |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
195 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
196 return false; |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
197 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
198 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
199 |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
200 bool DicomValue::ParseInteger64(int64_t& result) const |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
201 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
202 return ParseValue<int64_t, true>(result, *this); |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
203 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
204 |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
205 bool DicomValue::ParseUnsignedInteger32(uint32_t& result) const |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
206 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
207 uint64_t tmp; |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
208 if (ParseValue<uint64_t, false>(tmp, *this)) |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
209 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
210 result = static_cast<uint32_t>(tmp); |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
211 return (tmp == static_cast<uint64_t>(result)); // Check no overflow occurs |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
212 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
213 else |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
214 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
215 return false; |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
216 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
217 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
218 |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
219 bool DicomValue::ParseUnsignedInteger64(uint64_t& result) const |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
220 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
221 return ParseValue<uint64_t, false>(result, *this); |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
222 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
223 |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
224 bool DicomValue::ParseFloat(float& result) const |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
225 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
226 return ParseValue<float, true>(result, *this); |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
227 } |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
228 |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
229 bool DicomValue::ParseDouble(double& result) const |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
230 { |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
231 return ParseValue<double, true>(result, *this); |
3590c936e56f
parsing numbers in DicomValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
232 } |
2412
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
233 |
3690
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
234 bool DicomValue::ParseFirstFloat(float& result) const |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
235 { |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
236 return ParseFirstValue<float, true>(result, *this); |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
237 } |
a9ce35d67c3c
implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
238 |
3519
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
239 bool DicomValue::ParseFirstUnsignedInteger(unsigned int& result) const |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
240 { |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
241 return ParseFirstValue<unsigned int, true>(result, *this); |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
242 } |
fc26659493b6
added support for COLUMNS/ROWS tags with invalid 800\0 value observed in some US images
amazy
parents:
3060
diff
changeset
|
243 |
2412
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
244 bool DicomValue::CopyToString(std::string& result, |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
245 bool allowBinary) const |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
246 { |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
247 if (IsNull()) |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
248 { |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
249 return false; |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
250 } |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
251 else if (IsBinary() && !allowBinary) |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
252 { |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
253 return false; |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
254 } |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
255 else |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
256 { |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
257 result.assign(content_); |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
258 return true; |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
259 } |
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2410
diff
changeset
|
260 } |
2863
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
261 |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
262 |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
263 static const char* KEY_TYPE = "Type"; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
264 static const char* KEY_CONTENT = "Content"; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
265 |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
266 void DicomValue::Serialize(Json::Value& target) const |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
267 { |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
268 target = Json::objectValue; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
269 |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
270 switch (type_) |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
271 { |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
272 case Type_Null: |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
273 target[KEY_TYPE] = "Null"; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
274 break; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
275 |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
276 case Type_String: |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
277 target[KEY_TYPE] = "String"; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
278 target[KEY_CONTENT] = content_; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
279 break; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
280 |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
281 case Type_Binary: |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
282 { |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
283 target[KEY_TYPE] = "Binary"; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
284 |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
285 std::string base64; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
286 Toolbox::EncodeBase64(base64, content_); |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
287 target[KEY_CONTENT] = base64; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
288 break; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
289 } |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
290 |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
291 default: |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
292 throw OrthancException(ErrorCode_InternalError); |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
293 } |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
294 } |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
295 |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
296 void DicomValue::Unserialize(const Json::Value& source) |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
297 { |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
298 std::string type = SerializationToolbox::ReadString(source, KEY_TYPE); |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
299 |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
300 if (type == "Null") |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
301 { |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
302 type_ = Type_Null; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
303 content_.clear(); |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
304 } |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
305 else if (type == "String") |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
306 { |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
307 type_ = Type_String; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
308 content_ = SerializationToolbox::ReadString(source, KEY_CONTENT); |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
309 } |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
310 else if (type == "Binary") |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
311 { |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
312 type_ = Type_Binary; |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
313 |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
314 const std::string base64 =SerializationToolbox::ReadString(source, KEY_CONTENT); |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
315 Toolbox::DecodeBase64(content_, base64); |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
316 } |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
317 else |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
318 { |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
319 throw OrthancException(ErrorCode_BadFileFormat); |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
320 } |
da12ba232119
serialization of DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
321 } |
1738
15a788a63846
DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 } |