Mercurial > hg > orthanc
annotate OrthancFramework/Sources/JobsEngine/Operations/JobOperationValues.cpp @ 5040:1c08cd68250a
removed the 'name' of MainDicomTags to simplify code -> DicomMap::ParseMainDicomTags has been deprecated and one should use DicomMap::FromDicomAsJson on 'full' formatted tags
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 27 Jun 2022 12:39:51 +0200 |
parents | 43e613a7756b |
children | 0ea402b4d901 |
rev | line source |
---|---|
2601 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2601 | 7 * |
8 * 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
|
9 * 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
|
10 * 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
|
11 * the License, or (at your option) any later version. |
2601 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * 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
|
16 * Lesser General Public License for more details. |
2601 | 17 * |
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
|
18 * 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
|
19 * 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
|
20 * <http://www.gnu.org/licenses/>. |
2601 | 21 **/ |
22 | |
23 | |
24 #include "../../PrecompiledHeaders.h" | |
25 #include "JobOperationValues.h" | |
26 | |
2621
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
27 #include "../IJobUnserializer.h" |
2601 | 28 #include "../../OrthancException.h" |
29 | |
30 #include <cassert> | |
2621
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
31 #include <memory> |
2601 | 32 |
33 namespace Orthanc | |
34 { | |
4348
93c281752e7a
reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4310
diff
changeset
|
35 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1 |
93c281752e7a
reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4310
diff
changeset
|
36 void JobOperationValues::Append(JobOperationValue* value) |
93c281752e7a
reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4310
diff
changeset
|
37 { |
93c281752e7a
reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4310
diff
changeset
|
38 throw OrthancException(ErrorCode_DiscontinuedAbi, "Removed in 1.8.1"); |
93c281752e7a
reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4310
diff
changeset
|
39 } |
93c281752e7a
reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4310
diff
changeset
|
40 #endif |
93c281752e7a
reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4310
diff
changeset
|
41 |
93c281752e7a
reintroduced backward ABI compatibility in Orthanc Framework .so for unit tests of Orthanc 1.7.2 to 1.8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4310
diff
changeset
|
42 |
2601 | 43 void JobOperationValues::Append(JobOperationValues& target, |
44 bool clear) | |
45 { | |
46 target.Reserve(target.GetSize() + GetSize()); | |
47 | |
48 for (size_t i = 0; i < values_.size(); i++) | |
49 { | |
50 if (clear) | |
51 { | |
52 target.Append(values_[i]); | |
53 values_[i] = NULL; | |
54 } | |
55 else | |
56 { | |
57 target.Append(GetValue(i).Clone()); | |
58 } | |
59 } | |
60 | |
61 if (clear) | |
62 { | |
63 Clear(); | |
64 } | |
65 } | |
66 | |
4300 | 67 JobOperationValues::~JobOperationValues() |
68 { | |
69 Clear(); | |
70 } | |
71 | |
72 void JobOperationValues::Move(JobOperationValues &target) | |
73 { | |
74 return Append(target, true); | |
75 } | |
76 | |
77 void JobOperationValues::Copy(JobOperationValues &target) | |
78 { | |
79 return Append(target, false); | |
80 } | |
81 | |
2601 | 82 |
83 void JobOperationValues::Clear() | |
84 { | |
85 for (size_t i = 0; i < values_.size(); i++) | |
86 { | |
87 if (values_[i] != NULL) | |
88 { | |
89 delete values_[i]; | |
90 } | |
91 } | |
92 | |
93 values_.clear(); | |
94 } | |
95 | |
4300 | 96 void JobOperationValues::Reserve(size_t count) |
97 { | |
98 values_.reserve(count); | |
99 } | |
100 | |
2601 | 101 |
4310
2ae905070221
renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
102 void JobOperationValues::Append(IJobOperationValue* value) // Takes ownership |
2601 | 103 { |
104 if (value == NULL) | |
105 { | |
106 throw OrthancException(ErrorCode_NullPointer); | |
107 } | |
108 else | |
109 { | |
110 values_.push_back(value); | |
111 } | |
112 } | |
113 | |
4300 | 114 size_t JobOperationValues::GetSize() const |
115 { | |
116 return values_.size(); | |
117 } | |
118 | |
2601 | 119 |
4310
2ae905070221
renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
120 IJobOperationValue& JobOperationValues::GetValue(size_t index) const |
2601 | 121 { |
122 if (index >= values_.size()) | |
123 { | |
124 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
125 } | |
126 else | |
127 { | |
128 assert(values_[index] != NULL); | |
129 return *values_[index]; | |
130 } | |
131 } | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
132 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
133 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
134 void JobOperationValues::Serialize(Json::Value& target) const |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
135 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
136 target = Json::arrayValue; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
137 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
138 for (size_t i = 0; i < values_.size(); i++) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
139 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
140 Json::Value tmp; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
141 values_[i]->Serialize(tmp); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
142 target.append(tmp); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
143 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2601
diff
changeset
|
144 } |
2621
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
145 |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
146 |
2655 | 147 JobOperationValues* JobOperationValues::Unserialize(IJobUnserializer& unserializer, |
148 const Json::Value& source) | |
2621
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
149 { |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
150 if (source.type() != Json::arrayValue) |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
151 { |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
152 throw OrthancException(ErrorCode_BadFileFormat); |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
153 } |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
154 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
155 std::unique_ptr<JobOperationValues> result(new JobOperationValues); |
2621
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
156 |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
157 result->Reserve(source.size()); |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
158 |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
159 for (Json::Value::ArrayIndex i = 0; i < source.size(); i++) |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
160 { |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
161 result->Append(unserializer.UnserializeValue(source[i])); |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
162 } |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
163 |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
164 return result.release(); |
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2616
diff
changeset
|
165 } |
2601 | 166 } |