Mercurial > hg > orthanc
annotate OrthancFramework/Sources/SerializationToolbox.cpp @ 4844:55e8fb8e8028
tagging a pre-release of the Orthanc framework for WSI 1.1
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Dec 2021 14:01:17 +0100 |
parents | bec432ee1094 |
children | 43e613a7756b |
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 | |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
4831
7053502fbf97
added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4775
diff
changeset
|
6 * Copyright (C) 2021-2021 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 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
75 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
|
76 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
|
77 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
78 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
|
79 !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
|
80 (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
|
81 value[field.c_str()].type() != Json::uintValue)) |
2656 | 82 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
83 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
|
84 "Integer value expected in field: " + field); |
2656 | 85 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
86 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
87 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
88 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
|
89 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
90 } |
2656 | 91 |
92 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
93 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
|
94 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
|
95 int defaultValue) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
96 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
97 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
|
98 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
99 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
|
100 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
101 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
|
102 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
103 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
|
104 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
105 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
106 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
107 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
108 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
|
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 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
111 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
|
112 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
113 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
|
114 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
115 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
|
116 "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
|
117 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
118 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
119 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
120 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
|
121 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
122 } |
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
|
123 |
09798f2b985f
added a Timeout argument to every DICOM command + 'TargetAet' not mandatory anymore in /retrieve
Alain Mazy <alain@mazy.be>
parents:
3641
diff
changeset
|
124 |
4451
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
125 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
|
126 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
|
127 unsigned int defaultValue) |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
128 { |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
129 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
|
130 { |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
131 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
|
132 } |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
133 else |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
134 { |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
135 return defaultValue; |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
136 } |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
137 } |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
138 |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
139 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
140 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
|
141 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
|
142 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
143 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
|
144 !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
|
145 value[field.c_str()].type() != Json::booleanValue) |
2656 | 146 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
147 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
|
148 "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
|
149 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
150 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
151 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
152 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
|
153 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
154 } |
2656 | 155 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
156 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
157 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
|
158 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
|
159 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
|
160 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
161 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
|
162 !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
|
163 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
|
164 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
165 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
|
166 "List of strings expected in field: " + field); |
2656 | 167 } |
168 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
169 const Json::Value& arr = value[field.c_str()]; |
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 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
|
172 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
173 for (Json::Value::ArrayIndex i = 0; i < arr.size(); i++) |
2656 | 174 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
175 if (arr[i].type() != Json::stringValue) |
2656 | 176 { |
2966 | 177 throw OrthancException(ErrorCode_BadFileFormat, |
178 "List of strings expected in field: " + field); | |
2656 | 179 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
180 else |
2656 | 181 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
182 target[i] = arr[i].asString(); |
2656 | 183 } |
184 } | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
185 } |
2656 | 186 |
187 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
188 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
|
189 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
|
190 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
|
191 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
192 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
|
193 ReadArrayOfStrings(tmp, value, 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 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
196 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
|
197 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
198 target.push_back(tmp[i]); |
2656 | 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::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
|
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); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
209 |
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++) |
2656 | 212 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
213 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
|
214 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
215 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
216 |
2656 | 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::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
|
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 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
|
223 !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
|
224 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
|
225 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
226 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
|
227 "Set of DICOM tags expected in field: " + field); |
2656 | 228 } |
229 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
230 const Json::Value& arr = value[field.c_str()]; |
2656 | 231 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
232 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
233 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
234 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
|
235 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
236 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
|
237 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
238 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
|
239 !ParseTagInternal(tag, arr[i].asCString())) |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
240 { |
2966 | 241 throw OrthancException(ErrorCode_BadFileFormat, |
242 "Set of DICOM tags expected in field: " + field); | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
243 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
244 else |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
245 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
246 target.insert(tag); |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
247 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
248 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
249 } |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
250 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
251 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
252 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
|
253 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
|
254 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
|
255 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
256 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
|
257 !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
|
258 value[field.c_str()].type() != Json::objectValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
259 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
260 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
|
261 "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
|
262 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
263 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
264 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
|
265 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
266 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
267 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
268 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
|
269 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
270 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
|
271 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
272 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
|
273 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
274 if (tmp.type() != Json::stringValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
275 { |
2966 | 276 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
|
277 "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
|
278 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
279 else |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
280 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
281 target[members[i]] = tmp.asString(); |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
282 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
283 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
284 } |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
285 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
286 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
287 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
|
288 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
|
289 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
|
290 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
291 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
|
292 !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
|
293 value[field.c_str()].type() != Json::objectValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
294 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
295 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
|
296 "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
|
297 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
298 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
299 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
|
300 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
301 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
302 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
303 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
|
304 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
305 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
|
306 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
307 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
|
308 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
309 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
|
310 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
311 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
|
312 tmp.type() != Json::stringValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
313 { |
2966 | 314 throw OrthancException(ErrorCode_BadFileFormat, |
315 "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
|
316 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
317 else |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
318 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
319 target[tag] = tmp.asString(); |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
320 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
321 } |
2656 | 322 } |
3991
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 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
329 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
|
330 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
|
331 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
332 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
|
333 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
334 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
335 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
|
336 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
337 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
|
338 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
|
339 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
340 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
|
341 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
342 } |
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 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
345 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
|
346 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
|
347 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
|
348 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
349 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
|
350 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
|
351 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
352 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
|
353 } |
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 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
|
356 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
357 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
|
358 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
359 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
|
360 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
|
361 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
362 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
|
363 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
364 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
365 |
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 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
|
368 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
|
369 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
|
370 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
371 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
|
372 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
|
373 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
374 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
|
375 } |
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 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
|
378 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
379 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
|
380 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
381 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
|
382 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
|
383 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
384 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
|
385 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
386 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
387 |
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 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
|
390 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
|
391 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
|
392 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
393 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
|
394 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
|
395 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
396 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
|
397 } |
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 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
|
400 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
401 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
|
402 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
403 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
|
404 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
|
405 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
406 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
|
407 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
408 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
409 |
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 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
|
412 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
|
413 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
|
414 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
415 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
|
416 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
|
417 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
418 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
|
419 } |
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 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
|
422 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
423 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
|
424 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
425 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
|
426 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
|
427 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
428 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
|
429 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
430 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
431 |
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 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
|
434 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
|
435 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
|
436 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
437 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
|
438 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
|
439 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
440 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
|
441 } |
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 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
|
444 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
445 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
|
446 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
447 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
|
448 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
|
449 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
450 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
|
451 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
452 } |
4775
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
453 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
454 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
455 template <typename T, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
456 bool allowSigned> |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
457 static bool ParseValue(T& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
458 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
459 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
460 try |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
461 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
462 std::string value = Toolbox::StripSpaces(source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
463 if (value.empty()) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
464 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
465 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
466 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
467 else if (!allowSigned && |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
468 value[0] == '-') |
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 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
471 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
472 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
473 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
474 target = boost::lexical_cast<T>(value); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
475 return true; |
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 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
478 catch (boost::bad_lexical_cast&) |
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 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
483 |
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 bool SerializationToolbox::ParseInteger32(int32_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
486 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
487 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
488 int64_t tmp; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
489 if (ParseValue<int64_t, true>(tmp, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
490 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
491 target = static_cast<int32_t>(tmp); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
492 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
|
493 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
494 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
495 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
496 return false; |
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 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
501 bool SerializationToolbox::ParseInteger64(int64_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
502 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
503 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
504 return ParseValue<int64_t, true>(target, 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 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
507 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
508 bool SerializationToolbox::ParseUnsignedInteger32(uint32_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
509 const std::string& source) |
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 uint64_t tmp; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
512 if (ParseValue<uint64_t, false>(tmp, source)) |
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 target = static_cast<uint32_t>(tmp); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
515 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
|
516 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
517 else |
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 false; |
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 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
524 bool SerializationToolbox::ParseUnsignedInteger64(uint64_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
525 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
526 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
527 return ParseValue<uint64_t, false>(target, 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 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
530 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
531 bool SerializationToolbox::ParseFloat(float& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
532 const std::string& source) |
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 ParseValue<float, true>(target, source); |
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 bool SerializationToolbox::ParseDouble(double& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
539 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
540 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
541 return ParseValue<double, true>(target, source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
542 } |
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 static bool GetFirstItem(std::string& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
546 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
547 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
548 std::vector<std::string> tokens; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
549 Toolbox::TokenizeString(tokens, 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 if (tokens.empty()) |
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 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
554 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
555 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
556 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
557 target = tokens[0]; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
558 return true; |
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 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
561 |
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 bool SerializationToolbox::ParseFirstInteger32(int32_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
564 const std::string& 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 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
567 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
568 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
569 return ParseInteger32(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
570 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
571 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
572 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
573 return false; |
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::ParseFirstInteger64(int64_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 ParseInteger64(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::ParseFirstUnsignedInteger32(uint32_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 ParseUnsignedInteger32(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::ParseFirstUnsignedInteger64(uint64_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 ParseUnsignedInteger64(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::ParseFirstFloat(float& 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 ParseFloat(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::ParseFirstDouble(double& 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 ParseDouble(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 } |
4834
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
651 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
652 |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
653 bool SerializationToolbox::ParseBoolean(bool& result, |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
654 const std::string& value) |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
655 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
656 if (value == "0" || |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
657 value == "false") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
658 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
659 result = false; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
660 return true; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
661 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
662 else if (value == "1" || |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
663 value == "true") |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
664 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
665 result = true; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
666 return true; |
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 else |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
669 { |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
670 return false; |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
671 } |
bec432ee1094
download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
672 } |
2656 | 673 } |