annotate OrthancFramework/Sources/SerializationToolbox.cpp @ 5858:66fd63b8601e find-refactoring

StorageAccessOnFind: cont
author Alain Mazy <am@orthanc.team>
date Mon, 04 Nov 2024 22:34:14 +0100
parents f7adfb22e20e
children
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5380
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * 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
10 * 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
11 * 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
12 * the License, or (at your option) any later version.
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * Lesser General Public License for more details.
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
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
19 * 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
20 * 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
21 * <http://www.gnu.org/licenses/>.
2656
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
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "PrecompiledHeaders.h"
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "SerializationToolbox.h"
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "OrthancException.h"
4775
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
29 #include "Toolbox.h"
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
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
31 #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
32 # 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
33 #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
34
4775
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
35 #include <boost/lexical_cast.hpp>
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
36
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
37
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 namespace Orthanc
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
40 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
41 const char* name)
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
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
43 #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
44 try
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
45 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
46 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
47 return true;
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
48 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
49 catch (OrthancException&)
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
50 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
51 return false;
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
52 }
2982
94c8222c52b7 New URIs to launch new C-FIND to explore the hierarchy of a C-FIND answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
53 #else
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
54 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
55 #endif
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
56 }
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
57
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
58
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
59 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
60 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
61 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
62 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
63 !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
64 value[field.c_str()].type() != Json::stringValue)
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
66 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
67 "String value expected in field: " + field);
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
69 else
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
70 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
71 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
72 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
73 }
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
5255
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
76 std::string SerializationToolbox::ReadString(const Json::Value& value,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
77 const std::string& field,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
78 const std::string& defaultValue)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
79 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
80 if (value.isMember(field.c_str()))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
81 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
82 return ReadString(value, field);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
83 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
84 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
85 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
86 return defaultValue;
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
90
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
91 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
92 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
93 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
94 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
95 !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
96 (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
97 value[field.c_str()].type() != Json::uintValue))
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
99 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
100 "Integer value expected in field: " + field);
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
102 else
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
103 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
104 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
105 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
106 }
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
109 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
110 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
111 int defaultValue)
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
112 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
113 if (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
114 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
115 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
116 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
117 else
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
118 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
119 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
120 }
3991
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
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
124 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
125 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
126 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
127 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
128
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
129 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
130 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
131 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
132 "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
133 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
134 else
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
135 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
136 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
137 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
138 }
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
139
09798f2b985f added a Timeout argument to every DICOM command + 'TargetAet' not mandatory anymore in /retrieve
Alain Mazy <alain@mazy.be>
parents: 3641
diff changeset
140
4451
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
141 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
142 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
143 unsigned int defaultValue)
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
144 {
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
145 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
146 {
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
147 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
148 }
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
149 else
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
150 {
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
151 return defaultValue;
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
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
155
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
156 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
157 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
158 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
159 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
160 !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
161 value[field.c_str()].type() != Json::booleanValue)
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
163 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
164 "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
165 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
166 else
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
167 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
168 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
169 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
170 }
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
172
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
173 void SerializationToolbox::ReadArrayOfStrings(std::vector<std::string>& target,
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
174 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
175 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
176 {
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
177 if (valueObject.type() != Json::objectValue ||
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
178 !valueObject.isMember(field.c_str()) ||
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
179 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
180 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
181 throw OrthancException(ErrorCode_BadFileFormat,
5379
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
182 "List of strings expected in field: " + field);
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
185 const Json::Value& arr = valueObject[field.c_str()];
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
5379
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
187 try
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
188 {
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
189 ReadArrayOfStrings(target, arr);
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
190 }
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
191 catch (OrthancException& ex)
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
192 { // more detailed error
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
193 throw OrthancException(ErrorCode_BadFileFormat,
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
194 "List of strings expected in field: " + field);
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 }
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
197
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
198
5379
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
199 void SerializationToolbox::ReadArrayOfStrings(std::vector<std::string>& target,
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
200 const Json::Value& valueArray)
5379
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
201 {
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
202 if (valueArray.type() != Json::arrayValue)
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
5379
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
204 throw OrthancException(ErrorCode_BadFileFormat,
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
205 "List of strings expected");
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
206 }
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
207
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
208 target.resize(valueArray.size());
5379
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
209
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
210 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
211 {
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
212 if (valueArray[i].type() != Json::stringValue)
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
214 throw OrthancException(ErrorCode_BadFileFormat,
5379
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
215 "List of strings expected");
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
217 else
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
219 target[i] = valueArray[i].asString();
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
222 }
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
225 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
226 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
227 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
228 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
229 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
230 ReadArrayOfStrings(tmp, value, field);
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
232 target.clear();
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
233 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
234 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
235 target.push_back(tmp[i]);
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
237 }
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
240 void SerializationToolbox::ReadSetOfStrings(std::set<std::string>& target,
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
241 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
242 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
243 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
244 std::vector<std::string> tmp;
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
245 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
246
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
247 target.clear();
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
248 for (size_t i = 0; i < tmp.size(); i++)
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
250 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
251 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
252 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
253
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
5379
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
255 void SerializationToolbox::ReadSetOfStrings(std::set<std::string>& target,
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
256 const Json::Value& valueArray)
5379
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
257 {
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
258 std::vector<std::string> tmp;
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
259 ReadArrayOfStrings(tmp, valueArray);
5379
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
260
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
261 target.clear();
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
262 for (size_t i = 0; i < tmp.size(); i++)
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
263 {
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
264 target.insert(tmp[i]);
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
b31c73bc7cb6 Toolbox : more set functions
Alain Mazy <am@osimis.io>
parents: 5255
diff changeset
268
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
269 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
270 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
271 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
272 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
273 if (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
274 !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
275 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
276 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
277 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
278 "Set of DICOM tags expected in field: " + field);
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
281 const Json::Value& arr = value[field.c_str()];
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
283 target.clear();
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
284
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
285 for (Json::Value::ArrayIndex i = 0; i < arr.size(); i++)
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
286 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
287 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
288
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
289 if (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
290 !ParseTagInternal(tag, arr[i].asCString()))
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
291 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
292 throw OrthancException(ErrorCode_BadFileFormat,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
293 "Set of DICOM tags expected in field: " + field);
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
294 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
295 else
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
296 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
297 target.insert(tag);
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
298 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
299 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
300 }
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
301
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
302
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
303 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
304 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
305 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
306 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
307 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
308 !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
309 value[field.c_str()].type() != Json::objectValue)
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
310 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
311 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
312 "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
313 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
314
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
315 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
316
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
317 target.clear();
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
318
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
319 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
320
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
321 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
322 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
323 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
324
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
325 if (tmp.type() != Json::stringValue)
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
326 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
327 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
328 "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
329 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
330 else
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
331 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
332 target[members[i]] = tmp.asString();
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
333 }
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
334 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
335 }
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
336
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
337
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
338 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
339 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
340 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
341 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
342 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
343 !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
344 value[field.c_str()].type() != Json::objectValue)
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
345 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
346 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
347 "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
348 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
349
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
350 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
351
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
352 target.clear();
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
353
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
354 Json::Value::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
355
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
356 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
357 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
358 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
359
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
360 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
361
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
362 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
363 tmp.type() != Json::stringValue)
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
364 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
365 throw OrthancException(ErrorCode_BadFileFormat,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2845
diff changeset
366 "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
367 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
368 else
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
369 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
370 target[tag] = tmp.asString();
2845
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
371 }
218e2c864d1d serialization of SplitStudyJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
372 }
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
374
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
375
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
376 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
377 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
378 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
379 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
380 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
381 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
382 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
383 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
384 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
385
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
386 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
387
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
388 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
389 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
390 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
391 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
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
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
396 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
397 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
398 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
399 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
400 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
401 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
402 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
403 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
404 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
405
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
406 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
407
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
408 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
409
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
410 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
411 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
412 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
413 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
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
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
417
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
418 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
419 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
420 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
421 {
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
422 if (targetObject.type() != Json::objectValue ||
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
423 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
424 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
425 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
426 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
427
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
428 Json::Value& targetArray = targetObject[field];
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
429
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
430 targetArray = Json::arrayValue;
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
431
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
432 WriteSetOfStrings(targetArray, values);
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
433 }
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
434
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
435
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
436 void SerializationToolbox::WriteSetOfStrings(Json::Value& targetArray,
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
437 const std::set<std::string>& values)
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
438 {
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
439 if (targetArray.type() != Json::arrayValue)
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
440 {
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
441 throw OrthancException(ErrorCode_BadFileFormat);
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
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
444 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
445
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
446 for (std::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
447 it != values.end(); ++it)
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
448 {
5380
97004471a5c5 Toolbox : more set functions (cont)
Alain Mazy <am@osimis.io>
parents: 5379
diff changeset
449 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
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
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
454 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
455 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
456 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
457 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
458 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
459 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
460 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
461 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
462 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
463
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
464 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
465
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
466 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
467
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
468 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
469 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
470 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
471 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
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
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
476 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
477 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
478 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
479 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
480 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
481 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
482 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
483 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
484 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
485
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
486 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
487
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
488 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
489
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
490 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
491 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
492 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
493 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
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
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
498 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
499 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
500 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
501 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
502 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
503 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
504 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
505 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
506 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
507
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
508 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
509
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
510 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
511
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
512 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
513 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
514 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
515 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
516 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3870
diff changeset
517 }
4775
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
520 template <typename T,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
521 bool allowSigned>
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
522 static bool ParseValue(T& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
523 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
524 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
525 try
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
526 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
527 std::string value = Toolbox::StripSpaces(source);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
528 if (value.empty())
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
529 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
530 return false;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
531 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
532 else if (!allowSigned &&
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
533 value[0] == '-')
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
534 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
535 return false;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
536 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
537 else
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
538 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
539 target = boost::lexical_cast<T>(value);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
540 return true;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
541 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
542 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
543 catch (boost::bad_lexical_cast&)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
544 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
545 return false;
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
550 bool SerializationToolbox::ParseInteger32(int32_t& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
551 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
552 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
553 int64_t tmp;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
554 if (ParseValue<int64_t, true>(tmp, source))
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
555 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
556 target = static_cast<int32_t>(tmp);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
557 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
558 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
559 else
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
560 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
561 return false;
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
566 bool SerializationToolbox::ParseInteger64(int64_t& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
567 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
568 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
569 return ParseValue<int64_t, true>(target, source);
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
573 bool SerializationToolbox::ParseUnsignedInteger32(uint32_t& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
574 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
575 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
576 uint64_t tmp;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
577 if (ParseValue<uint64_t, false>(tmp, source))
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
578 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
579 target = static_cast<uint32_t>(tmp);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
580 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
581 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
582 else
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
583 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
584 return false;
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
589 bool SerializationToolbox::ParseUnsignedInteger64(uint64_t& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
590 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
591 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
592 return ParseValue<uint64_t, false>(target, source);
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
596 bool SerializationToolbox::ParseFloat(float& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
597 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
598 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
599 return ParseValue<float, true>(target, source);
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
603 bool SerializationToolbox::ParseDouble(double& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
604 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
605 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
606 return ParseValue<double, true>(target, source);
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
610 static bool GetFirstItem(std::string& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
611 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
612 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
613 std::vector<std::string> tokens;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
614 Toolbox::TokenizeString(tokens, source, '\\');
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
615
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
616 if (tokens.empty())
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
617 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
618 return false;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
619 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
620 else
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
621 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
622 target = tokens[0];
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
623 return true;
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
628 bool SerializationToolbox::ParseFirstInteger32(int32_t& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
629 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
630 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
631 std::string first;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
632 if (GetFirstItem(first, source))
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
633 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
634 return ParseInteger32(target, first);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
635 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
636 else
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
637 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
638 return false;
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
643 bool SerializationToolbox::ParseFirstInteger64(int64_t& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
644 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
645 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
646 std::string first;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
647 if (GetFirstItem(first, source))
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
648 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
649 return ParseInteger64(target, first);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
650 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
651 else
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
652 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
653 return false;
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
658 bool SerializationToolbox::ParseFirstUnsignedInteger32(uint32_t& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
659 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
660 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
661 std::string first;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
662 if (GetFirstItem(first, source))
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
663 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
664 return ParseUnsignedInteger32(target, first);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
665 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
666 else
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
667 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
668 return false;
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
673 bool SerializationToolbox::ParseFirstUnsignedInteger64(uint64_t& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
674 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
675 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
676 std::string first;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
677 if (GetFirstItem(first, source))
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
678 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
679 return ParseUnsignedInteger64(target, first);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
680 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
681 else
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
682 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
683 return false;
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
688 bool SerializationToolbox::ParseFirstFloat(float& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
689 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
690 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
691 std::string first;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
692 if (GetFirstItem(first, source))
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
693 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
694 return ParseFloat(target, first);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
695 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
696 else
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
697 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
698 return false;
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
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
703 bool SerializationToolbox::ParseFirstDouble(double& target,
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
704 const std::string& source)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
705 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
706 std::string first;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
707 if (GetFirstItem(first, source))
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
708 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
709 return ParseDouble(target, first);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
710 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
711 else
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
712 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
713 return false;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
714 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
715 }
4834
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
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
718 bool SerializationToolbox::ParseBoolean(bool& result,
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
719 const std::string& value)
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
720 {
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
721 if (value == "0" ||
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
722 value == "false")
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
723 {
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
724 result = false;
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
725 return true;
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
726 }
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
727 else if (value == "1" ||
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
728 value == "true")
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
729 {
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
730 result = true;
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
731 return true;
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
732 }
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
733 else
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
734 {
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
735 return false;
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
736 }
bec432ee1094 download of numpy arrays from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
737 }
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 }