comparison OrthancStone/Sources/Toolbox/OsiriX/DictionaryValue.cpp @ 1584:bd180f97c734

parsing osirix annotations
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 21 Oct 2020 17:33:17 +0200
parents
children 4fb8fdf03314
comparison
equal deleted inserted replaced
1583:c8644706e78b 1584:bd180f97c734
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
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 "DictionaryValue.h"
23
24 #include <OrthancException.h>
25
26
27 namespace OrthancStone
28 {
29 namespace OsiriX
30 {
31 DictionaryValue::~DictionaryValue()
32 {
33 for (Content::iterator it = content_.begin(); it != content_.end(); ++it)
34 {
35 assert(it->second != NULL);
36 delete it->second;
37 }
38 }
39
40
41 void DictionaryValue::SetValue(const std::string& key,
42 IValue* value /* takes ownership */)
43 {
44 if (value == NULL)
45 {
46 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
47 }
48 else
49 {
50 std::unique_ptr<IValue> protection(value);
51
52 Content::iterator found = content_.find(key);
53 if (found == content_.end())
54 {
55 content_[key] = protection.release();
56 }
57 else
58 {
59 assert(found->second != NULL);
60 delete found->second;
61 found->second = protection.release();
62 }
63 }
64 }
65
66
67 const IValue* DictionaryValue::LookupValue(const std::string& key) const
68 {
69 Content::const_iterator found = content_.find(key);
70
71 if (found == content_.end())
72 {
73 return NULL;
74 }
75 else
76 {
77 assert(found->second != NULL);
78 return found->second;
79 }
80 }
81
82
83 const IValue& DictionaryValue::GetValue(const std::string& key) const
84 {
85 const IValue* value = LookupValue(key);
86 if (value == NULL)
87 {
88 // "HasValue()" should have been called
89 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
90 }
91 else
92 {
93 return *value;
94 }
95 }
96
97
98 void DictionaryValue::GetMembers(std::set<std::string>& target) const
99 {
100 target.clear();
101
102 for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it)
103 {
104 target.insert(it->first);
105 }
106 }
107 }
108 }