comparison Core/SerializationToolbox.cpp @ 2981:eff50153a7b3 db-changes

integration mainline->db-changes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Dec 2018 15:58:08 +0100
parents 10c610e80b15
children 94c8222c52b7
comparison
equal deleted inserted replaced
2896:3fabf9a673f6 2981:eff50153a7b3
45 { 45 {
46 if (value.type() != Json::objectValue || 46 if (value.type() != Json::objectValue ||
47 !value.isMember(field.c_str()) || 47 !value.isMember(field.c_str()) ||
48 value[field.c_str()].type() != Json::stringValue) 48 value[field.c_str()].type() != Json::stringValue)
49 { 49 {
50 throw OrthancException(ErrorCode_BadFileFormat); 50 throw OrthancException(ErrorCode_BadFileFormat,
51 "String value expected in field: " + field);
51 } 52 }
52 else 53 else
53 { 54 {
54 return value[field.c_str()].asString(); 55 return value[field.c_str()].asString();
55 } 56 }
62 if (value.type() != Json::objectValue || 63 if (value.type() != Json::objectValue ||
63 !value.isMember(field.c_str()) || 64 !value.isMember(field.c_str()) ||
64 (value[field.c_str()].type() != Json::intValue && 65 (value[field.c_str()].type() != Json::intValue &&
65 value[field.c_str()].type() != Json::uintValue)) 66 value[field.c_str()].type() != Json::uintValue))
66 { 67 {
67 throw OrthancException(ErrorCode_BadFileFormat); 68 throw OrthancException(ErrorCode_BadFileFormat,
69 "Integer value expected in field: " + field);
68 } 70 }
69 else 71 else
70 { 72 {
71 return value[field.c_str()].asInt(); 73 return value[field.c_str()].asInt();
72 } 74 }
78 { 80 {
79 int tmp = ReadInteger(value, field); 81 int tmp = ReadInteger(value, field);
80 82
81 if (tmp < 0) 83 if (tmp < 0)
82 { 84 {
83 throw OrthancException(ErrorCode_BadFileFormat); 85 throw OrthancException(ErrorCode_BadFileFormat,
86 "Unsigned integer value expected in field: " + field);
84 } 87 }
85 else 88 else
86 { 89 {
87 return static_cast<unsigned int>(tmp); 90 return static_cast<unsigned int>(tmp);
88 } 91 }
94 { 97 {
95 if (value.type() != Json::objectValue || 98 if (value.type() != Json::objectValue ||
96 !value.isMember(field.c_str()) || 99 !value.isMember(field.c_str()) ||
97 value[field.c_str()].type() != Json::booleanValue) 100 value[field.c_str()].type() != Json::booleanValue)
98 { 101 {
99 throw OrthancException(ErrorCode_BadFileFormat); 102 throw OrthancException(ErrorCode_BadFileFormat,
103 "Boolean value expected in field: " + field);
100 } 104 }
101 else 105 else
102 { 106 {
103 return value[field.c_str()].asBool(); 107 return value[field.c_str()].asBool();
104 } 108 }
111 { 115 {
112 if (value.type() != Json::objectValue || 116 if (value.type() != Json::objectValue ||
113 !value.isMember(field.c_str()) || 117 !value.isMember(field.c_str()) ||
114 value[field.c_str()].type() != Json::arrayValue) 118 value[field.c_str()].type() != Json::arrayValue)
115 { 119 {
116 throw OrthancException(ErrorCode_BadFileFormat); 120 throw OrthancException(ErrorCode_BadFileFormat,
121 "List of strings expected in field: " + field);
117 } 122 }
118 123
119 const Json::Value& arr = value[field.c_str()]; 124 const Json::Value& arr = value[field.c_str()];
120 125
121 target.resize(arr.size()); 126 target.resize(arr.size());
122 127
123 for (Json::Value::ArrayIndex i = 0; i < arr.size(); i++) 128 for (Json::Value::ArrayIndex i = 0; i < arr.size(); i++)
124 { 129 {
125 if (arr[i].type() != Json::stringValue) 130 if (arr[i].type() != Json::stringValue)
126 { 131 {
127 throw OrthancException(ErrorCode_BadFileFormat); 132 throw OrthancException(ErrorCode_BadFileFormat,
133 "List of strings expected in field: " + field);
128 } 134 }
129 else 135 else
130 { 136 {
131 target[i] = arr[i].asString(); 137 target[i] = arr[i].asString();
132 } 138 }
170 { 176 {
171 if (value.type() != Json::objectValue || 177 if (value.type() != Json::objectValue ||
172 !value.isMember(field.c_str()) || 178 !value.isMember(field.c_str()) ||
173 value[field.c_str()].type() != Json::arrayValue) 179 value[field.c_str()].type() != Json::arrayValue)
174 { 180 {
175 throw OrthancException(ErrorCode_BadFileFormat); 181 throw OrthancException(ErrorCode_BadFileFormat,
182 "Set of DICOM tags expected in field: " + field);
176 } 183 }
177 184
178 const Json::Value& arr = value[field.c_str()]; 185 const Json::Value& arr = value[field.c_str()];
179 186
180 target.clear(); 187 target.clear();
184 DicomTag tag(0, 0); 191 DicomTag tag(0, 0);
185 192
186 if (arr[i].type() != Json::stringValue || 193 if (arr[i].type() != Json::stringValue ||
187 !DicomTag::ParseHexadecimal(tag, arr[i].asCString())) 194 !DicomTag::ParseHexadecimal(tag, arr[i].asCString()))
188 { 195 {
189 throw OrthancException(ErrorCode_BadFileFormat); 196 throw OrthancException(ErrorCode_BadFileFormat,
197 "Set of DICOM tags expected in field: " + field);
190 } 198 }
191 else 199 else
192 { 200 {
193 target.insert(tag); 201 target.insert(tag);
194 } 202 }
202 { 210 {
203 if (value.type() != Json::objectValue || 211 if (value.type() != Json::objectValue ||
204 !value.isMember(field.c_str()) || 212 !value.isMember(field.c_str()) ||
205 value[field.c_str()].type() != Json::objectValue) 213 value[field.c_str()].type() != Json::objectValue)
206 { 214 {
207 throw OrthancException(ErrorCode_BadFileFormat); 215 throw OrthancException(ErrorCode_BadFileFormat,
216 "Associative array of strings to strings expected in field: " + field);
208 } 217 }
209 218
210 const Json::Value& source = value[field.c_str()]; 219 const Json::Value& source = value[field.c_str()];
211 220
212 target.clear(); 221 target.clear();
217 { 226 {
218 const Json::Value& tmp = source[members[i]]; 227 const Json::Value& tmp = source[members[i]];
219 228
220 if (tmp.type() != Json::stringValue) 229 if (tmp.type() != Json::stringValue)
221 { 230 {
222 throw OrthancException(ErrorCode_BadFileFormat); 231 throw OrthancException(ErrorCode_BadFileFormat,
232 "Associative array of string to strings expected in field: " + field);
223 } 233 }
224 else 234 else
225 { 235 {
226 target[members[i]] = tmp.asString(); 236 target[members[i]] = tmp.asString();
227 } 237 }
235 { 245 {
236 if (value.type() != Json::objectValue || 246 if (value.type() != Json::objectValue ||
237 !value.isMember(field.c_str()) || 247 !value.isMember(field.c_str()) ||
238 value[field.c_str()].type() != Json::objectValue) 248 value[field.c_str()].type() != Json::objectValue)
239 { 249 {
240 throw OrthancException(ErrorCode_BadFileFormat); 250 throw OrthancException(ErrorCode_BadFileFormat,
251 "Associative array of DICOM tags to strings expected in field: " + field);
241 } 252 }
242 253
243 const Json::Value& source = value[field.c_str()]; 254 const Json::Value& source = value[field.c_str()];
244 255
245 target.clear(); 256 target.clear();
253 DicomTag tag(0, 0); 264 DicomTag tag(0, 0);
254 265
255 if (!DicomTag::ParseHexadecimal(tag, members[i].c_str()) || 266 if (!DicomTag::ParseHexadecimal(tag, members[i].c_str()) ||
256 tmp.type() != Json::stringValue) 267 tmp.type() != Json::stringValue)
257 { 268 {
258 throw OrthancException(ErrorCode_BadFileFormat); 269 throw OrthancException(ErrorCode_BadFileFormat,
270 "Associative array of DICOM tags to strings expected in field: " + field);
259 } 271 }
260 else 272 else
261 { 273 {
262 target[tag] = tmp.asString(); 274 target[tag] = tmp.asString();
263 } 275 }