comparison Framework/Orthanc/Core/Toolbox.h @ 15:da2cf3ace87a

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 Nov 2016 17:20:44 +0100
parents 0b9034112fde
children
comparison
equal deleted inserted replaced
14:0b9034112fde 15:da2cf3ace87a
54 54
55 #if !defined(BOOST_HAS_REGEX) 55 #if !defined(BOOST_HAS_REGEX)
56 # error The macro BOOST_HAS_REGEX must be defined 56 # error The macro BOOST_HAS_REGEX must be defined
57 #endif 57 #endif
58 58
59 #if !defined(ORTHANC_SANDBOXED) 59
60 # define ORTHANC_SANDBOXED 0 60 /**
61 #endif 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
62 70
63 namespace Orthanc 71 namespace Orthanc
64 { 72 {
65 typedef std::vector<std::string> UriComponents; 73 typedef std::vector<std::string> UriComponents;
66 74
70 78
71 namespace Toolbox 79 namespace Toolbox
72 { 80 {
73 void USleep(uint64_t microSeconds); 81 void USleep(uint64_t microSeconds);
74 82
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 83 void ToUpperCase(std::string& s); // Inplace version
82 84
83 void ToLowerCase(std::string& s); // Inplace version 85 void ToLowerCase(std::string& s); // Inplace version
84 86
85 void ToUpperCase(std::string& result, 87 void ToUpperCase(std::string& result,
86 const std::string& source); 88 const std::string& source);
87 89
88 void ToLowerCase(std::string& result, 90 void ToLowerCase(std::string& result,
89 const std::string& source); 91 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 92
109 void SplitUriComponents(UriComponents& components, 93 void SplitUriComponents(UriComponents& components,
110 const std::string& uri); 94 const std::string& uri);
111 95
112 void TruncateUri(UriComponents& target, 96 void TruncateUri(UriComponents& target,
119 std::string AutodetectMimeType(const std::string& path); 103 std::string AutodetectMimeType(const std::string& path);
120 104
121 std::string FlattenUri(const UriComponents& components, 105 std::string FlattenUri(const UriComponents& components,
122 size_t fromLevel = 0); 106 size_t fromLevel = 0);
123 107
124 #if ORTHANC_SANDBOXED == 0
125 uint64_t GetFileSize(const std::string& path);
126 #endif
127
128 #if ORTHANC_ENABLE_MD5 == 1 108 #if ORTHANC_ENABLE_MD5 == 1
129 void ComputeMD5(std::string& result, 109 void ComputeMD5(std::string& result,
130 const std::string& data); 110 const std::string& data);
131 111
132 void ComputeMD5(std::string& result, 112 void ComputeMD5(std::string& result,
162 void EncodeDataUriScheme(std::string& result, 142 void EncodeDataUriScheme(std::string& result,
163 const std::string& mime, 143 const std::string& mime,
164 const std::string& content); 144 const std::string& content);
165 #endif 145 #endif
166 146
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, 147 std::string ConvertToUtf8(const std::string& source,
174 Encoding sourceEncoding); 148 Encoding sourceEncoding);
175 149
176 std::string ConvertFromUtf8(const std::string& source, 150 std::string ConvertFromUtf8(const std::string& source,
177 Encoding targetEncoding); 151 Encoding targetEncoding);
180 size_t size); 154 size_t size);
181 155
182 std::string ConvertToAscii(const std::string& source); 156 std::string ConvertToAscii(const std::string& source);
183 157
184 std::string StripSpaces(const std::string& source); 158 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 159
193 // In-place percent-decoding for URL 160 // In-place percent-decoding for URL
194 void UrlDecode(std::string& s); 161 void UrlDecode(std::string& s);
195 162
196 Endianness DetectEndianness(); 163 Endianness DetectEndianness();
200 #endif 167 #endif
201 168
202 void TokenizeString(std::vector<std::string>& result, 169 void TokenizeString(std::vector<std::string>& result,
203 const std::string& source, 170 const std::string& source,
204 char separator); 171 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 172
212 #if ORTHANC_ENABLE_PUGIXML == 1 173 #if ORTHANC_ENABLE_PUGIXML == 1
213 void JsonToXml(std::string& target, 174 void JsonToXml(std::string& target,
214 const Json::Value& source, 175 const Json::Value& source,
215 const std::string& rootElement = "root", 176 const std::string& rootElement = "root",
216 const std::string& arrayElement = "item"); 177 const std::string& arrayElement = "item");
217 #endif 178 #endif
218 179
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); 180 bool IsInteger(const std::string& str);
225 181
226 void CopyJsonWithoutComments(Json::Value& target, 182 void CopyJsonWithoutComments(Json::Value& target,
227 const Json::Value& source); 183 const Json::Value& source);
228 184
229 bool StartsWith(const std::string& str, 185 bool StartsWith(const std::string& str,
230 const std::string& prefix); 186 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 187
241 void UriEncode(std::string& target, 188 void UriEncode(std::string& target,
242 const std::string& source); 189 const std::string& source);
243 190
244 std::string GetJsonStringField(const ::Json::Value& json, 191 std::string GetJsonStringField(const ::Json::Value& json,
254 int defaultValue); 201 int defaultValue);
255 202
256 unsigned int GetJsonUnsignedIntegerField(const ::Json::Value& json, 203 unsigned int GetJsonUnsignedIntegerField(const ::Json::Value& json,
257 const std::string& key, 204 const std::string& key,
258 unsigned int defaultValue); 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);
259 } 212 }
260 } 213 }