Mercurial > hg > orthanc-databases
annotate Framework/Common/Dictionary.cpp @ 585:65e39e76c2b6 find-refactoring tip
fix handling of attachments revision
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Mon, 04 Nov 2024 18:38:32 +0100 |
parents | c49136b34891 |
children |
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" |
522
c49136b34891
use a prepared statement for InsertOrUpdateMetadata
Alain Mazy <am@orthanc.team>
parents:
507
diff
changeset
|
28 #include "Integer32Value.h" |
0 | 29 #include "Integer64Value.h" |
30 #include "NullValue.h" | |
31 #include "Utf8StringValue.h" | |
32 | |
152 | 33 #include <Logging.h> |
34 #include <OrthancException.h> | |
0 | 35 |
36 #include <cassert> | |
37 | |
38 namespace OrthancDatabases | |
39 { | |
305
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
40 void Dictionary::Clear() |
0 | 41 { |
42 for (Values::iterator it = values_.begin(); | |
43 it != values_.end(); ++it) | |
44 { | |
45 assert(it->second != NULL); | |
46 delete it->second; | |
47 } | |
305
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
48 |
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
49 values_.clear(); |
0 | 50 } |
305
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
51 |
0 | 52 |
53 bool Dictionary::HasKey(const std::string& key) const | |
54 { | |
55 return values_.find(key) != values_.end(); | |
56 } | |
57 | |
58 | |
59 void Dictionary::Remove(const std::string& key) | |
60 { | |
61 Values::iterator found = values_.find(key); | |
62 | |
63 if (found != values_.end()) | |
64 { | |
65 assert(found->second != NULL); | |
66 delete found->second; | |
67 values_.erase(found); | |
68 } | |
69 } | |
70 | |
71 | |
72 void Dictionary::SetValue(const std::string& key, | |
73 IValue* value) // Takes ownership | |
74 { | |
75 if (value == NULL) | |
76 { | |
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
78 } | |
79 | |
80 Values::iterator found = values_.find(key); | |
81 | |
82 if (found == values_.end()) | |
83 { | |
84 values_[key] = value; | |
85 } | |
86 else | |
87 { | |
88 assert(found->second != NULL); | |
89 delete found->second; | |
90 found->second = value; | |
91 } | |
92 } | |
93 | |
94 | |
95 void Dictionary::SetUtf8Value(const std::string& key, | |
96 const std::string& utf8) | |
97 { | |
98 SetValue(key, new Utf8StringValue(utf8)); | |
99 } | |
100 | |
101 | |
102 void Dictionary::SetBinaryValue(const std::string& key, | |
103 const std::string& binary) | |
104 { | |
105 SetValue(key, new BinaryStringValue(binary)); | |
106 } | |
107 | |
108 | |
14
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
109 void Dictionary::SetFileValue(const std::string& key, |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
110 const std::string& file) |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
111 { |
244
02cd7254c949
separating class InputFileValue from FileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
112 SetValue(key, new InputFileValue(file)); |
14
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 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
116 void Dictionary::SetFileValue(const std::string& key, |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
117 const void* content, |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
118 size_t size) |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
119 { |
244
02cd7254c949
separating class InputFileValue from FileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
120 SetValue(key, new InputFileValue(content, size)); |
14
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 |
9774802fd05f
PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
123 |
0 | 124 void Dictionary::SetIntegerValue(const std::string& key, |
125 int64_t value) | |
126 { | |
127 SetValue(key, new Integer64Value(value)); | |
128 } | |
129 | |
522
c49136b34891
use a prepared statement for InsertOrUpdateMetadata
Alain Mazy <am@orthanc.team>
parents:
507
diff
changeset
|
130 |
c49136b34891
use a prepared statement for InsertOrUpdateMetadata
Alain Mazy <am@orthanc.team>
parents:
507
diff
changeset
|
131 void Dictionary::SetInteger32Value(const std::string& key, |
c49136b34891
use a prepared statement for InsertOrUpdateMetadata
Alain Mazy <am@orthanc.team>
parents:
507
diff
changeset
|
132 int32_t value) |
c49136b34891
use a prepared statement for InsertOrUpdateMetadata
Alain Mazy <am@orthanc.team>
parents:
507
diff
changeset
|
133 { |
c49136b34891
use a prepared statement for InsertOrUpdateMetadata
Alain Mazy <am@orthanc.team>
parents:
507
diff
changeset
|
134 SetValue(key, new Integer32Value(value)); |
c49136b34891
use a prepared statement for InsertOrUpdateMetadata
Alain Mazy <am@orthanc.team>
parents:
507
diff
changeset
|
135 } |
c49136b34891
use a prepared statement for InsertOrUpdateMetadata
Alain Mazy <am@orthanc.team>
parents:
507
diff
changeset
|
136 |
0 | 137 void Dictionary::SetNullValue(const std::string& key) |
138 { | |
139 SetValue(key, new NullValue); | |
140 } | |
141 | |
142 | |
143 const IValue& Dictionary::GetValue(const std::string& key) const | |
144 { | |
145 Values::const_iterator found = values_.find(key); | |
146 | |
147 if (found == values_.end()) | |
148 { | |
149 LOG(ERROR) << "Inexistent value in a dictionary: " << key; | |
150 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem); | |
151 } | |
152 else | |
153 { | |
154 assert(found->second != NULL); | |
155 return *found->second; | |
156 } | |
157 } | |
158 } |