comparison Core/Toolbox.h @ 2140:aa4b8895cd23

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 Nov 2016 16:12:47 +0100
parents 595cf22b3e7e
children a260a8ad83f1
comparison
equal deleted inserted replaced
2139:764c9157301b 2140:aa4b8895cd23
70 70
71 namespace Toolbox 71 namespace Toolbox
72 { 72 {
73 void USleep(uint64_t microSeconds); 73 void USleep(uint64_t microSeconds);
74 74
75 #if ORTHANC_SANDBOXED == 0
76 ServerBarrierEvent ServerBarrier(const bool& stopFlag);
77
78 ServerBarrierEvent ServerBarrier();
79 #endif
80
81 void ToUpperCase(std::string& s); // Inplace version 75 void ToUpperCase(std::string& s); // Inplace version
82 76
83 void ToLowerCase(std::string& s); // Inplace version 77 void ToLowerCase(std::string& s); // Inplace version
84 78
85 void ToUpperCase(std::string& result, 79 void ToUpperCase(std::string& result,
86 const std::string& source); 80 const std::string& source);
87 81
88 void ToLowerCase(std::string& result, 82 void ToLowerCase(std::string& result,
89 const std::string& source); 83 const std::string& source);
90
91 #if ORTHANC_SANDBOXED == 0
92 void ReadFile(std::string& content,
93 const std::string& path);
94
95 bool ReadHeader(std::string& header,
96 const std::string& path,
97 size_t headerSize);
98
99 void WriteFile(const std::string& content,
100 const std::string& path);
101
102 void WriteFile(const void* content,
103 size_t size,
104 const std::string& path);
105
106 void RemoveFile(const std::string& path);
107 #endif
108 84
109 void SplitUriComponents(UriComponents& components, 85 void SplitUriComponents(UriComponents& components,
110 const std::string& uri); 86 const std::string& uri);
111 87
112 void TruncateUri(UriComponents& target, 88 void TruncateUri(UriComponents& target,
119 std::string AutodetectMimeType(const std::string& path); 95 std::string AutodetectMimeType(const std::string& path);
120 96
121 std::string FlattenUri(const UriComponents& components, 97 std::string FlattenUri(const UriComponents& components,
122 size_t fromLevel = 0); 98 size_t fromLevel = 0);
123 99
124 #if ORTHANC_SANDBOXED == 0
125 uint64_t GetFileSize(const std::string& path);
126 #endif
127
128 #if ORTHANC_ENABLE_MD5 == 1 100 #if ORTHANC_ENABLE_MD5 == 1
129 void ComputeMD5(std::string& result, 101 void ComputeMD5(std::string& result,
130 const std::string& data); 102 const std::string& data);
131 103
132 void ComputeMD5(std::string& result, 104 void ComputeMD5(std::string& result,
162 void EncodeDataUriScheme(std::string& result, 134 void EncodeDataUriScheme(std::string& result,
163 const std::string& mime, 135 const std::string& mime,
164 const std::string& content); 136 const std::string& content);
165 #endif 137 #endif
166 138
167 #if ORTHANC_SANDBOXED == 0
168 std::string GetPathToExecutable();
169
170 std::string GetDirectoryOfExecutable();
171 #endif
172
173 std::string ConvertToUtf8(const std::string& source, 139 std::string ConvertToUtf8(const std::string& source,
174 Encoding sourceEncoding); 140 Encoding sourceEncoding);
175 141
176 std::string ConvertFromUtf8(const std::string& source, 142 std::string ConvertFromUtf8(const std::string& source,
177 Encoding targetEncoding); 143 Encoding targetEncoding);
180 size_t size); 146 size_t size);
181 147
182 std::string ConvertToAscii(const std::string& source); 148 std::string ConvertToAscii(const std::string& source);
183 149
184 std::string StripSpaces(const std::string& source); 150 std::string StripSpaces(const std::string& source);
185
186 #if BOOST_HAS_DATE_TIME == 1
187 std::string GetNowIsoString();
188
189 void GetNowDicom(std::string& date,
190 std::string& time);
191 #endif
192 151
193 // In-place percent-decoding for URL 152 // In-place percent-decoding for URL
194 void UrlDecode(std::string& s); 153 void UrlDecode(std::string& s);
195 154
196 Endianness DetectEndianness(); 155 Endianness DetectEndianness();
200 #endif 159 #endif
201 160
202 void TokenizeString(std::vector<std::string>& result, 161 void TokenizeString(std::vector<std::string>& result,
203 const std::string& source, 162 const std::string& source,
204 char separator); 163 char separator);
205
206 #if ORTHANC_SANDBOXED == 0
207 void MakeDirectory(const std::string& path);
208
209 bool IsExistingFile(const std::string& path);
210 #endif
211 164
212 #if ORTHANC_ENABLE_PUGIXML == 1 165 #if ORTHANC_ENABLE_PUGIXML == 1
213 void JsonToXml(std::string& target, 166 void JsonToXml(std::string& target,
214 const Json::Value& source, 167 const Json::Value& source,
215 const std::string& rootElement = "root", 168 const std::string& rootElement = "root",
216 const std::string& arrayElement = "item"); 169 const std::string& arrayElement = "item");
217 #endif 170 #endif
218 171
219 #if ORTHANC_SANDBOXED == 0
220 void ExecuteSystemCommand(const std::string& command,
221 const std::vector<std::string>& arguments);
222 #endif
223
224 bool IsInteger(const std::string& str); 172 bool IsInteger(const std::string& str);
225 173
226 void CopyJsonWithoutComments(Json::Value& target, 174 void CopyJsonWithoutComments(Json::Value& target,
227 const Json::Value& source); 175 const Json::Value& source);
228 176
229 bool StartsWith(const std::string& str, 177 bool StartsWith(const std::string& str,
230 const std::string& prefix); 178 const std::string& prefix);
231
232 #if ORTHANC_SANDBOXED == 0
233 int GetProcessId();
234
235 bool IsRegularFile(const std::string& path);
236 #endif
237
238 FILE* OpenFile(const std::string& path,
239 FileMode mode);
240 179
241 void UriEncode(std::string& target, 180 void UriEncode(std::string& target,
242 const std::string& source); 181 const std::string& source);
243 182
244 std::string GetJsonStringField(const ::Json::Value& json, 183 std::string GetJsonStringField(const ::Json::Value& json,
255 194
256 unsigned int GetJsonUnsignedIntegerField(const ::Json::Value& json, 195 unsigned int GetJsonUnsignedIntegerField(const ::Json::Value& json,
257 const std::string& key, 196 const std::string& key,
258 unsigned int defaultValue); 197 unsigned int defaultValue);
259 } 198 }
199
200
201 #if ORTHANC_SANDBOXED == 0
202 namespace SystemToolbox
203 {
204 ServerBarrierEvent ServerBarrier(const bool& stopFlag);
205
206 ServerBarrierEvent ServerBarrier();
207
208 void ReadFile(std::string& content,
209 const std::string& path);
210
211 bool ReadHeader(std::string& header,
212 const std::string& path,
213 size_t headerSize);
214
215 void WriteFile(const void* content,
216 size_t size,
217 const std::string& path);
218
219 void WriteFile(const std::string& content,
220 const std::string& path);
221
222 void RemoveFile(const std::string& path);
223
224 uint64_t GetFileSize(const std::string& path);
225
226 void MakeDirectory(const std::string& path);
227
228 bool IsExistingFile(const std::string& path);
229
230 std::string GetPathToExecutable();
231
232 std::string GetDirectoryOfExecutable();
233
234 void ExecuteSystemCommand(const std::string& command,
235 const std::vector<std::string>& arguments);
236
237 int GetProcessId();
238
239 bool IsRegularFile(const std::string& path);
240
241 FILE* OpenFile(const std::string& path,
242 FileMode mode);
243
244 #if BOOST_HAS_DATE_TIME == 1
245 std::string GetNowIsoString();
246
247 void GetNowDicom(std::string& date,
248 std::string& time);
249 #endif
250 }
251 #endif /* ORTHANC_SANDBOXED */
260 } 252 }