annotate OrthancFramework/Sources/EnumerationDictionary.h @ 5236:5e0db9eac1f8 db-protobuf

integration mainline->db-protobuf
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Apr 2023 21:43:37 +0200
parents 08e0c9c0ab39
children 48b8dae6dc77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1772
diff changeset
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
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * the License, or (at your option) any later version.
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * 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
16 * Lesser General Public License for more details.
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
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
18 * 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
19 * 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
20 * <http://www.gnu.org/licenses/>.
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #pragma once
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "OrthancException.h"
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
1102
ce6386b37afd avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
28 #include "Toolbox.h"
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <boost/lexical_cast.hpp>
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <string>
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <map>
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace Orthanc
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
35 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
36 class EnumerationDictionary
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
38 private:
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<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
40 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
41
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
42 EnumerationToString enumerationToString_;
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
43 StringToEnumeration stringToEnumeration_;
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
45 public:
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
46 void Clear()
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
47 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
48 enumerationToString_.clear();
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
49 stringToEnumeration_.clear();
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
50 }
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
52 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
53 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
54 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
55 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
56
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
57 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
58 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
59 // 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
60 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
61 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
62 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
63 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
64 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
65 }
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
66
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
67 // 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
68 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
69 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
70 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
71 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
72
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
73 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
74 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
75 if (Toolbox::IsInteger(str))
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
77 return static_cast<Enumeration>(boost::lexical_cast<int>(str));
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
80 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
81 found = stringToEnumeration_.find(str);
435
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
82
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
83 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
84 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
85 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
86 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
87 else
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
88 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
89 return found->second;
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
91 }
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
93 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
94 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
95 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
96 found = enumerationToString_.find(e);
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
98 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
99 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
100 // 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
101 return boost::lexical_cast<std::string>(static_cast<int>(e));
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
103 else
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
104 {
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
105 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
106 }
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
107 }
5204
08e0c9c0ab39 added UserMetadata in /system
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
108
08e0c9c0ab39 added UserMetadata in /system
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
109 const std::map<std::string, Enumeration>& GetAllEntries() const
08e0c9c0ab39 added UserMetadata in /system
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
110 {
08e0c9c0ab39 added UserMetadata in /system
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
111 return stringToEnumeration_;
08e0c9c0ab39 added UserMetadata in /system
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
112 }
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
113 };
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }