Mercurial > hg > orthanc-stone
comparison Resources/Orthanc/Core/Toolbox.h @ 16:ff1e935768e7
reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Nov 2016 20:06:52 +0100 |
parents | Framework/Orthanc/Core/Toolbox.h@da2cf3ace87a |
children | b01d46e5a2b3 |
comparison
equal
deleted
inserted
replaced
15:da2cf3ace87a | 16:ff1e935768e7 |
---|---|
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 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #pragma once | |
34 | |
35 #include "Enumerations.h" | |
36 | |
37 #include <stdint.h> | |
38 #include <vector> | |
39 #include <string> | |
40 #include <json/json.h> | |
41 | |
42 | |
43 #if !defined(ORTHANC_ENABLE_BASE64) | |
44 # error The macro ORTHANC_ENABLE_BASE64 must be defined | |
45 #endif | |
46 | |
47 #if !defined(ORTHANC_ENABLE_MD5) | |
48 # error The macro ORTHANC_ENABLE_MD5 must be defined | |
49 #endif | |
50 | |
51 #if !defined(ORTHANC_ENABLE_PUGIXML) | |
52 # error The macro ORTHANC_ENABLE_PUGIXML must be defined | |
53 #endif | |
54 | |
55 #if !defined(BOOST_HAS_REGEX) | |
56 # error The macro BOOST_HAS_REGEX must be defined | |
57 #endif | |
58 | |
59 | |
60 /** | |
61 * NOTE: GUID vs. UUID | |
62 * The simple answer is: no difference, they are the same thing. Treat | |
63 * them as a 16 byte (128 bits) value that is used as a unique | |
64 * value. In Microsoft-speak they are called GUIDs, but call them | |
65 * UUIDs when not using Microsoft-speak. | |
66 * http://stackoverflow.com/questions/246930/is-there-any-difference-between-a-guid-and-a-uuid | |
67 **/ | |
68 | |
69 | |
70 | |
71 namespace Orthanc | |
72 { | |
73 typedef std::vector<std::string> UriComponents; | |
74 | |
75 class NullType | |
76 { | |
77 }; | |
78 | |
79 namespace Toolbox | |
80 { | |
81 void USleep(uint64_t microSeconds); | |
82 | |
83 void ToUpperCase(std::string& s); // Inplace version | |
84 | |
85 void ToLowerCase(std::string& s); // Inplace version | |
86 | |
87 void ToUpperCase(std::string& result, | |
88 const std::string& source); | |
89 | |
90 void ToLowerCase(std::string& result, | |
91 const std::string& source); | |
92 | |
93 void SplitUriComponents(UriComponents& components, | |
94 const std::string& uri); | |
95 | |
96 void TruncateUri(UriComponents& target, | |
97 const UriComponents& source, | |
98 size_t fromLevel); | |
99 | |
100 bool IsChildUri(const UriComponents& baseUri, | |
101 const UriComponents& testedUri); | |
102 | |
103 std::string AutodetectMimeType(const std::string& path); | |
104 | |
105 std::string FlattenUri(const UriComponents& components, | |
106 size_t fromLevel = 0); | |
107 | |
108 #if ORTHANC_ENABLE_MD5 == 1 | |
109 void ComputeMD5(std::string& result, | |
110 const std::string& data); | |
111 | |
112 void ComputeMD5(std::string& result, | |
113 const void* data, | |
114 size_t size); | |
115 #endif | |
116 | |
117 void ComputeSHA1(std::string& result, | |
118 const std::string& data); | |
119 | |
120 void ComputeSHA1(std::string& result, | |
121 const void* data, | |
122 size_t size); | |
123 | |
124 bool IsSHA1(const char* str, | |
125 size_t size); | |
126 | |
127 bool IsSHA1(const std::string& s); | |
128 | |
129 #if ORTHANC_ENABLE_BASE64 == 1 | |
130 void DecodeBase64(std::string& result, | |
131 const std::string& data); | |
132 | |
133 void EncodeBase64(std::string& result, | |
134 const std::string& data); | |
135 | |
136 # if BOOST_HAS_REGEX == 1 | |
137 bool DecodeDataUriScheme(std::string& mime, | |
138 std::string& content, | |
139 const std::string& source); | |
140 # endif | |
141 | |
142 void EncodeDataUriScheme(std::string& result, | |
143 const std::string& mime, | |
144 const std::string& content); | |
145 #endif | |
146 | |
147 std::string ConvertToUtf8(const std::string& source, | |
148 Encoding sourceEncoding); | |
149 | |
150 std::string ConvertFromUtf8(const std::string& source, | |
151 Encoding targetEncoding); | |
152 | |
153 bool IsAsciiString(const void* data, | |
154 size_t size); | |
155 | |
156 std::string ConvertToAscii(const std::string& source); | |
157 | |
158 std::string StripSpaces(const std::string& source); | |
159 | |
160 // In-place percent-decoding for URL | |
161 void UrlDecode(std::string& s); | |
162 | |
163 Endianness DetectEndianness(); | |
164 | |
165 #if BOOST_HAS_REGEX == 1 | |
166 std::string WildcardToRegularExpression(const std::string& s); | |
167 #endif | |
168 | |
169 void TokenizeString(std::vector<std::string>& result, | |
170 const std::string& source, | |
171 char separator); | |
172 | |
173 #if ORTHANC_ENABLE_PUGIXML == 1 | |
174 void JsonToXml(std::string& target, | |
175 const Json::Value& source, | |
176 const std::string& rootElement = "root", | |
177 const std::string& arrayElement = "item"); | |
178 #endif | |
179 | |
180 bool IsInteger(const std::string& str); | |
181 | |
182 void CopyJsonWithoutComments(Json::Value& target, | |
183 const Json::Value& source); | |
184 | |
185 bool StartsWith(const std::string& str, | |
186 const std::string& prefix); | |
187 | |
188 void UriEncode(std::string& target, | |
189 const std::string& source); | |
190 | |
191 std::string GetJsonStringField(const ::Json::Value& json, | |
192 const std::string& key, | |
193 const std::string& defaultValue); | |
194 | |
195 bool GetJsonBooleanField(const ::Json::Value& json, | |
196 const std::string& key, | |
197 bool defaultValue); | |
198 | |
199 int GetJsonIntegerField(const ::Json::Value& json, | |
200 const std::string& key, | |
201 int defaultValue); | |
202 | |
203 unsigned int GetJsonUnsignedIntegerField(const ::Json::Value& json, | |
204 const std::string& key, | |
205 unsigned int defaultValue); | |
206 | |
207 std::string GenerateUuid(); | |
208 | |
209 bool IsUuid(const std::string& str); | |
210 | |
211 bool StartsWithUuid(const std::string& str); | |
212 } | |
213 } |