comparison Orthanc/Core/Toolbox.h @ 25:15acbf5e7545

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 02 Jun 2015 11:16:30 +0200
parents
children 7c6cf09d838b
comparison
equal deleted inserted replaced
24:ed9acb0f938e 25:15acbf5e7545
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
41 #if ORTHANC_PUGIXML_ENABLED == 1
42 #include <json/json.h>
43 #endif
44
45 namespace Orthanc
46 {
47 typedef std::vector<std::string> UriComponents;
48
49 class NullType
50 {
51 };
52
53 namespace Toolbox
54 {
55 void ServerBarrier(const bool& stopFlag);
56
57 void ServerBarrier();
58
59 void ToUpperCase(std::string& s); // Inplace version
60
61 void ToLowerCase(std::string& s); // Inplace version
62
63 void ToUpperCase(std::string& result,
64 const std::string& source);
65
66 void ToLowerCase(std::string& result,
67 const std::string& source);
68
69 void ReadFile(std::string& content,
70 const std::string& path);
71
72 void WriteFile(const std::string& content,
73 const std::string& path);
74
75 void USleep(uint64_t microSeconds);
76
77 void RemoveFile(const std::string& path);
78
79 void SplitUriComponents(UriComponents& components,
80 const std::string& uri);
81
82 void TruncateUri(UriComponents& target,
83 const UriComponents& source,
84 size_t fromLevel);
85
86 bool IsChildUri(const UriComponents& baseUri,
87 const UriComponents& testedUri);
88
89 std::string AutodetectMimeType(const std::string& path);
90
91 std::string FlattenUri(const UriComponents& components,
92 size_t fromLevel = 0);
93
94 uint64_t GetFileSize(const std::string& path);
95
96 void ComputeMD5(std::string& result,
97 const std::string& data);
98
99 void ComputeMD5(std::string& result,
100 const void* data,
101 size_t length);
102
103 void ComputeSHA1(std::string& result,
104 const std::string& data);
105
106 bool IsSHA1(const std::string& str);
107
108 void DecodeBase64(std::string& result,
109 const std::string& data);
110
111 void EncodeBase64(std::string& result,
112 const std::string& data);
113
114 std::string GetPathToExecutable();
115
116 std::string GetDirectoryOfExecutable();
117
118 std::string ConvertToUtf8(const std::string& source,
119 const Encoding sourceEncoding);
120
121 std::string ConvertToAscii(const std::string& source);
122
123 std::string StripSpaces(const std::string& source);
124
125 #if BOOST_HAS_DATE_TIME == 1
126 std::string GetNowIsoString();
127 #endif
128
129 // In-place percent-decoding for URL
130 void UrlDecode(std::string& s);
131
132 Endianness DetectEndianness();
133
134 #if BOOST_HAS_REGEX == 1
135 std::string WildcardToRegularExpression(const std::string& s);
136 #endif
137
138 void TokenizeString(std::vector<std::string>& result,
139 const std::string& source,
140 char separator);
141
142 #if BOOST_HAS_REGEX == 1
143 void DecodeDataUriScheme(std::string& mime,
144 std::string& content,
145 const std::string& source);
146 #endif
147
148 void MakeDirectory(const std::string& path);
149
150 bool IsExistingFile(const std::string& path);
151
152 #if ORTHANC_PUGIXML_ENABLED == 1
153 void JsonToXml(std::string& target,
154 const Json::Value& source,
155 const std::string& rootElement = "root",
156 const std::string& arrayElement = "item");
157 #endif
158
159 void ExecuteSystemCommand(const std::string& command,
160 const std::vector<std::string>& arguments);
161
162 bool IsInteger(const std::string& str);
163 }
164 }