Mercurial > hg > orthanc-databases
annotate Framework/Common/Dictionary.cpp @ 507:54d518dcd74a
updated copyright, as Orthanc Team now replaces Osimis
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 May 2024 21:47:02 +0200 |
parents | ecd0b719cff5 |
children | c49136b34891 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
507
54d518dcd74a
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
459
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
54d518dcd74a
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
459
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
459
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU Affero General Public License | |
11 * as published by the Free Software Foundation, either version 3 of | |
12 * the License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * Affero General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU Affero General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "Dictionary.h" | |
25 | |
26 #include "BinaryStringValue.h" | |
244
02cd7254c949
separating class InputFileValue from FileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
27 #include "InputFileValue.h" |
0 | 28 #include "Integer64Value.h" |
29 #include "NullValue.h" | |
30 #include "Utf8StringValue.h" | |
31 | |
152 | 32 #include <Logging.h> |
33 #include <OrthancException.h> | |
0 | 34 |
35 #include <cassert> | |
36 | |
37 namespace OrthancDatabases | |
38 { | |
305
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
39 void Dictionary::Clear() |
0 | 40 { |
41 for (Values::iterator it = values_.begin(); | |
42 it != values_.end(); ++it) | |
43 { | |
44 assert(it->second != NULL); | |
45 delete it->second; | |
46 } | |
305
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
47 |
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
48 values_.clear(); |
0 | 49 } |
305
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
50 |
0 | 51 |
52 bool Dictionary::HasKey(const std::string& key) const | |
53 { | |
54 return values_.find(key) != values_.end(); | |
55 } | |
56 | |
57 | |
58 void Dictionary::Remove(const std::string& key) | |
59 { | |
60 Values::iterator found = values_.find(key); | |
61 | |
62 if (found != values_.end()) | |
63 { | |
64 assert(found->second != NULL); | |
65 delete found->second; | |
66 values_.erase(found); | |
67 } | |
68 } | |
69 | |
70 | |
71 void Dictionary::SetValue(const std::string& key, | |
72 IValue* value) // Takes ownership | |
73 { | |
74 if (value == NULL) | |
75 { | |
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
77 } | |
78 | |
79 Values::iterator found = values_.find(key); | |
80 | |
81 if (found == values_.end()) | |
82 { | |
83 values_[key] = value; | |
84 } | |
85 else | |
86 { | |
87 assert(found->second != NULL); | |
88 delete found->second; | |
89 found->second = value; | |
90 } | |
91 } | |
92 | |
93 | |
94 void Dictionary::SetUtf8Value(const std::string& key, | |
95 const std::string& utf8) | |
96 { | |
97 SetValue(key, new Utf8StringValue(utf8)); | |
98 } | |
99 | |
100 | |
101 void Dictionary::SetBinaryValue(const std::string& key, | |
102 const std::string& binary) | |
103 { | |
104 SetValue(key, new BinaryStringValue(binary)); | |
105 } | |
106 | |
107 | |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
108 void Dictionary::SetFileValue(const std::string& key, |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
109 const std::string& file) |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
110 { |
244
02cd7254c949
separating class InputFileValue from FileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
111 SetValue(key, new InputFileValue(file)); |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
112 } |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
113 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
114 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
115 void Dictionary::SetFileValue(const std::string& key, |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
116 const void* content, |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
117 size_t size) |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
118 { |
244
02cd7254c949
separating class InputFileValue from FileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
119 SetValue(key, new InputFileValue(content, size)); |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
120 } |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
121 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
122 |
0 | 123 void Dictionary::SetIntegerValue(const std::string& key, |
124 int64_t value) | |
125 { | |
126 SetValue(key, new Integer64Value(value)); | |
127 } | |
128 | |
129 | |
130 void Dictionary::SetNullValue(const std::string& key) | |
131 { | |
132 SetValue(key, new NullValue); | |
133 } | |
134 | |
135 | |
136 const IValue& Dictionary::GetValue(const std::string& key) const | |
137 { | |
138 Values::const_iterator found = values_.find(key); | |
139 | |
140 if (found == values_.end()) | |
141 { | |
142 LOG(ERROR) << "Inexistent value in a dictionary: " << key; | |
143 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem); | |
144 } | |
145 else | |
146 { | |
147 assert(found->second != NULL); | |
148 return *found->second; | |
149 } | |
150 } | |
151 } |