1 /**
2  * Orthanc - A Lightweight, RESTful DICOM Store
3  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4  * Department, University Hospital of Liege, Belgium
5  * Copyright (C) 2017-2021 Osimis S.A., Belgium
6  *
7  * This program is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this program. If not, see
19  * <http://www.gnu.org/licenses/>.
20  **/
21 
22 
23 #pragma once
24 
25 #include "DicomFormat/DicomTag.h"
26 #include "OrthancFramework.h"
27 
28 #include <json/value.h>
29 #include <list>
30 #include <map>
31 
32 namespace Orthanc
33 {
34   class ORTHANC_PUBLIC SerializationToolbox
35   {
36   public:
37     static std::string ReadString(const Json::Value& value,
38                                   const std::string& field);
39 
40     static int ReadInteger(const Json::Value& value,
41                            const std::string& field);
42 
43     static int ReadInteger(const Json::Value& value,
44                            const std::string& field,
45                            int defaultValue);
46 
47     static unsigned int ReadUnsignedInteger(const Json::Value& value,
48                                             const std::string& field);
49 
50     static unsigned int ReadUnsignedInteger(const Json::Value& value,
51                                             const std::string& field,
52                                             unsigned int defaultValue);
53 
54     static bool ReadBoolean(const Json::Value& value,
55                             const std::string& field);
56 
57     static void ReadArrayOfStrings(std::vector<std::string>& target,
58                                    const Json::Value& value,
59                                    const std::string& field);
60 
61     static void ReadListOfStrings(std::list<std::string>& target,
62                                   const Json::Value& value,
63                                   const std::string& field);
64 
65     static void ReadSetOfStrings(std::set<std::string>& target,
66                                  const Json::Value& value,
67                                  const std::string& field);
68 
69     static void ReadSetOfTags(std::set<DicomTag>& target,
70                               const Json::Value& value,
71                               const std::string& field);
72 
73     static void ReadMapOfStrings(std::map<std::string, std::string>& target,
74                                  const Json::Value& value,
75                                  const std::string& field);
76 
77     static void ReadMapOfTags(std::map<DicomTag, std::string>& target,
78                               const Json::Value& value,
79                               const std::string& field);
80 
81     static void WriteArrayOfStrings(Json::Value& target,
82                                     const std::vector<std::string>& values,
83                                     const std::string& field);
84 
85     static void WriteListOfStrings(Json::Value& target,
86                                    const std::list<std::string>& values,
87                                    const std::string& field);
88 
89     static void WriteSetOfStrings(Json::Value& target,
90                                   const std::set<std::string>& values,
91                                   const std::string& field);
92 
93     static void WriteSetOfTags(Json::Value& target,
94                                const std::set<DicomTag>& tags,
95                                const std::string& field);
96 
97     static void WriteMapOfStrings(Json::Value& target,
98                                   const std::map<std::string, std::string>& values,
99                                   const std::string& field);
100 
101     static void WriteMapOfTags(Json::Value& target,
102                                const std::map<DicomTag, std::string>& values,
103                                const std::string& field);
104 
105     static bool ParseInteger32(int32_t& result,
106                                const std::string& value);
107 
108     static bool ParseInteger64(int64_t& result,
109                                const std::string& value);
110 
111     static bool ParseUnsignedInteger32(uint32_t& result,
112                                        const std::string& value);
113 
114     static bool ParseUnsignedInteger64(uint64_t& result,
115                                        const std::string& value);
116 
117     static bool ParseFloat(float& result,
118                            const std::string& value);
119 
120     static bool ParseDouble(double& result,
121                             const std::string& value);
122 
123     static bool ParseFirstInteger32(int32_t& result,
124                                     const std::string& value);
125 
126     static bool ParseFirstInteger64(int64_t& result,
127                                     const std::string& value);
128 
129     static bool ParseFirstUnsignedInteger32(uint32_t& result,
130                                             const std::string& value);
131 
132     static bool ParseFirstUnsignedInteger64(uint64_t& result,
133                                             const std::string& value);
134 
135     static bool ParseFirstFloat(float& result,
136                                 const std::string& value);
137 
138     static bool ParseFirstDouble(double& result,
139                                  const std::string& value);
140   };
141 }
142