annotate OrthancFramework/Sources/EnumerationDictionary.h @ 5853:4d932683049d get-scu tip

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