Mercurial > hg > orthanc
annotate OrthancFramework/Sources/EnumerationDictionary.h @ 4302:4c91fbede7d2
missing macro CIVETWEB_KEEP_ALIVE_TIMEOUT_SECONDS
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 06 Nov 2020 10:00:05 +0100 |
parents | bf7b9edf6b81 |
children | d9473bd5ed43 |
rev | line source |
---|---|
434 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1103
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
434 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the License, or (at your option) any later version. |
434 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
434 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
434 | 20 **/ |
21 | |
22 | |
23 #pragma once | |
24 | |
25 #include "OrthancException.h" | |
26 | |
1102
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
27 #include "Toolbox.h" |
434 | 28 #include <boost/lexical_cast.hpp> |
29 #include <string> | |
30 #include <map> | |
31 | |
32 namespace Orthanc | |
33 { | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
34 template <typename Enumeration> |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
35 class EnumerationDictionary |
434 | 36 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
37 private: |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
38 typedef std::map<Enumeration, std::string> EnumerationToString; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
39 typedef std::map<std::string, Enumeration> StringToEnumeration; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
40 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
41 EnumerationToString enumerationToString_; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
42 StringToEnumeration stringToEnumeration_; |
434 | 43 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
44 public: |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
45 void Clear() |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
46 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
47 enumerationToString_.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
48 stringToEnumeration_.clear(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
49 } |
434 | 50 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
51 bool Contains(Enumeration value) const |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
52 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
53 return enumerationToString_.find(value) != enumerationToString_.end(); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
54 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
55 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
56 void Add(Enumeration value, const std::string& str) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
57 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
58 // Check if these values are free |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
59 if (enumerationToString_.find(value) != enumerationToString_.end() || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
60 stringToEnumeration_.find(str) != stringToEnumeration_.end() || |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
61 Toolbox::IsInteger(str) /* Prevent the registration of a number */) |
1103
bec1eccf976c
Hot restart of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1102
diff
changeset
|
62 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
63 throw OrthancException(ErrorCode_BadRequest); |
1772
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
64 } |
53e045b5a8ec
MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
65 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
66 // OK, the string is free and is not a number |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
67 enumerationToString_[value] = str; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
68 stringToEnumeration_[str] = value; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
69 stringToEnumeration_[boost::lexical_cast<std::string>(static_cast<int>(value))] = value; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
70 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
71 |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
72 Enumeration Translate(const std::string& str) const |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
73 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
74 if (Toolbox::IsInteger(str)) |
434 | 75 { |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
76 return static_cast<Enumeration>(boost::lexical_cast<int>(str)); |
434 | 77 } |
78 | |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
79 typename StringToEnumeration::const_iterator |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
80 found = stringToEnumeration_.find(str); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
81 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
82 if (found == stringToEnumeration_.end()) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
83 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
84 throw OrthancException(ErrorCode_InexistentItem); |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
85 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
86 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
87 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
88 return found->second; |
434 | 89 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
90 } |
434 | 91 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
92 std::string Translate(Enumeration e) const |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
93 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
94 typename EnumerationToString::const_iterator |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
95 found = enumerationToString_.find(e); |
434 | 96 |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
97 if (found == enumerationToString_.end()) |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
98 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
99 // No name for this item |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
100 return boost::lexical_cast<std::string>(static_cast<int>(e)); |
434 | 101 } |
3991
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
102 else |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
103 { |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
104 return found->second; |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
105 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
106 } |
5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
107 }; |
434 | 108 } |