comparison Orthanc/Core/Toolbox.h @ 78:d6da56f86e5a

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 25 Sep 2015 11:29:17 +0200
parents
children abdde1dfb3eb
comparison
equal deleted inserted replaced
77:f44ebb25691c 78:d6da56f86e5a
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2015 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 namespace Orthanc
43 {
44 typedef std::vector<std::string> UriComponents;
45
46 class NullType
47 {
48 };
49
50 namespace Toolbox
51 {
52 void ServerBarrier(const bool& stopFlag);
53
54 void ServerBarrier();
55
56 void ToUpperCase(std::string& s); // Inplace version
57
58 void ToLowerCase(std::string& s); // Inplace version
59
60 void ToUpperCase(std::string& result,
61 const std::string& source);
62
63 void ToLowerCase(std::string& result,
64 const std::string& source);
65
66 void ReadFile(std::string& content,
67 const std::string& path);
68
69 void WriteFile(const std::string& content,
70 const std::string& path);
71
72 void WriteFile(const void* content,
73 size_t size,
74 const std::string& path);
75
76 void USleep(uint64_t microSeconds);
77
78 void RemoveFile(const std::string& path);
79
80 void SplitUriComponents(UriComponents& components,
81 const std::string& uri);
82
83 void TruncateUri(UriComponents& target,
84 const UriComponents& source,
85 size_t fromLevel);
86
87 bool IsChildUri(const UriComponents& baseUri,
88 const UriComponents& testedUri);
89
90 std::string AutodetectMimeType(const std::string& path);
91
92 std::string FlattenUri(const UriComponents& components,
93 size_t fromLevel = 0);
94
95 uint64_t GetFileSize(const std::string& path);
96
97 #if !defined(ORTHANC_ENABLE_MD5) || ORTHANC_ENABLE_MD5 == 1
98 void ComputeMD5(std::string& result,
99 const std::string& data);
100
101 void ComputeMD5(std::string& result,
102 const void* data,
103 size_t length);
104 #endif
105
106 void ComputeSHA1(std::string& result,
107 const std::string& data);
108
109 bool IsSHA1(const char* str,
110 size_t size);
111
112 bool IsSHA1(const std::string& s);
113
114 #if !defined(ORTHANC_ENABLE_BASE64) || ORTHANC_ENABLE_BASE64 == 1
115 void DecodeBase64(std::string& result,
116 const std::string& data);
117
118 void EncodeBase64(std::string& result,
119 const std::string& data);
120 #endif
121
122 std::string GetPathToExecutable();
123
124 std::string GetDirectoryOfExecutable();
125
126 std::string ConvertToUtf8(const std::string& source,
127 Encoding sourceEncoding);
128
129 std::string ConvertFromUtf8(const std::string& source,
130 Encoding targetEncoding);
131
132 std::string ConvertToAscii(const std::string& source);
133
134 std::string StripSpaces(const std::string& source);
135
136 #if BOOST_HAS_DATE_TIME == 1
137 std::string GetNowIsoString();
138
139 void GetNowDicom(std::string& date,
140 std::string& time);
141 #endif
142
143 // In-place percent-decoding for URL
144 void UrlDecode(std::string& s);
145
146 Endianness DetectEndianness();
147
148 #if BOOST_HAS_REGEX == 1
149 std::string WildcardToRegularExpression(const std::string& s);
150 #endif
151
152 void TokenizeString(std::vector<std::string>& result,
153 const std::string& source,
154 char separator);
155
156 #if BOOST_HAS_REGEX == 1
157 void DecodeDataUriScheme(std::string& mime,
158 std::string& content,
159 const std::string& source);
160 #endif
161
162 void MakeDirectory(const std::string& path);
163
164 bool IsExistingFile(const std::string& path);
165
166 #if ORTHANC_PUGIXML_ENABLED == 1
167 void JsonToXml(std::string& target,
168 const Json::Value& source,
169 const std::string& rootElement = "root",
170 const std::string& arrayElement = "item");
171 #endif
172
173 void ExecuteSystemCommand(const std::string& command,
174 const std::vector<std::string>& arguments);
175
176 bool IsInteger(const std::string& str);
177
178 void CopyJsonWithoutComments(Json::Value& target,
179 const Json::Value& source);
180
181 bool StartsWith(const std::string& str,
182 const std::string& prefix);
183
184 int GetProcessId();
185 }
186 }