Mercurial > hg > orthanc
annotate OrthancFramework/Sources/SerializationToolbox.cpp @ 5278:ed7257b61bd7
back to mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 Apr 2023 17:43:54 +0200 |
parents | f783b99e4738 |
children | b31c73bc7cb6 |
rev | line source |
---|---|
2656 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2656 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * the License, or (at your option) any later version. |
2656 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
16 * Lesser General Public License for more details. |
2656 | 17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
2656 | 21 **/ |
22 | |
23 | |
24 #include "PrecompiledHeaders.h" | |
25 #include "SerializationToolbox.h" | |
26 | |
27 #include "OrthancException.h" | |
4775
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
28 #include "Toolbox.h" |
2656 | 29 |
2982
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
30 #if ORTHANC_ENABLE_DCMTK == 1 |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
31 # include "DicomParsing/FromDcmtkBridge.h" |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
32 #endif |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
33 |
4775
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
34 #include <boost/lexical_cast.hpp> |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
35 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
36 |
2656 | 37 namespace Orthanc |
38 { | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
39 static bool ParseTagInternal(DicomTag& tag, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
40 const char* name) |
2656 | 41 { |
2982
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
42 #if ORTHANC_ENABLE_DCMTK == 1 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
43 try |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
44 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
45 tag = FromDcmtkBridge::ParseTag(name); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
46 return true; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
47 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
48 catch (OrthancException&) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
49 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
50 return false; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
51 } |
2982
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
52 #else |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
53 return DicomTag::ParseHexadecimal(tag, name); |
2982
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
54 #endif |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
55 } |
2982
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
56 |
94c8222c52b7
New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
57 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
58 std::string SerializationToolbox::ReadString(const Json::Value& value, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
59 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
60 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
61 if (value.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
62 !value.isMember(field.c_str()) || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
63 value[field.c_str()].type() != Json::stringValue) |
2656 | 64 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
65 throw OrthancException(ErrorCode_BadFileFormat, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
66 "String value expected in field: " + field); |
2656 | 67 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
68 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
69 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
70 return value[field.c_str()].asString(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
71 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
72 } |
2656 | 73 |
74 | |
5255 | 75 std::string SerializationToolbox::ReadString(const Json::Value& value, |
76 const std::string& field, | |
77 const std::string& defaultValue) | |
78 { | |
79 if (value.isMember(field.c_str())) | |
80 { | |
81 return ReadString(value, field); | |
82 } | |
83 else | |
84 { | |
85 return defaultValue; | |
86 } | |
87 } | |
88 | |
89 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
90 int SerializationToolbox::ReadInteger(const Json::Value& value, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
91 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
92 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
93 if (value.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
94 !value.isMember(field.c_str()) || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
95 (value[field.c_str()].type() != Json::intValue && |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
96 value[field.c_str()].type() != Json::uintValue)) |
2656 | 97 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
98 throw OrthancException(ErrorCode_BadFileFormat, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
99 "Integer value expected in field: " + field); |
2656 | 100 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
101 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
102 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
103 return value[field.c_str()].asInt(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
104 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
105 } |
2656 | 106 |
107 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
108 int SerializationToolbox::ReadInteger(const Json::Value& value, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
109 const std::string& field, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
110 int defaultValue) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
111 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
112 if (value.isMember(field.c_str())) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
113 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
114 return ReadInteger(value, field); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
115 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
116 else |
3870
09798f2b985f
added a Timeout argument to every DICOM command + 'TargetAet' not mandatory anymore in /retrieve
Alain Mazy <alain@mazy.be>
parents:
3641
diff
changeset
|
117 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
118 return defaultValue; |
3870
09798f2b985f
added a Timeout argument to every DICOM command + 'TargetAet' not mandatory anymore in /retrieve
Alain Mazy <alain@mazy.be>
parents:
3641
diff
changeset
|
119 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
120 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
121 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
122 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
123 unsigned int SerializationToolbox::ReadUnsignedInteger(const Json::Value& value, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
124 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
125 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
126 int tmp = ReadInteger(value, field); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
127 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
128 if (tmp < 0) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
129 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
130 throw OrthancException(ErrorCode_BadFileFormat, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
131 "Unsigned integer value expected in field: " + field); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
132 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
133 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
134 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
135 return static_cast<unsigned int>(tmp); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
136 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
137 } |
3870
09798f2b985f
added a Timeout argument to every DICOM command + 'TargetAet' not mandatory anymore in /retrieve
Alain Mazy <alain@mazy.be>
parents:
3641
diff
changeset
|
138 |
09798f2b985f
added a Timeout argument to every DICOM command + 'TargetAet' not mandatory anymore in /retrieve
Alain Mazy <alain@mazy.be>
parents:
3641
diff
changeset
|
139 |
4451
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
140 unsigned int SerializationToolbox::ReadUnsignedInteger(const Json::Value& value, |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
141 const std::string& field, |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
142 unsigned int defaultValue) |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
143 { |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
144 if (value.isMember(field.c_str())) |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
145 { |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
146 return ReadUnsignedInteger(value, field); |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
147 } |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
148 else |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
149 { |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
150 return defaultValue; |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
151 } |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
152 } |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
153 |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
154 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
155 bool SerializationToolbox::ReadBoolean(const Json::Value& value, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
156 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
157 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
158 if (value.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
159 !value.isMember(field.c_str()) || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
160 value[field.c_str()].type() != Json::booleanValue) |
2656 | 161 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
162 throw OrthancException(ErrorCode_BadFileFormat, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
163 "Boolean value expected in field: " + field); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
164 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
165 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
166 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
167 return value[field.c_str()].asBool(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
168 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
169 } |
2656 | 170 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
171 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
172 void SerializationToolbox::ReadArrayOfStrings(std::vector<std::string>& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
173 const Json::Value& value, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
174 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
175 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
176 if (value.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
177 !value.isMember(field.c_str()) || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
178 value[field.c_str()].type() != Json::arrayValue) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
179 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
180 throw OrthancException(ErrorCode_BadFileFormat, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
181 "List of strings expected in field: " + field); |
2656 | 182 } |
183 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
184 const Json::Value& arr = value[field.c_str()]; |
2656 | 185 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
186 target.resize(arr.size()); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
187 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
188 for (Json::Value::ArrayIndex i = 0; i < arr.size(); i++) |
2656 | 189 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
190 if (arr[i].type() != Json::stringValue) |
2656 | 191 { |
2966 | 192 throw OrthancException(ErrorCode_BadFileFormat, |
193 "List of strings expected in field: " + field); | |
2656 | 194 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
195 else |
2656 | 196 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
197 target[i] = arr[i].asString(); |
2656 | 198 } |
199 } | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
200 } |
2656 | 201 |
202 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
203 void SerializationToolbox::ReadListOfStrings(std::list<std::string>& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
204 const Json::Value& value, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
205 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
206 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
207 std::vector<std::string> tmp; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
208 ReadArrayOfStrings(tmp, value, field); |
2656 | 209 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
210 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
211 for (size_t i = 0; i < tmp.size(); i++) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
212 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
213 target.push_back(tmp[i]); |
2656 | 214 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
215 } |
2656 | 216 |
217 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
218 void SerializationToolbox::ReadSetOfStrings(std::set<std::string>& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
219 const Json::Value& value, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
220 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
221 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
222 std::vector<std::string> tmp; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
223 ReadArrayOfStrings(tmp, value, field); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
224 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
225 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
226 for (size_t i = 0; i < tmp.size(); i++) |
2656 | 227 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
228 target.insert(tmp[i]); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
229 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
230 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
231 |
2656 | 232 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
233 void SerializationToolbox::ReadSetOfTags(std::set<DicomTag>& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
234 const Json::Value& value, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
235 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
236 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
237 if (value.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
238 !value.isMember(field.c_str()) || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
239 value[field.c_str()].type() != Json::arrayValue) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
240 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
241 throw OrthancException(ErrorCode_BadFileFormat, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
242 "Set of DICOM tags expected in field: " + field); |
2656 | 243 } |
244 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
245 const Json::Value& arr = value[field.c_str()]; |
2656 | 246 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
247 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
248 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
249 for (Json::Value::ArrayIndex i = 0; i < arr.size(); i++) |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
250 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
251 DicomTag tag(0, 0); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
252 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
253 if (arr[i].type() != Json::stringValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
254 !ParseTagInternal(tag, arr[i].asCString())) |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
255 { |
2966 | 256 throw OrthancException(ErrorCode_BadFileFormat, |
257 "Set of DICOM tags expected in field: " + field); | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
258 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
259 else |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
260 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
261 target.insert(tag); |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
262 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
263 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
264 } |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
265 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
266 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
267 void SerializationToolbox::ReadMapOfStrings(std::map<std::string, std::string>& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
268 const Json::Value& value, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
269 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
270 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
271 if (value.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
272 !value.isMember(field.c_str()) || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
273 value[field.c_str()].type() != Json::objectValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
274 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
275 throw OrthancException(ErrorCode_BadFileFormat, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
276 "Associative array of strings to strings expected in field: " + field); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
277 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
278 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
279 const Json::Value& source = value[field.c_str()]; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
280 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
281 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
282 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
283 Json::Value::Members members = source.getMemberNames(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
284 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
285 for (size_t i = 0; i < members.size(); i++) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
286 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
287 const Json::Value& tmp = source[members[i]]; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
288 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
289 if (tmp.type() != Json::stringValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
290 { |
2966 | 291 throw OrthancException(ErrorCode_BadFileFormat, |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
292 "Associative array of string to strings expected in field: " + field); |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
293 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
294 else |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
295 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
296 target[members[i]] = tmp.asString(); |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
297 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
298 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
299 } |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
300 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
301 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
302 void SerializationToolbox::ReadMapOfTags(std::map<DicomTag, std::string>& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
303 const Json::Value& value, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
304 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
305 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
306 if (value.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
307 !value.isMember(field.c_str()) || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
308 value[field.c_str()].type() != Json::objectValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
309 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
310 throw OrthancException(ErrorCode_BadFileFormat, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
311 "Associative array of DICOM tags to strings expected in field: " + field); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
312 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
313 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
314 const Json::Value& source = value[field.c_str()]; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
315 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
316 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
317 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
318 Json::Value::Members members = source.getMemberNames(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
319 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
320 for (size_t i = 0; i < members.size(); i++) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
321 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
322 const Json::Value& tmp = source[members[i]]; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
323 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
324 DicomTag tag(0, 0); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
325 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
326 if (!ParseTagInternal(tag, members[i].c_str()) || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
327 tmp.type() != Json::stringValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
328 { |
2966 | 329 throw OrthancException(ErrorCode_BadFileFormat, |
330 "Associative array of DICOM tags to strings expected in field: " + field); | |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
331 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
332 else |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
333 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
334 target[tag] = tmp.asString(); |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
335 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
336 } |
2656 | 337 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
338 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
339 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
340 void SerializationToolbox::WriteArrayOfStrings(Json::Value& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
341 const std::vector<std::string>& values, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
342 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
343 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
344 if (target.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
345 target.isMember(field.c_str())) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
346 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
347 throw OrthancException(ErrorCode_BadFileFormat); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
348 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
349 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
350 Json::Value& value = target[field]; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
351 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
352 value = Json::arrayValue; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
353 for (size_t i = 0; i < values.size(); i++) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
354 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
355 value.append(values[i]); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
356 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
357 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
358 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
359 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
360 void SerializationToolbox::WriteListOfStrings(Json::Value& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
361 const std::list<std::string>& values, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
362 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
363 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
364 if (target.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
365 target.isMember(field.c_str())) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
366 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
367 throw OrthancException(ErrorCode_BadFileFormat); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
368 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
369 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
370 Json::Value& value = target[field]; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
371 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
372 value = Json::arrayValue; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
373 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
374 for (std::list<std::string>::const_iterator it = values.begin(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
375 it != values.end(); ++it) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
376 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
377 value.append(*it); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
378 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
379 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
380 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
381 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
382 void SerializationToolbox::WriteSetOfStrings(Json::Value& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
383 const std::set<std::string>& values, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
384 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
385 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
386 if (target.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
387 target.isMember(field.c_str())) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
388 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
389 throw OrthancException(ErrorCode_BadFileFormat); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
390 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
391 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
392 Json::Value& value = target[field]; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
393 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
394 value = Json::arrayValue; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
395 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
396 for (std::set<std::string>::const_iterator it = values.begin(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
397 it != values.end(); ++it) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
398 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
399 value.append(*it); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
400 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
401 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
402 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
403 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
404 void SerializationToolbox::WriteSetOfTags(Json::Value& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
405 const std::set<DicomTag>& tags, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
406 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
407 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
408 if (target.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
409 target.isMember(field.c_str())) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
410 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
411 throw OrthancException(ErrorCode_BadFileFormat); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
412 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
413 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
414 Json::Value& value = target[field]; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
415 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
416 value = Json::arrayValue; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
417 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
418 for (std::set<DicomTag>::const_iterator it = tags.begin(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
419 it != tags.end(); ++it) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
420 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
421 value.append(it->Format()); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
422 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
423 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
424 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
425 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
426 void SerializationToolbox::WriteMapOfStrings(Json::Value& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
427 const std::map<std::string, std::string>& values, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
428 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
429 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
430 if (target.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
431 target.isMember(field.c_str())) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
432 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
433 throw OrthancException(ErrorCode_BadFileFormat); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
434 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
435 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
436 Json::Value& value = target[field]; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
437 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
438 value = Json::objectValue; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
439 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
440 for (std::map<std::string, std::string>::const_iterator |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
441 it = values.begin(); it != values.end(); ++it) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
442 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
443 value[it->first] = it->second; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
444 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
445 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
446 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
447 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
448 void SerializationToolbox::WriteMapOfTags(Json::Value& target, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
449 const std::map<DicomTag, std::string>& values, |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
450 const std::string& field) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
451 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
452 if (target.type() != Json::objectValue || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
453 target.isMember(field.c_str())) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
454 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
455 throw OrthancException(ErrorCode_BadFileFormat); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
456 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
457 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
458 Json::Value& value = target[field]; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
459 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
460 value = Json::objectValue; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
461 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
462 for (std::map<DicomTag, std::string>::const_iterator |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
463 it = values.begin(); it != values.end(); ++it) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
464 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
465 value[it->first.Format()] = it->second; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
466 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
467 } |
4775
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
468 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
469 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
470 template <typename T, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
471 bool allowSigned> |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
472 static bool ParseValue(T& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
473 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
474 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
475 try |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
476 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
477 std::string value = Toolbox::StripSpaces(source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
478 if (value.empty()) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
479 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
480 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
481 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
482 else if (!allowSigned && |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
483 value[0] == '-') |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
484 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
485 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
486 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
487 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
488 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
489 target = boost::lexical_cast<T>(value); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
490 return true; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
491 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
492 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
493 catch (boost::bad_lexical_cast&) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
494 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
495 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
496 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
497 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
498 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
499 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
500 bool SerializationToolbox::ParseInteger32(int32_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
501 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
502 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
503 int64_t tmp; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
504 if (ParseValue<int64_t, true>(tmp, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
505 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
506 target = static_cast<int32_t>(tmp); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
507 return (tmp == static_cast<int64_t>(target)); // Check no overflow occurs |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
508 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
509 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
510 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
511 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
512 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
513 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
514 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
515 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
516 bool SerializationToolbox::ParseInteger64(int64_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
517 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
518 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
519 return ParseValue<int64_t, true>(target, source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
520 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
521 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
522 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
523 bool SerializationToolbox::ParseUnsignedInteger32(uint32_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
524 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
525 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
526 uint64_t tmp; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
527 if (ParseValue<uint64_t, false>(tmp, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
528 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
529 target = static_cast<uint32_t>(tmp); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
530 return (tmp == static_cast<uint64_t>(target)); // Check no overflow occurs |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
531 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
532 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
533 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
534 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
535 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
536 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
537 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
538 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
539 bool SerializationToolbox::ParseUnsignedInteger64(uint64_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
540 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
541 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
542 return ParseValue<uint64_t, false>(target, source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
543 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
544 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
545 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
546 bool SerializationToolbox::ParseFloat(float& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
547 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
548 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
549 return ParseValue<float, true>(target, source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
550 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
551 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
552 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
553 bool SerializationToolbox::ParseDouble(double& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
554 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
555 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
556 return ParseValue<double, true>(target, source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
557 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
558 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
559 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
560 static bool GetFirstItem(std::string& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
561 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
562 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
563 std::vector<std::string> tokens; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
564 Toolbox::TokenizeString(tokens, source, '\\'); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
565 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
566 if (tokens.empty()) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
567 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
568 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
569 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
570 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
571 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
572 target = tokens[0]; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
573 return true; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
574 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
575 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
576 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
577 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
578 bool SerializationToolbox::ParseFirstInteger32(int32_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
579 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
580 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
581 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
582 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
583 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
584 return ParseInteger32(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
585 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
586 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
587 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
588 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
589 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
590 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
591 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
592 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
593 bool SerializationToolbox::ParseFirstInteger64(int64_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
594 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
595 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
596 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
597 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
598 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
599 return ParseInteger64(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
600 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
601 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
602 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
603 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
604 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
605 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
606 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
607 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
608 bool SerializationToolbox::ParseFirstUnsignedInteger32(uint32_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
609 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
610 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
611 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
612 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
613 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
614 return ParseUnsignedInteger32(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
615 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
616 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
617 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
618 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
619 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
620 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
621 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
622 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
623 bool SerializationToolbox::ParseFirstUnsignedInteger64(uint64_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
624 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
625 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
626 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
627 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
628 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
629 return ParseUnsignedInteger64(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
630 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
631 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
632 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
633 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
634 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
635 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
636 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
637 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
638 bool SerializationToolbox::ParseFirstFloat(float& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
639 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
640 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
641 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
642 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
643 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
644 return ParseFloat(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
645 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
646 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
647 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
648 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
649 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
650 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
651 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
652 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
653 bool SerializationToolbox::ParseFirstDouble(double& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
654 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
655 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
656 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
657 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
658 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
659 return ParseDouble(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
660 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
661 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
662 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
663 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
664 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
665 } |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
666 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
667 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
668 bool SerializationToolbox::ParseBoolean(bool& result, |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
669 const std::string& value) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
670 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
671 if (value == "0" || |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
672 value == "false") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
673 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
674 result = false; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
675 return true; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
676 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
677 else if (value == "1" || |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
678 value == "true") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
679 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
680 result = true; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
681 return true; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
682 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
683 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
684 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
685 return false; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
686 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
687 } |
2656 | 688 } |