Mercurial > hg > orthanc
annotate Core/Enumerations.cpp @ 562:f64e3838d6e1 find-move-scp
refactoring enumerations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 18 Sep 2013 16:49:48 +0200 |
parents | 6f8ae46ed90e |
children | 2d0a347e8cfc |
rev | line source |
---|---|
477 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, | |
4 * 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 #include "Enumerations.h" | |
34 | |
35 #include "OrthancException.h" | |
562
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
36 #include "Toolbox.h" |
477 | 37 |
38 namespace Orthanc | |
39 { | |
40 const char* EnumerationToString(HttpMethod method) | |
41 { | |
42 switch (method) | |
43 { | |
44 case HttpMethod_Get: | |
45 return "GET"; | |
46 | |
47 case HttpMethod_Post: | |
48 return "POST"; | |
49 | |
50 case HttpMethod_Delete: | |
51 return "DELETE"; | |
52 | |
53 case HttpMethod_Put: | |
54 return "PUT"; | |
55 | |
56 default: | |
57 return "?"; | |
58 } | |
59 } | |
60 | |
61 | |
62 const char* EnumerationToString(HttpStatus status) | |
63 { | |
64 switch (status) | |
65 { | |
66 case HttpStatus_100_Continue: | |
67 return "Continue"; | |
68 | |
69 case HttpStatus_101_SwitchingProtocols: | |
70 return "Switching Protocols"; | |
71 | |
72 case HttpStatus_102_Processing: | |
73 return "Processing"; | |
74 | |
75 case HttpStatus_200_Ok: | |
76 return "OK"; | |
77 | |
78 case HttpStatus_201_Created: | |
79 return "Created"; | |
80 | |
81 case HttpStatus_202_Accepted: | |
82 return "Accepted"; | |
83 | |
84 case HttpStatus_203_NonAuthoritativeInformation: | |
85 return "Non-Authoritative Information"; | |
86 | |
87 case HttpStatus_204_NoContent: | |
88 return "No Content"; | |
89 | |
90 case HttpStatus_205_ResetContent: | |
91 return "Reset Content"; | |
92 | |
93 case HttpStatus_206_PartialContent: | |
94 return "Partial Content"; | |
95 | |
96 case HttpStatus_207_MultiStatus: | |
97 return "Multi-Status"; | |
98 | |
99 case HttpStatus_208_AlreadyReported: | |
100 return "Already Reported"; | |
101 | |
102 case HttpStatus_226_IMUsed: | |
103 return "IM Used"; | |
104 | |
105 case HttpStatus_300_MultipleChoices: | |
106 return "Multiple Choices"; | |
107 | |
108 case HttpStatus_301_MovedPermanently: | |
109 return "Moved Permanently"; | |
110 | |
111 case HttpStatus_302_Found: | |
112 return "Found"; | |
113 | |
114 case HttpStatus_303_SeeOther: | |
115 return "See Other"; | |
116 | |
117 case HttpStatus_304_NotModified: | |
118 return "Not Modified"; | |
119 | |
120 case HttpStatus_305_UseProxy: | |
121 return "Use Proxy"; | |
122 | |
123 case HttpStatus_307_TemporaryRedirect: | |
124 return "Temporary Redirect"; | |
125 | |
126 case HttpStatus_400_BadRequest: | |
127 return "Bad Request"; | |
128 | |
129 case HttpStatus_401_Unauthorized: | |
130 return "Unauthorized"; | |
131 | |
132 case HttpStatus_402_PaymentRequired: | |
133 return "Payment Required"; | |
134 | |
135 case HttpStatus_403_Forbidden: | |
136 return "Forbidden"; | |
137 | |
138 case HttpStatus_404_NotFound: | |
139 return "Not Found"; | |
140 | |
141 case HttpStatus_405_MethodNotAllowed: | |
142 return "Method Not Allowed"; | |
143 | |
144 case HttpStatus_406_NotAcceptable: | |
145 return "Not Acceptable"; | |
146 | |
147 case HttpStatus_407_ProxyAuthenticationRequired: | |
148 return "Proxy Authentication Required"; | |
149 | |
150 case HttpStatus_408_RequestTimeout: | |
151 return "Request Timeout"; | |
152 | |
153 case HttpStatus_409_Conflict: | |
154 return "Conflict"; | |
155 | |
156 case HttpStatus_410_Gone: | |
157 return "Gone"; | |
158 | |
159 case HttpStatus_411_LengthRequired: | |
160 return "Length Required"; | |
161 | |
162 case HttpStatus_412_PreconditionFailed: | |
163 return "Precondition Failed"; | |
164 | |
165 case HttpStatus_413_RequestEntityTooLarge: | |
166 return "Request Entity Too Large"; | |
167 | |
168 case HttpStatus_414_RequestUriTooLong: | |
169 return "Request-URI Too Long"; | |
170 | |
171 case HttpStatus_415_UnsupportedMediaType: | |
172 return "Unsupported Media Type"; | |
173 | |
174 case HttpStatus_416_RequestedRangeNotSatisfiable: | |
175 return "Requested Range Not Satisfiable"; | |
176 | |
177 case HttpStatus_417_ExpectationFailed: | |
178 return "Expectation Failed"; | |
179 | |
180 case HttpStatus_422_UnprocessableEntity: | |
181 return "Unprocessable Entity"; | |
182 | |
183 case HttpStatus_423_Locked: | |
184 return "Locked"; | |
185 | |
186 case HttpStatus_424_FailedDependency: | |
187 return "Failed Dependency"; | |
188 | |
189 case HttpStatus_426_UpgradeRequired: | |
190 return "Upgrade Required"; | |
191 | |
192 case HttpStatus_500_InternalServerError: | |
193 return "Internal Server Error"; | |
194 | |
195 case HttpStatus_501_NotImplemented: | |
196 return "Not Implemented"; | |
197 | |
198 case HttpStatus_502_BadGateway: | |
199 return "Bad Gateway"; | |
200 | |
201 case HttpStatus_503_ServiceUnavailable: | |
202 return "Service Unavailable"; | |
203 | |
204 case HttpStatus_504_GatewayTimeout: | |
205 return "Gateway Timeout"; | |
206 | |
207 case HttpStatus_505_HttpVersionNotSupported: | |
208 return "HTTP Version Not Supported"; | |
209 | |
210 case HttpStatus_506_VariantAlsoNegotiates: | |
211 return "Variant Also Negotiates"; | |
212 | |
213 case HttpStatus_507_InsufficientStorage: | |
214 return "Insufficient Storage"; | |
215 | |
216 case HttpStatus_509_BandwidthLimitExceeded: | |
217 return "Bandwidth Limit Exceeded"; | |
218 | |
219 case HttpStatus_510_NotExtended: | |
220 return "Not Extended"; | |
221 | |
222 default: | |
223 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
224 } | |
225 } | |
562
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
226 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
227 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
228 const char* EnumerationToString(ResourceType type) |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
229 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
230 switch (type) |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
231 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
232 case ResourceType_Patient: |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
233 return "Patient"; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
234 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
235 case ResourceType_Study: |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
236 return "Study"; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
237 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
238 case ResourceType_Series: |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
239 return "Series"; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
240 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
241 case ResourceType_Instance: |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
242 return "Instance"; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
243 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
244 default: |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
245 throw OrthancException(ErrorCode_ParameterOutOfRange); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
246 } |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
247 } |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
248 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
249 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
250 ResourceType StringToResourceType(const char* type) |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
251 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
252 std::string s(type); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
253 Toolbox::ToUpperCase(s); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
254 |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
255 if (s == "PATIENT") |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
256 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
257 return ResourceType_Patient; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
258 } |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
259 else if (s == "STUDY") |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
260 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
261 return ResourceType_Study; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
262 } |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
263 else if (s == "SERIES") |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
264 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
265 return ResourceType_Series; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
266 } |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
267 else if (s == "INSTANCE" || s == "IMAGE") |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
268 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
269 return ResourceType_Instance; |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
270 } |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
271 else |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
272 { |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
273 throw OrthancException(ErrorCode_ParameterOutOfRange); |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
274 } |
f64e3838d6e1
refactoring enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
275 } |
477 | 276 } |