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