annotate OrthancFramework/Sources/SerializationToolbox.cpp @ 5406:aaf7c49a9ddc am-http-compression

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