Mercurial > hg > orthanc
annotate OrthancFramework/Sources/SerializationToolbox.cpp @ 4802:6a23cd1fc66b
fix news
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 19 Oct 2021 17:00:23 +0200 |
parents | add0337b928a |
children | 7053502fbf97 |
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 |
2656 | 6 * |
7 * 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
|
8 * 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
|
9 * 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
|
10 * the License, or (at your option) any later version. |
2656 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * 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
|
15 * Lesser General Public License for more details. |
2656 | 16 * |
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
|
17 * 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
|
18 * 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
|
19 * <http://www.gnu.org/licenses/>. |
2656 | 20 **/ |
21 | |
22 | |
23 #include "PrecompiledHeaders.h" | |
24 #include "SerializationToolbox.h" | |
25 | |
26 #include "OrthancException.h" | |
4775
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
27 #include "Toolbox.h" |
2656 | 28 |
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
|
29 #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
|
30 # 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
|
31 #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
|
32 |
4775
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
33 #include <boost/lexical_cast.hpp> |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
34 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
35 |
2656 | 36 namespace Orthanc |
37 { | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
38 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
|
39 const char* name) |
2656 | 40 { |
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
|
41 #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
|
42 try |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
43 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
44 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
|
45 return true; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
46 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
47 catch (OrthancException&) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
48 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
49 return false; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
50 } |
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
|
51 #else |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
52 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
|
53 #endif |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
54 } |
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
|
55 |
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 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
57 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
|
58 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
|
59 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
60 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
|
61 !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
|
62 value[field.c_str()].type() != Json::stringValue) |
2656 | 63 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
64 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
|
65 "String value expected in field: " + field); |
2656 | 66 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
67 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
68 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
69 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
|
70 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
71 } |
2656 | 72 |
73 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
74 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
|
75 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
|
76 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
77 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
|
78 !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
|
79 (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
|
80 value[field.c_str()].type() != Json::uintValue)) |
2656 | 81 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
82 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
|
83 "Integer value expected in field: " + field); |
2656 | 84 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
85 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
86 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
87 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
|
88 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
89 } |
2656 | 90 |
91 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
92 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
|
93 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
|
94 int defaultValue) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
95 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
96 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
|
97 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
98 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
|
99 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
100 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
|
101 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
102 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
|
103 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
104 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
105 |
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 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
|
108 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
|
109 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
110 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
|
111 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
112 if (tmp < 0) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
113 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
114 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
|
115 "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
|
116 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
117 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
118 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
119 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
|
120 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
121 } |
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
|
122 |
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 |
4451
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
124 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
|
125 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
|
126 unsigned int defaultValue) |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
127 { |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
128 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
|
129 { |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
130 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
|
131 } |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
132 else |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
133 { |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
134 return defaultValue; |
f4dbdb2dcba6
new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
135 } |
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 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
139 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
|
140 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
|
141 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
142 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
|
143 !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
|
144 value[field.c_str()].type() != Json::booleanValue) |
2656 | 145 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
146 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
|
147 "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
|
148 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
149 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
150 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
151 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
|
152 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
153 } |
2656 | 154 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
155 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
160 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
|
161 !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
|
162 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
|
163 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
164 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
|
165 "List of strings expected in field: " + field); |
2656 | 166 } |
167 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
168 const Json::Value& arr = value[field.c_str()]; |
2656 | 169 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
170 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
|
171 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
172 for (Json::Value::ArrayIndex i = 0; i < arr.size(); i++) |
2656 | 173 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
174 if (arr[i].type() != Json::stringValue) |
2656 | 175 { |
2966 | 176 throw OrthancException(ErrorCode_BadFileFormat, |
177 "List of strings expected in field: " + field); | |
2656 | 178 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
179 else |
2656 | 180 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
181 target[i] = arr[i].asString(); |
2656 | 182 } |
183 } | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
184 } |
2656 | 185 |
186 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
191 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
|
192 ReadArrayOfStrings(tmp, value, field); |
2656 | 193 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
194 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
195 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
|
196 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
197 target.push_back(tmp[i]); |
2656 | 198 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
199 } |
2656 | 200 |
201 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
206 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
|
207 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
|
208 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
209 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
210 for (size_t i = 0; i < tmp.size(); i++) |
2656 | 211 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
212 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
|
213 } |
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 |
2656 | 216 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
221 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
|
222 !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
|
223 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
|
224 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
225 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
|
226 "Set of DICOM tags expected in field: " + field); |
2656 | 227 } |
228 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
229 const Json::Value& arr = value[field.c_str()]; |
2656 | 230 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
231 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
232 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
233 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
|
234 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
235 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
|
236 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
237 if (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
|
238 !ParseTagInternal(tag, arr[i].asCString())) |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
239 { |
2966 | 240 throw OrthancException(ErrorCode_BadFileFormat, |
241 "Set of DICOM tags expected in field: " + field); | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
242 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
243 else |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
244 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
245 target.insert(tag); |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
246 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
247 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
248 } |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
249 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
250 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
251 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
|
252 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
|
253 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
|
254 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
255 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
|
256 !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
|
257 value[field.c_str()].type() != Json::objectValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
258 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
259 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
|
260 "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
|
261 } |
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 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
|
264 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
265 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
266 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
267 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
|
268 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
269 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
|
270 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
271 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
|
272 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
273 if (tmp.type() != Json::stringValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
274 { |
2966 | 275 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
|
276 "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
|
277 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
278 else |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
279 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
280 target[members[i]] = tmp.asString(); |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
281 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
282 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
283 } |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
284 |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
285 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
286 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
|
287 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
|
288 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
|
289 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
290 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
|
291 !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
|
292 value[field.c_str()].type() != Json::objectValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
293 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
294 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
|
295 "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
|
296 } |
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 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
|
299 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
300 target.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
301 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
302 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
|
303 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
304 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
|
305 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
306 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
|
307 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
308 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
|
309 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
310 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
|
311 tmp.type() != Json::stringValue) |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
312 { |
2966 | 313 throw OrthancException(ErrorCode_BadFileFormat, |
314 "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
|
315 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
316 else |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
317 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
318 target[tag] = tmp.asString(); |
2845
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
319 } |
218e2c864d1d
serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
320 } |
2656 | 321 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
322 |
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 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
|
325 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
|
326 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
|
327 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
328 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
|
329 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
|
330 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
331 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
|
332 } |
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 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
|
335 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
336 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
|
337 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
|
338 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
339 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
|
340 } |
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 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
|
345 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
|
346 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
|
347 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
348 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
|
349 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
|
350 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
351 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
|
352 } |
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 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
|
355 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
356 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
|
357 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
358 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
|
359 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
|
360 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
361 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
|
362 } |
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 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
|
367 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
|
368 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
|
369 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
370 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
|
371 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
|
372 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
373 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
|
374 } |
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 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
|
377 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
378 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
|
379 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
380 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
|
381 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
|
382 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
383 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
|
384 } |
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 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
|
389 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
|
390 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
|
391 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
392 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
|
393 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
|
394 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
395 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
|
396 } |
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 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
|
399 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
400 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
|
401 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
402 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
|
403 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
|
404 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
405 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
|
406 } |
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 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
|
411 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
|
412 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
|
413 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
414 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
|
415 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
|
416 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
417 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
|
418 } |
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 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
|
421 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
422 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
|
423 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
424 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
|
425 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
|
426 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
427 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
|
428 } |
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 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
|
433 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
|
434 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
|
435 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
436 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
|
437 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
|
438 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
439 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
|
440 } |
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 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
|
443 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
444 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
|
445 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
446 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
|
447 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
|
448 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
449 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
|
450 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3870
diff
changeset
|
451 } |
4775
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
452 |
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 template <typename T, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
455 bool allowSigned> |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
456 static bool ParseValue(T& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
457 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
458 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
459 try |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
460 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
461 std::string value = Toolbox::StripSpaces(source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
462 if (value.empty()) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
463 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
464 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
465 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
466 else if (!allowSigned && |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
467 value[0] == '-') |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
468 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
469 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
470 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
471 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
472 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
473 target = boost::lexical_cast<T>(value); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
474 return true; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
475 } |
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 catch (boost::bad_lexical_cast&) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
478 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
479 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
480 } |
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 bool SerializationToolbox::ParseInteger32(int32_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
485 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
486 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
487 int64_t tmp; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
488 if (ParseValue<int64_t, true>(tmp, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
489 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
490 target = static_cast<int32_t>(tmp); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
491 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
|
492 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
493 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
494 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
495 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
496 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
497 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
498 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
499 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
500 bool SerializationToolbox::ParseInteger64(int64_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
501 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
502 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
503 return ParseValue<int64_t, true>(target, source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
504 } |
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 bool SerializationToolbox::ParseUnsignedInteger32(uint32_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
508 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
509 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
510 uint64_t tmp; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
511 if (ParseValue<uint64_t, false>(tmp, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
512 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
513 target = static_cast<uint32_t>(tmp); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
514 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
|
515 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
516 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
517 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
518 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
519 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
520 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
521 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
522 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
523 bool SerializationToolbox::ParseUnsignedInteger64(uint64_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
524 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
525 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
526 return ParseValue<uint64_t, false>(target, source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
527 } |
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 bool SerializationToolbox::ParseFloat(float& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
531 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
532 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
533 return ParseValue<float, true>(target, source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
534 } |
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 bool SerializationToolbox::ParseDouble(double& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
538 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
539 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
540 return ParseValue<double, true>(target, source); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
541 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
542 |
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 static bool GetFirstItem(std::string& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
545 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
546 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
547 std::vector<std::string> tokens; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
548 Toolbox::TokenizeString(tokens, source, '\\'); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
549 |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
550 if (tokens.empty()) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
551 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
552 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
553 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
554 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
555 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
556 target = tokens[0]; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
557 return true; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
558 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
559 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
560 |
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 bool SerializationToolbox::ParseFirstInteger32(int32_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
563 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
564 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
565 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
566 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
567 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
568 return ParseInteger32(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
569 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
570 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
571 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
572 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
573 } |
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 bool SerializationToolbox::ParseFirstInteger64(int64_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
578 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
579 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
580 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
581 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
582 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
583 return ParseInteger64(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
584 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
585 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
586 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
587 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
588 } |
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 bool SerializationToolbox::ParseFirstUnsignedInteger32(uint32_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
593 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
594 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
595 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
596 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
597 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
598 return ParseUnsignedInteger32(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
599 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
600 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
601 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
602 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
603 } |
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 bool SerializationToolbox::ParseFirstUnsignedInteger64(uint64_t& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
608 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
609 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
610 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
611 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
612 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
613 return ParseUnsignedInteger64(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
614 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
615 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
616 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
617 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
618 } |
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 bool SerializationToolbox::ParseFirstFloat(float& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
623 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
624 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
625 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
626 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
627 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
628 return ParseFloat(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
629 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
630 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
631 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
632 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
633 } |
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 bool SerializationToolbox::ParseFirstDouble(double& target, |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
638 const std::string& source) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
639 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
640 std::string first; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
641 if (GetFirstItem(first, source)) |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
642 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
643 return ParseDouble(target, first); |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
644 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
645 else |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
646 { |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
647 return false; |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
648 } |
add0337b928a
refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4451
diff
changeset
|
649 } |
2656 | 650 } |